12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
-
-
- #include "config.h"
- #include "log.h"
- #include "state_scan.h"
- #include "state.h"
-
- static enum system_state state = STATE_INIT;
-
- void state_switch(enum system_state next) {
- if (state == next) {
- return;
- }
-
-
- switch (state) {
- case STATE_SCAN:
- debug("leaving STATE_SCAN");
- state_scan_exit();
- break;
-
- default:
- break;
- }
-
-
- switch (next) {
- case STATE_SCAN:
- debug("entering STATE_SCAN");
- state_scan_enter();
- break;
-
- default:
- break;
- }
-
- state = next;
- }
-
- void state_run(void) {
-
- static uint32_t last_heartbeat = 0;
- uint32_t now = to_ms_since_boot(get_absolute_time());
- if (now < (last_heartbeat + 1000)) {
- return;
- }
- last_heartbeat = now;
-
- switch (state) {
- case STATE_INIT:
- break;
-
- case STATE_SCAN: {
- state_scan_run();
- break;
- }
-
- default:
- debug("invalid main state %d", state);
- state_switch(STATE_SCAN);
- break;
- }
- }
|