You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
The following function accepts `id` from a caller; type is a parameter of type `id_t`. The return type is `boolean`. It will be used to determine a Target for the ***current state*** and ***next state***:
45
46
47
+
Syntax:
46
48
```C
47
49
bool PredicateFunction(id_t id); // Predicate Function
48
50
```
49
51
52
+
Example:
53
+
```C
54
+
boolPredicateInput(id_t id) {
55
+
// TODO: PREDICATE FUNCTION
56
+
57
+
return button.isKeyPressed();
58
+
}
59
+
```
50
60
51
61
## Target
52
62
A Target has two destinations:
@@ -66,19 +76,40 @@ The State Function is a function to implement Input/Output control, read/write d
66
76
```C
67
77
typedef void (*StateFunc)(State); // State Function Pointer
68
78
```
79
+
State:
80
+
```C
81
+
typedefstruct {
82
+
id_t id; // State id
83
+
bool firstScan; // First Scan when State Activated
84
+
} State;
85
+
```
69
86
70
87
The following function accepts`state` from a caller; type is parameters of type`State`:
71
88
89
+
Syntax:
72
90
```C
73
91
voidStateFunction(State state); // State Function
74
92
```
75
-
State:
93
+
Example:
76
94
```C
77
-
typedefstruct {
78
-
id_t id; // State id
79
-
bool firstScan; // First Scan when State Activated
80
-
} State;
95
+
void MotorStatus(State state) {
96
+
StatusState status;
97
+
98
+
if (state.firstScan) {
99
+
Serial.println("Motor Status Function")
100
+
}
101
+
102
+
if (motor[state.id].timerON) {
103
+
if (motor[state.id].running) {
104
+
status = RUNNING;
105
+
} else {
106
+
status = FAULT;
107
+
}
108
+
digitalWrite(motor[state.in].faultPin, status == FAULT);
109
+
}
110
+
}
81
111
```
112
+
82
113
NOTE: The Id can also be obtained from`objectName.id`.
83
114
```C
84
115
id_t id = finiteStateMachine.id;
@@ -87,19 +118,11 @@ id_t id = finiteStateMachine.id;
87
118
##Event Function
88
119
An Event Function is an option. Finite-State will handle events when the state changes for`ENTRY` and`EXIT` actions.
89
120
90
-
91
121
```C
92
122
typedefvoid (*EventFunc)(EventArgs); // Event Function Pointer
93
123
```
94
124
95
-
The following function accepts `state` from a caller; type is parameters of type `State`:
96
-
97
-
```C
98
-
void EventFunction(State state); // Event Function
99
-
```
100
-
101
125
EventArgs:
102
-
103
126
```C
104
127
typedef struct {
105
128
id_t id; // State id
@@ -116,6 +139,27 @@ enum Events : int8_t {
116
139
};
117
140
```
118
141
142
+
The following function accepts`state` from a caller; type is parameters of type`State`: