|
|
@ -18,6 +18,7 @@
|
|
|
|
#include "Kaleidoscope-FocusSerial.h"
|
|
|
|
#include "Kaleidoscope-FocusSerial.h"
|
|
|
|
#include "kaleidoscope_internal/LEDModeManager.h"
|
|
|
|
#include "kaleidoscope_internal/LEDModeManager.h"
|
|
|
|
#include "kaleidoscope/keyswitch_state.h"
|
|
|
|
#include "kaleidoscope/keyswitch_state.h"
|
|
|
|
|
|
|
|
#include "kaleidoscope/LiveKeys.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace kaleidoscope::internal; // NOLINT(build/namespaces)
|
|
|
|
using namespace kaleidoscope::internal; // NOLINT(build/namespaces)
|
|
|
|
|
|
|
|
|
|
|
@ -32,7 +33,6 @@ LEDMode *LEDControl::cur_led_mode_ = nullptr;
|
|
|
|
uint8_t LEDControl::syncDelay = 32;
|
|
|
|
uint8_t LEDControl::syncDelay = 32;
|
|
|
|
uint16_t LEDControl::syncTimer = 0;
|
|
|
|
uint16_t LEDControl::syncTimer = 0;
|
|
|
|
bool LEDControl::enabled_ = true;
|
|
|
|
bool LEDControl::enabled_ = true;
|
|
|
|
Key LEDControl::pending_next_prev_key_ = Key_NoKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LEDControl::LEDControl(void) {
|
|
|
|
LEDControl::LEDControl(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -156,16 +156,33 @@ void LEDControl::enable() {
|
|
|
|
Runtime.device().syncLeds();
|
|
|
|
Runtime.device().syncLeds();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
kaleidoscope::EventHandlerResult LEDControl::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, uint8_t keyState) {
|
|
|
|
kaleidoscope::EventHandlerResult LEDControl::onKeyEvent(KeyEvent &event) {
|
|
|
|
if (mappedKey.getFlags() != (SYNTHETIC | IS_INTERNAL | LED_TOGGLE))
|
|
|
|
if (event.key.getFlags() != (SYNTHETIC | IS_INTERNAL | LED_TOGGLE))
|
|
|
|
return kaleidoscope::EventHandlerResult::OK;
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
|
|
|
|
|
|
|
if (keyToggledOn(keyState)) {
|
|
|
|
if (keyToggledOn(event.state)) {
|
|
|
|
if (mappedKey == Key_LEDEffectNext || mappedKey == Key_LEDEffectPrevious) {
|
|
|
|
if (event.key == Key_LEDEffectNext || event.key == Key_LEDEffectPrevious) {
|
|
|
|
// Handling of these keys is delayed into `beforeReportingState`
|
|
|
|
// First, check for an active shift key.
|
|
|
|
// so that we can incorporate the shift modifier state.
|
|
|
|
bool shift_active = false;
|
|
|
|
pending_next_prev_key_ = mappedKey;
|
|
|
|
// This change should be back-ported to #904
|
|
|
|
} else if (mappedKey == Key_LEDToggle) {
|
|
|
|
for (Key active_key : live_keys.all()) {
|
|
|
|
|
|
|
|
if (active_key.isKeyboardShift()) {
|
|
|
|
|
|
|
|
shift_active = true;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next, record which key (next or previous) was pressed as a boolean.
|
|
|
|
|
|
|
|
bool key_is_next = (event.key == Key_LEDEffectNext);
|
|
|
|
|
|
|
|
// This is basically an XOR with two booleans. If the "next" key was
|
|
|
|
|
|
|
|
// pressed and no shift key is active, or if the "previous" key was
|
|
|
|
|
|
|
|
// pressed and a shift key is active, we activate the next LED
|
|
|
|
|
|
|
|
// Mode. Otherwise, we activate the previous mode.
|
|
|
|
|
|
|
|
if (key_is_next != shift_active) {
|
|
|
|
|
|
|
|
next_mode();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
prev_mode();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else if (event.key == Key_LEDToggle) {
|
|
|
|
if (enabled_)
|
|
|
|
if (enabled_)
|
|
|
|
disable();
|
|
|
|
disable();
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -176,24 +193,10 @@ kaleidoscope::EventHandlerResult LEDControl::onKeyswitchEvent(Key &mappedKey, Ke
|
|
|
|
return kaleidoscope::EventHandlerResult::EVENT_CONSUMED;
|
|
|
|
return kaleidoscope::EventHandlerResult::EVENT_CONSUMED;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) {
|
|
|
|
kaleidoscope::EventHandlerResult LEDControl::afterEachCycle() {
|
|
|
|
if (!enabled_)
|
|
|
|
if (!enabled_)
|
|
|
|
return kaleidoscope::EventHandlerResult::OK;
|
|
|
|
return kaleidoscope::EventHandlerResult::OK;
|
|
|
|
|
|
|
|
|
|
|
|
if (pending_next_prev_key_ != Key_NoKey) {
|
|
|
|
|
|
|
|
bool is_shifted =
|
|
|
|
|
|
|
|
kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_LeftShift) ||
|
|
|
|
|
|
|
|
kaleidoscope::Runtime.hid().keyboard().isModifierKeyActive(Key_RightShift);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ((pending_next_prev_key_ == Key_LEDEffectNext && !is_shifted) ||
|
|
|
|
|
|
|
|
(pending_next_prev_key_ == Key_LEDEffectPrevious && is_shifted)) {
|
|
|
|
|
|
|
|
next_mode();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
prev_mode();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
pending_next_prev_key_ = Key_NoKey;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Runtime.hasTimeExpired(syncTimer, syncDelay)) {
|
|
|
|
if (Runtime.hasTimeExpired(syncTimer, syncDelay)) {
|
|
|
|
syncLeds();
|
|
|
|
syncLeds();
|
|
|
|
syncTimer += syncDelay;
|
|
|
|
syncTimer += syncDelay;
|
|
|
|