Adapt miscellaneous LED mode plugins to KeyEvent handlers

Signed-off-by: Michael Richters <gedankenexperimenter@gmail.com>
pull/1024/head
Michael Richters 4 years ago
parent 889b664a4a
commit 2073c4f855
No known key found for this signature in database
GPG Key ID: 1288FD13E4EEF0C0

@ -50,20 +50,22 @@ void FingerPainter::toggle(void) {
edit_mode_ = !edit_mode_;
}
EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
EventHandlerResult FingerPainter::onKeyEvent(KeyEvent &event) {
if (!Runtime.has_leds || !edit_mode_)
return EventHandlerResult::OK;
if (!keyToggledOn(key_state)) {
return EventHandlerResult::EVENT_CONSUMED;
if (keyToggledOff(event.state)) {
return EventHandlerResult::OK;
}
if (!key_addr.isValid())
return EventHandlerResult::EVENT_CONSUMED;
if (!event.addr.isValid())
return EventHandlerResult::OK;
// TODO(anyone): The following works only for keyboards with LEDs for each key.
uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, Runtime.device().getLedIndex(key_addr));
uint8_t color_index = ::LEDPaletteTheme
.lookupColorIndexAtPosition(color_base_,
Runtime.device().getLedIndex(event.addr));
// Find the next color in the palette that is different.
// But do not loop forever!
@ -80,7 +82,9 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_
new_color = ::LEDPaletteTheme.lookupPaletteColor(color_index);
}
::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, Runtime.device().getLedIndex(key_addr), color_index);
::LEDPaletteTheme.updateColorIndexAtPosition(color_base_,
Runtime.device().getLedIndex(event.addr),
color_index);
return EventHandlerResult::EVENT_CONSUMED;
}

@ -32,7 +32,7 @@ class FingerPainter : public LEDMode {
static void toggle(void);
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command);
EventHandlerResult onSetup();
EventHandlerResult onNameQuery();

@ -133,36 +133,38 @@ void Heatmap::TransientLEDMode::resetMap() {
highest_ = 1;
}
EventHandlerResult Heatmap::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
// It may be better to use `onKeyswitchEvent()` here
EventHandlerResult Heatmap::onKeyEvent(KeyEvent &event) {
// If the keyboard has no LEDs, return
if (!Runtime.has_leds)
return EventHandlerResult::OK;
// this methode is called frequently by Kaleidoscope
// even if the module isn't activated
// If the event doesn't correspond to a physical key, skip it
if (!event.addr.isValid())
return EventHandlerResult::OK;
// if it is a synthetic key, skip it
if (key_state & INJECTED)
if (event.state & INJECTED)
return EventHandlerResult::OK;
// if the key is not toggled on, skip it
if (!keyToggledOn(key_state))
if (!keyToggledOn(event.state))
return EventHandlerResult::OK;
// if the LED mode is not current, skip it
if (::LEDControl.get_mode_index() != led_mode_id_)
return EventHandlerResult::OK;
return ::LEDControl.get_mode<TransientLEDMode>()
->onKeyswitchEvent(mapped_key, key_addr, key_state);
return ::LEDControl.get_mode<TransientLEDMode>()->onKeyEvent(event);
}
EventHandlerResult Heatmap::TransientLEDMode::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
EventHandlerResult Heatmap::TransientLEDMode::onKeyEvent(KeyEvent &event) {
// increment the heatmap_ value related to the key
heatmap_[key_addr.toInt()]++;
heatmap_[event.addr.toInt()]++;
// check highest_
if (highest_ < heatmap_[key_addr.toInt()]) {
highest_ = heatmap_[key_addr.toInt()];
if (highest_ < heatmap_[event.addr.toInt()]) {
highest_ = heatmap_[event.addr.toInt()];
// if highest_ (and so heatmap_ value related to the key)
// is close to overflow: call shiftStats

@ -33,7 +33,7 @@ class Heatmap : public Plugin,
static uint8_t heat_colors_length;
void resetMap(void);
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult beforeEachCycle();
// This class' instance has dynamic lifetime
@ -48,7 +48,7 @@ class Heatmap : public Plugin,
explicit TransientLEDMode(const Heatmap *parent);
void resetMap();
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult beforeEachCycle();
protected:

@ -61,40 +61,40 @@ void AlphaSquareEffect::TransientLEDMode::refreshAt(KeyAddr key_addr) {
::LEDControl.setCrgbAt(key_addr, CRGB(0, 0, 0));
}
EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, uint8_t keyState) {
EventHandlerResult AlphaSquareEffect::onKeyEvent(KeyEvent &event) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;
if (::LEDControl.get_mode_index() != led_mode_id_)
return EventHandlerResult::OK;
if (keyState & INJECTED)
if (event.state & INJECTED)
return EventHandlerResult::OK;
if (mappedKey < Key_A || mappedKey > Key_0)
if (event.key < Key_A || event.key > Key_0)
return EventHandlerResult::OK;
if (!keyIsPressed(keyState))
return EventHandlerResult::OK;
// if (!keyIsPressed(event.state))
// return EventHandlerResult::OK;
uint8_t display_col = 2;
auto this_led_mode = ::LEDControl.get_mode<TransientLEDMode>();
Key prev_key = this_led_mode->last_key_left_;
if (key_addr.col() < Runtime.device().matrix_columns / 2) {
this_led_mode->last_key_left_ = mappedKey;
if (event.addr.col() < Runtime.device().matrix_columns / 2) {
this_led_mode->last_key_left_ = event.key;
this_led_mode->start_time_left_ = Runtime.millisAtCycleStart();
} else {
prev_key = this_led_mode->last_key_right_;
this_led_mode->last_key_right_ = mappedKey;
this_led_mode->last_key_right_ = event.key;
this_led_mode->start_time_right_ = Runtime.millisAtCycleStart();
display_col = 10;
}
if (prev_key != mappedKey)
if (prev_key != event.key)
::AlphaSquare.clear(prev_key, display_col);
::AlphaSquare.display(mappedKey, display_col);
::AlphaSquare.display(event.key, display_col);
return EventHandlerResult::OK;
}

@ -30,7 +30,7 @@ class AlphaSquareEffect : public Plugin,
static uint16_t length;
EventHandlerResult onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, uint8_t keyState);
EventHandlerResult onKeyEvent(KeyEvent &event);
// This class' instance has dynamic lifetime
//

@ -34,19 +34,20 @@ StalkerEffect::TransientLEDMode::TransientLEDMode(const StalkerEffect *parent)
map_{}
{}
EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState) {
EventHandlerResult StalkerEffect::onKeyEvent(KeyEvent &event) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;
if (!key_addr.isValid())
if (!event.addr.isValid())
return EventHandlerResult::OK;
if (::LEDControl.get_mode_index() != led_mode_id_)
return EventHandlerResult::OK;
if (keyIsPressed(keyState)) {
::LEDControl.get_mode<TransientLEDMode>()->map_[key_addr.toInt()] = 0xff;
}
// The simplest thing to do is trigger on both press and release. The color
// will fade while the key is held, and get restored to full brightness when
// it's released.
::LEDControl.get_mode<TransientLEDMode>()->map_[event.addr.toInt()] = 0xff;
return EventHandlerResult::OK;
}

@ -39,7 +39,7 @@ class StalkerEffect : public Plugin,
static uint16_t step_length;
static cRGB inactive_color;
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState);
EventHandlerResult onKeyEvent(KeyEvent &event);
// This class' instance has dynamic lifetime
//

@ -45,20 +45,21 @@ WavepoolEffect::TransientLEDMode::TransientLEDMode(const WavepoolEffect *parent)
page_(0)
{}
EventHandlerResult WavepoolEffect::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
if (!key_addr.isValid())
EventHandlerResult WavepoolEffect::onKeyEvent(KeyEvent &event) {
if (!event.addr.isValid())
return EventHandlerResult::OK;
if (::LEDControl.get_mode_index() != led_mode_id_)
return EventHandlerResult::OK;
return ::LEDControl.get_mode<TransientLEDMode>()
->onKeyswitchEvent(mapped_key, key_addr, key_state);
return ::LEDControl.get_mode<TransientLEDMode>()->onKeyEvent(event);
}
EventHandlerResult WavepoolEffect::TransientLEDMode::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
if (keyIsPressed(key_state)) {
surface_[page_][pgm_read_byte(rc2pos + key_addr.toInt())] = 0x7f;
EventHandlerResult WavepoolEffect::TransientLEDMode::onKeyEvent(KeyEvent &event) {
// It might be better to trigger on both toggle-on and toggle-off, but maybe
// just the former.
if (keyIsPressed(event.state)) {
surface_[page_][pgm_read_byte(rc2pos + event.addr.toInt())] = 0x7f;
frames_since_event_ = 0;
}

@ -34,7 +34,7 @@ class WavepoolEffect : public Plugin,
public:
WavepoolEffect(void) {}
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
EventHandlerResult onKeyEvent(KeyEvent &event);
// ms before idle animation starts after last keypress
static uint16_t idle_timeout;
@ -53,7 +53,7 @@ class WavepoolEffect : public Plugin,
//
explicit TransientLEDMode(const WavepoolEffect *parent);
EventHandlerResult onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state);
EventHandlerResult onKeyEvent(KeyEvent &event);
protected:

@ -29,7 +29,7 @@ TriColor::TriColor(cRGB base_color, cRGB mod_color, cRGB esc_color) {
void TriColor::TransientLEDMode::update(void) {
for (auto key_addr : KeyAddr::all()) {
Key k = Layer.lookup(key_addr);
Key k = Layer.lookupOnActiveLayer(key_addr);
// Special keys are always mod_color
if (k.getFlags() != 0) {

Loading…
Cancel
Save