Merge branch 'pull/prev-mode'

Fixes #17.
pull/365/head
Gergely Nagy 7 years ago
commit 0b5003d3d2

@ -34,6 +34,19 @@ void LEDControl::next_mode(void) {
return set_mode(mode);
}
void LEDControl::prev_mode(void) {
if (mode == 0) {
// wrap around
mode = LED_MAX_MODES - 1;
// then count down until reaching a valid mode
while (mode > 0 && !modes[mode]) mode--;
} else {
mode--;
}
return set_mode(mode);
}
void
LEDControl::set_mode(uint8_t mode_) {
if (mode_ >= LED_MAX_MODES)
@ -117,8 +130,13 @@ Key LEDControl::eventHandler(Key mappedKey, byte row, byte col, uint8_t keyState
if (mappedKey.flags != (SYNTHETIC | IS_INTERNAL | LED_TOGGLE))
return mappedKey;
if (keyToggledOn(keyState))
if (keyToggledOn(keyState)) {
if (mappedKey == Key_LEDEffectNext) {
next_mode();
} else if (mappedKey == Key_LEDEffectPrevious) {
prev_mode();
}
}
return Key_NoKey;
}

@ -7,6 +7,7 @@
#define LED_TOGGLE B00000001 // Synthetic, internal
#define Key_LEDEffectNext (Key) { 0, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | LED_TOGGLE }
#define Key_LEDEffectPrevious (Key) { 1, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | LED_TOGGLE }
namespace kaleidoscope {
/** Base class for LED modes.
@ -90,6 +91,7 @@ class LEDControl : public KaleidoscopePlugin {
void begin(void) final;
static void next_mode(void);
static void prev_mode(void);
static void setup(void);
static void update(void) {
if (modes[mode])

Loading…
Cancel
Save