From b45de68ebb9b354db709184d44f847143054d139 Mon Sep 17 00:00:00 2001 From: Matthew Colvin <35540398+Mc067415@users.noreply.github.com> Date: Sun, 27 Aug 2023 21:41:50 -0500 Subject: [PATCH] Add get brightness to the displayAbstract to allow removal of backlight brightness stored in OmoteUI class "implement" new getter function in sim and esp32. --- Platformio/HAL/HardwareModules/DisplayAbstract.h | 1 + Platformio/HAL/Targets/ESP32/HardwareRevX.cpp | 4 +++- Platformio/HAL/Targets/ESP32/HardwareRevX.hpp | 1 - Platformio/HAL/Targets/ESP32/display/display.cpp | 4 ++++ Platformio/HAL/Targets/ESP32/display/display.hpp | 1 + Platformio/HAL/Targets/Simulator/SDLDisplay.cpp | 4 ++++ Platformio/HAL/Targets/Simulator/SDLDisplay.hpp | 5 +++-- Platformio/OmoteUI/OmoteUI.cpp | 3 ++- Platformio/OmoteUI/OmoteUI.hpp | 6 ------ Platformio/OmoteUI/displaySettings.cpp | 4 ++-- 10 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Platformio/HAL/HardwareModules/DisplayAbstract.h b/Platformio/HAL/HardwareModules/DisplayAbstract.h index 7974829..a15e88c 100644 --- a/Platformio/HAL/HardwareModules/DisplayAbstract.h +++ b/Platformio/HAL/HardwareModules/DisplayAbstract.h @@ -6,6 +6,7 @@ class DisplayAbstract public: DisplayAbstract(); virtual void setBrightness(uint8_t brightness) = 0; + virtual uint8_t getBrightness() = 0; virtual void turnOff() = 0; protected: diff --git a/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp index 88217cd..af34996 100644 --- a/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp +++ b/Platformio/HAL/Targets/ESP32/HardwareRevX.cpp @@ -148,7 +148,7 @@ void HardwareRevX::activityDetection() { void HardwareRevX::enterSleep() { // Save settings to internal flash memory preferences.putBool("wkpByIMU", wakeupByIMUEnabled); - preferences.putUChar("blBrightness", backlight_brightness); + preferences.putUChar("blBrightness", mDisplay->getBrightness()); preferences.putUChar("currentDevice", currentDevice); if (!preferences.getBool("alreadySetUp")) preferences.putBool("alreadySetUp", true); @@ -279,12 +279,14 @@ void HardwareRevX::setupBacklight() { void HardwareRevX::restorePreferences() { // Restore settings from internal flash memory + int backlight_brightness = 255; preferences.begin("settings", false); if (preferences.getBool("alreadySetUp")) { wakeupByIMUEnabled = preferences.getBool("wkpByIMU"); backlight_brightness = preferences.getUChar("blBrightness"); currentDevice = preferences.getUChar("currentDevice"); } + mDisplay->setBrightness(backlight_brightness); } void HardwareRevX::setupIMU() { diff --git a/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp index 464b524..08013c6 100644 --- a/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp +++ b/Platformio/HAL/Targets/ESP32/HardwareRevX.hpp @@ -69,7 +69,6 @@ private: Preferences preferences; bool wakeupByIMUEnabled = true; - int backlight_brightness = 255; byte currentDevice = 1; // Current Device to control (allows switching // mappings between devices) diff --git a/Platformio/HAL/Targets/ESP32/display/display.cpp b/Platformio/HAL/Targets/ESP32/display/display.cpp index c27ba7e..d5e5d1c 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.cpp +++ b/Platformio/HAL/Targets/ESP32/display/display.cpp @@ -64,6 +64,10 @@ void Display::setBrightness(uint8_t brightness) startFade(); } +uint8_t Display::getBrightness(){ + return mAwakeBrightness; +} + void Display::setCurrentBrightness(uint8_t brightness){ mBrightness = brightness; ledcWrite(LCD_BACKLIGHT_LEDC_CHANNEL, mBrightness); diff --git a/Platformio/HAL/Targets/ESP32/display/display.hpp b/Platformio/HAL/Targets/ESP32/display/display.hpp index e70a52f..e4e0bdf 100644 --- a/Platformio/HAL/Targets/ESP32/display/display.hpp +++ b/Platformio/HAL/Targets/ESP32/display/display.hpp @@ -25,6 +25,7 @@ class Display: public DisplayAbstract /// @brief Set brightness setting and fade to it /// @param brightness virtual void setBrightness(uint8_t brightness) override; + virtual uint8_t getBrightness() override; virtual void turnOff() override; void onTouch(Notification::HandlerTy aTouchHandler); diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp index 3ee7e4f..231ad1e 100644 --- a/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.cpp @@ -13,6 +13,10 @@ void SDLDisplay::setBrightness(uint8_t brightness){ } +uint8_t SDLDisplay::getBrightness(){ + +} + void SDLDisplay::turnOff(){ } diff --git a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp index 53fd84c..e49ab0d 100644 --- a/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp +++ b/Platformio/HAL/Targets/Simulator/SDLDisplay.hpp @@ -6,8 +6,9 @@ class SDLDisplay : public DisplayAbstract{ public: static std::shared_ptr getInstance(); - void setBrightness(uint8_t brightness); - void turnOff(); + virtual void setBrightness(uint8_t brightness) override; + virtual uint8_t getBrightness() override; + virtual void turnOff() override; protected: virtual void flushDisplay(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p) override; diff --git a/Platformio/OmoteUI/OmoteUI.cpp b/Platformio/OmoteUI/OmoteUI.cpp index a77e52d..77daff9 100644 --- a/Platformio/OmoteUI/OmoteUI.cpp +++ b/Platformio/OmoteUI/OmoteUI.cpp @@ -29,7 +29,8 @@ void OmoteUI::tabview_device_event_cb(lv_event_t *e) { // Slider Event handler void OmoteUI::bl_slider_event_cb(lv_event_t *e) { lv_obj_t *slider = lv_event_get_target(e); - backlight_brightness = std::clamp(lv_slider_get_value(slider), 60, 255); + auto newBrightness = std::clamp(lv_slider_get_value(slider), 60, 255); + mHardware->display()->setBrightness(newBrightness); } // Apple Key Event handler diff --git a/Platformio/OmoteUI/OmoteUI.hpp b/Platformio/OmoteUI/OmoteUI.hpp index 5b40d0c..11c7873 100644 --- a/Platformio/OmoteUI/OmoteUI.hpp +++ b/Platformio/OmoteUI/OmoteUI.hpp @@ -229,12 +229,6 @@ void create_keyboard(); */ void update_wifi_selection_subpage(int page); -/************************************** Display settings menu ********************************************************/ - /** - * Variable to store the current backlight brightness level - */ - unsigned int backlight_brightness; - /** * @brief Function to create the display settings page. * diff --git a/Platformio/OmoteUI/displaySettings.cpp b/Platformio/OmoteUI/displaySettings.cpp index ffa421c..6588334 100644 --- a/Platformio/OmoteUI/displaySettings.cpp +++ b/Platformio/OmoteUI/displaySettings.cpp @@ -18,12 +18,12 @@ void OmoteUI::display_settings(lv_obj_t* parent) lv_obj_set_style_bg_color(slider, lv_color_white(), LV_PART_KNOB); lv_obj_set_style_bg_opa(slider, LV_OPA_COVER, LV_PART_MAIN); lv_obj_set_style_bg_color(slider, lv_color_lighten(color_primary, 50), LV_PART_MAIN); - lv_slider_set_value(slider, this->backlight_brightness, LV_ANIM_OFF); + lv_slider_set_value(slider, mHardware->display()->getBrightness() , LV_ANIM_OFF); lv_obj_set_size(slider, lv_pct(66), 10); lv_obj_align(slider, LV_ALIGN_TOP_MID, 0, 3); brightnessIcon = imgs.addHighBrightnessIcon(menuBox); lv_obj_align(brightnessIcon, LV_ALIGN_TOP_RIGHT, 0, -1); - lv_obj_add_event_cb(slider, [] (lv_event_t* e) {mInstance->bl_slider_event_cb(e);}, LV_EVENT_VALUE_CHANGED, &this->backlight_brightness); + lv_obj_add_event_cb(slider, [] (lv_event_t* e) {mInstance->bl_slider_event_cb(e);}, LV_EVENT_VALUE_CHANGED, nullptr); menuLabel = lv_label_create(menuBox); lv_label_set_text(menuLabel, "Lift to Wake");