Updated to work with the new plugin API

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 7 years ago
parent 75663c4896
commit f3887ec283

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

@ -1,6 +1,6 @@
/* -*- mode: c++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -21,6 +21,7 @@
#include <Kaleidoscope-LED-Stalker.h>
#include <Kaleidoscope-Macros.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(___, ___, ___, ___, ___, ___, M(0),
@ -39,10 +40,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
___, ___, ___, ___,
___),
};
// *INDENT-ON*
static Key eventDropper(Key, byte, byte, uint8_t) {
return Key_NoKey;
class EventDropper_ : public kaleidoscope::Plugin {
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) {
if (macro_index == 0 && keyToggledOn(key_state))
@ -120,15 +129,16 @@ static const kaleidoscope::GhostInTheFirmware::GhostKey ghost_keys[] PROGMEM = {
{0, 0, 0, 0}
};
KALEIDOSCOPE_INIT_PLUGINS(GhostInTheFirmware,
StalkerEffect,
Macros,
EventDropper);
void setup() {
Kaleidoscope.use(&GhostInTheFirmware, &StalkerEffect, &Macros);
Kaleidoscope.setup();
StalkerEffect.variant = STALKER(BlazingTrail);
GhostInTheFirmware.ghost_keys = ghost_keys;
Kaleidoscope.useEventHandlerHook(eventDropper);
Kaleidoscope.setup();
}
void loop() {

@ -28,20 +28,13 @@ uint32_t GhostInTheFirmware::start_time_;
uint16_t GhostInTheFirmware::press_timeout_;
uint16_t GhostInTheFirmware::delay_timeout_;
GhostInTheFirmware::GhostInTheFirmware(void) {
}
void GhostInTheFirmware::begin(void) {
Kaleidoscope.useLoopHook(this->loopHook);
}
void GhostInTheFirmware::activate(void) {
is_active_ = true;
}
void GhostInTheFirmware::loopHook(bool is_post_clear) {
if (is_post_clear || !is_active_)
return;
EventHandlerResult GhostInTheFirmware::beforeReportingState() {
if (!is_active_)
return EventHandlerResult::OK;
if (press_timeout_ == 0) {
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) {
current_pos_ = 0;
is_active_ = false;
return;
return EventHandlerResult::OK;
}
is_pressed_ = true;
start_time_ = millis();
@ -73,7 +66,23 @@ void GhostInTheFirmware::loopHook(bool is_post_clear) {
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++ -*-
* 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
* it under the terms of the GNU General Public License as published by
@ -21,7 +21,7 @@
#include <Kaleidoscope.h>
namespace kaleidoscope {
class GhostInTheFirmware : public KaleidoscopePlugin {
class GhostInTheFirmware : public kaleidoscope::Plugin {
public:
typedef struct {
byte row;
@ -31,11 +31,18 @@ class GhostInTheFirmware : public KaleidoscopePlugin {
} GhostKey;
static const GhostKey *ghost_keys;
GhostInTheFirmware(void);
GhostInTheFirmware(void) {}
void begin(void) final;
static void activate(void);
EventHandlerResult beforeReportingState();
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private:
static bool is_active_;
static bool is_pressed_;

Loading…
Cancel
Save