From 5099d8ebb9b4574db958d768900f2902979027df Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 13 Oct 2018 12:35:58 +0200 Subject: [PATCH] Rearrange the file layout in preparation of becoming a monorepo Move the documentation to `doc/plugin/HostPowerManagement.md`, sources under `src/kaleidoscope/plugin/` (appropriately namespaced). This is in preparation of merging plugins into a single monorepo. Signed-off-by: Gergely Nagy --- README.md | 44 +---------------- doc/plugin/HostPowerManagement.md | 47 +++++++++++++++++++ .../HostPowerManagement.ino | 8 ++-- src/Kaleidoscope-HostPowerManagement.h | 2 +- .../plugin}/HostPowerManagement.cpp | 6 ++- .../plugin}/HostPowerManagement.h | 10 +++- 6 files changed, 65 insertions(+), 52 deletions(-) create mode 100644 doc/plugin/HostPowerManagement.md rename src/{Kaleidoscope => kaleidoscope/plugin}/HostPowerManagement.cpp (92%) rename src/{Kaleidoscope => kaleidoscope/plugin}/HostPowerManagement.h (84%) diff --git a/README.md b/README.md index f89544f9..09498c2f 100644 --- a/README.md +++ b/README.md @@ -5,46 +5,4 @@ [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-HostPowerManagement.svg?branch=master [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-HostPowerManagement -Support performing custom actions whenever the host suspends, resumes, or is -sleeping. - -## Using the plugin - -To use the plugin, one needs to include the header, and activate it. No further -configuration is necessary, unless one wants to perform custom actions. - -```c++ -#include -#include - -KALEIDOSCOPE_INIT_PLUGINS(HostPowerManagement); - -void setup () { - Kaleidoscope.setup (); -} -``` - -## Plugin methods - -The plugin provides the `HostPowerManagement` object, with no public methods. - -## Overrideable methods - -### `hostPowerManagementEventHandler(event)` - -> The `hostPowerManagementEventHandler` method is the brain of the plugin: this function -> tells it what action to perform in response to the various events. -> -> Currently supported events are: `kaleidoscope::HostPowerManagement::Suspend` is fired -> once when the host suspends; `kaleidoscope::HostPowerManagement::Sleep` is fired every -> cycle while the host is suspended; `kaleidoscope::HostPowerManagement::Resume` is -> fired once when the host wakes up. -> -> The default implementation is empty. - -## Further reading - -Starting from the [example][plugin:example] is the recommended way of getting -started with the plugin. - - [plugin:example]: https://github.com/keyboardio/Kaleidoscope-HostPowerManagement/blob/master/examples/HostPowerManagement/HostPowerManagement.ino +See [doc/plugin/HostPowerManagement.md](doc/plugin/HostPowerManagement.md) for documentation. diff --git a/doc/plugin/HostPowerManagement.md b/doc/plugin/HostPowerManagement.md new file mode 100644 index 00000000..0a5268cc --- /dev/null +++ b/doc/plugin/HostPowerManagement.md @@ -0,0 +1,47 @@ +# Kaleidoscope-HostPowerManagement + +Support performing custom actions whenever the host suspends, resumes, or is +sleeping. + +## Using the plugin + +To use the plugin, one needs to include the header, and activate it. No further +configuration is necessary, unless one wants to perform custom actions. + +```c++ +#include +#include + +KALEIDOSCOPE_INIT_PLUGINS(HostPowerManagement); + +void setup () { + Kaleidoscope.setup (); +} +``` + +## Plugin methods + +The plugin provides the `HostPowerManagement` object, with no public methods. + +## Overrideable methods + +### `hostPowerManagementEventHandler(event)` + +> The `hostPowerManagementEventHandler` method is the brain of the plugin: this function +> tells it what action to perform in response to the various events. +> +> Currently supported events are: +> `kaleidoscope::plugin::HostPowerManagement::Suspend` is fired once when the +> host suspends; `kaleidoscope::plugin::HostPowerManagement::Sleep` is fired +> every cycle while the host is suspended; +> `kaleidoscope::plugin::HostPowerManagement::Resume` is fired once when the +> host wakes up. +> +> The default implementation is empty. + +## Further reading + +Starting from the [example][plugin:example] is the recommended way of getting +started with the plugin. + + [plugin:example]: https://github.com/keyboardio/Kaleidoscope-HostPowerManagement/blob/master/examples/HostPowerManagement/HostPowerManagement.ino diff --git a/examples/HostPowerManagement/HostPowerManagement.ino b/examples/HostPowerManagement/HostPowerManagement.ino index 5f27cbdf..72d6f9df 100644 --- a/examples/HostPowerManagement/HostPowerManagement.ino +++ b/examples/HostPowerManagement/HostPowerManagement.ino @@ -43,18 +43,18 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { }; // *INDENT-ON* -void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) { +void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) { switch (event) { - case kaleidoscope::HostPowerManagement::Suspend: + case kaleidoscope::plugin::HostPowerManagement::Suspend: LEDControl.paused = true; LEDControl.set_all_leds_to({0, 0, 0}); LEDControl.syncLeds(); break; - case kaleidoscope::HostPowerManagement::Resume: + case kaleidoscope::plugin::HostPowerManagement::Resume: LEDControl.paused = false; LEDControl.refreshAll(); break; - case kaleidoscope::HostPowerManagement::Sleep: + case kaleidoscope::plugin::HostPowerManagement::Sleep: break; } } diff --git a/src/Kaleidoscope-HostPowerManagement.h b/src/Kaleidoscope-HostPowerManagement.h index 6b9a0251..f6e56935 100644 --- a/src/Kaleidoscope-HostPowerManagement.h +++ b/src/Kaleidoscope-HostPowerManagement.h @@ -18,4 +18,4 @@ #pragma once -#include +#include diff --git a/src/Kaleidoscope/HostPowerManagement.cpp b/src/kaleidoscope/plugin/HostPowerManagement.cpp similarity index 92% rename from src/Kaleidoscope/HostPowerManagement.cpp rename to src/kaleidoscope/plugin/HostPowerManagement.cpp index 46f8053f..ce4c9826 100644 --- a/src/Kaleidoscope/HostPowerManagement.cpp +++ b/src/kaleidoscope/plugin/HostPowerManagement.cpp @@ -25,6 +25,7 @@ extern uint8_t _usbSuspendState; namespace kaleidoscope { +namespace plugin { bool HostPowerManagement::was_suspended_ = false; bool HostPowerManagement::initial_suspend_ = true; @@ -54,9 +55,10 @@ EventHandlerResult HostPowerManagement::beforeEachCycle() { return EventHandlerResult::OK; } +} } -__attribute__((weak)) void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) { +__attribute__((weak)) void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) { } -kaleidoscope::HostPowerManagement HostPowerManagement; +kaleidoscope::plugin::HostPowerManagement HostPowerManagement; diff --git a/src/Kaleidoscope/HostPowerManagement.h b/src/kaleidoscope/plugin/HostPowerManagement.h similarity index 84% rename from src/Kaleidoscope/HostPowerManagement.h rename to src/kaleidoscope/plugin/HostPowerManagement.h index 61b8716b..2dbb36f7 100644 --- a/src/Kaleidoscope/HostPowerManagement.h +++ b/src/kaleidoscope/plugin/HostPowerManagement.h @@ -26,6 +26,7 @@ "removed." namespace kaleidoscope { +namespace plugin { class HostPowerManagement : public kaleidoscope::Plugin { public: typedef enum { @@ -46,6 +47,11 @@ class HostPowerManagement : public kaleidoscope::Plugin { }; } -void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event); +// Backwards compatibility +typedef plugin::HostPowerManagement HostPowerManagement; -extern kaleidoscope::HostPowerManagement HostPowerManagement; +} + +void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event); + +extern kaleidoscope::plugin::HostPowerManagement HostPowerManagement;