Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/boards/sf32lb52-xty-ai_base/bsp_pinmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,15 @@ static void BSP_PIN_Common(void)
HAL_PIN_Set(PAD_PA21, GPIO_A21, PIN_PULLDOWN, 1);
#endif

HAL_PIN_Set(PAD_PA11, GPIO_A11, PIN_PULLDOWN, 1); // 漏电
#ifdef BSP_USING_BOARD_SF32LB52_XTY_AI_THT
HAL_PIN_Set(PAD_PA38, GPIO_A38, PIN_PULLDOWN, 1); // 漏电
HAL_PIN_Set(PAD_PA40, GPIO_A40, PIN_PULLDOWN, 1); // 漏电
#else
HAL_PIN_Set(PAD_PA38, GPIO_A38, PIN_PULLUP, 1); // 漏电
HAL_PIN_Set(PAD_PA40, GPIO_A40, PIN_PULLUP, 1); // 漏电
#endif

HAL_PIN_Set(PAD_PA11, GPIO_A11, PIN_PULLDOWN, 1); // 漏电
#endif

}
Expand Down
7 changes: 4 additions & 3 deletions app/src/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ CPPDEFINES += ['MBEDTLS_PLATFORM_MEMORY']

cwd = GetCurrentDir()
CPPPATH = [cwd]
libpath = [cwd]
CPPPATH += [cwd + '/et_config']
libpath = [cwd + '/kws']
CPPPATH += [cwd + '/kws']
# Add source code
src = Glob('*.c')
src = src + Glob('./mcp/*.cc')
src = src + Glob('./iot/*.cc')
src = src + Glob('./iot/*.cc')
src = src + Glob('./kws/*.c')
#SrcRemove(src, 'xiaozhi.c')

group = DefineGroup('Applications', src, depend = [''], CPPDEFINES = CPPDEFINES,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include "et_keyword.h"
#include "et_thres_list.h"
#include "et_weights.h"
#include "et_config/third_kws_event.h"
#include "third_kws_event.h"
#include "xiaozhi_public.h"
extern void simulate_button_pressed();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
64 changes: 61 additions & 3 deletions app/src/mcp/mcp_server.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
// #include "lwip/apps/websocket_client.h" // 提供 wsock_write 和 OPCODE_TEXT 定义
#include "../xiaozhi2.h" // 提供 g_xz_ws 定义
extern xiaozhi_ws_t g_xz_ws;

extern uint8_t aec_enabled;
extern uint8_t vad_enable;
extern "C" {
extern void xiaozhi_ui_update_volume(int volume);
extern void xiaozhi_ui_update_brightness(int brightness);
extern void ctrl_wakeup(bool is_wakeup);
extern void ctrl_interrupt(bool is_interrupt);
}


Expand Down Expand Up @@ -112,8 +115,63 @@ void McpServer::AddCommonTools() {
});
}

// 添加RGB LED工具
RGBLEDTool::RegisterRGBLEDTool(this);
// 添加RGB LED工具
RGBLEDTool::RegisterRGBLEDTool(this);

//添加唤醒工具
AddTool("self.wakeup.enable",
"Enable the wakeup function.",
PropertyList(),
[=](const PropertyList&) -> ReturnValue
{
ctrl_wakeup(true);
return true;
});

AddTool("self.wakeup.disable",
"Disable the wakeup function.",
PropertyList(),
[=](const PropertyList&) -> ReturnValue
{
ctrl_wakeup(false);
return true;
});

AddTool("self.wakeup.get_status",
"Get the current status of the wakeup function.",
PropertyList(),
[=](const PropertyList&) -> ReturnValue
{
return (bool)aec_enabled;
});

// 添加打断功能控制工具
AddTool("self.interrupt.enable",
"Enable the interrupt function.",
PropertyList(),
[=](const PropertyList&) -> ReturnValue
{
ctrl_interrupt(true);
return true;
});

AddTool("self.interrupt.disable",
"Disable the interrupt function.",
PropertyList(),
[=](const PropertyList&) -> ReturnValue
{
ctrl_interrupt(false);
return true;
});

AddTool("self.interrupt.get_status",
"Get the current status of the interrupt function.",
PropertyList(),
[=](const PropertyList&) -> ReturnValue
{
// 注意:vad_enable为1表示不打断,为0表示可打断
return (bool)(!vad_enable);
});

#endif
// Restore the original tools list to the end of the tools list
Expand Down
11 changes: 6 additions & 5 deletions app/src/xiaozhi2.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,11 +387,7 @@ static void xz_button2_event_handler(int32_t pin, button_action_t action)
{
if (action == BUTTON_PRESSED)
{
lv_obj_t *now_screen = lv_screen_active();
if (now_screen != standby_screen)
{
rt_sem_release(g_activation_context.sem);
}

rt_kprintf("xz_button2_event_handler - pressed\n");
}
else if (action == BUTTON_LONG_PRESSED)
Expand All @@ -405,6 +401,11 @@ static void xz_button2_event_handler(int32_t pin, button_action_t action)
// }

// 长按3秒,直接发送关机消息到ui_task
lv_obj_t *now_screen = lv_screen_active();
if (now_screen != standby_screen)
{
rt_sem_release(g_activation_context.sem);
}
rt_mb_send(g_ui_task_mb, UI_EVENT_SHUTDOWN);
}

Expand Down
44 changes: 40 additions & 4 deletions app/src/xiaozhi_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ rt_mq_t ui_msg_queue = RT_NULL;
#define LCD_DEVICE_NAME "lcd"
#define TOUCH_NAME "touch"
rt_mailbox_t g_ui_task_mb =RT_NULL;
static lv_obj_t* wakeup_switch = NULL;
static lv_obj_t* interrupt_switch = NULL;
// 开机动画相关全局变量
static struct rt_semaphore update_ui_sema;
extern const lv_image_dsc_t startup_logo; //开机动画图标
Expand Down Expand Up @@ -186,7 +188,7 @@ uint8_t vad_enable = 1; //0是支持打断,1是不支持打断
#if defined (KWS_ENABLE_DEFAULT) && KWS_ENABLE_DEFAULT
uint8_t aec_enabled = 1;
#else
uint8_t aec_enabled = 0;
uint8_t aec_enabled = 1;
#endif
// xiaozhi2
extern rt_mailbox_t g_button_event_mb;
Expand Down Expand Up @@ -220,6 +222,40 @@ static int g_battery_level = 60; // 默认为满电
static lv_obj_t *g_battery_fill = NULL; // 电池填充对象
static lv_obj_t *g_battery_label = NULL; // 电量标签

void ctrl_wakeup(bool is_wakeup)
{
if (wakeup_switch != NULL)
{
if(is_wakeup)
{
lv_obj_add_state(wakeup_switch, LV_STATE_CHECKED);
aec_enabled = 1;
}
else
{
lv_obj_clear_state(wakeup_switch, LV_STATE_CHECKED);
aec_enabled = 0;
}
}
}

void ctrl_interrupt(bool is_interrupt)
{
if (interrupt_switch != NULL)
{
if(!is_interrupt)
{
lv_obj_add_state(interrupt_switch, LV_STATE_CHECKED);
vad_enable = 1; //1是不打断
}
else
{
lv_obj_clear_state(interrupt_switch, LV_STATE_CHECKED);
vad_enable = 0;
}
}
}

// 亮度表需要按照从小到大排序
static const uint16_t brigtness_tb[] =
{
Expand Down Expand Up @@ -995,9 +1031,9 @@ rt_err_t xiaozhi_ui_obj_init()
#endif

create_tip_label(cont, "不打断", 1, 0); //vad
create_switch(cont, vad_switch_event_handler, 1, 2, 1);
interrupt_switch = create_switch(cont, vad_switch_event_handler, 1, 2, 1);
create_tip_label(cont, "唤醒", 2, 0); //aec
create_switch(cont, aec_switch_event_handler, 2, 2, 0);
wakeup_switch = create_switch(cont, aec_switch_event_handler, 2, 2, 1);
create_tip_label(cont, "音量", 3, 0);
volume_slider = create_slider(cont, slider_event_handler, 3, 1, VOL_MIN_LEVEL, VOL_MAX_LEVEL, VOL_DEFAULE_LEVEL);
create_tip_label(cont, "亮度", 4, 0);
Expand Down Expand Up @@ -1258,7 +1294,7 @@ extern weather_info_t g_current_weather;
void update_xiaozhi_ui_time(void *parameter)
{

// 更新当前时间信息
// 获取当前时间
xiaozhi_time_get_current(&g_current_time);

// 使用消息队列发送更新UI的消息到UI线程
Expand Down
101 changes: 23 additions & 78 deletions app/src/xiaozhi_weather.c
Original file line number Diff line number Diff line change
Expand Up @@ -602,52 +602,6 @@ void time_ui_update_callback(void)
}


//更新RTC时间
int xiaozhi_rtc_update(time_t timestamp)
{
if (timestamp <= 0)
{
LOG_E("Invalid timestamp: %ld", (long)timestamp);
return -RT_ERROR;
}

// 尝试更新RTC设备
if (g_rtc_device)
{
rt_err_t result = rt_device_control(
g_rtc_device, RT_DEVICE_CTRL_RTC_SET_TIME, &timestamp);
if (result == RT_EOK)
{
LOG_I("RTC time updated successfully: %ld", (long)timestamp);

// 验证RTC时间是否正确设置
time_t verify_time = 0;
result = rt_device_control(
g_rtc_device, RT_DEVICE_CTRL_RTC_GET_TIME, &verify_time);
if (result == RT_EOK)
{
LOG_E("verify_time: %ld", (long)verify_time);
return RT_EOK;
}
else
{
LOG_E("Failed to verify RTC time after setting");
return -RT_ERROR;
}
}
else
{
LOG_E("Failed to update RTC time: %d", result);
return -RT_ERROR;
}
}
else
{
LOG_W("RTC device not available, cannot store time");
return -RT_ERROR;
}
}

void weather_ui_update_callback(void)
{
// 更新天气信息
Expand Down Expand Up @@ -881,33 +835,16 @@ int xiaozhi_ntp_sync(void)
// 尝试多个NTP服务器
for (int i = 0; i < sizeof(ntp_servers) / sizeof(ntp_servers[0]); i++)
{
rt_kprintf("Trying NTP server: %s\n", ntp_servers[i]);

#ifdef PKG_USING_NETUTILS
// 尝试使用RT-Thread的NTP功能
extern time_t ntp_get_time(const char *host_name);
extern time_t ntp_sync_to_rtc(const char *host_name);

// 先获取时间
cur_time = ntp_get_time(ntp_servers[i]);
if (cur_time > 1000000000)
{ // 基本的时间有效性检查(大约是2001年之后)
// 获取服务时间并设置rtc时间
cur_time = ntp_sync_to_rtc(ntp_servers[i]);
if (cur_time > 1000000000)// 基本的时间有效性检查(大约是2001年之后)
{
sync_success = 1;

// 验证获取的时间转换结果
// struct tm *ntp_local = localtime(&cur_time);
// LOG_I("ntp_local:%d-%d-%d %d:%d:%d\n", ntp_local->tm_year + 1900, ntp_local->tm_mon + 1, ntp_local->tm_mday,
// ntp_local->tm_hour, ntp_local->tm_min, ntp_local->tm_sec);

// 尝试直接同步到RTC
time_t sync_result = ntp_sync_to_rtc(ntp_servers[i]);
if (sync_result > 0)
{
cur_time = sync_result; // 使用RTC返回的时间
}
else
{
LOG_W("NTP direct RTC sync failed, will manually update RTC");
}

}
#else
// 如果没有NTP支持,使用系统时间
Expand All @@ -921,24 +858,32 @@ int xiaozhi_ntp_sync(void)

if (sync_success)
{
// 确保时间写入RTC(关键步骤)
if (xiaozhi_rtc_update(cur_time) == RT_EOK)
// 验证RTC时间是否正确设置
time_t verify_time = 0;
rt_err_t result = rt_device_control(
g_rtc_device, RT_DEVICE_CTRL_RTC_GET_TIME, &verify_time);
if (result == RT_EOK)
{
LOG_I("Time successfully stored to RTC");
LOG_I("RTC time verification successful: %ld", (long)verify_time);
// 检查设置的时间和获取的时间是否一致
if (verify_time == cur_time) {
LOG_I("RTC time matches NTP time");
} else {
LOG_W("RTC time mismatch. NTP: %ld, RTC: %ld", (long)cur_time, (long)verify_time);
}
}
else
{
LOG_W("Failed to store time to RTC, but sync considered "
"successful");
LOG_E("Failed to verify RTC time: %d", result);
}
// 清除同步进行标志
// 清除同步进行标志
g_ntp_sync_in_progress = 0;
return RT_EOK;
}

rt_thread_mdelay(1000); // 等待1秒再尝试下一个服务器
}
// 清除同步进行标志
// 清除同步进行标志
g_ntp_sync_in_progress = 0;
return -RT_ERROR;
}
Expand All @@ -958,10 +903,10 @@ void xiaozhi_time_weather(void)//获取最新时间和天气
return;

}
ntp_result = xiaozhi_ntp_sync();
ntp_result = xiaozhi_ntp_sync();//同步网络服务时间
if (ntp_result == RT_EOK)
{
update_xiaozhi_ui_time(NULL);
update_xiaozhi_ui_time(NULL);//更新界面时间显示
LOG_I("Time synchronization successful, next sync in 30min");
break;
}
Expand Down