/**************************************************************************** Module Event_Checker.c Description Contains the Event Checker for the main state machine Notes History WhenWhoWhat/Why -------------- ----------- NRM ****************************************************************************/ /*----------------------------- Include Files -----------------------------*/ #include <hidef.h>/* common defines and macros */ #include <mc9s12e128.h>/* derivative information */ #include <stdio.h> #include <S12E128bits.h> #include"ADS12.h" #include"SCI.h" #include"HC_Controller.h" #include"EventChecker.h" #pragma LINK_INFO DERIVATIVE"SampleS12" /*----------------------------- Module Defines ----------------------------*/ #define _OFF_ 0 #define _ON_1 #define _SET_ 1 /*---------------------------- Module Functions ---------------------------*/ Event_tCheck_Events(void); static charQueryCurrent_Switch_State(void); /*---------------------------- Module Variables ---------------------------*/ static unsigned charPrevious_Switch_State=_OFF_; static unsigned charCurrent_Switch_State=_OFF_; staticEvent_t PreviousEvent=NO_EVENT; Event_t CurrentEvent=NO_EVENT; /*------------------------------ Module Code ------------------------------*/ /**************************************************************************** Function Check_Events() Parameters Returns The event in Event_t type Description Notes Author Nick Musser ****************************************************************************/ Event_tCheck_Events(void) { charKeyStroke; charKey_Switch=QueryCurrent_Switch_State(); Event_t CurrentEvent=NO_EVENT; //Test State machine with these manual (keyboard hit triggered) events if(kbhit() !=0)// there was a key pressed { KeyStroke=getchar(); switch(toupper(KeyStroke)) { case'A':CurrentEvent=SWITCH_ON;break; case'B':CurrentEvent=CIPHER_RECEIVED;break; case'C':CurrentEvent=GO;break; case'D':CurrentEvent=SKIP_MODE_ON;break; case'E':CurrentEvent=NEW_MESSAGE;break; case'F':CurrentEvent=TIME_TO_SEND_INPUTS;break; case'G':CurrentEvent=NO_EVENT;break; case'H':CurrentEvent=SWITCH_OFF;break; } return(CurrentEvent); } if(Key_Switch==_ON_)// If game switch is on and it was off before { returnSWITCH_ON;// return switch on event } if(Key_Switch==_OFF_)// if game switch is off and it was on { returnSWITCH_OFF;// return switch OFF event } if(Query_Received_Cipher_Flag() ==_SET_)// if cipher flag is set { returnCIPHER_RECEIVED;// return CIPHER_RECEIVED event } if(Query_GO_Flag() ==_SET_)// GO flag is set { returnGO;// return GO event } if(Query_New_Message_Flag() ==_SET_)// if New message flag is set { returnNEW_MESSAGE;// return NEW MESSAGE event } if(Query_Time_To_Send_Inputs_Flag() ==_SET_)// if Time to send Inputs flag is set { returnTIME_TO_SEND_INPUTS;// retun TIME TO SEND INPUTS event } returnCurrentEvent; } /**************************************************************************** Function QueryCurrent_Switch_State() Parameters Returns 0, 1, or 2 Description Queries the current switch state.Returns 1 if the switch has been turned on, returns a 0 if the switch has been turned off, and a 2 otherwise Notes Author Nick Musser ****************************************************************************/ charQueryCurrent_Switch_State(void) { charPort_Value= (PTP&BIT2HI);// read switch port Previous_Switch_State=Current_Switch_State;// assign current port state to previous switch state if(Port_Value!=_OFF_)// if switch port is high { Current_Switch_State=_ON_;// current switch state is high } if(Port_Value==_OFF_)// if switch port is low { Current_Switch_State=_OFF_;// current swtich state is low } if((Current_Switch_State==_ON_) && (Previous_Switch_State==_OFF_))// If game switch is on and it was off before { return1;// indicate that a on change has occured } if((Current_Switch_State==_OFF_) && (Previous_Switch_State==_ON_))// if game switch is off and it was on { return0;// indicate that an off change has occured } return2;// no change has occurred. }// end of function