Move time update logic from display module to time manager

This commit is contained in:
2023-05-17 17:55:13 +01:00
parent d84bb7ac4b
commit 89eb99b80f
5 changed files with 57 additions and 26 deletions

View File

@@ -16,7 +16,6 @@
#define TAG "Display"
#define DRIVER_TASK_PERIOD_US 4000UL
#define TIME_UPDATE_PERIOD_US 1000000UL
#define CLAMP(x, lim) ((x) > (lim) ? (lim) : (x))
@@ -52,11 +51,9 @@ static void show_time(unsigned hour, unsigned minute)
show_digit(DISPLAY_DIGIT_4, minute % 10);
}
static void update_time(void *arg)
static void update_time(const Time *time)
{
(void)arg;
const Time time = get_time();
show_time(time.hour, time.minute);
show_time(time->hour, time->minute);
}
void display_init()
@@ -83,23 +80,5 @@ void display_init()
FATAL();
}
esp_timer_handle_t update_timer;
const esp_timer_create_args_t update_timer_config = {
.callback = &update_time,
.arg = NULL,
.name = "display driver task",
};
error = esp_timer_create(&update_timer_config, &update_timer);
if (error != ESP_OK) {
ESP_LOGE(TAG, "Error creating timer for driver task: %04x", error);
FATAL();
}
error = esp_timer_start_periodic(update_timer, TIME_UPDATE_PERIOD_US);
if (error != ESP_OK) {
ESP_LOGE(TAG, "Error starting timer for driver task: %04x", error);
FATAL();
}
update_time(NULL);
add_time_callback(&update_time);
}