From 20437d0d0531c0a935576efdc93d9a30bf6da1af Mon Sep 17 00:00:00 2001 From: ThomasintAnker Date: Thu, 27 Jun 2024 10:51:43 +0200 Subject: Fixed wrong order of playing --- main/i2c.c | 14 ++++++++++---- 1 file 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() { -- cgit v1.2.3