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