|
|
|
@ -18,69 +18,65 @@
|
|
|
|
|
|
|
|
|
|
#include <Kaleidoscope-EEPROM-Keymap-Programmer.h>
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
|
uint16_t EEPROMKeymapProgrammer::updatePosition;
|
|
|
|
|
EEPROMKeymapProgrammer::state_t EEPROMKeymapProgrammer::state;
|
|
|
|
|
namespace kaleidoscope {
|
|
|
|
|
uint16_t EEPROMKeymapProgrammer::update_position_;
|
|
|
|
|
EEPROMKeymapProgrammer::state_t EEPROMKeymapProgrammer::state_;
|
|
|
|
|
EEPROMKeymapProgrammer::mode_t EEPROMKeymapProgrammer::mode;
|
|
|
|
|
Key EEPROMKeymapProgrammer::newKey;
|
|
|
|
|
Key EEPROMKeymapProgrammer::new_key_;
|
|
|
|
|
|
|
|
|
|
EEPROMKeymapProgrammer::EEPROMKeymapProgrammer(void) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
EEPROMKeymapProgrammer::begin (void) {
|
|
|
|
|
void EEPROMKeymapProgrammer::begin(void) {
|
|
|
|
|
event_handler_hook_use(eventHandlerHook);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
EEPROMKeymapProgrammer::nextState (void) {
|
|
|
|
|
switch (state) {
|
|
|
|
|
void EEPROMKeymapProgrammer::nextState(void) {
|
|
|
|
|
switch (state_) {
|
|
|
|
|
case INACTIVE:
|
|
|
|
|
state = WAIT_FOR_KEY;
|
|
|
|
|
state_ = WAIT_FOR_KEY;
|
|
|
|
|
break;
|
|
|
|
|
case WAIT_FOR_KEY:
|
|
|
|
|
if (mode == CODE)
|
|
|
|
|
state = WAIT_FOR_CODE;
|
|
|
|
|
state_ = WAIT_FOR_CODE;
|
|
|
|
|
else
|
|
|
|
|
state = WAIT_FOR_SOURCE_KEY;
|
|
|
|
|
state_ = WAIT_FOR_SOURCE_KEY;
|
|
|
|
|
break;
|
|
|
|
|
case WAIT_FOR_CODE:
|
|
|
|
|
case WAIT_FOR_SOURCE_KEY:
|
|
|
|
|
::EEPROMKeymap.updateKey (updatePosition, newKey);
|
|
|
|
|
::EEPROMKeymap.updateKey(update_position_, new_key_);
|
|
|
|
|
cancel();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
EEPROMKeymapProgrammer::cancel (void) {
|
|
|
|
|
updatePosition = 0;
|
|
|
|
|
newKey = Key_NoKey;
|
|
|
|
|
state = INACTIVE;
|
|
|
|
|
void EEPROMKeymapProgrammer::cancel(void) {
|
|
|
|
|
update_position_ = 0;
|
|
|
|
|
new_key_ = Key_NoKey;
|
|
|
|
|
state_ = INACTIVE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
|
EEPROMKeymapProgrammer::eventHandlerHook (Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
|
if (state == INACTIVE)
|
|
|
|
|
return mappedKey;
|
|
|
|
|
Key EEPROMKeymapProgrammer::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
|
|
|
|
|
if (state_ == INACTIVE)
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
|
|
if (state == WAIT_FOR_KEY) {
|
|
|
|
|
if (key_toggled_on (keyState)) {
|
|
|
|
|
updatePosition = Layer.top () * ROWS * COLS + row * COLS + col;
|
|
|
|
|
if (state_ == WAIT_FOR_KEY) {
|
|
|
|
|
if (key_toggled_on(key_state)) {
|
|
|
|
|
update_position_ = Layer.top() * ROWS * COLS + row * COLS + col;
|
|
|
|
|
}
|
|
|
|
|
if (key_toggled_off (keyState)) {
|
|
|
|
|
if ((uint16_t)(Layer.top () * ROWS * COLS + row * COLS + col) == updatePosition)
|
|
|
|
|
if (key_toggled_off(key_state)) {
|
|
|
|
|
if ((uint16_t)(Layer.top() * ROWS * COLS + row * COLS + col) == update_position_)
|
|
|
|
|
nextState();
|
|
|
|
|
}
|
|
|
|
|
return Key_NoKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (state == WAIT_FOR_SOURCE_KEY) {
|
|
|
|
|
if (key_toggled_on (keyState)) {
|
|
|
|
|
newKey = Layer.getKeyFromPROGMEM (Layer.top (), row, col);
|
|
|
|
|
if (state_ == WAIT_FOR_SOURCE_KEY) {
|
|
|
|
|
if (key_toggled_on(key_state)) {
|
|
|
|
|
new_key_ = Layer.getKeyFromPROGMEM(Layer.top(), row, col);
|
|
|
|
|
}
|
|
|
|
|
if (key_toggled_off (keyState)) {
|
|
|
|
|
if (newKey == Layer.getKeyFromPROGMEM (Layer.top (), row, col))
|
|
|
|
|
if (key_toggled_off(key_state)) {
|
|
|
|
|
if (new_key_ == Layer.getKeyFromPROGMEM(Layer.top(), row, col))
|
|
|
|
|
nextState();
|
|
|
|
|
}
|
|
|
|
|
return Key_NoKey;
|
|
|
|
@ -88,23 +84,23 @@ EEPROMKeymapProgrammer::eventHandlerHook (Key mappedKey, byte row, byte col, uin
|
|
|
|
|
|
|
|
|
|
// WAIT_FOR_CODE state
|
|
|
|
|
|
|
|
|
|
if (mappedKey < Key_1 || mappedKey > Key_0)
|
|
|
|
|
return mappedKey;
|
|
|
|
|
if (mapped_key < Key_1 || mapped_key > Key_0)
|
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
|
|
if (!key_toggled_on (keyState))
|
|
|
|
|
if (!key_toggled_on(key_state))
|
|
|
|
|
return Key_NoKey;
|
|
|
|
|
|
|
|
|
|
uint8_t n;
|
|
|
|
|
if (mappedKey.keyCode == Key_0.keyCode)
|
|
|
|
|
if (mapped_key.keyCode == Key_0.keyCode)
|
|
|
|
|
n = 0;
|
|
|
|
|
else
|
|
|
|
|
n = mappedKey.keyCode - Key_1.keyCode + 1;
|
|
|
|
|
n = mapped_key.keyCode - Key_1.keyCode + 1;
|
|
|
|
|
|
|
|
|
|
newKey.raw = newKey.raw * 10 + n;
|
|
|
|
|
new_key_.raw = new_key_.raw * 10 + n;
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
KaleidoscopePlugins::EEPROMKeymapProgrammer EEPROMKeymapProgrammer;
|
|
|
|
|
kaleidoscope::EEPROMKeymapProgrammer EEPROMKeymapProgrammer;
|
|
|
|
|