Added slider to settings gui for adjusting wake up

sensitivity.
This commit is contained in:
JustMe-NL 2024-04-19 17:36:14 +02:00
parent 84e8895102
commit d1f3a4592f
8 changed files with 58 additions and 4 deletions

View file

@ -19,6 +19,7 @@ void init_preferences_HAL(void) {
// from here
currentScene = std::string(preferences.getString("currentScene").c_str());
currentGUIname = std::string(preferences.getString("currentGUIname").c_str());
set_wakeupByIMUthreshold_HAL(preferences.getUChar("threshold"));
// Serial.printf("Preferences restored: brightness %d, GUI %s, scene %s\r\n", get_backlightBrightness_HAL(), get_currentGUIname().c_str(), get_currentScene().c_str());
} else {
@ -37,6 +38,8 @@ void save_preferences_HAL(void) {
// from here
preferences.putString("currentScene", currentScene.c_str());
preferences.putString("currentGUIname", currentGUIname.c_str());
preferences.putUChar("threshold", get_wakeupByIMUthreshold_HAL());
if (!preferences.getBool("alreadySetUp")) {
preferences.putBool("alreadySetUp", true);
}

View file

@ -26,10 +26,19 @@ bool wakeupByIMUEnabled = true;
uint32_t sleepTimeout;
// Timestamp of the last activity. Go to sleep if (millis() - lastActivityTimestamp > sleepTimeout)
uint32_t lastActivityTimestamp;
char wakeupByIMUthreshold;
LIS3DH IMU(I2C_MODE, 0x19);
Wakeup_reasons wakeup_reason;
char get_wakeupByIMUthreshold_HAL() {
return wakeupByIMUthreshold;
}
void set_wakeupByIMUthreshold_HAL(char awakeupByIMUthreshold) {
if (awakeupByIMUthreshold > 0x7F) awakeupByIMUthreshold = 0x7F;
wakeupByIMUthreshold = awakeupByIMUthreshold;
}
void setLastActivityTimestamp_HAL() {
// There was motion, touchpad or key hit.
// Set the time where this happens.
@ -85,7 +94,7 @@ void configIMUInterruptsBeforeGoingToSleep()
//LIS3DH_INT1_THS
dataToWrite = 0;
//Provide 7 bit value, 0x7F always equals max range by accelRange setting
dataToWrite |= 0x45;
dataToWrite |= (0x7F - get_wakeupByIMUthreshold_HAL());
IMU.writeRegister(LIS3DH_INT1_THS, dataToWrite);
//LIS3DH_INT1_DURATION

View file

@ -19,3 +19,5 @@ uint32_t get_sleepTimeout_HAL();
void set_sleepTimeout_HAL(uint32_t aSleepTimeout);
bool get_wakeupByIMUEnabled_HAL();
void set_wakeupByIMUEnabled_HAL(bool aWakeupByIMUEnabled);
char get_wakeupByIMUthreshold_HAL();
void set_wakeupByIMUthreshold_HAL(char awakeupByIMUthreshold);

View file

@ -5,6 +5,7 @@
bool wakeupByIMUEnabled = true;
// timeout before going to sleep
uint32_t sleepTimeout;
char wakeupByIMUthreshold;
void init_sleep_HAL() {}
void init_IMU_HAL(void) {}
@ -25,3 +26,10 @@ void set_wakeupByIMUEnabled_HAL(bool aWakeupByIMUEnabled) {
wakeupByIMUEnabled = aWakeupByIMUEnabled;
printf("lift to wake set to %d\r\n", aWakeupByIMUEnabled);
}
char get_wakeupByIMUthreshold_HAL() {
return wakeupByIMUthreshold;
}
void set_wakeupByIMUthreshold_HAL(char awakeupByIMUthreshold) {
if (awakeupByIMUthreshold > 0x7F) awakeupByIMUthreshold = 0x7F;
wakeupByIMUthreshold = awakeupByIMUthreshold;
}

View file

@ -9,3 +9,5 @@ uint32_t get_sleepTimeout_HAL();
void set_sleepTimeout_HAL(uint32_t aSleepTimeout);
bool get_wakeupByIMUEnabled_HAL();
void set_wakeupByIMUEnabled_HAL(bool aWakeupByIMUEnabled);
char get_wakeupByIMUthreshold_HAL();
void set_wakeupByIMUthreshold_HAL(char awakeupByIMUthreshold);

View file

@ -80,6 +80,12 @@ bool get_wakeupByIMUEnabled() {
void set_wakeupByIMUEnabled(bool aWakeupByIMUEnabled) {
set_wakeupByIMUEnabled_HAL(aWakeupByIMUEnabled);
}
char get_wakeupByIMUthreshold() {
return get_wakeupByIMUthreshold_HAL();
}
void set_wakeupByIMUthreshold(char awakeupByIMUthreshold) {
set_wakeupByIMUthreshold_HAL(awakeupByIMUthreshold);
}
// --- keypad -----------------------------------------------------------------
void init_keys(void) {

View file

@ -32,6 +32,8 @@ uint32_t get_sleepTimeout();
void set_sleepTimeout(uint32_t aSleepTimeout);
bool get_wakeupByIMUEnabled();
void set_wakeupByIMUEnabled(bool aWakeupByIMUEnabled);
char get_wakeupByIMUthreshold();
void set_wakeupByIMUthreshold(char awakeupByIMUthreshold);
// --- keypad -----------------------------------------------------------------
void init_keys(void);

View file

@ -22,6 +22,14 @@ static void bl_slider_event_cb(lv_event_t* e){
set_backlightBrightness(slider_value);
}
static void th_slider_event_cb(lv_event_t* e){
lv_obj_t* slider = lv_event_get_target(e);
int32_t slider_value = lv_slider_get_value(slider);
if (slider_value < 0) {slider_value = 0;}
if (slider_value > 127) {slider_value = 127;}
set_wakeupByIMUthreshold((char) slider_value);
}
// Wakeup by IMU Switch Event handler
static void WakeEnableSetting_event_cb(lv_event_t* e){
set_wakeupByIMUEnabled(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED));
@ -64,7 +72,7 @@ void create_tab_content_settings(lv_obj_t* tab) {
lv_label_set_text(menuLabel, "Display");
lv_obj_t* menuBox = lv_obj_create(tab);
lv_obj_set_size(menuBox, lv_pct(100), 109);
lv_obj_set_size(menuBox, lv_pct(100), 160);
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN);
@ -135,6 +143,20 @@ void create_tab_content_settings(lv_obj_t* tab) {
lv_obj_set_style_border_color(lv_dropdown_get_list(drop), lv_color_hex(0x505050), LV_PART_MAIN);
lv_obj_add_event_cb(drop, timout_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
// Add text & slider for sensitivity setting
menuLabel = lv_label_create(menuBox);
lv_label_set_text(menuLabel, "Wake up sensitivity");
lv_obj_align(menuLabel, LV_ALIGN_TOP_LEFT, 0, 94);
lv_obj_t *thslider = lv_slider_create(menuBox);
lv_slider_set_range(thslider, 0, 127);
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_color(thslider, lv_color_lighten(color_primary, 50), LV_PART_MAIN);
lv_slider_set_value(thslider, get_wakeupByIMUthreshold(), LV_ANIM_OFF);
lv_obj_set_size(thslider, lv_pct(90), 10);
lv_obj_align(thslider, LV_ALIGN_TOP_LEFT, 10, 124);
lv_obj_add_event_cb(thslider, th_slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
// // Add another label, then a settings box for WiFi
// menuLabel = lv_label_create(tab);
// lv_label_set_text(menuLabel, "Wi-Fi");