30 likes | 209 Views
main (). int main(void) { unsigned int buttons, dir , mode, sm_code , mS ; system_init (); /* Initialize Cerebot MX7ck */ while(1) /* Infinite application loop */ { buttons= read_buttons (); decode_buttons (buttons, & dir , &mode);
E N D
main () intmain(void) { unsigned int buttons, dir, mode, sm_code, mS; system_init(); /* Initialize Cerebot MX7ck */ while(1) /* Infinite application loop */ { buttons=read_buttons(); decode_buttons(buttons, &dir, &mode); sm_code=sw_fsm(dir, mode); output_sm_code(sm_code); mS=delay_calc(mode); hw_msDelay(mS); } return(1); } /* End of main */
decode_buttons() void decode_buttons(unsigned int buttons, unsigned int *dir, unsigned int *mode) { switch (buttons) { case BTN1 : *dir = CW; *mode = HS; break; [...] } // case } // decode_buttons dir and mode are pointer variables local to decode_buttons
sw_fsm() unsigned intsw_fsm(unsigned intdir, unsigned int mode) { enum {S0=0, S0_5, S1, S1_5, S2, S2_5, S3, S3_5}; static unsigned intpstate; const unsigned intsm_code[] = {0x02, 0x0A, [...] }; switch (pstate) // Next State Logic { case S0: if (dir==CW) { if (mode == HS) pstate= S0_5; else // FS pstate = S1; } else // CCW [...] break; [...] No magic numbers!