Don't measure and notify percentage on charging event.

This commit is contained in:
Riku Isokoski 2021-10-09 13:39:27 +03:00
parent a9f7153fdf
commit 1777b9dee8
3 changed files with 11 additions and 5 deletions

View File

@ -13,7 +13,7 @@ Battery::Battery() {
nrf_gpio_cfg_input(PinMap::Charging, static_cast<nrf_gpio_pin_pull_t> GPIO_PIN_CNF_PULL_Disabled); 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); isCharging = !nrf_gpio_pin_read(PinMap::Charging);
isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent); isPowerPresent = !nrf_gpio_pin_read(PinMap::PowerPresent);
@ -22,6 +22,10 @@ void Battery::Update() {
} else if (!isPowerPresent) { } else if (!isPowerPresent) {
isFull = false; isFull = false;
} }
}
void Battery::MeasureVoltage() {
ReadPowerState();
if (isReading) { if (isReading) {
return; return;

View File

@ -10,7 +10,8 @@ namespace Pinetime {
public: public:
Battery(); Battery();
void Update(); void ReadPowerState();
void MeasureVoltage();
void Register(System::SystemTask* systemTask); void Register(System::SystemTask* systemTask);
uint8_t PercentRemaining() const { uint8_t PercentRemaining() const {

View File

@ -136,7 +136,6 @@ void SystemTask::Work() {
touchPanel.Init(); touchPanel.Init();
dateTimeController.Register(this); dateTimeController.Register(this);
batteryController.Register(this); batteryController.Register(this);
batteryController.Update();
motorController.Init(); motorController.Init();
motionSensor.SoftReset(); motionSensor.SoftReset();
timerController.Register(this); 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); 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); idleTimer = xTimerCreate("idleTimer", pdMS_TO_TICKS(2000), pdFALSE, this, IdleTimerCallback);
dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback); dimTimer = xTimerCreate("dimTimer", pdMS_TO_TICKS(settingsController.GetScreenTimeOut() - 2000), pdFALSE, this, DimTimerCallback);
measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback); measureBatteryTimer = xTimerCreate("measureBattery", batteryMeasurementPeriod, pdTRUE, this, MeasureBatteryTimerCallback);
@ -345,11 +346,11 @@ void SystemTask::Work() {
stepCounterMustBeReset = true; stepCounterMustBeReset = true;
break; break;
case Messages::OnChargingEvent: case Messages::OnChargingEvent:
batteryController.Update(); batteryController.ReadPowerState();
motorController.RunForDuration(15); motorController.RunForDuration(15);
break; break;
case Messages::MeasureBatteryTimerExpired: case Messages::MeasureBatteryTimerExpired:
batteryController.Update(); batteryController.MeasureVoltage();
break; break;
case Messages::BatteryPercentageUpdated: case Messages::BatteryPercentageUpdated:
nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining()); nimbleController.NotifyBatteryLevel(batteryController.PercentRemaining());