|
|
|
@ -25,16 +25,14 @@ namespace kaleidoscope {
|
|
|
|
|
namespace plugin {
|
|
|
|
|
|
|
|
|
|
uint16_t Turbo::interval_ = 10;
|
|
|
|
|
uint16_t Turbo::flashInterval_ = 69;
|
|
|
|
|
uint16_t Turbo::flash_interval_ = 69;
|
|
|
|
|
bool Turbo::sticky_ = false;
|
|
|
|
|
bool Turbo::flash_ = true;
|
|
|
|
|
cRGB Turbo::activeColor_ = CRGB(160, 0, 0);
|
|
|
|
|
cRGB Turbo::active_color_ = CRGB(160, 0, 0);
|
|
|
|
|
|
|
|
|
|
bool Turbo::enable = false;
|
|
|
|
|
uint32_t Turbo::startTime = 0;
|
|
|
|
|
uint32_t Turbo::flashStartTime = 0;
|
|
|
|
|
KeyAddr Turbo::keyPositions[4];
|
|
|
|
|
uint16_t Turbo::numKeys = 0;
|
|
|
|
|
bool Turbo::active_ = false;
|
|
|
|
|
uint32_t Turbo::start_time_ = 0;
|
|
|
|
|
uint32_t Turbo::flash_start_time_ = 0;
|
|
|
|
|
|
|
|
|
|
uint16_t Turbo::interval() {
|
|
|
|
|
return interval_;
|
|
|
|
@ -44,10 +42,10 @@ void Turbo::interval(uint16_t newVal) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint16_t Turbo::flashInterval() {
|
|
|
|
|
return flashInterval_;
|
|
|
|
|
return flash_interval_;
|
|
|
|
|
}
|
|
|
|
|
void Turbo::flashInterval(uint16_t newVal) {
|
|
|
|
|
flashInterval_ = newVal;
|
|
|
|
|
flash_interval_ = newVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Turbo::sticky() {
|
|
|
|
@ -65,75 +63,91 @@ void Turbo::flash(bool newVal) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cRGB Turbo::activeColor() {
|
|
|
|
|
return activeColor_;
|
|
|
|
|
return active_color_;
|
|
|
|
|
}
|
|
|
|
|
void Turbo::activeColor(cRGB newVal) {
|
|
|
|
|
activeColor_ = newVal;
|
|
|
|
|
active_color_ = newVal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Turbo::findKeyPositions() {
|
|
|
|
|
numKeys = 0;
|
|
|
|
|
|
|
|
|
|
for (auto key_addr : KeyAddr::all()) {
|
|
|
|
|
if (Layer.lookupOnActiveLayer(key_addr) == Key_Turbo) {
|
|
|
|
|
keyPositions[numKeys++] = key_addr;
|
|
|
|
|
}
|
|
|
|
|
EventHandlerResult Turbo::onKeyEvent(KeyEvent &event) {
|
|
|
|
|
if (active_ && flash_ && keyToggledOff(event.state)) {
|
|
|
|
|
if (event.key.isKeyboardKey())
|
|
|
|
|
LEDControl::refreshAt(event.addr);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHandlerResult Turbo::onSetup() {
|
|
|
|
|
Turbo::findKeyPositions();
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHandlerResult Turbo::onNameQuery() {
|
|
|
|
|
return ::Focus.sendName(F("Turbo"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHandlerResult Turbo::onLayerChange() {
|
|
|
|
|
Turbo::findKeyPositions();
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
}
|
|
|
|
|
if (event.key != Key_Turbo)
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
|
|
|
|
|
EventHandlerResult Turbo::onKeyswitchEvent(Key &key, KeyAddr key_addr, uint8_t key_state) {
|
|
|
|
|
if (key != Key_Turbo) return EventHandlerResult::OK;
|
|
|
|
|
enable = sticky_ ? (keyIsPressed(key_state) ? enable : !enable) : keyIsPressed(key_state);
|
|
|
|
|
if (!enable) {
|
|
|
|
|
for (uint16_t i = 0; i < numKeys; i++) {
|
|
|
|
|
LEDControl::refreshAt(KeyAddr(keyPositions[i]));
|
|
|
|
|
}
|
|
|
|
|
if (keyToggledOn(event.state)) {
|
|
|
|
|
active_ = true;
|
|
|
|
|
start_time_ = Runtime.millisAtCycleStart() - interval_;
|
|
|
|
|
} else {
|
|
|
|
|
active_ = false;
|
|
|
|
|
if (flash_)
|
|
|
|
|
LEDControl::refreshAll();
|
|
|
|
|
}
|
|
|
|
|
return EventHandlerResult::EVENT_CONSUMED;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHandlerResult Turbo::afterEachCycle() {
|
|
|
|
|
if (enable) {
|
|
|
|
|
if (Runtime.millisAtCycleStart() - startTime > interval_) {
|
|
|
|
|
kaleidoscope::Runtime.hid().keyboard().sendReport();
|
|
|
|
|
startTime = Runtime.millisAtCycleStart();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flash_) {
|
|
|
|
|
if (Runtime.millisAtCycleStart() - flashStartTime > flashInterval_ * 2) {
|
|
|
|
|
for (uint16_t i = 0; i < numKeys; i++) {
|
|
|
|
|
LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), activeColor_);
|
|
|
|
|
if (active_) {
|
|
|
|
|
if (Runtime.hasTimeExpired(start_time_, interval_)) {
|
|
|
|
|
// Reset the timer.
|
|
|
|
|
start_time_ = Runtime.millisAtCycleStart();
|
|
|
|
|
|
|
|
|
|
// Clear the existing Keyboard HID report. It might be nice to keep the
|
|
|
|
|
// modifiers active, but I'll save that for another time.
|
|
|
|
|
Runtime.hid().keyboard().releaseAllKeys();
|
|
|
|
|
// Send the empty report to register the release of all the held keys.
|
|
|
|
|
Runtime.hid().keyboard().sendReport();
|
|
|
|
|
|
|
|
|
|
// Just in case the Turbo key has been wiped from `live_keys[]` without
|
|
|
|
|
// `onKeyEvent()` being called with a toggle-off:
|
|
|
|
|
active_ = false;
|
|
|
|
|
|
|
|
|
|
// Go through the `live_keys[]` array and add any Keyboard HID keys to the
|
|
|
|
|
// new report.
|
|
|
|
|
for (Key key : live_keys.all()) {
|
|
|
|
|
if (key == Key_Turbo) {
|
|
|
|
|
active_ = true;
|
|
|
|
|
}
|
|
|
|
|
flashStartTime = Runtime.millisAtCycleStart();
|
|
|
|
|
} else if (Runtime.millisAtCycleStart() - flashStartTime > flashInterval_) {
|
|
|
|
|
for (uint16_t i = 0; i < numKeys; i++) {
|
|
|
|
|
LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), {0, 0, 0});
|
|
|
|
|
if (key.isKeyboardKey()) {
|
|
|
|
|
Runtime.addToReport(key);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
LEDControl::syncLeds();
|
|
|
|
|
} else {
|
|
|
|
|
for (uint16_t i = 0; i < numKeys; i++) {
|
|
|
|
|
LEDControl::setCrgbAt(KeyAddr(keyPositions[i]), activeColor_);
|
|
|
|
|
|
|
|
|
|
// Send the re-populated keyboard report.
|
|
|
|
|
Runtime.hid().keyboard().sendReport();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHandlerResult Turbo::beforeSyncingLeds() {
|
|
|
|
|
if (flash_ && active_) {
|
|
|
|
|
static bool leds_on = false;
|
|
|
|
|
cRGB color = CRGB(0, 0, 0);
|
|
|
|
|
if (leds_on) {
|
|
|
|
|
color = active_color_;
|
|
|
|
|
}
|
|
|
|
|
if (Runtime.hasTimeExpired(flash_start_time_, flash_interval_)) {
|
|
|
|
|
flash_start_time_ = Runtime.millisAtCycleStart();
|
|
|
|
|
leds_on = !leds_on;
|
|
|
|
|
}
|
|
|
|
|
for (KeyAddr key_addr : KeyAddr::all()) {
|
|
|
|
|
Key key = live_keys[key_addr];
|
|
|
|
|
if (key.isKeyboardKey()) {
|
|
|
|
|
LEDControl::setCrgbAt(key_addr, color);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return EventHandlerResult::OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
EventHandlerResult Turbo::onNameQuery() {
|
|
|
|
|
return ::Focus.sendName(F("Turbo"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|