Data_Voltmeter.c 5.63 KB
Newer Older
hu's avatar
hu committed
1 2 3 4
#include "Data_Voltmeter.h"
#include "RTE_ADC.h"
#include "GaugesInterface.h"
//-------------------------------------------
hu's avatar
hu committed
5
//电压计数据处理
hu's avatar
hu committed
6 7 8
//-------------------------------------------
//区域5显示逻辑
//-------------------------------------------
hu's avatar
hu committed
9
//344 - 3.4.2.2电压计显示画面
hu's avatar
hu committed
10 11 12
//-------------------------------------------
static struct
{
hu's avatar
hu committed
13 14 15 16 17 18 19
    uint8_t SumCnt ;
    uint32_t ActVoltage ;
    uint8_t Timer ;
    uint8_t Gui_Voltmeter ;
    uint8_t Valid ;
    uint16_t AvrVoltage ;
} VoltmeterVariable ;
hu's avatar
hu committed
20 21 22

static void Data_Voltmeter_2_Gui(void);
static uint16_t Get_VoltFilter(void);
hu's avatar
hu committed
23
static
hu's avatar
hu committed
24 25
/*-------------------------------------------------------------------------
 * Function Name  : Voltmeter_KL30_Init
hu's avatar
hu committed
26
 * Description    :
hu's avatar
hu committed
27 28 29 30 31 32 33
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
void Voltmeter_KL30_Init(void)
{
hu's avatar
hu committed
34 35 36 37 38 39
    VoltmeterVariable.SumCnt = 0 ;
    VoltmeterVariable.ActVoltage = 0 ;
    VoltmeterVariable.AvrVoltage = 0 ;
    VoltmeterVariable.Timer = 0 ;
    VoltmeterVariable.Gui_Voltmeter = 0 ;
    VoltmeterVariable.Valid = 0 ;
hu's avatar
hu committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
}
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
hu's avatar
hu committed
59
 * Description    :
hu's avatar
hu committed
60 61 62 63 64 65 66
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
void Voltmeter_Processing_Service(void)
{
hu's avatar
hu committed
67
    Data_Voltmeter_2_Gui();
hu's avatar
hu committed
68 69 70 71 72 73 74 75 76 77 78
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_VoltFilter
 * Description    : 电压滤波
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
static uint16_t Get_VoltFilter(void)
{
hu's avatar
hu committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    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 ;
hu's avatar
hu committed
102 103 104 105 106 107 108 109 110 111 112
}
/*-------------------------------------------------------------------------
 * Function Name  : Data_Voltmeter_2_Gui
 * Description    : 电压计逻辑处理
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : None
 --------------------------------------------------------------------------*/
static void Data_Voltmeter_2_Gui(void)
{
hu's avatar
hu committed
113 114 115
    static uint8_t u8GuiMode = 0 ;

    VoltmeterVariable.AvrVoltage = Get_VoltFilter();
hu's avatar
hu committed
116
    VoltmeterVariable.AvrVoltage += 800u;/*增加二极管压降补偿*/
hu's avatar
hu committed
117

118 119

    if ((VoltmeterVariable.AvrVoltage >= 17000u) && (VoltmeterVariable.AvrVoltage <= 30500u))
hu's avatar
hu committed
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
    {
        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 ;
hu's avatar
hu committed
149 150 151 152 153 154 155 156 157 158 159
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_Voltmeter_AvrVoltage
 * Description    : 平均电压
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 刷图时使用
 --------------------------------------------------------------------------*/
uint16_t Get_Voltmeter_AvrVoltage(void)
{
hu's avatar
hu committed
160 161 162
    uint16_t u16Result = 0 ;
    u16Result = VoltmeterVariable.AvrVoltage ;
    return u16Result ;
hu's avatar
hu committed
163 164 165 166 167 168 169 170 171 172 173
}
/*-------------------------------------------------------------------------
 * Function Name  : Gui_Get_Voltmeter_DisplayMode
 * Description    : 电压计线段数
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 刷图时使用
 --------------------------------------------------------------------------*/
uint8_t Gui_Get_Voltmeter_DisplayMode(void)
{
hu's avatar
hu committed
174 175 176
    uint8_t u8Result = 0 ;
    u8Result = VoltmeterVariable.Gui_Voltmeter ;
    return u8Result ;
hu's avatar
hu committed
177 178 179 180 181 182 183 184 185 186 187
}
/*-------------------------------------------------------------------------
 * Function Name  : Get_Voltmeter_Valid
 * Description    : 有效?
 * Input          : None
 * Output         : None
 * Return         : None
 * onther         : 刷图时使用
 --------------------------------------------------------------------------*/
uint8_t Get_Voltmeter_Valid(void)
{
hu's avatar
hu committed
188 189 190
    uint8_t u8Result = 0 ;
    u8Result = VoltmeterVariable.Valid ;
    return u8Result ;
hu's avatar
hu committed
191 192 193 194 195 196
}