diff --git a/src/Kaleidoscope-HostOS.h b/src/Kaleidoscope-HostOS.h index 93016481..3a137545 100644 --- a/src/Kaleidoscope-HostOS.h +++ b/src/Kaleidoscope-HostOS.h @@ -1,6 +1,6 @@ /* -*- mode: c++ -*- * Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope - * Copyright (C) 2016, 2017 Keyboard.io, Inc + * Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc * * 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 @@ -18,4 +18,5 @@ #pragma once #include +#include #include diff --git a/src/Kaleidoscope/HostOS-Base.cpp b/src/Kaleidoscope/HostOS-Base.cpp index e728045d..d3207bcf 100644 --- a/src/Kaleidoscope/HostOS-Base.cpp +++ b/src/Kaleidoscope/HostOS-Base.cpp @@ -55,20 +55,5 @@ void Base::os(Type new_os) { EEPROM.update(eeprom_slice_, os_); } -bool Base::focusHook(const char *command) { - if (strcmp_P(command, PSTR("hostos.type")) != 0) - return false; - - if (Serial.peek() == '\n') { - Serial.println(::HostOS.os()); - } else { - uint8_t new_os = Serial.parseInt(); - ::HostOS.os((Type) new_os); - } - - Serial.read(); - return true; -} - } } diff --git a/src/Kaleidoscope/HostOS-Base.h b/src/Kaleidoscope/HostOS-Base.h index 3b83ad34..84d546e1 100644 --- a/src/Kaleidoscope/HostOS-Base.h +++ b/src/Kaleidoscope/HostOS-Base.h @@ -38,8 +38,6 @@ class Base : public kaleidoscope::Plugin { Type os(void); void os(Type new_os); - static bool focusHook(const char *command); - protected: virtual void autoDetect(void) {} Type os_; @@ -53,5 +51,3 @@ class Base : public kaleidoscope::Plugin { } 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 new file mode 100644 index 00000000..930d6d6e --- /dev/null +++ b/src/Kaleidoscope/HostOS-Focus.cpp @@ -0,0 +1,46 @@ +/* -*- mode: c++ -*- + * Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope + * Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc + * + * 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, version 3. + * + * 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 kaleidoscope { +namespace hostos { + +EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *command) { + const char *cmd = PSTR("hostos.type"); + + if (::Focus.handleHelp(command, cmd)) + return EventHandlerResult::OK; + if (strcmp_P(command, cmd) != 0) + return EventHandlerResult::OK; + + if (Serial.peek() == '\n') { + Serial.println(::HostOS.os()); + } else { + uint8_t new_os = Serial.parseInt(); + ::HostOS.os((Type) new_os); + } + + Serial.read(); + return EventHandlerResult::EVENT_CONSUMED; +} + +} +} + +kaleidoscope::hostos::FocusHostOSCommand FocusHostOSCommand; diff --git a/src/Kaleidoscope/HostOS-Focus.h b/src/Kaleidoscope/HostOS-Focus.h new file mode 100644 index 00000000..e40a47df --- /dev/null +++ b/src/Kaleidoscope/HostOS-Focus.h @@ -0,0 +1,34 @@ +/* -*- mode: c++ -*- + * Kaleidoscope-HostOS -- Host OS detection and tracking for Kaleidoscope + * Copyright (C) 2016, 2017, 2018 Keyboard.io, Inc + * + * 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, version 3. + * + * 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 kaleidoscope { +namespace hostos { + +class FocusHostOSCommand : public kaleidoscope::Plugin { + public: + FocusHostOSCommand() {} + EventHandlerResult onFocusEvent(const char *command); +}; + +} +} + +extern kaleidoscope::hostos::FocusHostOSCommand FocusHostOSCommand;