day_one_face: show set date on short alarm button press

This commit is contained in:
Christian Buschau 2023-09-20 00:55:51 +02:00
parent e8b7985dde
commit 984990fb66
No known key found for this signature in database
GPG Key ID: 74B8EC7053894AC4
2 changed files with 107 additions and 58 deletions

View File

@ -100,6 +100,7 @@ void day_one_face_activate(movement_settings_t *settings, void *context) {
state->current_page = PAGE_DISPLAY; state->current_page = PAGE_DISPLAY;
state->quick_cycle = false; state->quick_cycle = false;
state->ticks = 0;
// fetch the user's birth date from the birthday register. // fetch the user's birth date from the birthday register.
movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2); movement_birthdate_t movement_birthdate = (movement_birthdate_t) watch_get_backup_data(2);
@ -112,7 +113,7 @@ bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, vo
(void) settings; (void) settings;
day_one_state_t *state = (day_one_state_t *)context; day_one_state_t *state = (day_one_state_t *)context;
char buf[6]; char buf[9];
switch (event.event_type) { switch (event.event_type) {
case EVENT_ACTIVATE: case EVENT_ACTIVATE:
@ -120,80 +121,126 @@ bool day_one_face_loop(movement_event_t event, movement_settings_t *settings, vo
break; break;
case EVENT_LOW_ENERGY_UPDATE: case EVENT_LOW_ENERGY_UPDATE:
case EVENT_TICK: case EVENT_TICK:
if (state->current_page != PAGE_DISPLAY) { if (state->quick_cycle) {
if (state->quick_cycle) { if (watch_get_pin_level(BTN_ALARM)) {
if (watch_get_pin_level(BTN_ALARM)) { _day_one_face_increment(state);
_day_one_face_increment(state); } else {
} else { _day_one_face_abort_quick_cycle(state);
_day_one_face_abort_quick_cycle(state);
}
} }
}
switch (state->current_page) {
// if in settings mode, update whatever the current page is // if in settings mode, update whatever the current page is
switch (state->current_page) { case PAGE_YEAR:
case PAGE_YEAR: watch_display_string("YR ", 0);
watch_display_string("YR ", 0); if (event.subsecond % 2) {
if (event.subsecond % 2) { sprintf(buf, "%4d", state->birth_year);
sprintf(buf, "%4d", state->birth_year); watch_display_string(buf, 4);
watch_display_string(buf, 4); }
} break;
break; case PAGE_MONTH:
case PAGE_MONTH: watch_display_string("MO ", 0);
watch_display_string("MO ", 0); if (event.subsecond % 2) {
if (event.subsecond % 2) { sprintf(buf, "%2d", state->birth_month);
sprintf(buf, "%2d", state->birth_month); watch_display_string(buf, 4);
watch_display_string(buf, 4); }
} break;
break; case PAGE_DAY:
case PAGE_DAY: watch_display_string("DA ", 0);
watch_display_string("DA ", 0); if (event.subsecond % 2) {
if (event.subsecond % 2) { sprintf(buf, "%2d", state->birth_day);
sprintf(buf, "%2d", state->birth_day); watch_display_string(buf, 6);
watch_display_string(buf, 6); }
} break;
break;
default:
break;
}
} else {
// otherwise, check if we have to update. the display only needs to change at midnight! // otherwise, check if we have to update. the display only needs to change at midnight!
watch_date_time date_time = watch_rtc_get_date_time(); case PAGE_DISPLAY: {
if (date_time.unit.hour == 0 && date_time.unit.minute == 0 && date_time.unit.second == 0) { watch_date_time date_time = watch_rtc_get_date_time();
_day_one_face_update(state); if (date_time.unit.hour == 0 && date_time.unit.minute == 0 && date_time.unit.second == 0) {
} _day_one_face_update(state);
}
break;}
case PAGE_DATE:
if (state->ticks > 0) {
state->ticks--;
} else {
state->current_page = PAGE_DISPLAY;
_day_one_face_update(state);
}
break;
default:
break;
} }
break; break;
case EVENT_LIGHT_BUTTON_DOWN: case EVENT_LIGHT_BUTTON_DOWN:
// only illuminate if we're in display mode // only illuminate if we're in display mode
if (state->current_page == PAGE_DISPLAY) movement_illuminate_led(); switch (state->current_page) {
case PAGE_DISPLAY:
// fall through
case PAGE_DATE:
movement_illuminate_led();
break;
default:
break;
}
break; break;
case EVENT_LIGHT_BUTTON_UP: case EVENT_LIGHT_BUTTON_UP:
// otherwise use the light button to advance settings pages. // otherwise use the light button to advance settings pages.
if (state->current_page != PAGE_DISPLAY) { switch (state->current_page) {
// go to next setting page... case PAGE_YEAR:
state->current_page = (state->current_page + 1) % 4; // fall through
if (state->current_page == PAGE_DISPLAY) { case PAGE_MONTH:
// ...unless we've been pushed back to display mode. // fall through
movement_request_tick_frequency(1); case PAGE_DAY:
// force display since it normally won't update til midnight. // go to next setting page...
_day_one_face_update(state); state->current_page = (state->current_page + 1) % 4;
} if (state->current_page == PAGE_DISPLAY) {
// ...unless we've been pushed back to display mode.
movement_request_tick_frequency(1);
// force display since it normally won't update til midnight.
_day_one_face_update(state);
}
break;
default:
break;
} }
break; break;
case EVENT_ALARM_BUTTON_UP: case EVENT_ALARM_BUTTON_UP:
// if we are on a settings page, increment whatever value we're setting. // if we are on a settings page, increment whatever value we're setting.
if (state->current_page != PAGE_DISPLAY) { switch (state->current_page) {
_day_one_face_abort_quick_cycle(state); case PAGE_YEAR:
_day_one_face_increment(state); // fall through
case PAGE_MONTH:
// fall through
case PAGE_DAY:
_day_one_face_abort_quick_cycle(state);
_day_one_face_increment(state);
break;
case PAGE_DISPLAY:
state->current_page = PAGE_DATE;
sprintf(buf, "%04d%02d%02d", state->birth_year % 10000, state->birth_month % 100, state->birth_day % 100);
watch_display_string(buf, 2);
state->ticks = 2;
break;
default:
break;
} }
break; break;
case EVENT_ALARM_LONG_PRESS: case EVENT_ALARM_LONG_PRESS:
// if we aren't already in settings mode, put us there. // if we aren't already in settings mode, put us there.
if (state->current_page == PAGE_DISPLAY) { switch (state->current_page) {
state->current_page++; case PAGE_DISPLAY:
movement_request_tick_frequency(4); state->current_page++;
} else { movement_request_tick_frequency(4);
state->quick_cycle = true; break;
movement_request_tick_frequency(8); case PAGE_YEAR:
// fall through
case PAGE_MONTH:
// fall through
case PAGE_DAY:
state->quick_cycle = true;
movement_request_tick_frequency(8);
break;
default:
break;
} }
break; break;
case EVENT_ALARM_LONG_UP: case EVENT_ALARM_LONG_UP:

View File

@ -34,7 +34,8 @@ typedef enum {
PAGE_DISPLAY, PAGE_DISPLAY,
PAGE_YEAR, PAGE_YEAR,
PAGE_MONTH, PAGE_MONTH,
PAGE_DAY PAGE_DAY,
PAGE_DATE
} day_one_page_t; } day_one_page_t;
typedef struct { typedef struct {
@ -44,6 +45,7 @@ typedef struct {
uint8_t birth_day; uint8_t birth_day;
bool birthday_changed; bool birthday_changed;
bool quick_cycle; bool quick_cycle;
uint8_t ticks;
} day_one_state_t; } day_one_state_t;
void day_one_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr); void day_one_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);