1919#include <drivers/rt_drv_encoder.h>
2020#include "drv_flash.h"
2121#include "xiaozhi_weather.h"
22+ #include "lv_timer.h"
23+ #include "lv_display.h"
2224extern void xiaozhi_ui_update_ble (char * string );
2325extern void xiaozhi_ui_update_emoji (char * string );
2426extern void xiaozhi_ui_chat_status (char * string );
@@ -35,7 +37,12 @@ extern void xz_ws_audio_init();
3537extern rt_tick_t last_listen_tick ;
3638extern xiaozhi_ws_t g_xz_ws ;
3739extern rt_mailbox_t g_button_event_mb ;
40+ extern void ui_sleep_callback (lv_timer_t * timer );
41+ extern lv_obj_t * standby_screen ;
3842rt_mailbox_t g_battery_mb ;
43+ extern lv_timer_t * ui_sleep_timer ;
44+ extern lv_obj_t * shutdown_screen ;
45+ extern lv_obj_t * sleep_screen ;
3946/* Common functions for RT-Thread based platform
4047 * -----------------------------------------------*/
4148/**
@@ -213,18 +220,18 @@ static void battery_level_task(void *parameter)
213220 // 获取到的是电池电压,单位是mV
214221 // 假设电池电压范围是3.6V到4.2V,对应的电量范围是0%到100%
215222 uint32_t battery_percentage = 0 ;
216- if (battery_level < 3600 )
223+ if (battery_level < 36000 )
217224 {
218225 battery_percentage = 0 ; // 小于3.6V,电量为0
219226 }
220- else if (battery_level > 4200 )
227+ else if (battery_level > 42000 )
221228 {
222229 battery_percentage = 100 ; // 大于4.2V,电量为100
223230 }
224231 else
225232 {
226233 // 线性插值计算电量百分比
227- battery_percentage = ((battery_level - 3600 ) * 100 ) / (4200 - 3600 );
234+ battery_percentage = ((battery_level - 36000 ) * 100 ) / (42000 - 36000 );
228235 }
229236
230237 rt_mb_send (g_battery_mb , battery_percentage );
@@ -331,7 +338,7 @@ void pan_reconnect()
331338
332339 LOG_I ("Attempting to reconnect PAN, attempt %d" ,
333340 first_reconnect_attempts + 1 );
334- xiaozhi_ui_chat_status ("connecting pan ..." );
341+ xiaozhi_ui_chat_status ("重新连接 PAN ..." );
335342 xiaozhi_ui_chat_output ("正在重连PAN..." );
336343 xiaozhi_ui_standby_chat_output ("正在重连PAN..." );
337344 if (first_reconnect_attempts < max_reconnect_attempts )
@@ -394,6 +401,11 @@ static int bt_app_interface_event_handle(uint16_t type, uint16_t event_id,
394401 g_bt_app_env .bt_connected = FALSE;
395402 xiaozhi_ui_chat_output ("蓝牙断开连接" );
396403 xiaozhi_ui_standby_chat_output ("蓝牙断开连接" );//待机画面
404+ lv_obj_t * now_screen = lv_screen_active ();
405+ if (now_screen != standby_screen && now_screen != sleep_screen && now_screen != shutdown_screen )
406+ {
407+ ui_swith_to_standby_screen ();
408+ }
397409 // memset(&g_bt_app_env.bd_addr, 0xFF,
398410 // sizeof(g_bt_app_env.bd_addr));
399411 if (info -> res == BT_NOTIFY_COMMON_SCO_DISCONNECTED )
@@ -567,9 +579,13 @@ static void check_poweron_reason(void)
567579#endif
568580 else if (PMUC_WSR_PIN_ALL & pm_get_wakeup_src ())
569581 {
570- rt_thread_mdelay (2500 ); // 延时2.5秒
571- int val = rt_pin_read (43 );
572- rt_kprintf ("Power key(PA43) level after 2.5s: %d\n" , val );
582+ rt_thread_mdelay (1000 ); // 延时1秒
583+ #ifdef BSP_USING_BOARD_SF32LB52_LCD_N16R8
584+ int val = rt_pin_read (BSP_KEY1_PIN );
585+ #else
586+ int val = rt_pin_read (BSP_KEY2_PIN );
587+ #endif
588+ rt_kprintf ("Power key level after 1s: %d\n" , val );
573589 if (val != KEY2_ACTIVE_LEVEL )
574590 {
575591 // 按键已松开,认为是误触发,直接关机
@@ -763,7 +779,7 @@ int main(void)
763779 else if (value == BT_APP_CONNECT_PAN_SUCCESS )
764780 {
765781 rt_kputs ("BT_APP_CONNECT_PAN_SUCCESS\r\n" );
766- xiaozhi_ui_chat_output ("初始化 请稍等..." );
782+ // xiaozhi_ui_chat_output("初始化 请稍等...");
767783 xiaozhi_ui_standby_chat_output ("初始化 请稍等..." );
768784 xiaozhi_ui_update_ble ("open" );
769785 xiaozhi_ui_chat_status ("初始化..." );
@@ -773,16 +789,22 @@ int main(void)
773789 rt_thread_mdelay (2000 );
774790 // 执行NTP与天气同步
775791 xiaozhi_time_weather ();
776- xiaozhi_ui_chat_output ("连接小智中..." );
792+ // xiaozhi_ui_chat_output("连接小智中...");
777793 xiaozhi_ui_standby_chat_output ("请按键连接小智..." );
778794
779795#ifdef XIAOZHI_USING_MQTT
780796 xiaozhi (0 , NULL );
781797 rt_kprintf ("Select MQTT Version\n" );
782798#else
783- xz_button_init ();
799+ xz_button_init ();
784800 // xiaozhi2(0, NULL); // Start Xiaozhi
785801#endif
802+ // 在蓝牙和PAN连接成功后创建睡眠定时器
803+ if (!ui_sleep_timer && g_pan_connected )
804+ {
805+ rt_kprintf ("create sleep timer2\n" );
806+ ui_sleep_timer = lv_timer_create (ui_sleep_callback , 40000 , NULL );
807+ }
786808 }
787809 else if (value == KEEP_FIRST_PAN_RECONNECT )
788810 {
0 commit comments