Detect full charge and improve watchface display
This commit is contained in:
@@ -19,6 +19,12 @@ void Battery::Update() {
|
||||
isCharging = !nrf_gpio_pin_read(chargingPin);
|
||||
isPowerPresent = !nrf_gpio_pin_read(powerPresentPin);
|
||||
|
||||
if (isPowerPresent && !isCharging) {
|
||||
isFull = true;
|
||||
} else if (!isPowerPresent) {
|
||||
isFull = false;
|
||||
}
|
||||
|
||||
if (isReading) {
|
||||
return;
|
||||
}
|
||||
@@ -65,12 +71,12 @@ void Battery::SaadcEventHandler(nrfx_saadc_evt_t const* p_event) {
|
||||
// p_event->data.done.p_buffer[0] = (adc_voltage / reference_voltage) * 1024
|
||||
voltage = p_event->data.done.p_buffer[0] * (8 * 600) / 1024;
|
||||
|
||||
if (voltage > battery_max) {
|
||||
if (isFull) {
|
||||
percentRemaining = 100;
|
||||
} else if (voltage < battery_min) {
|
||||
percentRemaining = 0;
|
||||
} else {
|
||||
percentRemaining = (voltage - battery_min) * 100 / (battery_max - battery_min);
|
||||
percentRemaining = std::min((voltage - battery_min) * 100 / (battery_max - battery_min), 99);
|
||||
}
|
||||
|
||||
nrfx_saadc_uninit();
|
||||
|
Reference in New Issue
Block a user