Chained ifs -> case statement.

Easier to read. Easier to modify. More size-efficient code.
pull/21/head
Jesse Vincent 8 years ago
parent 25f10397fe
commit 130af01807

@ -27,16 +27,27 @@ LEDControl_::LEDControl_(void) {
void LEDControl_::initialize_led_mode(uint8_t mode) { void LEDControl_::initialize_led_mode(uint8_t mode) {
set_all_leds_to(led_off); set_all_leds_to(led_off);
if (mode == LED_MODE_OFF) { switch (LED_MODE_OFF) {
// set_all_leds_to(led_off);
} else if (mode == LED_MODE_HEATMAP) { case LED_MODE_OFF:
} else if (mode == LED_MODE_BREATHE) { break;
} else if (mode == LED_MODE_RAINBOW) { case LED_MODE_HEATMAP:
} else if (mode == LED_MODE_RAINBOW_WAVE) { break;
} else if (mode == LED_MODE_CHASE) { case LED_MODE_BREATHE:
} else if (mode == LED_MODE_STEADY) { break;
case LED_MODE_RAINBOW:
break;
case LED_MODE_RAINBOW_WAVE:
break;
case LED_MODE_CHASE:
break;
case LED_MODE_STEADY:
set_all_leds_to(led_steady); set_all_leds_to(led_steady);
break;
default:
break;
} }
} }
@ -77,21 +88,32 @@ void LEDControl_::update(uint8_t current_keymap) {
if (led_mode != last_led_mode) { if (led_mode != last_led_mode) {
initialize_led_mode(led_mode); initialize_led_mode(led_mode);
} }
if (led_mode == LED_MODE_OFF) { switch (led_mode) {
} else if (led_mode == LED_MODE_HEATMAP) {
} else if (led_mode == LED_MODE_BREATHE) { case LED_MODE_OFF:
break;
case LED_MODE_HEATMAP:
break;
case LED_MODE_BREATHE:
effect_breathe_update(); effect_breathe_update();
} else if (led_mode == LED_MODE_RAINBOW) { break;
case LED_MODE_RAINBOW:
effect_rainbow_update(); effect_rainbow_update();
} else if (led_mode == LED_MODE_RAINBOW_WAVE) { break;
case LED_MODE_RAINBOW_WAVE:
effect_rainbow_wave_update(); effect_rainbow_wave_update();
} else if (led_mode == LED_MODE_CHASE) { break;
case LED_MODE_CHASE:
effect_chase_update(); effect_chase_update();
} else if (led_mode == LED_MODE_STEADY) { break;
case LED_MODE_STEADY:
effect_steady_update(); effect_steady_update();
} else if (led_mode == LED_SPECIAL_MODE_NUMLOCK) { break;
case LED_SPECIAL_MODE_NUMLOCK:
effect_numlock_update(); effect_numlock_update();
break;
default:
break;
} }
led_sync(); led_sync();

Loading…
Cancel
Save