Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc17ccf7

Browse files
committed
modified: README.md
1 parent522de64 commitc17ccf7

File tree

1 file changed

+57
-13
lines changed

1 file changed

+57
-13
lines changed

‎README.md‎

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ typedef struct {
2424
##Initial State
2525
The Finite-State require to initial with an initial id.
2626

27+
Syntax:
2728
```C
2829
voidbegin(const id_t id);
2930
```
@@ -43,10 +44,19 @@ typedef bool (*PredicateFunc)(id_t); // Predicate Function Pointer
4344
4445
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***:
4546
47+
Syntax:
4648
```C
4749
bool PredicateFunction(id_t id); // Predicate Function
4850
```
4951

52+
Example:
53+
```C
54+
boolPredicateInput(id_t id) {
55+
// TODO: PREDICATE FUNCTION
56+
57+
return button.isKeyPressed();
58+
}
59+
```
5060
5161
## Target
5262
A Target has two destinations:
@@ -66,19 +76,40 @@ The State Function is a function to implement Input/Output control, read/write d
6676
```C
6777
typedef void (*StateFunc)(State); // State Function Pointer
6878
```
79+
State:
80+
```C
81+
typedefstruct {
82+
id_t id; // State id
83+
bool firstScan; // First Scan when State Activated
84+
} State;
85+
```
6986

7087
The following function accepts`state` from a caller; type is parameters of type`State`:
7188

89+
Syntax:
7290
```C
7391
voidStateFunction(State state); // State Function
7492
```
75-
State:
93+
Example:
7694
```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+
}
81111
```
112+
82113
NOTE: The Id can also be obtained from`objectName.id`.
83114
```C
84115
id_t id = finiteStateMachine.id;
@@ -87,19 +118,11 @@ id_t id = finiteStateMachine.id;
87118
##Event Function
88119
An Event Function is an option. Finite-State will handle events when the state changes for`ENTRY` and`EXIT` actions.
89120

90-
91121
```C
92122
typedefvoid (*EventFunc)(EventArgs); // Event Function Pointer
93123
```
94124
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-
101125
EventArgs:
102-
103126
```C
104127
typedef struct {
105128
id_t id; // State id
@@ -116,6 +139,27 @@ enum Events : int8_t {
116139
};
117140
```
118141

142+
The following function accepts`state` from a caller; type is parameters of type`State`:
143+
Syntax:
144+
```C
145+
voidEventFunction(State state); // Event Function
146+
```
147+
148+
Example:
149+
```C
150+
void EventMotorControl(EventArgs e) {
151+
switch (e.event) {
152+
case ENTRY:
153+
digitalWrite(motor[state.in].output, true);
154+
break;
155+
case EXIT:
156+
digitalWrite(motor[state.in].output, false);
157+
break;
158+
}
159+
}
160+
```
161+
162+
119163
#Example
120164
##Fan Control With A Thermostat
121165

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp