Kaleidoscope Style Guide conformance

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

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-GhostInTheFirmware.svg?branch=master
[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: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
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`
@ -31,23 +31,24 @@ that.
#include <Kaleidoscope-GhostInTheFirmware.h>
#include <Kaleidoscope-Macros.h>
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 0 && key_toggled_on (keyState))
GhostInTheFirmware.activate ();
const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) {
if (macro_index == 0 && key_toggled_on(key_state))
GhostInTheFirmware.activate();
return MACRO_NONE;
}
static const KaleidoscopePlugins::GhostInTheFirmware::GhostKey ghostKeys[] PROGMEM = {
static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = {
{0, 0, 200, 50},
{0, 0, 0}
};
void setup () {
Kaleidoscope.setup (KEYMAP_SIZE);
void setup() {
USE_PLUGINS(&GhostInTheFirmware, &Macros);
GhostInTheFirmware.configure (ghostKeys);
Kaleidoscope.use (&GhostInTheFirmware, &Macros, NULL);
Kaleidoscope.setup ();
GhostInTheFirmware.ghost_keys = ghost_keys;
}
```
@ -57,24 +58,27 @@ hence the macro.
## Plugin methods
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`,
> `column`, a `pressTime`, and a `delay`. Each of these will be pressed in
> different cycles, unlike macros which play back within a single cycle.
> Set the sequence of keys to press, by assigning a sequence to this variable.
> Each element is a quartett of `row`, `column`, a `pressTime`, and a `delay`.
> 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
> after an additional `delay` milliseconds, the plugin will move on to the next
> 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`.
### `.activate()`
> Start playing back the sequence. Best called from a macro.
## Further reading
Starting from the [example][plugin:example] is the recommended way of getting

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

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

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

Loading…
Cancel
Save