summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/components/battery/BatteryController.cpp6
-rw-r--r--src/components/battery/BatteryController.h3
-rw-r--r--src/systemtask/SystemTask.cpp7
3 files changed, 11 insertions, 5 deletions
diff --git a/src/components/battery/BatteryController.cpp b/src/components/battery/BatteryController.cpp
index 0ef4ff1a..e807f033 100644
--- a/src/components/battery/BatteryController.cpp
+++ b/src/components/battery/BatteryController.cpp
@@ -13,7 +13,7 @@ Battery::Battery() {
nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled);
}
-void Battery::Update() {
+void Battery::ReadPowerState() {
isCharging = !nrf_gpio_pin_read(PinMap::Charging);
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
@@ -22,6 +22,10 @@ void Battery::Update() {
} else if (!isPowerPresent) {
isFull = false;
}
+}
+
+void Battery::MeasureVoltage() {
+ ReadPowerState();
if (isReading) {
return;
diff --git a/src/components/battery/BatteryController.h b/src/components/battery/BatteryController.h
index 55c26309..5a7394c4 100644
--- a/src/components/battery/BatteryController.h
+++ b/src/components/battery/BatteryController.h
@@ -10,7 +10,8 @@ namespace Pinetime {
public:
Battery();
- void Update();
+ void ReadPowerState();
+ void MeasureVoltage();
void Register(System::SystemTask* systemTask);
uint8_t PercentRemaining() const {
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 0a53101f..ec8b5e4e 100644
--- a/src/systemtask/SystemTask.cpp
+++ b/src/systemtask/SystemTask.cpp
@@ -136,7 +136,6 @@ void SystemTask::Work() {
touchPanel.Init();
dateTimeController.Register(this);
batteryController.Register(this);
- batteryController.Update();
motorController.Init();
motionSensor.SoftReset();
timerController.Register(this);
@@ -194,6 +193,8 @@ void SystemTask::Work() {
nrf_gpio_cfg_sense_input(PinMap::PowerPresent, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_SENSE_HIGH);
}
+ batteryController.MeasureVoltage();
+
idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback);
@@ -345,11 +346,11 @@ void SystemTask::Work() {
stepCounterMustBeReset = true;
break;
case Messages::OnChargingEvent:
- batteryController.Update();
+ batteryController.ReadPowerState();
motorController.RunForDuration(15);
break;
case Messages::MeasureBatteryTimerExpired:
- batteryController.Update();
+ batteryController.MeasureVoltage();
break;
case Messages::BatteryPercentageUpdated:
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());