movement: first crack at background tasks API

This commit is contained in:
Joey Castillo
2021-10-23 17:55:19 -04:00
parent ee1b3c8780
commit 8475ffcd7a
4 changed files with 41 additions and 13 deletions

View File

@@ -63,7 +63,6 @@ void thermistor_logging_face_activate(movement_settings_t *settings, void *conte
bool thermistor_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context) {
thermistor_logger_state_t *logger_state = (thermistor_logger_state_t *)context;
watch_date_time date_time = watch_rtc_get_date_time();
switch (event.event_type) {
case EVENT_TIMEOUT:
movement_move_to_face(0);
@@ -90,11 +89,9 @@ bool thermistor_logging_face_loop(movement_event_t event, movement_settings_t *s
if (logger_state->ts_ticks && --logger_state->ts_ticks == 0) {
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, settings->bit.clock_mode_24h);
}
// this is just temporary for testing: log a data point every 30 seconds.
if (date_time.unit.second % 30 == 0 && !logger_state->ts_ticks) {
_thermistor_logging_face_log_data(logger_state);
_thermistor_logging_face_update_display(logger_state, settings->bit.use_imperial_units, settings->bit.clock_mode_24h);
}
break;
case EVENT_BACKGROUND_TASK:
_thermistor_logging_face_log_data(logger_state);
break;
default:
break;
@@ -107,3 +104,11 @@ void thermistor_logging_face_resign(movement_settings_t *settings, void *context
(void) settings;
(void) context;
}
bool thermistor_logging_face_wants_background_task(movement_settings_t *settings, void *context) {
(void) settings;
(void) context;
// this will get called at the top of each minute, so all we check is if we're at the top of the hour as well.
// if we are, we ask for a background task.
return watch_rtc_get_date_time().unit.minute == 0;
}

View File

@@ -22,13 +22,14 @@ void thermistor_logging_face_setup(movement_settings_t *settings, void ** contex
void thermistor_logging_face_activate(movement_settings_t *settings, void *context);
bool thermistor_logging_face_loop(movement_event_t event, movement_settings_t *settings, void *context);
void thermistor_logging_face_resign(movement_settings_t *settings, void *context);
bool thermistor_logging_face_wants_background_task(movement_settings_t *settings, void *context);
static const watch_face_t thermistor_logging_face = {
thermistor_logging_face_setup,
thermistor_logging_face_activate,
thermistor_logging_face_loop,
thermistor_logging_face_resign,
NULL
thermistor_logging_face_wants_background_task
};
#endif // THERMISTOR_LOGGING_FACE_H_