You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.4 KiB
77 lines
2.4 KiB
8 years ago
|
/* -*- mode: c++ -*-
|
||
8 years ago
|
* Kaleidoscope-GhostInTheFirmware -- Let the keyboard write for you!
|
||
6 years ago
|
* Copyright (C) 2017 Keyboard.io, Inc
|
||
8 years ago
|
*
|
||
6 years ago
|
* 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, version 3.
|
||
8 years ago
|
*
|
||
6 years ago
|
* 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.
|
||
8 years ago
|
*
|
||
6 years ago
|
* You should have received a copy of the GNU General Public License along with
|
||
|
* this program. If not, see <http://www.gnu.org/licenses/>.
|
||
8 years ago
|
*/
|
||
|
|
||
8 years ago
|
#include <Kaleidoscope.h>
|
||
|
#include <Kaleidoscope-GhostInTheFirmware.h>
|
||
8 years ago
|
|
||
8 years ago
|
namespace kaleidoscope {
|
||
6 years ago
|
namespace plugin {
|
||
8 years ago
|
const GhostInTheFirmware::GhostKey *GhostInTheFirmware::ghost_keys;
|
||
|
bool GhostInTheFirmware::is_active_;
|
||
|
bool GhostInTheFirmware::is_pressed_;
|
||
|
uint16_t GhostInTheFirmware::current_pos_;
|
||
|
uint32_t GhostInTheFirmware::start_time_;
|
||
|
uint16_t GhostInTheFirmware::press_timeout_;
|
||
|
uint16_t GhostInTheFirmware::delay_timeout_;
|
||
8 years ago
|
|
||
8 years ago
|
void GhostInTheFirmware::activate(void) {
|
||
|
is_active_ = true;
|
||
8 years ago
|
}
|
||
8 years ago
|
|
||
7 years ago
|
EventHandlerResult GhostInTheFirmware::beforeReportingState() {
|
||
|
if (!is_active_)
|
||
|
return EventHandlerResult::OK;
|
||
8 years ago
|
|
||
8 years ago
|
if (press_timeout_ == 0) {
|
||
|
press_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].pressTime));
|
||
|
delay_timeout_ = pgm_read_word(&(ghost_keys[current_pos_].delay));
|
||
8 years ago
|
|
||
8 years ago
|
if (press_timeout_ == 0) {
|
||
|
current_pos_ = 0;
|
||
|
is_active_ = false;
|
||
7 years ago
|
return EventHandlerResult::OK;
|
||
8 years ago
|
}
|
||
8 years ago
|
is_pressed_ = true;
|
||
|
start_time_ = millis();
|
||
8 years ago
|
} else {
|
||
8 years ago
|
if (is_pressed_ && ((millis() - start_time_) > press_timeout_)) {
|
||
|
is_pressed_ = false;
|
||
|
start_time_ = millis();
|
||
8 years ago
|
|
||
8 years ago
|
byte row = pgm_read_byte(&(ghost_keys[current_pos_].row));
|
||
|
byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));
|
||
8 years ago
|
|
||
8 years ago
|
handleKeyswitchEvent(Key_NoKey, row, col, WAS_PRESSED);
|
||
8 years ago
|
} else if (is_pressed_) {
|
||
|
byte row = pgm_read_byte(&(ghost_keys[current_pos_].row));
|
||
|
byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));
|
||
8 years ago
|
|
||
8 years ago
|
handleKeyswitchEvent(Key_NoKey, row, col, IS_PRESSED);
|
||
8 years ago
|
} else if ((millis() - start_time_) > delay_timeout_) {
|
||
|
current_pos_++;
|
||
|
press_timeout_ = 0;
|
||
8 years ago
|
}
|
||
8 years ago
|
}
|
||
7 years ago
|
|
||
|
return EventHandlerResult::OK;
|
||
|
}
|
||
|
|
||
6 years ago
|
}
|
||
|
}
|
||
8 years ago
|
|
||
6 years ago
|
kaleidoscope::plugin::GhostInTheFirmware GhostInTheFirmware;
|