Fixing settings in the abstraction branch (#39)
* Fixing settings * updating the simulator
This commit is contained in:
parent
6a78c4cfa1
commit
59897369ec
|
@ -24,7 +24,16 @@ public:
|
||||||
virtual std::shared_ptr<BatteryInterface> battery() = 0;
|
virtual std::shared_ptr<BatteryInterface> battery() = 0;
|
||||||
virtual std::shared_ptr<DisplayAbstract> display() = 0;
|
virtual std::shared_ptr<DisplayAbstract> display() = 0;
|
||||||
virtual std::shared_ptr<wifiHandlerInterface> wifi() = 0;
|
virtual std::shared_ptr<wifiHandlerInterface> wifi() = 0;
|
||||||
|
|
||||||
|
virtual char getCurrentDevice() = 0;
|
||||||
|
virtual void setCurrentDevice(char currentDevice) = 0;
|
||||||
|
|
||||||
|
virtual bool getWakeupByIMUEnabled() = 0;
|
||||||
|
virtual void setWakeupByIMUEnabled(bool wakeupByIMUEnabled) = 0;
|
||||||
|
|
||||||
|
virtual uint16_t getSleepTimeout() = 0;
|
||||||
|
virtual void setSleepTimeout(uint16_t sleepTimeout) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
};
|
};
|
|
@ -78,7 +78,7 @@ void HardwareRevX::init() {
|
||||||
mWifiHandler = wifiHandler::getInstance();
|
mWifiHandler = wifiHandler::getInstance();
|
||||||
restorePreferences();
|
restorePreferences();
|
||||||
|
|
||||||
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;});
|
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = this->getSleepTimeout();});
|
||||||
|
|
||||||
setupIMU();
|
setupIMU();
|
||||||
setupIR();
|
setupIR();
|
||||||
|
@ -134,7 +134,7 @@ void HardwareRevX::activityDetection() {
|
||||||
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)
|
if (motion > MOTION_THRESHOLD)
|
||||||
standbyTimer = SLEEP_TIMEOUT;
|
standbyTimer = sleepTimeout;
|
||||||
|
|
||||||
// Store the current acceleration and time
|
// Store the current acceleration and time
|
||||||
accXold = accX;
|
accXold = accX;
|
||||||
|
@ -142,11 +142,37 @@ void HardwareRevX::activityDetection() {
|
||||||
accZold = accZ;
|
accZold = accZ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char HardwareRevX::getCurrentDevice(){
|
||||||
|
return currentDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareRevX::setCurrentDevice(char currentDevice){
|
||||||
|
this->currentDevice = currentDevice;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HardwareRevX::getWakeupByIMUEnabled(){
|
||||||
|
return wakeupByIMUEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareRevX::setWakeupByIMUEnabled(bool wakeupByIMUEnabled){
|
||||||
|
this->wakeupByIMUEnabled = wakeupByIMUEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t HardwareRevX::getSleepTimeout(){
|
||||||
|
return sleepTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareRevX::setSleepTimeout(uint16_t sleepTimeout){
|
||||||
|
this->sleepTimeout = sleepTimeout;
|
||||||
|
standbyTimer = sleepTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
void HardwareRevX::enterSleep() {
|
void HardwareRevX::enterSleep() {
|
||||||
// Save settings to internal flash memory
|
// Save settings to internal flash memory
|
||||||
preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
|
preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
|
||||||
preferences.putUChar("blBrightness", mDisplay->getBrightness());
|
preferences.putUChar("blBrightness", mDisplay->getBrightness());
|
||||||
preferences.putUChar("currentDevice", currentDevice);
|
preferences.putUChar("currentDevice", currentDevice);
|
||||||
|
preferences.putUInt("sleepTimeout", sleepTimeout);
|
||||||
if (!preferences.getBool("alreadySetUp"))
|
if (!preferences.getBool("alreadySetUp"))
|
||||||
preferences.putBool("alreadySetUp", true);
|
preferences.putBool("alreadySetUp", true);
|
||||||
preferences.end();
|
preferences.end();
|
||||||
|
@ -259,6 +285,11 @@ void HardwareRevX::restorePreferences() {
|
||||||
wakeupByIMUEnabled = preferences.getBool("wkpByIMU");
|
wakeupByIMUEnabled = preferences.getBool("wkpByIMU");
|
||||||
backlight_brightness = preferences.getUChar("blBrightness");
|
backlight_brightness = preferences.getUChar("blBrightness");
|
||||||
currentDevice = preferences.getUChar("currentDevice");
|
currentDevice = preferences.getUChar("currentDevice");
|
||||||
|
sleepTimeout = preferences.getUInt("sleepTimeout");
|
||||||
|
// setting the default to prevent a 0ms sleep timeout
|
||||||
|
if(sleepTimeout == 0){
|
||||||
|
sleepTimeout = SLEEP_TIMEOUT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mDisplay->setBrightness(backlight_brightness);
|
mDisplay->setBrightness(backlight_brightness);
|
||||||
}
|
}
|
||||||
|
@ -312,7 +343,7 @@ void HardwareRevX::loopHandler() {
|
||||||
if (customKeypad.key[i].kstate == PRESSED ||
|
if (customKeypad.key[i].kstate == PRESSED ||
|
||||||
customKeypad.key[i].kstate == HOLD) {
|
customKeypad.key[i].kstate == HOLD) {
|
||||||
standbyTimer =
|
standbyTimer =
|
||||||
SLEEP_TIMEOUT; // Reset the sleep timer when a button is pressed
|
sleepTimeout; // Reset the sleep timer when a button is pressed
|
||||||
int keyCode = customKeypad.key[i].kcode;
|
int keyCode = customKeypad.key[i].kcode;
|
||||||
Serial.println(customKeypad.key[i].kchar);
|
Serial.println(customKeypad.key[i].kchar);
|
||||||
// Send IR codes depending on the current device (tabview page)
|
// Send IR codes depending on the current device (tabview page)
|
||||||
|
|
|
@ -36,7 +36,16 @@ public:
|
||||||
virtual std::shared_ptr<BatteryInterface> battery() override;
|
virtual std::shared_ptr<BatteryInterface> battery() override;
|
||||||
virtual std::shared_ptr<DisplayAbstract> display() override;
|
virtual std::shared_ptr<DisplayAbstract> display() override;
|
||||||
virtual std::shared_ptr<wifiHandlerInterface> wifi() override;
|
virtual std::shared_ptr<wifiHandlerInterface> wifi() override;
|
||||||
|
|
||||||
|
virtual char getCurrentDevice() override;
|
||||||
|
virtual void setCurrentDevice(char currentDevice) override;
|
||||||
|
|
||||||
|
virtual bool getWakeupByIMUEnabled() override;
|
||||||
|
virtual void setWakeupByIMUEnabled(bool wakeupByIMUEnabled) override;
|
||||||
|
|
||||||
|
virtual uint16_t getSleepTimeout() override;
|
||||||
|
virtual void setSleepTimeout(uint16_t sleepTimeout) override;
|
||||||
|
|
||||||
/// @brief To be ran in loop out in main
|
/// @brief To be ran in loop out in main
|
||||||
// TODO move to a freertos task
|
// TODO move to a freertos task
|
||||||
void loopHandler();
|
void loopHandler();
|
||||||
|
@ -64,6 +73,7 @@ private:
|
||||||
// IMU Motion Detection
|
// IMU Motion Detection
|
||||||
LIS3DH IMU = LIS3DH(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19.
|
LIS3DH IMU = LIS3DH(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19.
|
||||||
int standbyTimer = SLEEP_TIMEOUT;
|
int standbyTimer = SLEEP_TIMEOUT;
|
||||||
|
int sleepTimeout = SLEEP_TIMEOUT;
|
||||||
int motion = 0;
|
int motion = 0;
|
||||||
WakeReason wakeup_reason;
|
WakeReason wakeup_reason;
|
||||||
|
|
||||||
|
|
|
@ -45,4 +45,28 @@ std::shared_ptr<DisplayAbstract> HardwareSimulator::display(){
|
||||||
}
|
}
|
||||||
std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi(){
|
std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi(){
|
||||||
return mWifiHandler;
|
return mWifiHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char HardwareSimulator::getCurrentDevice(){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareSimulator::setCurrentDevice(char currentDevice){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HardwareSimulator::getWakeupByIMUEnabled(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareSimulator::setWakeupByIMUEnabled(bool wakeupByIMUEnabled){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t HardwareSimulator::getSleepTimeout(){
|
||||||
|
return 20000;
|
||||||
|
}
|
||||||
|
|
||||||
|
void HardwareSimulator::setSleepTimeout(uint16_t sleepTimeout){
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
@ -24,6 +24,15 @@ public:
|
||||||
virtual std::shared_ptr<DisplayAbstract> display() override;
|
virtual std::shared_ptr<DisplayAbstract> display() override;
|
||||||
virtual std::shared_ptr<wifiHandlerInterface> wifi() override;
|
virtual std::shared_ptr<wifiHandlerInterface> wifi() override;
|
||||||
|
|
||||||
|
virtual char getCurrentDevice() override;
|
||||||
|
virtual void setCurrentDevice(char currentDevice) override;
|
||||||
|
|
||||||
|
virtual bool getWakeupByIMUEnabled() override;
|
||||||
|
virtual void setWakeupByIMUEnabled(bool wakeupByIMUEnabled) override;
|
||||||
|
|
||||||
|
virtual uint16_t getSleepTimeout() override;
|
||||||
|
virtual void setSleepTimeout(uint16_t sleepTimeout) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::thread mTickThread;
|
std::thread mTickThread;
|
||||||
std::thread mHardwareStatusTitleUpdate;
|
std::thread mHardwareStatusTitleUpdate;
|
||||||
|
|
|
@ -24,6 +24,7 @@ void OmoteUI::store_scroll_value_event_cb(lv_event_t *e) {
|
||||||
// Update current device when the tabview page is changes
|
// Update current device when the tabview page is changes
|
||||||
void OmoteUI::tabview_device_event_cb(lv_event_t *e) {
|
void OmoteUI::tabview_device_event_cb(lv_event_t *e) {
|
||||||
currentDevice = lv_tabview_get_tab_act(lv_event_get_target(e));
|
currentDevice = lv_tabview_get_tab_act(lv_event_get_target(e));
|
||||||
|
this->mHardware->setCurrentDevice(currentDevice);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Slider Event handler
|
// Slider Event handler
|
||||||
|
@ -41,8 +42,15 @@ void OmoteUI::appleKey_event_cb(lv_event_t *e) {
|
||||||
|
|
||||||
// Wakeup by IMU Switch Event handler
|
// Wakeup by IMU Switch Event handler
|
||||||
void OmoteUI::WakeEnableSetting_event_cb(lv_event_t *e) {
|
void OmoteUI::WakeEnableSetting_event_cb(lv_event_t *e) {
|
||||||
wakeupByIMUEnabled =
|
this->mHardware->setWakeupByIMUEnabled(lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED));
|
||||||
lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
|
}
|
||||||
|
|
||||||
|
// Wakeup timeout dropdown Event handler
|
||||||
|
void OmoteUI::wakeTimeoutSetting_event_cb(lv_event_t *e){
|
||||||
|
lv_obj_t * drop = lv_event_get_target(e);
|
||||||
|
|
||||||
|
int sleepTimeout = sleepTimeoutMap[lv_dropdown_get_selected(drop)];
|
||||||
|
mHardware->setSleepTimeout(sleepTimeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Smart Home Toggle Event handler
|
// Smart Home Toggle Event handler
|
||||||
|
@ -391,7 +399,8 @@ void OmoteUI::layout_UI() {
|
||||||
|
|
||||||
|
|
||||||
// Set current page according to the current Device
|
// Set current page according to the current Device
|
||||||
lv_tabview_set_act(tabview, 0, LV_ANIM_OFF);
|
currentDevice = this->mHardware->getCurrentDevice();
|
||||||
|
lv_tabview_set_act(tabview, currentDevice, LV_ANIM_OFF);
|
||||||
|
|
||||||
|
|
||||||
// Create a page indicator
|
// Create a page indicator
|
||||||
|
|
|
@ -33,6 +33,8 @@ public:
|
||||||
void store_scroll_value_event_cb(lv_event_t *e);
|
void store_scroll_value_event_cb(lv_event_t *e);
|
||||||
// Update current device when the tabview page is changes
|
// Update current device when the tabview page is changes
|
||||||
void tabview_device_event_cb(lv_event_t *e);
|
void tabview_device_event_cb(lv_event_t *e);
|
||||||
|
// Update wake timeout handler
|
||||||
|
void wakeTimeoutSetting_event_cb(lv_event_t *e);
|
||||||
// Slider Event handler
|
// Slider Event handler
|
||||||
void bl_slider_event_cb(lv_event_t *e);
|
void bl_slider_event_cb(lv_event_t *e);
|
||||||
// Apple Key Event handler
|
// Apple Key Event handler
|
||||||
|
@ -78,6 +80,8 @@ private:
|
||||||
|
|
||||||
std::unique_ptr<poller> batteryPoller;
|
std::unique_ptr<poller> batteryPoller;
|
||||||
|
|
||||||
|
int sleepTimeoutMap[5] = {10000,30000,60000,180000,600000};
|
||||||
|
|
||||||
void reset_settings_menu();
|
void reset_settings_menu();
|
||||||
void attach_keyboard(lv_obj_t* textarea);
|
void attach_keyboard(lv_obj_t* textarea);
|
||||||
std::shared_ptr<std::vector<WifiInfo>> found_wifi_networks;
|
std::shared_ptr<std::vector<WifiInfo>> found_wifi_networks;
|
||||||
|
@ -130,7 +134,6 @@ void create_keyboard();
|
||||||
Images imgs = Images();
|
Images imgs = Images();
|
||||||
uint_fast8_t currentDevice = 4;
|
uint_fast8_t currentDevice = 4;
|
||||||
lv_color_t color_primary = lv_color_hex(0x303030); // gray
|
lv_color_t color_primary = lv_color_hex(0x303030); // gray
|
||||||
bool wakeupByIMUEnabled = true;
|
|
||||||
|
|
||||||
inline static const uint_fast8_t virtualKeyMapTechnisat[10] = {
|
inline static const uint_fast8_t virtualKeyMapTechnisat[10] = {
|
||||||
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0};
|
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0};
|
||||||
|
|
|
@ -33,7 +33,7 @@ void OmoteUI::display_settings(lv_obj_t* parent)
|
||||||
lv_obj_align(wakeToggle, LV_ALIGN_TOP_RIGHT, 0, 29);
|
lv_obj_align(wakeToggle, LV_ALIGN_TOP_RIGHT, 0, 29);
|
||||||
lv_obj_set_style_bg_color(wakeToggle, lv_color_hex(0x505050), LV_PART_MAIN);
|
lv_obj_set_style_bg_color(wakeToggle, lv_color_hex(0x505050), LV_PART_MAIN);
|
||||||
lv_obj_add_event_cb(wakeToggle, [] (lv_event_t* e) {mInstance->WakeEnableSetting_event_cb(e);}, LV_EVENT_VALUE_CHANGED, NULL);
|
lv_obj_add_event_cb(wakeToggle, [] (lv_event_t* e) {mInstance->WakeEnableSetting_event_cb(e);}, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
if(wakeupByIMUEnabled) lv_obj_add_state(wakeToggle, LV_STATE_CHECKED); // set default state
|
if(mHardware->getWakeupByIMUEnabled()) 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");
|
||||||
|
@ -52,5 +52,10 @@ void OmoteUI::display_settings(lv_obj_t* parent)
|
||||||
lv_obj_set_style_bg_color(lv_dropdown_get_list(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_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_set_style_border_color(lv_dropdown_get_list(drop), lv_color_hex(0x505050), LV_PART_MAIN);
|
||||||
|
int sleepTimeoutMapSize = sizeof(sleepTimeoutMap)/sizeof(sleepTimeoutMap[0]);
|
||||||
|
int currentTimeout = mHardware->getSleepTimeout();
|
||||||
|
for(int i = 0; i < sleepTimeoutMapSize; i++){
|
||||||
|
if(currentTimeout == sleepTimeoutMap[i]) lv_dropdown_set_selected(drop, i);
|
||||||
|
}
|
||||||
|
lv_obj_add_event_cb(drop, [] (lv_event_t* e) {mInstance->wakeTimeoutSetting_event_cb(e);}, LV_EVENT_VALUE_CHANGED, NULL);
|
||||||
}
|
}
|
Loading…
Reference in New Issue