Fixes for power

This commit is contained in:
Ken Van Hoeylandt 2025-08-30 17:38:22 +02:00
parent c087d997f3
commit 28026d817f
5 changed files with 26 additions and 7 deletions

View File

@ -1,3 +1,4 @@
#include <Bq27220.h>
#include <Tactility/TactilityCore.h>
#include <Tactility/kernel/SystemEvents.h>
#include <Tactility/service/gps/GpsService.h>
@ -21,6 +22,18 @@ bool tpagerInit() {
}
tt::kernel::subscribeSystemEvent(tt::kernel::SystemEvent::BootSplash, [](auto) {
tt::hal::findDevices([](auto device) {
if (device->getName() == "BQ27220") {
auto bq27220 = std::reinterpret_pointer_cast<Bq27220>(device);
if (bq27220 != nullptr) {
bq27220->configureCapacity(1500, 1500);
return false;
}
}
return true;
});
auto gps_service = tt::service::gps::findGpsService();
if (gps_service != nullptr) {
std::vector<tt::hal::gps::GpsConfiguration> gps_configurations;

View File

@ -18,7 +18,6 @@ using namespace tt::hal;
DeviceVector createDevices() {
auto bq27220 = std::make_shared<Bq27220>(I2C_NUM_0);
bq27220->configureCapacity(1500, 1500);
auto power = std::make_shared<TpagerPower>(bq27220);
auto tca8418 = std::make_shared<Tca8418>(I2C_NUM_0);

View File

@ -127,7 +127,7 @@ bool Bq27220::getCurrent(int16_t &value) {
return false;
}
bool Bq27220::getBatteryStatus(Bq27220::BatteryStatus &batt_sta) {
bool Bq27220::getBatteryStatus(BatteryStatus &batt_sta) {
if (readRegister16(registers::CMD_BATTERY_STATUS, batt_sta.full)) {
swapEndianess(batt_sta.full);
return true;

View File

@ -114,7 +114,7 @@ static void registerSystemApps() {
addApp(app::development::manifest);
#endif
if (getConfiguration()->hardware->power != nullptr) {
if (hal::findDevices(hal::Device::Type::Power).size() > 0) {
addApp(app::power::manifest);
}
}

View File

@ -89,13 +89,20 @@ static const char* getSdCardStatusIcon(hal::sdcard::SdCardDevice::State state) {
}
static _Nullable const char* getPowerStatusIcon() {
auto get_power = getConfiguration()->hardware->power;
if (get_power == nullptr) {
// TODO: Support multiple power devices?
std::shared_ptr<hal::power::PowerDevice> power;
hal::findDevices<hal::power::PowerDevice>(hal::Device::Type::Power, [&power](const auto& device) {
if (device->supportsMetric(hal::power::PowerDevice::MetricType::ChargeLevel)) {
power = device;
return false;
}
return true;
});
if (power == nullptr) {
return nullptr;
}
auto power = get_power();
hal::power::PowerDevice::MetricData charge_level;
if (!power->getMetric(hal::power::PowerDevice::MetricType::ChargeLevel, charge_level)) {
return nullptr;