Add power enabled check to power API (#68)

This commit is contained in:
Ken Van Hoeylandt
2024-11-03 22:30:41 +01:00
committed by GitHub
parent 632d7ccccf
commit 28c456e2d9
4 changed files with 27 additions and 2 deletions
+12
View File
@@ -5,11 +5,22 @@
extern "C" {
#endif
/**
* M5.Power by default doesn't have a check to see if charging is enabled.
* However, it's always enabled by default after boot, so we cover that here:
*/
static bool is_charging_enabled = true;
static bool power_is_charging() {
return M5.Power.isCharging() == m5::Power_Class::is_charging;
}
static bool power_is_charging_enabled() {
return is_charging_enabled;
}
static void power_set_charging_enabled(bool enabled) {
is_charging_enabled = enabled; // Local shadow copy because M5 API doesn't provide a function for it
M5.Power.setBatteryCharge(enabled);
}
@@ -24,6 +35,7 @@ static int32_t power_get_current() {
Power core2_power = {
.is_charging = &power_is_charging,
.is_charging_enabled = &power_is_charging_enabled,
.set_charging_enabled = &power_set_charging_enabled,
.get_charge_level = &power_get_charge_level,
.get_current = &power_get_current