add movement_default_loop_handler, test with default watch faces

This commit is contained in:
joeycastillo 2023-01-14 14:21:04 -05:00
parent 9ebea46300
commit 0ef80b62da
10 changed files with 44 additions and 41 deletions

View file

@ -218,6 +218,26 @@ void movement_illuminate_led(void) {
}
}
bool movement_default_loop_handler(movement_event_t event, movement_settings_t *settings) {
(void)settings;
switch (event.event_type) {
case EVENT_MODE_BUTTON_UP:
movement_move_to_next_face();
break;
case EVENT_LIGHT_BUTTON_DOWN:
movement_illuminate_led();
break;
case EVENT_MODE_LONG_PRESS:
movement_move_to_face(0);
break;
default:
break;
}
return true;
}
void movement_move_to_face(uint8_t watch_face_index) {
movement_state.watch_face_changed = true;
movement_state.next_watch_face = watch_face_index;

View file

@ -285,6 +285,9 @@ typedef struct {
void movement_move_to_face(uint8_t watch_face_index);
void movement_move_to_next_face(void);
bool movement_default_loop_handler(movement_event_t event, movement_settings_t *settings);
void movement_illuminate_led(void);
void movement_request_tick_frequency(uint8_t freq);

View file

@ -53,13 +53,10 @@ bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t *
case EVENT_TICK:
// If needed, update your display here.
break;
case EVENT_MODE_BUTTON_UP:
// You shouldn't need to change this case; Mode almost always moves to the next watch face.
movement_move_to_next_face();
break;
case EVENT_LIGHT_BUTTON_UP:
// If you have other uses for the Light button, you can opt not to illuminate the LED for this event.
movement_illuminate_led();
// You can use the Light button for your own purposes. Note that by default, Movement will also
// illuminatethe LED in response to EVENT_LIGHT_BUTTON_DOWN; to suppress that behavior, add an
// empty case for EVENT_LIGHT_BUTTON_DOWN.
break;
case EVENT_ALARM_BUTTON_UP:
// Just in case you have need for another button.
@ -76,7 +73,12 @@ bool <#watch_face_name#>_face_loop(movement_event_t event, movement_settings_t *
// watch_start_tick_animation(500);
break;
default:
break;
// Movement's default loop handler will step in for any cases you don't handle above:
// * EVENT_LIGHT_BUTTON_DOWN lights the LED
// * EVENT_ALARM_BUTTON_UP moves to the next watch face in the list
// * EVENT_MODE_LONG_PRESS returns to the first watch face in the list
// You can override any of these behaviors by adding a case for these events to this switch statement.
return movement_default_loop_handler(event, settings);
}
// return true if the watch can enter standby mode. If you are PWM'ing an LED or buzzing the buzzer here,

View file

@ -128,12 +128,6 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
// handle alarm indicator
if (state->alarm_enabled != settings->bit.alarm_enabled) _update_alarm_indicator(settings->bit.alarm_enabled, state);
break;
case EVENT_MODE_BUTTON_UP:
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_DOWN:
movement_illuminate_led();
break;
case EVENT_ALARM_LONG_PRESS:
state->signal_enabled = !state->signal_enabled;
if (state->signal_enabled) watch_set_indicator(WATCH_INDICATOR_BELL);
@ -145,7 +139,7 @@ bool simple_clock_face_loop(movement_event_t event, movement_settings_t *setting
movement_play_signal();
break;
default:
break;
return movement_default_loop_handler(event, settings);
}
return true;

View file

@ -113,18 +113,12 @@ static bool world_clock_face_do_display_mode(movement_event_t event, movement_se
}
watch_display_string(buf, pos);
break;
case EVENT_MODE_BUTTON_UP:
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_DOWN:
movement_illuminate_led();
break;
case EVENT_ALARM_LONG_PRESS:
movement_request_tick_frequency(4);
state->current_screen = 1;
break;
default:
break;
return movement_default_loop_handler(event, settings);
}
return true;

View file

@ -155,12 +155,6 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings,
watch_display_string(" ", 8);
if (!watch_tick_animation_is_running()) watch_start_tick_animation(1000);
break;
case EVENT_MODE_BUTTON_UP:
movement_move_to_next_face();
break;
case EVENT_LIGHT_BUTTON_DOWN:
movement_illuminate_led();
break;
case EVENT_ALARM_BUTTON_UP:
// Pressing the alarm adds an offset of one day to the displayed value,
// so you can see moon phases in the future.
@ -171,7 +165,7 @@ bool moon_phase_face_loop(movement_event_t event, movement_settings_t *settings,
// QUESTION: Should timeout reset offset to 0?
break;
default:
break;
return movement_default_loop_handler(event, settings);
}
return true;

View file

@ -107,9 +107,6 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings,
_stopwatch_face_update_display(stopwatch_state, true);
}
break;
case EVENT_MODE_BUTTON_UP:
movement_move_to_next_face();
break;
case EVENT_LIGHT_BUTTON_DOWN:
movement_illuminate_led();
if (!stopwatch_state->running) {
@ -161,7 +158,7 @@ bool stopwatch_face_loop(movement_event_t event, movement_settings_t *settings,
}
break;
default:
break;
return movement_default_loop_handler(event, settings);
}
return true;

View file

@ -339,9 +339,6 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti
_sunrise_sunset_face_update_settings_display(event, state);
}
break;
case EVENT_MODE_BUTTON_UP:
movement_move_to_next_face();
break;
case EVENT_LIGHT_BUTTON_DOWN:
if (state->page) {
state->active_digit++;
@ -360,8 +357,6 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti
_sunrise_sunset_face_update(settings, state);
}
break;
case EVENT_LIGHT_BUTTON_UP:
break;
case EVENT_ALARM_BUTTON_UP:
if (state->page) {
_sunrise_sunset_face_advance_digit(state);
@ -393,7 +388,7 @@ bool sunrise_sunset_face_loop(movement_event_t event, movement_settings_t *setti
}
break;
default:
break;
return movement_default_loop_handler(event, settings);
}
return true;

View file

@ -56,11 +56,15 @@ void preferences_face_activate(movement_settings_t *settings, void *context) {
bool preferences_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
uint8_t current_page = *((uint8_t *)context);
switch (event.event_type) {
case EVENT_TICK:
case EVENT_ACTIVATE:
// Do nothing; handled below.
break;
case EVENT_MODE_BUTTON_UP:
watch_set_led_off();
movement_move_to_next_face();
return false;
case EVENT_LIGHT_BUTTON_UP:
case EVENT_LIGHT_BUTTON_DOWN:
current_page = (current_page + 1) % PREFERENCES_FACE_NUM_PREFEFENCES;
*((uint8_t *)context) = current_page;
break;
@ -93,7 +97,7 @@ bool preferences_face_loop(movement_event_t event, movement_settings_t *settings
movement_move_to_face(0);
break;
default:
break;
return movement_default_loop_handler(event, settings);
}
watch_display_string((char *)preferences_face_titles[current_page], 0);

View file

@ -128,7 +128,7 @@ bool set_time_face_loop(movement_event_t event, movement_settings_t *settings, v
movement_move_to_face(0);
break;
default:
break;
return movement_default_loop_handler(event, settings);
}
char buf[11];