rough draft a callback inside HardwareAbstract
to show concept.
This commit is contained in:
parent
35de08d2e3
commit
6268a28682
3 changed files with 27 additions and 6 deletions
|
@ -18,4 +18,14 @@ std::optional<HardwareAbstract::batteryStatus> HardwareAbstract::getBatteryStatu
|
|||
return currentStatus;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
void HardwareAbstract::notifyBatteryChange(HardwareAbstract::batteryStatus aStatus){
|
||||
for (auto handler : mBatteryEventHandlers){
|
||||
handler(aStatus);
|
||||
}
|
||||
}
|
||||
|
||||
void HardwareAbstract::onBatteryChange(std::function<void(HardwareAbstract::batteryStatus)> onBatteryStatusChangeHandler){
|
||||
mBatteryEventHandlers.push_back(std::move(onBatteryStatusChangeHandler));
|
||||
}
|
|
@ -2,10 +2,12 @@
|
|||
// 2023 Matthew Colvin
|
||||
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <lvgl.h>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#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<void(batteryStatus)> onBatteryStatusChangeHandler);
|
||||
|
||||
private:
|
||||
std::shared_ptr<BatteryInterface> mBattery;
|
||||
std::shared_ptr<wifiHandlerInterface> mWifiHandler;
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Reference in a new issue