diff --git a/README.md b/README.md index cd962016..81118a0e 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,9 @@ [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-HostOS.svg?branch=master [travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-HostOS - [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 `HostOS` extension is not all that useful in itself, rather, it is a building block other plugins and extensions can use to not repeat the same @@ -41,18 +41,19 @@ the `HostOS` library header. #include #include -void someFunction (void) { - if (HostOS.os() == Kaleidoscope::HostOS::LINUX) { +void someFunction(void) { + if (HostOS.os() == kaleidoscope::HostOS::LINUX) { // do something linux-y } - if (HostOS.os() == Kaleidoscope::HostOS::OSX) { + if (HostOS.os() == kaleidoscope::HostOS::OSX) { // do something OSX-y } } -void setup (void) { - Kaleidoscope.setup (KEYMAP_SIZE); - Kaleidoscope.use (&HostOS); +void setup(void) { + USE_PLUGINS(&HostOS); + + Kaleidoscope.setup (); } ``` diff --git a/examples/HostOS/HostOS.ino b/examples/HostOS/HostOS.ino index 8f77f88b..264898fa 100644 --- a/examples/HostOS/HostOS.ino +++ b/examples/HostOS/HostOS.ino @@ -21,30 +21,29 @@ const Key keymaps[][ROWS][COLS] PROGMEM = { [0] = KEYMAP_STACKED - ( - Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, - Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, - Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, - Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, - - Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, - Key_skip, - - Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, - Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, - Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, - Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, - - Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, - Key_skip - ), + (Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey, + Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab, + Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G, + Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape, + + Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, + Key_skip, + + Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip, + Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals, + Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote, + Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus, + + Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, + Key_skip), }; void setup() { Serial.begin(9600); - Kaleidoscope.setup(KEYMAP_SIZE); - Kaleidoscope.use(&HostOS, NULL); + USE_PLUGINS(&HostOS); + + Kaleidoscope.setup(); Serial.print("Host OS id is: "); Serial.println(HostOS.os(), DEC); diff --git a/src/Kaleidoscope-HostOS.h b/src/Kaleidoscope-HostOS.h index c3f9fd96..f3295a91 100644 --- a/src/Kaleidoscope-HostOS.h +++ b/src/Kaleidoscope-HostOS.h @@ -20,4 +20,3 @@ #include #include -#include diff --git a/src/Kaleidoscope/HostOS-Base.cpp b/src/Kaleidoscope/HostOS-Base.cpp index 1e8cc58b..ada98a9f 100644 --- a/src/Kaleidoscope/HostOS-Base.cpp +++ b/src/Kaleidoscope/HostOS-Base.cpp @@ -21,39 +21,53 @@ #include -namespace KaleidoscopePlugins { -namespace HostOS { -void -Base::begin(void) { - if (isConfigured) +namespace kaleidoscope { +namespace hostos { + +void Base::begin(void) { + if (is_configured_) return; - eepromSlice = ::EEPROMSettings.requestSlice(sizeof(osType)); + eeprom_slice_ = ::EEPROMSettings.requestSlice(sizeof(os_)); - isConfigured = true; + is_configured_ = true; - if (osType != AUTO) { + if (os_ != AUTO) { return; } - if ((osType = (Type)EEPROM.read(eepromSlice)) != AUTO) + if ((os_ = (Type)EEPROM.read(eeprom_slice_)) != AUTO) return; autoDetect(); } -HostOS::Type -Base::os(void) { - if (osType == AUTO) +Type Base::os(void) { + if (os_ == AUTO) autoDetect(); - return osType; + return os_; +} + +void Base::os(Type new_os) { + os_ = new_os; + EEPROM.update(eeprom_slice_, os_); } -void -Base::os(HostOS::Type osType_) { - osType = osType_; - EEPROM.update(eepromSlice, osType); +bool Base::focusHook(const char *command) { + if (strcmp_P(command, PSTR("hostos.type")) != 0) + return false; + + if (Serial.peek() == '\n') { + Serial.println(os_); + } else { + uint8_t new_os = Serial.parseInt(); + os((Type) new_os); + } + + Serial.read(); + return true; +} + +} } -}; -}; diff --git a/src/Kaleidoscope/HostOS-Base.h b/src/Kaleidoscope/HostOS-Base.h index b0a2f562..a9bb5fb1 100644 --- a/src/Kaleidoscope/HostOS-Base.h +++ b/src/Kaleidoscope/HostOS-Base.h @@ -20,8 +20,9 @@ #include -namespace KaleidoscopePlugins { -namespace HostOS { +namespace kaleidoscope { +namespace hostos { + typedef enum { LINUX, OSX, @@ -36,17 +37,22 @@ class Base : public KaleidoscopePlugin { void begin(void) final; Type os(void); - void os(Type osType); + void os(Type new_os); + + bool focusHook(const char *command); protected: - virtual void autoDetect(void) {}; - Type osType; + virtual void autoDetect(void) {} + Type os_; private: - uint16_t eepromSlice; - bool isConfigured = false; -}; -}; + uint16_t eeprom_slice_; + bool is_configured_ = false; }; -extern KaleidoscopePlugins::HostOS::Base HostOS; +} +} + +extern kaleidoscope::hostos::Base HostOS; + +#define FOCUS_HOOK_HOSTOS FOCUS_HOOK(HostOS.focusHook, "hostos.type") diff --git a/src/Kaleidoscope/HostOS-Focus.cpp b/src/Kaleidoscope/HostOS-Focus.cpp deleted file mode 100644 index 6bfce4f1..00000000 --- a/src/Kaleidoscope/HostOS-Focus.cpp +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- mode: c++ -*- - * Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope - * Copyright (C) 2016, 2017 Gergely Nagy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -namespace KaleidoscopePlugins { -namespace HostOS { -bool -Focus(const char *command) { - if (strcmp_P(command, PSTR("hostos.type")) != 0) - return false; - - if (Serial.peek() == '\n') { - Serial.println(::HostOS.os()); - } else { - uint8_t os = Serial.parseInt(); - ::HostOS.os((KaleidoscopePlugins::HostOS::Type) os); - } - - Serial.read(); - return true; -} -} -} diff --git a/src/Kaleidoscope/HostOS-Focus.h b/src/Kaleidoscope/HostOS-Focus.h deleted file mode 100644 index 032c6076..00000000 --- a/src/Kaleidoscope/HostOS-Focus.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- mode: c++ -*- - * Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope - * Copyright (C) 2016, 2017 Gergely Nagy - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#pragma once - -#include - -namespace KaleidoscopePlugins { -namespace HostOS { -bool Focus(const char *command); -}; -}; - -#define FOCUS_HOOK_HOSTOS \ - FOCUS_HOOK(KaleidoscopePlugins::HostOS::Focus, "hostos.type") diff --git a/src/Kaleidoscope/HostOS-Guesser.cpp b/src/Kaleidoscope/HostOS-Guesser.cpp index 25af7b21..879e3da4 100644 --- a/src/Kaleidoscope/HostOS-Guesser.cpp +++ b/src/Kaleidoscope/HostOS-Guesser.cpp @@ -20,31 +20,32 @@ #include -namespace KaleidoscopePlugins { -namespace HostOS { +namespace kaleidoscope { +namespace hostos { + Guesser::Guesser(void) { } -void -Guesser::autoDetect(void) { +void Guesser::autoDetect(void) { Serial.begin(9600); delay(15000); switch (FingerprintUSBHost.guessHostOS()) { case GuessedHost::WINDOWS: - osType = WINDOWS; + os_ = WINDOWS; break; case GuessedHost::LINUX: - osType = LINUX; + os_ = LINUX; break; case GuessedHost::MACOS: - osType = OSX; + os_ = OSX; break; default: - osType = OTHER; + os_ = OTHER; break; } } -}; -}; + +} +} diff --git a/src/Kaleidoscope/HostOS-Guesser.h b/src/Kaleidoscope/HostOS-Guesser.h index 0d1e410c..72f9ce87 100644 --- a/src/Kaleidoscope/HostOS-Guesser.h +++ b/src/Kaleidoscope/HostOS-Guesser.h @@ -20,14 +20,16 @@ #include -namespace KaleidoscopePlugins { -namespace HostOS { +namespace kaleidoscope { +namespace hostos { + class Guesser : public Base { public: Guesser(void); protected: - virtual void autoDetect(void) final; + void autoDetect(void) final; }; + +} } -}; diff --git a/src/Kaleidoscope/HostOS-select.h b/src/Kaleidoscope/HostOS-select.h index a80de9c0..fd2cdb75 100644 --- a/src/Kaleidoscope/HostOS-select.h +++ b/src/Kaleidoscope/HostOS-select.h @@ -22,7 +22,7 @@ #include #if KALEIDOSCOPE_HOSTOS_GUESSER -KaleidoscopePlugins::HostOS::Base HostOS = KaleidoscopePlugins::HostOS::Guesser(); +kaleidoscope::hostos::Base HostOS = kaleidoscope::hostos::Guesser(); #else -KaleidoscopePlugins::HostOS::Base HostOS; +kaleidoscope::hostos::Base HostOS; #endif