setting timout via GUI now works, not only dropdown without functionality
This commit is contained in:
parent
2fda106f4e
commit
581015e9a9
8 changed files with 74 additions and 29 deletions
|
@ -57,7 +57,7 @@ void my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data){
|
||||||
bool touched = false;
|
bool touched = false;
|
||||||
if ((touchX > 0) || (touchY > 0)) {
|
if ((touchX > 0) || (touchY > 0)) {
|
||||||
touched = true;
|
touched = true;
|
||||||
standbyTimer = SLEEP_TIMEOUT;
|
resetStandbyTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !touched ){
|
if( !touched ){
|
||||||
|
|
|
@ -44,7 +44,7 @@ void printReceivedMessages(bool clearMessages = false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void showNewIRmessage(String message) {
|
void showNewIRmessage(String message) {
|
||||||
standbyTimer = SLEEP_TIMEOUT; // Reset the sleep timer when a IR message is received
|
resetStandbyTimer(); // Reset the sleep timer when a IR message is received
|
||||||
|
|
||||||
// Serial.printf(" new IR message received: %s\r\n", message.c_str());
|
// Serial.printf(" new IR message received: %s\r\n", message.c_str());
|
||||||
// const char *a = message.c_str();
|
// const char *a = message.c_str();
|
||||||
|
|
|
@ -19,6 +19,23 @@ static void WakeEnableSetting_event_cb(lv_event_t * e){
|
||||||
wakeupByIMUEnabled = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
|
wakeupByIMUEnabled = lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// timout event handler
|
||||||
|
static void timout_event_cb(lv_event_t * e){
|
||||||
|
lv_obj_t * drop = lv_event_get_target(e);
|
||||||
|
uint16_t selected = lv_dropdown_get_selected(drop);
|
||||||
|
switch (selected) {
|
||||||
|
case 0: {actualSleepTimeout = 10000; break;}
|
||||||
|
case 1: {actualSleepTimeout = 20000; break;}
|
||||||
|
case 2: {actualSleepTimeout = 40000; break;}
|
||||||
|
case 3: {actualSleepTimeout = 60000; break;}
|
||||||
|
case 4: {actualSleepTimeout = 180000; break;}
|
||||||
|
case 5: {actualSleepTimeout = 600000; break;}
|
||||||
|
case 6: {actualSleepTimeout = 3600000; break;}
|
||||||
|
}
|
||||||
|
// Serial.printf("New timeout: %lu ms\r\n", actualSleepTimeout);
|
||||||
|
resetStandbyTimer();
|
||||||
|
}
|
||||||
|
|
||||||
void init_gui_settings(lv_obj_t* tabview) {
|
void init_gui_settings(lv_obj_t* tabview) {
|
||||||
|
|
||||||
lv_obj_t* tab = lv_tabview_add_tab(tabview, "Settings");
|
lv_obj_t* tab = lv_tabview_add_tab(tabview, "Settings");
|
||||||
|
@ -35,7 +52,7 @@ void init_gui_settings(lv_obj_t* tabview) {
|
||||||
lv_label_set_text(menuLabel, "Display");
|
lv_label_set_text(menuLabel, "Display");
|
||||||
|
|
||||||
lv_obj_t* menuBox = lv_obj_create(tab);
|
lv_obj_t* menuBox = lv_obj_create(tab);
|
||||||
lv_obj_set_size(menuBox, lv_pct(100), 77); // 109, 32 weniger wegen fehlendem Timeout
|
lv_obj_set_size(menuBox, lv_pct(100), 109);
|
||||||
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
|
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
|
||||||
lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN);
|
lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN);
|
||||||
|
|
||||||
|
@ -69,23 +86,38 @@ void init_gui_settings(lv_obj_t* tabview) {
|
||||||
lv_obj_add_event_cb(wakeToggle, WakeEnableSetting_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
lv_obj_add_event_cb(wakeToggle, WakeEnableSetting_event_cb, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
if(wakeupByIMUEnabled) lv_obj_add_state(wakeToggle, LV_STATE_CHECKED); // set default state
|
if(wakeupByIMUEnabled) lv_obj_add_state(wakeToggle, LV_STATE_CHECKED); // set default state
|
||||||
|
|
||||||
// menuLabel = lv_label_create(menuBox);
|
menuLabel = lv_label_create(menuBox);
|
||||||
// lv_label_set_text(menuLabel, "Timeout");
|
lv_label_set_text(menuLabel, "Timeout");
|
||||||
// lv_obj_align(menuLabel, LV_ALIGN_TOP_LEFT, 0, 64);
|
lv_obj_align(menuLabel, LV_ALIGN_TOP_LEFT, 0, 64);
|
||||||
// lv_obj_t* drop = lv_dropdown_create(menuBox);
|
lv_obj_t* drop = lv_dropdown_create(menuBox);
|
||||||
// lv_dropdown_set_options(drop, "10s\n"
|
lv_dropdown_set_options(drop, "10s\n"
|
||||||
// "30s\n"
|
"20s\n"
|
||||||
// "1m\n"
|
"40s\n"
|
||||||
// "3m");
|
"1m\n"
|
||||||
// lv_obj_align(drop, LV_ALIGN_TOP_RIGHT, 0, 61);
|
"3m\n"
|
||||||
// lv_obj_set_size(drop, 70, 22);
|
"10m\n"
|
||||||
// //lv_obj_set_style_text_font(drop, &lv_font_montserrat_12, LV_PART_MAIN);
|
"1h"); // 1h for debug purposes, if you don't want the device to go to slepp
|
||||||
// //lv_obj_set_style_text_font(lv_dropdown_get_list(drop), &lv_font_montserrat_12, LV_PART_MAIN);
|
// if you add more options here, do the same in timout_event_cb()
|
||||||
// lv_obj_set_style_pad_top(drop, 1, LV_PART_MAIN);
|
switch (actualSleepTimeout) {
|
||||||
// lv_obj_set_style_bg_color(drop, color_primary, LV_PART_MAIN);
|
case 10000: {lv_dropdown_set_selected(drop, 0); break;}
|
||||||
// lv_obj_set_style_bg_color(lv_dropdown_get_list(drop), color_primary, LV_PART_MAIN);
|
case 20000: {lv_dropdown_set_selected(drop, 1); break;}
|
||||||
// lv_obj_set_style_border_width(lv_dropdown_get_list(drop), 1, LV_PART_MAIN);
|
case 40000: {lv_dropdown_set_selected(drop, 2); break;}
|
||||||
// lv_obj_set_style_border_color(lv_dropdown_get_list(drop), lv_color_hex(0x505050), LV_PART_MAIN);
|
case 60000: {lv_dropdown_set_selected(drop, 3); break;}
|
||||||
|
case 180000: {lv_dropdown_set_selected(drop, 4); break;}
|
||||||
|
case 600000: {lv_dropdown_set_selected(drop, 5); break;}
|
||||||
|
case 3600000: {lv_dropdown_set_selected(drop, 6); break;}
|
||||||
|
}
|
||||||
|
lv_dropdown_set_selected_highlight(drop, true);
|
||||||
|
lv_obj_align(drop, LV_ALIGN_TOP_RIGHT, 0, 61);
|
||||||
|
lv_obj_set_size(drop, 70, 22);
|
||||||
|
//lv_obj_set_style_text_font(drop, &lv_font_montserrat_12, LV_PART_MAIN);
|
||||||
|
//lv_obj_set_style_text_font(lv_dropdown_get_list(drop), &lv_font_montserrat_12, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_pad_top(drop, 1, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_color(drop, color_primary, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_bg_color(lv_dropdown_get_list(drop), color_primary, LV_PART_MAIN);
|
||||||
|
lv_obj_set_style_border_width(lv_dropdown_get_list(drop), 1, LV_PART_MAIN);
|
||||||
|
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 another label, then a settings box for WiFi
|
// // Add another label, then a settings box for WiFi
|
||||||
// menuLabel = lv_label_create(tab);
|
// menuLabel = lv_label_create(tab);
|
||||||
|
|
|
@ -154,7 +154,7 @@ void keypad_loop(void) {
|
||||||
// we are not allowed to do this, because of the same reason as above
|
// we are not allowed to do this, because of the same reason as above
|
||||||
// continue;
|
// continue;
|
||||||
} else {
|
} else {
|
||||||
standbyTimer = SLEEP_TIMEOUT; // Reset the sleep timer when a button is pressed
|
resetStandbyTimer(); // Reset the sleep timer when a button is pressed
|
||||||
}
|
}
|
||||||
char keyChar = customKeypad.key[i].kchar;
|
char keyChar = customKeypad.key[i].kchar;
|
||||||
int keyCode = customKeypad.key[i].kcode;
|
int keyCode = customKeypad.key[i].kcode;
|
||||||
|
|
|
@ -25,6 +25,9 @@ void setup() {
|
||||||
// --- Startup ---
|
// --- Startup ---
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
|
// Restore settings from internal flash memory
|
||||||
|
init_preferences();
|
||||||
|
|
||||||
// Button Pin Definition
|
// Button Pin Definition
|
||||||
init_keys();
|
init_keys();
|
||||||
|
|
||||||
|
@ -38,9 +41,6 @@ void setup() {
|
||||||
// init TFT
|
// init TFT
|
||||||
init_tft();
|
init_tft();
|
||||||
|
|
||||||
// Restore settings from internal flash memory
|
|
||||||
init_preferences();
|
|
||||||
|
|
||||||
// init GUI
|
// init GUI
|
||||||
init_gui();
|
init_gui();
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@ void init_preferences(void) {
|
||||||
preferences.begin("settings", false);
|
preferences.begin("settings", false);
|
||||||
if(preferences.getBool("alreadySetUp")){
|
if(preferences.getBool("alreadySetUp")){
|
||||||
wakeupByIMUEnabled = preferences.getBool("wkpByIMU");
|
wakeupByIMUEnabled = preferences.getBool("wkpByIMU");
|
||||||
|
actualSleepTimeout = preferences.getUInt("slpTimeout");
|
||||||
backlight_brightness = preferences.getUChar("blBrightness");
|
backlight_brightness = preferences.getUChar("blBrightness");
|
||||||
currentScreen = preferences.getUChar("currentScreen");
|
currentScreen = preferences.getUChar("currentScreen");
|
||||||
allDevsPowered = preferences.getUChar("allDevsPowered");
|
allDevsPowered = preferences.getUChar("allDevsPowered");
|
||||||
|
|
|
@ -14,11 +14,16 @@
|
||||||
#include "device_keyboard_ble.h"
|
#include "device_keyboard_ble.h"
|
||||||
|
|
||||||
int motion = 0;
|
int motion = 0;
|
||||||
int standbyTimer = SLEEP_TIMEOUT;
|
uint32_t actualSleepTimeout;
|
||||||
|
uint32_t standbyTimer;
|
||||||
bool wakeupByIMUEnabled = true;
|
bool wakeupByIMUEnabled = true;
|
||||||
LIS3DH IMU(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19.
|
LIS3DH IMU(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19.
|
||||||
byte wakeup_reason;
|
byte wakeup_reason;
|
||||||
|
|
||||||
|
void resetStandbyTimer() {
|
||||||
|
standbyTimer = actualSleepTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
void activityDetection(){
|
void activityDetection(){
|
||||||
static int accXold;
|
static int accXold;
|
||||||
static int accYold;
|
static int accYold;
|
||||||
|
@ -33,7 +38,7 @@ void activityDetection(){
|
||||||
standbyTimer -= 100;
|
standbyTimer -= 100;
|
||||||
if(standbyTimer < 0) standbyTimer = 0;
|
if(standbyTimer < 0) standbyTimer = 0;
|
||||||
// If the motion exceeds the threshold, the standbyTimer is reset
|
// If the motion exceeds the threshold, the standbyTimer is reset
|
||||||
if(motion > MOTION_THRESHOLD) standbyTimer = SLEEP_TIMEOUT;
|
if(motion > MOTION_THRESHOLD) resetStandbyTimer();
|
||||||
|
|
||||||
// Store the current acceleration and time
|
// Store the current acceleration and time
|
||||||
accXold = accX;
|
accXold = accX;
|
||||||
|
@ -97,6 +102,7 @@ void configIMUInterrupts()
|
||||||
void enterSleep(){
|
void enterSleep(){
|
||||||
// Save settings to internal flash memory
|
// Save settings to internal flash memory
|
||||||
preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
|
preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
|
||||||
|
preferences.putUInt("slpTimeout", actualSleepTimeout);
|
||||||
preferences.putUChar("blBrightness", backlight_brightness);
|
preferences.putUChar("blBrightness", backlight_brightness);
|
||||||
preferences.putUChar("currentScreen", currentScreen);
|
preferences.putUChar("currentScreen", currentScreen);
|
||||||
preferences.putUChar("allDevsPowered", allDevsPowered);
|
preferences.putUChar("allDevsPowered", allDevsPowered);
|
||||||
|
@ -162,6 +168,10 @@ void enterSleep(){
|
||||||
}
|
}
|
||||||
|
|
||||||
void init_sleep() {
|
void init_sleep() {
|
||||||
|
if (actualSleepTimeout == 0){
|
||||||
|
actualSleepTimeout = DEFAULT_SLEEP_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
// Find out wakeup cause
|
// Find out wakeup cause
|
||||||
if(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_EXT1){
|
if(esp_sleep_get_wakeup_cause() == ESP_SLEEP_WAKEUP_EXT1){
|
||||||
if(log(esp_sleep_get_ext1_wakeup_status())/log(2) == 13) wakeup_reason = WAKEUP_BY_IMU;
|
if(log(esp_sleep_get_ext1_wakeup_status())/log(2) == 13) wakeup_reason = WAKEUP_BY_IMU;
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
#define ACC_INT 20
|
#define ACC_INT 20
|
||||||
|
|
||||||
// IMU declarations
|
// IMU declarations
|
||||||
#define SLEEP_TIMEOUT 20000 // time until device enters sleep mode in milliseconds
|
#define DEFAULT_SLEEP_TIMEOUT 20000 // time until device enters sleep mode in milliseconds
|
||||||
#define MOTION_THRESHOLD 50 // motion above threshold keeps device awake
|
extern uint32_t actualSleepTimeout;
|
||||||
extern int standbyTimer;
|
extern uint32_t standbyTimer;
|
||||||
extern bool wakeupByIMUEnabled;
|
extern bool wakeupByIMUEnabled;
|
||||||
|
#define MOTION_THRESHOLD 50 // motion above threshold keeps device awake
|
||||||
|
|
||||||
// Other declarations
|
// Other declarations
|
||||||
extern byte wakeup_reason;
|
extern byte wakeup_reason;
|
||||||
|
@ -22,5 +23,6 @@ void enterSleep();
|
||||||
void init_sleep();
|
void init_sleep();
|
||||||
void setup_IMU();
|
void setup_IMU();
|
||||||
void check_activity();
|
void check_activity();
|
||||||
|
void resetStandbyTimer();
|
||||||
|
|
||||||
#endif /*__SLEEP_H__*/
|
#endif /*__SLEEP_H__*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue