diff --git a/Translations/translation_EN.json b/Translations/translation_EN.json index c6f440a6f7..bbf0c0a318 100644 --- a/Translations/translation_EN.json +++ b/Translations/translation_EN.json @@ -233,6 +233,10 @@ "displayText": "Hall sensor\nsensitivity", "description": "Sensitivity to magnets (1=least sensitive | ... | 9=most sensitive)" }, + "HallEffSleepTimeout": { + "displayText": "HallSensor\nSleepTime", + "description": "Interval before \"sleep mode\" starts when hall effect is above threshold" + }, "TemperatureUnit": { "displayText": "Temperature\nunit", "description": "C=°Celsius | F=°Fahrenheit" diff --git a/Translations/translations_definitions.json b/Translations/translations_definitions.json index 3b735c3afd..5cfe4302f4 100644 --- a/Translations/translations_definitions.json +++ b/Translations/translations_definitions.json @@ -411,6 +411,13 @@ "include": ["HALL_SENSOR"], "description": "If the unit has a hall effect sensor (Pinecil), this adjusts how sensitive it is at detecting a magnet to put the device into sleep mode." }, + { + "id": "HallEffSleepTimeout", + "maxLen": 10, + "maxLen2": 10, + "include": ["HALL_SENSOR"], + "description": "If the unit has a hall effect sensor (Pinecil), this adjusts how long the device takes before it drops down to the sleep temperature when hall sensor is over threshold." + }, { "id": "TemperatureUnit", "maxLen": 6, diff --git a/source/Core/Inc/Settings.h b/source/Core/Inc/Settings.h index 007e47b810..9a5198ea69 100644 --- a/source/Core/Inc/Settings.h +++ b/source/Core/Inc/Settings.h @@ -49,32 +49,33 @@ enum SettingsOptions { TempChangeLongStep = 26, // Temperature-change-increment on long button press TempChangeShortStep = 27, // Temperature-change-increment on short button press HallEffectSensitivity = 28, // Operating mode of the hall effect sensor - AccelMissingWarningCounter = 29, // Counter of how many times we have warned we cannot detect the accelerometer - PDMissingWarningCounter = 30, // Counter of how many times we have warned we cannot detect the pd interface - UILanguage = 31, // Selected UI Language code, null-terminated *only if* the length is less than 8 chars - PDNegTimeout = 32, // PD timeout in 100ms steps - OLEDInversion = 33, // Invert the colours on the display - OLEDBrightness = 34, // Brightness for the OLED display - LOGOTime = 35, // Duration the logo will be displayed for - CalibrateCJC = 36, // Toggle calibrate CJC at next boot - BluetoothLE = 37, // Toggle BLE if present - USBPDMode = 38, // Toggle PPS & EPR - ProfilePhases = 39, // Number of profile mode phases - ProfilePreheatTemp = 40, // Temperature to preheat to before the first phase - ProfilePreheatSpeed = 41, // Maximum allowed preheat speed in degrees per second - ProfilePhase1Temp = 42, // Temperature to target for the end of phase 1 - ProfilePhase1Duration = 43, // Target duration for phase 1 - ProfilePhase2Temp = 44, // Temperature to target for the end of phase 2 - ProfilePhase2Duration = 45, // Target duration for phase 2 - ProfilePhase3Temp = 46, // Temperature to target for the end of phase 3 - ProfilePhase3Duration = 47, // Target duration for phase 3 - ProfilePhase4Temp = 48, // Temperature to target for the end of phase 4 - ProfilePhase4Duration = 49, // Target duration for phase 4 - ProfilePhase5Temp = 50, // Temperature to target for the end of phase 5 - ProfilePhase5Duration = 51, // Target duration for phase 5 - ProfileCooldownSpeed = 52, // Maximum allowed cooldown speed in degrees per second + HallEffectSleepTime = 29, // Seconds timeout to sleep when hall effect over threshold + AccelMissingWarningCounter = 30, // Counter of how many times we have warned we cannot detect the accelerometer + PDMissingWarningCounter = 31, // Counter of how many times we have warned we cannot detect the pd interface + UILanguage = 32, // Selected UI Language code, null-terminated *only if* the length is less than 8 chars + PDNegTimeout = 33, // PD timeout in 100ms steps + OLEDInversion = 34, // Invert the colours on the display + OLEDBrightness = 35, // Brightness for the OLED display + LOGOTime = 36, // Duration the logo will be displayed for + CalibrateCJC = 37, // Toggle calibrate CJC at next boot + BluetoothLE = 38, // Toggle BLE if present + USBPDMode = 39, // Toggle PPS & EPR + ProfilePhases = 40, // Number of profile mode phases + ProfilePreheatTemp = 41, // Temperature to preheat to before the first phase + ProfilePreheatSpeed = 42, // Maximum allowed preheat speed in degrees per second + ProfilePhase1Temp = 43, // Temperature to target for the end of phase 1 + ProfilePhase1Duration = 44, // Target duration for phase 1 + ProfilePhase2Temp = 45, // Temperature to target for the end of phase 2 + ProfilePhase2Duration = 46, // Target duration for phase 2 + ProfilePhase3Temp = 47, // Temperature to target for the end of phase 3 + ProfilePhase3Duration = 48, // Target duration for phase 3 + ProfilePhase4Temp = 49, // Temperature to target for the end of phase 4 + ProfilePhase4Duration = 50, // Target duration for phase 4 + ProfilePhase5Temp = 51, // Temperature to target for the end of phase 5 + ProfilePhase5Duration = 52, // Target duration for phase 5 + ProfileCooldownSpeed = 53, // Maximum allowed cooldown speed in degrees per second // - SettingsOptionsLength = 53, // + SettingsOptionsLength = 54, // }; typedef enum { diff --git a/source/Core/Inc/Translation.h b/source/Core/Inc/Translation.h index 1e48b129d3..92185f6763 100644 --- a/source/Core/Inc/Translation.h +++ b/source/Core/Inc/Translation.h @@ -84,6 +84,7 @@ enum class SettingsItemIndex : uint8_t { SleepTimeout, ShutdownTimeout, HallEffSensitivity, + HallEffSleepTimeout, TemperatureUnit, DisplayRotation, CooldownBlink, diff --git a/source/Core/Src/Settings.cpp b/source/Core/Src/Settings.cpp index 9425590f82..ea9d277840 100644 --- a/source/Core/Src/Settings.cpp +++ b/source/Core/Src/Settings.cpp @@ -80,6 +80,7 @@ static const SettingConstants settingsConstants[(int)SettingsOptions::SettingsOp { 5, TEMP_CHANGE_LONG_STEP_MAX, 5, TEMP_CHANGE_LONG_STEP}, // TempChangeLongStep { 1, TEMP_CHANGE_SHORT_STEP_MAX, 1, TEMP_CHANGE_SHORT_STEP}, // TempChangeShortStep { 0, 9, 1, 7}, // HallEffectSensitivity + { 0, 12, 1, 0}, // HallEffectSleepTime { 0, 9, 1, 0}, // AccelMissingWarningCounter { 0, 9, 1, 0}, // PDMissingWarningCounter { 0, 0xFFFF, 0, 41431 /*EN*/}, // UILanguage diff --git a/source/Core/Src/settingsGUI.cpp b/source/Core/Src/settingsGUI.cpp index 1a9d4373e1..c21071a5f5 100644 --- a/source/Core/Src/settingsGUI.cpp +++ b/source/Core/Src/settingsGUI.cpp @@ -111,6 +111,7 @@ static void displayLogoTime(void); #ifdef HALL_SENSOR static void displayHallEffect(void); +static void displayHallEffectSleepTime(void); static bool showHallEffect(void); #endif /* HALL_SENSOR */ @@ -162,6 +163,7 @@ static void displayAdvancedMenu(void); * -Sleep Time * -Shutdown Time * Hall Sensor Sensitivity + * Hall Sensor Sleep Time * * UI * Temperature Unit @@ -346,6 +348,8 @@ const menuitem PowerSavingMenu[] = { #ifdef HALL_SENSOR /* Hall Effect Sensitivity */ {SETTINGS_DESC(SettingsItemIndex::HallEffSensitivity), nullptr, displayHallEffect, showHallEffect, SettingsOptions::HallEffectSensitivity, SettingsItemIndex::HallEffSensitivity, 7}, + /* Hall Effect Sleep Time */ + {SETTINGS_DESC(SettingsItemIndex::HallEffSleepTimeout), nullptr, displayHallEffectSleepTime, showHallEffect, SettingsOptions::HallEffectSleepTime, SettingsItemIndex::HallEffSleepTimeout, 5}, #endif /* HALL_SENSOR */ /* vvvv end of menu marker. DO NOT REMOVE vvvv */ {0, nullptr, nullptr, nullptr, SettingsOptions::SettingsOptionsLength, SettingsItemIndex::NUM_ITEMS, 0} @@ -740,6 +744,16 @@ static void displayHallEffect(void) { } } static bool showHallEffect(void) { return getHallSensorFitted(); } +static void displayHallEffectSleepTime(void) { + if (getSettingValue(SettingsOptions::HallEffectSleepTime)) { + OLED::printNumber(getSettingValue(SettingsOptions::HallEffectSleepTime) * 5, 2, FontStyle::LARGE, false); + OLED::print(LargeSymbolSeconds, FontStyle::LARGE); + } else { + // When sleep time is set to zero, we sleep for 1 second anyways. This is the default. + OLED::printNumber(1, 2, FontStyle::LARGE, false); + OLED::print(LargeSymbolSeconds, FontStyle::LARGE); + } +} #endif /* HALL_SENSOR */ static void setTempF(const enum SettingsOptions option) { diff --git a/source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h b/source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h index dccbec2c8a..1bd0835ee4 100644 --- a/source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h +++ b/source/Core/Threads/UI/logic/utils/OperatingModeUtilities.h @@ -7,6 +7,7 @@ void GUIDelay(); // bool checkForUnderVoltage(void); // uint32_t getSleepTimeout(void); // +uint32_t getHallEffectSleepTimeout(void); // bool shouldBeSleeping(); // bool shouldShutdown(void); // void printVoltage(void); // diff --git a/source/Core/Threads/UI/logic/utils/getHallEffectSleepTimeout.cpp b/source/Core/Threads/UI/logic/utils/getHallEffectSleepTimeout.cpp new file mode 100644 index 0000000000..3845a82fa1 --- /dev/null +++ b/source/Core/Threads/UI/logic/utils/getHallEffectSleepTimeout.cpp @@ -0,0 +1,16 @@ +#include "OperatingModeUtilities.h" + +#ifndef NO_SLEEP_MODE +#ifdef HALL_SENSOR +uint32_t getHallEffectSleepTimeout(void) { + + if (getSettingValue(SettingsOptions::HallEffectSensitivity) && getSettingValue(SettingsOptions::HallEffectSleepTime)) { + + uint32_t sleepThres = getSettingValue(SettingsOptions::HallEffectSleepTime) * 5 * TICKS_SECOND; + return sleepThres; + + } + return TICKS_SECOND; +} +#endif +#endif diff --git a/source/Core/Threads/UI/logic/utils/shouldDeviceSleep.cpp b/source/Core/Threads/UI/logic/utils/shouldDeviceSleep.cpp index 9e27f2ebd0..6b50800e8b 100644 --- a/source/Core/Threads/UI/logic/utils/shouldDeviceSleep.cpp +++ b/source/Core/Threads/UI/logic/utils/shouldDeviceSleep.cpp @@ -32,7 +32,7 @@ bool shouldBeSleeping() { if (lastHallEffectSleepStart == 0) { lastHallEffectSleepStart = xTaskGetTickCount(); } - if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) { + if ((xTaskGetTickCount() - lastHallEffectSleepStart) > getHallEffectSleepTimeout()) { return true; } } else {