diff --git a/Boards/LilygoTLoraPager/Source/Init.cpp b/Boards/LilygoTLoraPager/Source/Init.cpp index bb160911..cf1c7ce7 100644 --- a/Boards/LilygoTLoraPager/Source/Init.cpp +++ b/Boards/LilygoTLoraPager/Source/Init.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -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(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 gps_configurations; diff --git a/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp b/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp index f8cd5d2f..05f6ad09 100644 --- a/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp +++ b/Boards/LilygoTLoraPager/Source/LilygoTloraPager.cpp @@ -18,7 +18,6 @@ using namespace tt::hal; DeviceVector createDevices() { auto bq27220 = std::make_shared(I2C_NUM_0); - bq27220->configureCapacity(1500, 1500); auto power = std::make_shared(bq27220); auto tca8418 = std::make_shared(I2C_NUM_0); diff --git a/Drivers/BQ27220/Source/Bq27220.cpp b/Drivers/BQ27220/Source/Bq27220.cpp index cbf31ebb..1596af07 100644 --- a/Drivers/BQ27220/Source/Bq27220.cpp +++ b/Drivers/BQ27220/Source/Bq27220.cpp @@ -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; diff --git a/Tactility/Source/Tactility.cpp b/Tactility/Source/Tactility.cpp index ec9568e5..a2516ae3 100644 --- a/Tactility/Source/Tactility.cpp +++ b/Tactility/Source/Tactility.cpp @@ -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); } } diff --git a/Tactility/Source/service/statusbar/Statusbar.cpp b/Tactility/Source/service/statusbar/Statusbar.cpp index e0bb1d48..4d9e8145 100644 --- a/Tactility/Source/service/statusbar/Statusbar.cpp +++ b/Tactility/Source/service/statusbar/Statusbar.cpp @@ -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 power; + hal::findDevices(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;