Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 6 years ago
parent 649289319a
commit 592c094565

@ -1,6 +1,6 @@
# Kaleidoscope-TopsyTurvy
![status][st:stable] [![Build Status][travis:image]][travis:status]
![status][st:experimental] [![Build Status][travis:image]][travis:status]
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy
@ -26,9 +26,9 @@ effects to, and use the plugin:
// In the keymap:
TOPSY(1), TOPSY(2), TOPSY(3)
void setup () {
Kaleidoscope.use (&TopsyTurvy);
KALEIDOSCOPE_INIT_PLUGINS(TopsyTurvy);
void setup () {
Kaleidoscope.setup ();
}
```

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-TopsyTurvy -- Turn the effect of Shift upside down for certain keys
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -19,6 +19,7 @@
#include <Kaleidoscope.h>
#include <Kaleidoscope-TopsyTurvy.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
@ -38,10 +39,11 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip),
};
// *INDENT-ON*
void setup() {
Kaleidoscope.use(&TopsyTurvy);
KALEIDOSCOPE_INIT_PLUGINS(TopsyTurvy);
void setup() {
Kaleidoscope.setup();
}

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-TopsyTurvy -- Turn the effect of Shift upside down for certain keys
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,16 +26,9 @@ namespace kaleidoscope {
uint8_t TopsyTurvy::mod_state_;
uint8_t TopsyTurvy::last_pressed_position_;
TopsyTurvy::TopsyTurvy(void) {
}
void TopsyTurvy::begin(void) {
Kaleidoscope.useEventHandlerHook(eventHandlerHook);
}
Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult TopsyTurvy::onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
if (key_state & TOPSYTURVY)
return mapped_key;
return EventHandlerResult::OK;
if (mapped_key.raw == Key_LeftShift.raw)
bitWrite(mod_state_, 0, keyIsPressed(key_state));
@ -43,21 +36,22 @@ Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
bitWrite(mod_state_, 1, keyIsPressed(key_state));
if (!keyIsPressed(key_state) && !keyWasPressed(key_state))
return mapped_key;
return EventHandlerResult::OK;
if (mapped_key < ranges::TT_FIRST || mapped_key > ranges::TT_LAST)
return mapped_key;
return EventHandlerResult::OK;
if (keyToggledOn(key_state)) {
last_pressed_position_ = row * COLS + col;
} else {
if (last_pressed_position_ != row * COLS + col)
return Key_NoKey;
if (last_pressed_position_ != row * COLS + col) {
return EventHandlerResult::EVENT_CONSUMED;
}
}
Key new_key = {.raw = mapped_key.raw - ranges::TT_FIRST};
if (new_key.raw == Key_NoKey.raw)
return mapped_key;
return EventHandlerResult::OK;
// invert the shift state
@ -81,8 +75,23 @@ Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key
hid::pressRawKey(Key_RightShift);
}
return EventHandlerResult::EVENT_CONSUMED;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void TopsyTurvy::begin() {
Kaleidoscope.useEventHandlerHook(legacyEventHandler);
}
Key TopsyTurvy::legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state) {
EventHandlerResult r = ::TopsyTurvy.onKeyswitchEvent(mapped_key, row, col, key_state);
if (r == EventHandlerResult::OK)
return mapped_key;
return Key_NoKey;
}
#endif
}

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* Kaleidoscope-TopsyTurvy -- Turn the effect of Shift upside down for certain keys
* Copyright (C) 2017 Gergely Nagy
* Copyright (C) 2017, 2018 Gergely Nagy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,14 +27,19 @@ namespace kaleidoscope {
class TopsyTurvy: public KaleidoscopePlugin {
public:
TopsyTurvy(void);
TopsyTurvy(void) {}
EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state);
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static Key legacyEventHandler(Key mapped_key, byte row, byte col, uint8_t key_state);
#endif
void begin(void) final;
private:
static uint8_t mod_state_;
static uint8_t last_pressed_position_;
static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
};
}

Loading…
Cancel
Save