充能统计添加中间值滤波
修改晶振起振超时时间和flash相关以适应gd32
This commit is contained in:
@@ -106,10 +106,6 @@ void debug_enable(int enable)
|
||||
|
||||
#else
|
||||
|
||||
void debug_enable(int enable)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@@ -67,7 +67,7 @@ void debug_enable(int enable);
|
||||
|
||||
#define debug_init()
|
||||
#define debug_log(...)
|
||||
|
||||
#define debug_enable(s)
|
||||
|
||||
#endif
|
||||
|
||||
|
61
source/soft/filter.c
Normal file
61
source/soft/filter.c
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
#include "filter.h"
|
||||
|
||||
|
||||
|
||||
// 过滤器
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void filter_init(filter_def *f,uint16_t value){
|
||||
for(int i=0;i<FILTER_ITEM_NUM;i++){
|
||||
f->items[i].data.value = value;
|
||||
f->items[i].data.index = i;
|
||||
}
|
||||
f->index=FILTER_ITEM_NUM;
|
||||
}
|
||||
|
||||
|
||||
// 从指定位置开始排序
|
||||
static void filter_sort(filter_def *f,int index,uint16_t value){
|
||||
int i=index;
|
||||
for(;;){
|
||||
if((i<FILTER_ITEM_NUM-1)&&(value>f->items[i+1].data.value)){
|
||||
f->items[i].item=f->items[i+1].item;
|
||||
i++;
|
||||
// printf("i=%d,to tail\n",i);
|
||||
}else if((i>0)&&(value<f->items[i-1].data.value)){
|
||||
f->items[i].item=f->items[i-1].item;
|
||||
i--;
|
||||
// printf("i=%d,to head\n",i);
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
f->items[i].data.value = value;
|
||||
f->items[i].data.index = f->index;
|
||||
f->index++;
|
||||
}
|
||||
|
||||
|
||||
// 插入数据,小在前,大在后
|
||||
void filter_insert(filter_def *f,uint16_t value)
|
||||
{
|
||||
for(int i=0;i<FILTER_ITEM_NUM;i++){
|
||||
if(f->items[i].data.index==(uint16_t)(f->index-FILTER_ITEM_NUM))
|
||||
{
|
||||
filter_sort(f,i,value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(f->index>0){
|
||||
while(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
55
source/soft/filter.h
Normal file
55
source/soft/filter.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#ifndef filter_h__
|
||||
#define filter_h__
|
||||
|
||||
|
||||
#include "stdint.h"
|
||||
#include "stdio.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
|
||||
|
||||
|
||||
// 过滤器
|
||||
|
||||
#define FILTER_ITEM_NUM 5
|
||||
|
||||
|
||||
typedef union {
|
||||
struct
|
||||
{
|
||||
uint16_t value;
|
||||
uint16_t index;
|
||||
}data;
|
||||
uint32_t item;
|
||||
} filter_item;
|
||||
|
||||
|
||||
struct _filter_def{
|
||||
uint16_t index;
|
||||
filter_item items[FILTER_ITEM_NUM];
|
||||
};
|
||||
typedef struct _filter_def filter_def;
|
||||
|
||||
void filter_init(filter_def *f,uint16_t value);
|
||||
|
||||
void filter_insert(filter_def *f,uint16_t value);
|
||||
|
||||
// 返回中间值
|
||||
#define filter_get_mid(f)\
|
||||
(f)->items[FILTER_ITEM_NUM>>1].data.value
|
||||
|
||||
// 返回头
|
||||
#define filter_get_head(f)\
|
||||
(f)->items[0].data.value
|
||||
|
||||
// 返回尾
|
||||
#define filter_get_tail(f)\
|
||||
(f)->items[FILTER_ITEM_NUM-1].data.value
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user