Update to use the newest HostOS version

Also cleaned up the documentation a little, while there.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 7 years ago
parent 34ca05501d
commit 588e332d12

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-Unicode.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-Unicode.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-Unicode [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: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.png?style=flat&colorA=e05d44&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.png?style=flat&colorA=dfb317&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 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 symbols on the host. Because inputting Unicode varies from OS to OS, this helper
@ -26,11 +26,11 @@ singleton object.
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-Unicode.h> #include <Kaleidoscope-Unicode.h>
void setup (void) { void setup() {
Kaleidoscope.setup (KEYMAP_SIZE); USE_PLUGINS(&Unicode);
Kaleidoscope.use (&Unicode, NULL); Kaleidoscope.setup();
Unicode.type (0x2328); Unicode.type(0x2328);
} }
``` ```
@ -84,14 +84,14 @@ functionality.
### `unicodeCustomStart()` ### `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 > be called whenever the [`.start()`](#start) method is called. The default
> implementation does nothing, and should be overridden to implement the custom > implementation does nothing, and should be overridden to implement the custom
> magic needed to enter unicode input mode. > magic needed to enter unicode input mode.
### `unicodeCustomInput()` ### `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 > be called whenever the [`.input()`](#input) method is called. The default
> implementation does nothing, and should be overridden to implement the custom > implementation does nothing, and should be overridden to implement the custom
> magic needed while inputting the hex code itself (such as holding additional > magic needed while inputting the hex code itself (such as holding additional
@ -99,7 +99,7 @@ functionality.
### `unicodeCustomEnd()` ### `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 > be called whenever the [`.end()`](#end) method is called. The default
> implementation does nothing, and should be overridden to implement the custom > implementation does nothing, and should be overridden to implement the custom
> magic needed to leave unicode input mode. > magic needed to leave unicode input mode.

@ -44,8 +44,10 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
}; };
void setup() { void setup() {
Kaleidoscope.setup(KEYMAP_SIZE); USE_PLUGINS(&Unicode);
Kaleidoscope.use(&HostOS, &Unicode, NULL);
Kaleidoscope.setup();
Unicode.type(0x2328); Unicode.type(0x2328);
} }

@ -18,7 +18,7 @@
#include <Kaleidoscope-Unicode.h> #include <Kaleidoscope-Unicode.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
Unicode::Unicode(void) { Unicode::Unicode(void) {
} }
@ -29,7 +29,7 @@ void Unicode::begin(void) {
void Unicode::start(void) { void Unicode::start(void) {
switch (::HostOS.os()) { switch (::HostOS.os()) {
case HostOS::LINUX: case hostos::LINUX:
Keyboard.press(Key_LeftControl.keyCode); Keyboard.press(Key_LeftControl.keyCode);
Keyboard.press(Key_LeftShift.keyCode); Keyboard.press(Key_LeftShift.keyCode);
Keyboard.press(Key_U.keyCode); Keyboard.press(Key_U.keyCode);
@ -39,7 +39,7 @@ void Unicode::start(void) {
Keyboard.release(Key_U.keyCode); Keyboard.release(Key_U.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
break; break;
case HostOS::WINDOWS: case hostos::WINDOWS:
Keyboard.press(Key_RightAlt.keyCode); Keyboard.press(Key_RightAlt.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
Keyboard.release(Key_RightAlt.keyCode); Keyboard.release(Key_RightAlt.keyCode);
@ -49,7 +49,7 @@ void Unicode::start(void) {
Keyboard.release(Key_U.keyCode); Keyboard.release(Key_U.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
break; break;
case HostOS::OSX: case hostos::OSX:
Keyboard.press(Key_LeftAlt.keyCode); Keyboard.press(Key_LeftAlt.keyCode);
break; break;
default: default:
@ -60,10 +60,10 @@ void Unicode::start(void) {
void Unicode::input(void) { void Unicode::input(void) {
switch (::HostOS.os()) { switch (::HostOS.os()) {
case HostOS::LINUX: case hostos::LINUX:
case HostOS::WINDOWS: case hostos::WINDOWS:
break; break;
case HostOS::OSX: case hostos::OSX:
Keyboard.press(Key_LeftAlt.keyCode); Keyboard.press(Key_LeftAlt.keyCode);
break; break;
default: default:
@ -74,15 +74,15 @@ void Unicode::input(void) {
void Unicode::end(void) { void Unicode::end(void) {
switch (::HostOS.os()) { switch (::HostOS.os()) {
case HostOS::LINUX: case hostos::LINUX:
Keyboard.press(Key_Spacebar.keyCode); Keyboard.press(Key_Spacebar.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
Keyboard.release(Key_Spacebar.keyCode); Keyboard.release(Key_Spacebar.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
break; break;
case HostOS::WINDOWS: case hostos::WINDOWS:
break; break;
case HostOS::OSX: case hostos::OSX:
Keyboard.release(Key_LeftAlt.keyCode); Keyboard.release(Key_LeftAlt.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
break; break;
@ -93,14 +93,14 @@ void Unicode::end(void) {
} }
void Unicode::typeCode(uint32_t unicode) { void Unicode::typeCode(uint32_t unicode) {
bool onZeroStart = true; bool on_zero_start = true;
for (int8_t i = 7; i >= 0; i--) { for (int8_t i = 7; i >= 0; i--) {
if (i <= 3) { if (i <= 3) {
onZeroStart = false; on_zero_start = false;
} }
uint8_t digit = ((unicode >> (i * 4)) & 0xF); uint8_t digit = ((unicode >> (i * 4)) & 0xF);
if (digit == 0) { if (digit == 0) {
if (onZeroStart == false) { if (on_zero_start == false) {
Key key = hexToKey(digit); Key key = hexToKey(digit);
input(); input();
Keyboard.press(key.keyCode); Keyboard.press(key.keyCode);
@ -117,7 +117,7 @@ void Unicode::typeCode(uint32_t unicode) {
input(); input();
Keyboard.release(key.keyCode); Keyboard.release(key.keyCode);
Keyboard.sendReport(); Keyboard.sendReport();
onZeroStart = false; on_zero_start = false;
} }
delay(5); delay(5);
} }
@ -128,7 +128,8 @@ void Unicode::type(uint32_t unicode) {
typeCode(unicode); typeCode(unicode);
end(); end();
} }
} // namespace KaleidoscopePlugins
}
__attribute__((weak)) Key hexToKey(uint8_t hex) { __attribute__((weak)) Key hexToKey(uint8_t hex) {
uint8_t m; uint8_t m;
@ -152,4 +153,4 @@ __attribute__((weak)) void unicodeCustomEnd(void) {
__attribute__((weak)) void unicodeCustomInput(void) { __attribute__((weak)) void unicodeCustomInput(void) {
} }
KaleidoscopePlugins::Unicode Unicode; kaleidoscope::Unicode Unicode;

@ -21,7 +21,7 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-HostOS.h> #include <Kaleidoscope-HostOS.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
class Unicode : public KaleidoscopePlugin { class Unicode : public KaleidoscopePlugin {
public: public:
Unicode(void); Unicode(void);
@ -43,4 +43,4 @@ void unicodeCustomStart(void);
void unicodeCustomEnd(void); void unicodeCustomEnd(void);
void unicodeCustomInput(void); void unicodeCustomInput(void);
extern KaleidoscopePlugins::Unicode Unicode; extern kaleidoscope::Unicode Unicode;

Loading…
Cancel
Save