瀏覽代碼

左屏按键30s不发lora

wanghechen 8 月之前
父節點
當前提交
70c42fa622

+ 1 - 1
components/EPD/EPD.c

@@ -1484,7 +1484,7 @@ IRAM_ATTR bool epd_cache_quick(screen_t screen,const unsigned char* old,const un
 
     if((screen == SCREEN_LEFT)&&(old!=NULL))
     {
-        printf("left partial quick\r\n");
+        printf("epd_cache_quick\r\n");
         //Reset the display
         gpio_set_level(PIN_L_RST, 0);
         vTaskDelay(10 / portTICK_PERIOD_MS);

+ 63 - 48
components/LORA/LORA.c

@@ -24,7 +24,7 @@
 #include "sdkconfig.h"
 #include "../../main/user_sleep.h"
 #include "esp_sleep.h"
-
+#include "SPIFFS.h"
 QueueHandle_t lora_receiveQueue;
 
 
@@ -656,7 +656,7 @@ uint8_t set_lora(uint8_t new_channel,uint8_t eflag)
     gpio_set_level(LORA_SET_PIN, 1);
     return ret;
 }
-void reset_lora(void)
+void reset_lora(uint8_t new_channel)
 {
 
 
@@ -682,19 +682,20 @@ void reset_lora(void)
        
           y_ringbuf_read_clear(lora_ringbuf, data, user_size);
 
-          if(user_size!=0)
-          {
-              printf("rsp len = %d\r\n",user_size);
-              for(int i = 0;i<user_size;i++)
-              printf("%02x",data[i]);
-          }
+          // if(user_size!=0)
+          // {
+          //     printf("lora_set_config_mode len = %d\r\n",user_size);
+          //     for(int i = 0;i<user_size;i++)
+          //       printf("%02x",data[i]);
+          //     printf("\n\n");
+          // }
 
 
 
 
 
           
-          lora_set_channel(LORA_CHANENL);
+          lora_set_channel(new_channel);
           vTaskDelay(100/ portTICK_PERIOD_MS);
 
           user_size = y_ringbuf_get_used_size(lora_ringbuf);
@@ -702,6 +703,7 @@ void reset_lora(void)
           y_ringbuf_read_clear(lora_ringbuf, data, user_size);
           if(data[1] == 0xee)
           {
+            printf("->err\n\n\n");
             lora_set_channel(LORA_CHANENL);
             vTaskDelay(100/ portTICK_PERIOD_MS);
             user_size = y_ringbuf_get_used_size(lora_ringbuf);
@@ -709,9 +711,10 @@ void reset_lora(void)
           }
           if(user_size!=0 )
           {
-                printf("rsp len = %d\r\n",user_size);
+                printf("lora_set_channel len = %d\r\n",user_size);
               for(int i = 0;i<user_size;i++)
-              printf("%02x",data[i]);
+                printf("%02x",data[i]);
+              printf("\n\n");
           }
 
 
@@ -724,12 +727,13 @@ void reset_lora(void)
        
           y_ringbuf_read_clear(lora_ringbuf, data, user_size);
 
-          if(user_size!=0)
-          {
-                printf("rsp len = %d\r\n",user_size);
-              for(int i = 0;i<user_size;i++)
-              printf("%02x",data[i]);
-          }
+          // if(user_size!=0)
+          // {
+          //       printf("lora_set_bps len = %d\r\n",user_size);
+          //     for(int i = 0;i<user_size;i++)
+          //       printf("%02x",data[i]);
+          //     printf("\n\n");
+          // }
 
 
 
@@ -741,12 +745,13 @@ void reset_lora(void)
        
           y_ringbuf_read_clear(lora_ringbuf, data, user_size);
 
-          if(user_size!=0)
-          {
-                printf("rsp len = %d\r\n",user_size);
-              for(int i = 0;i<user_size;i++)
-              printf("%02x",data[i]);
-          }
+          // if(user_size!=0)
+          // {
+          //       printf("lora_set_device_id len = %d\r\n",user_size);
+          //     for(int i = 0;i<user_size;i++)
+          //       printf("%02x",data[i]);
+          //     printf("\n\n");
+          // }
 
 
           lora_set_dst_device_id(0xFFFFFFFF);
@@ -757,13 +762,14 @@ void reset_lora(void)
        
           y_ringbuf_read_clear(lora_ringbuf, data, user_size);
 
-          if(user_size!=0)
-          {
+          // if(user_size!=0)
+          // {
            
-                printf("rsp len = %d\r\n",user_size);
-              for(int i = 0;i<user_size;i++)
-              printf("%02x",data[i]);
-          }
+          //       printf("lora_set_dst_device_id len = %d\r\n",user_size);
+          //     for(int i = 0;i<user_size;i++)
+          //       printf("%02x",data[i]);
+          //     printf("\n\n");
+          // }
 
 
           lora_get_rssi(0x07);
@@ -774,13 +780,14 @@ void reset_lora(void)
        
           y_ringbuf_read_clear(lora_ringbuf, data, user_size);
 
-          if(user_size!=0)
-          {
+          // if(user_size!=0)
+          // {
               
-                printf("rsp len = %d\r\n",user_size);
-              for(int i = 0;i<user_size;i++)
-              printf("%02x",data[i]);
-          }
+          //       printf("lora_get_rssi len = %d\r\n",user_size);
+          //     for(int i = 0;i<user_size;i++)
+          //       printf("%02x",data[i]);
+          //     printf("\n\n");
+          // }
 
           
 
@@ -794,13 +801,13 @@ void reset_lora(void)
        
           y_ringbuf_read_clear(lora_ringbuf, data, user_size);
 
-          if(user_size!=0)
-          {
-              
-                printf("rsp len = %d\r\n",user_size);
-              for(int i = 0;i<user_size;i++)
-              printf("%02x",data[i]);
-          }
+          // if(user_size!=0)
+          // {
+          //   printf("lora_set_config_mode len = %d\r\n",user_size);
+          //   for(int i = 0;i<user_size;i++)
+          //     printf("%02x",data[i]);
+          //   printf("\n\n");
+          // }
 
 
 
@@ -820,9 +827,9 @@ void reset_lora(void)
 static void tx_task(void *arg)
 {
 
-	//Cmd_t cmd;
-	int index = 0;
-	unsigned char receivedMessage[30];
+	// //Cmd_t cmd;
+	// int index = 0;
+	// unsigned char receivedMessage[30];
 
 //发送lora初始化AT指令
 #if HPD_LORA_ENABLE
@@ -833,7 +840,7 @@ lora_sendData((unsigned char*)lora_cmd[lora.cmd_index].cmd,strlen((char *)lora_c
 #if VJ_LORA_ENABLE
 #if 1
 
-  reset_lora();
+  reset_lora(LORA_CHANENL);
 
 
 //lora_sendData((unsigned char*)lora_cmd[lora.cmd_index].cmd,4);
@@ -1992,7 +1999,7 @@ void lora_set_exit_config_mode()
 
 void lora_set_channel(uint8_t channel)
 {
-  //printf("%s\r\n",__FUNCTION__);
+  ESP_LOGW(LOG_TAG," ------>%s channel = %d\r\n",__FUNCTION__,channel);
 #if 1
    uint8_t lorabuf[4];
    lorabuf[0]=0x03;
@@ -2472,8 +2479,16 @@ int  reson = is_wake_up_reson();  //返回唤醒的原因
 if ((reson != ESP_SLEEP_WAKEUP_ULP) && (reson != ESP_SLEEP_WAKEUP_TIMER)/*&& (reson != ESP_SLEEP_WAKEUP_EXT0)*/) //ota完后软件复位,重新配置lora
 {
     printf("lora cmd init start\r\n");
+    extern Machine_info_t Machine_info;
+    if(Machine_info.lora_new_channel == LORA_CHANENL)
+    {
+      xTaskCreate(tx_task, "uart_tx_task", 1024*3, NULL, configMAX_PRIORITIES-1, &lora_uart_tx_handle);
+    }
+    else
+    {
+      ESP_LOGE(LOG_TAG,"不设置LORA_CHANENL");
+    }
 
-    xTaskCreate(tx_task, "uart_tx_task", 1024*2, NULL, configMAX_PRIORITIES-1, &lora_uart_tx_handle);
 }else
 {
   lora.lora_mode = Lora_UART_Mode;   //复位直接进入透传模式

+ 1 - 1
components/LORA/include/LORA.h

@@ -246,7 +246,7 @@ void timer_wake_uart_sleep_out_config();
 
 
 void lora_factory_config();
-void reset_lora(void);
+void reset_lora(uint8_t new_channel);
 uint8_t set_lora(uint8_t new_channel,uint8_t eflag);
 uint8_t crc8( uint8_t *pData, 
                     uint16_t dataLen,

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

@@ -136,8 +136,8 @@ void power_button_deinit(void);
 
 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);
 
 #endif/*_USER_BUTTON_H_*/

+ 71 - 22
components/button/user_button.c

@@ -11,11 +11,14 @@
 
 
 #include "../EPD//include/EPD.h"
-
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <sys/time.h>
 
 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;
@@ -25,9 +28,9 @@ static button_handle_t user_button_handle[KEY_NUM] = {0};
 
 static button_handle_t user_powerbutton_handle[3] = {0};
 TimerHandle_t btn_timer_handle;
-bool is_setting = false;
-bool is_reset_net = false;//配网
-
+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;
 
 uint16_t adc_value[][2]=
 {
@@ -135,7 +138,52 @@ void btn_timer_Callback(TimerHandle_t xTimer)
     is_setting = 0;
     //xTimerStop(btn_timer_handle,0);
 }
+static void get_rtc_time(struct tm* tmp)
+{
+    struct timeval tv;
+    gettimeofday(&tv, NULL);
+
+    // 打印 RTC 时间戳
+    printf("RTC Timestamp: %lld\n", tv.tv_sec);
 
+    // 使用 localtime 函数将时间戳转换为本地时间
+    tmp = localtime(&tv.tv_sec);
+
+    // 打印本地时间
+    printf(" get_rtc_time: %04d-%02d-%02d %02d:%02d:%02d\n",
+           tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
+           tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+}
+bool is_btn_timeout(void)
+{
+    struct timeval now_time;
+    gettimeofday(&now_time, NULL);
+    ESP_LOGW(LOG_TAG,"is_send_lora= %s now_time =  %lld,last =  %lld,\n",is_send_lora?"ture":"false",now_time.tv_sec, btn_last_time.tv_sec);
+    if(((now_time.tv_sec - btn_last_time.tv_sec) > 30)&&(is_send_lora))
+    {
+        struct tm* tmp = localtime(&now_time.tv_sec);
+        // printf("btn_last_time: %lld\n", btn_last_time.tv_sec);
+        ESP_LOGW(LOG_TAG,"发送-----现在按键时间: %04d-%02d-%02d %02d:%02d:%02d\n",
+        tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
+        tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+        is_send_lora = false;
+        return true;
+    }
+    return false;
+}
+void reset_btn_last_time(void)
+{
+    if(!is_send_lora)
+    {
+        is_send_lora = true;
+    }
+    gettimeofday(&btn_last_time, NULL);
+    struct tm* tmp = localtime(&btn_last_time.tv_sec);
+    // printf("btn_last_time: %lld\n", btn_last_time.tv_sec);
+    ESP_LOGW(LOG_TAG,"最后按键时间: %04d-%02d-%02d %02d:%02d:%02d\n",
+        tmp->tm_year + 1900, tmp->tm_mon + 1, tmp->tm_mday,
+        tmp->tm_hour, tmp->tm_min, tmp->tm_sec);
+}
 void button_init(adc_oneshot_unit_handle_t adc_handle)
 {
     int i;
@@ -168,21 +216,7 @@ void button_init(adc_oneshot_unit_handle_t adc_handle)
     }
 
     #endif
-
-}
-void button_deinit(void)
-{
-    printf("button_deinit\n");
-    for(int i=0;i<KEY_NUM;i++)
-    {
-        iot_button_delete(user_button_handle[i]);
-    }
-    //iot_button_delete(user_powerbutton_handle[0]);
-}
-
-
-void power_button_init(adc_oneshot_unit_handle_t adc_handle)
-{
+//电源按键
     btn_timer_handle = xTimerCreate(
     "btn_timer_handle",             
     pdMS_TO_TICKS(10*1000),    
@@ -191,7 +225,6 @@ void power_button_init(adc_oneshot_unit_handle_t adc_handle)
     btn_timer_Callback         
     );
 
- int i = 0;
 
 
 
@@ -270,7 +303,7 @@ void power_button_init(adc_oneshot_unit_handle_t adc_handle)
 
 
 
-        for(int i = 0;i < 1 ;i++)
+        for( i = 0;i < 1 ;i++)
     {
        //power_btn_cfg.adc_button_config.button_index = i;
        //power_btn_cfg.adc_button_config.min = power_adc_value[i][0] ;
@@ -330,6 +363,21 @@ void power_button_init(adc_oneshot_unit_handle_t adc_handle)
 
 
 
+}
+void button_deinit(void)
+{
+    printf("button_deinit\n");
+    for(int i=0;i<KEY_NUM;i++)
+    {
+        iot_button_delete(user_button_handle[i]);
+    }
+    //iot_button_delete(user_powerbutton_handle[0]);
+}
+
+
+void power_button_init(adc_oneshot_unit_handle_t adc_handle)
+{
+
 
 }
 
@@ -482,6 +530,7 @@ static void user_button_single_click_cb(void *arg,void *usr_data)
     is_setting = false;
     is_reset_net = false;
     ESP_LOGW(LOG_TAG," single_click_cb[%d]", iot_button_get_ticks_time((button_handle_t)arg));
+
     switch ((int)usr_data)
     {
     case BAOYANG_KEY:

+ 6 - 2
main/ulp_riscv_adc_example_main.c

@@ -391,6 +391,10 @@ static void light_sleep_task(void *args)
 
         //char *wakeup_reason = malloc(20*sizeof(uint8_t));
         int reson = esp_sleep_get_wakeup_cause();
+        if(is_btn_timeout())
+        {
+            terminal_send_data();  //添加数据队列
+        }
         // printf("reson = %d\r\n",reson);
         switch (reson) {
             case ESP_SLEEP_WAKEUP_TIMER:
@@ -434,7 +438,7 @@ static void light_sleep_task(void *args)
                     Machine_info.wait_send_rssi_bat++;
                     printf("唤醒: bat %d wait_send_rssi_bat = %d,\r\n",Machine_info.batt_precent,Machine_info.wait_send_rssi_bat);
 
-                    if(Machine_info.wait_send_rssi_bat>100)
+                    if(Machine_info.wait_send_rssi_bat>(30*60/TIMER_WAKEUP_TIME_S))//30分钟发一次lora
                     {
                         printf("already send rssi and bat\r\n");
                         Machine_info.wait_send_rssi_bat = 0;
@@ -447,7 +451,7 @@ static void light_sleep_task(void *args)
                     {
                         if(is_sync_time(&Machine_info))  //同步到时间
                         {
-                           printf("update left value min %d,last min %d\r\n",Machine_info.min,Machine_info.last_button.Minute); 
+                           ESP_LOGW(LOG_TAG,"update left value min %d,last min %d\r\n",Machine_info.min,Machine_info.last_button.Minute); 
                            Machine_info.last_button.time_min += (Machine_info.min - Machine_info.last_button.Minute);
                         }else
                         {

+ 2 - 2
main/user_sleep.h

@@ -2,8 +2,8 @@
 #define __USER_SLEEP_H__
 
 
-
-#define TIMER_WAKEUP_TIME_US    (6 * 1000 * 1000)     //定义的唤醒的时间         单位s
+#define TIMER_WAKEUP_TIME_S      6
+#define TIMER_WAKEUP_TIME_US    (TIMER_WAKEUP_TIME_S * 1000 * 1000)     //定义的唤醒的时间  
 #define TIMER_CAN_SEND_TIME     (200)                 //定义可以唤醒lora工作的时间单位ms
 #define LORA_POWER_TIME         (2000)
 

+ 2 - 2
main/yc_protocol.c

@@ -1671,7 +1671,7 @@ static void hardware_ungwpair_func(const LORA_DATA_T* buf)
     vTaskDelay(300 / portTICK_PERIOD_MS);
     Machine_info.lora_new_channel = LORA_CHANENL;
     // dymatic_change_chanel(Machine_info.lora_factory_channel);  //切换信道
-    reset_lora();
+    reset_lora(LORA_CHANENL);
 }
 /*网关收到终端发送的数据 ACK 终端收到用于删除当前的msgid的数据*/
 static void hardware_ack_delete_msg_id(const LORA_DATA_T* buf)
@@ -3337,7 +3337,7 @@ void set_status_heights(void)
 
 void lora_timer_callback(void* arg)
 {
-    ESP_LOGD(LOG_TAG," lora_timer_callback");
+    ESP_LOGI(LOG_TAG," lora_timer_callback");
     
     if(xQueueSend(yc_data_queue,&yc_data,0) != true)
     {

+ 10 - 10
main/yc_terminal.c

@@ -212,6 +212,7 @@ switch (ret) {
     
 
     strcpy((char *)Machine_info.cid,result);
+    // strcpy((char *)Machine_info.cid,"1tpmQwHNS");
     printf("device id %s,result = %s,len = %d\r\n",cid,result,len);
 
     printf("Machine_info cid %s\r\n",Machine_info.cid);
@@ -1205,8 +1206,8 @@ static void left_screen_task(void* arg)
             font_exit_sleep();
 
             printf("left 拿锁\n");
-            //if(xSemaphoreTake(screen_semaphore, portMAX_DELAY) == true)
-            if(1)
+            if(xSemaphoreTake(screen_semaphore, portMAX_DELAY) == true)
+            // if(1)
             {
                 if(Machine_info.left_current_Quick_refresh_time >=  Machine_info.left_max_Quick_refresh_time)
                 {
@@ -1220,7 +1221,7 @@ static void left_screen_task(void* arg)
                     Paint_leftScreen_main_quick(&info);
                 }
                 printf("left 还锁\n");
-                //xSemaphoreGive(screen_semaphore);
+                xSemaphoreGive(screen_semaphore);
             }
             else
             {
@@ -1410,12 +1411,12 @@ static void right_screen_task(void* arg)
             ESP_LOGD(LOG_TAG,"right_screen_task");
 
 
-            printf("refresh %d,max %d\r\n",Machine_info.right_current_Quick_refresh_time,Machine_info.right_max_Quick_refresh_time);
+            // printf("refresh %d,max %d\r\n",Machine_info.right_current_Quick_refresh_time,Machine_info.right_max_Quick_refresh_time);
 
 
             printf("right 拿锁\n");
-            //if(xSemaphoreTake(screen_semaphore, portMAX_DELAY) == true)
-            if(1)
+            if(xSemaphoreTake(screen_semaphore, portMAX_DELAY) == true)
+            // if(1)
             {
                 if(Machine_info.right_current_Quick_refresh_time >=  Machine_info.right_max_Quick_refresh_time)
                 {
@@ -1428,7 +1429,7 @@ static void right_screen_task(void* arg)
                     Paint_rightScreen_main_slow(&info);
                 }
                 printf("right 还锁\n");
-                //xSemaphoreGive(screen_semaphore);
+                xSemaphoreGive(screen_semaphore);
             }
             else
             {
@@ -1595,8 +1596,7 @@ static void button_task(void* arg)
 
                         printf("Machine_info.Duration_time = %ld\r\n",Machine_info.Duration_time);
                         
-                        terminal_send_data();  //添加数据队列
-                       
+                        reset_btn_last_time();
                        #if 0
                                 printf("list before\r\n");
                                 printList(Send_list);
@@ -1793,7 +1793,7 @@ static void button_task(void* arg)
 
                     vTaskDelay(300 / portTICK_PERIOD_MS);
                     reset_default(true,1);
-                    reset_lora();
+                    reset_lora(LORA_CHANENL);
                     vTaskDelay(300 / portTICK_PERIOD_MS);
                 }
             }