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

Updated to use the new plugin APIs
pull/365/head
Gergely Nagy 7 years ago committed by GitHub
commit 58376f486d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -41,11 +41,10 @@ void magicComboActions(uint8_t combo_index, uint32_t left_hand, uint32_t right_h
} }
} }
KALEIDOSCOPE_INIT_PLUGINS(MagicCombo);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use(&MagicCombo);
Kaleidoscope.setup(); Kaleidoscope.setup();
MagicCombo.magic_combos = magic_combos; MagicCombo.magic_combos = magic_combos;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-MagicCombo -- Magic combo framework * Kaleidoscope-MagicCombo -- Magic combo framework
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 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
@ -35,7 +35,7 @@ static const kaleidoscope::MagicCombo::combo_t magic_combos[] PROGMEM = {
{0, 0} {0, 0}
}; };
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (
@ -49,18 +49,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey), Key_NoKey),
}; };
// *INDENT-ON*
KALEIDOSCOPE_INIT_PLUGINS(MagicCombo);
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.use(&MagicCombo);
Kaleidoscope.setup(); Kaleidoscope.setup();
MagicCombo.magic_combos = magic_combos; MagicCombo.magic_combos = magic_combos;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-MagicCombo -- Magic combo framework * Kaleidoscope-MagicCombo -- Magic combo framework
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 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
@ -34,16 +34,9 @@ const MagicCombo::combo_t *MagicCombo::magic_combos;
uint16_t MagicCombo::min_interval = 500; uint16_t MagicCombo::min_interval = 500;
uint32_t MagicCombo::end_time_; uint32_t MagicCombo::end_time_;
MagicCombo::MagicCombo(void) { EventHandlerResult MagicCombo::beforeReportingState() {
} if (!magic_combos)
return EventHandlerResult::OK;
void MagicCombo::begin(void) {
Kaleidoscope.useLoopHook(loopHook);
}
void MagicCombo::loopHook(bool is_post_clear) {
if (!magic_combos || is_post_clear)
return;
for (byte i = 0;; i++) { for (byte i = 0;; i++) {
combo_t combo; combo_t combo;
@ -63,8 +56,23 @@ void MagicCombo::loopHook(bool is_post_clear) {
break; break;
} }
} }
return EventHandlerResult::OK;
} }
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void MagicCombo::begin() {
Kaleidoscope.useLoopHook(legacyLoopHook);
}
void MagicCombo::legacyLoopHook(bool is_post_clear) {
if (is_post_clear)
return;
::MagicCombo.beforeReportingState();
}
#endif
}; };
__attribute__((weak)) void magicComboActions(uint8_t comboIndex, uint32_t left_hand, uint32_t right_hand) { __attribute__((weak)) void magicComboActions(uint8_t comboIndex, uint32_t left_hand, uint32_t right_hand) {

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-MagicCombo -- Magic combo framework * Kaleidoscope-MagicCombo -- Magic combo framework
* Copyright (C) 2016, 2017 Gergely Nagy * Copyright (C) 2016, 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
@ -22,23 +22,27 @@
namespace kaleidoscope { namespace kaleidoscope {
class MagicCombo : public KaleidoscopePlugin { class MagicCombo : public kaleidoscope::Plugin {
public: public:
typedef struct { typedef struct {
uint32_t left_hand, right_hand; uint32_t left_hand, right_hand;
} combo_t; } combo_t;
MagicCombo(void); MagicCombo(void) {}
void begin(void) final;
static const combo_t *magic_combos; static const combo_t *magic_combos;
static uint16_t min_interval; static uint16_t min_interval;
EventHandlerResult beforeReportingState();
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private: private:
static uint32_t end_time_; static uint32_t end_time_;
static void loopHook(bool is_post_clear);
}; };
} }

Loading…
Cancel
Save