add fake battery Drain to simulator
Fake drain of a period of 3 minuets
This commit is contained in:
parent
3318265e0a
commit
628ae37b9d
4 changed files with 40 additions and 6 deletions
|
@ -1,9 +1,34 @@
|
||||||
#include "BatteryInterface.h"
|
#include "BatteryInterface.h"
|
||||||
|
#include <chrono>
|
||||||
|
#include <thread>
|
||||||
|
#include <cmath>
|
||||||
class BatterySimulator: public BatteryInterface{
|
class BatterySimulator: public BatteryInterface{
|
||||||
public:
|
public:
|
||||||
BatterySimulator() {};
|
BatterySimulator() :
|
||||||
virtual int getPercentage() override { return 75; }
|
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; }
|
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;
|
||||||
};
|
};
|
|
@ -9,6 +9,16 @@ std::shared_ptr<OmoteUI> OmoteUI::mInstance = nullptr;
|
||||||
// #if defined(IS_SIMULATOR) && (IS_SIMULATOR == true)
|
// #if defined(IS_SIMULATOR) && (IS_SIMULATOR == true)
|
||||||
// #endif
|
// #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
|
// Set the page indicator scroll position relative to the tabview scroll
|
||||||
// position
|
// position
|
||||||
void OmoteUI::store_scroll_value_event_cb(lv_event_t *e) {
|
void OmoteUI::store_scroll_value_event_cb(lv_event_t *e) {
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
/// of resources.
|
/// of resources.
|
||||||
class OmoteUI {
|
class OmoteUI {
|
||||||
public:
|
public:
|
||||||
OmoteUI(std::shared_ptr<HardwareAbstract> aHardware)
|
OmoteUI(std::shared_ptr<HardwareAbstract> aHardware);
|
||||||
: mHardware(aHardware){};
|
|
||||||
|
|
||||||
static std::weak_ptr<OmoteUI> getRefrence() { return getInstance(); };
|
static std::weak_ptr<OmoteUI> getRefrence() { return getInstance(); };
|
||||||
static std::shared_ptr<OmoteUI>
|
static std::shared_ptr<OmoteUI>
|
||||||
|
|
|
@ -50,7 +50,7 @@ lib_archive = false
|
||||||
build_src_filter =
|
build_src_filter =
|
||||||
+<../OmoteUI/*>
|
+<../OmoteUI/*>
|
||||||
+<../HAL/HardwareAbstract.cpp>
|
+<../HAL/HardwareAbstract.cpp>
|
||||||
+<../HAL/HardwareModules/DisplayAbstract.cpp>
|
+<../HAL/HardwareModules/*.cpp>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue