From 6268a2868291ab901006b576118fdc89d91aff1a Mon Sep 17 00:00:00 2001 From: Matthew Colvin Date: Fri, 11 Aug 2023 15:56:24 -0500 Subject: [PATCH] rough draft a callback inside HardwareAbstract to show concept. --- Platformio/HAL/HardwareAbstract.cpp | 12 +++++++++++- Platformio/HAL/HardwareAbstract.hpp | 6 ++++++ Platformio/OmoteUI/OmoteUI.cpp | 15 ++++++++++----- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/Platformio/HAL/HardwareAbstract.cpp b/Platformio/HAL/HardwareAbstract.cpp index 13c1adb..d424d89 100644 --- a/Platformio/HAL/HardwareAbstract.cpp +++ b/Platformio/HAL/HardwareAbstract.cpp @@ -18,4 +18,14 @@ std::optional HardwareAbstract::getBatteryStatu return currentStatus; } return std::nullopt; -} \ No newline at end of file +} + + void HardwareAbstract::notifyBatteryChange(HardwareAbstract::batteryStatus aStatus){ + for (auto handler : mBatteryEventHandlers){ + handler(aStatus); + } + } + + void HardwareAbstract::onBatteryChange(std::function onBatteryStatusChangeHandler){ + mBatteryEventHandlers.push_back(std::move(onBatteryStatusChangeHandler)); + } \ No newline at end of file diff --git a/Platformio/HAL/HardwareAbstract.hpp b/Platformio/HAL/HardwareAbstract.hpp index 95cb070..aaa9e98 100644 --- a/Platformio/HAL/HardwareAbstract.hpp +++ b/Platformio/HAL/HardwareAbstract.hpp @@ -2,10 +2,12 @@ // 2023 Matthew Colvin #pragma once +#include #include #include #include #include +#include #include "BatteryInterface.h" #include "DisplayInterface.h" #include "wifiHandlerInterface.h" @@ -34,6 +36,10 @@ public: /// @param message - Debug message virtual void debugPrint(std::string message) = 0; + // Didn't actually implement this but would need to set up something to intermittently notify of batteryChange. + void notifyBatteryChange(batteryStatus aStatus); + void onBatteryChange(std::function onBatteryStatusChangeHandler); + private: std::shared_ptr mBattery; std::shared_ptr mWifiHandler; diff --git a/Platformio/OmoteUI/OmoteUI.cpp b/Platformio/OmoteUI/OmoteUI.cpp index f88d340..fcd1bd8 100644 --- a/Platformio/OmoteUI/OmoteUI.cpp +++ b/Platformio/OmoteUI/OmoteUI.cpp @@ -93,7 +93,7 @@ void OmoteUI::loopHandler(){ void OmoteUI::layout_UI() { // --- LVGL UI Configuration --- - + // Set the background color lv_obj_set_style_bg_color(lv_scr_act(), lv_color_black(), LV_PART_MAIN); @@ -173,10 +173,10 @@ void OmoteUI::layout_UI() { // Add content to the Apple TV tab (3) // Add a nice apple tv logo - + lv_obj_t* appleImg = imgs.addAppleTVIcon(tab3); lv_obj_align(appleImg, LV_ALIGN_CENTER, 0, -60); - + // create two buttons and add their icons accordingly lv_obj_t *button = lv_btn_create(tab3); lv_obj_align(button, LV_ALIGN_BOTTOM_LEFT, 10, 0); @@ -240,7 +240,7 @@ void OmoteUI::layout_UI() { 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, NULL); @@ -307,6 +307,11 @@ void OmoteUI::layout_UI() { lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN); lv_obj_set_style_border_width(menuBox, 0, LV_PART_MAIN); + mHardware->onBatteryChange([menuLabel](HardwareAbstract::batteryStatus aCurrentBattery){ + // I dont know enough about lvgl to do this but basically take aCurrentBattery and update UI elements here. + // See Notice menuLabel is captured and useable here. + }); + // Add content to the smart home tab (4) lv_obj_set_layout(tab4, LV_LAYOUT_FLEX); @@ -490,7 +495,7 @@ void OmoteUI::layout_UI() { lv_obj_t *img1 = imgs.addLeftGradiant(lv_scr_act()); lv_obj_align(img1, LV_ALIGN_BOTTOM_LEFT, 0, 0); lv_obj_set_size(img1, 30, 30); // stretch the 1-pixel high image to 30px - + lv_obj_t* img2 = imgs.addRightGradiant(lv_scr_act()); lv_obj_align(img2, LV_ALIGN_BOTTOM_RIGHT, 0, 0); lv_obj_set_size(img2, 30, 30);