feat(protocol): 添加时间同步和主题颜色协议支持
- 添加CDC_PROTO_TYPE_LED_STATE、CDC_PROTO_TYPE_TIME_SYNC和 CDC_PROTO_TYPE_THEME_RGB协议类型定义 - 在protobuf中定义LedState、TimeSync和ThemeRgb消息结构 - 更新CdcPacketBody消息以包含新的协议类型 - 增加协议能力标志位以支持新功能
This commit is contained in:
@@ -14,8 +14,10 @@
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
#include "bat_state_event.h"
|
||||
#include "datetime_event.h"
|
||||
#include "hid_led_event.h"
|
||||
#include "mode_switch_event.h"
|
||||
#include "theme_rgb_update_event.h"
|
||||
#include "theme_color.h"
|
||||
#include "ui/ui_main.h"
|
||||
|
||||
@@ -40,6 +42,8 @@ static struct ui_main_model ui_model = {
|
||||
static bool initialized;
|
||||
static bool running;
|
||||
static bool lvgl_initialized;
|
||||
static char date_text[DATETIME_EVENT_DATE_TEXT_LEN] = "1970/01/01";
|
||||
static char time_text[DATETIME_EVENT_TIME_TEXT_LEN] = "00:00:00";
|
||||
|
||||
static int backlight_set(bool on)
|
||||
{
|
||||
@@ -93,7 +97,7 @@ static int module_start(void)
|
||||
lvgl_initialized = true;
|
||||
|
||||
lvgl_lock();
|
||||
ui_main_init(&ui_model, "WH Mini", "Hello World");
|
||||
ui_main_init(&ui_model, date_text, time_text);
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
@@ -135,7 +139,7 @@ static void refresh_ui(void)
|
||||
}
|
||||
|
||||
lvgl_lock();
|
||||
ui_main_refresh_all(&ui_model, "WH Mini", "Hello World");
|
||||
ui_main_refresh_all(&ui_model, date_text, time_text);
|
||||
lvgl_unlock();
|
||||
}
|
||||
|
||||
@@ -167,6 +171,28 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_theme_rgb_update_event(aeh)) {
|
||||
const struct theme_rgb_update_event *event =
|
||||
cast_theme_rgb_update_event(aeh);
|
||||
|
||||
ui_model.theme_color = (lv_color_t)LV_COLOR_MAKE(event->theme.r,
|
||||
event->theme.g,
|
||||
event->theme.b);
|
||||
refresh_ui();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_datetime_event(aeh)) {
|
||||
const struct datetime_event *event = cast_datetime_event(aeh);
|
||||
|
||||
strncpy(date_text, event->date_text, sizeof(date_text));
|
||||
date_text[sizeof(date_text) - 1] = '\0';
|
||||
strncpy(time_text, event->time_text, sizeof(time_text));
|
||||
time_text[sizeof(time_text) - 1] = '\0';
|
||||
refresh_ui();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (is_module_state_event(aeh)) {
|
||||
const struct module_state_event *event = cast_module_state_event(aeh);
|
||||
int err;
|
||||
@@ -221,8 +247,10 @@ static bool app_event_handler(const struct app_event_header *aeh)
|
||||
|
||||
APP_EVENT_LISTENER(MODULE, app_event_handler);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, bat_state_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, datetime_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, hid_led_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, module_state_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, mode_switch_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, theme_rgb_update_event);
|
||||
APP_EVENT_SUBSCRIBE_EARLY(MODULE, power_down_event);
|
||||
APP_EVENT_SUBSCRIBE(MODULE, wake_up_event);
|
||||
|
||||
Reference in New Issue
Block a user