Data_Voltmeter.c 5.23 KB
Newer Older
hu's avatar
hu committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
#include "Data_Voltmeter.h"
#include "RTE_ADC.h"
#include "GaugesInterface.h"
//-------------------------------------------
//电压计数据处理 wangboyu
//-------------------------------------------
//区域5显示逻辑
//-------------------------------------------
//344 - 3.4.2.2电压计显示画面 
//-------------------------------------------
static struct
{
	uint8_t SumCnt ;
	uint32_t ActVoltage ;
	uint8_t Timer ;
	uint8_t Gui_Voltmeter ;
	uint8_t Valid ;
	uint16_t AvrVoltage ;
}VoltmeterVariable ;

static void Data_Voltmeter_2_Gui(void);
static uint16_t Get_VoltFilter(void);
static 
/*-------------------------------------------------------------------------
 * Function Name  : Voltmeter_KL30_Init
 * Description    : 
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
void Voltmeter_KL30_Init(void)
{
	VoltmeterVariable.SumCnt = 0 ;
	VoltmeterVariable.ActVoltage = 0 ;
	VoltmeterVariable.AvrVoltage = 0 ;
	VoltmeterVariable.Timer = 0 ;
	VoltmeterVariable.Gui_Voltmeter = 0 ;
	VoltmeterVariable.Valid = 0 ;	
}
void Voltmeter_KL15_ON_Init(void)
{

}
void Voltmeter_KL15_OFF_Init(void)
{

}
void Voltmeter_Wakeup_Init(void)
{

}
void Voltmeter_Sleep_Init(void)
{

}
/*-------------------------------------------------------------------------
 * Function Name  : Voltmeter_Processing_Service
 * Description    : 
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
void Voltmeter_Processing_Service(void)
{
	Data_Voltmeter_2_Gui();	
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_VoltFilter
 * Description    : 电压滤波
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
static uint16_t Get_VoltFilter(void)
{
	uint8_t Valid = 0 ;
	uint16_t Voltage = 0 ;
	Valid = RTE_Read_KL30_Valid() ;
	if(Valid)
	{
		Voltage = (uint16_t)RTE_Read_KL30_Voltage();
		if (VoltmeterVariable.SumCnt < 10u)
		{
			VoltmeterVariable.ActVoltage += Voltage;
			VoltmeterVariable.SumCnt += 1u;
			Voltage = (uint16_t)(VoltmeterVariable.ActVoltage / VoltmeterVariable.SumCnt);
		}
		else
		{
			VoltmeterVariable.SumCnt = 0u;
			VoltmeterVariable.ActVoltage = 0u;
			VoltmeterVariable.ActVoltage += Voltage;
			VoltmeterVariable.SumCnt += 1u;
			Voltage = (uint16_t) (VoltmeterVariable.ActVoltage / VoltmeterVariable.SumCnt);
		}
	}
	
	return Voltage ;
}
/*-------------------------------------------------------------------------
 * Function Name  : Data_Voltmeter_2_Gui
 * Description    : 电压计逻辑处理
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
static void Data_Voltmeter_2_Gui(void)
{
	static uint8_t u8GuiMode = 0 ;
	
	VoltmeterVariable.AvrVoltage = Get_VoltFilter();
	
	if((VoltmeterVariable.AvrVoltage >= 17000)&&(VoltmeterVariable.AvrVoltage <= 30500))
	{
		VoltmeterVariable.Valid = 1 ;
		VoltmeterVariable.Timer = 0 ;
				
		
	}
	else
	{//检测出范围以外数据时的处理
		if(VoltmeterVariable.Timer < (2000 / 20))
		{//未到2sec前保持原图像
			VoltmeterVariable.Timer ++ ;
		}
		else
		{
			VoltmeterVariable.Valid = 0 ;
		}
	}

	if(VoltmeterVariable.Valid)
	{
		SetGaugesPara(VoltGauges, VoltmeterVariable.AvrVoltage);		
		u8GuiMode = GetGaugesCurrentPos(VoltGauges);
	}
	else
	{

	}
	
	VoltmeterVariable.Gui_Voltmeter = u8GuiMode ;	
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_Voltmeter_AvrVoltage
 * Description    : 平均电压
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 刷图时使用
 --------------------------------------------------------------------------*/
uint16_t Get_Voltmeter_AvrVoltage(void)
{
	uint16_t u16Result = 0 ;
	u16Result = VoltmeterVariable.AvrVoltage ;
	return u16Result ;
}
/*-------------------------------------------------------------------------
 * Function Name  : Gui_Get_Voltmeter_DisplayMode
 * Description    : 电压计线段数
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 刷图时使用
 --------------------------------------------------------------------------*/
uint8_t Gui_Get_Voltmeter_DisplayMode(void)
{
	uint8_t u8Result = 0 ;
	u8Result = VoltmeterVariable.Gui_Voltmeter ;
	return u8Result ;
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_Voltmeter_Valid
 * Description    : 有效?
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 刷图时使用
 --------------------------------------------------------------------------*/
uint8_t Get_Voltmeter_Valid(void)
{
	uint8_t u8Result = 0 ;
	u8Result = VoltmeterVariable.Valid ;
	return u8Result ;
}