From 7d13fbde75b58ff4c9deaef95ca0c03a1083f8e8 Mon Sep 17 00:00:00 2001
From: WXK <287788329@qq.com>
Date: 星期五, 29 八月 2025 10:26:55 +0800
Subject: [PATCH] 1.9,加入电量新计算方法 测试电池能干多久问题   目前1s检测一下adc

---
 keil/include/main/main.c |   49 +++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/keil/include/main/main.c b/keil/include/main/main.c
index b813625..62f6340 100644
--- a/keil/include/main/main.c
+++ b/keil/include/main/main.c
@@ -184,7 +184,7 @@
 //        ADC_INTERNAL_VREF_MV + adc_code_to_mv((int16_t)*result, ADC_INTERNAL_VREF_MV));
         fVoltage_mv=ADC_INTERNAL_VREF_MV + adc_code_to_mv((int16_t)*result, ADC_INTERNAL_VREF_MV);
         fVoltage_mv=fVoltage_mv*2+1100;
-        if(fVoltage_mv < 2800)
+        if(fVoltage_mv < 2000)
         {
             bat_percent = 0;
         }
@@ -194,9 +194,10 @@
         }
         else
         {
-            bat_percent = ((fVoltage_mv - 2800) /3);
+            bat_percent = ((fVoltage_mv - 2000) /11);
         }
     }
+//    LOG_INFO(TRACE_MODULE_APP, "当前静止:%d 电量:%d\r\n",nomove_count,fVoltage_mv);
 //				if(fVoltage_mv<3300)
 //				{
 //					power_low_flag=1;
@@ -219,7 +220,9 @@
 void IMUTask(void)
 {
 	if(nomove_count>g_com_map[NOMOVESLEEP_TIME]&&g_com_map[IMU_ENABLE]==1)
-	{power_wakeup_enable((enum POWER_WAKEUP_SOURCE_T)ACCLERATE_DETECT_Pin, POWER_WAKEUP_LEVEL_HIGH);
+	{
+        LOG_INFO(TRACE_MODULE_APP, "进入休眠\r\n");
+        power_wakeup_enable((enum POWER_WAKEUP_SOURCE_T)ACCLERATE_DETECT_Pin, POWER_WAKEUP_LEVEL_HIGH);
 		mcu_deep_sleep();
 	}
 }
@@ -371,7 +374,9 @@
 static void move_handler(enum IO_PIN_T pin)
 {
     nomove_count=0;
-    Motion_Detection_callback();
+//    LOG_INFO(TRACE_MODULE_APP, "加速度唤醒了\r\n");
+//    LOG_INFO(TRACE_MODULE_APP, "当前静止:%d 电量:%d\r\n",nomove_count,fVoltage_mv);
+//    Motion_Detection_callback();
 }
 static void pca_handler(enum IO_PIN_T pin)
 {
@@ -426,7 +431,7 @@
     ip2 = (g_com_map[TCP_IP_2]>>12&0xf)*1000+(g_com_map[TCP_IP_2]>>8&0xf)*100+(g_com_map[TCP_IP_2]>>4&0xf)*10+(g_com_map[TCP_IP_2]&0xf);
     ip3 = (g_com_map[TCP_IP_3]>>12&0xf)*1000+(g_com_map[TCP_IP_3]>>8&0xf)*100+(g_com_map[TCP_IP_3]>>4&0xf)*10+(g_com_map[TCP_IP_3]&0xf);
     port = g_com_map[TCP_PORT];
-    g_com_map[VERSION] = (1<<8)|8;
+    g_com_map[VERSION] = (1<<8)|9;
     LOG_INFO(TRACE_MODULE_APP,"设备ID: %x .\r\n",dev_id);
     LOG_INFO(TRACE_MODULE_APP,"固件版本:4G-GPS定位手环 V%d.%d. \r\n",g_com_map[VERSION]>>8,g_com_map[VERSION]&0xff);
     LOG_INFO(TRACE_MODULE_APP,"服务器地址: %d.%d.%d.%d:%d.\r\n",ip0,ip1,ip2,ip3,port);
@@ -623,6 +628,9 @@
 
 }
 extern uint8_t shengji_flag;
+extern uint16_t adc_caiji;
+uint8_t send_frame1[10];
+extern uint8_t adc_one;
 int main(void)
 {
     board_clock_run();
@@ -652,7 +660,7 @@
     LOG_INFO(TRACE_MODULE_APP, "UWB simple example\r\n");
     
     struct PWM_CFG_T usr_pwm_cfg = {
-        .general_prescale = 15,
+        .general_prescale = 7,
         .int_en = 1,
         .callback = pwm_callback,
     };
@@ -664,7 +672,7 @@
 		
     IIC2_Init();
     SC7A22H_Motion_Detection_Init();
-    gpio_pin_clr(ADC_GND_ENABLE);
+//    gpio_pin_clr(ADC_GND_ENABLE);
     Program_Init();
     uart_receive(UART_ID0,m_EUART_DMA_RXBuf,EUART_RX_BUF_SIZE,uart_receive_callback);
     power_init();
@@ -690,8 +698,33 @@
         }
         if(g_start_send_flag)
         {
+            
+//                adc_caiji++;
+//    if(adc_caiji>5&&adc_one==0)
+//    {
+//    adc_one=1;  
+//    adc_caiji=0;  
+//    MinuteTask();
+//    }
+//    else if(adc_one==1&&adc_caiji>3600)
+//    {
+//    adc_caiji=0;  
+//    MinuteTask(); 
+//    }
+    
+//    send_frame1[0] = 0x55;
+//    send_frame1[1] = 0xAA;
+//    send_frame1[2] = nomove_count;
+//    memcpy(&send_frame1[3],&fVoltage_mv,2);        
+////    send_frame1[3] = data_length+5;
+////    send_frame1[4] = CMD_REPLY;
+////    send_frame1[5] = index;
+////    send_frame1[6] = data_length;
+//    uart_send(UART_ID0, send_frame1,5, NULL);
+    
             g_start_send_flag = 0;
             gpio_pin_set(IO_PIN_7);//亮
+//            LOG_INFO(TRACE_MODULE_APP, "当前静止:%d 电量:%d\r\n",nomove_count,fVoltage_mv);
 		    SwitchTagState();	
             gpio_pin_clr(IO_PIN_7);//灭
         }
@@ -702,7 +735,7 @@
         LoraUp_Poll();
 #ifndef DEBUG_MODE
         
-			if(sleep_flag&&state5v==0){//开始一段时间无休眠
+			if(sleep_flag&&state5v==0&&motor_keeptime==0){//开始一段时间无休眠
 						trace_flush();
             uint32_t lock = int_lock();
 						//LOG_INFO(TRACE_MODULE_APP, "进入低功耗");

--
Gitblit v1.9.3