Use set/clear logic on buttons
This commit is contained in:
@@ -9,45 +9,36 @@
|
|||||||
void ProcessUI() {
|
void ProcessUI() {
|
||||||
uint8_t Buttons = getButtons(); //read the buttons status
|
uint8_t Buttons = getButtons(); //read the buttons status
|
||||||
static uint32_t lastModeChange = 0;
|
static uint32_t lastModeChange = 0;
|
||||||
if (millis() - getLastButtonPress() < 100)
|
if (millis() - getLastButtonPress() < 30)
|
||||||
Buttons = 0;
|
Buttons = 0;
|
||||||
|
else if (Buttons != 0) {
|
||||||
|
resetLastButtonPress();
|
||||||
|
resetButtons();
|
||||||
|
}
|
||||||
//rough prevention for de-bouncing and allocates settling time
|
//rough prevention for de-bouncing and allocates settling time
|
||||||
|
|
||||||
switch (operatingMode) {
|
switch (operatingMode) {
|
||||||
case STARTUP:
|
case STARTUP:
|
||||||
if ((millis() - getLastButtonPress() > 1000)) {
|
|
||||||
if (Buttons == (BUT_A | BUT_B)) {
|
if (Buttons == (BUT_A | BUT_B)) {
|
||||||
operatingMode = THERMOMETER;
|
operatingMode = THERMOMETER;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
} else if (Buttons == BUT_A) {
|
} else if (Buttons == BUT_A) {
|
||||||
//A key pressed so we are moving to soldering mode
|
//A key pressed so we are moving to soldering mode
|
||||||
operatingMode = SOLDERING;
|
operatingMode = SOLDERING;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
} else if (Buttons == BUT_B) {
|
} else if (Buttons == BUT_B) {
|
||||||
//B Button was pressed so we are moving to the Settings menu
|
//B Button was pressed so we are moving to the Settings menu
|
||||||
operatingMode = SETTINGS;
|
operatingMode = SETTINGS;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//Nothing else to check here
|
|
||||||
break;
|
break;
|
||||||
case SOLDERING:
|
case SOLDERING:
|
||||||
//We need to check the buttons if we need to jump out
|
//We need to check the buttons if we need to jump out
|
||||||
if (Buttons == BUT_A || Buttons == BUT_B) {
|
if (Buttons == BUT_A || Buttons == BUT_B) {
|
||||||
//A or B key pressed so we are moving to temp set
|
//A or B key pressed so we are moving to temp set
|
||||||
operatingMode = TEMP_ADJ;
|
operatingMode = TEMP_ADJ;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
} else if (Buttons == (BUT_A | BUT_B)) {
|
} else if (Buttons == (BUT_A | BUT_B)) {
|
||||||
if (millis() - getLastButtonPress() > 500) {
|
|
||||||
//Both buttons were pressed, exit back to the cooling screen
|
//Both buttons were pressed, exit back to the cooling screen
|
||||||
operatingMode = COOLING;
|
operatingMode = COOLING;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
//We need to check the timer for movement in case we need to goto idle
|
//We need to check the timer for movement in case we need to goto idle
|
||||||
if (systemSettings.movementEnabled)
|
if (systemSettings.movementEnabled)
|
||||||
@@ -62,32 +53,29 @@ void ProcessUI() {
|
|||||||
uint16_t voltage = readDCVoltage(); //get X10 voltage
|
uint16_t voltage = readDCVoltage(); //get X10 voltage
|
||||||
if ((voltage / 10) < systemSettings.cutoutVoltage) {
|
if ((voltage / 10) < systemSettings.cutoutVoltage) {
|
||||||
operatingMode = UVLOWARN;
|
operatingMode = UVLOWARN;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
lastModeChange = millis();
|
lastModeChange = millis();
|
||||||
}
|
}
|
||||||
//Update the PID Loop
|
//Update the PID Loop
|
||||||
int32_t newOutput = computePID(systemSettings.SolderingTemp);
|
int32_t newOutput = computePID(systemSettings.SolderingTemp);
|
||||||
|
|
||||||
setIronTimer(newOutput);
|
setIronTimer(newOutput);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case TEMP_ADJ:
|
case TEMP_ADJ:
|
||||||
if (Buttons & BUT_A) {
|
if (Buttons == BUT_A) {
|
||||||
//A key pressed so we are moving down in temp
|
//A key pressed so we are moving down in temp
|
||||||
resetLastButtonPress();
|
|
||||||
if (systemSettings.SolderingTemp > 1000)
|
if (systemSettings.SolderingTemp > 1000)
|
||||||
systemSettings.SolderingTemp -= 100;
|
systemSettings.SolderingTemp -= 100;
|
||||||
} else if (Buttons & BUT_B) {
|
} else if (Buttons == BUT_B) {
|
||||||
//B key pressed so we are moving up in temp
|
//B key pressed so we are moving up in temp
|
||||||
resetLastButtonPress();
|
|
||||||
if (systemSettings.SolderingTemp < 4500)
|
if (systemSettings.SolderingTemp < 4500)
|
||||||
systemSettings.SolderingTemp += 100;
|
systemSettings.SolderingTemp += 100;
|
||||||
} else {
|
} else {
|
||||||
//we check the timeout for how long the buttons have not been pushed
|
//we check the timeout for how long the buttons have not been pushed
|
||||||
//if idle for > 3 seconds then we return to soldering
|
//if idle for > 3 seconds then we return to soldering
|
||||||
if (millis() - getLastButtonPress() > 2000) {
|
//Or if both buttons pressed
|
||||||
|
if ((millis() - getLastButtonPress() > 2000)
|
||||||
|
|| Buttons == (BUT_A | BUT_B)) {
|
||||||
operatingMode = SOLDERING;
|
operatingMode = SOLDERING;
|
||||||
saveSettings();
|
saveSettings();
|
||||||
}
|
}
|
||||||
@@ -98,7 +86,6 @@ void ProcessUI() {
|
|||||||
//Here we are in the menu so we need to increment through the sub menus / increase the value
|
//Here we are in the menu so we need to increment through the sub menus / increase the value
|
||||||
|
|
||||||
if (Buttons & BUT_A) {
|
if (Buttons & BUT_A) {
|
||||||
resetLastButtonPress();
|
|
||||||
//A key iterates through the menu
|
//A key iterates through the menu
|
||||||
if (settingsPage == SETTINGSOPTIONSCOUNT) {
|
if (settingsPage == SETTINGSOPTIONSCOUNT) {
|
||||||
//Roll off the end
|
//Roll off the end
|
||||||
@@ -154,14 +141,10 @@ void ProcessUI() {
|
|||||||
if (Buttons & BUT_A) {
|
if (Buttons & BUT_A) {
|
||||||
//A Button was pressed so we are moving back to soldering
|
//A Button was pressed so we are moving back to soldering
|
||||||
operatingMode = SOLDERING;
|
operatingMode = SOLDERING;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
return;
|
return;
|
||||||
} else if (Buttons & BUT_B) {
|
} else if (Buttons & BUT_B) {
|
||||||
//B Button was pressed so we are moving back to soldering
|
//B Button was pressed so we are moving back to soldering
|
||||||
operatingMode = SOLDERING;
|
operatingMode = SOLDERING;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
return;
|
return;
|
||||||
} else if (systemSettings.movementEnabled)
|
} else if (systemSettings.movementEnabled)
|
||||||
if (millis() - getLastMovement() < 1000) {//moved in the last second
|
if (millis() - getLastMovement() < 1000) {//moved in the last second
|
||||||
@@ -170,9 +153,7 @@ void ProcessUI() {
|
|||||||
}
|
}
|
||||||
//else if nothing has been pushed we need to compute the PID to keep the iron at the sleep temp
|
//else if nothing has been pushed we need to compute the PID to keep the iron at the sleep temp
|
||||||
int32_t newOutput = computePID(systemSettings.SleepTemp);
|
int32_t newOutput = computePID(systemSettings.SleepTemp);
|
||||||
|
|
||||||
setIronTimer(newOutput);
|
setIronTimer(newOutput);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
case COOLING: {
|
case COOLING: {
|
||||||
setIronTimer(0); //turn off heating
|
setIronTimer(0); //turn off heating
|
||||||
@@ -180,13 +161,9 @@ void ProcessUI() {
|
|||||||
uint16_t temp = readIronTemp(0, 1); //take a new reading as the heater code is not taking new readings
|
uint16_t temp = readIronTemp(0, 1); //take a new reading as the heater code is not taking new readings
|
||||||
if (temp < 400) { //if the temp is < 40C then we can go back to IDLE
|
if (temp < 400) { //if the temp is < 40C then we can go back to IDLE
|
||||||
operatingMode = STARTUP;
|
operatingMode = STARTUP;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
} else if (Buttons & (BUT_A | BUT_B)) { //we check if the user has pushed a button to ack
|
} else if (Buttons & (BUT_A | BUT_B)) { //we check if the user has pushed a button to ack
|
||||||
//Either button was pushed
|
//Either button was pushed
|
||||||
operatingMode = STARTUP;
|
operatingMode = STARTUP;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -199,36 +176,28 @@ void ProcessUI() {
|
|||||||
break;
|
break;
|
||||||
case THERMOMETER: {
|
case THERMOMETER: {
|
||||||
//This lets the user check the tip temp without heating the iron.. And eventually calibration will be added here
|
//This lets the user check the tip temp without heating the iron.. And eventually calibration will be added here
|
||||||
if ((millis() - getLastButtonPress() > 1000)) {
|
|
||||||
if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
|
if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
|
||||||
//Single button press, cycle over to the DC display
|
//Single button press, cycle over to the DC display
|
||||||
operatingMode = DCINDISP;
|
operatingMode = DCINDISP;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
} else if (Buttons == (BUT_A | BUT_B)) {
|
} else if (Buttons == (BUT_A | BUT_B)) {
|
||||||
//If the user is holding both button, exit the screen
|
//If the user is holding both button, exit the screen
|
||||||
operatingMode = STARTUP;
|
operatingMode = STARTUP;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case DCINDISP: {
|
case DCINDISP: {
|
||||||
//This lets the user check the input voltage
|
//This lets the user check the input voltage
|
||||||
if ((millis() - getLastButtonPress() > 1000)) {
|
|
||||||
if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
|
if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
|
||||||
//Single button press, cycle over to the temp display
|
//Single button press, cycle over to the temp display
|
||||||
operatingMode = THERMOMETER;
|
operatingMode = THERMOMETER;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
} else if (Buttons == (BUT_A | BUT_B)) {
|
} else if (Buttons == (BUT_A | BUT_B)) {
|
||||||
//If the user is holding both button, exit the screen
|
//If the user is holding both button, exit the screen
|
||||||
operatingMode = STARTUP;
|
operatingMode = STARTUP;
|
||||||
resetLastButtonPress();
|
|
||||||
resetButtons();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
Reference in New Issue
Block a user