Greatly simplify the plugin by removing auto-detection

The `FingerprintUSBHost` library isn't the most reliable thing, so instead of
setting false expectations, remove auto-detection instead. This makes the plugin
a whole lost simpler, and depend on one less library.

Fixes #9.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/389/head
Gergely Nagy 6 years ago
parent 74f5f6d2e7
commit 985e31b48b
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

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

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

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

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

@ -20,7 +20,6 @@
#include <Kaleidoscope.h>
namespace kaleidoscope {
namespace hostos {
class FocusHostOSCommand : public kaleidoscope::Plugin {
public:
@ -28,7 +27,6 @@ class FocusHostOSCommand : public kaleidoscope::Plugin {
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
#include <Kaleidoscope/HostOS-Base.h>
#include <Kaleidoscope/HostOS-Guesser.h>
#if KALEIDOSCOPE_HOSTOS_GUESSER
kaleidoscope::hostos::Base HostOS = kaleidoscope::hostos::Guesser();
#else
kaleidoscope::hostos::Base HostOS;
#endif
#warning <Kaleidoscope/HostOS-select.h> is an obsolete header, and can be safely removed.

@ -15,15 +15,14 @@
* 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 <EEPROM.h>
namespace kaleidoscope {
namespace hostos {
EventHandlerResult Base::onSetup(void) {
EventHandlerResult HostOS::onSetup(void) {
if (is_configured_)
return EventHandlerResult::OK;
@ -31,29 +30,20 @@ EventHandlerResult Base::onSetup(void) {
is_configured_ = true;
if (os_ != AUTO) {
if (os_ != hostos::UNKNOWN) {
return EventHandlerResult::OK;
}
if ((os_ = (Type)EEPROM.read(eeprom_slice_)) != AUTO)
return EventHandlerResult::OK;
autoDetect();
os_ = (hostos::Type)EEPROM.read(eeprom_slice_);
return EventHandlerResult::OK;
}
Type Base::os(void) {
if (os_ == AUTO)
autoDetect();
return os_;
}
void Base::os(Type new_os) {
void HostOS::os(hostos::Type new_os) {
os_ = new_os;
EEPROM.update(eeprom_slice_, os_);
}
}
}
kaleidoscope::HostOS HostOS;

@ -28,26 +28,36 @@ typedef enum {
WINDOWS,
OTHER,
AUTO = 0xff,
UNKNOWN = 0xff,
AUTO = UNKNOWN
} 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:
HostOS() {}
EventHandlerResult onSetup();
Type os(void);
void os(Type new_os);
hostos::Type os(void) {
return os_;
}
void os(hostos::Type new_os);
protected:
virtual void autoDetect(void) {}
Type os_;
void autoDetect() DEPRECATED(AUTODETECT) {}
private:
hostos::Type os_;
uint16_t eeprom_slice_;
bool is_configured_ = false;
};
}
}
extern kaleidoscope::hostos::Base HostOS;
extern kaleidoscope::HostOS HostOS;
Loading…
Cancel
Save