diff --git a/README.md b/README.md index 52b82866..ef1cca88 100644 --- a/README.md +++ b/README.md @@ -22,10 +22,11 @@ configuration is necessary, unless one wants to perform custom actions. #include #include +KALEIDOSCOPE_INIT_PLUGINS(HostPowerManagement); + void setup () { Kaleidoscope.setup (); - Kaleidoscope.use(&HostPowerManagement); HostPowerManagement.enableWakeup(); } ``` diff --git a/examples/HostPowerManagement/HostPowerManagement.ino b/examples/HostPowerManagement/HostPowerManagement.ino index 0c498931..77b159ab 100644 --- a/examples/HostPowerManagement/HostPowerManagement.ino +++ b/examples/HostPowerManagement/HostPowerManagement.ino @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-HostPowerManagement -- Host power management support plugin. - * 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 @@ -20,6 +20,7 @@ #include #include +// *INDENT-OFF* const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED ( @@ -33,14 +34,14 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { 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_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_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_NoKey ), - }; +// *INDENT-ON* void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) { switch (event) { @@ -58,11 +59,12 @@ void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event ev } } +KALEIDOSCOPE_INIT_PLUGINS(LEDControl, + HostPowerManagement); + void setup() { Kaleidoscope.setup(); - Kaleidoscope.use(&HostPowerManagement); - HostPowerManagement.enableWakeup(); } diff --git a/src/Kaleidoscope/HostPowerManagement.cpp b/src/Kaleidoscope/HostPowerManagement.cpp index d91ddbf9..1a8fd422 100644 --- a/src/Kaleidoscope/HostPowerManagement.cpp +++ b/src/Kaleidoscope/HostPowerManagement.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-HostPowerManagement -- Host power management support plugin. - * 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 @@ -29,14 +29,7 @@ namespace kaleidoscope { bool HostPowerManagement::was_suspended_ = false; bool HostPowerManagement::initial_suspend_ = true; -void HostPowerManagement::begin(void) { - Kaleidoscope.useLoopHook(loopHook); -} - -void HostPowerManagement::loopHook(bool post_clear) { - if (post_clear) - return; - +EventHandlerResult HostPowerManagement::beforeEachCycle() { if ((_usbSuspendState & (1 << SUSPI))) { if (!initial_suspend_) { if (!was_suspended_) { @@ -54,7 +47,23 @@ void HostPowerManagement::loopHook(bool post_clear) { hostPowerManagementEventHandler(Resume); } } + + return EventHandlerResult::OK; +} + +// Legacy V1 API +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API +void HostPowerManagement::begin() { + Kaleidoscope.useLoopHook(legacyLoopHook); +} + +void HostPowerManagement::legacyLoopHook(bool is_post_clear) { + if (is_post_clear) + return; + + ::HostPowerManagement.beforeEachCycle(); } +#endif } diff --git a/src/Kaleidoscope/HostPowerManagement.h b/src/Kaleidoscope/HostPowerManagement.h index 79e321f1..59d71a2d 100644 --- a/src/Kaleidoscope/HostPowerManagement.h +++ b/src/Kaleidoscope/HostPowerManagement.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-HostPowerManagement -- Host power management support plugin. - * 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 @@ -22,7 +22,7 @@ #include "WakeupKeyboard.h" namespace kaleidoscope { -class HostPowerManagement : public KaleidoscopePlugin { +class HostPowerManagement : public kaleidoscope::Plugin { public: typedef enum { Suspend, @@ -30,18 +30,23 @@ class HostPowerManagement : public KaleidoscopePlugin { Resume, } Event; - HostPowerManagement(void) {}; + HostPowerManagement(void) {} - void begin(void) final; void enableWakeup(void) { - WakeupKeyboard.begin(); - }; + WakeupKeyboard.init(); + } + + EventHandlerResult beforeEachCycle(); + +#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API + protected: + void begin(); + static void legacyLoopHook(bool is_post_clear); +#endif private: static bool was_suspended_; static bool initial_suspend_; - - static void loopHook(bool post_clear); }; } diff --git a/src/Kaleidoscope/WakeupKeyboard.cpp b/src/Kaleidoscope/WakeupKeyboard.cpp index a1585584..f527c792 100644 --- a/src/Kaleidoscope/WakeupKeyboard.cpp +++ b/src/Kaleidoscope/WakeupKeyboard.cpp @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- - * Kaleidoscope-MyOldFriend -- Host power management support plugin. - * Copyright (C) 2017 Gergely Nagy + * Kaleidoscope-HostPowerManagement -- Host power management support plugin. + * 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 @@ -85,7 +85,7 @@ bool WakeupKeyboard_::setup(USBSetup& setup) { return false; } -void WakeupKeyboard_::begin() { +void WakeupKeyboard_::init() { } WakeupKeyboard_ WakeupKeyboard; diff --git a/src/Kaleidoscope/WakeupKeyboard.h b/src/Kaleidoscope/WakeupKeyboard.h index d1199ffa..e6ac356b 100644 --- a/src/Kaleidoscope/WakeupKeyboard.h +++ b/src/Kaleidoscope/WakeupKeyboard.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- - * Kaleidoscope-MyOldFriend -- Host power management support plugin. - * Copyright (C) 2017 Gergely Nagy + * Kaleidoscope-HostPowerManagement -- Host power management support plugin. + * 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 @@ -22,10 +22,10 @@ #include "PluggableUSB.h" #include "HID.h" -class WakeupKeyboard_ : public PluggableUSBModule, public KaleidoscopePlugin { +class WakeupKeyboard_ : public PluggableUSBModule, public kaleidoscope::Plugin { public: WakeupKeyboard_(void); - void begin() final; + void init(); protected: int getInterface(uint8_t* interfaceCount);