Merge pull request #10 from keyboardio/f/no-fingerprint

Greatly simplify the plugin by removing auto-detection
pull/389/head
Gergely Nagy 6 years ago committed by GitHub
commit 97ce885b5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -7,13 +7,11 @@
The `HostOS` extension is not all that useful in itself, rather, it is a 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 building block other plugins and extensions can use to not repeat the same
guesswork and logic. Its primary purpose is to help either detect, or keep track guesswork and logic.
of the host operating system. The detection part is not the most reliable thing,
mind you.
The goal is to have a single place that remembers the host OS, either detected, The goal is to have a single place that remembers the host OS, whether set by
or set by the end-user, in a Sketch, or via a macro, or some other way. This the end-user in a Sketch, or via a macro, or some other way. This information
information can then be reused by other plugins. can then be reused by other plugins.
See the [Unicode][plugin:unicode] extension for an example about how to use See the [Unicode][plugin:unicode] extension for an example about how to use
`HostOS` in practice. `HostOS` in practice.
@ -22,20 +20,11 @@ See the [Unicode][plugin:unicode] extension for an example about how to use
## Using the extension ## Using the extension
The extension provides a `HostOS` singleton object. It can either be a simple The extension provides a `HostOS` singleton object.
one without auto-detection (the default), or one that will try to detect the
Host OS, using the [FingerprintUSBHost][fprdetect] library. To enable
auto-detection, `KALEIDOSCOPE_HOSTOS_GUESSER` must be defined before including
the `HostOS` library header.
[fprdetect]: https://github.com/keyboardio/FingerprintUSBHost
```c++ ```c++
#define KALEIDOSCOPE_HOSTOS_GUESSER 1
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-HostOS.h> #include <Kaleidoscope-HostOS.h>
#include <Kaleidoscope/HostOS-select.h>
void someFunction(void) { void someFunction(void) {
if (HostOS.os() == kaleidoscope::hostos::LINUX) { if (HostOS.os() == kaleidoscope::hostos::LINUX) {
@ -46,16 +35,13 @@ void someFunction(void) {
} }
} }
KALEIDOSCOPE_INIT_PLUGINS(HostOS); KALEIDOSCOPE_INIT_PLUGINS(HostOS)
void setup(void) { void setup(void) {
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```
To be able to choose between the two variants, one must also include the
`Kaleidoscope/HostOS-select.h` header.
## Extension methods ## Extension methods
The extension provides the following methods on the `HostOS` singleton: The extension provides the following methods on the `HostOS` singleton:

@ -16,7 +16,6 @@
*/ */
#include <Kaleidoscope-HostOS.h> #include <Kaleidoscope-HostOS.h>
#include <Kaleidoscope/HostOS-select.h>
// *INDENT-OFF* // *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {

@ -17,6 +17,5 @@
#pragma once #pragma once
#include <Kaleidoscope/HostOS-Base.h> #include <Kaleidoscope/HostOS.h>
#include <Kaleidoscope/HostOS-Focus.h> #include <Kaleidoscope/HostOS-Focus.h>
#include <Kaleidoscope/HostOS-Guesser.h>

@ -19,7 +19,6 @@
#include <Kaleidoscope-FocusSerial.h> #include <Kaleidoscope-FocusSerial.h>
namespace kaleidoscope { namespace kaleidoscope {
namespace hostos {
EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *command) { EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *command) {
const char *cmd = PSTR("hostos.type"); const char *cmd = PSTR("hostos.type");
@ -33,14 +32,13 @@ EventHandlerResult FocusHostOSCommand::onFocusEvent(const char *command) {
Serial.println(::HostOS.os()); Serial.println(::HostOS.os());
} else { } else {
uint8_t new_os = Serial.parseInt(); uint8_t new_os = Serial.parseInt();
::HostOS.os((Type) new_os); ::HostOS.os((hostos::Type) new_os);
} }
Serial.read(); Serial.read();
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
}
} }
kaleidoscope::hostos::FocusHostOSCommand FocusHostOSCommand; kaleidoscope::FocusHostOSCommand FocusHostOSCommand;

@ -20,7 +20,6 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace kaleidoscope { namespace kaleidoscope {
namespace hostos {
class FocusHostOSCommand : public kaleidoscope::Plugin { class FocusHostOSCommand : public kaleidoscope::Plugin {
public: public:
@ -28,7 +27,6 @@ class FocusHostOSCommand : public kaleidoscope::Plugin {
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
}; };
}
} }
extern kaleidoscope::hostos::FocusHostOSCommand FocusHostOSCommand; extern kaleidoscope::FocusHostOSCommand FocusHostOSCommand;

@ -1,47 +0,0 @@
/* -*- 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 <http://www.gnu.org/licenses/>.
*/
#include <Kaleidoscope/HostOS-Guesser.h>
#include <FingerprintUSBHost.h>
namespace kaleidoscope {
namespace hostos {
void Guesser::autoDetect(void) {
Serial.begin(9600);
delay(15000);
switch (FingerprintUSBHost.guessHostOS()) {
case GuessedHost::WINDOWS:
os_ = WINDOWS;
break;
case GuessedHost::LINUX:
os_ = LINUX;
break;
case GuessedHost::MACOS:
os_ = OSX;
break;
default:
os_ = OTHER;
break;
}
}
}
}

@ -1,34 +0,0 @@
/* -*- 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <Kaleidoscope/HostOS-Base.h>
namespace kaleidoscope {
namespace hostos {
class Guesser : public Base {
public:
Guesser(void) {}
protected:
void autoDetect(void) final;
};
}
}

@ -17,11 +17,4 @@
#pragma once #pragma once
#include <Kaleidoscope/HostOS-Base.h> #warning <Kaleidoscope/HostOS-select.h> is an obsolete header, and can be safely removed.
#include <Kaleidoscope/HostOS-Guesser.h>
#if KALEIDOSCOPE_HOSTOS_GUESSER
kaleidoscope::hostos::Base HostOS = kaleidoscope::hostos::Guesser();
#else
kaleidoscope::hostos::Base HostOS;
#endif

@ -15,15 +15,14 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Kaleidoscope/HostOS-Base.h> #include <Kaleidoscope/HostOS.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <EEPROM.h> #include <EEPROM.h>
namespace kaleidoscope { namespace kaleidoscope {
namespace hostos {
EventHandlerResult Base::onSetup(void) { EventHandlerResult HostOS::onSetup(void) {
if (is_configured_) if (is_configured_)
return EventHandlerResult::OK; return EventHandlerResult::OK;
@ -31,29 +30,20 @@ EventHandlerResult Base::onSetup(void) {
is_configured_ = true; is_configured_ = true;
if (os_ != AUTO) { if (os_ != hostos::UNKNOWN) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
if ((os_ = (Type)EEPROM.read(eeprom_slice_)) != AUTO) os_ = (hostos::Type)EEPROM.read(eeprom_slice_);
return EventHandlerResult::OK;
autoDetect();
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
Type Base::os(void) { void HostOS::os(hostos::Type new_os) {
if (os_ == AUTO)
autoDetect();
return os_;
}
void Base::os(Type new_os) {
os_ = new_os; os_ = new_os;
EEPROM.update(eeprom_slice_, os_); EEPROM.update(eeprom_slice_, os_);
} }
} }
}
kaleidoscope::HostOS HostOS;

@ -28,26 +28,36 @@ typedef enum {
WINDOWS, WINDOWS,
OTHER, OTHER,
AUTO = 0xff, UNKNOWN = 0xff,
AUTO = UNKNOWN
} Type; } Type;
class Base : public kaleidoscope::Plugin { }
#define _DEPRECATED_MESSAGE_AUTODETECT \
"The auto-detect mechanism of HostOS was removed, because it was\n" \
"too unreliable. As such, the HostOS.autoDetect() method does\n" \
"nothing anymore. Please consider other ways of changing the\n" \
"HostOS type."
class HostOS : public kaleidoscope::Plugin {
public: public:
HostOS() {}
EventHandlerResult onSetup(); EventHandlerResult onSetup();
Type os(void); hostos::Type os(void) {
void os(Type new_os); return os_;
}
void os(hostos::Type new_os);
protected: void autoDetect() DEPRECATED(AUTODETECT) {}
virtual void autoDetect(void) {}
Type os_;
private: private:
hostos::Type os_;
uint16_t eeprom_slice_; uint16_t eeprom_slice_;
bool is_configured_ = false; bool is_configured_ = false;
}; };
}
} }
extern kaleidoscope::hostos::Base HostOS; extern kaleidoscope::HostOS HostOS;
Loading…
Cancel
Save