OMOTE/Platformio/HAL/Targets/Simulator/batterySimulator.hpp
Matthew Colvin 65162049b3 convert notification driven battery to lvgl timer based polling
using new poller class to simplify the battery interface and
downstream usages of battery.

tweaked poller destructor and remove the default constructor
in preference of using a unique pointer

convert simulator to use a std::thread for lvgl Tick api because
the SDL thread sleep was not true to time. (and is simplified the code...)
2023-09-09 21:47:36 -04:00

23 lines
No EOL
908 B
C++

#include "BatteryInterface.h"
#include <chrono>
#include <cmath>
class BatterySimulator: public BatteryInterface{
public:
BatterySimulator() :
mCreationTime(std::chrono::high_resolution_clock::now())
{};
~BatterySimulator(){}
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 false; }
private:
std::chrono::_V2::system_clock::time_point mCreationTime;
};