From d9da70c2f455a92cb5fa016766ece7f93d33b261 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 15 Mar 2017 15:59:59 +0100 Subject: [PATCH] Add Focus support helpers Signed-off-by: Gergely Nagy --- src/Kaleidoscope-HostOS.h | 1 + src/Kaleidoscope/HostOS-Focus.cpp | 54 +++++++++++++++++++++++++++++++ src/Kaleidoscope/HostOS-Focus.h | 36 +++++++++++++++++++++ 3 files changed, 91 insertions(+) create mode 100644 src/Kaleidoscope/HostOS-Focus.cpp create mode 100644 src/Kaleidoscope/HostOS-Focus.h diff --git a/src/Kaleidoscope-HostOS.h b/src/Kaleidoscope-HostOS.h index f3295a91..c3f9fd96 100644 --- a/src/Kaleidoscope-HostOS.h +++ b/src/Kaleidoscope-HostOS.h @@ -20,3 +20,4 @@ #include #include +#include diff --git a/src/Kaleidoscope/HostOS-Focus.cpp b/src/Kaleidoscope/HostOS-Focus.cpp new file mode 100644 index 00000000..fe5b45b3 --- /dev/null +++ b/src/Kaleidoscope/HostOS-Focus.cpp @@ -0,0 +1,54 @@ +/* -*- 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) { + enum { + GET, + SET, + } subCommand; + + if (strncmp_P (command, PSTR ("hostos."), 7) != 0) + return false; + if (strcmp_P (command + 7, PSTR ("type")) == 0) + subCommand = GET; + else if (strcmp_P (command + 7, PSTR ("set")) == 0) + subCommand = SET; + else + return false; + + switch (subCommand) { + case GET: + Serial.println (::HostOS.os ()); + break; + case SET: + uint8_t os = Serial.parseInt (); + ::HostOS.os ((KaleidoscopePlugins::HostOS::Type) os); + break; + } + + Serial.read (); + return true; + } + } +} diff --git a/src/Kaleidoscope/HostOS-Focus.h b/src/Kaleidoscope/HostOS-Focus.h new file mode 100644 index 00000000..7d104b76 --- /dev/null +++ b/src/Kaleidoscope/HostOS-Focus.h @@ -0,0 +1,36 @@ +/* -*- 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\n" \ + "-----------\n" \ + "Display the OS type, as known to the plugin.\n\n" \ + "hostos.set type\n" \ + "---------------\n" \ + "Set the OS type.")