Merge pull request #701 from keyboardio/hardware/storage-and-serialport-abstraction

Storage & Serial abstraction
pull/704/head
Jesse Vincent 5 years ago committed by GitHub
commit 9ee9d34a8f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -17,7 +17,7 @@ the box, without any further configuration:
KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport); KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport);
void setup (void) { void setup (void) {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```

@ -43,7 +43,7 @@ void setup () {
return; return;
} }
EEPROM.get(settingsBase, testSettings); KeyboardHardware.storage().get(settingsBase, testSettings);
} }
``` ```

@ -32,11 +32,11 @@ dictionary:
#include <Kaleidoscope-Leader.h> #include <Kaleidoscope-Leader.h>
static void leaderA(uint8_t seq_index) { static void leaderA(uint8_t seq_index) {
Serial.println("leaderA"); KeyboardHardware.serialPort().println("leaderA");
} }
static void leaderTX(uint8_t seq_index) { static void leaderTX(uint8_t seq_index) {
Serial.println("leaderTX"); KeyboardHardware.serialPort().println("leaderTX");
} }
static const kaleidoscope::Leader::dictionary_t leader_dictionary[] PROGMEM = static const kaleidoscope::Leader::dictionary_t leader_dictionary[] PROGMEM =
@ -46,7 +46,7 @@ static const kaleidoscope::Leader::dictionary_t leader_dictionary[] PROGMEM =
KALEIDOSCOPE_INIT_PLUGINS(Leader); KALEIDOSCOPE_INIT_PLUGINS(Leader);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup(); Kaleidoscope.setup();

@ -34,8 +34,8 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym
kaleidoscope::hid::sendKeyboardReport (); kaleidoscope::hid::sendKeyboardReport ();
break; break;
case kaleidoscope::plugin::Syster::SymbolAction: case kaleidoscope::plugin::Syster::SymbolAction:
Serial.print ("systerAction: symbol="); KeyboardHardware.serialPort().print ("systerAction: symbol=");
Serial.println (symbol); KeyboardHardware.serialPort().println (symbol);
if (strcmp (symbol, "coffee") == 0) { if (strcmp (symbol, "coffee") == 0) {
Unicode.type (0x2615); Unicode.type (0x2615);
} }
@ -46,7 +46,7 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, HostOS, Unicode, Syster); KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, HostOS, Unicode, Syster);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```

@ -86,7 +86,7 @@ static kaleidoscope::plugin::LEDSolidColor solidViolet(70, 0, 60);
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {
if (macroIndex == 1 && keyToggledOn(keyState)) { if (macroIndex == 1 && keyToggledOn(keyState)) {
Serial.print("Keyboard.IO keyboard driver v0.00"); KeyboardHardware.serialPort().print("Keyboard.IO keyboard driver v0.00");
return MACRO(I(25), return MACRO(I(25),
D(LeftShift), T(M), U(LeftShift), T(O), T(D), T(E), T(L), D(LeftShift), T(M), U(LeftShift), T(O), T(D), T(E), T(L),
T(Spacebar), T(Spacebar),

@ -167,7 +167,7 @@ KALEIDOSCOPE_INIT_PLUGINS(Macros);
void setup() { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
} }
void loop() { void loop() {

@ -50,7 +50,7 @@ KEYMAPS(
KALEIDOSCOPE_INIT_PLUGINS(GeminiPR); KALEIDOSCOPE_INIT_PLUGINS(GeminiPR);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup(); Kaleidoscope.setup();
} }

@ -43,7 +43,7 @@ KEYMAPS(
KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport); KALEIDOSCOPE_INIT_PLUGINS(CycleTimeReport);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup(); Kaleidoscope.setup();
} }

@ -56,7 +56,7 @@ KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings,
Macros); Macros);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup(); Kaleidoscope.setup();

@ -42,16 +42,16 @@ KEYMAPS(
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings); KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup(); Kaleidoscope.setup();
while (!Serial) { while (!KeyboardHardware.serialPort()) {
} }
Serial.println(EEPROMSettings.isValid() ? F("valid EEPROM settings") : F("invalid EEPROM settings")); KeyboardHardware.serialPort().println(EEPROMSettings.isValid() ? F("valid EEPROM settings") : F("invalid EEPROM settings"));
Serial.println(EEPROMSettings.crc(), HEX); KeyboardHardware.serialPort().println(EEPROMSettings.crc(), HEX);
Serial.println(EEPROMSettings.version()); KeyboardHardware.serialPort().println(EEPROMSettings.version());
} }
void loop() { void loop() {

@ -43,12 +43,12 @@ KEYMAPS(
KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, HostOS); KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings, HostOS);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup(); Kaleidoscope.setup();
Serial.print("Host OS id is: "); KeyboardHardware.serialPort().print("Host OS id is: ");
Serial.println(HostOS.os(), DEC); KeyboardHardware.serialPort().println(HostOS.os(), DEC);
} }
void loop() { void loop() {

@ -61,7 +61,7 @@ KEYMAPS(
KALEIDOSCOPE_INIT_PLUGINS(GeminiPR); KALEIDOSCOPE_INIT_PLUGINS(GeminiPR);
void setup() { void setup() {
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
Kaleidoscope.setup(); Kaleidoscope.setup();
} }

@ -40,11 +40,11 @@ KEYMAPS(
// *INDENT-ON* // *INDENT-ON*
static void leaderTestA(uint8_t seq_index) { static void leaderTestA(uint8_t seq_index) {
Serial.println(F("leaderTestA")); KeyboardHardware.serialPort().println(F("leaderTestA"));
} }
static void leaderTestAA(uint8_t seq_index) { static void leaderTestAA(uint8_t seq_index) {
Serial.println(F("leaderTestAA")); KeyboardHardware.serialPort().println(F("leaderTestAA"));
} }
static const kaleidoscope::plugin::Leader::dictionary_t leader_dictionary[] PROGMEM = static const kaleidoscope::plugin::Leader::dictionary_t leader_dictionary[] PROGMEM =

@ -56,8 +56,8 @@ void systerAction(kaleidoscope::plugin::Syster::action_t action, const char *sym
kaleidoscope::hid::sendKeyboardReport(); kaleidoscope::hid::sendKeyboardReport();
break; break;
case kaleidoscope::plugin::Syster::SymbolAction: case kaleidoscope::plugin::Syster::SymbolAction:
Serial.print("systerAction: symbol="); KeyboardHardware.serialPort().print("systerAction: symbol=");
Serial.println(symbol); KeyboardHardware.serialPort().println(symbol);
if (strcmp(symbol, "coffee") == 0) { if (strcmp(symbol, "coffee") == 0) {
Unicode.type(0x2615); Unicode.type(0x2615);
} }

@ -24,6 +24,8 @@
#include "kaleidoscope/MatrixAddr.h" #include "kaleidoscope/MatrixAddr.h"
#include "kaleidoscope_internal/deprecations.h" #include "kaleidoscope_internal/deprecations.h"
#include "EEPROM.h"
#ifndef CRGB #ifndef CRGB
#error cRGB and CRGB *must* be defined before including this header! #error cRGB and CRGB *must* be defined before including this header!
#endif #endif
@ -385,6 +387,20 @@ class Hardware {
*/ */
void enableHardwareTestMode() {} void enableHardwareTestMode() {}
/**
* Method to return the object the hardware uses for storage.
*/
auto storage() -> decltype(EEPROM) & {
return EEPROM;
}
/**
* Method to return the serial port object used by the hardware.
*/
auto serialPort() -> decltype(Serial) & {
return Serial;
}
/** @} */ /** @} */
}; };
} }

@ -34,7 +34,7 @@ Kaleidoscope_::setup(void) {
// //
// TODO(anyone): Figure out a way we can get rid of this, and fix the bug // TODO(anyone): Figure out a way we can get rid of this, and fix the bug
// properly. // properly.
Serial.begin(9600); KeyboardHardware.serialPort().begin(9600);
kaleidoscope::Hooks::onSetup(); kaleidoscope::Hooks::onSetup();

@ -49,7 +49,7 @@ static void playKeyCode(Key key, uint8_t keyStates, bool explicit_report) {
static void readKeyCodeAndPlay(uint16_t pos, uint8_t flags, uint8_t keyStates, bool explicit_report) { static void readKeyCodeAndPlay(uint16_t pos, uint8_t flags, uint8_t keyStates, bool explicit_report) {
Key key; Key key;
key.flags = flags; key.flags = flags;
key.keyCode = EEPROM.read(pos++); key.keyCode = KeyboardHardware.storage().read(pos++);
playKeyCode(key, keyStates, explicit_report); playKeyCode(key, keyStates, explicit_report);
} }
@ -63,7 +63,7 @@ void DynamicMacros::updateDynamicMacroCache(void) {
map_[0] = 0; map_[0] = 0;
while (pos < storage_base_ + storage_size_) { while (pos < storage_base_ + storage_size_) {
macro = EEPROM.read(pos++); macro = KeyboardHardware.storage().read(pos++);
switch (macro) { switch (macro) {
case MACRO_ACTION_STEP_EXPLICIT_REPORT: case MACRO_ACTION_STEP_EXPLICIT_REPORT:
case MACRO_ACTION_STEP_IMPLICIT_REPORT: case MACRO_ACTION_STEP_IMPLICIT_REPORT:
@ -91,8 +91,8 @@ void DynamicMacros::updateDynamicMacroCache(void) {
previous_macro_ended = false; previous_macro_ended = false;
uint8_t keyCode, flags; uint8_t keyCode, flags;
do { do {
flags = EEPROM.read(pos++); flags = KeyboardHardware.storage().read(pos++);
keyCode = EEPROM.read(pos++); keyCode = KeyboardHardware.storage().read(pos++);
} while (!(flags == 0 && keyCode == 0)); } while (!(flags == 0 && keyCode == 0));
break; break;
} }
@ -101,7 +101,7 @@ void DynamicMacros::updateDynamicMacroCache(void) {
previous_macro_ended = false; previous_macro_ended = false;
uint8_t keyCode, flags; uint8_t keyCode, flags;
do { do {
keyCode = EEPROM.read(pos++); keyCode = KeyboardHardware.storage().read(pos++);
} while (keyCode != 0); } while (keyCode != 0);
break; break;
} }
@ -128,7 +128,7 @@ void DynamicMacros::play(uint8_t macro_id) {
pos = storage_base_ + map_[macro_id]; pos = storage_base_ + map_[macro_id];
while (true) { while (true) {
switch (macro = EEPROM.read(pos++)) { switch (macro = KeyboardHardware.storage().read(pos++)) {
case MACRO_ACTION_STEP_EXPLICIT_REPORT: case MACRO_ACTION_STEP_EXPLICIT_REPORT:
explicit_report = true; explicit_report = true;
break; break;
@ -140,23 +140,23 @@ void DynamicMacros::play(uint8_t macro_id) {
kaleidoscope::hid::sendMouseReport(); kaleidoscope::hid::sendMouseReport();
break; break;
case MACRO_ACTION_STEP_INTERVAL: case MACRO_ACTION_STEP_INTERVAL:
interval = EEPROM.read(pos++); interval = KeyboardHardware.storage().read(pos++);
break; break;
case MACRO_ACTION_STEP_WAIT: { case MACRO_ACTION_STEP_WAIT: {
uint8_t wait = EEPROM.read(pos++); uint8_t wait = KeyboardHardware.storage().read(pos++);
delay(wait); delay(wait);
break; break;
} }
case MACRO_ACTION_STEP_KEYDOWN: case MACRO_ACTION_STEP_KEYDOWN:
flags = EEPROM.read(pos++); flags = KeyboardHardware.storage().read(pos++);
readKeyCodeAndPlay(pos++, flags, IS_PRESSED, explicit_report); readKeyCodeAndPlay(pos++, flags, IS_PRESSED, explicit_report);
break; break;
case MACRO_ACTION_STEP_KEYUP: case MACRO_ACTION_STEP_KEYUP:
flags = EEPROM.read(pos++); flags = KeyboardHardware.storage().read(pos++);
readKeyCodeAndPlay(pos++, flags, WAS_PRESSED, explicit_report); readKeyCodeAndPlay(pos++, flags, WAS_PRESSED, explicit_report);
break; break;
case MACRO_ACTION_STEP_TAP: case MACRO_ACTION_STEP_TAP:
flags = EEPROM.read(pos++); flags = KeyboardHardware.storage().read(pos++);
readKeyCodeAndPlay(pos++, flags, IS_PRESSED | WAS_PRESSED, false); readKeyCodeAndPlay(pos++, flags, IS_PRESSED | WAS_PRESSED, false);
break; break;
@ -173,8 +173,8 @@ void DynamicMacros::play(uint8_t macro_id) {
case MACRO_ACTION_STEP_TAP_SEQUENCE: { case MACRO_ACTION_STEP_TAP_SEQUENCE: {
uint8_t keyCode; uint8_t keyCode;
do { do {
flags = EEPROM.read(pos++); flags = KeyboardHardware.storage().read(pos++);
keyCode = EEPROM.read(pos++); keyCode = KeyboardHardware.storage().read(pos++);
playKeyCode(Key(keyCode, flags), IS_PRESSED | WAS_PRESSED, false); playKeyCode(Key(keyCode, flags), IS_PRESSED | WAS_PRESSED, false);
delay(interval); delay(interval);
} while (!(flags == 0 && keyCode == 0)); } while (!(flags == 0 && keyCode == 0));
@ -183,7 +183,7 @@ void DynamicMacros::play(uint8_t macro_id) {
case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: { case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: {
uint8_t keyCode; uint8_t keyCode;
do { do {
keyCode = EEPROM.read(pos++); keyCode = KeyboardHardware.storage().read(pos++);
playKeyCode(Key(keyCode, 0), IS_PRESSED | WAS_PRESSED, false); playKeyCode(Key(keyCode, 0), IS_PRESSED | WAS_PRESSED, false);
delay(interval); delay(interval);
} while (keyCode != 0); } while (keyCode != 0);
@ -221,7 +221,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) {
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
for (uint16_t i = 0; i < storage_size_; i++) { for (uint16_t i = 0; i < storage_size_; i++) {
uint8_t b; uint8_t b;
b = EEPROM.read(storage_base_ + i); b = KeyboardHardware.storage().read(storage_base_ + i);
::Focus.send(b); ::Focus.send(b);
} }
} else { } else {
@ -231,7 +231,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) {
uint8_t b; uint8_t b;
::Focus.read(b); ::Focus.read(b);
EEPROM.update(storage_base_ + pos++, b); KeyboardHardware.storage().update(storage_base_ + pos++, b);
} }
updateDynamicMacroCache(); updateDynamicMacroCache();
} }

@ -55,8 +55,8 @@ Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) {
uint16_t pos = ((layer * KeyboardHardware.numKeys()) + key_addr.toInt()) * 2; uint16_t pos = ((layer * KeyboardHardware.numKeys()) + key_addr.toInt()) * 2;
key.flags = EEPROM.read(keymap_base_ + pos); key.flags = KeyboardHardware.storage().read(keymap_base_ + pos);
key.keyCode = EEPROM.read(keymap_base_ + pos + 1); key.keyCode = KeyboardHardware.storage().read(keymap_base_ + pos + 1);
return key; return key;
} }
@ -77,8 +77,8 @@ uint16_t EEPROMKeymap::keymap_base(void) {
} }
void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) { void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) {
EEPROM.update(keymap_base_ + base_pos * 2, key.flags); KeyboardHardware.storage().update(keymap_base_ + base_pos * 2, key.flags);
EEPROM.update(keymap_base_ + base_pos * 2 + 1, key.keyCode); KeyboardHardware.storage().update(keymap_base_ + base_pos * 2 + 1, key.keyCode);
} }
void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) { void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) {

@ -28,7 +28,7 @@ bool EEPROMSettings::sealed_;
uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings); uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings);
EventHandlerResult EEPROMSettings::onSetup() { EventHandlerResult EEPROMSettings::onSetup() {
EEPROM.get(0, settings_); KeyboardHardware.storage().get(0, settings_);
/* If the version is undefined, set up sensible defaults. */ /* If the version is undefined, set up sensible defaults. */
if (settings_.version == VERSION_UNDEFINED) { if (settings_.version == VERSION_UNDEFINED) {
@ -49,7 +49,7 @@ EventHandlerResult EEPROMSettings::onSetup() {
* not able to catch all writes yet. For the sake of consistency, if we * not able to catch all writes yet. For the sake of consistency, if we
* encounter a firmware with no version defined, we'll set sensible * encounter a firmware with no version defined, we'll set sensible
* defaults. */ * defaults. */
EEPROM.put(0, settings_); KeyboardHardware.storage().put(0, settings_);
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -146,7 +146,7 @@ uint16_t EEPROMSettings::used(void) {
} }
void EEPROMSettings::update(void) { void EEPROMSettings::update(void) {
EEPROM.put(0, settings_); KeyboardHardware.storage().put(0, settings_);
is_valid_ = true; is_valid_ = true;
} }
@ -220,22 +220,22 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
switch (sub_command) { switch (sub_command) {
case CONTENTS: { case CONTENTS: {
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
for (uint16_t i = 0; i < EEPROM.length(); i++) { for (uint16_t i = 0; i < KeyboardHardware.storage().length(); i++) {
uint8_t d = EEPROM[i]; uint8_t d = KeyboardHardware.storage().read(i);
::Focus.send(d); ::Focus.send(d);
} }
} else { } else {
for (uint16_t i = 0; i < EEPROM.length() && !::Focus.isEOL(); i++) { for (uint16_t i = 0; i < KeyboardHardware.storage().length() && !::Focus.isEOL(); i++) {
uint8_t d; uint8_t d;
::Focus.read(d); ::Focus.read(d);
EEPROM.update(i, d); KeyboardHardware.storage().update(i, d);
} }
} }
break; break;
} }
case FREE: case FREE:
::Focus.send(EEPROM.length() - ::EEPROMSettings.used()); ::Focus.send(KeyboardHardware.storage().length() - ::EEPROMSettings.used());
break; break;
} }

@ -18,7 +18,6 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <EEPROM.h>
#define _DEPRECATED_MESSAGE_EEPROMSETTINGS_VERSION_SET \ #define _DEPRECATED_MESSAGE_EEPROMSETTINGS_VERSION_SET \
"The EEPROMSettings.version(uint8_t version) method has been deprecated,\n" \ "The EEPROMSettings.version(uint8_t version) method has been deprecated,\n" \

@ -101,7 +101,7 @@ EventHandlerResult FingerPainter::onFocusEvent(const char *command) {
if (sub_command == CLEAR) { if (sub_command == CLEAR) {
for (uint16_t i = 0; i < KeyboardHardware.numKeys() / 2; i++) { for (uint16_t i = 0; i < KeyboardHardware.numKeys() / 2; i++) {
EEPROM.update(color_base_ + i, 0); KeyboardHardware.storage().update(color_base_ + i, 0);
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -27,20 +27,20 @@ namespace plugin {
char FocusSerial::command_[32]; char FocusSerial::command_[32];
void FocusSerial::drain(void) { void FocusSerial::drain(void) {
if (Serial.available()) if (KeyboardHardware.serialPort().available())
while (Serial.peek() != '\n') while (KeyboardHardware.serialPort().peek() != '\n')
Serial.read(); KeyboardHardware.serialPort().read();
} }
EventHandlerResult FocusSerial::beforeReportingState() { EventHandlerResult FocusSerial::beforeReportingState() {
if (Serial.available() == 0) if (KeyboardHardware.serialPort().available() == 0)
return EventHandlerResult::OK; return EventHandlerResult::OK;
uint8_t i = 0; uint8_t i = 0;
do { do {
command_[i++] = Serial.read(); command_[i++] = KeyboardHardware.serialPort().read();
if (Serial.peek() == '\n') if (KeyboardHardware.serialPort().peek() == '\n')
break; break;
} while (command_[i - 1] != ' ' && i < 32); } while (command_[i - 1] != ' ' && i < 32);
if (command_[i - 1] == ' ') if (command_[i - 1] == ' ')
@ -50,12 +50,12 @@ EventHandlerResult FocusSerial::beforeReportingState() {
Kaleidoscope.onFocusEvent(command_); Kaleidoscope.onFocusEvent(command_);
Serial.println(F("\r\n.")); KeyboardHardware.serialPort().println(F("\r\n."));
drain(); drain();
if (Serial.peek() == '\n') if (KeyboardHardware.serialPort().peek() == '\n')
Serial.read(); KeyboardHardware.serialPort().read();
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -65,7 +65,7 @@ bool FocusSerial::handleHelp(const char *command,
if (strcmp_P(command, PSTR("help")) != 0) if (strcmp_P(command, PSTR("help")) != 0)
return false; return false;
Serial.println((const __FlashStringHelper *)help_message); KeyboardHardware.serialPort().println((const __FlashStringHelper *)help_message);
return true; return true;
} }
@ -75,7 +75,7 @@ EventHandlerResult FocusSerial::onFocusEvent(const char *command) {
} }
void FocusSerial::printBool(bool b) { void FocusSerial::printBool(bool b) {
Serial.print((b) ? F("true") : F("false")); KeyboardHardware.serialPort().print((b) ? F("true") : F("false"));
} }
} }

@ -37,12 +37,12 @@ class FocusSerial : public kaleidoscope::Plugin {
} }
void send(const bool b) { void send(const bool b) {
printBool(b); printBool(b);
Serial.print(SEPARATOR); KeyboardHardware.serialPort().print(SEPARATOR);
} }
template <typename V> template <typename V>
void send(V v) { void send(V v) {
Serial.print(v); KeyboardHardware.serialPort().print(v);
Serial.print(SEPARATOR); KeyboardHardware.serialPort().print(SEPARATOR);
} }
template <typename Var, typename... Vars> template <typename Var, typename... Vars>
void send(Var v, const Vars&... vars) { void send(Var v, const Vars&... vars) {
@ -53,31 +53,31 @@ class FocusSerial : public kaleidoscope::Plugin {
void sendRaw() {} void sendRaw() {}
template <typename Var, typename... Vars> template <typename Var, typename... Vars>
void sendRaw(Var v, const Vars&... vars) { void sendRaw(Var v, const Vars&... vars) {
Serial.print(v); KeyboardHardware.serialPort().print(v);
sendRaw(vars...); sendRaw(vars...);
} }
const char peek() { const char peek() {
return Serial.peek(); return KeyboardHardware.serialPort().peek();
} }
void read(Key &key) { void read(Key &key) {
key.raw = Serial.parseInt(); key.raw = KeyboardHardware.serialPort().parseInt();
} }
void read(cRGB &color) { void read(cRGB &color) {
color.r = Serial.parseInt(); color.r = KeyboardHardware.serialPort().parseInt();
color.g = Serial.parseInt(); color.g = KeyboardHardware.serialPort().parseInt();
color.b = Serial.parseInt(); color.b = KeyboardHardware.serialPort().parseInt();
} }
void read(uint8_t &u8) { void read(uint8_t &u8) {
u8 = Serial.parseInt(); u8 = KeyboardHardware.serialPort().parseInt();
} }
void read(uint16_t &u16) { void read(uint16_t &u16) {
u16 = Serial.parseInt(); u16 = KeyboardHardware.serialPort().parseInt();
} }
bool isEOL() { bool isEOL() {
return Serial.peek() == '\n'; return KeyboardHardware.serialPort().peek() == '\n';
} }
static constexpr char COMMENT = '#'; static constexpr char COMMENT = '#';

@ -39,7 +39,7 @@ EventHandlerResult GeminiPR::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr,
if (keys_held_ == 0) { if (keys_held_ == 0) {
state_[0] |= 0x80; state_[0] |= 0x80;
Serial.write(state_, sizeof(state_)); KeyboardHardware.serialPort().write(state_, sizeof(state_));
memset(state_, 0, sizeof(state_)); memset(state_, 0, sizeof(state_));
} }
} }

@ -18,8 +18,6 @@
#include <kaleidoscope/plugin/HostOS.h> #include <kaleidoscope/plugin/HostOS.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <EEPROM.h>
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -35,14 +33,14 @@ EventHandlerResult HostOS::onSetup(void) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
os_ = (hostos::Type)EEPROM.read(eeprom_slice_); os_ = (hostos::Type)KeyboardHardware.storage().read(eeprom_slice_);
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
void HostOS::os(hostos::Type new_os) { void HostOS::os(hostos::Type new_os) {
os_ = new_os; os_ = new_os;
EEPROM.update(eeprom_slice_, os_); KeyboardHardware.storage().update(eeprom_slice_, os_);
} }
} }

@ -58,7 +58,7 @@ void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_
const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) { const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) {
uint8_t color_index; uint8_t color_index;
color_index = EEPROM.read(map_base + position / 2); color_index = KeyboardHardware.storage().read(map_base + position / 2);
if (position % 2) if (position % 2)
color_index &= ~0xf0; color_index &= ~0xf0;
else else
@ -76,7 +76,7 @@ const cRGB LEDPaletteTheme::lookupColorAtPosition(uint16_t map_base, uint16_t po
const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) {
cRGB color; cRGB color;
EEPROM.get(palette_base_ + color_index * sizeof(cRGB), color); KeyboardHardware.storage().get(palette_base_ + color_index * sizeof(cRGB), color);
color.r ^= 0xff; color.r ^= 0xff;
color.g ^= 0xff; color.g ^= 0xff;
color.b ^= 0xff; color.b ^= 0xff;
@ -87,7 +87,7 @@ const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) {
void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) { void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) {
uint8_t indexes; uint8_t indexes;
indexes = EEPROM.read(map_base + position / 2); indexes = KeyboardHardware.storage().read(map_base + position / 2);
if (position % 2) { if (position % 2) {
uint8_t other = indexes >> 4; uint8_t other = indexes >> 4;
indexes = (other << 4) + color_index; indexes = (other << 4) + color_index;
@ -95,7 +95,7 @@ void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t pos
uint8_t other = indexes & ~0xf0; uint8_t other = indexes & ~0xf0;
indexes = (color_index << 4) + other; indexes = (color_index << 4) + other;
} }
EEPROM.update(map_base + position / 2, indexes); KeyboardHardware.storage().update(map_base + position / 2, indexes);
} }
EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) {
@ -129,7 +129,7 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) {
color.g ^= 0xff; color.g ^= 0xff;
color.b ^= 0xff; color.b ^= 0xff;
EEPROM.put(palette_base_ + i * sizeof(color), color); KeyboardHardware.storage().put(palette_base_ + i * sizeof(color), color);
i++; i++;
} }
@ -155,7 +155,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command,
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
for (uint16_t pos = 0; pos < max_index; pos++) { for (uint16_t pos = 0; pos < max_index; pos++) {
uint8_t indexes = EEPROM.read(theme_base + pos); uint8_t indexes = KeyboardHardware.storage().read(theme_base + pos);
::Focus.send((uint8_t)(indexes >> 4), indexes & ~0xf0); ::Focus.send((uint8_t)(indexes >> 4), indexes & ~0xf0);
} }
@ -171,7 +171,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command,
uint8_t indexes = (idx1 << 4) + idx2; uint8_t indexes = (idx1 << 4) + idx2;
EEPROM.update(theme_base + pos, indexes); KeyboardHardware.storage().update(theme_base + pos, indexes);
pos++; pos++;
} }

@ -159,13 +159,13 @@ void TestMode::toggle_programming_leds_on() {
} }
void TestMode::run_tests() { void TestMode::run_tests() {
// Serial.println("Running tests"); // KeyboardHardware.serialPort().println("Running tests");
toggle_programming_leds_on(); toggle_programming_leds_on();
// Disable debouncing // Disable debouncing
KeyboardHardware.setKeyscanInterval(2); KeyboardHardware.setKeyscanInterval(2);
test_leds(); test_leds();
testMatrix(); testMatrix();
// Serial.println("Done running tests"); // KeyboardHardware.serialPort().println("Done running tests");
} }
} }

@ -107,12 +107,12 @@ EventHandlerResult TypingBreaks::onSetup() {
// If idleTime is max, assume that EEPROM is uninitialized, and store the // If idleTime is max, assume that EEPROM is uninitialized, and store the
// defaults. // defaults.
uint32_t idle_time; uint32_t idle_time;
EEPROM.get(settings_base_, idle_time); KeyboardHardware.storage().get(settings_base_, idle_time);
if (idle_time == 0xffffffff) { if (idle_time == 0xffffffff) {
EEPROM.put(settings_base_, settings); KeyboardHardware.storage().put(settings_base_, settings);
} }
EEPROM.get(settings_base_, settings); KeyboardHardware.storage().get(settings_base_, settings);
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -192,7 +192,7 @@ EventHandlerResult TypingBreaks::onFocusEvent(const char *command) {
break; break;
} }
EEPROM.put(settings_base_, settings); KeyboardHardware.storage().put(settings_base_, settings);
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }

Loading…
Cancel
Save