committed by
GitHub
parent
80245e08fa
commit
103588948f
@@ -1,4 +1,5 @@
|
||||
#include "hal/Configuration.h"
|
||||
#include "hal/SimulatorPower.h"
|
||||
#include "LvglTask.h"
|
||||
#include "src/lv_init.h"
|
||||
#include "SdlDisplay.h"
|
||||
@@ -6,8 +7,6 @@
|
||||
|
||||
#define TAG "hardware"
|
||||
|
||||
extern const tt::hal::Power power;
|
||||
|
||||
static bool initBoot() {
|
||||
lv_init();
|
||||
lvgl_task_start();
|
||||
@@ -30,7 +29,7 @@ extern const tt::hal::Configuration hardware = {
|
||||
.createDisplay = createDisplay,
|
||||
.createKeyboard = createKeyboard,
|
||||
.sdcard = nullptr,
|
||||
.power = &power,
|
||||
.power = simulatorPower,
|
||||
.i2c = {
|
||||
tt::hal::i2c::Configuration {
|
||||
.name = "Internal",
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
#include "hal/Power.h"
|
||||
|
||||
static bool is_charging_enabled = false;
|
||||
|
||||
static bool isCharging() {
|
||||
return is_charging_enabled;
|
||||
}
|
||||
|
||||
static bool isChargingEnabled() {
|
||||
return is_charging_enabled;
|
||||
}
|
||||
|
||||
static void setChargingEnabled(bool enabled) {
|
||||
is_charging_enabled = enabled;
|
||||
}
|
||||
|
||||
static uint8_t getChargeLevel() {
|
||||
return 204;
|
||||
}
|
||||
|
||||
static int32_t getCurrent() {
|
||||
return is_charging_enabled ? 100 : -50;
|
||||
}
|
||||
|
||||
extern const tt::hal::Power power = {
|
||||
.isCharging = isCharging,
|
||||
.isChargingEnabled = isChargingEnabled,
|
||||
.setChargingEnabled = setChargingEnabled,
|
||||
.getChargeLevel = getChargeLevel,
|
||||
.getCurrent = getCurrent
|
||||
};
|
||||
@@ -0,0 +1,44 @@
|
||||
#include "SimulatorPower.h"
|
||||
|
||||
#define TAG "simulator_power"
|
||||
|
||||
bool SimulatorPower::supportsMetric(MetricType type) const {
|
||||
switch (type) {
|
||||
case IS_CHARGING:
|
||||
case CURRENT:
|
||||
case BATTERY_VOLTAGE:
|
||||
case CHARGE_LEVEL:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // Safety guard for when new enum values are introduced
|
||||
}
|
||||
|
||||
bool SimulatorPower::getMetric(Power::MetricType type, Power::MetricData& data) {
|
||||
switch (type) {
|
||||
case IS_CHARGING:
|
||||
data.valueAsBool = true;
|
||||
return true;
|
||||
case CURRENT:
|
||||
data.valueAsInt32 = 42;
|
||||
return true;
|
||||
case BATTERY_VOLTAGE:
|
||||
data.valueAsUint32 = 4032;
|
||||
return true;
|
||||
case CHARGE_LEVEL:
|
||||
data.valueAsUint8 = 80;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // Safety guard for when new enum values are introduced
|
||||
}
|
||||
|
||||
static std::shared_ptr<Power> power;
|
||||
|
||||
std::shared_ptr<Power> simulatorPower() {
|
||||
if (power == nullptr) {
|
||||
power = std::make_shared<SimulatorPower>();
|
||||
}
|
||||
return power;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#pragma once
|
||||
|
||||
#include "hal/Power.h"
|
||||
#include <memory>
|
||||
|
||||
using namespace tt::hal;
|
||||
|
||||
class SimulatorPower : public Power {
|
||||
|
||||
bool allowedToCharge = false;
|
||||
|
||||
public:
|
||||
|
||||
SimulatorPower() {}
|
||||
~SimulatorPower() {}
|
||||
|
||||
bool supportsMetric(MetricType type) const override;
|
||||
bool getMetric(Power::MetricType type, Power::MetricData& data) override;
|
||||
|
||||
bool supportsChargeControl() const { return true; }
|
||||
bool isAllowedToCharge() const { return allowedToCharge; }
|
||||
void setAllowedToCharge(bool canCharge) { allowedToCharge = canCharge; }
|
||||
};
|
||||
|
||||
std::shared_ptr<Power> simulatorPower();
|
||||
Reference in New Issue
Block a user