コード例 #1
0
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();

  kaleidoscope::hid::initializeKeyboard();
  kaleidoscope::hid::initializeConsumerControl();
  kaleidoscope::hid::initializeSystemControl();

  // A workaround, so that the compiler does not optimize handleKeyswitchEvent out...
  // This is a no-op, but tricks the compiler into not being too helpful
  // TODO(anyone): figure out how to hint the compiler in a more reasonable way
  handleKeyswitchEvent(Key_NoKey, 255, 255, 0);

  // Update the keymap cache, so we start with a non-empty state.
  Layer.updateActiveLayers();
  for (byte row = 0; row < ROWS; row++) {
    for (byte col = 0; col < COLS; col++) {
      Layer.updateLiveCompositeKeymap(row, col);
    }
  }
}
コード例 #2
0
EventHandlerResult GhostInTheFirmware::beforeReportingState() {
  if (!is_active_)
    return EventHandlerResult::OK;

  if (press_timeout_ == 0) {
    press_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].pressTime));
    delay_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].delay));

    if (press_timeout_ == 0) {
      current_pos_ = 0;
      is_active_ = false;
      return EventHandlerResult::OK;
    }
    is_pressed_ = true;
    start_time_ = millis();
  } else {
    if (is_pressed_ && ((millis() - start_time_) > press_timeout_)) {
      is_pressed_ = false;
      start_time_ = millis();

      byte row = pgm_read_byte(&(ghost_keys[current_pos_].row));
      byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));

      handleKeyswitchEvent(Key_NoKey, row, col, WAS_PRESSED);
    } else if (is_pressed_) {
      byte row = pgm_read_byte(&(ghost_keys[current_pos_].row));
      byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));

      handleKeyswitchEvent(Key_NoKey, row, col, IS_PRESSED);
    } else if ((millis() - start_time_) > delay_timeout_) {
      current_pos_++;
      press_timeout_ = 0;
    }
  }

  return EventHandlerResult::OK;
}