// // FSM implemention which illustrates a finite state machine // Scott Hudson, HCII CMU 10/99 // // Note that the behavior of this FSM may be a little suprising. In // particular, you can't ever end up in state 3 (lower right) because // an exit always preceeds the release (this is a flaw in the way the // event delivery for the project was defined). // // background image with a drawing of the state machine region machine at 0,0, 290,182 drawn with "fsm_machine.gif"; // region that provides input to the simulation region input_region at 39,200, 256,355 drawn with "test_region.gif"; // button for resetting to start state region reset_button at 10,10, 107,47 drawn with "reset_out.gif"; // highlight icons over the images of states // we turn these on (displaying state_highlight.gif) and off (displaying // nothing) in order to show the current state region state0_highlight at 15,140, 15,140 drawn with "state_highlight.gif"; region state1_highlight at 121,141, 121,141; region state2_highlight at 121,9, 121,9; region state3_highlight at 248,141, 248,141; region state4_highlight at 248,9, 248, 9; // States in the diagram are numbered as follows: // (2)---->(4) // ^ // | // (0)----------->(1)-----(3) // state state0 on press input_region goto state1 { // move the hightlight from state 0 to state 1 clear_image(state0_highlight); set_image(state1_highlight, "state_highlight.gif"); }; end state; state state1 on exit input_region goto state2 { // move the hightlight from state 1 to state 2 clear_image(state1_highlight); set_image(state2_highlight, "state_highlight.gif"); }; on release input_region goto state3 { // move the hightlight from state 1 to state 3 clear_image(state1_highlight); set_image(state3_highlight, "state_highlight.gif"); }; // implement a simple reset button on press reset_button goto state0 { // move the hightlight from state 1 back to state 0 clear_image(state1_highlight); set_image(state0_highlight, "state_highlight.gif"); }; end state; state state2 on enter input_region goto state1 { // move the hightlight from state 2 to state 1 clear_image(state2_highlight); set_image(state1_highlight, "state_highlight.gif"); }; on release input_region or release reset_button or release machine or release none goto state4 { // move the hightlight from state 2 to state 4 clear_image(state2_highlight); set_image(state4_highlight, "state_highlight.gif"); }; // implement a simple reset button on press reset_button goto state0 { // move the hightlight from state 2 back to state 0 clear_image(state2_highlight); set_image(state0_highlight, "state_highlight.gif"); }; end state; state state3 // implement a simple reset button on press reset_button goto state0 { // move the hightlight from state 3 back to state 0 clear_image(state3_highlight); set_image(state0_highlight, "state_highlight.gif"); }; end state; state state4 // implement a simple reset button on press reset_button goto state0 { // move the hightlight from state 4 back to state 0 clear_image(state4_highlight); set_image(state0_highlight, "state_highlight.gif"); }; end state;