Kaleidoscope icon indicating copy to clipboard operation
Kaleidoscope copied to clipboard

Moving the Serialport initialization out of Runtime_::setup

Open algernon opened this issue 3 years ago • 0 comments
trafficstars

We're initializing the serialport in Runtime_::setup(), just before calling the onSetup() hooks:

  // 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.
  device().serialPort().begin(9600);

Ideally, we'd want to delegate this task to the device's setup(). However, we do not want to repeat the same code for every single hardware plugin, which means we want to do it in kaleidoscope::device::Base. However, that class does not have access to Runtime, so we can't do Runtime.device() there to grab the device object used at runtime. We can only rely on the base class and the properties, and that - at the moment - is not sufficient to push the serial port initialization into the device base class. While Base does have a serialPort() function, that just returns NoOpSerial, rather than the Serial object the derived class sets.

In the end, we'll want to move the serial port override to properties too. We may need to implement a thin layer for it, like we did for Storage.

algernon avatar Mar 31 '22 18:03 algernon