diff options
author | ThomasintAnker <thomasintanker1@gmail.com> | 2024-06-27 10:51:43 +0200 |
---|---|---|
committer | ThomasintAnker <thomasintanker1@gmail.com> | 2024-06-27 10:51:43 +0200 |
commit | 20437d0d0531c0a935576efdc93d9a30bf6da1af (patch) | |
tree | 83dd4f9435c70fe2cc37ae6c5515d44ea149d39c /main | |
parent | 47ace5dc53a86affe93ccd24b67e28aa7277da2c (diff) |
Fixed wrong order of playing
Diffstat (limited to 'main')
-rw-r--r-- | main/i2c.c | 14 |
1 files changed, 10 insertions, 4 deletions
@@ -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() { |