Browse Source

修改关机进入休眠,只刷左屏

wanghechen 8 tháng trước cách đây
mục cha
commit
5150e018db

+ 3 - 3
components/LORA/LORA.c

@@ -681,7 +681,7 @@ void print_lora(void)
   uint8_t  data[50] = {0};
   lora.lora_mode = Lora_Cmd_Mode;
   gpio_set_level(LORA_SET_PIN, 0);
-  
+
           lora_set_config_mode(0x01);
           vTaskDelay(100/ portTICK_PERIOD_MS);
            user_size = y_ringbuf_get_used_size(lora_ringbuf);
@@ -1109,7 +1109,7 @@ void lora_receive_callback_handler()
 
 
                         //printf("string =%s\r\n",data);
-                        printf("%.*s\n", user_size, data);
+                        printf("->Lora_UART_Mode %.*s\n", user_size, data);
                         //发送消息处理
                         #if 0
                         xQueueSend(lora_dealhandle, &length, portMAX_DELAY);
@@ -1117,7 +1117,7 @@ void lora_receive_callback_handler()
 
                         if (xQueueSend(lora_dealhandle, &length, portMAX_DELAY) == pdPASS) {
                             // 消息发送成功
-                            ESP_LOGW(LOG_TAG,"send ok");
+                            // ESP_LOGW(LOG_TAG,"send ok");
                         } else {
                             // 消息发送失败,可能是消息队列已满
                             ESP_LOGE(LOG_TAG,"send fail");

+ 3 - 0
components/button/include/iot_button.h

@@ -286,6 +286,9 @@ esp_err_t iot_button_resume(void);
  */
 esp_err_t iot_button_stop(void);
 
+
+bool is_button_timer_active(void);
+
 #ifdef __cplusplus
 }
 #endif

+ 5 - 0
components/button/iot_button.c

@@ -707,3 +707,8 @@ esp_err_t iot_button_stop(void)
     g_is_timer_running = false;
     return ESP_OK;
 }
+
+bool is_button_timer_active(void)//判断btn定时器是否活动
+{
+    return g_is_timer_running;
+}

+ 14 - 3
components/button/user_button.c

@@ -43,7 +43,8 @@ uint16_t adc_value[][2]=
 };
 
 
-
+static void press_up_cb(void *arg,void *usr_data);
+static void long_press_up_cb(void *arg,void *usr_data);
 
 
 
@@ -213,8 +214,10 @@ void button_init(adc_oneshot_unit_handle_t adc_handle)
             printf( "Button create failed");
         }
         button_idx = i;
-        int ret = iot_button_register_cb( user_button_handle[i], BUTTON_PRESS_DOWN, user_button_single_click_cb,button_idx);
-                  //iot_button_register_cb( user_powerbutton_handle[i], BUTTON_LONG_PRESS_START, power_long_press_cb,button_idx);
+        // 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_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);
     }
 
@@ -419,6 +422,14 @@ static void power_long_press_cb(void *arg,void *usr_data)
 }
 iot_button_get_long_press_hold_cnt((button_handle_t)arg)
 #else
+static void press_up_cb(void *arg,void *usr_data)
+{
+    ESP_LOGE(LOG_TAG,"BUTTON_PRESS_UP %d",(int)usr_data);
+}
+static void long_press_up_cb(void *arg,void *usr_data)
+{
+    ESP_LOGE(LOG_TAG,"BUTTON_LONG_PRESS_UP %d",(int)usr_data);
+}
 static void power_long_press_start_cb(void *arg,void *usr_data)
 {
     // printf("power_long_press_start_cb\n");

+ 50 - 62
main/ulp_riscv_adc_example_main.c

@@ -26,8 +26,6 @@
 #include "esp_adc/adc_cali_scheme.h"
 #include "user_sleep.h"
 
-#include "freertos/FreeRTOS.h"
-#include "freertos/task.h"
 #include "driver/uart.h"
 #include "esp_sleep.h"
 #include "esp_log.h"
@@ -47,12 +45,9 @@
 #include "esp_sleep.h"
 #include "soc/sens_reg.h"
 #include "driver/gpio.h"
-#include "ulp_riscv.h"
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 #include "freertos/timers.h"
-#include "esp_sleep.h"
-#include "driver/uart.h"
 #include "iot_button.h"
 
 static const char *LOG_TAG = "ulp_riscv_adc";
@@ -238,6 +233,10 @@ static void light_sleep_task(void *args)
                                 //esp_light_sleep_start();
 
                             }else if((Machine_info.power_status == 1) &&  Machine_info.paired == 1) //开机状态且配对
+                            /*{
+                                ESP_LOGW(LOG_TAG,"//开机状态且配对\r\n");//不进休眠
+                            }
+                            else if(Machine_info.paired ==0 )*/
                             {
                                 //重新配置休眠唤醒时间
                                 //printf("esp_sleep_enable_timer_wakeup ret = %d\n",esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US));//配置当前休眠的唤醒时间
@@ -323,12 +322,10 @@ static void light_sleep_task(void *args)
                         #endif
                             esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US);  //配置当前休眠的唤醒时间
                             //adc_oneshot_del_unit(adc1_handle);
-                            ESP_LOGW(LOG_TAG,"-> sleep\r\n");
-                            uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
-                            uart_wait_tx_idle_polling(1);
 
-                            extern bool left_refresh_complete;
-                            extern bool right_refresh_complete;
+
+                            // extern bool left_refresh_complete;
+                            // extern bool right_refresh_complete;
 
 
                             #if 0
@@ -367,7 +364,19 @@ static void light_sleep_task(void *args)
 
                             //OTA 不休眠
                             if(!is_adv){
-                                esp_light_sleep_start();
+                                ESP_LOGW(LOG_TAG,"-> sleep\r\n");
+                                uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
+                                uart_wait_tx_idle_polling(1);
+                                if(!is_button_timer_active())
+                                {
+                                    vTaskDelay(100/ portTICK_PERIOD_MS);//给出时间片
+                                    esp_light_sleep_start();
+                                }
+                                else
+                                {
+                                    ESP_LOGW(LOG_TAG,"-> btn is active\r\n");
+                                }
+
                             }else{
                                 iot_button_stop();
                                 ESP_LOGW(LOG_TAG,"OTA not sleep");
@@ -395,7 +404,7 @@ static void light_sleep_task(void *args)
         {
             terminal_send_data();  //添加数据队列
         }
-        // printf("reson = %d\r\n",reson);
+        ESP_LOGW(LOG_TAG,"wakeup reson = %d\r\n",reson);
         switch (reson) {
             case ESP_SLEEP_WAKEUP_TIMER:
 
@@ -476,9 +485,6 @@ static void light_sleep_task(void *args)
                 
                 break;
             case ESP_SLEEP_WAKEUP_GPIO:
-            bool is_left = false;
-            printf("ULP ESP_SLEEP_WAKEUP_GPIO  WAKE UP\r\n");
-
              lev_2 = gpio_get_level(2);
 
       
@@ -497,15 +503,13 @@ static void light_sleep_task(void *args)
 
                                 gpio_hold_dis(PIN_R_CS);
 
-                            is_left = false;
-                            if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+                            
+                            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,"queue:screen_queue");
+                                ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                             } 
-                                // extern void dis_right_instructions();
-                                // dis_right_instructions();
-                                //dis_instructions();
-                                //right_screen_send();
                                 printf("charge in\r\n");
                             }
 
@@ -515,15 +519,14 @@ static void light_sleep_task(void *args)
                             {
                                 Machine_info.is_charge = false;   //拔掉充电
                                 is_first_charge = false;
-
-                                //right_screen_send();
                                 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)
+                            // 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,"queue:screen_queue");
+                                ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                             } 
                                 sleep_timer_start(1000);
 
@@ -570,24 +573,14 @@ static void light_sleep_task(void *args)
 
                 break;
             case ESP_SLEEP_WAKEUP_UART:
-            printf("ESP_SLEEP_WAKEUP_UART\r\n");
+
                 //wakeup_reason = "uart";
                 /* Hang-up for a while to switch and execuse the uart task
                  * Otherwise the chip may fall sleep again before running uart task */
                  vTaskDelay(1);
                 break;
             case ESP_SLEEP_WAKEUP_ULP:
-             //wakeup_reason = "ulp";
                iot_button_resume();
-               printf("ULP SLEEP WAKE UP\r\n");
-                // is_sleep = true;//常按会进休眠,然后ulp唤醒,设置is_sleep = true,再次进入休眠
-                if(Machine_info.paired && Machine_info.power_status )
-                {
-                    printf("is_sleep = true\r\n");
-                    vTaskDelay(2000/ portTICK_PERIOD_MS);
-                    is_sleep = true;//配对且开机,进入休眠
-                }
-
              break;
             case ESP_SLEEP_WAKEUP_EXT0:
 
@@ -595,24 +588,17 @@ static void light_sleep_task(void *args)
             {
                 iot_button_resume();
             }
-            if(Machine_info.paired && Machine_info.power_status )
-            {
-                vTaskDelay(2000/ portTICK_PERIOD_MS);
-                is_sleep = true;//配对且开机,进入休眠
-            }
+            // if(Machine_info.paired && Machine_info.power_status )
+            // {
+            //     vTaskDelay(2000/ portTICK_PERIOD_MS);
+            //     is_sleep = true;//配对且开机,进入休眠
+            // }
 
-            printf("ESP_SLEEP_WAKEUP_EXT0 \r\n");
             break;
             default:
 
-
-            //printf("other = %d\r\n",reson);
-
-            //esp_light_sleep_start();
-            //wakeup_reason = "other";
             break;
         }
-        //free(wakeup_reason);
        /* extern bool is_adv;
         if(is_adv)//OTA 模式不检测电量
         {
@@ -629,15 +615,17 @@ static void light_sleep_task(void *args)
                 printf("-->low batt , power off\r\n");
                 Machine_info.power_status = 0;
                 // dis_instructions();  //进入关机界面
-                bool is_left = true;
-                if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
-                {
-                    ESP_LOGE(LOG_TAG,"queue:screen_queue");
-                } 
-                is_left = false;
-                if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+                // 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,"queue:screen_queue");
+                    ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                 } 
                 sleep_timer_start(1000);
             }
@@ -665,7 +653,7 @@ static void light_sleep_task(void *args)
                             is_left = false
                             if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
                             {
-                                ESP_LOGE(LOG_TAG,"queue:screen_queue");
+                                ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                             } 
                                 // extern void dis_right_instructions();
                                 // dis_right_instructions();
@@ -685,7 +673,7 @@ static void light_sleep_task(void *args)
                             is_left = false
                             if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
                             {
-                                ESP_LOGE(LOG_TAG,"queue:screen_queue");
+                                ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                             } 
 
                                 sleep_timer_start(1000);

+ 7 - 2
main/user_config.h

@@ -98,6 +98,11 @@ typedef enum
     STATE_END,
 }Machine_state_t;
 
+// typedef struct
+// {
+//     bool is_into_sleep;
+//     bool is_left;
+// }Screen_dis_t;
 
 
 extern int last_batt_precent;
@@ -105,6 +110,6 @@ extern int last_batt_precent;
 void esp_ble_ota(void);
 void reset_default(bool is_dis,uint8_t power_status);
 
-void Paint_leftScreen(bool is_poweron,bool is_paired,bool is_quick,bool is_test);
-void Paint_rightScreen(bool is_poweron,bool is_paired,bool is_quick,bool is_test);
+void Paint_leftScreen(bool is_poweron,bool is_test);
+void Paint_rightScreen(bool is_poweron,bool is_test);
 #endif

+ 4 - 4
main/yc_paint.c

@@ -1552,9 +1552,9 @@ static void dis_right_sms(void)
             ESP_LOGE(LOG_TAG,"err:右屏说明书保存失败");
         }
 }
-void Paint_leftScreen(bool is_poweron,bool is_paired,bool is_quick,bool is_test)
+void Paint_leftScreen(bool is_poweron,bool is_quick)
 {
-    ESP_LOGI(LOG_TAG,"Paint_leftScreen");
+    ESP_LOGI(LOG_TAG,"Paint_leftScreen %s - %s ",is_quick?"快刷":"慢刷",is_poweron?"开机":"关机");
     if(!is_poweron)
     {
         //关机展示说明书
@@ -1992,9 +1992,9 @@ void Paint_leftScreen(bool is_poweron,bool is_paired,bool is_quick,bool is_test)
 
     free(image_320x384_buf);
 }
-void Paint_rightScreen(bool is_poweron,bool is_paired,bool is_quick,bool is_test)
+void Paint_rightScreen(bool is_poweron,bool is_quick)
 {
-    ESP_LOGI(LOG_TAG,"Paint_rightScreen");
+    ESP_LOGI(LOG_TAG,"Paint_rightScreen %s  - %s ",is_quick?"快刷":"慢刷",is_poweron?"开机":"关机");
     if(!is_poweron)
     {
         //关机展示说明书

+ 51 - 39
main/yc_protocol.c

@@ -19,10 +19,10 @@
 #include "driver/uart.h"
 #include "freertos/timers.h"
 #include "SPIFFS.h"
+// #include "user_config.h"
 
 
-
-
+Screen_dis_t screen_dis_info;
 //声明一个TimerHandle_t类型的变量,用于存储定时器句柄
 
 extern EventGroupHandle_t screen_event;
@@ -108,18 +108,21 @@ void reset_default(bool is_dis,uint8_t power_status)
     }
     // Paint_leftScreen_main_quick(&Machine_info);
     // Paint_rightScreen_main_quick(&Machine_info);
-    bool is_left = true;
+
+    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,&is_left,portMAX_DELAY) != true)
+    if(xQueueSend(screen_queue,&screen_dis_info,portMAX_DELAY) != true)
     {
-        ESP_LOGE(LOG_TAG,"queue:screen_queue");
-    } 
-    is_left = false;
-    if(xQueueSend(screen_queue,&is_left,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,"queue:screen_queue");
+        ESP_LOGE(LOG_TAG,"err:screen queue send fail");
     } 
 }
 
@@ -223,7 +226,8 @@ void update_last_button_info(uint8_t btn)
 }
 void screen_display(void)
 {
-    bool is_left = false;
+
+
     font_exit_sleep();
 
     EventBits_t bits = xEventGroupWaitBits(screen_event,
@@ -236,33 +240,36 @@ void screen_display(void)
      * happened. */
     if(bits == 3){
 
-        printf("--------------------left right all screen---------------\r\n");
-        is_left = false;
-        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+        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,"queue:screen_queue");
+            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
         }
-        is_left = true;
-        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+        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,"queue:screen_queue");
+            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
         }
 
     }
     else if (bits & RIGHT_SCREEN_BIT) {
         ESP_LOGE(LOG_TAG,"RIGHT_SCREEN_BIT");
-        is_left = false;
-        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+        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,"queue:screen_queue");
+            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
         }
     } 
     else if (bits & LEFT_SCREEN_BIT) {
         ESP_LOGE(LOG_TAG,"LEFT_SCREEN_BIT");
-        is_left = true;
-        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+        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,"queue:screen_queue");
+            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
         }
     } else {
         ESP_LOGE(LOG_TAG, "UNEXPECTED EVENT");
@@ -1716,18 +1723,21 @@ 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);
-    bool is_left = true;
+
+    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,&is_left,portMAX_DELAY) != true)
+    if(xQueueSend(screen_queue,&screen_dis_info,portMAX_DELAY) != true)
     {
-        ESP_LOGE(LOG_TAG,"queue:screen_queue");
+        ESP_LOGE(LOG_TAG,"err:screen queue send fail");
     } 
-    is_left = false;
-    if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+    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,"queue:screen_queue");
+        ESP_LOGE(LOG_TAG,"err:screen queue send fail");
     } 
     break;
 
@@ -2105,14 +2115,14 @@ bool subcontract(YC_DATA_T* data)
 
                 use_data.data_len = all_len; //(((buf[positions[index] - 2])<<8) | ((buf[positions[index] - 1])))+2;
                 memcpy(use_data.data_buf,data->data ,use_data.data_len);
-                //print_yc_data(&use_data);
+#if 0
                 printf("single cmd len =%d\r\n",use_data.data_len);
                 for(int i = 0;i<use_data.data_len;i++)
                 {
                     printf("%02X",use_data.data_buf[i]);
                 }
                 printf("\r\n");
-
+#endif
                 bool is = mac_is_true(&use_data.data_buf[3]);
 
                 if(is)
@@ -2174,7 +2184,7 @@ bool subcontract(YC_DATA_T* data)
 
 
           rsp_msgid = (buf[13]<<8)|buf[14];  //获取当前消息id 用于删除;
-          printf("rsp_msgid %02x,%02x,%d\r\n",buf[13],buf[14],rsp_msgid);
+          ESP_LOGW(LOG_TAG,"--rsp_msgid %02x,%02x,%d\r\n",buf[13],buf[14],rsp_msgid);
         
             for(int index = 0;index<result;index++)
             {
@@ -2185,7 +2195,6 @@ bool subcontract(YC_DATA_T* data)
                     {
                         use_data.data_len = 15 + 2 + (((buf[positions[index] +13])<<8) | ((buf[positions[index]+14])));
 
-
                         use_data.data_buf[0] = 0x00;
                         use_data.data_buf[1] = 0x00;
 
@@ -3780,10 +3789,11 @@ void lora_rev_cmd_send_ack()
 }
 void right_screen_send()
 {
-    bool is_left = false;
-    if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+    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,"queue:screen_queue");
+        ESP_LOGE(LOG_TAG,"err:screen queue send fail");
     } 
 }
 void user_compare(int last,int now)//这个函数用来比较rssi和 电量变化 刷右屏//
@@ -3846,7 +3856,7 @@ void user_compare_power_off(int last,int now)//这个函数用来比较关机状
         // ESP_LOGW(LOG_TAG,"last[%d]-now[%d]",last,now);
         return;
     }
-    bool is_left = false;
+
     bool is_dis = false;
     switch (last)
     {
@@ -3892,9 +3902,11 @@ void user_compare_power_off(int last,int now)//这个函数用来比较关机状
     }
     if(is_dis)
     {
-        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+        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,"queue:screen_queue");
+            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
         } 
     }
 }

+ 6 - 2
main/yc_protocol.h

@@ -58,8 +58,12 @@ typedef enum
    KEY_NEW_STATUS_CMD      = 1,
 };
 
-
-
+typedef struct
+{
+    bool is_into_sleep;
+    bool is_left;
+}Screen_dis_t;
+extern Screen_dis_t screen_dis_info;
 
 typedef enum 
 {

+ 51 - 90
main/yc_terminal.c

@@ -358,7 +358,7 @@ void app_init()
 //charge_init();
 //decection_charging_init();
 
-    screen_queue   =   xQueueCreate(25, sizeof(bool));
+    screen_queue   =   xQueueCreate(25, sizeof(Screen_dis_t));
 
 
     lora_data_queue     =   xQueueCreate(20, sizeof(LORA_DATA_T));
@@ -467,10 +467,11 @@ if(last_paint_buf_right!=NULL)
         adc1_init();
         // extern void dis_right_instructions();
         // dis_right_instructions();
-    bool is_left = false;
-    if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+     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,"queue:screen_queue");
+        ESP_LOGE(LOG_TAG,"err:screen queue send fail");
     } 
         int power_key  = 0; 
         int charge_key = 0; 
@@ -489,7 +490,7 @@ if(last_paint_buf_right!=NULL)
             Machine_info.batt_precent =  read_battery_voltage();
 
             Machine_info.last_batt_precent = Machine_info.batt_precent;  
-        is_left = false;
+        screen_dis_info.is_left = false;
         while(1)
         {
             //value++;
@@ -520,10 +521,10 @@ if(last_paint_buf_right!=NULL)
 
                 // extern void dis_right_instructions();
                 // dis_right_instructions();
-                is_left = false;
-                if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+
+                if(xQueueSend(screen_queue,&screen_dis_info,portMAX_DELAY) != true)
                 {
-                    ESP_LOGE(LOG_TAG,"queue:screen_queue");
+                    ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                 } 
 
 
@@ -858,8 +859,8 @@ extern uint32_t ulp_wakeup_result;
 
                 
                     #if 1
-                    bool is_left = true;
-                        if(xQueueSend(screen_queue,&Machine_info,portMAX_DELAY) != true)
+                        screen_dis_info.is_left = true;
+                        if(xQueueSend(screen_queue,&screen_dis_info,portMAX_DELAY) != true)
                         {
                             printf("left send fail\r\n");
                         } 
@@ -1111,8 +1112,8 @@ static void screen_task(void* arg)
     {
         // Paint_leftScreen_main_powerOn();
         // Paint_rightScreen_main_powerON();
-        Paint_leftScreen(Machine_info.power_status,Machine_info.paired,false,false);
-        Paint_rightScreen(Machine_info.power_status,Machine_info.paired,false,false);
+        Paint_leftScreen(Machine_info.power_status,false);
+        Paint_rightScreen(Machine_info.power_status,false);
     }
     else if(reson == ESP_SLEEP_WAKEUP_EXT0)
     {
@@ -1120,30 +1121,29 @@ static void screen_task(void* arg)
         ESP_LOGW(LOG_TAG,"按键从深睡唤醒,开机刷新屏慕");
         //  Paint_leftScreen_main_slow(&Machine_info);
         //  Paint_rightScreen_main_slow(&Machine_info);
-        Paint_leftScreen(Machine_info.power_status,Machine_info.paired,false,false);
-        Paint_rightScreen(Machine_info.power_status,Machine_info.paired,false,false);
+        Paint_leftScreen(Machine_info.power_status,false);
+        Paint_rightScreen(Machine_info.power_status,false);
     }
-    bool is_left = false;
+    screen_dis_info.is_left = false;
+    screen_dis_info.is_into_sleep = true;
     Machine_info.left_current_Quick_refresh_time = 1;//开机慢刷
     while(1)
     {
-        if(xQueueReceive(screen_queue, &is_left,(TickType_t)portMAX_DELAY))
+        if(xQueueReceive(screen_queue, &screen_dis_info,(TickType_t)portMAX_DELAY))
         {
             font_exit_sleep();
-            ESP_LOGD(LOG_TAG,"%s",is_left?"左屏刷新":"右屏刷新");
-            if(is_left)//刷左屏
+            ESP_LOGI(LOG_TAG,"%s , %s",screen_dis_info.is_left?"左屏刷新":"右屏刷新",screen_dis_info.is_into_sleep?"进入睡眠":"不进睡眠");
+            if(screen_dis_info.is_left)//刷左屏
             {
                 if(Machine_info.left_current_Quick_refresh_time >=  Machine_info.left_max_Quick_refresh_time)
                 {
                     Machine_info.left_current_Quick_refresh_time = 0;
-                    // Paint_leftScreen_main_slow(&Machine_info);
-                    Paint_leftScreen(Machine_info.power_status,Machine_info.paired,false,false);
+                    Paint_leftScreen(Machine_info.power_status,false);
                 }
                 else
                 {
                     Machine_info.left_current_Quick_refresh_time++;
-                    // Paint_leftScreen_main_quick(&Machine_info);
-                    Paint_leftScreen(Machine_info.power_status,Machine_info.paired,true,false);
+                    Paint_leftScreen(Machine_info.power_status,true);
                 }
             }
             else//刷右屏
@@ -1151,21 +1151,21 @@ static void screen_task(void* arg)
                 if(Machine_info.right_current_Quick_refresh_time ==  0)
                 {
                     Machine_info.left_current_Quick_refresh_time = 1;
-                    Paint_rightScreen(Machine_info.power_status,Machine_info.paired,true,false);
+                    Paint_rightScreen(Machine_info.power_status,true);
                 }
                 else
                 {
-                    Paint_rightScreen(Machine_info.power_status,Machine_info.paired,false,false);
+                    Paint_rightScreen(Machine_info.power_status,false);
                 }
             }
 
-            if((Machine_info.power_status == 1)&&(Machine_info.paired == 1))
+            if((Machine_info.power_status == 1)&&(Machine_info.paired == 1)&& screen_dis_info.is_into_sleep)
             {
-                ESP_LOGW(LOG_TAG,"刷屏进入休眠 %s",is_left?"左屏刷新":"右屏刷新");
+                ESP_LOGW(LOG_TAG,"刷屏进入休眠 %s",screen_dis_info.is_left?"左屏刷新":"右屏刷新");
                 sleep_timer_start(100);  //进入睡眠
             }
 
-            if(Machine_info.power_status == 0 && is_left == false)//展示说明书都是先左后右,等右屏刷完再休眠
+            if(Machine_info.power_status == 0 && screen_dis_info.is_left == false)//展示说明书都是先左后右,等右屏刷完再休眠
             {
                 printf("=>screen deep sleep\r\n");
                 uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
@@ -1194,7 +1194,7 @@ static void button_task(void* arg)
 {
     //update_last_button_info(Machine_info.current_button.button_info);//初始化上个按键为运行,用作paint0703计时
     uint8_t button_info;
-    bool is_left = false;
+
     while(1)
     {
         if(xQueueReceive(button_Data_queue, &button_info, (TickType_t)portMAX_DELAY))
@@ -1216,7 +1216,8 @@ static void button_task(void* arg)
 #endif
             if(button_info < 0x12)  //左屏慕按键
             {
-                // print_lora();//按键查询lora配置 
+                // vTaskDelay(200/ portTICK_PERIOD_MS);
+                //  print_lora();//按键查询lora配置 
                 if(Machine_info.btn_dis_flag[button_info-1] == false)
                 {
                     printf("按键关闭,默认运行\n");
@@ -1234,7 +1235,7 @@ static void button_task(void* arg)
                 {        
                         if(Machine_info.paired == 1)
                         {
-                            printf("paired add data to list chanl = 0x%02x\r\n",Machine_info.lora_new_channel);
+                            // printf("paired add data to list chanl = 0x%02x\r\n",Machine_info.lora_new_channel);
                             getRtcTime(&Machine_info);  //获取当前时间
                             //更新当前时间
                             Machine_info.current_button.button_info = button_info;
@@ -1298,12 +1299,12 @@ static void button_task(void* arg)
                         Machine_info.last_button.button_info =  Machine_info.current_button.button_info;
                         // Machine_info.left_state = button_info;
                         Machine_info.left_state = Machine_info.current_button.button_info;
-                        ESP_LOGE(LOG_TAG,"----Machine_info.left_state = %d",Machine_info.left_state);
     #if 1
-                        bool is_left = true;
-                        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+                        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,"queue:screen_queue");
+                            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                         } 
     #endif 
                         // Set duty to 50%
@@ -1372,23 +1373,7 @@ static void button_task(void* arg)
                         if(Machine_info.power_status == 1)  //开机状态
                         {
                             Machine_info.power_status = 0;
-                            // dis_instructions();
-
-                            // bool is_left = true;
-                            // if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
-                            // {
-                            //     ESP_LOGE(LOG_TAG,"queue:screen_queue");
-                            // } 
-                            // is_left = false;
-                            // if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
-                            // {
-                            //     ESP_LOGE(LOG_TAG,"queue:screen_queue");
-                            // } 
-                            // vTaskDelay(1000 / portTICK_PERIOD_MS);
-                            // sleep_timer_start(100); //开始进入倒计时休眠 
-    
-                            printf("last power on current power off ready sleep\r\n");
-                            // sleep_timer_start(100); //开始进入倒计时休眠 //更改为刷完两个屏幕,倒计时
+                            printf("poweron->poweroff\r\n");
                         }
                         else if(Machine_info.power_status == 0)  
                         {
@@ -1407,55 +1392,30 @@ static void button_task(void* arg)
 
                             //恢复串口i功能
                             uart_sleep_out_config();
-                            
-
-                            // Paint_leftScreen_main_slow(&Machine_info);
-                            // Paint_rightScreen_main_slow(&Machine_info);
-                            // Paint_leftScreen_main_quick(&Machine_info);
-                            // Paint_rightScreen_main_quick(&Machine_info);
-                                                        // dis_instructions();
-                            // bool is_left = true;
-                            // if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
-                            // {
-                            //     ESP_LOGE(LOG_TAG,"queue:screen_queue");
-                            // } 
-                            // is_left = false;
-                            // if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
-                            // {
-                            //     ESP_LOGE(LOG_TAG,"queue:screen_queue");
-                            // } 
-
-                            // if( (Machine_info.power_status == 1) &&  (Machine_info.paired == 1))
-                            // {
-                            //     //判断当前开机 是否配对 继续执行时间片操作
-                            //     sleep_timer_start(100); //开始进入倒计时休眠 
-                            // }
+                        
                         }
 
-                        is_left = true;
-                        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+                        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,"queue:screen_queue");
+                            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                         } 
-                        is_left = false;
-                        if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+                        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,"queue:screen_queue");
+                            ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                         } 
-                        if(Machine_info.paired || !Machine_info.power_status)
-                        {
-                            sleep_timer_start(100); //开始进入倒计时休眠 
-                        }
-
                 }
 
 
                 if(button_info == POWER_ON_INTO_DIS_RIGHT) 
                 {
-                    is_left = false;
-                    if(xQueueSend(screen_queue,&is_left,portMAX_DELAY) != true)
+                    screen_dis_info.is_left = false;
+                    if(xQueueSend(screen_queue,&screen_dis_info,portMAX_DELAY) != true)
                     {
-                        ESP_LOGE(LOG_TAG,"queue:screen_queue");
+                        ESP_LOGE(LOG_TAG,"err:screen queue send fail");
                     } 
                 }
 
@@ -1804,7 +1764,7 @@ void read_deal_data_callback_handler()
             user_size = y_ringbuf_get_used_size(lora_ringbuf);
             if(user_size>0)
             {  
-                printf("times comming length=%d\r\n",user_size);
+                printf("lora 数据长度 = %d\r\n",user_size);
             #if 0
             if(user_size == 36)
             {
@@ -1821,13 +1781,14 @@ void read_deal_data_callback_handler()
                 {
 #if 1
                     int len = y_ringbuf_read_clear(lora_ringbuf, result, user_size); //读取并清除数据
-    #if 1
+    #if 0
                     for (int i = 0; i < user_size; i++)
                     {
                         printf("%02x",result[i]);
                     }
                     printf("\r\n");
     #endif
+                    ESP_LOG_BUFFER_HEX("接收的lora:",result,user_size);
                     yc_data.len =  user_size;
                     yc_data.data = malloc(sizeof(uint8_t)*user_size);//分配内存
                     memcpy(yc_data.data,result,user_size);