diff --git a/Platformio/HAL/Targets/Simulator/batterySimulator.hpp b/Platformio/HAL/Targets/Simulator/batterySimulator.hpp index 69f2172..e5b52ec 100644 --- a/Platformio/HAL/Targets/Simulator/batterySimulator.hpp +++ b/Platformio/HAL/Targets/Simulator/batterySimulator.hpp @@ -1,9 +1,34 @@ #include "BatteryInterface.h" - +#include +#include +#include class BatterySimulator: public BatteryInterface{ public: - BatterySimulator() {}; - virtual int getPercentage() override { return 75; } + BatterySimulator() : + mCreationTime(std::chrono::high_resolution_clock::now()), + mBattNotifier(std::thread(&BatterySimulator::batteryNotifyThread,this)) + {}; + + ~BatterySimulator(){ + mBattNotifier.join(); + } + virtual int getPercentage() override { + auto now = std::chrono::high_resolution_clock::now(); + auto batteryRunTime = std::chrono::duration_cast(now - mCreationTime); + constexpr auto minToBatteryZero = 3; + auto fakeBattPercentage = 100 - ((batteryRunTime / std::chrono::duration>(minToBatteryZero)) * 100); + return std::floor(fakeBattPercentage < 100 ? fakeBattPercentage : 0); + } + virtual bool isCharging() override { return true; } + private: + void batteryNotifyThread(){ + while (true){ + NotifyCurrentStatus(); + std::this_thread::sleep_for(std::chrono::seconds(5)); + } + } + std::chrono::_V2::system_clock::time_point mCreationTime; + std::thread mBattNotifier; }; \ No newline at end of file diff --git a/Platformio/OmoteUI/OmoteUI.cpp b/Platformio/OmoteUI/OmoteUI.cpp index f8376ca..39e1d73 100644 --- a/Platformio/OmoteUI/OmoteUI.cpp +++ b/Platformio/OmoteUI/OmoteUI.cpp @@ -9,6 +9,16 @@ std::shared_ptr OmoteUI::mInstance = nullptr; // #if defined(IS_SIMULATOR) && (IS_SIMULATOR == true) // #endif +OmoteUI::OmoteUI(std::shared_ptr aHardware) : mHardware(aHardware){ + mHardware->battery()->onBatteryStatusChange([this](int percent, bool isCharging){ + if(percent > 95) lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_FULL); + else if(percent > 75) lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_3); + else if(percent > 50) lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_2); + else if(percent > 25) lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_1); + else lv_label_set_text(objBattIcon, LV_SYMBOL_BATTERY_EMPTY); + }); +} + // Set the page indicator scroll position relative to the tabview scroll // position void OmoteUI::store_scroll_value_event_cb(lv_event_t *e) { diff --git a/Platformio/OmoteUI/OmoteUI.hpp b/Platformio/OmoteUI/OmoteUI.hpp index a6040a6..2f8daea 100644 --- a/Platformio/OmoteUI/OmoteUI.hpp +++ b/Platformio/OmoteUI/OmoteUI.hpp @@ -15,8 +15,7 @@ /// of resources. class OmoteUI { public: - OmoteUI(std::shared_ptr aHardware) - : mHardware(aHardware){}; + OmoteUI(std::shared_ptr aHardware); static std::weak_ptr getRefrence() { return getInstance(); }; static std::shared_ptr diff --git a/Platformio/platformio.ini b/Platformio/platformio.ini index 8894a46..e52c59f 100644 --- a/Platformio/platformio.ini +++ b/Platformio/platformio.ini @@ -50,7 +50,7 @@ lib_archive = false build_src_filter = +<../OmoteUI/*> +<../HAL/HardwareAbstract.cpp> - +<../HAL/HardwareModules/DisplayAbstract.cpp> + +<../HAL/HardwareModules/*.cpp>