add fake battery Drain to simulator

Fake drain of a period of 3 minuets
This commit is contained in:
Matthew Colvin 2023-08-24 20:25:55 -05:00 committed by MatthewColvin
parent 3318265e0a
commit 628ae37b9d
4 changed files with 40 additions and 6 deletions

View file

@ -1,9 +1,34 @@
#include "BatteryInterface.h"
#include <chrono>
#include <thread>
#include <cmath>
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<std::chrono::seconds>(now - mCreationTime);
constexpr auto minToBatteryZero = 3;
auto fakeBattPercentage = 100 - ((batteryRunTime / std::chrono::duration<float,std::ratio<60LL>>(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;
};

View file

@ -9,6 +9,16 @@ std::shared_ptr<OmoteUI> OmoteUI::mInstance = nullptr;
// #if defined(IS_SIMULATOR) && (IS_SIMULATOR == true)
// #endif
OmoteUI::OmoteUI(std::shared_ptr<HardwareAbstract> 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) {

View file

@ -15,8 +15,7 @@
/// of resources.
class OmoteUI {
public:
OmoteUI(std::shared_ptr<HardwareAbstract> aHardware)
: mHardware(aHardware){};
OmoteUI(std::shared_ptr<HardwareAbstract> aHardware);
static std::weak_ptr<OmoteUI> getRefrence() { return getInstance(); };
static std::shared_ptr<OmoteUI>

View file

@ -50,7 +50,7 @@ lib_archive = false
build_src_filter =
+<../OmoteUI/*>
+<../HAL/HardwareAbstract.cpp>
+<../HAL/HardwareModules/DisplayAbstract.cpp>
+<../HAL/HardwareModules/*.cpp>