forked from endurodave/C_StateMachine
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
54 lines (40 loc) · 1.33 KB
/
main.c
File metadata and controls
54 lines (40 loc) · 1.33 KB
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
48
49
50
51
52
53
54
#include "fb_allocator.h"
#include "StateMachine.h"
#include "Motor.h"
#include "CentrifugeTest.h"
// Define motor objects
static Motor motorObj1;
static Motor motorObj2;
// Define two public Motor state machine instances
SM_DEFINE(Motor1SM, &motorObj1)
SM_DEFINE(Motor2SM, &motorObj2)
int main(void)
{
ALLOC_Init();
MotorData* data;
// Create event data
data = SM_XAlloc(sizeof(MotorData));
data->speed = 100;
// Call MTR_SetSpeed event function to start motor
SM_Event(Motor1SM, MTR_SetSpeed, data);
// Call MTR_SetSpeed event function to change motor speed
data = SM_XAlloc(sizeof(MotorData));
data->speed = 200;
SM_Event(Motor1SM, MTR_SetSpeed, data);
// Get current speed from Motor1SM
INT currentSpeed = SM_Get(Motor1SM, MTR_GetSpeed);
// Stop motor again will be ignored
SM_Event(Motor1SM, MTR_Halt, NULL);
// Motor2SM example
data = SM_XAlloc(sizeof(MotorData));
data->speed = 300;
SM_Event(Motor2SM, MTR_SetSpeed, data);
SM_Event(Motor2SM, MTR_Halt, NULL);
// CentrifugeTestSM example
SM_Event(CentrifugeTestSM, CFG_Cancel, NULL);
SM_Event(CentrifugeTestSM, CFG_Start, NULL);
while (CFG_IsPollActive())
SM_Event(CentrifugeTestSM, CFG_Poll, NULL);
ALLOC_Term();
return 0;
}