Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a sleep timeout setting for hall sensor #1969

Merged
merged 6 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Translations/translation_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 7 additions & 0 deletions Translations/translations_definitions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
51 changes: 26 additions & 25 deletions source/Core/Inc/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this has to go at the end, these index's are used for setting migration between reflash so new settings need to be appended :(

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done in fdefb5b + fb904a5

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 {
Expand Down
1 change: 1 addition & 0 deletions source/Core/Inc/Translation.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ enum class SettingsItemIndex : uint8_t {
SleepTimeout,
ShutdownTimeout,
HallEffSensitivity,
HallEffSleepTimeout,
TemperatureUnit,
DisplayRotation,
CooldownBlink,
Expand Down
1 change: 1 addition & 0 deletions source/Core/Src/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions source/Core/Src/settingsGUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -162,6 +163,7 @@ static void displayAdvancedMenu(void);
* -Sleep Time
* -Shutdown Time
* Hall Sensor Sensitivity
* Hall Sensor Sleep Time
*
* UI
* Temperature Unit
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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); //
Expand Down
16 changes: 16 additions & 0 deletions source/Core/Threads/UI/logic/utils/getHallEffectSleepTimeout.cpp
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion source/Core/Threads/UI/logic/utils/shouldDeviceSleep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool shouldBeSleeping() {
if (lastHallEffectSleepStart == 0) {
lastHallEffectSleepStart = xTaskGetTickCount();
}
if ((xTaskGetTickCount() - lastHallEffectSleepStart) > TICKS_SECOND) {
if ((xTaskGetTickCount() - lastHallEffectSleepStart) > getHallEffectSleepTimeout()) {
return true;
}
} else {
Expand Down
Loading