Data_Voltmeter.c 5.63 KB
Newer Older
hu's avatar
hu committed
1 2 3
#include "Data_Voltmeter.h"
#include "RTE_ADC.h"
#include "GaugesInterface.h"
4

hu's avatar
hu committed
5
//-------------------------------------------
hu's avatar
hu committed
6
//电压计数据处理
hu's avatar
hu committed
7 8 9
//-------------------------------------------
//区域5显示逻辑
//-------------------------------------------
hu's avatar
hu committed
10
//344 - 3.4.2.2电压计显示画面
hu's avatar
hu committed
11 12 13
//-------------------------------------------
static struct
{
hu's avatar
hu committed
14 15 16 17 18 19 20
    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
21 22 23

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

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

119 120

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