Kaleidoscope Style Guide conformance

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

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-SpaceCadet.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-SpaceCadet.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-SpaceCadet [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-SpaceCadet
[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
[Space Cadet][space-cadet] Shift is a way to make it more convenient to input [Space Cadet][space-cadet] Shift is a way to make it more convenient to input
parens - those `(` and `)` things -, symbols that a lot of programming languages parens - those `(` and `)` things -, symbols that a lot of programming languages
@ -37,43 +37,38 @@ enabling the plugin:
#include <Kaleidoscope-SpaceCadet.h> #include <Kaleidoscope-SpaceCadet.h>
void setup() { void setup() {
Kaleidoscope.setup ();
USE_PLUGINS(&SpaceCadetShift); USE_PLUGINS(&SpaceCadetShift);
Kaleidoscope.setup();
} }
``` ```
This assumes a US QWERTY layout on the host computer, and will use the `9` and This assumes a US QWERTY layout on the host computer, and will use the `9` and
`0` keys for the left and right parens, respectively. To change these keys, use `0` keys for the left and right parens, respectively. To change these keys, use
the [`.configure()`](#configureleft-right) method outlined below. the `.opening_paren` and `.closing_paren` properties outlined below.
## Plugin methods ## Plugin methods
The plugin has a number of methods available on the `SpaceCadetShift` object: The plugin provides the `SpaceCadetShift` object, with the following methods and
properties:
### `.configure(left, right)` ### `.opening_paren`
> Used to change the configuration of the plugin, namely, the keys used for the > Set this property to the key that - when shifted - will result in an opening paren.
> left and right parens. These keys will be pressed with `Shift` held, and
> should result in the opening and closing parens.
> >
> As an example, assuming a Hungarian QWERTZ layout where the parens are not on > Defaults to `Key_9`.
> `9` and `0`, we can use the following little snippet in the `setup` method of
> our Sketch:
```c++ ### `.closing_paren`
void setup () {
SpaceCadetShift.configure(Key_8, Key_9);
Kaleidoscope.setup ();
}
```
### `.timeOut`
> The number of milliseconds to wait before considering a held key in isolation > Set this property to the key that - when shifted - will result in a closing paren.
> as its secondary role. That is, we'd have to hold a `Shift` key this long, by
> itself, to trigger the `Shift` role in itself.
> >
> Not strictly a method, it is a variable one can assign a new value to. > Defaults to `Key_0`.
### `.time_out`
> Set this property to the number of milliseconds to wait before considering a
> held key in isolation as its secondary role. That is, we'd have to hold a
> `Shift` key this long, by itself, to trigger the `Shift` role in itself.
> >
> Defaults to 1000. > Defaults to 1000.

@ -40,8 +40,9 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
}; };
void setup() { void setup() {
Kaleidoscope.setup();
USE_PLUGINS(&SpaceCadetShift); USE_PLUGINS(&SpaceCadetShift);
Kaleidoscope.setup();
} }
void loop() { void loop() {

@ -18,89 +18,79 @@
#include <Kaleidoscope-SpaceCadet.h> #include <Kaleidoscope-SpaceCadet.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
uint8_t SpaceCadetShift::parenNeeded; uint8_t SpaceCadetShift::paren_needed_;
uint32_t SpaceCadetShift::startTime; uint32_t SpaceCadetShift::start_time_;
uint16_t SpaceCadetShift::timeOut = 1000; uint16_t SpaceCadetShift::time_out = 1000;
Key SpaceCadetShift::leftParen, SpaceCadetShift::rightParen; Key SpaceCadetShift::opening_paren = Key_9, SpaceCadetShift::closing_paren = Key_0;
SpaceCadetShift::SpaceCadetShift() { SpaceCadetShift::SpaceCadetShift() {
leftParen.raw = Key_9.raw;
rightParen.raw = Key_0.raw;
} }
void void SpaceCadetShift::begin() {
SpaceCadetShift::begin() { event_handler_hook_use(eventHandlerHook);
event_handler_hook_use(this->eventHandlerHook);
} }
void Key SpaceCadetShift::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
SpaceCadetShift::configure(Key left, Key right) {
leftParen = left;
rightParen = right;
}
Key
SpaceCadetShift::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
// If nothing happened, bail out fast. // If nothing happened, bail out fast.
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;
} }
// If a key has been just toggled on... // If a key has been just toggled on...
if (key_toggled_on(keyState)) { if (key_toggled_on(key_state)) {
if (mappedKey.raw == Key_LeftShift.raw) { // if it is LShift, remember it if (mapped_key.raw == Key_LeftShift.raw) { // if it is LShift, remember it
bitWrite(parenNeeded, 0, 1); bitWrite(paren_needed_, 0, 1);
startTime = millis(); start_time_ = millis();
} else if (mappedKey.raw == Key_RightShift.raw) { // if it is RShift, remember it } else if (mapped_key.raw == Key_RightShift.raw) { // if it is RShift, remember it
bitWrite(parenNeeded, 1, 1); bitWrite(paren_needed_, 1, 1);
startTime = millis(); start_time_ = millis();
} else { // if it is something else, we do not need a paren at the end. } else { // if it is something else, we do not need a paren at the end.
parenNeeded = 0; paren_needed_ = 0;
startTime = 0; start_time_ = 0;
} }
// this is all we need to do on keypress, let the next handler do its thing too. // this is all we need to do on keypress, let the next handler do its thing too.
return mappedKey; return mapped_key;
} }
// if the state is empty, that means that either the shifts weren't pressed, // if the state is empty, that means that either the shifts weren't pressed,
// or we used another key in the interim. in both cases, nothing special to do. // or we used another key in the interim. in both cases, nothing special to do.
if (!parenNeeded) if (!paren_needed_)
return mappedKey; return mapped_key;
// if we timed out, that means we need to keep pressing shift, but won't // if we timed out, that means we need to keep pressing shift, but won't
// need the parens in the end. // need the parens in the end.
if ((millis() - startTime) >= timeOut) { if ((millis() - start_time_) >= time_out) {
parenNeeded = 0; paren_needed_ = 0;
return mappedKey; return mapped_key;
} }
// if we have a state, but the key in question is not either of the shifts, // if we have a state, but the key in question is not either of the shifts,
// return. This can happen when another key is released, and that should not // return. This can happen when another key is released, and that should not
// interrupt us. // interrupt us.
if (mappedKey.raw != Key_LeftShift.raw && if (mapped_key.raw != Key_LeftShift.raw &&
mappedKey.raw != Key_RightShift.raw) mapped_key.raw != Key_RightShift.raw)
return mappedKey; return mapped_key;
// if a key toggled off (and that must be one of the shifts at this point), // if a key toggled off (and that must be one of the shifts at this point),
// send the parens too (if we were interrupted, we bailed out earlier). // send the parens too (if we were interrupted, we bailed out earlier).
if (key_toggled_off(keyState)) { if (key_toggled_off(key_state)) {
Key paren = leftParen; Key paren = opening_paren;
if (bitRead(parenNeeded, 1)) if (bitRead(paren_needed_, 1))
paren = rightParen; paren = closing_paren;
handle_keyswitch_event(mappedKey, row, col, IS_PRESSED | INJECTED); handle_keyswitch_event(mapped_key, row, col, IS_PRESSED | INJECTED);
handle_keyswitch_event(paren, row, col, IS_PRESSED | INJECTED); handle_keyswitch_event(paren, row, col, IS_PRESSED | INJECTED);
Keyboard.sendReport(); Keyboard.sendReport();
parenNeeded = 0; paren_needed_ = 0;
} }
return mappedKey; return mapped_key;
} }
}; }
KaleidoscopePlugins::SpaceCadetShift SpaceCadetShift; kaleidoscope::SpaceCadetShift SpaceCadetShift;

@ -20,23 +20,23 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class SpaceCadetShift : public KaleidoscopePlugin { class SpaceCadetShift : public KaleidoscopePlugin {
public: public:
SpaceCadetShift(void); SpaceCadetShift(void);
void begin(void) final; void begin(void) final;
static void configure(Key left, Key right); static uint16_t time_out;
static uint16_t timeOut; static Key opening_paren, closing_paren;
private: private:
static uint8_t parenNeeded; static uint8_t paren_needed_;
static uint32_t startTime; static uint32_t start_time_;
static Key leftParen, rightParen;
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);
}; };
}; };
extern KaleidoscopePlugins::SpaceCadetShift SpaceCadetShift; extern kaleidoscope::SpaceCadetShift SpaceCadetShift;

Loading…
Cancel
Save