Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent c91db9c565
commit e5a8a77a4a

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-TopsyTurvy
[st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52 [st:stable]: https://img.shields.io/badge/stable-✔-black.svg?style=flat&colorA=44cc11&colorB=494e52
[st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52 [st:broken]: https://img.shields.io/badge/broken-X-black.svg?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&colorB=494e52 [st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52
`TopsyTurvy` is a plugin that inverts the behaviour of the `Shift` key for some `TopsyTurvy` is a plugin that inverts the behaviour of the `Shift` key for some
selected keys. That is, if configured so, it will input `!` when pressing the selected keys. That is, if configured so, it will input `!` when pressing the
@ -23,17 +23,18 @@ the provided `TopsyTurvy` object to use the dictionary:
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-TopsyTurvy.h> #include <Kaleidoscope-TopsyTurvy.h>
static const Key topsyTurvyList[] PROGMEM = { static const Key topsy_turvy_list[] PROGMEM = {
Key_1, Key_2, Key_3, Key_4, Key_5, Key_1, Key_2, Key_3, Key_4, Key_5,
Key_6, Key_7, Key_8, Key_9, Key_0, Key_6, Key_7, Key_8, Key_9, Key_0,
Key_NoKey Key_NoKey
}; };
void setup () { void setup () {
TopsyTurvy.configure (topsyTurvyList);
Kaleidoscope.setup ();
USE_PLUGINS (&TopsyTurvy); USE_PLUGINS (&TopsyTurvy);
Kaleidoscope.setup ();
TopsyTurvy.key_list = topsy_turvy_list;
} }
``` ```
@ -42,11 +43,12 @@ in `PROGMEM`.
## Plugin methods ## Plugin methods
The plugin provides the `TopsyTurvy` object, with the following methods: The plugin provides the `TopsyTurvy` object, with the following property:
### `.configure(list)` ### `.key_list`
> Tells `TopsyTurvy` to use the specified list of keys. > Set this property to the list of `Key`s `TopsyTurvy` should invert the `Shift`
> behaviour for.
## Further reading ## Further reading

@ -39,17 +39,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip), Key_skip),
}; };
static const Key topsyTurvyList[] PROGMEM = { static const Key topsy_turvy_list[] PROGMEM = {
Key_1, Key_2, Key_3, Key_4, Key_5, Key_1, Key_2, Key_3, Key_4, Key_5,
Key_6, Key_7, Key_8, Key_9, Key_0, Key_6, Key_7, Key_8, Key_9, Key_0,
Key_NoKey Key_NoKey
}; };
void setup() { void setup() {
TopsyTurvy.configure(topsyTurvyList); USE_PLUGINS(&TopsyTurvy);
Kaleidoscope.setup(); Kaleidoscope.setup();
USE_PLUGINS(&TopsyTurvy);
TopsyTurvy.key_list = topsy_turvy_list;
} }
void loop() { void loop() {

@ -20,76 +20,69 @@
#define TOPSYTURVY 0b01000000 #define TOPSYTURVY 0b01000000
namespace KaleidoscopePlugins { namespace kaleidoscope {
const Key *TopsyTurvy::topsyTurvyList = NULL; const Key *TopsyTurvy::key_list = NULL;
uint8_t TopsyTurvy::topsyTurvyModState; uint8_t TopsyTurvy::mod_state_;
TopsyTurvy::TopsyTurvy(void) { TopsyTurvy::TopsyTurvy(void) {
} }
void void TopsyTurvy::begin(void) {
TopsyTurvy::begin(void) { event_handler_hook_use(eventHandlerHook);
event_handler_hook_use(this->eventHandlerHook);
} }
void Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
TopsyTurvy::configure(const Key list[]) { if (key_state & TOPSYTURVY)
topsyTurvyList = (const Key *)list; return mapped_key;
}
Key
TopsyTurvy::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (keyState & TOPSYTURVY)
return mappedKey;
if (!topsyTurvyList) if (!key_list)
return mappedKey; return mapped_key;
if (mappedKey.raw == Key_LeftShift.raw) if (mapped_key.raw == Key_LeftShift.raw)
bitWrite(topsyTurvyModState, 0, key_is_pressed(keyState)); bitWrite(mod_state_, 0, key_is_pressed(key_state));
if (mappedKey.raw == Key_RightShift.raw) if (mapped_key.raw == Key_RightShift.raw)
bitWrite(topsyTurvyModState, 1, key_is_pressed(keyState)); bitWrite(mod_state_, 1, key_is_pressed(key_state));
if (!key_is_pressed(keyState) && !key_was_pressed(keyState)) if (!key_is_pressed(key_state) && !key_was_pressed(key_state))
return mappedKey; return mapped_key;
uint8_t idx = 0; uint8_t idx = 0;
Key newKey; Key newKey;
do { do {
newKey.raw = pgm_read_word(&(topsyTurvyList[idx].raw)); newKey.raw = pgm_read_word(&(key_list[idx].raw));
idx++; idx++;
} while (newKey.raw != mappedKey.raw && newKey.raw != Key_NoKey.raw); } while (newKey.raw != mapped_key.raw && newKey.raw != Key_NoKey.raw);
if (newKey.raw == Key_NoKey.raw) if (newKey.raw == Key_NoKey.raw)
return mappedKey; return mapped_key;
// invert the shift state // invert the shift state
if (!topsyTurvyModState) { if (!mod_state_) {
if (key_is_pressed(keyState)) if (key_is_pressed(key_state))
Keyboard.press(Key_LeftShift.keyCode); Keyboard.press(Key_LeftShift.keyCode);
handle_keyswitch_event(mappedKey, row, col, keyState | TOPSYTURVY); handle_keyswitch_event(mapped_key, row, col, key_state | TOPSYTURVY);
Keyboard.sendReport(); Keyboard.sendReport();
if (key_toggled_off(keyState)) if (key_toggled_off(key_state))
Keyboard.release(Key_LeftShift.keyCode); Keyboard.release(Key_LeftShift.keyCode);
} else { } else {
Keyboard.release(Key_LeftShift.keyCode); Keyboard.release(Key_LeftShift.keyCode);
Keyboard.release(Key_RightShift.keyCode); Keyboard.release(Key_RightShift.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
handle_keyswitch_event(mappedKey, row, col, keyState | TOPSYTURVY); handle_keyswitch_event(mapped_key, row, col, key_state | TOPSYTURVY);
Keyboard.sendReport(); Keyboard.sendReport();
if (bitRead(topsyTurvyModState, 0)) if (bitRead(mod_state_, 0))
Keyboard.press(Key_LeftShift.keyCode); Keyboard.press(Key_LeftShift.keyCode);
if (bitRead(topsyTurvyModState, 1)) if (bitRead(mod_state_, 1))
Keyboard.press(Key_RightShift.keyCode); Keyboard.press(Key_RightShift.keyCode);
} }
return Key_NoKey; return Key_NoKey;
} }
} // namespace KaleidoscopePlugins }
KaleidoscopePlugins::TopsyTurvy TopsyTurvy; kaleidoscope::TopsyTurvy TopsyTurvy;

@ -20,21 +20,21 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class TopsyTurvy: public KaleidoscopePlugin { class TopsyTurvy: public KaleidoscopePlugin {
public: public:
TopsyTurvy(void); TopsyTurvy(void);
void begin(void) final; void begin(void) final;
static void configure(const Key topsyTurvyList[]); static const Key *key_list;
private: private:
static const Key *topsyTurvyList; static uint8_t mod_state_;
static uint8_t topsyTurvyModState;
static Key eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState); static Key eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state);
}; };
} // namespace KaleidoscopePlugins
extern KaleidoscopePlugins::TopsyTurvy TopsyTurvy; }
extern kaleidoscope::TopsyTurvy TopsyTurvy;

Loading…
Cancel
Save