-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Seperate SM & scheduler * feat: Clean up scheduler API even more Not working yet, just comitting to move machines! * fix: Now it works! * feat: Add docs * feat: Remove state enum * fix: format * fix: format should NOT format build! * chore: refactor state_info to just state * fix: format * fix: Update docs to reflect no enum * fix: Get rid of superfluous wait * fix: Const issue --------- Co-authored-by: Niklas Vainio <niklasvainio8@gmail.com>
- Loading branch information
1 parent
84d1573
commit 58d8f7c
Showing
22 changed files
with
297 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Helper script to recursively clang-format every file | ||
echo Formatting all files... | ||
find . -name "*.cpp" -o -name "*.c" -o -name "*.h" | xargs -I {} clang-format -i {} | ||
echo Done! | ||
find src -name "*.cpp" -o -name "*.c" -o -name "*.h" | xargs -I {} clang-format -i {} | ||
echo Done! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
# Adding a new state | ||
|
||
## Add your state code to `states/mystate.c` and `states/mystate.h` | ||
|
||
Here you will define your transition condition. For example, if you always want | ||
to transition, you can write: | ||
|
||
```c | ||
sm_state_t my_state_get_next_state(slate_t *slate) | ||
{ | ||
return next_state; | ||
} | ||
|
||
sched_state_info_t my_state_info = { | ||
.name = "my state", | ||
.num_tasks = 1, | ||
.task_list = {&my_task, &blink_task}, | ||
.get_next_state = &my_task_get_next_state} | ||
``` | ||
If you need to reference another state (e.g. to transition) or task you should | ||
include the top level list headers `state_machine/tasks.h` and | ||
`state_machine/states.h`, not the headers for each task and state. | ||
## Add your state to `states.h` | ||
First add your state to the extern list: | ||
```c | ||
extern sched_state_info_t init_state_info; | ||
extern sched_state_info_t running_state_info; | ||
extern sched_state_info_t my_state_info; | ||
``` | ||
|
||
Then, add your state to the array: | ||
|
||
```c | ||
static sched_state_info_t* all_states[] = { | ||
/* state_init */ | ||
&init_state_info, | ||
/* state_running */ | ||
&running_state_info, | ||
/* my_state */ | ||
&my_state_info}; | ||
``` | ||
# Adding a new task | ||
## Add your task code to `tasks/mytask.c` and `tasks/mytask.h` | ||
See the other tasks for details, most importantly you will need something like: | ||
```c | ||
sched_task_t my_task = {.name = "my task", | ||
.dispatch_period_ms = 1000, | ||
.task_init = &my_task_init, | ||
.task_dispatch = &my_task_dispatch, | ||
/* Set to an actual value on init */ | ||
.next_dispatch = 0}; | ||
``` | ||
|
||
## Add your task to `tasks.h` | ||
|
||
```c | ||
extern sched_task_t print_task; | ||
extern sched_task_t blink_task; | ||
extern sched_task_t my_task; | ||
``` | ||
|
||
Now you can use your task in states! |
Oops, something went wrong.