Skip to content

Commit

Permalink
Merge pull request #34 from futurexdesign/sounderPWM_Merging
Browse files Browse the repository at this point in the history
Sounder pwm merging
  • Loading branch information
futurexdesign authored Jun 8, 2023
2 parents faaf3bb + ba98d46 commit 7878a6f
Show file tree
Hide file tree
Showing 9 changed files with 416 additions and 9 deletions.
40 changes: 39 additions & 1 deletion KiwiBoard.emf
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"type": "analogItem",
"defaultValue": "50",
"item": {
"maxValue": 550,
"maxValue": 950,
"offset": 50,
"divisor": 1,
"unitName": "rpm",
Expand Down Expand Up @@ -483,6 +483,44 @@
"staticDataInRAM": false
}
},
{
"parentId": 30,
"type": "boolItem",
"defaultValue": "false",
"item": {
"naming": "ON_OFF",
"name": "Sound",
"variableName": "sounder",
"id": 49,
"eepromAddress": 97,
"functionName": "@soundChanged",
"readOnly": false,
"localOnly": false,
"visible": true,
"staticDataInRAM": false
}
},
{
"parentId": 30,
"type": "analogItem",
"defaultValue": "0",
"item": {
"maxValue": 100,
"offset": 0,
"divisor": 1,
"unitName": "%",
"step": 1,
"name": "Volume",
"variableName": "SoundLevel",
"id": 50,
"eepromAddress": 98,
"functionName": "@soundLevel",
"readOnly": false,
"localOnly": false,
"visible": true,
"staticDataInRAM": false
}
},
{
"parentId": 30,
"type": "boolItem",
Expand Down
46 changes: 43 additions & 3 deletions src/KiwiBoardFirmware_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "KiwiBoardFirmware_main.h"
#include "EncoderShim.h"
#include "heat.h"
#include "Sounder.h"

#ifdef SCREENCAP
#include "screenServer.h"
Expand All @@ -26,6 +27,7 @@ PicoPlatform *platform;
MotorControl *motorControl = nullptr;
MenuChangeObserver *observer;
EncoderShim *encoderShim;
BeepHandler *sounderOps; // Declare sounderOps (based on class BeepHandler)

// Error occurred, in HALT state.
bool HALT = false;
Expand Down Expand Up @@ -55,7 +57,6 @@ void setup() {
platform = new PicoPlatform();
platform->initializePlatform();


// Init the graphics subsystem and trigger the splash.
gfx.begin();
gfx.setRotation(3);
Expand All @@ -66,6 +67,9 @@ void setup() {
delay(2000);
gfx.fillScreen(TFT_BLACK);

// Setup Sounder
sounderOps = new BeepHandler(platform); // Instantiate object sounderOps based on BeepHandler

// Setup switches and encoder?
encoderShim = new EncoderShim();
encoderShim->initForEncoder();
Expand Down Expand Up @@ -95,13 +99,18 @@ void setup() {
setupMenu();
}

// Get saved values for sounder and sound level..
sounderOps->set_menuSound(menusounder.getBoolean());
sounderOps->set_sndLevel(menuSoundLevel.getIntValueIncludingOffset());

observer = new MenuChangeObserver(&menuMgr, &menuRunTime, &menuWash);
menuMgr.addChangeNotification(observer);

menuVersion.setTextValue(VERSION_NUM, true);

setMenuOptions();
scheduleTasks();

}

/**
Expand All @@ -117,6 +126,7 @@ void loop() {
void stoppedCallback(int pgm) {

// Stopped happened.
sounderOps->beep_activate(0, false); // 0 = End of cycle tone
resetIcons();
observer->resetConstraint();
}
Expand Down Expand Up @@ -270,12 +280,22 @@ void run(int program, MenuItem *icon) {
motorControl->stopMotion();
} else {
motorControl->startProgram(program, getSettings());

setIconStopped(icon);
observer->constrainToStopButton(icon);
}
}

void CALLBACK_FUNCTION soundLevel(int id) {

// Get changes to sound level and then set
// beep for every turn of the encoder when setting sound level

sounderOps->set_sndLevel(menuSoundLevel.getIntValueIncludingOffset());
sounderOps->beep_activate(1, true); // Short beep, override soundset var
settingsChanged = true; // Save settings

}

void CALLBACK_FUNCTION settings_changed(int id) {
// TODO Look for actual changes in the setting values rather than just saving settings any time
// someone went to the settings menu.... Or add a save button?
Expand Down Expand Up @@ -350,6 +370,19 @@ void CALLBACK_FUNCTION stealthChopChange(int id) {
settingsChanged = true;
}

/**
* Callback when the user changes the sound setting.
*
* @param id
*/
void CALLBACK_FUNCTION soundChanged(int id) {
Serial.println("Sound changed... ");

sounderOps->set_menuSound(menusounder.getBoolean());

settingsChanged = true;
}

/**
* Commit settings to eeprom if they have changed. Try not to thrash the EEPROM with too many
* calls.
Expand Down Expand Up @@ -391,6 +424,10 @@ void scheduleTasks() {
// To prevent thrashing of the EEPROM, only save settings periodically if things were touched.
taskManager.scheduleFixedRate(60, commit_if_needed, TIME_SECONDS);

// Sounder operation needs to be non-blocking so we update the status regularly
// Schedule sounder updates for every 20ms to ensure granularity for short beeps
taskManager.scheduleFixedRate(20, sounderOps, TIME_MILLIS);

// Only schedule the screen capture if SCREENCAP is defined from platformio.ini
#ifdef SCREENCAP
taskManager.scheduleFixedRate(2, screenCaptureTask, TIME_SECONDS);
Expand Down Expand Up @@ -513,7 +550,10 @@ void setIconStopped(MenuItem *icon) {
}

void checkLongPress(bool direction, bool held) {


// Button pressed, so we beep
sounderOps->beep_activate(1, false); // Short beep, no soundset override

// Check for a long press... no idea what menu ... but whatever?
if (held) {
// what are we long pressing on?
Expand Down
10 changes: 7 additions & 3 deletions src/KiwiBoardFirmware_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ RENDERING_CALLBACK_NAME_INVOKE(fnVersionRtCall, textItemRenderFn, "Version", -1,
TextMenuItem menuVersion(fnVersionRtCall, "1.00", 43, 10, NULL);
const BooleanMenuInfo minfomotorTest = { "Motor Test", 44, 0xffff, 1, motortest, NAMING_ON_OFF };
BooleanMenuItem menumotorTest(&minfomotorTest, false, &menuVersion, INFO_LOCATION_PGM);
const AnalogMenuInfo minfoSoundLevel = { "Volume", 50, 98, 100, soundLevel, 0, 1, "%" };
AnalogMenuItem menuSoundLevel(&minfoSoundLevel, 0, &menumotorTest, INFO_LOCATION_PGM);
const BooleanMenuInfo minfosounder = { "Sound", 49, 97, 1, soundChanged, NAMING_ON_OFF };
BooleanMenuItem menusounder(&minfosounder, false, &menuSoundLevel, INFO_LOCATION_PGM);
const BooleanMenuInfo minfoStealthChop = { "StealthChop", 45, 96, 1, stealthChopChange, NAMING_ON_OFF };
BooleanMenuItem menuStealthChop(&minfoStealthChop, true, &menumotorTest, INFO_LOCATION_PGM);
BooleanMenuItem menuStealthChop(&minfoStealthChop, true, &menusounder, INFO_LOCATION_PGM);
const AnalogMenuInfo minfoIRun = { "IRun", 33, 77, 31, iRunChanged, 0, 1, "" };
AnalogMenuItem menuIRun(&minfoIRun, 17, &menuStealthChop, INFO_LOCATION_PGM);
const AnalogMenuInfo minfoGlobalScaler = { "Global Scaler", 32, 75, 255, GlobalScalerChanged, 0, 1, "" };
Expand All @@ -50,7 +54,7 @@ BackMenuItem menuBackDrySettings(&minfoDrySettings, &menudry_duration, INFO_LOCA
SubMenuItem menuDrySettings(&minfoDrySettings, &menuBackDrySettings, &menuAdvanced, INFO_LOCATION_PGM);
const AnalogMenuInfo minfospinAMAX = { "Accel", 40, 88, 2000, settings_changed, 500, 1, "" };
AnalogMenuItem menuspinAMAX(&minfospinAMAX, 375, NULL, INFO_LOCATION_PGM);
const AnalogMenuInfo minfospin_speed = { "Speed", 14, 14, 550, settings_changed, 50, 1, "rpm" };
const AnalogMenuInfo minfospin_speed = { "Speed", 14, 14, 950, settings_changed, 50, 1, "rpm" };
AnalogMenuItem menuspin_speed(&minfospin_speed, 50, &menuspinAMAX, INFO_LOCATION_PGM);
const AnalogMenuInfo minfospin_duration = { "Time", 13, 12, 119, settings_changed, 1, 1, "sec" };
AnalogMenuItem menuspin_duration(&minfospin_duration, 44, &menuspin_speed, INFO_LOCATION_PGM);
Expand Down Expand Up @@ -89,10 +93,10 @@ void setupMenu() {
// Now add any readonly, non-remote and visible flags.
menuVersion.setReadOnly(true);
menuspinAMAX.setStep(25);
menuspin_speed.setStep(5);
menuwashAMAX.setStep(25);
menuwash_speed.setStep(5);
menudry_speed.setStep(5);
menuspin_speed.setStep(5);

// Code generated by plugins.
gfx.begin();
Expand Down
4 changes: 4 additions & 0 deletions src/KiwiBoardFirmware_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ extern GraphicsDeviceRenderer renderer;
// Global Menu Item exports
extern TextMenuItem menuVersion;
extern BooleanMenuItem menumotorTest;
extern AnalogMenuItem menuSoundLevel;
extern BooleanMenuItem menusounder;
extern BooleanMenuItem menuStealthChop;
extern AnalogMenuItem menuIRun;
extern AnalogMenuItem menuGlobalScaler;
Expand Down Expand Up @@ -77,6 +79,8 @@ void CALLBACK_FUNCTION dry(int id);
void CALLBACK_FUNCTION iRunChanged(int id);
void CALLBACK_FUNCTION motortest(int id);
void CALLBACK_FUNCTION settings_changed(int id);
void CALLBACK_FUNCTION soundChanged(int id);
void CALLBACK_FUNCTION soundLevel(int id);
void CALLBACK_FUNCTION spin(int id);
void CALLBACK_FUNCTION stealthChopChange(int id);
void CALLBACK_FUNCTION wash(int id);
Expand Down
Loading

0 comments on commit 7878a6f

Please sign in to comment.