From 26c7d0f2cbc6190b828c10f0ba50220d48065df8 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 5 Jan 2022 20:41:38 +1100 Subject: [PATCH 1/3] Clean up soldering temp adjust button handling --- source/Core/Src/Settings.cpp | 2 +- source/Core/Threads/GUIThread.cpp | 24 +++++++----------------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index 8beb8c9c11..e09501c3e2 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -29,7 +29,7 @@ typedef struct { uint16_t versionMarker; uint16_t length; // Length of valid bytes following uint16_t settingsValues[SettingsOptionsLength]; - // used to make this nicely "good enough" aligned to 32 butes to make driver code trivial + // used to make this nicely "good enough" aligned to 32 bytes to make driver code trivial uint32_t padding; } systemSettingsType; diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 1359fe57a4..054940bcff 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -202,36 +202,23 @@ static void gui_solderingTempAdjust() { break; case BUTTON_B_LONG: if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { - if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) { - delta = getSettingValue(SettingsOptions::TempChangeLongStep); - } else - delta = -getSettingValue(SettingsOptions::TempChangeLongStep); - + delta = -getSettingValue(SettingsOptions::TempChangeLongStep); autoRepeatTimer = xTaskGetTickCount(); autoRepeatAcceleration += PRESS_ACCEL_STEP; } break; case BUTTON_B_SHORT: - if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) { - delta = getSettingValue(SettingsOptions::TempChangeShortStep); - } else - delta = -getSettingValue(SettingsOptions::TempChangeShortStep); + delta = -getSettingValue(SettingsOptions::TempChangeShortStep); break; case BUTTON_F_LONG: if (xTaskGetTickCount() - autoRepeatTimer + autoRepeatAcceleration > PRESS_ACCEL_INTERVAL_MAX) { - if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) { - delta = -getSettingValue(SettingsOptions::TempChangeLongStep); - } else - delta = getSettingValue(SettingsOptions::TempChangeLongStep); + delta = getSettingValue(SettingsOptions::TempChangeLongStep); autoRepeatTimer = xTaskGetTickCount(); autoRepeatAcceleration += PRESS_ACCEL_STEP; } break; case BUTTON_F_SHORT: - if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) { - delta = -getSettingValue(SettingsOptions::TempChangeShortStep); - } else - delta = getSettingValue(SettingsOptions::TempChangeShortStep); + delta = getSettingValue(SettingsOptions::TempChangeShortStep); break; default: break; @@ -239,6 +226,9 @@ static void gui_solderingTempAdjust() { if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) { autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; } + if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) { + delta = -delta; + } // constrain between 10-450 C uint16_t newTemp = getSettingValue(SettingsOptions::SolderingTemp); newTemp += delta; From 827308f6911f063b5bde5f50101f7275c13c5d05 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 5 Jan 2022 21:00:14 +1100 Subject: [PATCH 2/3] Add some rounding --- source/Core/Threads/GUIThread.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index 054940bcff..face0ad188 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -226,12 +226,18 @@ static void gui_solderingTempAdjust() { if ((PRESS_ACCEL_INTERVAL_MAX - autoRepeatAcceleration) < PRESS_ACCEL_INTERVAL_MIN) { autoRepeatAcceleration = PRESS_ACCEL_INTERVAL_MAX - PRESS_ACCEL_INTERVAL_MIN; } + // If buttons are flipped; flip the delta if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) { delta = -delta; } - // constrain between 10-450 C - uint16_t newTemp = getSettingValue(SettingsOptions::SolderingTemp); + + // constrain between the set temp limits, i.e. 10-450 C + int16_t newTemp = getSettingValue(SettingsOptions::SolderingTemp); newTemp += delta; + // Round to nearest increment of delta + delta = abs(delta); + newTemp = (newTemp / delta) * delta; + if (getSettingValue(SettingsOptions::TemperatureInF)) { if (newTemp > MAX_TEMP_F) newTemp = MAX_TEMP_F; @@ -243,7 +249,7 @@ static void gui_solderingTempAdjust() { if (newTemp < MIN_TEMP_C) newTemp = MIN_TEMP_C; } - setSettingValue(SettingsOptions::SolderingTemp, newTemp); + setSettingValue(SettingsOptions::SolderingTemp, (uint16_t)newTemp); if (xTaskGetTickCount() - lastChange > (TICKS_SECOND * 2)) return; // exit if user just doesn't press anything for a bit From 52f0d5242aa1bd0b751fe5e65bf1635dc0d75144 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 5 Jan 2022 21:04:33 +1100 Subject: [PATCH 3/3] Update GUIThread.cpp --- source/Core/Threads/GUIThread.cpp | 40 +++++++++++++++---------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/source/Core/Threads/GUIThread.cpp b/source/Core/Threads/GUIThread.cpp index face0ad188..fe82e8cc8d 100644 --- a/source/Core/Threads/GUIThread.cpp +++ b/source/Core/Threads/GUIThread.cpp @@ -230,27 +230,27 @@ static void gui_solderingTempAdjust() { if (getSettingValue(SettingsOptions::ReverseButtonTempChangeEnabled)) { delta = -delta; } - - // constrain between the set temp limits, i.e. 10-450 C - int16_t newTemp = getSettingValue(SettingsOptions::SolderingTemp); - newTemp += delta; - // Round to nearest increment of delta - delta = abs(delta); - newTemp = (newTemp / delta) * delta; - - if (getSettingValue(SettingsOptions::TemperatureInF)) { - if (newTemp > MAX_TEMP_F) - newTemp = MAX_TEMP_F; - if (newTemp < MIN_TEMP_F) - newTemp = MIN_TEMP_F; - } else { - if (newTemp > MAX_TEMP_C) - newTemp = MAX_TEMP_C; - if (newTemp < MIN_TEMP_C) - newTemp = MIN_TEMP_C; + if (delta != 0) { + // constrain between the set temp limits, i.e. 10-450 C + int16_t newTemp = getSettingValue(SettingsOptions::SolderingTemp); + newTemp += delta; + // Round to nearest increment of delta + delta = abs(delta); + newTemp = (newTemp / delta) * delta; + + if (getSettingValue(SettingsOptions::TemperatureInF)) { + if (newTemp > MAX_TEMP_F) + newTemp = MAX_TEMP_F; + if (newTemp < MIN_TEMP_F) + newTemp = MIN_TEMP_F; + } else { + if (newTemp > MAX_TEMP_C) + newTemp = MAX_TEMP_C; + if (newTemp < MIN_TEMP_C) + newTemp = MIN_TEMP_C; + } + setSettingValue(SettingsOptions::SolderingTemp, (uint16_t)newTemp); } - setSettingValue(SettingsOptions::SolderingTemp, (uint16_t)newTemp); - if (xTaskGetTickCount() - lastChange > (TICKS_SECOND * 2)) return; // exit if user just doesn't press anything for a bit