summaryrefslogtreecommitdiff
path: root/src/systemtask/SystemTask.cpp
diff options
context:
space:
mode:
authorJF <JF002@users.noreply.github.com>2021-10-09 20:11:31 +0200
committerGitHub <noreply@github.com>2021-10-09 20:11:31 +0200
commitb969272c90bfbfa8ae7234809a896ba62411f797 (patch)
tree56e0d4f2af2e5b74d6050d74884a64076cdbdba1 /src/systemtask/SystemTask.cpp
parentc99feeea312f911e17b133a93c208caa88cb7b03 (diff)
parent1777b9dee8f1189df29f627707b970995f0d4afe (diff)
Merge pull request #719 from Riksu9000/improve_battery_reporting
Improve battery percentage calculation and reporting
Diffstat (limited to 'src/systemtask/SystemTask.cpp')
-rw-r--r--src/systemtask/SystemTask.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/systemtask/SystemTask.cpp b/src/systemtask/SystemTask.cpp
index 09c7e88d..582015da 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,7 +346,7 @@ void SystemTask::Work() {
stepCounterMustBeReset = true;
break;
case Messages::OnChargingEvent:
- batteryController.Update();
+ batteryController.ReadPowerState();
motorController.RunForDuration(15);
ReloadIdleTimer();
if (isSleeping && !isWakingUp) {
@@ -353,14 +354,10 @@ void SystemTask::Work() {
}
break;
case Messages::MeasureBatteryTimerExpired:
- sendBatteryNotification = true;
- batteryController.Update();
+ batteryController.MeasureVoltage();
break;
- case Messages::BatteryMeasurementDone:
- if (sendBatteryNotification) {
- sendBatteryNotification = false;
- nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
- }
+ case Messages::BatteryPercentageUpdated:
+ nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());
break;
default: