#define TESTADC_DISACRD_DELAY_MS 3
#define MINIMUM_VOLTAGE_RANGE 2
#define MAXIMUM_VOLTAGE_RANGE 17
+#define AVG_VOLTAGE_COUNT 7
static int history_percent = 0;
static float sum_vol = 0;
static int vol_num=0;
-static float history_data[5]={0};
+static float history_data[AVG_VOLTAGE_COUNT]={0};
static int left = 0;
static int right = -1;
static uint32_t history_time = 0;
if(get_charge_stat())
{
- if(history_percent > percent && abs(history_percent - percent) < 10)
- // if(history_percent > percent)
+ // if(history_percent > percent && abs(history_percent - percent) < 10)
+ if(history_percent > percent)
{
+
+ // PRINT("1111 charge percent[%d], history_percent[%d] \n",percent,history_percent);
percent = history_percent;
+ // PRINT("adjust percent[%d]\n",percent);
break;
}
//电量均匀增加
- else if(percent > history_percent && history_percent && abs(history_percent - percent) < 10)
- // else if(percent > history_percent && history_percent)
+ // else if(percent > history_percent && history_percent && abs(history_percent - percent) < 10)
+ else if(percent > history_percent && history_percent)
{
+ // PRINT("2222 charge percent[%d], history_percent[%d] \n",percent,history_percent);
history_percent++;
percent = history_percent;
- // PRINT("charge percent[%d], history_percent[%d] \n",percent,history_percent);
+ // PRINT("adjust percent[%d]\n",percent);
break;
}
}
else
{
- if(history_percent < percent && history_percent != 0 && abs(history_percent - percent) < 10)
- // if(history_percent < percent && history_percent != 0)
+ // if(history_percent < percent && history_percent != 0 && abs(history_percent - percent) < 10)
+ if(history_percent < percent && history_percent != 0)
{
+ // PRINT("1111 uncharge percent[%d], history_percent[%d] \n",percent,history_percent);
percent = history_percent;
+ // PRINT("adjust percent[%d]\n",percent);
break;
}
//电量均匀减少
- else if(history_percent > percent && abs(history_percent - percent) < 10)
- // else if(history_percent > percent)
+ // else if(history_percent > percent && abs(history_percent - percent) < 10)
+ else if(history_percent > percent)
{
+ // PRINT("2222 uncharge percent[%d], history_percent[%d] \n",percent,history_percent);
history_percent--;
percent = history_percent;
- // PRINT("uncharge percent[%d], history_percent[%d] \n",percent,history_percent);
+ // PRINT("adjust percent[%d]\n",percent);
break;
}
if(sample_time >= 10)
{
sample_time = 0;
- if(vol_num == 7)
+ if(vol_num == AVG_VOLTAGE_COUNT)
{
sum_vol -= history_data[left];
history_data[left] = 0;
left++;
- left = left % 7;
+ left = left % AVG_VOLTAGE_COUNT;
vol_num--;
}
vol_num++;
right++;
- right = right % 7;
+ right = right % AVG_VOLTAGE_COUNT;
history_data[right] = *vol;
sum_vol += history_data[right];
+ // PRINT("history_data[right] : %.3f\n",history_data[right]);
}
if(vol_num > 0)
{
max_vol = history_data[0];
for (int i = 0;i < vol_num; i++)
{
+ // PRINT("history_data[%d] : %.3f\n",i,history_data[i]);
if (history_data[i] < min_vol)
min_vol = history_data[i];
if (history_data[i] > max_vol)
FILE *fp;
BATTERY_DATA_T data[200];
uint8_t count = 0;
- uint8_t oldest = 0;
+ // uint8_t oldest = 0;
fp = fopen(filename, "r+b");
if(!fp)
fp = fopen(filename, "wb");
{
fread(data, sizeof(BATTERY_DATA_T), count, fp);
- for (int i = 1; i < count; i++)
+ for (int i = 0; i < count - 1; i++)
{
- if (data[i].tm < data[oldest].tm)
- {
- oldest = i;
- }
+ // if (data[i].tm < data[oldest].tm)
+ // {
+ // oldest = i;
+ // }
+ data[i] = data[i + 1];
}
- data[oldest] = newStruct;
+ data[count - 1] = newStruct;
fseek(fp, 0, SEEK_SET);
fwrite(data, sizeof(BATTERY_DATA_T), count, fp);
errcode_t uapi_battery_init(void)
{
battery_check_voltage();
- battery_percent_init(battery_get_percent_onstart()); //先读历史电量
+ battery_percent_init(0); //先读历史电量
app_task_definition_t taskcfg={0};
FILE *fp;
SLEEP_STAT_T data[50];
uint8_t count = 0;
- uint8_t oldest = 0;
+ // uint8_t oldest = 0;
fp = fopen(filename, "r+b");
if(!fp)
fp = fopen(filename, "wb");
{
fread(data, sizeof(SLEEP_STAT_T), count, fp);
- for (int i = 1; i < count; i++)
+ for (int i = 0; i < count - 1; i++)
{
- if (data[i].timestamp < data[oldest].timestamp)
- {
- oldest = i;
- }
+ // if (data[i].tm < data[oldest].tm)
+ // {
+ // oldest = i;
+ // }
+ data[i] = data[i + 1];
}
- data[oldest] = newStruct;
+ data[count - 1] = newStruct;
fseek(fp, 0, SEEK_SET);
fwrite(data, sizeof(SLEEP_STAT_T), count, fp);