Forráskód Böngészése

配上关机会有bug

wanghechen 8 hónapja
szülő
commit
d1264dadeb

+ 1 - 1
components/Decection/Decection.c

@@ -76,7 +76,7 @@ int adc_read_power_pin(adc_oneshot_unit_handle_t adc_handle)
 #if 0
         ESP_LOGI(TAG,"batt_percent = [%d],voltage[0][0] = [%d]",batt_percent, voltage[0][0]);
 #else
-    // printf("batt_percent = [%d],voltage[0][0] = [%d],adc value %d\r\n",batt_percent, voltage[0][0],(int)battery_percentage);
+     printf("voltage[0][0] = [%d],adc value %d\r\n",voltage[0][0],(int)battery_percentage);
 #endif
     return batt_percent;
 }

+ 2 - 2
components/EPD/EPD.c

@@ -433,7 +433,7 @@ void epd_write_data(screen_t screen, const uint8_t *data, int len)
 bool epd_check_status(screen_t screen)
 {
 
-#if 0
+#if 1//死等
     if(screen == SCREEN_LEFT)
     {
         while(!gpio_get_level(PIN_L_BUSY))
@@ -603,7 +603,7 @@ void epd_refresh(screen_t screen)
     epd_write_cmd(screen, 0x12, false); // DISPLAY REFRESH
     // ets_delay_us(200); //!!!The delay here is necessary, 200uS at least!!!
     // vTaskDelay(1 / portTICK_PERIOD_MS);
-    epd_check_status(screen); // waiting for the electronic paper
+    epd_check_status(screen); // waiting for the electronic paper//时间较长
 }
 void epd_sleep(screen_t screen)
 {

+ 6 - 1
components/LED/LED.c

@@ -1,7 +1,7 @@
 #include <stdio.h>
 #include "LED.h"
 #include "esp_log.h"
-
+#include "esp_rom_sys.h"
 static const char *LOG_TAG = "LED";
 
 // uint8_t led[6]={0x04,0x20,0x08,0x10,0x02,0x40 };
@@ -103,5 +103,10 @@ void beep_blink(uint16_t ms, uint16_t count)
         vTaskDelay(ms / portTICK_PERIOD_MS);
         beep_close();
         vTaskDelay(ms / portTICK_PERIOD_MS);
+
+        // beep_open();
+        // esp_rom_delay_us(ms*1000);//阻塞延时
+        // beep_close();
+        // esp_rom_delay_us(ms*1000);//阻塞延时
     }
 }

+ 1 - 1
components/LORA/LORA.c

@@ -1003,7 +1003,7 @@ void lora_receive_callback_handler()
         // printf("\r\n");
 
         // printf("string =%s\r\n",data);
-        printf(" -> Lora_UART_Mode %.*s\n", user_size, data);
+        // printf(" -> Lora_UART_Mode %.*s\n", user_size, data);
 // 发送消息处理
 #if 0
                         xQueueSend(lora_dealhandle, &length, portMAX_DELAY);

+ 1 - 1
components/button/include/user_button.h

@@ -139,5 +139,5 @@ int  find_key_value(int value);
 bool is_btn_timeout(void);
 void send_button_key_queue(uint8_t value);
 void reset_btn_last_time(void);
-bool is_power_press(void);
+bool is_key_press(void);
 #endif/*_USER_BUTTON_H_*/

+ 40 - 30
components/button/user_button.c

@@ -20,7 +20,7 @@ static const char *LOG_TAG = "user button";
 static struct timeval btn_last_time; // 左屏超过30s,不发送按键lora信息
 
 extern QueueHandle_t button_Data_queue;
-extern SemaphoreHandle_t button_semaphore;
+// extern SemaphoreHandle_t button_semaphore;
 
 static button_handle_t user_button_handle[KEY_NUM] = {0};
 
@@ -29,7 +29,7 @@ TimerHandle_t btn_timer_handle;
 RTC_FAST_ATTR static bool is_setting = false;
 RTC_FAST_ATTR static bool is_reset_net = false; // 配网
 RTC_FAST_ATTR static bool is_send_lora = false;
-
+RTC_FAST_ATTR static bool is_down = false;
 uint16_t adc_value[][2] =
     {
         {BAOYANG_MIN_ADC, BAOYANG_MAX_ADC},
@@ -71,14 +71,14 @@ int find_key_value(int value)
     return key;
 }
 
-static void user_button_single_click_cb(void *arg, void *usr_data);
+static void user_button_up_cb(void *arg, void *usr_data);
 
 static void power_long_press_start_cb(void *arg, void *usr_data);
 static void power_long_press_hold_cb(void *arg, void *usr_data);
 static void power_long_press_up_cb(void *arg, void *usr_data);
 static void power_press_up_cb(void *arg, void *usr_data);
 static void power_single_press_cb(void *arg, void *usr_data);
-
+static void button_down_cb(void *arg, void *usr_data);
 static void user_button_single_UP_cb(void *arg, void *usr_data);
 
 static void power_button_multi_press_cb(void *arg, void *usr_data);
@@ -190,8 +190,8 @@ void button_init(adc_oneshot_unit_handle_t adc_handle)
             printf("Button create failed");
         }
         button_idx = i;
-        // iot_button_register_cb( user_button_handle[i], BUTTON_PRESS_DOWN, user_button_single_click_cb,button_idx);
-        iot_button_register_cb(user_button_handle[i], BUTTON_PRESS_UP, user_button_single_click_cb, button_idx); // 松手才发按键消息
+        iot_button_register_cb( user_button_handle[i], BUTTON_PRESS_DOWN, button_down_cb,button_idx);
+        iot_button_register_cb(user_button_handle[i], BUTTON_PRESS_UP, user_button_up_cb, button_idx); // 松手才发按键消息
 
         // iot_button_register_cb( user_button_handle[i], BUTTON_LONG_PRESS_UP, long_press_up_cb,button_idx);
         // iot_button_register_cb( user_button_handle[i], BUTTON_PRESS_UP, user_button_single_click_cb,button_idx);
@@ -374,23 +374,22 @@ static void long_press_up_cb(void *arg, void *usr_data)
 {
     ESP_LOGE(LOG_TAG, "BUTTON_LONG_PRESS_UP %d", (int)usr_data);
 }
-static bool is_power = false;
+
 static void power_long_press_start_cb(void *arg, void *usr_data)
 {
     // ESP_LOGE(LOG_TAG, "power_long_press_start_cb\n");
-    is_power = true;
-}
-static void power_long_press_up_cb(void *arg, void *usr_data)
-{
+    // is_power = true;
 }
+// static void power_long_press_up_cb(void *arg, void *usr_data)
+// {
+// }
 static void power_press_up_cb(void *arg, void *usr_data)
 {
-    // ESP_LOGE(LOG_TAG, "power_long_press_up_cb\n");
-    is_power = false;
+    is_down = false;
 }
-bool is_power_press(void)
+bool is_key_press(void)
 {
-    return is_power;
+    return is_down;
 }
 static void power_long_press_hold_cb(void *arg, void *usr_data)
 {
@@ -447,13 +446,19 @@ static void power_long_press_hold_cb(void *arg, void *usr_data)
 static void power_single_press_cb(void *arg, void *usr_data)
 {
 
+    if (Machine_info.power_status == 0)
+    {
+        return;
+    }
+    is_down = true;
+    ESP_LOGE(LOG_TAG, "is_down true\n");
     switch ((int)usr_data)
     {
     case 0:
-        printf("power sigle press\r\n");
+        ESP_LOGW(LOG_TAG,"power sigle press\r\n");
 
-        if (Machine_info.power_status == 1) // 开机
-        {
+        // if (Machine_info.power_status == 1) // 开机
+        // {
 
             button_info = POWER_ON_PRESS_VALUE;
 
@@ -462,16 +467,16 @@ static void power_single_press_cb(void *arg, void *usr_data)
                 ESP_LOGE(LOG_TAG, "queue send is fail");
                 return;
             }
-        }
-        else
-        {
-            button_info = POWER_OFF_PRESS_VALUE; // 关机状态下单击按键
-            if (xQueueSend(button_Data_queue, &button_info, 0) != true)
-            {
-                ESP_LOGE(LOG_TAG, "queue send is fail");
-                return;
-            }
-        }
+        // }
+        // else
+        // {
+        //     button_info = POWER_OFF_PRESS_VALUE; // 关机状态下单击按键
+        //     if (xQueueSend(button_Data_queue, &button_info, 0) != true)
+        //     {
+        //         ESP_LOGE(LOG_TAG, "queue send is fail");
+        //         return;
+        //     }
+        // }
 
         break;
 
@@ -486,9 +491,14 @@ static void power_single_press_cb(void *arg, void *usr_data)
         break;
     }
 }
-
-static void user_button_single_click_cb(void *arg, void *usr_data)
+static void button_down_cb(void *arg, void *usr_data)
+{
+    ESP_LOGI(LOG_TAG, "%d true",(int)usr_data);
+    is_down = true;
+}
+static void user_button_up_cb(void *arg, void *usr_data)
 {
+    is_down = false;
     is_setting = false;
     is_reset_net = false;
     ESP_LOGW(LOG_TAG, " single_click_cb[%d]", iot_button_get_ticks_time((button_handle_t)arg));

+ 36 - 154
main/ulp_riscv_adc_example_main.c

@@ -93,7 +93,12 @@ static void light_sleep_task(void *args)
     int lev_2 = 0;
     while (true)
     {
-
+        if (is_key_press())
+        {
+            // ESP_LOGI(LOG_TAG,"按键按下不进行休眠操作");
+            vTaskDelay(1000 / portTICK_PERIOD_MS);
+            continue; // 按键按下不进行休眠操作
+        }
         extern bool is_sleep;
         if (is_sleep == true)
         {
@@ -108,7 +113,7 @@ static void light_sleep_task(void *args)
 
             is_first_run = false;
 
-            printf("start light_sleep ,is_first_run = %d\r\n", is_first_run);
+            ESP_LOGE(LOG_TAG, "start light_sleep ,is_first_run = %d\r\n", is_first_run);
 
             if (Machine_info.power_status == 0) // 关机状态
             {
@@ -164,12 +169,11 @@ static void light_sleep_task(void *args)
 // uart_driver_delete(UART_NUM_1);
 // esp_deep_sleep_start();
 #endif
-                printf("=>deep sleep\r\n");
-                uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
+
                 // vTaskDelay(100/ portTICK_PERIOD_MS);
 
 #if 1 // 电源按键
-                adc_oneshot_del_unit(adc1_handle);
+
                 gpio_reset_pin(4);
                 int ext_wakeup_pin_0 = 4;
                 printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
@@ -207,12 +211,20 @@ static void light_sleep_task(void *args)
 
 #endif
 
-                adc_oneshot_del_unit(adc1_handle);
-
                 esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_ON);
                 ESP_ERROR_CHECK(esp_sleep_enable_ulp_wakeup());
 
-                esp_deep_sleep_start();
+                // if (!is_key_press())
+                // {
+                    printf("=>deep sleep\r\n");
+                    uart_wait_tx_idle_polling(1); // 抛出剩余串口1消息
+                    uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
+                    iot_button_stop();
+                    adc_oneshot_del_unit(adc1_handle);
+                    vTaskDelay(100/ portTICK_PERIOD_MS);
+                    esp_deep_sleep_start();
+                // }
+
                 // esp_light_sleep_start();
             }
             else if ((Machine_info.power_status == 1) && Machine_info.paired == 1) // 开机状态且配对
@@ -295,37 +307,6 @@ static void light_sleep_task(void *args)
                 esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US); // 配置当前休眠的唤醒时间
                                                                      // adc_oneshot_del_unit(adc1_handle);
 
-                // extern bool left_refresh_complete;
-                // extern bool right_refresh_complete;
-
-#if 0
-                            while(1)
-                            {
-
-
-                                                        
-                                if((left_refresh_timer_isActive() == false)  &&(right_refresh_timer_isActive() == false)   )
-                                {
-                                    break;
-                                }
-
-                                printf("1left refresh complete %s,right refresh complete %s\n",left_refresh_timer_isActive()?"true":"false",right_refresh_timer_isActive()?"true":"false");
-
-#if 0
-                                if(
-                                    (left_refresh_complete == true)  || (right_refresh_complete == true) 
-                                 )
-                                 {
-                                    printf("left refresh complete %s,right refresh complete %s,",left_refresh_complete?"true":"false",right_refresh_complete?"true":"false");
-                                    break;
-                                 }
-
-                                 printf("left refresh complete %s,right refresh complete %s,",left_refresh_complete?"true":"false",right_refresh_complete?"true":"false");
-#endif
-                                 vTaskDelay(100/ portTICK_PERIOD_MS);
-                            }
-#endif
-
                 // gpio_hold_en(4);
 
                 // vTaskDelay(100/ portTICK_PERIOD_MS);
@@ -334,19 +315,18 @@ static void light_sleep_task(void *args)
                 if (!is_adv)
                 {
 
-                    if (!is_power_press())
-                    {
+                    // if (!is_key_press())
+                    // {
                         ESP_LOGW(LOG_TAG, "-> sleep\r\n");
                         uart_wait_tx_idle_polling(1);                           // 抛出剩余串口1消息
                         uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM); // 抛出剩余串口0消息
-
-                        vTaskDelay(100 / portTICK_PERIOD_MS); // 给出时间片
+                        vTaskDelay(100/ portTICK_PERIOD_MS);
                         esp_light_sleep_start();
-                    }
-                    else
-                    {
-                        ESP_LOGW(LOG_TAG, "power key is press\r\n");
-                    }
+                    // }
+                    // else
+                    // {
+                    //     ESP_LOGW(LOG_TAG, "power key is press\r\n");
+                    // }
                 }
                 else
                 {
@@ -427,7 +407,7 @@ static void light_sleep_task(void *args)
                     f_send_get_chart_data();
                     f_send_lora_rssi(Machine_info.rssi);
                     f_send_battary_vaule(Machine_info.batt_precent);
-                    f_send_get_time();
+                    // f_send_get_time();
                 }
 
                 if ((Machine_info.last_button.Minute != Machine_info.min) /*||(Machine_info.last_button.Hour != Machine_info.Hour)*/) //
@@ -473,13 +453,7 @@ static void light_sleep_task(void *args)
                             is_first_charge = true;
 
                             gpio_hold_dis(PIN_R_CS);
-
-                            screen_dis_info.is_left = false;
-                            screen_dis_info.is_into_sleep = true;
-                            if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                            {
-                                ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                            }
+                            set_screen_dis_info_and_send_queue(true, false, false, false,100);
                             printf("charge in\r\n");
                         }
                     }
@@ -490,15 +464,8 @@ static void light_sleep_task(void *args)
                             Machine_info.is_charge = false; // 拔掉充电
                             is_first_charge = false;
                             gpio_hold_dis(PIN_R_CS);
-                            // is_left = false;
-
-                            screen_dis_info.is_left = false;
-                            screen_dis_info.is_into_sleep = true;
-                            if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                            {
-                                ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                            }
-                            sleep_timer_start(1000);
+                            set_screen_dis_info_and_send_queue(true, false, false, false,100);
+                            // sleep_timer_start(1000);
 
                             // user_compare(last_batt_precent,Machine_info.batt_precent);//刷完左屏,比较一次电量。电量图标不同则刷一次右屏
 
@@ -554,7 +521,7 @@ static void light_sleep_task(void *args)
             {
                 iot_button_resume();
             }
-            if (Machine_info.paired && Machine_info.power_status)
+            if (Machine_info.paired && Machine_info.power_status && !is_key_press())
             {
                 vTaskDelay(2000 / portTICK_PERIOD_MS);
                 is_sleep = true; // 配对且关机,进入休眠
@@ -581,79 +548,14 @@ static void light_sleep_task(void *args)
             {
                 printf("-->low batt , power off\r\n");
 #if 0
-                Machine_info.power_status = 0;
-                // dis_instructions();  //进入关机界面
-                // screen_dis_info.is_left = true;
-                // screen_dis_info.is_into_sleep = false;
-                // if(xQueueSend(screen_queue,&screen_dis_info,portMAX_DELAY) != true)
-                // {
-                //     ESP_LOGE(LOG_TAG,"err:screen queue send fail");
-                // }
-                screen_dis_info.is_left = false;
-                screen_dis_info.is_into_sleep = true;
-                if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                {
-                    ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                }
-                sleep_timer_start(1000);
+                set_screen_dis_info_and_send_queue(false, false, false, false,100);
+                set_screen_dis_info_and_send_queue(true, false, true, false,100);
 #endif
             }
 
             lev_2 = gpio_get_level(2);
 
             {
-#if 0
-                    if(Machine_info.power_status == 0)  //关机的情况
-                    {
-
-                        if(!lev_2)   //充电
-                        {
-
-                            if(is_first_charge == false)
-                            {
-
-                                Machine_info.is_charge = true;   //充电中标志
-                                is_first_charge = true;
-
-
-                                gpio_hold_dis(PIN_R_CS);
-                            is_left = false
-                            if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
-                            {
-                                ESP_LOGE(LOG_TAG,"err:screen queue send fail");
-                            } 
-                                // extern void dis_right_instructions();
-                                // dis_right_instructions();
-                                printf("charge in\r\n");
-                            }
-
-                        }else  //未充电
-                        {
-                            if( is_first_charge == true)
-                            {
-                                Machine_info.is_charge = false;   //拔掉充电
-                                is_first_charge = false;
-
-                                gpio_hold_dis(PIN_R_CS);
-                                // extern void dis_right_instructions();
-                                // dis_right_instructions();
-                            is_left = false
-                            if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
-                            {
-                                ESP_LOGE(LOG_TAG,"err:screen queue send fail");
-                            } 
-
-                                sleep_timer_start(1000);
-                                //right_screen_send();
-                                //user_compare(last_batt_precent,Machine_info.batt_precent);//刷完左屏,比较一次电量。电量图标不同则刷一次右屏
-
-                                printf("not charge in or charge out\r\n");
-                            }  
-                        }
-
-
-                    }else
-#endif
 
                 if (Machine_info.power_status == 1) // 开机的情况
                 {
@@ -718,31 +620,11 @@ void app_main(void)
     xTaskCreate(light_sleep_task, "light_sleep_task", 4096 * 5, NULL, 1, NULL);
 
     printf("Machine_info.power_status = %d\r\n", Machine_info.power_status);
-#if 1
-    if (Machine_info.power_status == 0) // 关机状态
-    {
-        sleep_timer_start(5000);
-    }
-#else
 
     if (Machine_info.power_status == 0) // 关机状态
     {
-        Machine_info.power_status = 1;
-        // sleep_timer_start(5000);
-    }
-
-#endif
-
-#if 0
-      int  reson = is_wake_up_reson();  //返回唤醒的原因
-
-    if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER)) 
-    {
-            printf("sleep time = %d ms\r\n",(TIMER_WAKEUP_TIME_US)/1000);
-            esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US);  //配置当前休眠的唤醒时间
-            sleep_timer_start(5000);
+        sleep_timer_start(5000);
     }
-#endif
 }
 
 /*********************************************************************************

+ 5 - 8
main/user_sleep.c

@@ -69,6 +69,8 @@ extern void light_sleep_task(void *args);
 extern void wakeup_sleep_task(void *args);
 
 bool is_sleep = false;
+extern void set_screen_dis_info_and_send_queue(bool is_into_sleep,bool is_left,bool is_change_power,bool is_dont_dis,bool sleep_ms);
+
 
 /*********************************************************************************
  * function   :   sleep_timer_callback
@@ -120,7 +122,7 @@ void sleep_timer_start(int ms)
 
     xTimerStart(sleep_timer, 0); // 开始定时器
     // xTimerStart(sleep_Timerout, 0);
-
+    ESP_LOGI(LOG_TAG, "#############%s##############reset   sleep_timer [%d]",is_sleep?"true":"false" ,ms);
 #else
 
 #if 0
@@ -192,7 +194,7 @@ void Already_send_timer_callback(void *arg)
     // printf("sleep time = %d\r\n",(TIMER_WAKEUP_TIME_US*Machine_info.eflagID)/1000);
 
 #if 1
-    sleep_timer_start(1000); // 倒计时进入睡眠
+    set_screen_dis_info_and_send_queue(true,false,false,true,100);
 #endif
 
 #else
@@ -396,7 +398,7 @@ void user_sleep_into()
     ESP_ERROR_CHECK(esp_timer_create(&send_timer_args, &already_send_timer));
 #else
 
-#if 1
+
     // 创建
     sleep_timer = xTimerCreate(
         "sleep_timer",       // 定时器名称(可以为NULL)
@@ -415,11 +417,6 @@ void user_sleep_into()
         Already_send_timer_callback // 定时器回调函数
     );
 
-// xTimerStart(sleep_Timerout, 0);
-#else
-    sleep_timer_start(5000);
-
-#endif
 
 #endif
 

+ 2 - 2
main/yc_paint.c

@@ -771,9 +771,9 @@ static uint8_t *partial_right2_quick(void)
     memset((uint8_t *)tmp_paint_buf, 0, DISPLAY_BUFFER_SIZE /*sizeof(tmp_paint_buf)*/);
     Paint_NewImage((UBYTE *)tmp_paint_buf, 480, RIGHT2_HIGHT, ROTATE_0, WHITE);
 
-    ESP_LOGE(LOG_TAG, "paint Charge_close %d %d %d %d %d", Machine_info.person[0].Charge_close, Machine_info.person[1].Charge_close, Machine_info.person[2].Charge_close,
+    ESP_LOGI(LOG_TAG, "paint Charge_close %d %d %d %d %d", Machine_info.person[0].Charge_close, Machine_info.person[1].Charge_close, Machine_info.person[2].Charge_close,
              Machine_info.person[3].Charge_close, Machine_info.person[4].Charge_close);
-    ESP_LOGW(LOG_TAG, "责任人人数 [%d][%d][%d][%d][%d]", person_get_num(0), person_get_num(1), person_get_num(2), person_get_num(3), person_get_num(4)); // 获取当前类型人员数量
+    ESP_LOGI(LOG_TAG, "责任人人数 [%d][%d][%d][%d][%d]", person_get_num(0), person_get_num(1), person_get_num(2), person_get_num(3), person_get_num(4)); // 获取当前类型人员数量
 
     // 管理员不会关闭
     memset((uint8_t *)buffer, 0, sizeof(buffer));

+ 36 - 75
main/yc_protocol.c

@@ -101,24 +101,10 @@ void reset_default(bool is_dis, uint8_t power_status)
     {
         return;
     }
-    // Paint_leftScreen_main_quick(&Machine_info);
-    // Paint_rightScreen_main_quick(&Machine_info);
-    xQueueReset(screen_queue);
-    screen_dis_info.is_left = true;
-    screen_dis_info.is_into_sleep = false;
-    // 重置快刷
-    Machine_info.left_current_Quick_refresh_time = 0;
-    Machine_info.right_current_Quick_refresh_time = 0;
-    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-    {
-        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-    }
-    screen_dis_info.is_left = false;
-    screen_dis_info.is_into_sleep = false;
-    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-    {
-        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-    }
+
+    // xQueueReset(screen_queue);
+    set_screen_dis_info_and_send_queue(false, true, false, false,100);
+    set_screen_dis_info_and_send_queue(true, false, false, false,100);
 }
 
 /*
@@ -129,7 +115,7 @@ void reset_default(bool is_dis, uint8_t power_status)
 void print_systenInfo(void)
 {
     printf("=================================\r\n");
-    printf("=======%s======\r\n", "2024.1.4 [11时] burn"); // 打印烧录时间
+    printf("=======%s======\r\n", "2024.1.4 [22时] burn"); // 打印烧录时间
     printf("=============%s===========\r\n", __TIME__);
     printf("=================================\r\n");
     printf("========version V %d.%d.%d==========\r\n", VERSION_X, VERSION_Y, VERSION_Z);
@@ -172,6 +158,19 @@ void print_systenInfo(void)
 void send_update_status(void);
 void send_status_duration(void);
 
+
+void set_screen_dis_info_and_send_queue(bool is_into_sleep, bool is_left, bool is_change_power, bool is_dont_dis,int ms)
+{
+    screen_dis_info.is_into_sleep = is_into_sleep;
+    screen_dis_info.is_left = is_left;
+    screen_dis_info.is_change_power = is_change_power;
+    screen_dis_info.is_dont_dis = is_dont_dis;
+    screen_dis_info.sleep_ms = ms;
+    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
+    {
+        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
+    }
+}
 void terminal_send_data(void)
 {
     // send_rssi();
@@ -227,39 +226,20 @@ void screen_display(void)
      * happened. */
     if (bits == 3)
     {
-        xQueueReset(screen_queue);
-        screen_dis_info.is_left = true;
-        screen_dis_info.is_into_sleep = false;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
-        screen_dis_info.is_left = false;
-        screen_dis_info.is_into_sleep = true;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
+        // xQueueReset(screen_queue);
+        set_screen_dis_info_and_send_queue(false, true, false, false,100);
+        set_screen_dis_info_and_send_queue(true, false, false, false,100);
     }
     else if (bits & RIGHT_SCREEN_BIT)
     {
         ESP_LOGE(LOG_TAG, "RIGHT_SCREEN_BIT");
-        screen_dis_info.is_left = false;
-        screen_dis_info.is_into_sleep = true;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
+
+        set_screen_dis_info_and_send_queue(true, false, false, false,100);
     }
     else if (bits & LEFT_SCREEN_BIT)
     {
         ESP_LOGE(LOG_TAG, "LEFT_SCREEN_BIT");
-        screen_dis_info.is_left = true;
-        screen_dis_info.is_into_sleep = true;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
+        set_screen_dis_info_and_send_queue(true, true, false, false,100);
     }
     else
     {
@@ -1374,7 +1354,7 @@ static void hardware_gwpair_func(const LORA_DATA_T *buf)
 #endif
 
 #if USER_LIGHT_SLEEP_ENABLE || USER_DEEP_SLEEP_ENABLE
-    sleep_timer_start(2000); // 进入睡眠
+    set_screen_dis_info_and_send_queue(false, true, false, true,100);
 #endif
 
     // printf("start timer id = %d,%d\r\n",Machine_info.eflagID,Machine_info.eflagID * TIMER_CAN_SEND_TIME);
@@ -1631,22 +1611,12 @@ void business_logic_func(const LORA_DATA_T *buf, uint8_t cmd_index, int msg)
         hardware_gwpair_func(buf);
         // Paint_leftScreen_main_quick(&Machine_info);
         // Paint_rightScreen_main_quick(&Machine_info);
-        xQueueReset(screen_queue);
-        screen_dis_info.is_left = true;
-        screen_dis_info.is_into_sleep = false;
+        // xQueueReset(screen_queue);
         // 重置快刷
         Machine_info.left_current_Quick_refresh_time = 0;
         Machine_info.right_current_Quick_refresh_time = 0;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
-        screen_dis_info.is_left = false;
-        screen_dis_info.is_into_sleep = false;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
+        set_screen_dis_info_and_send_queue(false, true, false, false,100);
+        set_screen_dis_info_and_send_queue(false, false, false, false,100);
         break;
 
     case PROTOCOL_HARDWARE_UNGWPAIRED: // 取消配网
@@ -2347,12 +2317,12 @@ void f_send_get_time(void)
     strlorabuf[7] = mac_addr[4];
     strlorabuf[8] = mac_addr[5];
     strlorabuf[9] = Machine_info.eflagID; // 组内编号
-    strlorabuf[10] = 0x01;// cmd命令字
+    strlorabuf[10] = 0x01;                // cmd命令字
+
+    Machine_info.msg_id = allocateMsgIdNum(); // 分配ID
 
-    Machine_info.msg_id = allocateMsgIdNum();// 分配ID
-             
     strlorabuf[11] = ((Machine_info.msg_id) >> 8) & 0XFF; //
-    strlorabuf[12] = ((Machine_info.msg_id) >> 0) & 0XFF;     // 总包数,当前包数
+    strlorabuf[12] = ((Machine_info.msg_id) >> 0) & 0XFF; // 总包数,当前包数
 
     strlorabuf[13] = 0x00;
     strlorabuf[14] = 0x00; // 长度
@@ -2363,7 +2333,7 @@ void f_send_get_time(void)
         crc16 = crc16 + strlorabuf[i];
     strlorabuf[2] = crc16 & 0xff;
 
-    changebintotxt(strlorabuf, 15);// Serial.println((char *)strlorabuf);
+    changebintotxt(strlorabuf, 15); // Serial.println((char *)strlorabuf);
     strcat((char *)strlorabuf, (char *)Machine_info.cid);
     len = strlen((char *)strlorabuf);
 
@@ -3581,12 +3551,7 @@ void lora_rev_cmd_send_ack()
 }
 void right_screen_send()
 {
-    screen_dis_info.is_left = false;
-    screen_dis_info.is_into_sleep = true;
-    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-    {
-        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-    }
+    set_screen_dis_info_and_send_queue(true, false, false, false,100);
 }
 void user_compare(int last, int now) // 这个函数用来比较rssi和 电量变化 刷右屏//
 {
@@ -3689,11 +3654,7 @@ void user_compare_power_off(int last, int now) // 这个函数用来比较关机
     }
     if (is_dis)
     {
-        screen_dis_info.is_left = false;
-        screen_dis_info.is_into_sleep = true;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
+
+        set_screen_dis_info_and_send_queue(true, false, false, false,100);
     }
 }

+ 4 - 0
main/yc_protocol.h

@@ -56,6 +56,9 @@ typedef struct
 {
     bool is_into_sleep;
     bool is_left;
+    bool is_change_power;
+    bool is_dont_dis;//把所有进睡眠统一起来
+    int sleep_ms;
 } Screen_dis_t;
 extern Screen_dis_t screen_dis_info;
 
@@ -313,6 +316,7 @@ void user_compare_power_off(int last, int now); // 这个函数用来比较关
 
 void right_screen_send();
 void f_send_get_time(void);
+void set_screen_dis_info_and_send_queue(bool is_into_sleep,bool is_left,bool is_change_power,bool is_dont_dis,int ms);
 // /* 链表节点结构体 */
 // struct ListNode {
 //     uint16_t number;               // 节点值

+ 49 - 65
main/yc_terminal.c

@@ -57,7 +57,7 @@ QueueHandle_t wakeup_queue;
 
 QueueHandle_t Send_Data_queue; // 发送链表任务
 
-SemaphoreHandle_t button_semaphore; // 刷新屏幕时都得加上按键互斥锁
+// SemaphoreHandle_t button_semaphore; // 刷新屏幕时都得加上按键互斥锁
 
 // SemaphoreHandle_t screen_semaphore;  //刷新屏幕时都得加上互斥锁
 
@@ -395,12 +395,7 @@ if(tmp_paint_buf!=NULL)
         adc1_init();
         // extern void dis_right_instructions();
         // dis_right_instructions();
-        screen_dis_info.is_left = false;
-        screen_dis_info.is_into_sleep = true;
-        if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-        {
-            ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-        }
+        set_screen_dis_info_and_send_queue(true, false, false, false,100);
         int power_key = 0;
         int charge_key = 0;
 
@@ -447,16 +442,13 @@ if(tmp_paint_buf!=NULL)
                 // extern void dis_right_instructions();
                 // dis_right_instructions();
 
-                if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                {
-                    ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                }
+                set_screen_dis_info_and_send_queue(true, false, false, false,100);
 
                 printf("start power off\r\n");
                 uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
 
 #if 1 // 电源按键
-                // adc_oneshot_del_unit(adc1_handle);
+      // adc_oneshot_del_unit(adc1_handle);
                 gpio_reset_pin(4);
                 int ext_wakeup_pin_0 = 4;
                 printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
@@ -547,7 +539,7 @@ if(tmp_paint_buf!=NULL)
                     uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
 
 #if 1 // 电源按键
-                    // adc_oneshot_del_unit(adc1_handle);
+      // adc_oneshot_del_unit(adc1_handle);
                     gpio_reset_pin(4);
                     int ext_wakeup_pin_0 = 4;
                     printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
@@ -609,7 +601,7 @@ if(tmp_paint_buf!=NULL)
                 uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
 
 #if 1 // 电源按键
-                // adc_oneshot_del_unit(adc1_handle);
+      // adc_oneshot_del_unit(adc1_handle);
                 gpio_reset_pin(4);
                 int ext_wakeup_pin_0 = 4;
                 printf("Enabling EXT0 wakeup on pin GPIO%d\n", ext_wakeup_pin_0);
@@ -732,11 +724,7 @@ if(tmp_paint_buf!=NULL)
                 beep_blink(30, 1);
 
 #if 1
-                screen_dis_info.is_left = true;
-                if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                {
-                    printf("left send fail\r\n");
-                }
+                set_screen_dis_info_and_send_queue(true, true, false, false,100);
 #endif
 
                 while (1)
@@ -868,8 +856,16 @@ static void screen_task(void *arg)
     {
         if (xQueueReceive(screen_queue, &screen_rev_info, (TickType_t)portMAX_DELAY))
         {
+            ESP_LOGW(LOG_TAG, "screen_rev_info==>%s , %s ,%s ,%s", screen_rev_info.is_left ? "left refreshing" : "right refreshing", screen_rev_info.is_into_sleep ? "into sleep" : "not sleep",
+            screen_rev_info.is_change_power?"change power":"not change power",screen_rev_info.is_dont_dis?"dont dis":"dis");
+            if (screen_rev_info.is_dont_dis)
+            {
+                ESP_LOGE(LOG_TAG, "goto -> dont_dis");
+                goto dont_dis;
+            }
+
             font_exit_sleep();
-            ESP_LOGI(LOG_TAG, "%s , %s", screen_rev_info.is_left ? "left refreshing" : "right refreshing", screen_rev_info.is_into_sleep ? "into sleep" : "not sleep");
+
             if (screen_rev_info.is_left) // 刷左屏
             {
                 if (Machine_info.left_current_Quick_refresh_time >= Machine_info.left_max_Quick_refresh_time)
@@ -895,11 +891,16 @@ static void screen_task(void *arg)
                     Paint_rightScreen(Machine_info.power_status, false);
                 }
             }
-
+        dont_dis:
             if ((Machine_info.power_status == 1) && (Machine_info.paired == 1) && screen_rev_info.is_into_sleep)
             {
-                ESP_LOGW(LOG_TAG, "100ms sleep  %s", screen_rev_info.is_left ? "left" : "right");
-                sleep_timer_start(100); // 进入睡眠
+                // ESP_LOGD(LOG_TAG, "100ms sleep  %s", screen_rev_info.is_left ? "left" : "right");
+                if (screen_rev_info.is_change_power)
+                {
+                    ESP_LOGE(LOG_TAG,"=============power_status %s========  set power off",Machine_info.power_status?"is power on":"is power off");
+                    Machine_info.power_status = 0; // 关机
+                }
+                sleep_timer_start(screen_rev_info.sleep_ms); // 进入睡眠
             }
 
             //             if(Machine_info.power_status == 0 )//展示说明书都是先左后右,等右屏刷完再休眠
@@ -951,7 +952,7 @@ static void button_task(void *arg)
                      Machine_info.rssi,
                      Machine_info.paired ? "paired" : "not pair");
 
-                    //  print_lora_set_info();
+            //  print_lora_set_info();
 #endif
             if (button_info < 0x12) // 左屏慕按键
             {
@@ -963,7 +964,8 @@ static void button_task(void *arg)
                     button_info = STATE_OPERATION; // 按键关闭,默认运行
                     if ((Machine_info.power_status == 1) && (Machine_info.paired == 1))
                     {
-                        sleep_timer_start(100); // 进入睡眠
+                        set_screen_dis_info_and_send_queue(false, false, false, true,100);
+                        // sleep_timer_start(100); // 进入睡眠
                     }
                 }
                 Machine_info.current_button.button_info = button_info;
@@ -1032,12 +1034,7 @@ static void button_task(void *arg)
                     // Machine_info.left_state = button_info;
                     Machine_info.left_state = Machine_info.current_button.button_info;
 #if 1
-                    screen_dis_info.is_left = true;
-                    screen_dis_info.is_into_sleep = true;
-                    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                    {
-                        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                    }
+                    set_screen_dis_info_and_send_queue(true, true, false, false,100);
 #endif
 
                     beep_blink(30, 1);
@@ -1048,7 +1045,8 @@ static void button_task(void *arg)
                 else // 和上个按键重复,唤醒原因为ulp唤醒,不进入休眠
                 {
                     printf("repeat ,goto sleep !\r\n");
-                    sleep_timer_start(100); // 开始进入倒计时休眠
+                    // sleep_timer_start(100); // 开始进入倒计时休眠
+                    set_screen_dis_info_and_send_queue(false, false, false, true,1000);
                 }
             }
             else // 右屏幕按键触发
@@ -1062,23 +1060,30 @@ static void button_task(void *arg)
                     if ((Machine_info.power_status == 1) && (Machine_info.paired == 1))
                     {
                         // 判断当前开机 是否配对 继续执行时间片操作
-                        sleep_timer_start(100); // 开始进入倒计时休眠
+                        // sleep_timer_start(100); // 开始进入倒计时休眠
+                        set_screen_dis_info_and_send_queue(false, false, false, true,1000);
+                        
                     }
                 }
 
-                if (button_info == POWER_OFF_PRESS_VALUE) // power  关机时短按
-                {
-                    sleep_timer_start(100); // 开始进入倒计时休眠
-                }
+                // if (button_info == POWER_OFF_PRESS_VALUE) // power  关机时短按
+                // {
+                //     sleep_timer_start(100); // 开始进入倒计时休眠
+                // }
 
                 if (button_info == POWER_ON_INTO_STATUS_CHANGE_VALUE) // power 长按触发
                 {
-
+                    extern bool is_sleep;
+                    is_sleep = false;//强制不休眠
                     beep_blink(1000, 1);
 
                     if (Machine_info.power_status == 1) // 开机状态
                     {
-                        Machine_info.power_status = 0;
+                        // Machine_info.power_status = 0;
+                        // screen_dis_info.is_change_power = true;
+                        xQueueReset(screen_queue);
+                        set_screen_dis_info_and_send_queue(false, true, false, false,100);
+                        set_screen_dis_info_and_send_queue(true, false, true, false,1000);//关机
                         printf("poweron->poweroff\r\n");
                     }
                     else if (Machine_info.power_status == 0)
@@ -1096,38 +1101,17 @@ static void button_task(void *arg)
 
                         // 恢复串口i功能
                         uart_sleep_out_config();
-                    }
-                    xQueueReset(screen_queue);
-                    screen_dis_info.is_left = true;
-                    screen_dis_info.is_into_sleep = false;
-                    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                    {
-                        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                    }
-                    screen_dis_info.is_left = false;
-                    screen_dis_info.is_into_sleep = true;
-                    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                    {
-                        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
+                        set_screen_dis_info_and_send_queue(false, true, false, false,100);
+                        set_screen_dis_info_and_send_queue(true, false, false, false,100);
                     }
                 }
 
                 if (button_info == POWER_ON_INTO_DIS_RIGHT)
                 {
                     xQueueReset(screen_queue);
-                    screen_dis_info.is_left = true;
-                    screen_dis_info.is_into_sleep = false;
-                    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                    {
-                        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                    }
-                    screen_dis_info.is_left = false;
-                    screen_dis_info.is_into_sleep = true;
                     Machine_info.left_current_Quick_refresh_time = 5;
-                    if (xQueueSend(screen_queue, &screen_dis_info, portMAX_DELAY) != true)
-                    {
-                        ESP_LOGE(LOG_TAG, "err:screen queue send fail");
-                    }
+                    set_screen_dis_info_and_send_queue(false, true, false, false,100);
+                    set_screen_dis_info_and_send_queue(true, false, false, false,100);
                 }
 
                 if (button_info == POWER_ON_INTO_OTA_VALUE) // 进入OTA模式
@@ -1448,7 +1432,7 @@ void read_deal_data_callback_handler()
             user_size = y_ringbuf_get_used_size(lora_ringbuf);
             if (user_size > 0)
             {
-                printf("-->lora len = %d\r\n", user_size);
+                ESP_LOGI(LOG_TAG, "-->lora len = %d\r\n", user_size);
 #if 0
             if(user_size == 36)
             {