File tree Expand file tree Collapse file tree 1 file changed +13
-2
lines changed
projects/Edgi-Talk_XiaoZhi/Edgi_Talk_M55_XiaoZhi/applications/xiaozhi Expand file tree Collapse file tree 1 file changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -53,6 +53,15 @@ static void ensure_state_consistency(void)
5353 xiaozhi_ui_chat_status (" 休眠中" );
5454 xiaozhi_ui_chat_output ("等待唤醒" );
5555 }
56+
57+ /* 优化:如果WebSocket已连接但状态是Unknown,设置为Idle */
58+ if (g_state == kDeviceStateUnknown && g_xz_ws .is_connected && g_xz_ws .session_id [0 ] != '\0' )
59+ {
60+ LOG_D ("WebSocket connected with valid session, updating state to Idle\n" );
61+ g_state = kDeviceStateIdle ;
62+ xiaozhi_ui_chat_status (" 就绪" );
63+ xiaozhi_ui_chat_output ("就绪" );
64+ }
5665}
5766
5867/* Utility Functions */
@@ -140,7 +149,8 @@ void xz_button_thread_entry(void *param)
140149 /* 优雅的按键处理:先检查连接状态,再处理具体事件 */
141150 if (evt & BUTTON_EVENT_PRESSED )
142151 {
143- if (g_state == kDeviceStateUnknown || !g_xz_ws .is_connected )
152+ /* 优化状态检查逻辑:WebSocket已连接但状态未知时,认为是可用状态 */
153+ if (!g_xz_ws .is_connected )
144154 {
145155 /* 检查是否正在重连中 */
146156 if (WEBSOCKET_RECONNECT_FLAG == 1 )
@@ -158,7 +168,8 @@ void xz_button_thread_entry(void *param)
158168 }
159169 else
160170 {
161- /* 设备已连接,处理具体功能 */
171+ /* WebSocket已连接,可以处理功能请求 */
172+ /* 如果状态是Unknown但WebSocket已连接,视为Idle状态处理 */
162173 if (g_state == kDeviceStateSpeaking )
163174 {
164175 LOG_I ("Speaking aborted by user\n" );
You can’t perform that action at this time.
0 commit comments