From 06c2a71962b765e72391a3a72b55c4c5d5319182 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Wed, 5 Dec 2018 22:26:49 +0100 Subject: [PATCH] Initialize Serial from Kaleidoscope.setup() To work around an issue on OSX, initalize Serial as the very first thing in `Kaleidoscope.setup`. This is a - hopefully - temporary workaround, until we can track down the real issue. Signed-off-by: Gergely Nagy --- src/kaleidoscope/Kaleidoscope.cpp | 10 ++++++++++ src/kaleidoscope/plugin/FocusSerial.h | 4 ---- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/kaleidoscope/Kaleidoscope.cpp b/src/kaleidoscope/Kaleidoscope.cpp index 4aa602ec..3b4fc0a7 100644 --- a/src/kaleidoscope/Kaleidoscope.cpp +++ b/src/kaleidoscope/Kaleidoscope.cpp @@ -26,6 +26,16 @@ Kaleidoscope_::Kaleidoscope_(void) { void Kaleidoscope_::setup(void) { + // We are explicitly initializing the Serial port as early as possible to + // (temporarily, hopefully) work around an issue on OSX. If we initialize + // Serial too late, no matter what we do, we'll end up reading garbage from + // the serial port. For more information, see the following issue: + // https://github.com/keyboardio/Kaleidoscope-Bundle-Keyboardio/pull/7 + // + // TODO(anyone): Figure out a way we can get rid of this, and fix the bug + // properly. + Serial.begin(9600); + kaleidoscope::Hooks::onSetup(); KeyboardHardware.setup(); diff --git a/src/kaleidoscope/plugin/FocusSerial.h b/src/kaleidoscope/plugin/FocusSerial.h index ca6f856b..ef691c94 100644 --- a/src/kaleidoscope/plugin/FocusSerial.h +++ b/src/kaleidoscope/plugin/FocusSerial.h @@ -85,10 +85,6 @@ class FocusSerial : public kaleidoscope::Plugin { static constexpr char SEPARATOR = ' '; /* Hooks */ - EventHandlerResult onSetup() { - Serial.begin(9600); - return EventHandlerResult::OK; - } EventHandlerResult beforeReportingState(); EventHandlerResult onFocusEvent(const char *command);