wanghechen 10 месяцев назад
Родитель
Сommit
a3a52c6c02

+ 4 - 6
components/EPD/EPD.c

@@ -11,8 +11,8 @@
 // #include "../components/../main/user_sleep.h"
 #include "esp_timer.h"
 
-bool is_epd_ok = false;
-bool is_epd_ok_cplt = false;
+bool is_epd_ok = true;
+bool is_epd_ok_cplt = true;
 #include "../../main/user_sleep.h"
 #include "esp_sleep.h"
 
@@ -355,7 +355,6 @@ static void epd_data(screen_t screen, spi_device_handle_t spi, const uint8_t *da
         return; // no need to send anything
     if (len > SPI_MAX_LEN)
     {
-        is_epd_ok_cplt = false;
         int i;
         for (i = 0; i < len; i = i + SPI_MAX_LEN)
         {
@@ -376,7 +375,6 @@ static void epd_data(screen_t screen, spi_device_handle_t spi, const uint8_t *da
         ret = user_spi_device_queue_trans(spi, &t, portMAX_DELAY); // Transmit!
         assert(ret == ESP_OK);                                     // Should have had no issues.
         spi_get_result(spi);
-        is_epd_ok_cplt = true;
         // printf("-next2--%d\n", len);
         return;
     }
@@ -509,7 +507,7 @@ bool epd_check_status(screen_t screen)
                 t_after_us = esp_timer_get_time();
                 if ((t_after_us - t_before_us) > 1000 * 1000)
                 {
-                    printf("t_before_us =%lld ,t_after_us = %lld\n", t_before_us, t_after_us);
+                    // printf("t_before_us =%lld ,t_after_us = %lld\n", t_before_us, t_after_us);
                     return 0;
                     break;
                 }
@@ -540,7 +538,7 @@ bool epd_check_status(screen_t screen)
                 t_after_us = esp_timer_get_time();
                 if ((t_after_us - t_before_us) > 1000 * 1000)
                 {
-                    printf(" r t_before_us =%lld ,t_after_us = %lld\n", t_before_us, t_after_us);
+                    // printf(" r t_before_us =%lld ,t_after_us = %lld\n", t_before_us, t_after_us);
                     return 0;
                     break;
                 }

+ 57 - 76
components/EPD/include/EPD.h

@@ -3,90 +3,82 @@
 #include <inttypes.h>
 #include "driver/gpio.h"
 
-
 #define SOFTWARE_SPI_ENABLE 0
 
-#define QUICK_DISPLAY  0     //快刷
+#define QUICK_DISPLAY 0 // 快刷
 
-#define HARDWARE_SPI        1
-#if HARDWARE_SPI    
+#define HARDWARE_SPI 1
+#if HARDWARE_SPI
 
 #include "driver/spi_master.h"
 
 #define SPI_MAX_LEN 3200
 
-#define EPD_HOST    SPI2_HOST
+#define EPD_HOST SPI2_HOST
 
 #define PIN_SPI_MOSI 45
-#define PIN_SPI_CLK  48
+#define PIN_SPI_CLK 48
 
-#define PIN_L_CS   39
-#define PIN_L_DC   40
-#define PIN_L_RST  41
-#define PIN_L_BUSY  42
+#define PIN_L_CS 39
+#define PIN_L_DC 40
+#define PIN_L_RST 41
+#define PIN_L_BUSY 42
 
-#define PIN_R_CS   47
-#define PIN_R_DC   21
-#define PIN_R_RST  14
-#define PIN_R_BUSY  13
+#define PIN_R_CS 47
+#define PIN_R_DC 21
+#define PIN_R_RST 14
+#define PIN_R_BUSY 13
 
 #if !SOFTWARE_SPI_ENABLE //
-#define PIN_EPD_OUTPUT      ((1ULL<<PIN_L_CS)|(1ULL<<PIN_L_DC)|(1ULL<<PIN_L_RST)|(1ULL<<PIN_R_CS)|(1ULL<<PIN_R_DC)|(1ULL<<PIN_R_RST))
+#define PIN_EPD_OUTPUT ((1ULL << PIN_L_CS) | (1ULL << PIN_L_DC) | (1ULL << PIN_L_RST) | (1ULL << PIN_R_CS) | (1ULL << PIN_R_DC) | (1ULL << PIN_R_RST))
 #else
-#define PIN_EPD_OUTPUT      ((1ULL<<PIN_SPI_MOSI)|(1ULL<<PIN_SPI_CLK)|(1ULL<<PIN_L_CS)|(1ULL<<PIN_L_DC)|(1ULL<<PIN_L_RST)|(1ULL<<PIN_R_CS)|(1ULL<<PIN_R_DC)|(1ULL<<PIN_R_RST))
+#define PIN_EPD_OUTPUT ((1ULL << PIN_SPI_MOSI) | (1ULL << PIN_SPI_CLK) | (1ULL << PIN_L_CS) | (1ULL << PIN_L_DC) | (1ULL << PIN_L_RST) | (1ULL << PIN_R_CS) | (1ULL << PIN_R_DC) | (1ULL << PIN_R_RST))
 #endif
 
+#define PIN_EPD_INPUT ((1ULL << PIN_L_BUSY) | (1ULL << PIN_R_BUSY))
 
-#define PIN_EPD_INPUT        ((1ULL<<PIN_L_BUSY)|(1ULL<<PIN_R_BUSY))
-
-
-typedef enum {
-    SCREEN_LEFT     = 1,
-    SCREEN_RIGHT    = 2,
-}screen_t;
-
+typedef enum
+{
+    SCREEN_LEFT = 1,
+    SCREEN_RIGHT = 2,
+} screen_t;
 
-typedef struct {
+typedef struct
+{
     uint8_t cmd;
     uint8_t data[16];
-    uint8_t databytes; //No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
+    uint8_t databytes; // No of data in data; bit 7 = delay after set; 0xFF = end of cmds.
 } epd_init_cmd_t;
 
-
 extern spi_device_handle_t epd_spi;
-
-void epd_write_cmd(screen_t screen, unsigned char command,bool keep_cs_active);
+extern bool is_epd_ok_cplt;
+void epd_write_cmd(screen_t screen, unsigned char command, bool keep_cs_active);
 void epd_write_data(screen_t screen, const uint8_t *data, int len);
 void epd_init(void);
-void epd_display(screen_t screen,const unsigned char* picData);
-void epd_cache(screen_t screen,const unsigned char* picData);
+void epd_display(screen_t screen, const unsigned char *picData);
+void epd_cache(screen_t screen, const unsigned char *picData);
 void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
-                         screen_t screen,const unsigned char* picData);
+                        screen_t screen, const unsigned char *picData);
 void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
-                         screen_t screen,const unsigned char* picData);
-
+                       screen_t screen, const unsigned char *picData);
 
-                         void epd_partial_cache1(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
-                         screen_t screen,const unsigned char* picData);
+void epd_partial_cache1(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,
+                        screen_t screen, const unsigned char *picData);
 void epd_powerOn_refresh(screen_t screen);
 
-
 void epd_init_cmd(screen_t screen);
 
 void epd_sleep(screen_t screen);
 
-
 bool epd_check_status(screen_t screen);
 void epd_refresh(screen_t screen);
 
-
 void epd_check_power_off(screen_t screen);
 void epd_check_power_on(screen_t screen);
 
+void epd_cache_quick_full_screen_refresh(screen_t screen, const unsigned char *old, const unsigned char *new);
 
-void epd_cache_quick_full_screen_refresh(screen_t screen,const unsigned char* old,const unsigned char* new);
-
-void epd_cache_quick_partial_screen_refresh(screen_t screen,uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,const unsigned char* old,const unsigned char* new);
+void epd_cache_quick_partial_screen_refresh(screen_t screen, uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend, const unsigned char *old, const unsigned char *new);
 
 unsigned int compressRLE(uint8_t *input, unsigned int size, uint8_t *output);
 // 解压函数
@@ -96,24 +88,19 @@ void deepsleep_epd_check_status(screen_t screen);
 
 void deepsleep_epd_powerOn_refresh_sleep(screen_t screen);
 
-
-
-bool epd_cache_quick(screen_t screen,const unsigned char* old,const unsigned char* new);
+bool epd_cache_quick(screen_t screen, const unsigned char *old, const unsigned char *new);
 void epd_powerOn_refresh_sleep(screen_t screen);
 
 // esp_err_t user_spi_get_result(spi_device_handle_t spi);
 
 #else /*HARDWARE_SPI*/
 
-
-
-
-#define LOW_LEVEL       0
-#define HIGH_LEVEL      1
+#define LOW_LEVEL 0
+#define HIGH_LEVEL 1
 
 struct EPD_INFO_SET
 {
-    char* epd_name;
+    char *epd_name;
     uint8_t sclk_pin;
     uint8_t sda_pin;
     uint8_t busy_pin;
@@ -122,35 +109,29 @@ struct EPD_INFO_SET
     uint8_t cs_pin;
 };
 
-#define epd_set_level(EPD_PIN, LEVEL)     gpio_set_level(EPD_PIN, LEVEL)
-#define epd_get_level(EPD_PIN)               gpio_get_level(EPD_PIN)
-
-
-
-void epd_screen_init(struct EPD_INFO_SET* epd_pin_set);
-void epd_pin_init(struct EPD_INFO_SET* epd_pin_set);
-void epd_spi_write(struct EPD_INFO_SET* epd_pin_set, unsigned char value);
-void epd_write_cmd(struct EPD_INFO_SET* epd_pin_set, unsigned char command);
-void epd_write_data(struct EPD_INFO_SET* epd_pin_set, unsigned char command);
-void epd_init(struct EPD_INFO_SET* epd_pin_set);
-void epd_check_status(struct EPD_INFO_SET* epd_pin_set);
-void epd_refresh(struct EPD_INFO_SET* epd_pin_set);
-void epd_sleep(struct EPD_INFO_SET* epd_pin_set);
-void epd_clear_black(struct EPD_INFO_SET* epd_pin_set);
-void epd_clear_write(struct EPD_INFO_SET* epd_pin_set);
-
-
-
+#define epd_set_level(EPD_PIN, LEVEL) gpio_set_level(EPD_PIN, LEVEL)
+#define epd_get_level(EPD_PIN) gpio_get_level(EPD_PIN)
 
-void epd_display(struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
+void epd_screen_init(struct EPD_INFO_SET *epd_pin_set);
+void epd_pin_init(struct EPD_INFO_SET *epd_pin_set);
+void epd_spi_write(struct EPD_INFO_SET *epd_pin_set, unsigned char value);
+void epd_write_cmd(struct EPD_INFO_SET *epd_pin_set, unsigned char command);
+void epd_write_data(struct EPD_INFO_SET *epd_pin_set, unsigned char command);
+void epd_init(struct EPD_INFO_SET *epd_pin_set);
+void epd_check_status(struct EPD_INFO_SET *epd_pin_set);
+void epd_refresh(struct EPD_INFO_SET *epd_pin_set);
+void epd_sleep(struct EPD_INFO_SET *epd_pin_set);
+void epd_clear_black(struct EPD_INFO_SET *epd_pin_set);
+void epd_clear_write(struct EPD_INFO_SET *epd_pin_set);
 
+void epd_display(struct EPD_INFO_SET *epd_pin_set, const unsigned char *picData);
 
-void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
+void epd_display_partal(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend, struct EPD_INFO_SET *epd_pin_set, const unsigned char *picData);
 
-void epd_cache(struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
-void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend,struct EPD_INFO_SET* epd_pin_set,const unsigned char* picData);
-void epd_powerOn_refresh(struct EPD_INFO_SET* epd_pin_set);
+void epd_cache(struct EPD_INFO_SET *epd_pin_set, const unsigned char *picData);
+void epd_partial_cache(uint16_t Xstart, uint16_t Ystart, uint16_t Xend, uint16_t Yend, struct EPD_INFO_SET *epd_pin_set, const unsigned char *picData);
+void epd_powerOn_refresh(struct EPD_INFO_SET *epd_pin_set);
 
 #endif /*HARDWARE_SPI*/
 
-#endif/*_EPD_H_*/
+#endif /*_EPD_H_*/

+ 6 - 12
components/LORA/LORA.c

@@ -40,7 +40,6 @@ bool is_change_chanel = false;
 
 static const char *LOG_TAG = "LORA";
 
-
 uint8_t rawData_16[1024];
 extern QueueHandle_t lora_data_queue;
 // uint8_t rec_rssi;
@@ -57,7 +56,6 @@ uint8_t lora_software_version = 0;
 
 bool is_uart_wake = false;
 
-
 static esp_err_t uart_wakeup_config(void);
 
 // #if USER_QIXIN   //添加的初始化代码
@@ -742,13 +740,13 @@ void reset_lora(uint8_t new_channel)
     //     printf("\n\n");
     // }
 
-    lora_get_rssi(0x07);
+    // lora_get_rssi(0x07);
 
-    vTaskDelay(100 / portTICK_PERIOD_MS);
+    // vTaskDelay(100 / portTICK_PERIOD_MS);
 
-    user_size = y_ringbuf_get_used_size(lora_ringbuf);
+    // user_size = y_ringbuf_get_used_size(lora_ringbuf);
 
-    y_ringbuf_read_clear(lora_ringbuf, data, user_size);
+    // y_ringbuf_read_clear(lora_ringbuf, data, user_size);
 
     // if(user_size!=0)
     // {
@@ -2061,8 +2059,6 @@ void uart_sleep_out_config()
 {
 
   ESP_LOGW(LOG_TAG, "uart1 sleep out");
-  // gpio_reset_pin(LORA_TXD_PIN);
-  // gpio_reset_pin(LORA_RXD_PIN);
 
 #if VJ_LORA_ENABLE
   const uart_config_t uart_config = {
@@ -2513,7 +2509,6 @@ static void uart_event_task(void *pvParameters)
 
         printf("uart data len = %d\r\n", event.size);
 
-
         if (event.size > 0)
         {
           // 启动定时器,第二个参数为定时器超时时间,设置为0表示立即启动
@@ -2875,7 +2870,6 @@ int lora_send_data(const char *lora_data, int lora_data_len)
 
 void print_lora_set_info(void)
 {
-  ESP_LOGE(LOG_TAG,"lora_uart_Timerout %s",xTimerIsTimerActive(lora_uart_Timerout)?"Active":"not Active");
-  ESP_LOGE(LOG_TAG,"lora_uart_status = %d",lora_uart_status);
+  ESP_LOGE(LOG_TAG, "lora_uart_Timerout %s", xTimerIsTimerActive(lora_uart_Timerout) ? "Active" : "not Active");
+  ESP_LOGE(LOG_TAG, "lora_uart_status = %d", lora_uart_status);
 }
-

+ 27 - 76
main/ulp_riscv_adc_example_main.c

@@ -57,7 +57,7 @@ bool is_first_charge = false; // 当前充电发送只执行一次标志
 uint8_t charging_flag;
 extern const uint8_t ulp_main_bin_start[] asm("_binary_ulp_main_bin_start");
 extern const uint8_t ulp_main_bin_end[] asm("_binary_ulp_main_bin_end");
-
+extern bool is_paired_sleep;
 static void init_ulp_program(void);
 
 extern void app_init();
@@ -94,26 +94,18 @@ static void light_sleep_task(void *args)
     int lev_2 = 0;
     while (true)
     {
-        if (is_key_press() || !is_epd_ok|| !is_epd_ok_cplt)
+        if (is_key_press() || !is_epd_ok || !is_epd_ok_cplt)
         {
-            ESP_LOGI(LOG_TAG,"is_key_press() || !is_epd_ok|| !is_epd_ok_cplt");
+            ESP_LOGI(LOG_TAG, "%d %d %d not sleep 1s continue", is_key_press(), !is_epd_ok, !is_epd_ok_cplt);
             vTaskDelay(1000 / portTICK_PERIOD_MS);
-            continue; 
+            continue;
         }
         extern bool is_sleep;
         if (is_sleep == true)
         {
-// printf("system is ready sleep\r\n");
-#if LORA_SLEEP_ENABLE
-            // rtc_gpio_hold_dis(LORA_POWER_PIN);
             lora_set_power_level(0);
-// rtc_gpio_hold_en(LORA_POWER_PIN);
-#endif
-
 #if USER_LIGHT_SLEEP_ENABLE
 
-            is_first_run = false;
-
             // ESP_LOGE(LOG_TAG, "start light_sleep ,is_first_run = %d\r\n", is_first_run);
 
             if (Machine_info.power_status == 0) // 关机状态
@@ -223,20 +215,15 @@ static void light_sleep_task(void *args)
                 iot_button_stop();
                 adc_oneshot_del_unit(adc1_handle);
                 vTaskDelay(100 / portTICK_PERIOD_MS);
+                is_first_run = false;
                 esp_deep_sleep_start();
                 // }
 
                 // 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 )*/
+            else if ((Machine_info.power_status == 1) && Machine_info.paired == 1 && is_paired_sleep) // 开机状态且配对
             {
-                // 重新配置休眠唤醒时间
-                // printf("esp_sleep_enable_timer_wakeup ret = %d\n",esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US));//配置当前休眠的唤醒时间
-
+                is_paired_sleep = false; // 只有发送完lora消息后才会进入休眠
                 font_into_sleep();
 #include "EPD.h"
                 epd_sleep(SCREEN_LEFT);
@@ -295,39 +282,19 @@ static void light_sleep_task(void *args)
 
 #endif
 
-#if 0
-                            //充电按键
-                            gpio_reset_pin(2);
-                            const int ext_wakeup_pin_1 = 2;
-                            const uint64_t ext_wakeup_pin_1_mask = 1ULL << ext_wakeup_pin_1;
-                            printf("Enabling EXT1 wakeup on pins GPIO %d\r\n", ext_wakeup_pin_1);
-                            ESP_ERROR_CHECK(esp_sleep_enable_ext1_wakeup(ext_wakeup_pin_1_mask, ESP_EXT1_WAKEUP_ALL_LOW));
-#endif
-
 #endif
+                // 重新配置休眠唤醒时间
                 esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US); // 配置当前休眠的唤醒时间
-                                                                     // adc_oneshot_del_unit(adc1_handle);
-
-                // gpio_hold_en(4);
-
-                // vTaskDelay(100/ portTICK_PERIOD_MS);
-
                 // OTA 不休眠
                 if (!is_adv)
                 {
-
-                    // if (!is_key_press())
-                    // {
+                    getRtcTime(&Machine_info);
                     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);
+                    is_first_run = false;
                     esp_light_sleep_start();
-                    // }
-                    // else
-                    // {
-                    //     ESP_LOGW(LOG_TAG, "power key is press\r\n");
-                    // }
                 }
                 else
                 {
@@ -335,17 +302,15 @@ static void light_sleep_task(void *args)
                     ESP_LOGW(LOG_TAG, "OTA not sleep");
                 }
             }
+            else
+            {
+                goto not_sleep;
+            }
 
             is_sleep = false;
 #endif
-            // #if USER_DEEP_SLEEP_ENABLE
-            // printf("start deep sleep\r\n");
-            // uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
-            // //重新配置休眠唤醒时间
-            // esp_sleep_enable_timer_wakeup(TIMER_WAKEUP_TIME_US);  //配置当前休眠的唤醒时间
-            // // enter deep sleep
-            // esp_deep_sleep_start();
-            // #endif
+        not_sleep:
+            ESP_LOGE(LOG_TAG, "is_sleep = %d Machine_info.power_status = %d Machine_info.paired =%d is_paired_sleep = %d not_sleep", is_sleep, Machine_info.power_status, Machine_info.paired, is_paired_sleep);
         }
 
         // char *wakeup_reason = malloc(20*sizeof(uint8_t));
@@ -358,29 +323,7 @@ static void light_sleep_task(void *args)
         switch (reson)
         {
         case ESP_SLEEP_WAKEUP_TIMER:
-
             iot_button_resume();
-            // // wakeup_reason = "timer";
-            // #if LORA_SLEEP_ENABLE
-            //             // rtc_gpio_pullup_dis(LORA_POWER_PIN);
-            //             // rtc_gpio_deinit(LORA_POWER_PIN);
-            //             // rtc_gpio_init(LORA_POWER_PIN);
-            //             // rtc_gpio_set_direction(LORA_POWER_PIN, RTC_GPIO_MODE_OUTPUT_ONLY);
-            //             // rtc_gpio_pullup_en(LORA_POWER_PIN);
-            //             // rtc_gpio_set_level(LORA_POWER_PIN, 1);
-            //             lora_set_power_level(1); // 打开lora电源
-            // // rtc_gpio_hold_en(LORA_POWER_PIN);
-            // #endif
-
-            // #if FONT_SLEEP_ENABLE          // 字库唤醒恢复供电
-            //             font_exit_sleep(); // 退出睡眠
-
-            // #endif
-
-            // #if LCD_SLEEP_ENABLE
-
-            // #endif
-
             if (is_first_run == false)
             {
                 lora_set_power_level(1); // 打开lora电源
@@ -432,6 +375,8 @@ static void light_sleep_task(void *args)
                 // Machine_info.eflagID = 0x01;
                 // Already_send_timer_stop();
                 Already_send_timer_start(LORA_POWER_TIME + (Machine_info.eflagID * TIMER_CAN_SEND_TIME));
+
+                // Already_send_timer_start(LORA_POWER_TIME +2000);
                 // sleep_timer_start(700);  //进入睡眠
                 is_first_run = true;
             }
@@ -516,6 +461,11 @@ static void light_sleep_task(void *args)
             break;
         case ESP_SLEEP_WAKEUP_ULP:
             iot_button_resume();
+            if (Machine_info.paired == 1)
+            {
+                is_paired_sleep = true;
+                ESP_LOGW(LOG_TAG, "is_paired_sleep = true");
+            }
             break;
         case ESP_SLEEP_WAKEUP_EXT0:
 
@@ -534,6 +484,7 @@ static void light_sleep_task(void *args)
 
             break;
         }
+        // 先屏蔽电量刷屏部分代码2024.1.11
         /* extern bool is_adv;
          if(is_adv)//OTA 模式不检测电量
          {
@@ -548,7 +499,7 @@ static void light_sleep_task(void *args)
         {
             if (read_battery_voltage() == 0)
             {
-                ESP_LOGE(LOG_TAG,"-->low batt!!!! , power off\r\n");
+                ESP_LOGE(LOG_TAG, "-->low batt!!!! , power off\r\n");
 #if 0
                 set_screen_dis_info_and_send_queue(false, false, false, false,100);
                 set_screen_dis_info_and_send_queue(true, false, true, false,100);
@@ -596,8 +547,8 @@ static void light_sleep_task(void *args)
             {
                 bat_times = 0;
                 Machine_info.batt_precent = read_battery_voltage();
-                printf("compare current bat and last bat refresh display,current = %d,last =%d\r\n", Machine_info.batt_precent, Machine_info.last_batt_precent);
-                user_compare(Machine_info.last_batt_precent, Machine_info.batt_precent); // 刷完左屏,比较一次电量。电量值不同则刷一次右屏
+                // printf("compare current bat and last bat refresh display,current = %d,last =%d\r\n", Machine_info.batt_precent, Machine_info.last_batt_precent);
+                // user_compare(Machine_info.last_batt_precent, Machine_info.batt_precent); // 刷完左屏,比较一次电量。电量值不同则刷一次右屏
                 Machine_info.last_batt_precent = Machine_info.batt_precent;
             }
         }

+ 6 - 4
main/user_sleep.c

@@ -29,7 +29,7 @@
 #define TIMER_CHOICE 1 // 0:ESP  //1 FREERTOS
 
 #if TIMER_CHOICE
-
+bool is_paired_sleep = false;//配对后进入休眠标志,防止串口1数据错乱
 TimerHandle_t sleep_timer;        // 进入休眠定时器
 TimerHandle_t already_send_timer; // 可以发送数据的定时器
 #else
@@ -180,7 +180,7 @@ void Already_send_timer_callback(void *arg)
         {
             vTaskDelay(50 / portTICK_PERIOD_MS);
             lora_send_data((char *)Send_list->data, Send_list->len);
-            printf("->send one data to gateway\r\n");
+            ESP_LOG_BUFFER_HEX("->send one data to gateway", Send_list->data, Send_list->len);
         }
         else
         {
@@ -193,7 +193,9 @@ 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(100); // 进入睡眠
+    is_paired_sleep = true;
+     ESP_LOGW(LOG_TAG,"2is_paired_sleep = true");
+    sleep_timer_start(500); // 进入睡眠
 #endif
 
 #else
@@ -232,7 +234,7 @@ void Already_send_timer_start(int ms)
 {
 #if TIMER_CHOICE
     xTimerStop(already_send_timer, 0); // 停止定时器
-    // 在这里可以改变定时器的超时时间
+    // 在这里可以改变定时器的超时时间+
     // 第一个参数是定时器句柄,第二个参数是新的超时时间(以时钟节拍为单位)
     xTimerChangePeriod(already_send_timer, pdMS_TO_TICKS(ms), 0);
     xTimerStart(already_send_timer, 0); // 开始定时器

+ 1 - 1
main/yc_paint.c

@@ -1591,7 +1591,7 @@ void Paint_leftScreen(bool is_poweron, bool is_quick)
 
     uint8_t *background_128x64_buf = (uint8_t *)calloc(128 * 64 / 8, sizeof(uint8_t));
     // 得到图像buf
-    ESP_LOGW(LOG_TAG, "----------------Machine_info.left_state = %d-------left_display_mode =%d -------\r\n", Machine_info.left_state, Machine_info.left_display_mode);
+    // ESP_LOGW(LOG_TAG, "----------------Machine_info.left_state = %d-------left_display_mode =%d -------\r\n", Machine_info.left_state, Machine_info.left_display_mode);
 
     switch (Machine_info.left_state)
     {

+ 17 - 7
main/yc_protocol.c

@@ -115,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 [22时] burn"); // 打印烧录时间
+    printf("=======%s======\r\n", "2024.1.9 [18时] burn"); // 打印烧录时间
     printf("=============%s===========\r\n", __TIME__);
     printf("=================================\r\n");
     printf("========version V %d.%d.%d==========\r\n", VERSION_X, VERSION_Y, VERSION_Z);
@@ -160,7 +160,7 @@ void f_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)
 {
-    ESP_LOGE(LOG_TAG, "%d %d %d %d %d ",is_into_sleep,is_left,is_change_power,is_dont_dis,ms);
+    ESP_LOGE(LOG_TAG, "set_screen_dis_info_and_send_queue %d %d %d %d %d ", is_into_sleep, is_left, is_change_power, is_dont_dis, 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;
@@ -1353,6 +1353,9 @@ static void hardware_gwpair_func(const LORA_DATA_T *buf)
 
     // xQueueReset(screen_queue);
     // 重置快刷
+    extern bool is_paired_sleep;
+    is_paired_sleep = true;
+     ESP_LOGW(LOG_TAG,"3is_paired_sleep = true");
     Machine_info.left_current_Quick_refresh_time = 0;
     Machine_info.right_current_Quick_refresh_time = 0;
     set_screen_dis_info_and_send_queue(false, true, false, false, 100);
@@ -1953,7 +1956,7 @@ bool subcontract(YC_DATA_T *data)
     uint8_t *buf = data->data;
     USE_DATA_T use_data;
 
-    bool refresh_flag = false;
+    volatile bool refresh_flag = false;
 
     u8 targetSequence[] = {0x5A, 0x51};
     int sequenceSize = sizeof(targetSequence);
@@ -1969,7 +1972,7 @@ bool subcontract(YC_DATA_T *data)
             if ((buf[0] == 0x5A) && (buf[1] == 0x51) && (result == 1))
             {
                 // 单条命令处理逻辑
-
+                printf("deal one data \r\n");
                 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);
 #if 0
@@ -1990,6 +1993,7 @@ bool subcontract(YC_DATA_T *data)
                 else
                 {
                     printf("mac is fail not deal\r\n");
+                    goto err;
                 }
             }
             else
@@ -2019,6 +2023,7 @@ bool subcontract(YC_DATA_T *data)
                     else
                     {
                         printf("mac is fail not deal\r\n");
+                        goto err;
                     }
                 }
             }
@@ -2067,11 +2072,16 @@ bool subcontract(YC_DATA_T *data)
             else
             {
                 printf("mac is fail not deal\r\n");
+                goto err;
             }
         }
     }
     free(positions);
     return refresh_flag;
+err:
+    refresh_flag = false;
+    free(positions);
+    return refresh_flag;
 }
 
 // // len:有效数据长度,不是总长//
@@ -2749,8 +2759,8 @@ void f_send_status_duration(void)
     for (i = 3; i < 27; i++)
         crc16 = crc16 + strlorabuf[i];
     strlorabuf[2] = crc16 & 0xff;
-    ESP_LOGE(LOG_TAG,"{cmd:0e}send_status_duration btn -->[%d] -->Duration_time = %ld -->time :%d %d %d %d %d %d %d",strlorabuf[15],Machine_info.Duration_time,strlorabuf[16],strlorabuf[17],strlorabuf[18],strlorabuf[19],strlorabuf[20],strlorabuf[21],strlorabuf[22]);
-
+    ESP_LOGE(LOG_TAG, "{cmd:0e}send_status_duration btn -->[%d] -->Duration_time = %ld -->time :%d %d %d %d %d %d %d", strlorabuf[15], Machine_info.Duration_time, strlorabuf[16], strlorabuf[17], strlorabuf[18], strlorabuf[19], strlorabuf[20], strlorabuf[21], strlorabuf[22]);
+    Machine_info.Duration_time = 0;
     changebintotxt(strlorabuf, 27);
 
     // printf("Machine_info cid %s\r\n",Machine_info.cid);
@@ -2853,7 +2863,7 @@ void f_send_update_status(void)
     strlorabuf[25] = (Machine_info.current_button.time_min >> 8) & 0xff;
     strlorabuf[26] = Machine_info.current_button.time_min & 0xff;
     strlorabuf[27] = 0;
-    ESP_LOGE(LOG_TAG,"@@send_update_status -->btn = [%d] -->time :%d %d %d %d %d %d %d",strlorabuf[15],strlorabuf[16],strlorabuf[17],strlorabuf[18],strlorabuf[19],strlorabuf[20],strlorabuf[21],strlorabuf[22]);
+    ESP_LOGE(LOG_TAG, "@@send_update_status -->btn = [%d] -->time :%d %d %d %d %d %d %d", strlorabuf[15], strlorabuf[16], strlorabuf[17], strlorabuf[18], strlorabuf[19], strlorabuf[20], strlorabuf[21], strlorabuf[22]);
 
     crc16 = strlorabuf[0] + strlorabuf[1];
     for (i = 3; i < 27; i++)

+ 8 - 5
main/yc_terminal.c

@@ -644,7 +644,7 @@ if(tmp_paint_buf!=NULL)
 
             if (Machine_info.power_status == 0)
             {
-                printf("left key press power off\r\n");
+                ESP_LOGW(LOG_TAG,"left key press power off\r\n");
                 uart_wait_tx_idle_polling(CONFIG_ESP_CONSOLE_UART_NUM);
 
 #if 1
@@ -712,6 +712,7 @@ if(tmp_paint_buf!=NULL)
                 ESP_ERROR_CHECK(esp_sleep_enable_ulp_wakeup());
 
 #endif
+                printf("esp_deep_sleep_start\r\n");
                 esp_deep_sleep_start();
             }
             else
@@ -829,7 +830,7 @@ if(tmp_paint_buf!=NULL)
 }
 static void screen_task(void *arg)
 {
-    Machine_info.rssi = 100;        // 没有获取到真数据,默认100
+    // Machine_info.rssi = 100;        // 没有获取到真数据,默认100
     int reson = is_wake_up_reson(); // 返回唤醒的原因
     ESP_LOGW(LOG_TAG, "screen_task  %d", reson);
     if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER) && (reson != ESP_SLEEP_WAKEUP_EXT0))
@@ -860,7 +861,7 @@ static void screen_task(void *arg)
             }
 
             font_exit_sleep();
-
+            is_epd_ok_cplt = false;
             if (screen_rev_info.is_left) // 刷左屏
             {
                 if (screen_rev_info.is_change_power)
@@ -891,6 +892,7 @@ static void screen_task(void *arg)
                     Paint_rightScreen(Machine_info.power_status, false);
                 }
             }
+            is_epd_ok_cplt = true;
         dont_dis:
             // ESP_LOGE(LOG_TAG, "%d %d %d", Machine_info.power_status, Machine_info.paired, screen_rev_info.is_into_sleep);
 
@@ -905,8 +907,10 @@ static void screen_task(void *arg)
 
             if (Machine_info.power_status == 0) // 展示说明书都是先左后右,等右屏刷完再休眠
             {
+                ESP_LOGW(LOG_TAG, "now is power off");
                 sleep_timer_start(1000); // 进入睡眠
             }
+            ESP_LOGW(LOG_TAG, "screen task over");
         }
     }
 }
@@ -940,7 +944,7 @@ static void button_task(void *arg)
             if (button_info < 0x12) // 左屏慕按键
             {
                 // vTaskDelay(200/ portTICK_PERIOD_MS);
-                //  print_lora();//按键查询lora配置
+                // print_lora(); // 按键查询lora配置
                 if (Machine_info.btn_dis_flag[button_info - 1] == false)
                 {
                     printf("btn is close\n");
@@ -1002,7 +1006,6 @@ static void button_task(void *arg)
 #endif
 
                         set_status_heights();
-                        Machine_info.Duration_time = 0;
 
                         // 更新上次的状态
                         update_last_button_info(Machine_info.last_button.button_info);