Kaleidoscope Style Guide conformance

...and an update to use the new Ranges APIs.

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

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-Syster.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-Syster
[st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52
[st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&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.svg?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52
Syster is a way to input symbols in a different way: instead of macros, Leader
sequences or the like, we trigger the special input mode, and enter the symbol's
@ -28,18 +28,18 @@ will handle the symbol actions:
#include <Kaleidoscope-Syster.h>
#include <Kaleidoscope-Unicode.h>
void systerAction (KaleidoscopePlugins::Syster::action_t action, const char *symbol) {
void systerAction(kaleidoscope::Syster::action_t action, const char *symbol) {
switch (action) {
case KaleidoscopePlugins::Syster::StartAction:
case kaleidoscope::Syster::StartAction:
Unicode.type (0x2328);
break;
case KaleidoscopePlugins::Syster::EndAction:
case kaleidoscope::Syster::EndAction:
handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport ();
handle_keyswitch_event (Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport ();
break;
case KaleidoscopePlugins::Syster::SymbolAction:
case kaleidoscope::Syster::SymbolAction:
Serial.print ("systerAction: symbol=");
Serial.println (symbol);
if (strcmp (symbol, "coffee") == 0) {
@ -52,8 +52,9 @@ void systerAction (KaleidoscopePlugins::Syster::action_t action, const char *sym
void setup() {
Serial.begin(9600);
Kaleidoscope.setup (KEYMAP_SIZE);
Kaleidoscope.use (&Unicode, &Syster, NULL);
USE_PLUGINS(&Unicode, &Syster);
Kaleidoscope.setup ();
}
```
@ -70,20 +71,18 @@ methods outside of the object, however, that can be overridden:
> Called whenever an action needs to be taken, which can happen in three cases:
> First, when the `Syster` key is pressed, and the alternate processing starts.
> In this case, `action` will be set to
> `KaleidoscopePlugins::Syster::StartAction`, and `symbol` will be `NULL`. This
> function can be used to do some setup to make it more obvious that the Syster
> input mode is active, such as sending a Unicode symbol to the host, or
> lighting up LEDs, or anything else we'd like.
> In this case, `action` will be set to `kaleidoscope::Syster::StartAction`, and
> `symbol` will be `NULL`. This function can be used to do some setup to make it
> more obvious that the Syster input mode is active, such as sending a Unicode
> symbol to the host, or lighting up LEDs, or anything else we'd like.
>
> Second, when the sequence is finished with a `Space`. In this case, `action`
> will be set to `KaleidoscopePlugins::Syster::EndAction`, and `symbol` will be
> `NULL`. This can be used to undo anything that the start action did, if need
> be.
> will be set to `kaleidoscope::Syster::EndAction`, and `symbol` will be `NULL`.
> This can be used to undo anything that the start action did, if need be.
>
> Third, when the action for the symbol should be made. In this case, `action`
> is set to `KaleidoscopePlugins::Syster::SymbolAction`, and `symbol` will be a
> C string. It is up to us, what we do with this information, how we handle it.
> is set to `kaleidoscope::Syster::SymbolAction`, and `symbol` will be a C
> string. It is up to us, what we do with this information, how we handle it.
### `keyToChar(key)`

@ -39,22 +39,21 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
SYSTER
),
SYSTER),
};
void systerAction(KaleidoscopePlugins::Syster::action_t action, const char *symbol) {
void systerAction(kaleidoscope::Syster::action_t action, const char *symbol) {
switch (action) {
case KaleidoscopePlugins::Syster::StartAction:
case kaleidoscope::Syster::StartAction:
Unicode.type(0x2328);
break;
case KaleidoscopePlugins::Syster::EndAction:
case kaleidoscope::Syster::EndAction:
handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport();
handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
Keyboard.sendReport();
break;
case KaleidoscopePlugins::Syster::SymbolAction:
case kaleidoscope::Syster::SymbolAction:
Serial.print("systerAction: symbol=");
Serial.println(symbol);
if (strcmp(symbol, "coffee") == 0) {
@ -65,8 +64,9 @@ void systerAction(KaleidoscopePlugins::Syster::action_t action, const char *symb
}
void setup() {
Kaleidoscope.setup(KEYMAP_SIZE);
Kaleidoscope.use(&Unicode, &Syster, NULL);
USE_PLUGINS(&Unicode, &Syster);
Kaleidoscope.setup();
}
void loop() {

@ -18,61 +18,58 @@
#include <Kaleidoscope-Syster.h>
using namespace KaleidoscopePlugins::Ranges;
#undef SYSTER
namespace kaleidoscope {
namespace KaleidoscopePlugins {
// --- state ---
char Syster::symbol[SYSTER_MAX_SYMBOL_LENGTH + 1];
uint8_t Syster::symbolPos;
bool Syster::isActive;
char Syster::symbol_[SYSTER_MAX_SYMBOL_LENGTH + 1];
uint8_t Syster::symbol_pos_;
bool Syster::is_active_;
// --- helpers ---
#define isSyster(k) (k == SYSTER)
#define isSyster(k) (k == kaleidoscope::ranges::SYSTER)
// --- api ---
Syster::Syster(void) {
}
void
Syster::begin(void) {
event_handler_hook_use(this->eventHandlerHook);
void Syster::begin(void) {
event_handler_hook_use(eventHandlerHook);
}
void
Syster::reset(void) {
symbolPos = 0;
symbol[0] = 0;
isActive = false;
void Syster::reset(void) {
symbol_pos_ = 0;
symbol_[0] = 0;
is_active_ = false;
}
// --- hooks ---
Key
Syster::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
if (!isActive) {
if (!isSyster(mappedKey))
return mappedKey;
if (key_toggled_on(keyState)) {
isActive = true;
Key Syster::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
if (!is_active_) {
if (!isSyster(mapped_key))
return mapped_key;
if (key_toggled_on(key_state)) {
is_active_ = true;
systerAction(StartAction, NULL);
}
return Key_NoKey;
}
if (keyState & INJECTED)
return mappedKey;
if (key_state & INJECTED)
return mapped_key;
if (isSyster(mappedKey))
if (isSyster(mapped_key))
return Key_NoKey;
if (mappedKey == Key_Backspace && symbolPos == 0)
if (mapped_key == Key_Backspace && symbol_pos_ == 0)
return Key_NoKey;
if (key_toggled_off(keyState)) {
if (mappedKey == Key_Spacebar) {
for (uint8_t i = 0; i <= symbolPos; i++) {
if (key_toggled_off(key_state)) {
if (mapped_key == Key_Spacebar) {
for (uint8_t i = 0; i <= symbol_pos_; i++) {
handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, IS_PRESSED | INJECTED);
Keyboard.sendReport();
handle_keyswitch_event(Key_Backspace, UNKNOWN_KEYSWITCH_LOCATION, WAS_PRESSED | INJECTED);
@ -81,32 +78,31 @@ Syster::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
systerAction(EndAction, NULL);
symbol[symbolPos] = 0;
systerAction(SymbolAction, symbol);
symbol_[symbol_pos_] = 0;
systerAction(SymbolAction, symbol_);
reset();
return Key_NoKey;
}
}
if (key_toggled_on(keyState)) {
if (mappedKey == Key_Backspace) {
if (symbolPos > 0)
symbolPos--;
if (key_toggled_on(key_state)) {
if (mapped_key == Key_Backspace) {
if (symbol_pos_ > 0)
symbol_pos_--;
} else {
const char c = keyToChar(mappedKey);
const char c = keyToChar(mapped_key);
if (c)
symbol[symbolPos++] = c;
symbol_[symbol_pos_++] = c;
}
}
return mappedKey;
return mapped_key;
}
}
};
__attribute__((weak))
const char
keyToChar(Key key) {
__attribute__((weak)) const char keyToChar(Key key) {
if (key.flags != 0)
return 0;
@ -120,9 +116,7 @@ keyToChar(Key key) {
return 0;
}
__attribute__((weak))
void
systerAction(KaleidoscopePlugins::Syster::action_t action, const char *symbol) {
__attribute__((weak)) void systerAction(kaleidoscope::Syster::action_t action, const char *symbol) {
}
KaleidoscopePlugins::Syster Syster;
kaleidoscope::Syster Syster;

@ -23,9 +23,10 @@
#define SYSTER_MAX_SYMBOL_LENGTH 32
#define SYSTER (Key){ .raw = KaleidoscopePlugins::Ranges::SYSTER }
#define SYSTER ((Key) { .raw = kaleidoscope::ranges::SYSTER })
namespace kaleidoscope {
namespace KaleidoscopePlugins {
class Syster : public KaleidoscopePlugin {
public:
typedef enum {
@ -40,15 +41,15 @@ class Syster : public KaleidoscopePlugin {
static void reset(void);
private:
static char symbol[SYSTER_MAX_SYMBOL_LENGTH + 1];
static uint8_t symbolPos;
static bool isActive;
static char symbol_[SYSTER_MAX_SYMBOL_LENGTH + 1];
static uint8_t symbol_pos_;
static bool is_active_;
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);
};
};
const char keyToChar(Key key);
void systerAction(KaleidoscopePlugins::Syster::action_t action, const char *symbol);
void systerAction(kaleidoscope::Syster::action_t action, const char *symbol);
extern KaleidoscopePlugins::Syster Syster;
extern kaleidoscope::Syster Syster;

Loading…
Cancel
Save