diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index 7a41015..7887b6e 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -4,7 +4,6 @@ idf_component_register(SRCS "assets/fonts/bebas_neue/bebas_neue_120.c" "assets/fonts/material_webfont/material_webfont_32.c" "main.c" - "service/service_wifi.c" "impl/impl_btn.c" "impl/impl_dht.c" "impl/impl_epd.c" @@ -166,7 +165,9 @@ idf_component_register(SRCS "lib/lvgl/src/widgets/lv_switch.c" "lib/lvgl/src/widgets/lv_table.c" "lib/lvgl/src/widgets/lv_textarea.c" + "service/service_clock.c" "service/service_dht.c" + "service/service_wifi.c" INCLUDE_DIRS "lib" diff --git a/main/impl/impl_lvgl.c b/main/impl/impl_lvgl.c index f5826bc..fe94010 100644 --- a/main/impl/impl_lvgl.c +++ b/main/impl/impl_lvgl.c @@ -230,7 +230,7 @@ esp_err_t impl_lvgl_init(void) { lv_theme_t *default_theme = lv_theme_mono_init(disp, false, &lv_font_unscii_16); lv_disp_set_theme(disp, default_theme); - s_lv_semphr_handle = xSemaphoreCreateBinary(); + s_lv_semphr_handle = xSemaphoreCreateMutex(); if (s_lv_semphr_handle == NULL) { ESP_LOGE(LOG_TAG, "LVGL semaphore creation failed."); return ESP_FAIL; diff --git a/main/interface/if_battery.c b/main/interface/if_battery.c new file mode 100644 index 0000000..e69de29 diff --git a/main/interface/if_battery.h b/main/interface/if_battery.h new file mode 100644 index 0000000..e69de29 diff --git a/main/interface/if_standby.c b/main/interface/if_standby.c index a1766b1..9381df7 100644 --- a/main/interface/if_standby.c +++ b/main/interface/if_standby.c @@ -159,7 +159,18 @@ void if_standby_task(void *pvParameters) { case IF_STANDBY_ITEM_HUMID: lv_label_set_text(humid_label, queue_item.payload); lv_obj_align(humid_label, LV_ALIGN_CENTER, 0, 16); - + break; + case IF_STANDBY_ITEM_TIME: + lv_label_set_text(time_label, queue_item.payload); + lv_obj_set_align(time_label, LV_ALIGN_CENTER); + break; + case IF_STANDBY_ITEM_DATE: + lv_label_set_text(date_label, queue_item.payload); + lv_obj_set_align(date_label, LV_ALIGN_CENTER); + break; + case IF_STANDBY_ITEM_WEEKDAY: + lv_label_set_text(weekday_label, queue_item.payload); + lv_obj_set_align(weekday_label, LV_ALIGN_CENTER); break; default: break; @@ -175,7 +186,7 @@ esp_err_t if_standby_init(void) { impl_lvgl_unlock(); g_standby_screen_queue = xQueueCreate(8, sizeof(if_standby_queue_t)); - if(g_standby_screen_queue == NULL) { + if (g_standby_screen_queue == NULL) { return ESP_FAIL; } diff --git a/main/interface/if_standby.h b/main/interface/if_standby.h index 83315a5..e3795ac 100644 --- a/main/interface/if_standby.h +++ b/main/interface/if_standby.h @@ -8,6 +8,8 @@ #include "lvgl.h" +#define IF_STANDBY_PAYLOAD_LENGTH 16 + typedef enum { IF_STANDBY_ITEM_WIFI, IF_STANDBY_ITEM_WEEKDAY, @@ -20,7 +22,7 @@ typedef enum { typedef struct { if_standby_item_t item; - char payload[16]; + char payload[IF_STANDBY_PAYLOAD_LENGTH]; } if_standby_queue_t; extern lv_obj_t *g_standby_screen; diff --git a/main/interface/if_wifi.c b/main/interface/if_wifi.c index c72f3ba..0b08b7f 100644 --- a/main/interface/if_wifi.c +++ b/main/interface/if_wifi.c @@ -2,6 +2,11 @@ #include "esp_system.h" + +void if_wifi_task(void *pvParameters) { + +} + /** * @brief Initialize WiFi status/configuration component * @@ -11,8 +16,3 @@ esp_err_t if_wifi_init(lv_obj_t *parent_obj) { return ESP_OK; } - -esp_err_t if_wifi_destroy(void) { - // - return ESP_OK; -} \ No newline at end of file diff --git a/main/lib/ltc2941/ltc2941.c b/main/lib/ltc2941/ltc2941.c new file mode 100644 index 0000000..e69de29 diff --git a/main/lib/ltc2941/ltc2941.h b/main/lib/ltc2941/ltc2941.h new file mode 100644 index 0000000..e69de29 diff --git a/main/lib/lv_conf.h b/main/lib/lv_conf.h index 81f17ce..acfb759 100644 --- a/main/lib/lv_conf.h +++ b/main/lib/lv_conf.h @@ -181,7 +181,7 @@ e.g. "stm32f769xx.h" or "stm32f429xx.h"*/ *LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail *LV_LOG_LEVEL_USER Only logs added by the user *LV_LOG_LEVEL_NONE Do not log anything*/ -# define LV_LOG_LEVEL LV_LOG_LEVEL_INFO +# define LV_LOG_LEVEL LV_LOG_LEVEL_WARN /*1: Print the log with 'printf'; *0: User need to register a callback with `lv_log_register_print_cb()`*/ diff --git a/main/main.c b/main/main.c index 45b3520..2c165d6 100644 --- a/main/main.c +++ b/main/main.c @@ -13,6 +13,7 @@ #include "if_standby.h" #include "impl_lvgl.h" #include "service_dht.h" +#include "service_clock.h" #define APP_I2C_MASTER_NUM 0 #define APP_I2C_SDA_NUM GPIO_NUM_39 @@ -59,6 +60,7 @@ void app_main(void) { ESP_ERROR_CHECK(if_standby_init()); ESP_ERROR_CHECK(service_dht_init()); + ESP_ERROR_CHECK(service_clock_init()); /* Dead loop */ for (;;) { diff --git a/main/service/service_clock.c b/main/service/service_clock.c new file mode 100644 index 0000000..2a83fc8 --- /dev/null +++ b/main/service/service_clock.c @@ -0,0 +1,65 @@ +#include "service_clock.h" + +#include + +#include "esp_log.h" +#include "if_standby.h" + +#define LOG_TAG "SERVICE_CLOCK" + +static TaskHandle_t s_clock_task_handle; + +static char *s_wday_array[] = {"SUN", "MON", "TUE", "WED", "THU", "FRI"}; + +void clock_task(void *pvParameters) { + struct tm timeinfo; + time_t now; + + uint8_t prev_min = 0xFF; + uint8_t prev_mday = 0xFF; + uint8_t prev_wday = 0xFF; + + if_standby_queue_t queue_item; + + setenv("TZ", "CST-8", 1); + tzset(); + + for (;;) { + time(&now); + localtime_r(&now, &timeinfo); + + if ((timeinfo.tm_min != prev_min) || (prev_min == 0xFF)) { + queue_item.item = IF_STANDBY_ITEM_TIME; + snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%02u:%02u", timeinfo.tm_hour, timeinfo.tm_min); + xQueueSendToBack(g_standby_screen_queue, &queue_item, 0); + + prev_min = timeinfo.tm_min; + } + if ((timeinfo.tm_mday != prev_mday) || (prev_mday == 0xFF)) { + queue_item.item = IF_STANDBY_ITEM_DATE; + snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%04u/%02d/%02d", + (uint16_t)(timeinfo.tm_year + 1900), (uint8_t)(timeinfo.tm_mon + 1), (uint8_t)timeinfo.tm_mday); + xQueueSendToBack(g_standby_screen_queue, &queue_item, 0); + + prev_mday = timeinfo.tm_mday; + } + if ((timeinfo.tm_wday != prev_wday) || (prev_wday == 0xFF)) { + queue_item.item = IF_STANDBY_ITEM_WEEKDAY; + memcpy(queue_item.payload, s_wday_array[timeinfo.tm_wday], 4); + xQueueSendToBack(g_standby_screen_queue, &queue_item, 0); + + prev_wday = timeinfo.tm_wday; + } + + // TODO: Set an alarm at 0sec every 1 minute. + vTaskDelay(pdMS_TO_TICKS(200)); + } +} + +esp_err_t service_clock_init(void) { + if (xTaskCreate(clock_task, "CLOCK", 2048, NULL, 6, &s_clock_task_handle) != pdTRUE) { + return ESP_FAIL; + } + + return ESP_OK; +} \ No newline at end of file diff --git a/main/service/service_clock.h b/main/service/service_clock.h new file mode 100644 index 0000000..7099eb1 --- /dev/null +++ b/main/service/service_clock.h @@ -0,0 +1,8 @@ +#ifndef SERVICE_CLOCK_H +#define SERVICE_CLOCK_H + +#include "esp_system.h" + +esp_err_t service_clock_init(void); + +#endif \ No newline at end of file diff --git a/main/service/service_dht.c b/main/service/service_dht.c index eebcdf3..40204bd 100644 --- a/main/service/service_dht.c +++ b/main/service/service_dht.c @@ -29,11 +29,11 @@ void dht_task(void *pvParameters) { } queue_item.item = IF_STANDBY_ITEM_TEMP, - snprintf(queue_item.payload, 16, "%.2f", result.temperature); + snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%.2f", result.temperature); xQueueSendToBack(g_standby_screen_queue, &queue_item, 0); queue_item.item = IF_STANDBY_ITEM_HUMID; - snprintf(queue_item.payload, 16, "%.2f", result.humidity); + snprintf(queue_item.payload, IF_STANDBY_PAYLOAD_LENGTH, "%.2f", result.humidity); xQueueSendToBack(g_standby_screen_queue, &queue_item, 0); vTaskDelay(pdMS_TO_TICKS(30000));