
#include "Filter.h"
#include "Include.h"


#define Resistance_MAX 10000	//���������Ч��ֵ//0.1ŷ����
#define Resistance_Threshold 60 //0.1ŷ����
#define FilterCount_MAX 8		//���ö��ٴ�֮��ʼ�仯

unsigned int FuelResist = 0;	 //���˺����ֵ   
unsigned char FuelResistanceDir = 0; //��ֵ�仯����

unsigned char FuelFilterCount = 0; //���˼�������

//����0.1ŷΪ��λ�ĵ���
//���0.1ŷΪ��λ�ĵ���//���0xFFFF�Ǳ�ʾ��Ч
//10ms����һ��
unsigned int Resistance_Filter_Update(unsigned int Resistance_IN)
{
	/*if (Resistance_IN > Resistance_MAX)
	{
		FuelResist = 0xFFFF;
		FuelFilterCount = 0;
		FuelResistanceDir = 0;
	}
	else
	{
		if ((Resistance_IN > (FuelResist + Resistance_Threshold)) || (FuelResist > (Resistance_IN + Resistance_Threshold)))
		{
			FuelResist = Resistance_IN;
			FuelFilterCount = 0;
		}
		else
		{
			if (Resistance_IN > FuelResist)
			{
				if (1 != FuelResistanceDir)
				{
					FuelResistanceDir = 1;
					FuelFilterCount = 0;
				}
				else
				{
					FuelFilterCount++;
					if (FuelFilterCount > FilterCount_MAX)
					{
						FuelFilterCount = 0;
						FuelResist++;
					}
				}
			}
			else if (FuelResist > Resistance_IN)
			{
				if (2 != FuelResistanceDir)
				{
					FuelResistanceDir = 2;
					FuelFilterCount = 0;
				}
				else
				{
					FuelFilterCount++;
					if (FuelFilterCount > FilterCount_MAX)
					{
						FuelFilterCount = 0;
						FuelResist--;
					}
				}
			}
		}
	}*/
	return FuelResist;
}

/////////��ʱ������////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//���������ģ�������µ���Ӧ������
void Analog_Update(void)
{     
	if(ADC_Read_Signal_Valid(0))
	{
		AnalogKL30Voltage = ADC_Read_Signal(0);
	}
	else
	{
		AnalogKL30Voltage = 0xFFFF;
	}
       //��˯��״̬ʱ��ȡ
        if(_IGN_Sleep!=g_PowerIGN)
        {
                if(ADC_Read_Signal_Valid(1))
                {
                        AnalogKL15Voltage = ADC_Read_Signal(1);
                }
                else
                {
                        AnalogKL15Voltage = 0xFFFF;
                }
        }
        
          //��ѹǰ��
	if(ADC_Read_Signal_Valid(ADC_CH_AIR_PRESSURE_1))
	{
	         AirPress_Front.u8_Analog_Valid  = 1;
		AirPress_Front.u16Analog_Volt = ADC_Read_Signal(ADC_CH_AIR_PRESSURE_1);
	}
	else
	{
		AirPress_Front.u8_Analog_Valid  = 0;
		AirPress_Front.u16Analog_Volt = 0xFFFF;
	}
	//��ѹ����
	if(ADC_Read_Signal_Valid(ADC_CH_AIR_PRESSURE_2))
	{
		AirPress_Rear.u8_Analog_Valid = 1;
		AirPress_Rear.u16Analog_Volt  = ADC_Read_Signal(ADC_CH_AIR_PRESSURE_2);
	}
	else
	{
		AirPress_Rear.u8_Analog_Valid = 0;
		AirPress_Rear.u16Analog_Volt  = 0xFFFF;
	}
           //4����
           //ȼ��
/*	if(ADC_Read_Signal_Valid(ADC_CH_FUEL1_R))
	{
		AnalogFuelSensorRes = ADC_Read_Signal(ADC_CH_FUEL1_R);
	}
	else
	{
		AnalogFuelSensorRes = 0xFFFF;
	}
	*/
          //���ذ���
/*	if(ADC_Read_Signal_Valid(5))
	{
		 Analog_Keys = ADC_Read_Signal(5);
	}
	else
	{
		 Analog_Keys = 0xFFFF;
	}  */
           
}







