#include "debug_print.h"
+#include "custom_utils.h"
#define HAL_ADC_SAMPLE_NUMBER_CONFIG_0 10 /* Channel with buffer manual sample average number. */
#define HAL_ADC_SAMPLE_NUMBER_CONFIG_1 10 /* Channel without buffer manual sample average number. */
float battery_percent_map[][2]={
- {4.136,100},
- {4.086,95},
- {4.031,90},
- {3.977,85},
- {3.936,80},
- {3.883,75},
- {3.836,70},
- {3.804,65},
- {3.771,60},
- {3.74,55},
- {3.713,50},
- {3.693,45},
- {3.672,40},
- {3.654,35},
- {3.639,30},
- {3.62,25},
- {3.596,20},
- {3.571,15},
- {3.534,10},
- {3.487,5},
- {3.38,0}
+ {4.3,100},
+ {4.264,95},
+ {4.228,90},
+ {4.192,85},
+ {4.156,80},
+ {4.12,75},
+ {4.084,70},
+ {4.048,65},
+ {4.012,60},
+ {3.976,55},
+ {3.94,50},
+ {3.904,45},
+ {3.868,40},
+ {3.832,35},
+ {3.796,30},
+ {3.76,25},
+ {3.724,20},
+ {3.688,15},
+ {3.652,10},
+ {3.41,5},
+ {3.3,0}
};
-#define batteryservice_VOLTAGE_MAX (4.136f)
-#define batteryservice_VOLTAGE_MIN (3.38f)
+#define batteryservice_VOLTAGE_MAX (4.3f)
+#define batteryservice_VOLTAGE_MIN (3.3f)
static uint32_t g_adc_sample_times = 0;
static uint32_t g_adc_sample_discard = 0;
#define MINIMUM_VOLTAGE_RANGE 2
#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 int left = 0;
+static int right = -1;
+static uint32_t history_time = 0;
+static uint32_t sample_time = 0;
static battery_info_t current_battery_info={0};
*/
static int battery_get_power_percentage(float voltage)
{
+ uint32_t current_time = 0;
int percent = 0;
int map_len = sizeof(battery_percent_map)/sizeof(battery_percent_map[0]);
float temp_value = 0.0f;
temp_value = battery_percent_map[i][1] - (battery_percent_map[i][1] - battery_percent_map[i+1][1] ) * r_div ;
percent = (int)(temp_value + 0.5);
-
+
+ if(get_charge_stat())
+ {
+ if(history_percent > percent)
+ {
+ percent = history_percent;
+ break;
+ }
+ }
+ else
+ {
+ if(history_percent < percent && history_percent != 0)
+ {
+ percent = history_percent;
+ break;
+ }
+
+ }
+
+ history_percent = percent;
// printf("batterymap[%d]=%f,batterymap[%d]=%f, r_div = %f , temp_value = %f ,percent = %d\n",
// i,battery_percent_map[i][0],i+1,battery_percent_map[i+1][0],
// r_div,temp_value,percent
// );
break;
}
- }
+ }
+
+ uapi_get_timestampe_ss(¤t_time);
+ if(history_time == 0)
+ history_time = current_time;
+ sample_time = current_time - history_time;
+ history_time = current_time;
+
+ if(sample_time >= 10)
+ {
+ sample_time = 0;
+ if(percent_num == 5)
+ {
+ sum_percent -= history_data[left];
+ history_data[left] = 0;
+ left++;
+ left = left % 5;
+ percent_num--;
+ }
+
+ percent_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;