v2.5 power save mode
authorkyz <kongyuzhong@google.com>
Mon, 30 Jun 2025 08:28:26 +0000 (16:28 +0800)
committerkyz <kongyuzhong@google.com>
Mon, 30 Jun 2025 09:53:45 +0000 (17:53 +0800)
1. cpu进入stopmode  30秒定时唤醒
2. 读取角度变化超过2度,上报数据
3. 无变化2小时上报数据

USER/SRC/main.c

index cba83f1393efe1e6bd8f3d50ee14b911f74ce7e9..f4d5ba961ec60971e19c1e33c55d79824e6ebf3b 100644 (file)
 */
 
 #define  REPORT_TIME_SECS     (2*60*60) //2hours
-#define  ANGLE_CHANGE_MIN      (100)       //0.100 ¡æ
+#define  ANGLE_CHANGE_MIN     (2000)       //2.000 ¡æ
+
+static uint32_t last_sent_rtc_secs; //ÉÏ´ÎÉϱ¨rtcʱ¼ä£¬µ¥Î»Ã룬 ÓÃÓÚ¼ÆË㶨ʱÉϱ¨Ê±¼ä, ½Ç¶È²»±ä»¯2Сʱ·¢ËÍÒ»´Î
 
-static uint32_t  to_send_time_secs; //ÐÞ¸ÄΪ2Сʱ·¢ËÍÒ»´Î£¬ 2025/4/23
 static int last_x_angle;
 static int last_y_angle;
 static int last_z_angle;
@@ -45,8 +46,8 @@ int is_angle_changed( int x_angle, int y_angle, int z_angle )
        return 1;
 }
 
-#define STOP_MODE (0)                                                          //ֹͣģʽ
-#define SOFTWARE_VERSION  "app_version = 2.4"
+#define STOP_MODE (1)                                                          //ֹͣģʽ
+#define SOFTWARE_VERSION  "app_version = 2.5"
 
 u8 uid[32];
 
@@ -119,15 +120,19 @@ char data_format[] = "{\n\
 //²âÊÔ-µÚ¶þ¸ö°å×Ó
 void func_test(void)
 {
+       int send_err = 0;
+       uint32_t now_rtc_secs;
+       
        uint32_t to_report = 0;
-       to_send_time_secs = REPORT_TIME_SECS; //µÚÒ»´ÎÁ¢¼´Éϱ¨£¬ºóÃæµÈ´ýÉϱ¨×î´óÖÜÆÚ
+
+       now_rtc_secs = 0;
+       last_sent_rtc_secs = now_rtc_secs;
 
        while(1)
        {
                Request_Temp_And_Humidity();                            //Ö÷¶¯»ñȡһ´ÎÎÂʪ¶È´«¸ÐÆ÷µÄÊý¾Ý
                Cmd_11();                                                                               //Ö÷¶¯»ñȡһ´Î½Ç¶ÈÊý¾Ý
                Delay_s(1);
-               to_send_time_secs++;
                Process_Temp_And_Hum_Data();                                    //´¦ÀíÎÂʪ¶ÈÊý¾Ý
                Process_IM600_Data();                                   //´¦Àí½Ç¶È´«¸ÐÆ÷Êý¾Ý
 
@@ -136,33 +141,43 @@ void func_test(void)
                }else{
                        im600_receive_ok = 0;                           //¼Ó²»¼Óelse¶¼ÐÐ
                }
-               
-               if( to_send_time_secs >= REPORT_TIME_SECS ){
+
+               now_rtc_secs = RTC_GetCounter();
+               if( now_rtc_secs - last_sent_rtc_secs > REPORT_TIME_SECS ){ 
+                       //¹Ì¶¨2¸öСʱÉϱ¨Ò»´Î
                        to_report = 1;
                }else if( is_angle_changed(x_angle, y_angle, z_angle) ){
+                       //½Ç¶È±ä»¯´óÓÚ2¶È ÐèÒªÉϱ¨
                        to_report = 1;
                }else{
                        to_report = 0;
                }
                if( to_report ){
-                       last_x_angle = x_angle;
-                       last_y_angle = y_angle;
-                       last_z_angle = z_angle;
 
                        WH_GM5_Config();                                                                //ÅäÖÃ4GÄ£¿é
                        sprintf((char*)net.TxBuff,data_format1,uid,temp_value,hum_value,x_angle/(fp32)1000,(fp32)(y_angle/(fp32)1000),
                                   (fp32)(z_angle/(fp32)1000),(fp32)(raw_x/(fp32)10000),direction,Get_Battery_Power(),Bat_AdcGetValue(),Get_Sun_Adc_value());
                        encrypt();                                                                      //rc4¼ÓÃÜ
-                       if( WH_GM5_Send_Data() )                             //4GÄ£¿é·¢ËÍÊý¾Ý
-                               to_send_time_secs = 0;
+                       if( WH_GM5_Send_Data() ){                             //4GÄ£¿é·¢ËÍÊý¾Ý
+                               last_sent_rtc_secs = now_rtc_secs;
+                               last_x_angle = x_angle;
+                               last_y_angle = y_angle;
+                               last_z_angle = z_angle;
+                               send_success = 1;
+                               send_err = 0;
+                       }else{
+                               send_success =0;
+                               send_err ++;
+                               Delay_s(4);
+                       }
                }
 
-               Delay_s(1);
-               to_send_time_secs++;
+//             Delay_s(1);
                MCU_LED_TOGGLES;
                
 #if STOP_MODE
-               if(send_success == 1){
+               if(send_success == 1 || send_err > 5 || to_report==0 ){
+
                        ADC_Cmd(ADC1, DISABLE);
                        MCU_LED_OFF;                                                                                                    //¹Ø±ÕLEDµÆ
                        CTL_4G_PWR_OFF;
@@ -175,7 +190,7 @@ void func_test(void)
                        //RTC_WaitForLastTask();                                                                                //µÈ´ýÉÏÒ»´Î²Ù×÷Íê³É
                        RTC_EnterConfigMode();          
                        RTC_WaitForLastTask();                                  
-                       RTC_SetAlarm((10 )+RTC_GetCounter());                                                   //ÅäÖÃÏ´ÎÄÖÖÓΪ10sºó
+                       RTC_SetAlarm((30)+RTC_GetCounter());                                                    //ÅäÖÃÏ´ÎÄÖÖÓΪ60sºó
                        RTC_WaitForLastTask();
                        RTC_ExitConfigMode();                   
                        PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);    //½øÈëֹͣģʽµÍ¹¦ºÄ
@@ -183,6 +198,8 @@ void func_test(void)
                        SysTickEnableOrDisable(ENABLE);                                                                 //´ò¿ªsystick
                        
                        send_success = 0;
+                       send_err = 0;
+                       ConnectFlag = 0;
                        CTL_4G_PWR_ON;
                }
 #endif