|
@@ -238,7 +238,7 @@ Now let's look at how that information gets sent to the rest of the code:
|
|
|
|
|
|
## newEvent()
|
|
|
|
|
|
-Here's a block diagram of the message flow 
|
|
|
+Here's a block diagram of the message flow 
|
|
|
|
|
|
How do we send the information (events/messages) from the interrupt
|
|
|
service routine to the
|
|
@@ -433,7 +433,7 @@ discussion about [shared timers](#timers-as-a-resource)
|
|
|
The other task of this project simply flashes the LED on and off.
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
The code for this might be:
|
|
|
|
|
@@ -473,7 +473,7 @@ void ledTask(uint8 evt) {
|
|
|
|
|
|
Perhaps a more accurate state diagram might be:
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
As you build the code from the diagram, I *strongly* suggest that you use
|
|
|
a `switch(currentState) ....case STATE_1` approach to the task routine.
|
|
@@ -705,19 +705,14 @@ easily handle *dozens* of tasks, even on sub-$1 processors.
|
|
|
|
|
|
## Variations
|
|
|
|
|
|
-<style>
|
|
|
-.imageleft {float: left;}
|
|
|
-.imageright {float: right;}
|
|
|
-</style>
|
|
|
-
|
|
|
Now that the infrastructure is in place, it's easy to expand or modify
|
|
|
the code for changes in the project definition.
|
|
|
|
|
|
For example, suppose we want the `respondToButtonTask()` to restart the
|
|
|
LED timer on each key press:
|
|
|
|
|
|
-{.imageleft}
|
|
|
-
|
|
|
+<div style="display: flex;">
|
|
|
+\
|
|
|
```C
|
|
|
void rtbTask(uint8 event) {
|
|
|
switch(rtbState) {
|
|
@@ -742,13 +737,14 @@ void rtbTask(uint8 event) {
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
+</div>
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
Or have a 2nd press of the button cause the LED to extinguish early:
|
|
|
|
|
|
-{.imageleft}
|
|
|
-
|
|
|
+<div style="display: flex;">
|
|
|
+\
|
|
|
```C
|
|
|
void rtbTask(uint8 event) {
|
|
|
switch(rtbState) {
|
|
@@ -774,6 +770,7 @@ void rtbTask(uint8 event) {
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
+</div>
|
|
|
|
|
|
<hr>
|
|
|
|
|
@@ -781,7 +778,9 @@ void rtbTask(uint8 event) {
|
|
|
How about have the button start a flash sequence, and a 2nd press stops
|
|
|
it: (see also [substates](#substates))
|
|
|
|
|
|
-{.imageright}
|
|
|
+<div style="display: flex;">
|
|
|
+
|
|
|
+\
|
|
|
|
|
|
```C
|
|
|
void rtbTask(uint8 event) {
|
|
@@ -822,7 +821,7 @@ void rtbTask(uint8 event) {
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
-
|
|
|
+</div>
|
|
|
<hr>
|
|
|
|
|
|
Each of these diagrams corresponds to trivial changes in the state code.
|
|
@@ -999,6 +998,7 @@ void taskWindow(char event, int windowIndex) {
|
|
|
}
|
|
|
}
|
|
|
```
|
|
|
+
|
|
|
</details>
|
|
|
|
|
|
|
|
@@ -1014,7 +1014,7 @@ and turn off the light and alarm. And if the door closes during the 90 seconds,
|
|
|
|
|
|
Here is the state diagram.
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
And here is the corresponding code.
|
|
|
|
|
@@ -1596,7 +1596,7 @@ void (*myvectors[])(void) __attribute__ ((section(".vectors")))= {
|
|
|
For things like flashing LED's, you could create two states,
|
|
|
and toggle between them, like this:
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
<hr>
|
|
|
|
|
@@ -1614,7 +1614,8 @@ Alternatively, you could use the *timer counter*
|
|
|
variable, and make changes at the half-way point through the count.
|
|
|
This simplifies the substate design to this:
|
|
|
|
|
|
-{.imageright}
|
|
|
+<div style="display: flex;">
|
|
|
+\
|
|
|
|
|
|
```C
|
|
|
const uint16 FLASH_CYCLE_TIME 150;
|
|
@@ -1651,6 +1652,7 @@ void rtbTaskCode(char event) {
|
|
|
}
|
|
|
|
|
|
```
|
|
|
+</div>
|
|
|
|
|
|
## State Machine Initialization
|
|
|
|