From 2ba02d8ecf90e7851b0e572580b72fd28677b31b Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 13 Oct 2018 14:57:32 +0200 Subject: [PATCH] Rearrange the file layout in preparation of becoming a monorepo Move the documentation to `doc/plugin/LED-Palette-Theme.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 | 127 +---------------- doc/plugin/LED-Palette-Theme.md | 128 ++++++++++++++++++ src/Kaleidoscope-LED-Palette-Theme.h | 2 +- .../plugin}/LED-Palette-Theme.cpp | 4 +- .../plugin}/LED-Palette-Theme.h | 4 +- 5 files changed, 136 insertions(+), 129 deletions(-) create mode 100644 doc/plugin/LED-Palette-Theme.md rename src/{Kaleidoscope => kaleidoscope/plugin}/LED-Palette-Theme.cpp (98%) rename src/{Kaleidoscope => kaleidoscope/plugin}/LED-Palette-Theme.h (95%) diff --git a/README.md b/README.md index 49a884e6..cc6dc308 100644 --- a/README.md +++ b/README.md @@ -5,129 +5,4 @@ [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-Palette-Theme.svg?branch=master [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-LED-Palette-Theme -A common base for plugins that want to provide themes, or theme-related -capabilities, using a 16 color palette. In other words, this is for plugin -authors primarily. The primary aim of the plugin is to provide not only a common -palette, but tools that make it easier to use it too. - -## Using the plugin - -To use the plugin, one needs to do a bit more than include the header, and tell -the firmware to use it. Itself being a mere building block, to use it to its -full extent, we need to create our own plugin on top of it. - -```c++ -#include -#include -#include -#include - -namespace example { - -class TestLEDMode : public LEDMode { - public: - TestLEDMode() {} - - protected: - void setup(void) final; - void update(void) final; - - kaleidoscope::EventHandlerResult onFocusEvent(const char *command); - - private: - static uint16_t map_base_; -}; - -uint16_t TestLEDMode::map_base_; - -void TestLEDMode::setup(void) { - map_base_ = LEDPaletteTheme.reserveThemes(1); -} - -void TestLEDMode::update(void) { - LEDPaletteTheme.updateHandler(map_base_, 0); -} - -kaleidoscope::EventHandlerResult -TestLEDMode::onFocusEvent(const char *command) { - return LEDPaletteTheme.themeFocusEvent(command, PSTR("testLedMode.map"), map_base_, 1); -} - -} - -example::TestLEDMode TestLEDMode; - -KALEIDOSCOPE_INIT_PLUGINS( - Focus, - LEDPaletteTheme, - TestLEDMode, - EEPROMSettings -); - -void setup() { - Kaleidoscope.setup(); - - TestLEDMode.activate(); -} -``` - -This is a simple extension, where it provides a `testLEDMode.map` Focus command, -with which one can set the theme which will be saved to EEPROM. - -## Plugin methods - -The plugin provides the `LEDPaletteTheme` object, which has the following methods and properties: - -### `.reserveThemes(max_themes)` - -> Reserve space in EEPROM for `max_themes`. Each key on a theme uses half a byte -> of space. The function returns the `theme_base` to be used with the rest of -> the methods. -> -> The `theme_base` is a pointer into the EEPROM where the theme storage starts. - -### `.updateHandler(theme_base, theme)` - -> A helper we can call in our plugin's `.update()` method: given an EEPROM -> location (`theme_base`), and a `theme` index, it will update the keyboard with -> the colors of the specified theme. -> -> The `theme` argument can be any index between zero and `max_themes`. How the -> plugin decides which theme to display depends entirely on the plugin. - -### `.themeFocusEvent(command, expected_command, theme_base, max_themes)` - -> To be used in a custom `Focus` handler: handles the `expected_command` Focus -> command, and provides a way to query and update the themes supported by the -> plugin. -> -> When queried, it will list the color indexes. When used as a setter, it -> expects one index per key. -> -> The palette can be set via the `palette` focus command, provided by the -> `LEDPaletteTheme` plugin. - -## Focus commands - -### `palette` - -> Without arguments, prints the palette: RGB values for all 16 colors. -> -> With arguments, updates the palette with new colors. One does not need to give -> the full palette, the plugin will process as many arguments as available, and -> ignore anything past the last index. It expects colors to have all three -> components specified, or none at all. Thus, partial palette updates are -> possible, but only on the color level, not at component level. - -## Dependencies - -* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings) -* [Kaleidoscope-FocusSerial](https://github.com/keyboardio/Kaleidoscope-FocusSerial) -* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl) - -## 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-LED-Palette-Theme/blob/master/examples/LED-Palette-Theme/LED-Palette-Theme.ino +See [doc/plugin/LED-Palette-Theme.md](doc/plugin/LED-Palette-Theme.md) for documentation. diff --git a/doc/plugin/LED-Palette-Theme.md b/doc/plugin/LED-Palette-Theme.md new file mode 100644 index 00000000..f4d73941 --- /dev/null +++ b/doc/plugin/LED-Palette-Theme.md @@ -0,0 +1,128 @@ +# Kaleidoscope-LED-Palette-Theme + +A common base for plugins that want to provide themes, or theme-related +capabilities, using a 16 color palette. In other words, this is for plugin +authors primarily. The primary aim of the plugin is to provide not only a common +palette, but tools that make it easier to use it too. + +## Using the plugin + +To use the plugin, one needs to do a bit more than include the header, and tell +the firmware to use it. Itself being a mere building block, to use it to its +full extent, we need to create our own plugin on top of it. + +```c++ +#include +#include +#include +#include + +namespace example { + +class TestLEDMode : public LEDMode { + public: + TestLEDMode() {} + + protected: + void setup(void) final; + void update(void) final; + + kaleidoscope::EventHandlerResult onFocusEvent(const char *command); + + private: + static uint16_t map_base_; +}; + +uint16_t TestLEDMode::map_base_; + +void TestLEDMode::setup(void) { + map_base_ = LEDPaletteTheme.reserveThemes(1); +} + +void TestLEDMode::update(void) { + LEDPaletteTheme.updateHandler(map_base_, 0); +} + +kaleidoscope::EventHandlerResult +TestLEDMode::onFocusEvent(const char *command) { + return LEDPaletteTheme.themeFocusEvent(command, PSTR("testLedMode.map"), map_base_, 1); +} + +} + +example::TestLEDMode TestLEDMode; + +KALEIDOSCOPE_INIT_PLUGINS( + Focus, + LEDPaletteTheme, + TestLEDMode, + EEPROMSettings +); + +void setup() { + Kaleidoscope.setup(); + + TestLEDMode.activate(); +} +``` + +This is a simple extension, where it provides a `testLEDMode.map` Focus command, +with which one can set the theme which will be saved to EEPROM. + +## Plugin methods + +The plugin provides the `LEDPaletteTheme` object, which has the following methods and properties: + +### `.reserveThemes(max_themes)` + +> Reserve space in EEPROM for `max_themes`. Each key on a theme uses half a byte +> of space. The function returns the `theme_base` to be used with the rest of +> the methods. +> +> The `theme_base` is a pointer into the EEPROM where the theme storage starts. + +### `.updateHandler(theme_base, theme)` + +> A helper we can call in our plugin's `.update()` method: given an EEPROM +> location (`theme_base`), and a `theme` index, it will update the keyboard with +> the colors of the specified theme. +> +> The `theme` argument can be any index between zero and `max_themes`. How the +> plugin decides which theme to display depends entirely on the plugin. + +### `.themeFocusEvent(command, expected_command, theme_base, max_themes)` + +> To be used in a custom `Focus` handler: handles the `expected_command` Focus +> command, and provides a way to query and update the themes supported by the +> plugin. +> +> When queried, it will list the color indexes. When used as a setter, it +> expects one index per key. +> +> The palette can be set via the `palette` focus command, provided by the +> `LEDPaletteTheme` plugin. + +## Focus commands + +### `palette` + +> Without arguments, prints the palette: RGB values for all 16 colors. +> +> With arguments, updates the palette with new colors. One does not need to give +> the full palette, the plugin will process as many arguments as available, and +> ignore anything past the last index. It expects colors to have all three +> components specified, or none at all. Thus, partial palette updates are +> possible, but only on the color level, not at component level. + +## Dependencies + +* [Kaleidoscope-EEPROM-Settings](https://github.com/keyboardio/Kaleidoscope-EEPROM-Settings) +* [Kaleidoscope-FocusSerial](https://github.com/keyboardio/Kaleidoscope-FocusSerial) +* [Kaleidoscope-LEDControl](https://github.com/keyboardio/Kaleidoscope-LEDControl) + +## 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-LED-Palette-Theme/blob/master/examples/LED-Palette-Theme/LED-Palette-Theme.ino diff --git a/src/Kaleidoscope-LED-Palette-Theme.h b/src/Kaleidoscope-LED-Palette-Theme.h index 451db96a..4d1a5199 100644 --- a/src/Kaleidoscope-LED-Palette-Theme.h +++ b/src/Kaleidoscope-LED-Palette-Theme.h @@ -17,4 +17,4 @@ #pragma once -#include +#include diff --git a/src/Kaleidoscope/LED-Palette-Theme.cpp b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp similarity index 98% rename from src/Kaleidoscope/LED-Palette-Theme.cpp rename to src/kaleidoscope/plugin/LED-Palette-Theme.cpp index c8b8d680..bf441457 100644 --- a/src/Kaleidoscope/LED-Palette-Theme.cpp +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.cpp @@ -21,6 +21,7 @@ #include namespace kaleidoscope { +namespace plugin { uint16_t LEDPaletteTheme::palette_base_; @@ -171,6 +172,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command, return EventHandlerResult::EVENT_CONSUMED; } +} } -kaleidoscope::LEDPaletteTheme LEDPaletteTheme; +kaleidoscope::plugin::LEDPaletteTheme LEDPaletteTheme; diff --git a/src/Kaleidoscope/LED-Palette-Theme.h b/src/kaleidoscope/plugin/LED-Palette-Theme.h similarity index 95% rename from src/Kaleidoscope/LED-Palette-Theme.h rename to src/kaleidoscope/plugin/LED-Palette-Theme.h index 52bc935d..0f097b8a 100644 --- a/src/Kaleidoscope/LED-Palette-Theme.h +++ b/src/kaleidoscope/plugin/LED-Palette-Theme.h @@ -21,6 +21,7 @@ #include namespace kaleidoscope { +namespace plugin { class LEDPaletteTheme : public kaleidoscope::Plugin { public: @@ -46,6 +47,7 @@ class LEDPaletteTheme : public kaleidoscope::Plugin { static uint16_t palette_base_; }; +} } -extern kaleidoscope::LEDPaletteTheme LEDPaletteTheme; +extern kaleidoscope::plugin::LEDPaletteTheme LEDPaletteTheme;