diff --git a/README.md b/README.md index 73be331a..9091307f 100644 --- a/README.md +++ b/README.md @@ -5,71 +5,4 @@ [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-MagicCombo.svg?branch=master [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-MagicCombo -The `MagicCombo` extension provides a way to perform custom actions when a -particular set of keys are held down together. The functionality assigned to -these keys are not changed, and the custom action triggers as long as all keys -within the set are pressed. The order in which they were pressed do not matter. - -This can be used to tie complex actions to key chords. - -## Using the extension - -To use the extension, we must include the header, create actions for the magic -combos we want to trigger, and set up a mapping: - -```c++ -#include -#include -#include - -enum { KIND_OF_MAGIC }; - -void kindOfMagic(uint8_t combo_index) { - Macros.type(PSTR("It's a kind of magic!")); -} - -USE_MAGIC_COMBOS( -[KIND_OF_MAGIC] = { - .action = kindOfMagic, - .keys = {R3C6, R3C9} // Left Fn + Right Fn -}); - -KALEIDOSCOPE_INIT_PLUGINS(MagicCombo, Macros); - -void setup() { - Kaleidoscope.setup(); -} -``` - -It is recommended to use the `RxCy` macros of the core firmware to set the keys -that are part of a combination. - -## Plugin properties - -The extension provides a `MagicCombo` singleton object, with the following -property: - -### `.min_interval` - -> Restrict the magic action to fire at most once every `min_interval` -> milliseconds. -> -> Defaults to 500. - -## Plugin callbacks - -Whenever a combination is found to be held, the plugin will trigger the -specified action, which is just a regular method with a single `uint8_t` -argument: the index of the magic combo. This function will be called repeatedly -(every `min_interval` milliseconds) while the combination is held. - -## Further reading - -Starting from the [example][plugin:example] is the recommended way of getting -started with the plugin. - -`RxCy` coordinates for a Model01: - -![rxcy layout](./docs/rc_layout.png) - - [plugin:example]: https://github.com/keyboardio/Kaleidoscope-MagicCombo/blob/master/examples/MagicCombo/MagicCombo.ino +See [doc/plugin/MagicCombo.md](doc/plugin/MagicCombo.md) for documentation. diff --git a/docs/rc_layout.png b/doc/model01_coordinates.png similarity index 100% rename from docs/rc_layout.png rename to doc/model01_coordinates.png diff --git a/UPGRADING.md b/doc/plugin/MagicCombo.md similarity index 65% rename from UPGRADING.md rename to doc/plugin/MagicCombo.md index 1c9652d4..b86d2996 100644 --- a/UPGRADING.md +++ b/doc/plugin/MagicCombo.md @@ -1,5 +1,75 @@ -Breaking changes in `MagicCombo` -================================ +# Kaleidoscope-MagicCombo + +The `MagicCombo` extension provides a way to perform custom actions when a +particular set of keys are held down together. The functionality assigned to +these keys are not changed, and the custom action triggers as long as all keys +within the set are pressed. The order in which they were pressed do not matter. + +This can be used to tie complex actions to key chords. + +## Using the extension + +To use the extension, we must include the header, create actions for the magic +combos we want to trigger, and set up a mapping: + +```c++ +#include +#include +#include + +enum { KIND_OF_MAGIC }; + +void kindOfMagic(uint8_t combo_index) { + Macros.type(PSTR("It's a kind of magic!")); +} + +USE_MAGIC_COMBOS( +[KIND_OF_MAGIC] = { + .action = kindOfMagic, + .keys = {R3C6, R3C9} // Left Fn + Right Fn +}); + +KALEIDOSCOPE_INIT_PLUGINS(MagicCombo, Macros); + +void setup() { + Kaleidoscope.setup(); +} +``` + +It is recommended to use the `RxCy` macros of the core firmware to set the keys +that are part of a combination. + +## Plugin properties + +The extension provides a `MagicCombo` singleton object, with the following +property: + +### `.min_interval` + +> Restrict the magic action to fire at most once every `min_interval` +> milliseconds. +> +> Defaults to 500. + +## Plugin callbacks + +Whenever a combination is found to be held, the plugin will trigger the +specified action, which is just a regular method with a single `uint8_t` +argument: the index of the magic combo. This function will be called repeatedly +(every `min_interval` milliseconds) while the combination is held. + +## Further reading + +Starting from the [example][plugin:example] is the recommended way of getting +started with the plugin. + +`RxCy` coordinates for a Model01: + +![rxcy layout](../model01_coordinates.png) + + [plugin:example]: https://github.com/keyboardio/Kaleidoscope-MagicCombo/blob/master/examples/MagicCombo/MagicCombo.ino + +## Upgrading To make `MagicCombo` more portable, and easier to use, we had to break the API previously provided, there was no way to maintain backwards compatibility. This diff --git a/src/Kaleidoscope-MagicCombo.h b/src/Kaleidoscope-MagicCombo.h index 588dec13..ed5c3699 100644 --- a/src/Kaleidoscope-MagicCombo.h +++ b/src/Kaleidoscope-MagicCombo.h @@ -17,4 +17,4 @@ #pragma once -#include +#include diff --git a/src/Kaleidoscope/MagicCombo.cpp b/src/kaleidoscope/plugin/MagicCombo.cpp similarity index 95% rename from src/Kaleidoscope/MagicCombo.cpp rename to src/kaleidoscope/plugin/MagicCombo.cpp index a9c30f92..3dcd3ac5 100644 --- a/src/Kaleidoscope/MagicCombo.cpp +++ b/src/kaleidoscope/plugin/MagicCombo.cpp @@ -18,6 +18,7 @@ #include namespace kaleidoscope { +namespace plugin { uint16_t MagicCombo::min_interval = 500; uint32_t MagicCombo::end_time_; @@ -52,6 +53,7 @@ EventHandlerResult MagicCombo::beforeReportingState() { return EventHandlerResult::OK; } -}; +} +} -kaleidoscope::MagicCombo MagicCombo; +kaleidoscope::plugin::MagicCombo MagicCombo; diff --git a/src/Kaleidoscope/MagicCombo.h b/src/kaleidoscope/plugin/MagicCombo.h similarity index 84% rename from src/Kaleidoscope/MagicCombo.h rename to src/kaleidoscope/plugin/MagicCombo.h index bd0e710c..35706c26 100644 --- a/src/Kaleidoscope/MagicCombo.h +++ b/src/kaleidoscope/plugin/MagicCombo.h @@ -23,11 +23,14 @@ #define USE_MAGIC_COMBOS(...) \ namespace kaleidoscope { \ + namespace plugin { \ namespace magiccombo { \ - const kaleidoscope::MagicCombo::Combo combos[] PROGMEM = {__VA_ARGS__}; \ + const kaleidoscope::plugin::MagicCombo::Combo combos[] PROGMEM = \ + {__VA_ARGS__}; \ \ const uint8_t combos_length = sizeof(combos) / sizeof(*combos); \ } \ + } \ } #define _MAGICCOMBO_API_CHANGE \ @@ -38,6 +41,7 @@ " https://github.com/keyboardio/Kaleidoscope-MagicCombo/blob/master/UPGRADING.md" namespace kaleidoscope { +namespace plugin { class MagicCombo : public kaleidoscope::Plugin { public: @@ -73,4 +77,8 @@ extern const uint8_t combos_length; } -extern kaleidoscope::MagicCombo MagicCombo; +// Backward compatibility +typedef plugin::MagicCombo MagicCombo; +} + +extern kaleidoscope::plugin::MagicCombo MagicCombo;