Merge pull request #2 from keyboardio/f/plugin-v2

Updated to work with the new plugin API
pull/389/head
Gergely Nagy 6 years ago committed by GitHub
commit 8d8419ee51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -43,9 +43,10 @@ static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = {
{0, 0, 0} {0, 0, 0}
}; };
void setup() { KALEIDOSCOPE_INIT_PLUGINS(GhostInTheFirmware,
Kaleidoscope.use(&GhostInTheFirmware, &Macros); Macros);
void setup() {
Kaleidoscope.setup (); Kaleidoscope.setup ();
GhostInTheFirmware.ghost_keys = ghost_keys; GhostInTheFirmware.ghost_keys = ghost_keys;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-GhostInTheFirmware -- Let the keyboard write for you! * Kaleidoscope-GhostInTheFirmware -- Let the keyboard write for you!
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,6 +21,7 @@
#include <Kaleidoscope-LED-Stalker.h> #include <Kaleidoscope-LED-Stalker.h>
#include <Kaleidoscope-Macros.h> #include <Kaleidoscope-Macros.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
(___, ___, ___, ___, ___, ___, M(0), (___, ___, ___, ___, ___, ___, M(0),
@ -39,10 +40,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
___, ___, ___, ___, ___, ___, ___, ___,
___), ___),
}; };
// *INDENT-ON*
static Key eventDropper(Key, byte, byte, uint8_t) { class EventDropper_ : public kaleidoscope::Plugin {
return Key_NoKey; public:
} EventDropper_() {}
kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mapped_key, byte row, byte col, uint8_t key_state) {
return kaleidoscope::EventHandlerResult::EVENT_CONSUMED;
}
};
static EventDropper_ EventDropper;
const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) { const macro_t *macroAction(uint8_t macro_index, uint8_t key_state) {
if (macro_index == 0 && keyToggledOn(key_state)) if (macro_index == 0 && keyToggledOn(key_state))
@ -120,15 +129,16 @@ static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = {
{0, 0, 0, 0} {0, 0, 0, 0}
}; };
KALEIDOSCOPE_INIT_PLUGINS(GhostInTheFirmware,
StalkerEffect,
Macros,
EventDropper);
void setup() { void setup() {
Kaleidoscope.use(&GhostInTheFirmware, &StalkerEffect, &Macros); Kaleidoscope.setup();
StalkerEffect.variant = STALKER(BlazingTrail); StalkerEffect.variant = STALKER(BlazingTrail);
GhostInTheFirmware.ghost_keys = ghost_keys; GhostInTheFirmware.ghost_keys = ghost_keys;
Kaleidoscope.useEventHandlerHook(eventDropper);
Kaleidoscope.setup();
} }
void loop() { void loop() {

@ -28,20 +28,13 @@ uint32_t GhostInTheFirmware::start_time_;
uint16_t GhostInTheFirmware::press_timeout_; uint16_t GhostInTheFirmware::press_timeout_;
uint16_t GhostInTheFirmware::delay_timeout_; uint16_t GhostInTheFirmware::delay_timeout_;
GhostInTheFirmware::GhostInTheFirmware(void) {
}
void GhostInTheFirmware::begin(void) {
Kaleidoscope.useLoopHook(this->loopHook);
}
void GhostInTheFirmware::activate(void) { void GhostInTheFirmware::activate(void) {
is_active_ = true; is_active_ = true;
} }
void GhostInTheFirmware::loopHook(bool is_post_clear) { EventHandlerResult GhostInTheFirmware::beforeReportingState() {
if (is_post_clear || !is_active_) if (!is_active_)
return; return EventHandlerResult::OK;
if (press_timeout_ == 0) { if (press_timeout_ == 0) {
press_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].pressTime)); press_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].pressTime));
@ -50,7 +43,7 @@ void GhostInTheFirmware::loopHook(bool is_post_clear) {
if (press_timeout_ == 0) { if (press_timeout_ == 0) {
current_pos_ = 0; current_pos_ = 0;
is_active_ = false; is_active_ = false;
return; return EventHandlerResult::OK;
} }
is_pressed_ = true; is_pressed_ = true;
start_time_ = millis(); start_time_ = millis();
@ -73,7 +66,23 @@ void GhostInTheFirmware::loopHook(bool is_post_clear) {
press_timeout_ = 0; press_timeout_ = 0;
} }
} }
return EventHandlerResult::OK;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void GhostInTheFirmware::begin() {
Kaleidoscope.useLoopHook(legacyLoopHook);
}
void GhostInTheFirmware::legacyLoopHook(bool is_post_clear) {
if (is_post_clear)
return;
::GhostInTheFirmware.beforeReportingState();
} }
#endif
}; };

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-GhostInTheFirmware -- Let the keyboard write for you! * Kaleidoscope-GhostInTheFirmware -- Let the keyboard write for you!
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -21,7 +21,7 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace kaleidoscope { namespace kaleidoscope {
class GhostInTheFirmware : public KaleidoscopePlugin { class GhostInTheFirmware : public kaleidoscope::Plugin {
public: public:
typedef struct { typedef struct {
byte row; byte row;
@ -31,11 +31,18 @@ class GhostInTheFirmware : public KaleidoscopePlugin {
} GhostKey; } GhostKey;
static const GhostKey *ghost_keys; static const GhostKey *ghost_keys;
GhostInTheFirmware(void); GhostInTheFirmware(void) {}
void begin(void) final;
static void activate(void); static void activate(void);
EventHandlerResult beforeReportingState();
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private: private:
static bool is_active_; static bool is_active_;
static bool is_pressed_; static bool is_pressed_;

Loading…
Cancel
Save