优化电池充电 384/1
authorpenglei <1624952103@qq.com>
Wed, 26 Jun 2024 11:38:14 +0000 (19:38 +0800)
committerpenglei <1624952103@qq.com>
Wed, 26 Jun 2024 11:38:14 +0000 (19:38 +0800)
code/sdk/application/battery/service/battery_driver.cpp
code/sdk/drivers/peripheral/cywee/src/main_dml.c

index 3f458c5..cd83fd7 100644 (file)
@@ -264,9 +264,11 @@ static uint32_t g_adc_sample_stick = 0;
 #define MAXIMUM_VOLTAGE_RANGE         17
 
 static int history_percent = 0;
-static int sum_percent = 0;
-static int percent_num=0;
-static int history_data[5]={0};
+
+static float sum_vol = 0;
+static int vol_num=0;
+
+static float history_data[5]={0};
 static int left = 0;
 static int right = -1;
 static uint32_t history_time = 0;
@@ -436,6 +438,18 @@ static int battery_get_power_percentage(float voltage)
     
     }
 
+    if (voltage <= batteryservice_VOLTAGE_MIN)
+        percent = 0;
+
+    if (voltage >= batteryservice_VOLTAGE_MAX)
+        percent = 100;
+
+    return percent;
+}
+
+static void get_avg_voltage(float *vol)
+{
+    uint32_t current_time = 0;
     uapi_get_timestampe_ss(&current_time);
     if(history_time == 0)
         history_time = current_time;
@@ -445,33 +459,27 @@ static int battery_get_power_percentage(float voltage)
     if(sample_time >= 10)
     {
         sample_time = 0;
-        if(percent_num == 5)
+        if(vol_num == 5)
         {
-            sum_percent -= history_data[left];
+            sum_vol -= history_data[left];
             history_data[left] = 0;
             left++;
             left = left % 5;
-            percent_num--;
+            vol_num--;
         }
 
-        percent_num++;
+        vol_num++;
         right++;
         right = right % 5;
-        history_data[right] = percent;
-        sum_percent += history_data[right];
-    }
-
-    percent = sum_percent / percent_num;
-
-    if (voltage <= batteryservice_VOLTAGE_MIN)
-        percent = 0;
+        history_data[right] = *vol;
+        sum_vol += history_data[right];
+    }    
+    if(vol_num != 0)
+        *vol = sum_vol / vol_num;
 
-    if (voltage >= batteryservice_VOLTAGE_MAX)
-        percent = 100;
-
-    return percent;
 }
 
+
 static bool adc_get_sample_result(float *voltage, uint8_t channel)
 {
     uint32_t sample_number = 0;
@@ -525,6 +533,7 @@ static bool adc_get_sample_result(float *voltage, uint8_t channel)
     if(channel == 2)
     {
         *voltage = adc_trans_systick_to_battery_voltage(stick);
+        get_avg_voltage(voltage);
     }
     else if (channel == 0){
         *voltage = adc_trans_systick_to_battery_ntc(stick);
index d498411..6af8472 100644 (file)
@@ -1081,7 +1081,7 @@ int cywee_main_dml(void)
 
     cywee_activity_mode_change(SPORT_ACTIVE_MODE_NORMAL);
     
-    cywee_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY);
+    cywee_inactivity_mode_change(INACTIVITY_MODE_SEDENTARY_AND_NAP);
 
     //cywee_inactivity_mode_change(INACTIVITY_MODE_SLEEPING);