aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
Diffstat (limited to 'main')
-rw-r--r--main/i2c.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/main/i2c.c b/main/i2c.c
index 5074915..cf23d12 100644
--- a/main/i2c.c
+++ b/main/i2c.c
@@ -13,12 +13,18 @@
#include "pb-buf.h"
#include "pb-send.h"
-i2c_addr_t modules[CFG_PB_MOD_MAX];
+static pb_global_state_t _global_state = PB_GS_IDLE;
+pb_puzzle_module_t modules[CFG_PB_MOD_MAX];
size_t modules_size = 0;
static void state_exchange() {
-
+ pb_global_state_t new_state;
// TODO: Add calculation(?) to get global state
+ // noinit -> not possible, idle -> all idle, solved -> all solved, playing -> one playing
+ for (size_t i = 0; i < modules_size; i++) {
+
+ }
+ pb_hook_mod_state_write(new_state);
for (size_t i = 0; i < modules_size; i++) {
pb_buf_t buf = pb_send_state_req();
@@ -46,15 +52,28 @@ void bus_task() {
void pb_route_cmd_magic_res(pb_msg_t * msg) {
if (modules_size == CFG_PB_MOD_MAX) return;
- modules[modules_size++] = msg->sender;
+ pb_puzzle_module_t tmp_module = {msg->sender, PB_GS_NOINIT};
+ modules[modules_size++] = tmp_module;
printf("i2c: registered puzzle module w/ address 0x%02x\n", msg->sender);
}
void pb_route_cmd_state_res(pb_msg_t * msg) {
pb_cmd_state_t * cmd = msg->cmd;
- // return early if state has wrong size
- if (cmd->_magic_size != sizeof(pb_cmd_state_t))
- return;
+ i2c_addr_t sender = msg->sender;
+
+ // update sender state
+ for( size_t i = 0; i < modules_size; i++ ) {
+ if (modules[i].sender == sender) {
+ modules[i].state = (pb_global_state_t)cmd;
+ break;
+ }
+ }
+}
+
+pb_global_state_t pb_hook_mod_state_read() {
+ return _global_state;
+}
- // TODO: Get msg sender & update state in array struct (?)
+void pb_hook_mod_state_write(pb_global_state_t state) {
+ _global_state = state;
}