Added clock.

This commit is contained in:
imi415 2022-01-01 17:11:20 +08:00
parent 85ce092f39
commit f531b89c4d
Signed by: imi415
GPG Key ID: 17F01E106F9F5E0A
14 changed files with 102 additions and 13 deletions

View File

@ -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"

View File

@ -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;

View File

View File

View File

@ -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;
}

View File

@ -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;

View File

@ -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;
}

View File

View File

View File

@ -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()`*/

View File

@ -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 (;;) {

View File

@ -0,0 +1,65 @@
#include "service_clock.h"
#include <time.h>
#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;
}

View File

@ -0,0 +1,8 @@
#ifndef SERVICE_CLOCK_H
#define SERVICE_CLOCK_H
#include "esp_system.h"
esp_err_t service_clock_init(void);
#endif

View File

@ -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));