Fixing settings in the abstraction branch (#39)

* Fixing settings

* updating the simulator
This commit is contained in:
Paul Hortiatis 2023-09-17 06:14:39 -04:00 committed by GitHub
parent 6a78c4cfa1
commit 59897369ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 10 deletions

View File

@ -24,7 +24,16 @@ public:
virtual std::shared_ptr<BatteryInterface> battery() = 0;
virtual std::shared_ptr<DisplayAbstract> display() = 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:
};

View File

@ -78,7 +78,7 @@ void HardwareRevX::init() {
mWifiHandler = wifiHandler::getInstance();
restorePreferences();
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = SLEEP_TIMEOUT;});
mDisplay->onTouch([this]([[maybe_unused]] auto touchPoint){ standbyTimer = this->getSleepTimeout();});
setupIMU();
setupIR();
@ -134,7 +134,7 @@ void HardwareRevX::activityDetection() {
standbyTimer = 0;
// If the motion exceeds the threshold, the standbyTimer is reset
if (motion > MOTION_THRESHOLD)
standbyTimer = SLEEP_TIMEOUT;
standbyTimer = sleepTimeout;
// Store the current acceleration and time
accXold = accX;
@ -142,11 +142,37 @@ void HardwareRevX::activityDetection() {
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() {
// Save settings to internal flash memory
preferences.putBool("wkpByIMU", wakeupByIMUEnabled);
preferences.putUChar("blBrightness", mDisplay->getBrightness());
preferences.putUChar("currentDevice", currentDevice);
preferences.putUInt("sleepTimeout", sleepTimeout);
if (!preferences.getBool("alreadySetUp"))
preferences.putBool("alreadySetUp", true);
preferences.end();
@ -259,6 +285,11 @@ void HardwareRevX::restorePreferences() {
wakeupByIMUEnabled = preferences.getBool("wkpByIMU");
backlight_brightness = preferences.getUChar("blBrightness");
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);
}
@ -312,7 +343,7 @@ void HardwareRevX::loopHandler() {
if (customKeypad.key[i].kstate == PRESSED ||
customKeypad.key[i].kstate == HOLD) {
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;
Serial.println(customKeypad.key[i].kchar);
// Send IR codes depending on the current device (tabview page)

View File

@ -36,7 +36,16 @@ public:
virtual std::shared_ptr<BatteryInterface> battery() override;
virtual std::shared_ptr<DisplayAbstract> display() 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
// TODO move to a freertos task
void loopHandler();
@ -64,6 +73,7 @@ private:
// IMU Motion Detection
LIS3DH IMU = LIS3DH(I2C_MODE, 0x19); // Default constructor is I2C, addr 0x19.
int standbyTimer = SLEEP_TIMEOUT;
int sleepTimeout = SLEEP_TIMEOUT;
int motion = 0;
WakeReason wakeup_reason;

View File

@ -45,4 +45,28 @@ std::shared_ptr<DisplayAbstract> HardwareSimulator::display(){
}
std::shared_ptr<wifiHandlerInterface> HardwareSimulator::wifi(){
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){
}

View File

@ -24,6 +24,15 @@ public:
virtual std::shared_ptr<DisplayAbstract> display() 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:
std::thread mTickThread;
std::thread mHardwareStatusTitleUpdate;

View File

@ -24,6 +24,7 @@ void OmoteUI::store_scroll_value_event_cb(lv_event_t *e) {
// Update current device when the tabview page is changes
void OmoteUI::tabview_device_event_cb(lv_event_t *e) {
currentDevice = lv_tabview_get_tab_act(lv_event_get_target(e));
this->mHardware->setCurrentDevice(currentDevice);
}
// Slider Event handler
@ -41,8 +42,15 @@ void OmoteUI::appleKey_event_cb(lv_event_t *e) {
// Wakeup by IMU Switch Event handler
void OmoteUI::WakeEnableSetting_event_cb(lv_event_t *e) {
wakeupByIMUEnabled =
lv_obj_has_state(lv_event_get_target(e), LV_STATE_CHECKED);
this->mHardware->setWakeupByIMUEnabled(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
@ -391,7 +399,8 @@ void OmoteUI::layout_UI() {
// 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

View File

@ -33,6 +33,8 @@ public:
void store_scroll_value_event_cb(lv_event_t *e);
// Update current device when the tabview page is changes
void tabview_device_event_cb(lv_event_t *e);
// Update wake timeout handler
void wakeTimeoutSetting_event_cb(lv_event_t *e);
// Slider Event handler
void bl_slider_event_cb(lv_event_t *e);
// Apple Key Event handler
@ -78,6 +80,8 @@ private:
std::unique_ptr<poller> batteryPoller;
int sleepTimeoutMap[5] = {10000,30000,60000,180000,600000};
void reset_settings_menu();
void attach_keyboard(lv_obj_t* textarea);
std::shared_ptr<std::vector<WifiInfo>> found_wifi_networks;
@ -130,7 +134,6 @@ void create_keyboard();
Images imgs = Images();
uint_fast8_t currentDevice = 4;
lv_color_t color_primary = lv_color_hex(0x303030); // gray
bool wakeupByIMUEnabled = true;
inline static const uint_fast8_t virtualKeyMapTechnisat[10] = {
0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x0};

View File

@ -33,7 +33,7 @@ void OmoteUI::display_settings(lv_obj_t* parent)
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_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);
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_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);
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);
}