aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-06-21 10:51:19 +0200
committerLoek Le Blansch <loek@pipeframe.xyz>2024-06-21 10:51:19 +0200
commitd57d0cdb11451283fffbc3ac4b4deaacf188e94a (patch)
treebdd9568b5011a4c112f7a060b8eff4fc815e5974 /lib
parent3238485b246731990c8f073234ff202fb0fedc88 (diff)
add puzzle module init hook + weak implementation
Diffstat (limited to 'lib')
-rw-r--r--lib/pbdrv/pb-route.c9
-rw-r--r--lib/pbdrv/pb-route.h1
2 files changed, 9 insertions, 1 deletions
diff --git a/lib/pbdrv/pb-route.c b/lib/pbdrv/pb-route.c
index ee47700..df00cd3 100644
--- a/lib/pbdrv/pb-route.c
+++ b/lib/pbdrv/pb-route.c
@@ -56,8 +56,12 @@ __weak void pb_route_cmd_prop_req(pb_msg_t * msg) {}
__weak void pb_route_cmd_prop_res(pb_msg_t * msg) {}
__weak void pb_route_cmd_prop_set(pb_msg_t * msg) {}
+//! last known global state of last STATE REQ sender (i.e. main controller)
static pb_global_state_t _main_state = PB_GS_NOINIT;
__weak void pb_hook_main_state_update(pb_global_state_t state) {}
+__weak void pb_hook_module_init() {
+ pb_hook_mod_state_write(PB_GS_IDLE);
+}
__weak void pb_route_cmd_state_req(pb_msg_t * msg) {
pb_global_state_t own_state = pb_hook_mod_state_read();
pb_buf_t buf = pb_send_state_res(own_state);
@@ -66,8 +70,11 @@ __weak void pb_route_cmd_state_req(pb_msg_t * msg) {
// notify of new global state variable
pb_cmd_state_t * cmd = msg->cmd;
- if (cmd->state != _main_state)
+ if (cmd->state != _main_state) {
+ // first STATE REQ = module init OK
+ if (_main_state == PB_GS_NOINIT) pb_hook_module_init();
pb_hook_main_state_update(cmd->state);
+ }
_main_state = cmd->state;
}
diff --git a/lib/pbdrv/pb-route.h b/lib/pbdrv/pb-route.h
index 41c009a..967c4a9 100644
--- a/lib/pbdrv/pb-route.h
+++ b/lib/pbdrv/pb-route.h
@@ -27,6 +27,7 @@ void pb_route_cmd_state_res(pb_msg_t * msg);
void pb_route_cmd_state_set(pb_msg_t * msg);
void pb_hook_main_state_update(pb_global_state_t state);
+void pb_hook_module_init();
void pb_route_cmd_magic_req(pb_msg_t * msg);
void pb_route_cmd_magic_res(pb_msg_t * msg);