aboutsummaryrefslogtreecommitdiff
path: root/main
diff options
context:
space:
mode:
authorThomasintAnker <thomasintanker1@gmail.com>2024-06-27 10:51:43 +0200
committerThomasintAnker <thomasintanker1@gmail.com>2024-06-27 10:51:43 +0200
commit20437d0d0531c0a935576efdc93d9a30bf6da1af (patch)
tree83dd4f9435c70fe2cc37ae6c5515d44ea149d39c /main
parent47ace5dc53a86affe93ccd24b67e28aa7277da2c (diff)
Fixed wrong order of playing
Diffstat (limited to 'main')
-rw-r--r--main/i2c.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/main/i2c.c b/main/i2c.c
index 1d64f30..b90e3b2 100644
--- a/main/i2c.c
+++ b/main/i2c.c
@@ -62,16 +62,22 @@ static void update_state() {
// if a module is still playing, don't promote a next one to playing module
if (playing > 0) return;
+ size_t next_idx;
+ uint8_t first_addr = (1 << 7);
for (size_t i = 0; i < modules_size; i++) {
// find first module that is idle
pb_global_state_t module_state = modules[i].state;
if (module_state != PB_GS_IDLE) continue;
+
+ if (modules[i].sender > first_addr) continue;
- pb_buf_t buff = pb_send_state_set(PB_GS_PLAYING);
- pb_i2c_send(modules[i].sender, (uint8_t *) buff.data, buff.size);
- pb_buf_free(&buff);
- return;
+ first_addr = modules[i].sender;
+ next_idx = i;
}
+
+ pb_buf_t buff = pb_send_state_set(PB_GS_PLAYING);
+ pb_i2c_send(modules[next_idx].sender, (uint8_t *) buff.data, buff.size);
+ pb_buf_free(&buff);
}
static void state_exchange() {