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
|
@ -19,3 +19,13 @@ std::optional<HardwareAbstract::batteryStatus> HardwareAbstract::getBatteryStatu
|
||||||
}
|
}
|
||||||
return std::nullopt;
|
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
|
// 2023 Matthew Colvin
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <functional>
|
||||||
#include <lvgl.h>
|
#include <lvgl.h>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
#include "BatteryInterface.h"
|
#include "BatteryInterface.h"
|
||||||
#include "DisplayInterface.h"
|
#include "DisplayInterface.h"
|
||||||
#include "wifiHandlerInterface.h"
|
#include "wifiHandlerInterface.h"
|
||||||
|
@ -34,6 +36,10 @@ public:
|
||||||
/// @param message - Debug message
|
/// @param message - Debug message
|
||||||
virtual void debugPrint(std::string message) = 0;
|
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:
|
private:
|
||||||
std::shared_ptr<BatteryInterface> mBattery;
|
std::shared_ptr<BatteryInterface> mBattery;
|
||||||
std::shared_ptr<wifiHandlerInterface> mWifiHandler;
|
std::shared_ptr<wifiHandlerInterface> mWifiHandler;
|
||||||
|
|
|
@ -307,6 +307,11 @@ void OmoteUI::layout_UI() {
|
||||||
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
|
lv_obj_set_style_bg_color(menuBox, color_primary, LV_PART_MAIN);
|
||||||
lv_obj_set_style_border_width(menuBox, 0, 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)
|
// Add content to the smart home tab (4)
|
||||||
|
|
||||||
lv_obj_set_layout(tab4, LV_LAYOUT_FLEX);
|
lv_obj_set_layout(tab4, LV_LAYOUT_FLEX);
|
||||||
|
|
Loading…
Add table
Reference in a new issue