TucsonDon
Member
I have some code that I down loaded that I have been studying, it uses a state machine for a menu structure.
I have been trying to follow the flow by stepping through the code to lean and then adapt to my application. What is the benefit of defining the states in the header file?
C:
/* Instance data definition of state machine */
typedef struct{
XLP_8BIT_MENU_ENTRY_FLAG_T init_config_smEntry;
XLP_8BIT_MENU_STATEVAR_T stateVar;
XLP_8BIT_MENU_STATEVAR_T stateVarXLP_SM;
XLP_8BIT_MENU_INST_ID_T inst_id;
} XLP_8BIT_MENU_INSTANCEDATA_T;
C:
/* Macros to test if the machine is in a certain state. */
#define XLP_8BIT_MENU_IS_IN_LENGTH_TOGGLE_SM(instance)((((&instance)->stateVarXLP_SM==Length_Toggle_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_LENGTH_DISPLAY_SM(instance)((((&instance)->stateVarXLP_SM==Length_Display_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_SHOW_DEGREES_SM(instance)((((&instance)->stateVarXLP_SM==Show_Degrees_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_TIMEOUT_SM(instance)((((&instance)->stateVar==Timeout_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_BUZZER_SM(instance)((((&instance)->stateVarXLP_SM==Buzzer_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_SAVE_CUSTOM_SM(instance)((((&instance)->stateVarXLP_SM==Save_Custom_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_HFPLL_SM(instance)((((&instance)->stateVarXLP_SM==HFPLL_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_TIME_EXIT_SM(instance)((((&instance)->stateVarXLP_SM==Time_Exit_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_BUZZER_TOGGLE_SM(instance)((((&instance)->stateVarXLP_SM==Buzzer_Toggle_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_INIT_CONFIG_SM(instance)((((&instance)->stateVar==Init_Config_SM)) ? (1U) : (0U))
#define XLP_8BIT_MENU_IS_IN_LF_SM(instance)((((&instance)->stateVarXLP_SM==LF_SM)&&((&instance)->stateVar==XLP_SM)) ? (1U) : (0U))
I have been trying to follow the flow by stepping through the code to lean and then adapt to my application. What is the benefit of defining the states in the header file?