/* * SPDX-FileCopyrightText: 2022 Helmut Pozimski * * SPDX-License-Identifier: GPL-2.0-only */ #include #include #include #include #include "tm1637.h" #include "ds3231.h" #include "configuration.h" static void update_display(uint8_t hour, uint8_t minute) { if (hour < 10) { tm1637_set_segment(10, 0, 1); tm1637_set_segment(hour, 1, 1); } else { tm1637_set_segment(hour / 10, 0, 1); tm1637_set_segment(hour % 10, 1, 1); } if (minute < 10) { tm1637_set_segment(0, 2, 1); tm1637_set_segment(minute, 3, 1); } else { tm1637_set_segment(minute / 10, 2, 1); tm1637_set_segment(minute % 10, 3, 1); } } static struct tm *convert_to_local(struct tm *timeinfo) { setenv("TZ", "GMT+0GMT+0", 1); tzset(); time_t epoch_time = mktime(timeinfo); setenv("TZ", LOCAL_TIMEZONE, 1); tzset(); return localtime(&epoch_time); } static uint8_t max(uint8_t a, uint8_t b) { return (a > b) ? a : b; } static uint8_t determine_sleep_time(struct tm *local_time) { uint8_t wakeup_time_sec; wakeup_time_sec = 60 - local_time->tm_sec; wakeup_time_sec = max(wakeup_time_sec, 1); return wakeup_time_sec; } void display_update_task(void *pvParameters) { struct tm current_time; while(1) { ds3231_read_date_time(¤t_time); struct tm *local_time = convert_to_local(¤t_time); update_display(local_time->tm_hour, local_time->tm_min); vTaskDelay(determine_sleep_time(local_time) / portTICK_PERIOD_MS); } vTaskDelete( NULL ); }