RP-01/cva_asw_m0146/src/FanHeat.c
2025-04-11 10:46:09 +08:00

117 lines
2.7 KiB
C

/*******************************************************************************
* the includes
******************************************************************************/
#include "FanHeat.h"
#include "key.h"
#include "hwctrl.h"
#include "scm_canmatrix-binutil.h"
/*******************************************************************************
* the defines
******************************************************************************/
/*******************************************************************************
* the typedefs
******************************************************************************/
/*******************************************************************************
* the globals
******************************************************************************/
static uint8_t HeatState,FanState;
static uint16_t HeatDutyCounter;
/*******************************************************************************
* the const
******************************************************************************/
const uint8_t HeatDutyTab[4] = {0,10,20,80};
const uint8_t FanDutyTab[4] = {0,10,30,85};
/*******************************************************************************
* the functions
******************************************************************************/
static void HeatTask(void);
static void SetFanHeatMsg(void);
static void FanTask(void);
void FanHeatInit(void)
{
HeatState = 0;
FanState = 0;
HeatDutyCounter = 0;
}
void FanHeatMainTask(void)//10ms
{
if (getKeyPressFlag(KEY_HEAT) == KEY_PRESSED)
{
HeatState++;
if (HeatState > 3)
{
HeatState = 0;
}
FanState = 0;
}
if (getKeyPressFlag(KEY_FAN) == KEY_PRESSED)
{
FanState++;
if (FanState > 3)
{
FanState = 0;
}
HeatState = 0;
}
FanTask();
HeatTask();
SetFanHeatMsg();
}
static void HeatTask(void)
{
if (HeatState!=0)
{
if (HeatDutyCounter > HeatDutyTab[HeatState])
{
HeatDrv1Ctrl(0);
}
else
{
HeatDrv1Ctrl(1);
}
HeatDutyCounter++;
if (HeatDutyCounter >= 100)
{
HeatDutyCounter = 0;
}
}
else
{
HeatDutyCounter = 0;
HeatDrv1Ctrl(0);
}
}
static void FanTask(void)
{
static uint8_t LastFanState=0;
if (LastFanState != FanState)
{
LastFanState = FanState;
FanCtrlDuty(FanDutyTab[FanState]);
}
}
static void SetFanHeatMsg(void)
{
scm_canmatrix_tx.SCM_STATE.ZY_FAN_STATE = FanState;
scm_canmatrix_tx.SCM_STATE.ZY_HEAT_STATE = HeatState;
}