From 6f9d1474c6e106832c00e71d8cc2fb60736b9ce6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Sat, 22 Oct 2022 13:30:24 +0200 Subject: [PATCH] Fix uninitialized variables. This is not critical --- main.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/main.c b/main.c index b4fb76d..6210312 100644 --- a/main.c +++ b/main.c @@ -81,10 +81,10 @@ static void process_mode(enum color_mode mode, const struct poti_values *poti_va case MODE_GREEN: case MODE_BLUE: for (i = 0; i < 32; i++) { - dmx_universe[i*4] = mode == MODE_RED ? poti_vals->pot_vals_filtered[0] : 0; - dmx_universe[i*4+1] = mode == MODE_GREEN ? poti_vals->pot_vals_filtered[0] : 0; - dmx_universe[i*4+2] = mode == MODE_BLUE ? poti_vals->pot_vals_filtered[0] : 0; - dmx_universe[i*4+3] = 0x0; + dmx_universe[i * 4 + 0] = mode == MODE_RED ? poti_vals->pot_vals_filtered[0] : 0; + dmx_universe[i * 4 + 1] = mode == MODE_GREEN ? poti_vals->pot_vals_filtered[0] : 0; + dmx_universe[i * 4 + 2] = mode == MODE_BLUE ? poti_vals->pot_vals_filtered[0] : 0; + dmx_universe[i * 4 + 3] = 0x0; } dmx_universe[128] = 0; odr |= (1<<5); @@ -92,20 +92,20 @@ static void process_mode(enum color_mode mode, const struct poti_values *poti_va case MODE_RGB: odr |= (1<<5) | (1<<6) | (1<<7); for (i = 0; i < 32; i++) { - dmx_universe[i*4] =poti_vals->pot_vals_filtered[0]; - dmx_universe[i*4+1] = poti_vals->pot_vals_filtered[1]; - dmx_universe[i*4+2] = poti_vals->pot_vals_filtered[2]; - dmx_universe[i*4+3] = 0x0; + dmx_universe[i * 4 + 0] =poti_vals->pot_vals_filtered[0]; + dmx_universe[i * 4 + 1] = poti_vals->pot_vals_filtered[1]; + dmx_universe[i * 4 + 2] = poti_vals->pot_vals_filtered[2]; + dmx_universe[i * 4 + 3] = 0x0; } dmx_universe[128] = 0; break; case MODE_WHITE_DISCRETE: - odr |= (1<<5); + odr |= (1<<5) | (1<<6); for (i = 0; i < 32; i++) { - dmx_universe[i*4] = 0; - dmx_universe[i*4+1] = 0; - dmx_universe[i*4+2] = 0; - dmx_universe[i*4+3] = 0; + dmx_universe[i * 4 + 0] = 0; + dmx_universe[i * 4 + 1] = 0; + dmx_universe[i * 4 + 2] = 0; + dmx_universe[i * 4 + 3] = gamma_corr(poti_vals->pot_vals_filtered[1]); } dmx_universe[128] = gamma_corr(poti_vals->pot_vals_filtered[0]); break; @@ -171,10 +171,10 @@ int main(void) int i; uint8_t port; uint8_t button_pressed; - enum color_mode mode = MODE_WHITE_DISCRETE; + enum color_mode mode = MODE_DMX_SHUTDOWN; enum color_mode old_mode = MODE_BLUE; - struct poti_values poti_vals; - struct poti_values old_poti_vals; + struct poti_values poti_vals = {0}; + struct poti_values old_poti_vals = {0}; bool buttons_released_since_dual_press = true; setup_pins(); @@ -191,8 +191,6 @@ int main(void) dmx_universe[i] = 0x00; } - dmx_stream_start(); - while (1) { systick_wait_ms(20); poti_get_values(&poti_vals); @@ -212,6 +210,7 @@ int main(void) if (!buttons_released_since_dual_press) button_pressed = 0u; } else { + /* Buttons are released. Remember this */ buttons_released_since_dual_press = true; } @@ -264,6 +263,6 @@ int main(void) /* Move to old values. Used to detect changes */ old_mode = mode; - memcpy(&old_poti_vals, &poti_vals, sizeof(struct poti_values)); + old_poti_vals = poti_vals; } }