Merge PR #440 - fix countdown face issues

Avoid potential underflow when evaluating x - y with y > x.
Evaluate it only when y <= x instead.

Avoid clearing indicators in background task
since another watch face is likely active.

Reviewed-by: Matheus Afonso Martins Moreira <matheus@matheusmoreira.com>
GitHub-Pull-Request: https://github.com/joeycastillo/Sensor-Watch/pull/440
This commit is contained in:
Matheus Afonso Martins Moreira 2024-08-28 22:31:47 -03:00
commit 657ff724d0

View file

@ -87,7 +87,10 @@ static void draw(countdown_state_t *state, uint8_t subsecond) {
switch (state->mode) {
case cd_running:
delta = state->target_ts - state->now_ts;
if (state->target_ts <= state->now_ts)
delta = 0;
else
delta = state->target_ts - state->now_ts;
result = div(delta, 60);
state->seconds = result.rem;
result = div(result.quot, 60);
@ -97,6 +100,7 @@ static void draw(countdown_state_t *state, uint8_t subsecond) {
break;
case cd_reset:
case cd_paused:
watch_clear_indicator(WATCH_INDICATOR_BELL);
sprintf(buf, "CD %2d%02d%02d", state->hours, state->minutes, state->seconds);
break;
case cd_setting:
@ -130,7 +134,6 @@ static void pause(countdown_state_t *state) {
static void reset(countdown_state_t *state) {
state->mode = cd_reset;
movement_cancel_background_task();
watch_clear_indicator(WATCH_INDICATOR_BELL);
load_countdown(state);
}