-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathfsm_switch_case_simple_docfsm.c
48 lines (41 loc) · 1.15 KB
/
fsm_switch_case_simple_docfsm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <stdio.h>
#include <unistd.h>
#define FSM_TRANSITION( newStade, attr... ) state = newStade
#define FSM_INIT_FSM( startState, attr... ) state = startState
#define FSM_DECLARE_STATE( state, attr... ) state
typedef enum
{
FSM_DECLARE_STATE( ON, color=red, label='Light is on' ),
FSM_DECLARE_STATE( OFF, color=green )
} STATE_T;
int main( void )
{
int i;
STATE_T state;
printf( "Test of %s\n", __FILE__ );
FSM_INIT_FSM( ON, label='Start', color=blue );
for( i = 0; i < 10; i++ )
{
switch( state )
{
case ON:
{
printf( "State: ON\n" );
FSM_TRANSITION( OFF, color=red,
label='On-time\nexpired' );
break;
}
case OFF: {
printf( "State: OFF\n" );
FSM_TRANSITION( ON, color = green,
label = 'Off-time\n'
'expired' );
break;
}
}
sleep( 1 );
}
return 0;
}
// gcc fsm_switch_case_simple_docfsm.c -o fsm
// docfsm fsm_switch_case_simple_docfsm.c | dot -Tpng -o myFsmSwitchCase_for_docfsm.png