/*==============================================================*/
/*DESCRIPTION: Refer 5 of state machine pdf
*/
/*=============================================================*/
#include <LiquidCrystal.h>
#define PSAQ_ENGHD_VTA_Enable_FCT_BUTTON_PIN 6
#define PSAQ_ENGHD_STARTSTOP_ENABLE_FCT_BUTTON_PIN 7
#define VTA_ENGHD_STAT_BUTTON_PIN 8
#define STARTATOP_ENGHD_STAT_BUTTON_PIN 9
// initialize the library with the numbers of the interface pins
//LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
LiquidCrystal lcd(12,11,5,4,3,2);
typedef enum
{
E_HOOD_DISABLE,
E_HOOD_ENABLE,
} Hood_Super_State_E;
typedef enum
{
E_HOOD_CLOSE,
E_HOOD_OPEN,
} Hood_Sub_StateA_E;
/*variables used in ISR*/
/*===========================================================*/
volatile unsigned char Tick10msCounter = 0u;
volatile unsigned char Tick40msCounter = 0u;
volatile unsigned char Tick100msCounter = 0u;
/* Variables */
/*==========================================================================*/
static Hood_Super_State_E Hood_Config_state_re;
static Hood_Sub_StateA_E Hood_Control_state_re;
static bool PSAQ_EngHd_VTA_Enable_Fct;
static bool PSAQ_EngHd_StartStop_Enable_Fct;
static bool VTA_EngHd_Stat;
static bool StartStop_EngHd_Stat;
static unsigned char EngHd_Stat_BC_F=0u;
/* Private functions prototypes */
/*==========================================================================*/
static void Read_PSAQ_EngHd_VTA_Enable_Fct_Status();//BUTTON_PIN1
static void Read_PSAQ_EngHd_StartStop_Enable_Fct_Status();////BUTTON_PIN2
static void Read_VTA_EngHd_Stat_Status();//BUTTON_PIN3
static void Read_StartStop_EngHd_Stat_Status();//BUTTON_PIN4
static void Lcd_Display();
static void Task_10ms(void);
static void Task_40ms(void);
static void Task_100ms(void);
static void Hood_Config_Init(void);
static void HoodDisable_State_en(void);
static void HoodEnable_State_en(void);
static void HoodClose_State_en(void);
static void Hood_Config_du(void);
static void HoodEnable_du(void);
static void HoodClose_State_en(void);
static void HoodOpen_State_en(void);
/******************************************************************
* Name : setup
* Description : code to run once
Calling init functions
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
void setup()
{
Init();
//Serial.begin(115200);
Lcd_Init();
Interrupt_Init();
Hood_Config_Init();
}
/******************************************************************
* Name : Init
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void Init(void)
{
pinMode(PSAQ_ENGHD_VTA_Enable_FCT_BUTTON_PIN, INPUT);
pinMode(PSAQ_ENGHD_STARTSTOP_ENABLE_FCT_BUTTON_PIN, INPUT);
pinMode(VTA_ENGHD_STAT_BUTTON_PIN, INPUT);
pinMode(STARTATOP_ENGHD_STAT_BUTTON_PIN, INPUT);
}
/******************************************************************
* Name : Interrupt_Init
* Description : Setting the registers to create an interruption for
every 1ms using timer1 and prescalar of 64.
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
void Interrupt_Init()
{
cli(); //stop interrupts till we make the settings
TCCR1A = 0; // Reset entire TCCR1A to 0
TCCR1B = 0; // Reset entire TCCR1B to 0
TCCR1B |= B00000011;
TIMSK1 |= B00000010; //Set OCIE1A to 1 so we enable compare match A
OCR1A=250; //1ms
sei();
}
/******************************************************************
* Name : Lcd_Init
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void Lcd_Init()
{
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("EHd_St_BC_F:");
}
/******************************************************************
* Name : Hood_Config_Init
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
void Hood_Config_Init(void)
{
if((PSAQ_EngHd_StartStop_Enable_Fct == 0 ) && (PSAQ_EngHd_VTA_Enable_Fct == 0))
{
HoodDisable_State_en();
}
else
{
HoodEnable_State_en();
}
}
/******************************************************************
* Name : HoodDisable_State_en
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void HoodDisable_State_en(void)
{
Hood_Config_state_re = E_HOOD_DISABLE;
EngHd_Stat_BC_F = 3;
}
/******************************************************************
* Name : HoodEnable_State_en
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void HoodEnable_State_en(void)
{
Hood_Config_state_re = E_HOOD_ENABLE;
HoodClose_State_en();
}
/******************************************************************
* Name : HoodClose_State_en
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void HoodClose_State_en(void)
{
Hood_Control_state_re = E_HOOD_CLOSE;
EngHd_Stat_BC_F = 1;
}
/******************************************************************
* Name : loop
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
void loop()
{
if(Tick10msCounter>=10)//10ms task
{
Tick10msCounter = 0;
Task_10ms();
}
if(Tick40msCounter>=40)//40 ms task
{
Tick40msCounter = 0;//control fan in 40ms()
Task_40ms();
}
if(Tick100msCounter>=100)//100 ms task
{
Tick100msCounter = 0;
Task_100ms();
}
}
/******************************************************************
* Name : Task_10ms
* Description :
* Parameters :
* Return :
* Critical : N/A
******************************************************************/
static void Task_10ms(void)
{
Read_PSAQ_EngHd_VTA_Enable_Fct_Status();//BUTTON_PIN1
Read_PSAQ_EngHd_StartStop_Enable_Fct_Status();////BUTTON_PIN2
Read_VTA_EngHd_Stat_Status();//BUTTON_PIN3
Read_StartStop_EngHd_Stat_Status();//BUTTON_PIN4
Lcd_Display();
}
/******************************************************************
* Name : Task_40ms
* Description :
* Parameters :
* Return :
* Critical : N/A
******************************************************************/
static void Task_40ms(void)
{
Hood_Config_du();
}
/******************************************************************
* Name : Task_100ms
* Description :
* Parameters :
* Return :
* Critical : N/A
******************************************************************/
static void Task_100ms(void)
{
/* do nothing*/
}
/******************************************************************
* Name : Read_PSAQ_EngHd_VTA_Enable_Fct_Status
* Description :
* Parameters :
* Return :
* Critical : N/A
******************************************************************/
static void Read_PSAQ_EngHd_VTA_Enable_Fct_Status(void)
{
PSAQ_EngHd_VTA_Enable_Fct=digitalRead(PSAQ_ENGHD_VTA_Enable_FCT_BUTTON_PIN);
}
/******************************************************************
* Name : Read_PSAQ_EngHd_StartStop_Enable_Fct_Status
* Description :
* Parameters :
* Return :
* Critical : N/A
******************************************************************/
static void Read_PSAQ_EngHd_StartStop_Enable_Fct_Status(void)
{
PSAQ_EngHd_StartStop_Enable_Fct=digitalRead(PSAQ_ENGHD_STARTSTOP_ENABLE_FCT_BUTTON_PIN);
}
/******************************************************************
* Name : Read_VTA_EngHd_Stat_Status
* Description :
* Parameters :
* Return :
* Critical : N/A
******************************************************************/
static void Read_VTA_EngHd_Stat_Status(void)
{
VTA_EngHd_Stat=digitalRead(VTA_ENGHD_STAT_BUTTON_PIN);
}
/******************************************************************
* Name : Read_StartStop_EngHd_Stat_Status
* Description :
* Parameters :
* Return :
* Critical : N/A
******************************************************************/
static void Read_StartStop_EngHd_Stat_Status(void)
{
StartStop_EngHd_Stat=digitalRead(STARTATOP_ENGHD_STAT_BUTTON_PIN);
}
/******************************************************************
* Name : Lcd_Display
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void Lcd_Display()
{
lcd.setCursor(12,0);
lcd.print(EngHd_Stat_BC_F);
}
/******************************************************************
* Name : Hood_Config_du
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
void Hood_Config_du(void)
{
switch(Hood_Config_state_re)
{
case E_HOOD_DISABLE:
if((PSAQ_EngHd_StartStop_Enable_Fct == 1 ) || (PSAQ_EngHd_VTA_Enable_Fct == 1))
{
HoodEnable_State_en();
}
else
{
/* do nothing */
}
break;
case E_HOOD_ENABLE:
if((PSAQ_EngHd_StartStop_Enable_Fct == 0 )&&(PSAQ_EngHd_VTA_Enable_Fct == 0))
{
HoodDisable_State_en();
}
else
{
HoodEnable_du();
}
break;
}
}
/******************************************************************
* Name : HoodEnable_du
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void HoodEnable_du(void)
{
switch(Hood_Control_state_re)
{
case E_HOOD_CLOSE:
if((VTA_EngHd_Stat == 0)|| (StartStop_EngHd_Stat == 0))
{
HoodOpen_State_entry_fun();
}
else
{
/*do nothing*/
}
break;
case E_HOOD_OPEN:
if((VTA_EngHd_Stat == 1)&& (StartStop_EngHd_Stat == 1))
{
HoodClose_State_en();
}
else
{
/*do nothing*/
}
break;
}
}
/******************************************************************
* Name : HoodOpen_State_entry_fun
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
static void HoodOpen_State_entry_fun(void)
{
Hood_Control_state_re = E_HOOD_OPEN;
EngHd_Stat_BC_F = 2;
}
/******************************************************************
* Name : ISR
* Description :
* Parameters : None
* Return : None
* Critical : N/A
******************************************************************/
ISR(TIMER1_COMPA_vect)
{
TCNT1 = 0;
Tick10msCounter++;
Tick40msCounter++;
Tick100msCounter++;
}