From 588e332d1227ee5d80532350275e0ab5460985b6 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sun, 4 Jun 2017 19:06:20 +0200 Subject: [PATCH] Update to use the newest HostOS version Also cleaned up the documentation a little, while there. Signed-off-by: Gergely Nagy --- README.md | 20 ++++++++++---------- examples/Unicode/Unicode.ino | 6 ++++-- src/Kaleidoscope/Unicode.cpp | 33 +++++++++++++++++---------------- src/Kaleidoscope/Unicode.h | 4 ++-- 4 files changed, 33 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 72ffc42e..9d6a5db9 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-Unicode.svg?branch=master [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-Unicode - [st:stable]: https://img.shields.io/badge/stable-✔-black.png?style=flat&colorA=44cc11&colorB=494e52 - [st:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52 - [st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&colorB=494e52 + [st:stable]: https://img.shields.io/badge/stable-✔-black.svg?style=flat&colorA=44cc11&colorB=494e52 + [st:broken]: https://img.shields.io/badge/broken-X-black.svg?style=flat&colorA=e05d44&colorB=494e52 + [st:experimental]: https://img.shields.io/badge/experimental----black.svg?style=flat&colorA=dfb317&colorB=494e52 The `Unicode` extension makes it easier to write plugins that input Unicode symbols on the host. Because inputting Unicode varies from OS to OS, this helper @@ -26,11 +26,11 @@ singleton object. #include #include -void setup (void) { - Kaleidoscope.setup (KEYMAP_SIZE); - Kaleidoscope.use (&Unicode, NULL); +void setup() { + USE_PLUGINS(&Unicode); + Kaleidoscope.setup(); - Unicode.type (0x2328); + Unicode.type(0x2328); } ``` @@ -84,14 +84,14 @@ functionality. ### `unicodeCustomStart()` -> If the host OS type is set to `Kaleidoscope::HostOS::Custom`, then this function will +> If the host OS type is set to `kaleidoscope::hostos::Custom`, then this function will > be called whenever the [`.start()`](#start) method is called. The default > implementation does nothing, and should be overridden to implement the custom > magic needed to enter unicode input mode. ### `unicodeCustomInput()` -> If the host OS type is set to `Kaleidoscope::HostOS::Custom`, then this function will +> If the host OS type is set to `kaleidoscope::hostos::Custom`, then this function will > be called whenever the [`.input()`](#input) method is called. The default > implementation does nothing, and should be overridden to implement the custom > magic needed while inputting the hex code itself (such as holding additional @@ -99,7 +99,7 @@ functionality. ### `unicodeCustomEnd()` -> If the host OS type is set to `Kaleidoscope::HostOS::Custom`, then this function will +> If the host OS type is set to `kaleidoscope::hostos::Custom`, then this function will > be called whenever the [`.end()`](#end) method is called. The default > implementation does nothing, and should be overridden to implement the custom > magic needed to leave unicode input mode. diff --git a/examples/Unicode/Unicode.ino b/examples/Unicode/Unicode.ino index ce6e3796..66e16723 100644 --- a/examples/Unicode/Unicode.ino +++ b/examples/Unicode/Unicode.ino @@ -44,8 +44,10 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { }; void setup() { - Kaleidoscope.setup(KEYMAP_SIZE); - Kaleidoscope.use(&HostOS, &Unicode, NULL); + USE_PLUGINS(&Unicode); + + Kaleidoscope.setup(); + Unicode.type(0x2328); } diff --git a/src/Kaleidoscope/Unicode.cpp b/src/Kaleidoscope/Unicode.cpp index 7ec687e5..1fe8ccc7 100644 --- a/src/Kaleidoscope/Unicode.cpp +++ b/src/Kaleidoscope/Unicode.cpp @@ -18,7 +18,7 @@ #include -namespace KaleidoscopePlugins { +namespace kaleidoscope { Unicode::Unicode(void) { } @@ -29,7 +29,7 @@ void Unicode::begin(void) { void Unicode::start(void) { switch (::HostOS.os()) { - case HostOS::LINUX: + case hostos::LINUX: Keyboard.press(Key_LeftControl.keyCode); Keyboard.press(Key_LeftShift.keyCode); Keyboard.press(Key_U.keyCode); @@ -39,7 +39,7 @@ void Unicode::start(void) { Keyboard.release(Key_U.keyCode); Keyboard.sendReport(); break; - case HostOS::WINDOWS: + case hostos::WINDOWS: Keyboard.press(Key_RightAlt.keyCode); Keyboard.sendReport(); Keyboard.release(Key_RightAlt.keyCode); @@ -49,7 +49,7 @@ void Unicode::start(void) { Keyboard.release(Key_U.keyCode); Keyboard.sendReport(); break; - case HostOS::OSX: + case hostos::OSX: Keyboard.press(Key_LeftAlt.keyCode); break; default: @@ -60,10 +60,10 @@ void Unicode::start(void) { void Unicode::input(void) { switch (::HostOS.os()) { - case HostOS::LINUX: - case HostOS::WINDOWS: + case hostos::LINUX: + case hostos::WINDOWS: break; - case HostOS::OSX: + case hostos::OSX: Keyboard.press(Key_LeftAlt.keyCode); break; default: @@ -74,15 +74,15 @@ void Unicode::input(void) { void Unicode::end(void) { switch (::HostOS.os()) { - case HostOS::LINUX: + case hostos::LINUX: Keyboard.press(Key_Spacebar.keyCode); Keyboard.sendReport(); Keyboard.release(Key_Spacebar.keyCode); Keyboard.sendReport(); break; - case HostOS::WINDOWS: + case hostos::WINDOWS: break; - case HostOS::OSX: + case hostos::OSX: Keyboard.release(Key_LeftAlt.keyCode); Keyboard.sendReport(); break; @@ -93,14 +93,14 @@ void Unicode::end(void) { } void Unicode::typeCode(uint32_t unicode) { - bool onZeroStart = true; + bool on_zero_start = true; for (int8_t i = 7; i >= 0; i--) { if (i <= 3) { - onZeroStart = false; + on_zero_start = false; } uint8_t digit = ((unicode >> (i * 4)) & 0xF); if (digit == 0) { - if (onZeroStart == false) { + if (on_zero_start == false) { Key key = hexToKey(digit); input(); Keyboard.press(key.keyCode); @@ -117,7 +117,7 @@ void Unicode::typeCode(uint32_t unicode) { input(); Keyboard.release(key.keyCode); Keyboard.sendReport(); - onZeroStart = false; + on_zero_start = false; } delay(5); } @@ -128,7 +128,8 @@ void Unicode::type(uint32_t unicode) { typeCode(unicode); end(); } -} // namespace KaleidoscopePlugins + +} __attribute__((weak)) Key hexToKey(uint8_t hex) { uint8_t m; @@ -152,4 +153,4 @@ __attribute__((weak)) void unicodeCustomEnd(void) { __attribute__((weak)) void unicodeCustomInput(void) { } -KaleidoscopePlugins::Unicode Unicode; +kaleidoscope::Unicode Unicode; diff --git a/src/Kaleidoscope/Unicode.h b/src/Kaleidoscope/Unicode.h index 103c1fc7..21487cd6 100644 --- a/src/Kaleidoscope/Unicode.h +++ b/src/Kaleidoscope/Unicode.h @@ -21,7 +21,7 @@ #include #include -namespace KaleidoscopePlugins { +namespace kaleidoscope { class Unicode : public KaleidoscopePlugin { public: Unicode(void); @@ -43,4 +43,4 @@ void unicodeCustomStart(void); void unicodeCustomEnd(void); void unicodeCustomInput(void); -extern KaleidoscopePlugins::Unicode Unicode; +extern kaleidoscope::Unicode Unicode;