refactor: watch faces no longer need a pointer to settings!

This commit is contained in:
joeycastillo
2024-09-29 09:59:49 -04:00
parent 3bd8f8d51f
commit e88359d1d5
201 changed files with 1180 additions and 1553 deletions

View File

@@ -26,8 +26,7 @@
#include <string.h>
#include "beeps_face.h"
void beeps_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void beeps_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(beeps_state_t));
@@ -36,8 +35,7 @@ void beeps_face_setup(movement_settings_t *settings, uint8_t watch_face_index, v
}
}
void beeps_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void beeps_face_activate(void *context) {
(void) context;
}
@@ -48,7 +46,7 @@ static void _beep_face_update_lcd(beeps_state_t *state) {
watch_display_string(buf, 0);
}
bool beeps_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
bool beeps_face_loop(movement_event_t event, void *context) {
beeps_state_t *state = (beeps_state_t *)context;
switch (event.event_type) {
@@ -237,13 +235,12 @@ bool beeps_face_loop(movement_event_t event, movement_settings_t *settings, void
}
break;
default:
return movement_default_loop_handler(event, settings);
return movement_default_loop_handler(event);
}
return true;
}
void beeps_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void beeps_face_resign(void *context) {
(void) context;
}

View File

@@ -44,10 +44,10 @@ typedef struct {
uint8_t frequency;
} beeps_state_t;
void beeps_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void beeps_face_activate(movement_settings_t *settings, void *context);
bool beeps_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void beeps_face_resign(movement_settings_t *settings, void *context);
void beeps_face_setup(uint8_t watch_face_index, void ** context_ptr);
void beeps_face_activate(void *context);
bool beeps_face_loop(movement_event_t event, void *context);
void beeps_face_resign(void *context);
#define beeps_face ((const watch_face_t){ \
beeps_face_setup, \

View File

@@ -27,21 +27,18 @@
#include "character_set_face.h"
#include "watch.h"
void character_set_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void character_set_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
if (*context_ptr == NULL) *context_ptr = malloc(sizeof(char));
}
void character_set_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void character_set_face_activate(void *context) {
char *c = (char *)context;
*c = '@';
movement_request_tick_frequency(0);
}
bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void) settings;
bool character_set_face_loop(movement_event_t event, void *context) {
char *c = (char *)context;
char buf[11];
switch (event.event_type) {
@@ -57,14 +54,13 @@ bool character_set_face_loop(movement_event_t event, movement_settings_t *settin
movement_move_to_face(0);
break;
default:
movement_default_loop_handler(event, settings);
movement_default_loop_handler(event);
break;
}
return true;
}
void character_set_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void character_set_face_resign(void *context) {
(void) context;
}

View File

@@ -38,10 +38,10 @@
#include "movement.h"
void character_set_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void character_set_face_activate(movement_settings_t *settings, void *context);
bool character_set_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void character_set_face_resign(movement_settings_t *settings, void *context);
void character_set_face_setup(uint8_t watch_face_index, void ** context_ptr);
void character_set_face_activate(void *context);
bool character_set_face_loop(movement_event_t event, void *context);
void character_set_face_resign(void *context);
#define character_set_face ((const watch_face_t){ \
character_set_face_setup, \

View File

@@ -96,8 +96,7 @@ static uint8_t short_data[] = {
static uint8_t *nanosec_buffer = 0;
static uint16_t nanosec_buffer_size = 0;
void chirpy_demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void **context_ptr) {
(void)settings;
void chirpy_demo_face_setup(uint8_t watch_face_index, void **context_ptr) {
(void)watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(chirpy_demo_state_t));
@@ -107,8 +106,7 @@ void chirpy_demo_face_setup(movement_settings_t *settings, uint8_t watch_face_in
// Do any pin or peripheral setup here; this will be called whenever the watch wakes from deep sleep.
}
void chirpy_demo_face_activate(movement_settings_t *settings, void *context) {
(void)settings;
void chirpy_demo_face_activate(void *context) {
chirpy_demo_state_t *state = (chirpy_demo_state_t *)context;
memset(context, 0, sizeof(chirpy_demo_state_t));
@@ -254,8 +252,7 @@ static void _cdm_setup_chirp(chirpy_demo_state_t *state) {
state->tick_state.tick_fun = _cdf_countdown_tick;
}
bool chirpy_demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void)settings;
bool chirpy_demo_face_loop(movement_event_t event, void *context) {
chirpy_demo_state_t *state = (chirpy_demo_state_t *)context;
switch (event.event_type) {
@@ -323,8 +320,7 @@ bool chirpy_demo_face_loop(movement_event_t event, movement_settings_t *settings
return true;
}
void chirpy_demo_face_resign(movement_settings_t *settings, void *context) {
(void)settings;
void chirpy_demo_face_resign(void *context) {
(void)context;
if (nanosec_buffer != 0) {

View File

@@ -52,10 +52,10 @@
#include "movement.h"
void chirpy_demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void chirpy_demo_face_activate(movement_settings_t *settings, void *context);
bool chirpy_demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void chirpy_demo_face_resign(movement_settings_t *settings, void *context);
void chirpy_demo_face_setup(uint8_t watch_face_index, void ** context_ptr);
void chirpy_demo_face_activate(void *context);
bool chirpy_demo_face_loop(movement_event_t event, void *context);
void chirpy_demo_face_resign(void *context);
#define chirpy_demo_face ((const watch_face_t){ \
chirpy_demo_face_setup, \

View File

@@ -43,8 +43,7 @@ typedef enum {
DEMO_FACE_NUM_FACES
} demo_face_index_t;
void demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void demo_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(demo_face_index_t));
@@ -52,8 +51,7 @@ void demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, vo
}
}
void demo_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void demo_face_activate(void *context) {
(void) context;
movement_request_tick_frequency(0);
// ensure the watch never enters low energy mode
@@ -61,8 +59,7 @@ void demo_face_activate(movement_settings_t *settings, void *context) {
movement_set_backlight_dwell(3);
}
bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void) settings;
bool demo_face_loop(movement_event_t event, void *context) {
demo_face_index_t *screen = (demo_face_index_t *)context;
switch (event.event_type) {
case EVENT_ALARM_BUTTON_UP:
@@ -123,14 +120,13 @@ bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void
// ignore timeout
break;
default:
movement_default_loop_handler(event, settings);
movement_default_loop_handler(event);
break;
}
return true;
}
void demo_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void demo_face_resign(void *context) {
(void) context;
}

View File

@@ -38,10 +38,10 @@
#include "movement.h"
void demo_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void demo_face_activate(movement_settings_t *settings, void *context);
bool demo_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void demo_face_resign(movement_settings_t *settings, void *context);
void demo_face_setup(uint8_t watch_face_index, void ** context_ptr);
void demo_face_activate(void *context);
bool demo_face_loop(movement_event_t event, void *context);
void demo_face_resign(void *context);
#define demo_face ((const watch_face_t){ \
demo_face_setup, \

View File

@@ -69,8 +69,7 @@ static void _disable_output() {
while (RTC->MODE2.SYNCBUSY.bit.ENABLE);
}
void frequency_correction_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void frequency_correction_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(frequency_correction_state_t));
@@ -79,14 +78,12 @@ void frequency_correction_face_setup(movement_settings_t *settings, uint8_t watc
}
}
void frequency_correction_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void frequency_correction_face_activate(void *context) {
frequency_correction_state_t *state = (frequency_correction_state_t *)context;
_enable_output(state->period_event_output);
}
bool frequency_correction_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void) settings;
bool frequency_correction_face_loop(movement_event_t event, void *context) {
frequency_correction_state_t *state = (frequency_correction_state_t *)context;
int8_t freqcorr;
@@ -123,15 +120,14 @@ bool frequency_correction_face_loop(movement_event_t event, movement_settings_t
watch_start_tick_animation(500);
break;
default:
movement_default_loop_handler(event, settings);
movement_default_loop_handler(event);
break;
}
return true;
}
void frequency_correction_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void frequency_correction_face_resign(void *context) {
(void) context;
_disable_output();
@@ -139,27 +135,23 @@ void frequency_correction_face_resign(movement_settings_t *settings, void *conte
#else
void frequency_correction_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void frequency_correction_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
(void) context_ptr;
}
void frequency_correction_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void frequency_correction_face_activate(void *context) {
(void) context;
}
bool frequency_correction_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void) settings;
bool frequency_correction_face_loop(movement_event_t event, void *context) {
(void) context;
(void) event;
return true;
}
void frequency_correction_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void frequency_correction_face_resign(void *context) {
(void) context;
}

View File

@@ -43,10 +43,10 @@ typedef struct {
uint8_t period_event_output;
} frequency_correction_state_t;
void frequency_correction_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void frequency_correction_face_activate(movement_settings_t *settings, void *context);
bool frequency_correction_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void frequency_correction_face_resign(movement_settings_t *settings, void *context);
void frequency_correction_face_setup(uint8_t watch_face_index, void ** context_ptr);
void frequency_correction_face_activate(void *context);
bool frequency_correction_face_loop(movement_event_t event, void *context);
void frequency_correction_face_resign(void *context);
#define frequency_correction_face ((const watch_face_t){ \
frequency_correction_face_setup, \

View File

@@ -27,10 +27,9 @@
#include "hello_there_face.h"
#include "watch.h"
void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
void hello_there_face_setup(uint8_t watch_face_index, void ** context_ptr) {
// These next two lines just silence the compiler warnings associated with unused parameters.
// We have no use for the settings or the watch_face_index, so we make that explicit here.
(void) settings;
(void) watch_face_index;
// At boot, context_ptr will be NULL indicating that we don't have anyplace to store our context.
if (*context_ptr == NULL) {
@@ -39,9 +38,8 @@ void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_in
}
}
void hello_there_face_activate(movement_settings_t *settings, void *context) {
void hello_there_face_activate(void *context) {
// same as above: silence the warning, we don't need to check the settings.
(void) settings;
// we do however need to set some things in our context. Here we cast it to the correct type...
hello_there_state_t *state = (hello_there_state_t *)context;
// ...and set the initial state of our watch face. We start out displaying the word 'Hello',
@@ -50,8 +48,7 @@ void hello_there_face_activate(movement_settings_t *settings, void *context) {
state->animating = true;
}
bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void) settings;
bool hello_there_face_loop(movement_event_t event, void *context) {
hello_there_state_t *state = (hello_there_state_t *)context;
switch (event.event_type) {
@@ -87,16 +84,15 @@ bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings
movement_move_to_face(0);
break;
default:
movement_default_loop_handler(event, settings);
movement_default_loop_handler(event);
break;
}
return true;
}
void hello_there_face_resign(movement_settings_t *settings, void *context) {
void hello_there_face_resign(void *context) {
// our watch face, like most watch faces, has nothing special to do when resigning.
// watch faces that enable a peripheral or interact with a sensor may want to turn it off here.
(void) settings;
(void) context;
}

View File

@@ -39,10 +39,10 @@ typedef struct {
bool animating;
} hello_there_state_t;
void hello_there_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void hello_there_face_activate(movement_settings_t *settings, void *context);
bool hello_there_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void hello_there_face_resign(movement_settings_t *settings, void *context);
void hello_there_face_setup(uint8_t watch_face_index, void ** context_ptr);
void hello_there_face_activate(void *context);
bool hello_there_face_loop(movement_event_t event, void *context);
void hello_there_face_resign(void *context);
#define hello_there_face ((const watch_face_t){ \
hello_there_face_setup, \

View File

@@ -36,7 +36,7 @@
// Pressing the alarm button enters the log mode, where the main display shows the number of interrupts detected in each of the last
// 24 hours (the hour is shown in the top right digit and AM/PM indicator, if the clock is set to 12 hour mode)
static void _lis2dw_logging_face_update_display(movement_settings_t *settings, lis2dw_logger_state_t *logger_state, lis2dw_wakeup_source wakeup_source) {
static void _lis2dw_logging_face_update_display(lis2dw_logger_state_t *logger_state, lis2dw_wakeup_source wakeup_source) {
char buf[14];
char time_indication_character;
int8_t pos;
@@ -111,8 +111,7 @@ static void _lis2dw_logging_face_log_data(lis2dw_logger_state_t *logger_state) {
logger_state->z_interrupts_this_hour = 0;
}
void lis2dw_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void lis2dw_logging_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
if (*context_ptr == NULL) {
*context_ptr = malloc(sizeof(lis2dw_logger_state_t));
@@ -128,15 +127,14 @@ void lis2dw_logging_face_setup(movement_settings_t *settings, uint8_t watch_face
}
}
void lis2dh_logging_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void lis2dh_logging_face_activate(void *context) {
lis2dh_logger_state_t *logger_state = (lis2dh_logger_state_t *)context;
logger_state->display_index = 0;
logger_state->log_ticks = 0;
watch_enable_digital_input(A4);
}
bool lis2dw_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
bool lis2dw_logging_face_loop(movement_event_t event, void *context) {
lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context;
lis2dw_wakeup_source wakeup_source = 0;
lis2dw_interrupt_source interrupt_source = 0;
@@ -145,13 +143,13 @@ bool lis2dw_logging_face_loop(movement_event_t event, movement_settings_t *setti
case EVENT_LIGHT_BUTTON_DOWN:
logger_state->axis_index = (logger_state->axis_index + 1) % 4;
logger_state->log_ticks = 255;
_lis2dw_logging_face_update_display(settings, logger_state, wakeup_source);
_lis2dw_logging_face_update_display(logger_state, wakeup_source);
break;
case EVENT_ALARM_BUTTON_UP:
if (logger_state->log_ticks) logger_state->display_index = (logger_state->display_index + 1) % LIS2DW_LOGGING_NUM_DATA_POINTS;
logger_state->log_ticks = 255;
logger_state->axis_index = 0;
_lis2dw_logging_face_update_display(settings, logger_state, wakeup_source);
_lis2dw_logging_face_update_display(logger_state, wakeup_source);
break;
case EVENT_ACTIVATE:
case EVENT_TICK:
@@ -171,27 +169,25 @@ bool lis2dw_logging_face_loop(movement_event_t event, movement_settings_t *setti
} else {
watch_clear_indicator(WATCH_INDICATOR_SIGNAL);
}
_lis2dw_logging_face_update_display(settings, logger_state, wakeup_source);
_lis2dw_logging_face_update_display(logger_state, wakeup_source);
break;
case EVENT_BACKGROUND_TASK:
_lis2dw_logging_face_log_data(logger_state);
break;
default:
movement_default_loop_handler(event, settings);
movement_default_loop_handler(event);
break;
}
return true;
}
void lis2dw_logging_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void lis2dw_logging_face_resign(void *context) {
(void) context;
watch_disable_digital_input(A4);
}
bool lis2dw_logging_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
bool lis2dw_logging_face_wants_background_task(void *context) {
lis2dw_logger_state_t *logger_state = (lis2dw_logger_state_t *)context;
watch_date_time date_time = watch_rtc_get_date_time();

View File

@@ -57,11 +57,11 @@ typedef struct {
lis2dw_logger_data_point_t data[LIS2DW_LOGGING_NUM_DATA_POINTS];
} lis2dw_logger_state_t;
void lis2dw_logging_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void lis2dw_logging_face_activate(movement_settings_t *settings, void *context);
bool lis2dw_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void lis2dw_logging_face_resign(movement_settings_t *settings, void *context);
bool lis2dw_logging_face_wants_background_task(movement_settings_t *settings, void *context);
void lis2dw_logging_face_setup(uint8_t watch_face_index, void ** context_ptr);
void lis2dw_logging_face_activate(void *context);
bool lis2dw_logging_face_loop(movement_event_t event, void *context);
void lis2dw_logging_face_resign(void *context);
bool lis2dw_logging_face_wants_background_task(void *context);
#define lis2dw_logging_face ((const watch_face_t){ \
lis2dw_logging_face_setup, \

View File

@@ -39,19 +39,16 @@ static void _voltage_face_update_display(void) {
watch_display_string(buf, 0);
}
void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr) {
(void) settings;
void voltage_face_setup(uint8_t watch_face_index, void ** context_ptr) {
(void) watch_face_index;
(void) context_ptr;
}
void voltage_face_activate(movement_settings_t *settings, void *context) {
(void) settings;
void voltage_face_activate(void *context) {
(void) context;
}
bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
(void) settings;
bool voltage_face_loop(movement_event_t event, void *context) {
(void) context;
watch_date_time date_time;
switch (event.event_type) {
@@ -81,14 +78,13 @@ bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, vo
}
break;
default:
movement_default_loop_handler(event, settings);
movement_default_loop_handler(event);
break;
}
return true;
}
void voltage_face_resign(movement_settings_t *settings, void *context) {
(void) settings;
void voltage_face_resign(void *context) {
(void) context;
}

View File

@@ -38,10 +38,10 @@
#include "movement.h"
void voltage_face_setup(movement_settings_t *settings, uint8_t watch_face_index, void ** context_ptr);
void voltage_face_activate(movement_settings_t *settings, void *context);
bool voltage_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void voltage_face_resign(movement_settings_t *settings, void *context);
void voltage_face_setup(uint8_t watch_face_index, void ** context_ptr);
void voltage_face_activate(void *context);
bool voltage_face_loop(movement_event_t event, void *context);
void voltage_face_resign(void *context);
#define voltage_face ((const watch_face_t){ \
voltage_face_setup, \