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: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:broken]: https://img.shields.io/badge/broken-X-black.png?style=flat&colorA=e05d44&colorB=494e52
[st:experimental]: https://img.shields.io/badge/experimental----black.png?style=flat&colorA=dfb317&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.svg?style=flat&colorA=e05d44&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
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-select.h>
void someFunction (void) {
if (HostOS.os() == Kaleidoscope::HostOS::LINUX) {
void someFunction(void) {
if (HostOS.os() == kaleidoscope::HostOS::LINUX) {
// do something linux-y
}
if (HostOS.os() == Kaleidoscope::HostOS::OSX) {
if (HostOS.os() == kaleidoscope::HostOS::OSX) {
// do something OSX-y
}
}
void setup (void) {
Kaleidoscope.setup (KEYMAP_SIZE);
Kaleidoscope.use (&HostOS);
void setup(void) {
USE_PLUGINS(&HostOS);
Kaleidoscope.setup ();
}
```

@ -21,30 +21,29 @@
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
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_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_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
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_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_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip
),
(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_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_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
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_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_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_skip),
};
void setup() {
Serial.begin(9600);
Kaleidoscope.setup(KEYMAP_SIZE);
Kaleidoscope.use(&HostOS, NULL);
USE_PLUGINS(&HostOS);
Kaleidoscope.setup();
Serial.print("Host OS id is: ");
Serial.println(HostOS.os(), DEC);

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

@ -21,39 +21,53 @@
#include <EEPROM.h>
namespace KaleidoscopePlugins {
namespace HostOS {
void
Base::begin(void) {
if (isConfigured)
namespace kaleidoscope {
namespace hostos {
void Base::begin(void) {
if (is_configured_)
return;
eepromSlice = ::EEPROMSettings.requestSlice(sizeof(osType));
eeprom_slice_ = ::EEPROMSettings.requestSlice(sizeof(os_));
isConfigured = true;
is_configured_ = true;
if (osType != AUTO) {
if (os_ != AUTO) {
return;
}
if ((osType = (Type)EEPROM.read(eepromSlice)) != AUTO)
if ((os_ = (Type)EEPROM.read(eeprom_slice_)) != AUTO)
return;
autoDetect();
}
HostOS::Type
Base::os(void) {
if (osType == AUTO)
Type Base::os(void) {
if (os_ == AUTO)
autoDetect();
return osType;
return os_;
}
void Base::os(Type new_os) {
os_ = new_os;
EEPROM.update(eeprom_slice_, os_);
}
void
Base::os(HostOS::Type osType_) {
osType = osType_;
EEPROM.update(eepromSlice, osType);
bool Base::focusHook(const char *command) {
if (strcmp_P(command, PSTR("hostos.type")) != 0)
return false;
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>
namespace KaleidoscopePlugins {
namespace HostOS {
namespace kaleidoscope {
namespace hostos {
typedef enum {
LINUX,
OSX,
@ -36,17 +37,22 @@ class Base : public KaleidoscopePlugin {
void begin(void) final;
Type os(void);
void os(Type osType);
void os(Type new_os);
bool focusHook(const char *command);
protected:
virtual void autoDetect(void) {};
Type osType;
virtual void autoDetect(void) {}
Type os_;
private:
uint16_t eepromSlice;
bool isConfigured = false;
};
};
uint16_t eeprom_slice_;
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>
namespace KaleidoscopePlugins {
namespace HostOS {
namespace kaleidoscope {
namespace hostos {
Guesser::Guesser(void) {
}
void
Guesser::autoDetect(void) {
void Guesser::autoDetect(void) {
Serial.begin(9600);
delay(15000);
switch (FingerprintUSBHost.guessHostOS()) {
case GuessedHost::WINDOWS:
osType = WINDOWS;
os_ = WINDOWS;
break;
case GuessedHost::LINUX:
osType = LINUX;
os_ = LINUX;
break;
case GuessedHost::MACOS:
osType = OSX;
os_ = OSX;
break;
default:
osType = OTHER;
os_ = OTHER;
break;
}
}
};
};
}
}

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

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

Loading…
Cancel
Save