Kaleidoscope Style Guide conformance

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
pull/389/head
Gergely Nagy 8 years ago
parent 54d6241e67
commit 129272883a

@ -5,9 +5,9 @@
[travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-HostOS.svg?branch=master [travis:image]: https://travis-ci.org/keyboardio/Kaleidoscope-HostOS.svg?branch=master
[travis:status]: https://travis-ci.org/keyboardio/Kaleidoscope-HostOS [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: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.png?style=flat&colorA=e05d44&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.png?style=flat&colorA=dfb317&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 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
@ -41,18 +41,19 @@ the `HostOS` library header.
#include <Kaleidoscope-HostOS.h> #include <Kaleidoscope-HostOS.h>
#include <Kaleidoscope/HostOS-select.h> #include <Kaleidoscope/HostOS-select.h>
void someFunction (void) { void someFunction(void) {
if (HostOS.os() == Kaleidoscope::HostOS::LINUX) { if (HostOS.os() == kaleidoscope::HostOS::LINUX) {
// do something linux-y // do something linux-y
} }
if (HostOS.os() == Kaleidoscope::HostOS::OSX) { if (HostOS.os() == kaleidoscope::HostOS::OSX) {
// do something OSX-y // do something OSX-y
} }
} }
void setup (void) { void setup(void) {
Kaleidoscope.setup (KEYMAP_SIZE); USE_PLUGINS(&HostOS);
Kaleidoscope.use (&HostOS);
Kaleidoscope.setup ();
} }
``` ```

@ -21,30 +21,29 @@
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
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_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_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_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift, Key_skip,
Key_skip,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, 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_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_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_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_skip),
Key_skip
),
}; };
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Kaleidoscope.setup(KEYMAP_SIZE); USE_PLUGINS(&HostOS);
Kaleidoscope.use(&HostOS, NULL);
Kaleidoscope.setup();
Serial.print("Host OS id is: "); Serial.print("Host OS id is: ");
Serial.println(HostOS.os(), DEC); Serial.println(HostOS.os(), DEC);

@ -20,4 +20,3 @@
#include <Kaleidoscope/HostOS-Base.h> #include <Kaleidoscope/HostOS-Base.h>
#include <Kaleidoscope/HostOS-Guesser.h> #include <Kaleidoscope/HostOS-Guesser.h>
#include <Kaleidoscope/HostOS-Focus.h>

@ -21,39 +21,53 @@
#include <EEPROM.h> #include <EEPROM.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace HostOS { namespace hostos {
void
Base::begin(void) { void Base::begin(void) {
if (isConfigured) if (is_configured_)
return; return;
eepromSlice = ::EEPROMSettings.requestSlice(sizeof(osType)); eeprom_slice_ = ::EEPROMSettings.requestSlice(sizeof(os_));
isConfigured = true; is_configured_ = true;
if (osType != AUTO) { if (os_ != AUTO) {
return; return;
} }
if ((osType = (Type)EEPROM.read(eepromSlice)) != AUTO) if ((os_ = (Type)EEPROM.read(eeprom_slice_)) != AUTO)
return; return;
autoDetect(); autoDetect();
} }
HostOS::Type Type Base::os(void) {
Base::os(void) { if (os_ == AUTO)
if (osType == AUTO)
autoDetect(); autoDetect();
return osType; return os_;
}
void Base::os(Type new_os) {
os_ = new_os;
EEPROM.update(eeprom_slice_, os_);
} }
void bool Base::focusHook(const char *command) {
Base::os(HostOS::Type osType_) { if (strcmp_P(command, PSTR("hostos.type")) != 0)
osType = osType_; return false;
EEPROM.update(eepromSlice, osType);
if (Serial.peek() == '\n') {
Serial.println(os_);
} else {
uint8_t new_os = Serial.parseInt();
os((Type) new_os);
}
Serial.read();
return true;
}
}
} }
};
};

@ -20,8 +20,9 @@
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace HostOS { namespace hostos {
typedef enum { typedef enum {
LINUX, LINUX,
OSX, OSX,
@ -36,17 +37,22 @@ class Base : public KaleidoscopePlugin {
void begin(void) final; void begin(void) final;
Type os(void); Type os(void);
void os(Type osType); void os(Type new_os);
bool focusHook(const char *command);
protected: protected:
virtual void autoDetect(void) {}; virtual void autoDetect(void) {}
Type osType; Type os_;
private: private:
uint16_t eepromSlice; uint16_t eeprom_slice_;
bool isConfigured = false; bool is_configured_ = false;
};
};
}; };
extern KaleidoscopePlugins::HostOS::Base HostOS; }
}
extern kaleidoscope::hostos::Base HostOS;
#define FOCUS_HOOK_HOSTOS FOCUS_HOOK(HostOS.focusHook, "hostos.type")

@ -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 <http://www.gnu.org/licenses/>.
*/
#include <Kaleidoscope/HostOS-Base.h>
#include <Kaleidoscope/HostOS-Focus.h>
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;
}
}
}

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <Kaleidoscope/HostOS-Base.h>
namespace KaleidoscopePlugins {
namespace HostOS {
bool Focus(const char *command);
};
};
#define FOCUS_HOOK_HOSTOS \
FOCUS_HOOK(KaleidoscopePlugins::HostOS::Focus, "hostos.type")

@ -20,31 +20,32 @@
#include <FingerprintUSBHost.h> #include <FingerprintUSBHost.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace HostOS { namespace hostos {
Guesser::Guesser(void) { Guesser::Guesser(void) {
} }
void void Guesser::autoDetect(void) {
Guesser::autoDetect(void) {
Serial.begin(9600); Serial.begin(9600);
delay(15000); delay(15000);
switch (FingerprintUSBHost.guessHostOS()) { switch (FingerprintUSBHost.guessHostOS()) {
case GuessedHost::WINDOWS: case GuessedHost::WINDOWS:
osType = WINDOWS; os_ = WINDOWS;
break; break;
case GuessedHost::LINUX: case GuessedHost::LINUX:
osType = LINUX; os_ = LINUX;
break; break;
case GuessedHost::MACOS: case GuessedHost::MACOS:
osType = OSX; os_ = OSX;
break; break;
default: default:
osType = OTHER; os_ = OTHER;
break; break;
} }
} }
};
}; }
}

@ -20,14 +20,16 @@
#include <Kaleidoscope/HostOS-Base.h> #include <Kaleidoscope/HostOS-Base.h>
namespace KaleidoscopePlugins { namespace kaleidoscope {
namespace HostOS { namespace hostos {
class Guesser : public Base { class Guesser : public Base {
public: public:
Guesser(void); Guesser(void);
protected: protected:
virtual void autoDetect(void) final; void autoDetect(void) final;
}; };
}
} }
};

@ -22,7 +22,7 @@
#include <Kaleidoscope/HostOS-Guesser.h> #include <Kaleidoscope/HostOS-Guesser.h>
#if KALEIDOSCOPE_HOSTOS_GUESSER #if KALEIDOSCOPE_HOSTOS_GUESSER
KaleidoscopePlugins::HostOS::Base HostOS = KaleidoscopePlugins::HostOS::Guesser(); kaleidoscope::hostos::Base HostOS = kaleidoscope::hostos::Guesser();
#else #else
KaleidoscopePlugins::HostOS::Base HostOS; kaleidoscope::hostos::Base HostOS;
#endif #endif

Loading…
Cancel
Save