From d73b81657818194bc9049785ba7ea8928125ffdf Mon Sep 17 00:00:00 2001 From: Matthew Colvin <35540398+Mc067415@users.noreply.github.com> Date: Fri, 11 Aug 2023 23:57:18 -0500 Subject: [PATCH] Add docs around battery notifications --- Platformio/HAL/HardwareAbstract.cpp | 4 ++-- Platformio/HAL/HardwareAbstract.hpp | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Platformio/HAL/HardwareAbstract.cpp b/Platformio/HAL/HardwareAbstract.cpp index d424d89..1c5da99 100644 --- a/Platformio/HAL/HardwareAbstract.cpp +++ b/Platformio/HAL/HardwareAbstract.cpp @@ -21,11 +21,11 @@ std::optional HardwareAbstract::getBatteryStatu } void HardwareAbstract::notifyBatteryChange(HardwareAbstract::batteryStatus aStatus){ - for (auto handler : mBatteryEventHandlers){ + for (auto handler : mBatteryUpdateHandlers){ handler(aStatus); } } void HardwareAbstract::onBatteryChange(std::function onBatteryStatusChangeHandler){ - mBatteryEventHandlers.push_back(std::move(onBatteryStatusChangeHandler)); + mBatteryUpdateHandlers.push_back(std::move(onBatteryStatusChangeHandler)); } \ No newline at end of file diff --git a/Platformio/HAL/HardwareAbstract.hpp b/Platformio/HAL/HardwareAbstract.hpp index aaa9e98..e1fac74 100644 --- a/Platformio/HAL/HardwareAbstract.hpp +++ b/Platformio/HAL/HardwareAbstract.hpp @@ -36,9 +36,16 @@ 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); + /// @brief Register function to be ran when hardware notifies battery + /// status has changed. + /// @param onBatteryStatusChangeHandler - Callable to be ran when batter status changes void onBatteryChange(std::function onBatteryStatusChangeHandler); + + protected: + /// @brief Call in child class implementation to alert users + /// the battery status has changed + /// @param aStatus - Current Battery Status + void notifyBatteryChange(batteryStatus aStatus); private: std::shared_ptr mBattery;