Kaleidoscope Style Guide conformance

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

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-GhostInTheFirmware.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-GhostInTheFirmware.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-GhostInTheFirmware [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-GhostInTheFirmware
[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
Born out of the desire to demo LED effects on the keyboard without having to Born out of the desire to demo LED effects on the keyboard without having to
touch it by hand (which would obstruct the video), the `GhostInTheFirmware` touch it by hand (which would obstruct the video), the `GhostInTheFirmware`
@ -31,23 +31,24 @@ that.
#include <Kaleidoscope-GhostInTheFirmware.h> #include <Kaleidoscope-GhostInTheFirmware.h>
#include <Kaleidoscope-Macros.h> #include <Kaleidoscope-Macros.h>
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) {
if (macroIndex == 0 && key_toggled_on (keyState)) if (macro_index == 0 && key_toggled_on(key_state))
GhostInTheFirmware.activate(); GhostInTheFirmware.activate();
return MACRO_NONE; return MACRO_NONE;
} }
static const KaleidoscopePlugins::GhostInTheFirmware::GhostKey ghostKeys[] PROGMEM = { static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = {
{0, 0, 200, 50}, {0, 0, 200, 50},
{0, 0, 0} {0, 0, 0}
}; };
void setup() { void setup() {
Kaleidoscope.setup (KEYMAP_SIZE); USE_PLUGINS(&GhostInTheFirmware, &Macros);
GhostInTheFirmware.configure (ghostKeys); Kaleidoscope.setup ();
Kaleidoscope.use (&GhostInTheFirmware, &Macros, NULL);
GhostInTheFirmware.ghost_keys = ghost_keys;
} }
``` ```
@ -57,24 +58,27 @@ hence the macro.
## Plugin methods ## Plugin methods
The plugin provides the `GhostInTheFirmware` object, which has the following The plugin provides the `GhostInTheFirmware` object, which has the following
method: methods:
### `.activate()`
> Start playing back the sequence. Best called from a macro.
### `.configure(sequence)` ### `.ghost_keys`
> Set the sequence of keys to press. Each element is a quartett of `row`, > Set the sequence of keys to press, by assigning a sequence to this variable.
> `column`, a `pressTime`, and a `delay`. Each of these will be pressed in > Each element is a quartett of `row`, `column`, a `pressTime`, and a `delay`.
> different cycles, unlike macros which play back within a single cycle. > Each of these will be pressed in different cycles, unlike macros which play
> back within a single cycle.
> >
> The key at `row`, `column` will be held for `pressTime` milliseconds, and > The key at `row`, `column` will be held for `pressTime` milliseconds, and
> after an additional `delay` milliseconds, the plugin will move on to the next > after an additional `delay` milliseconds, the plugin will move on to the next
> entry in the sequence. > entry in the sequence.
> >
> Not strictly a method, it is a variable one can assign a new value to.
>
> The sequence *MUST* reside in `PROGMEM`. > The sequence *MUST* reside in `PROGMEM`.
### `.activate()`
> Start playing back the sequence. Best called from a macro.
## Further reading ## Further reading
Starting from the [example][plugin:example] is the recommended way of getting Starting from the [example][plugin:example] is the recommended way of getting

@ -19,13 +19,11 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-GhostInTheFirmware.h> #include <Kaleidoscope-GhostInTheFirmware.h>
#include <Kaleidoscope-LED-Stalker.h> #include <Kaleidoscope-LED-Stalker.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-Macros.h> #include <Kaleidoscope-Macros.h>
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (___, ___, ___, ___, ___, ___, M(0),
___, ___, ___, ___, ___, ___, M(0),
___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
@ -39,22 +37,21 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___, ___,
___, ___, ___, ___, ___, ___, ___, ___,
___ ___),
),
}; };
static Key eventDropper(Key mappedKey, byte row, byte col, uint8_t keyState) { static Key eventDropper(Key, byte, byte, uint8_t) {
return Key_NoKey; return Key_NoKey;
} }
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) {
if (macroIndex == 0 && key_toggled_on(keyState)) if (macro_index == 0 && key_toggled_on(key_state))
GhostInTheFirmware.activate(); GhostInTheFirmware.activate();
return MACRO_NONE; return MACRO_NONE;
} }
static const KaleidoscopePlugins::GhostInTheFirmware::GhostKey ghostKeys[] PROGMEM = { static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = {
{0, 6, 200, 50}, {0, 6, 200, 50},
{0, 5, 200, 50}, {0, 5, 200, 50},
{0, 4, 200, 50}, {0, 4, 200, 50},
@ -124,16 +121,14 @@ static const KaleidoscopePlugins::GhostInTheFirmware::GhostKey ghostKeys[] PROGM
}; };
void setup() { void setup() {
Serial.begin(9600); USE_PLUGINS(&GhostInTheFirmware, &StalkerEffect, &Macros);
Kaleidoscope.setup(KEYMAP_SIZE);
GhostInTheFirmware.configure(ghostKeys);
StalkerEffect.configure(STALKER(BlazingTrail, NULL)); StalkerEffect.configure(STALKER(BlazingTrail, NULL));
GhostInTheFirmware.ghost_keys = ghost_keys;
Kaleidoscope.use(&LEDControl, &GhostInTheFirmware, &StalkerEffect, &Macros,
NULL);
event_handler_hook_use(eventDropper); event_handler_hook_use(eventDropper);
Kaleidoscope.setup();
} }
void loop() { void loop() {

@ -19,70 +19,62 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-GhostInTheFirmware.h> #include <Kaleidoscope-GhostInTheFirmware.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
GhostInTheFirmware::GhostKey *GhostInTheFirmware::ghostKeys; const GhostInTheFirmware::GhostKey *GhostInTheFirmware::ghost_keys;
bool GhostInTheFirmware::isActive; bool GhostInTheFirmware::is_active_;
bool GhostInTheFirmware::isPressed; bool GhostInTheFirmware::is_pressed_;
uint16_t GhostInTheFirmware::currentPos; uint16_t GhostInTheFirmware::current_pos_;
uint32_t GhostInTheFirmware::startTime; uint32_t GhostInTheFirmware::start_time_;
uint16_t GhostInTheFirmware::pressTimeOut; uint16_t GhostInTheFirmware::press_timeout_;
uint16_t GhostInTheFirmware::delayTimeOut; uint16_t GhostInTheFirmware::delay_timeout_;
GhostInTheFirmware::GhostInTheFirmware(void) { GhostInTheFirmware::GhostInTheFirmware(void) {
} }
void void GhostInTheFirmware::begin(void) {
GhostInTheFirmware::begin(void) {
loop_hook_use(this->loopHook); loop_hook_use(this->loopHook);
} }
void void GhostInTheFirmware::activate(void) {
GhostInTheFirmware::activate(void) { is_active_ = true;
isActive = true;
} }
void void GhostInTheFirmware::loopHook(bool postClear) {
GhostInTheFirmware::configure(const GhostKey ghostKeys_[]) { if (postClear || !is_active_)
ghostKeys = (GhostKey *)ghostKeys_;
}
void
GhostInTheFirmware::loopHook(bool postClear) {
if (postClear || !isActive)
return; return;
if (pressTimeOut == 0) { if (press_timeout_ == 0) {
pressTimeOut = pgm_read_word(&(ghostKeys[currentPos].pressTime)); press_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].pressTime));
delayTimeOut = pgm_read_word(&(ghostKeys[currentPos].delay)); delay_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].delay));
if (pressTimeOut == 0) { if (press_timeout_ == 0) {
currentPos = 0; current_pos_ = 0;
isActive = false; is_active_ = false;
return; return;
} }
isPressed = true; is_pressed_ = true;
startTime = millis(); start_time_ = millis();
} else { } else {
if (isPressed && ((millis() - startTime) > pressTimeOut)) { if (is_pressed_ && ((millis() - start_time_) > press_timeout_)) {
isPressed = false; is_pressed_ = false;
startTime = millis(); start_time_ = millis();
byte row = pgm_read_byte(&(ghostKeys[currentPos].row)); byte row = pgm_read_byte(&(ghost_keys[current_pos_].row));
byte col = pgm_read_byte(&(ghostKeys[currentPos].col)); byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));
handle_keyswitch_event(Key_NoKey, row, col, WAS_PRESSED); handle_keyswitch_event(Key_NoKey, row, col, WAS_PRESSED);
} else if (isPressed) { } else if (is_pressed_) {
byte row = pgm_read_byte(&(ghostKeys[currentPos].row)); byte row = pgm_read_byte(&(ghost_keys[current_pos_].row));
byte col = pgm_read_byte(&(ghostKeys[currentPos].col)); byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));
handle_keyswitch_event(Key_NoKey, row, col, IS_PRESSED); handle_keyswitch_event(Key_NoKey, row, col, IS_PRESSED);
} else if ((millis() - startTime) > delayTimeOut) { } else if ((millis() - start_time_) > delay_timeout_) {
currentPos++; current_pos_++;
pressTimeOut = 0; press_timeout_ = 0;
} }
} }
} }
}; };
KaleidoscopePlugins::GhostInTheFirmware GhostInTheFirmware; kaleidoscope::GhostInTheFirmware GhostInTheFirmware;

@ -20,7 +20,7 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class GhostInTheFirmware : public KaleidoscopePlugin { class GhostInTheFirmware : public KaleidoscopePlugin {
public: public:
typedef struct { typedef struct {
@ -29,25 +29,23 @@ class GhostInTheFirmware : public KaleidoscopePlugin {
uint16_t pressTime; uint16_t pressTime;
uint16_t delay; uint16_t delay;
} GhostKey; } GhostKey;
static const GhostKey *ghost_keys;
GhostInTheFirmware(void); GhostInTheFirmware(void);
void begin(void) final; void begin(void) final;
static void configure(const GhostKey ghostKeys[]);
static void activate(void); static void activate(void);
private: private:
static GhostKey *ghostKeys; static bool is_active_;
static bool isActive; static bool is_pressed_;
static bool isPressed; static uint16_t current_pos_;
static uint16_t currentPos; static uint32_t start_time_;
static uint32_t startTime; static uint16_t press_timeout_;
static uint16_t pressTimeOut; static uint16_t delay_timeout_;
static uint16_t delayTimeOut;
static void loopHook(bool postClear); static void loopHook(bool postClear);
}; };
}
}; extern kaleidoscope::GhostInTheFirmware GhostInTheFirmware;
extern KaleidoscopePlugins::GhostInTheFirmware GhostInTheFirmware;

Loading…
Cancel
Save