Fix reverse threshold values

Sliders only support ranges from min to max but the slider visual and the setting to the IMU are reversed.
At the IMU we therefore store 0x7F, which is the maximum possible value, minus the slider value:
0x7F-0x3A = 0x45. So if the minimum IMU value is practically 0x40, the maximum slider value shuld be 0x3F.
We use a non signed variable so we only need to do a sanitycheck on the maximum slider value of 0x3F.
This commit is contained in:
JustMe-NL 2024-04-27 13:46:36 +02:00
parent b5d7a51d0a
commit caa4235c75
3 changed files with 3 additions and 4 deletions

View File

@ -19,7 +19,7 @@ void init_preferences_HAL(void) {
// from here // from here
currentScene = std::string(preferences.getString("currentScene").c_str()); currentScene = std::string(preferences.getString("currentScene").c_str());
currentGUIname = std::string(preferences.getString("currentGUIname").c_str()); currentGUIname = std::string(preferences.getString("currentGUIname").c_str());
set_wakeupByIMUthreshold_HAL(preferences.getUChar("threshold", 0x45)); set_wakeupByIMUthreshold_HAL(preferences.getUChar("threshold", 0x3A));
// Serial.printf("Preferences restored: brightness %d, GUI %s, scene %s\r\n", get_backlightBrightness_HAL(), get_currentGUIname().c_str(), get_currentScene().c_str()); // Serial.printf("Preferences restored: brightness %d, GUI %s, scene %s\r\n", get_backlightBrightness_HAL(), get_currentGUIname().c_str(), get_currentScene().c_str());
} else { } else {

View File

@ -35,8 +35,7 @@ char get_wakeupByIMUthreshold_HAL() {
return wakeupByIMUthreshold; return wakeupByIMUthreshold;
} }
void set_wakeupByIMUthreshold_HAL(char awakeupByIMUthreshold) { void set_wakeupByIMUthreshold_HAL(char awakeupByIMUthreshold) {
if (awakeupByIMUthreshold > 0x7F) awakeupByIMUthreshold = 0x7F; if (awakeupByIMUthreshold > 0x3F) awakeupByIMUthreshold = 0x3F;
if (awakeupByIMUthreshold < 0x40) awakeupByIMUthreshold = 0x40;
wakeupByIMUthreshold = awakeupByIMUthreshold; wakeupByIMUthreshold = awakeupByIMUthreshold;
} }

View File

@ -148,7 +148,7 @@ void create_tab_content_settings(lv_obj_t* tab) {
lv_label_set_text(menuLabel, "Wake up sensitivity"); lv_label_set_text(menuLabel, "Wake up sensitivity");
lv_obj_align(menuLabel, LV_ALIGN_TOP_LEFT, 0, 94); lv_obj_align(menuLabel, LV_ALIGN_TOP_LEFT, 0, 94);
lv_obj_t *thslider = lv_slider_create(menuBox); lv_obj_t *thslider = lv_slider_create(menuBox);
lv_slider_set_range(thslider, 0x40, 0x7F); lv_slider_set_range(thslider, 0, 0x3F);
lv_obj_set_style_bg_color(thslider, lv_color_white(), LV_PART_KNOB); lv_obj_set_style_bg_color(thslider, lv_color_white(), LV_PART_KNOB);
lv_obj_set_style_bg_opa(thslider, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_bg_opa(thslider, LV_OPA_COVER, LV_PART_MAIN);
lv_obj_set_style_bg_color(thslider, lv_color_lighten(color_primary, 50), LV_PART_MAIN); lv_obj_set_style_bg_color(thslider, lv_color_lighten(color_primary, 50), LV_PART_MAIN);