From 4d82db1f972968a3fade39d80e8ca0fb1d8e7bc4 Mon Sep 17 00:00:00 2001 From: Nate Soares Date: Wed, 3 Jan 2018 20:33:03 -0800 Subject: [PATCH] better wrap-around --- src/Kaleidoscope-LEDControl.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/Kaleidoscope-LEDControl.cpp b/src/Kaleidoscope-LEDControl.cpp index b955892d..3a9a0d53 100644 --- a/src/Kaleidoscope-LEDControl.cpp +++ b/src/Kaleidoscope-LEDControl.cpp @@ -35,13 +35,15 @@ void LEDControl::next_mode(void) { } void LEDControl::prev_mode(void) { - mode--; - - if (mode >= LED_MAX_MODES || !modes[mode]) { - return set_mode(0); + if (mode == 0) { + // wrap around + mode = LED_MAX_MODES; + // then count down until reaching a valid mode + while (mode > 0 && !modes[mode]) mode--; + } else { + mode--; } - - return set_mode(mode); + set_mode(mode); } void