From 8475ffcd7aaebcbf17c7188ef96ce01a9730e9b3 Mon Sep 17 00:00:00 2001 From: Joey Castillo Date: Sat, 23 Oct 2021 17:55:19 -0400 Subject: movement: first crack at background tasks API --- .../watch_faces/thermistor/thermistor_logging_face.c | 17 +++++++++++------ .../watch_faces/thermistor/thermistor_logging_face.h | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) (limited to 'movement/watch_faces') diff --git a/movement/watch_faces/thermistor/thermistor_logging_face.c b/movement/watch_faces/thermistor/thermistor_logging_face.c index 1ff20483..5351ce88 100644 --- a/movement/watch_faces/thermistor/thermistor_logging_face.c +++ b/movement/watch_faces/thermistor/thermistor_logging_face.c @@ -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; +} diff --git a/movement/watch_faces/thermistor/thermistor_logging_face.h b/movement/watch_faces/thermistor/thermistor_logging_face.h index 43d441be..ece89396 100644 --- a/movement/watch_faces/thermistor/thermistor_logging_face.h +++ b/movement/watch_faces/thermistor/thermistor_logging_face.h @@ -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_ -- cgit v1.2.3