|
|
@ -20,76 +20,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
#define TOPSYTURVY 0b01000000
|
|
|
|
#define TOPSYTURVY 0b01000000
|
|
|
|
|
|
|
|
|
|
|
|
namespace KaleidoscopePlugins {
|
|
|
|
namespace kaleidoscope {
|
|
|
|
|
|
|
|
|
|
|
|
const Key *TopsyTurvy::topsyTurvyList = NULL;
|
|
|
|
const Key *TopsyTurvy::key_list = NULL;
|
|
|
|
uint8_t TopsyTurvy::topsyTurvyModState;
|
|
|
|
uint8_t TopsyTurvy::mod_state_;
|
|
|
|
|
|
|
|
|
|
|
|
TopsyTurvy::TopsyTurvy(void) {
|
|
|
|
TopsyTurvy::TopsyTurvy(void) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
void TopsyTurvy::begin(void) {
|
|
|
|
TopsyTurvy::begin(void) {
|
|
|
|
event_handler_hook_use(eventHandlerHook);
|
|
|
|
event_handler_hook_use(this->eventHandlerHook);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
Key TopsyTurvy::eventHandlerHook(Key mapped_key, byte row, byte col, uint8_t key_state) {
|
|
|
|
TopsyTurvy::configure(const Key list[]) {
|
|
|
|
if (key_state & TOPSYTURVY)
|
|
|
|
topsyTurvyList = (const Key *)list;
|
|
|
|
return mapped_key;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Key
|
|
|
|
|
|
|
|
TopsyTurvy::eventHandlerHook(Key mappedKey, byte row, byte col, uint8_t keyState) {
|
|
|
|
|
|
|
|
if (keyState & TOPSYTURVY)
|
|
|
|
|
|
|
|
return mappedKey;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!topsyTurvyList)
|
|
|
|
if (!key_list)
|
|
|
|
return mappedKey;
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
|
|
|
|
if (mappedKey.raw == Key_LeftShift.raw)
|
|
|
|
if (mapped_key.raw == Key_LeftShift.raw)
|
|
|
|
bitWrite(topsyTurvyModState, 0, key_is_pressed(keyState));
|
|
|
|
bitWrite(mod_state_, 0, key_is_pressed(key_state));
|
|
|
|
if (mappedKey.raw == Key_RightShift.raw)
|
|
|
|
if (mapped_key.raw == Key_RightShift.raw)
|
|
|
|
bitWrite(topsyTurvyModState, 1, key_is_pressed(keyState));
|
|
|
|
bitWrite(mod_state_, 1, key_is_pressed(key_state));
|
|
|
|
|
|
|
|
|
|
|
|
if (!key_is_pressed(keyState) && !key_was_pressed(keyState))
|
|
|
|
if (!key_is_pressed(key_state) && !key_was_pressed(key_state))
|
|
|
|
return mappedKey;
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
|
|
|
|
uint8_t idx = 0;
|
|
|
|
uint8_t idx = 0;
|
|
|
|
Key newKey;
|
|
|
|
Key newKey;
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
newKey.raw = pgm_read_word(&(topsyTurvyList[idx].raw));
|
|
|
|
newKey.raw = pgm_read_word(&(key_list[idx].raw));
|
|
|
|
idx++;
|
|
|
|
idx++;
|
|
|
|
} while (newKey.raw != mappedKey.raw && newKey.raw != Key_NoKey.raw);
|
|
|
|
} while (newKey.raw != mapped_key.raw && newKey.raw != Key_NoKey.raw);
|
|
|
|
|
|
|
|
|
|
|
|
if (newKey.raw == Key_NoKey.raw)
|
|
|
|
if (newKey.raw == Key_NoKey.raw)
|
|
|
|
return mappedKey;
|
|
|
|
return mapped_key;
|
|
|
|
|
|
|
|
|
|
|
|
// invert the shift state
|
|
|
|
// invert the shift state
|
|
|
|
|
|
|
|
|
|
|
|
if (!topsyTurvyModState) {
|
|
|
|
if (!mod_state_) {
|
|
|
|
if (key_is_pressed(keyState))
|
|
|
|
if (key_is_pressed(key_state))
|
|
|
|
Keyboard.press(Key_LeftShift.keyCode);
|
|
|
|
Keyboard.press(Key_LeftShift.keyCode);
|
|
|
|
handle_keyswitch_event(mappedKey, row, col, keyState | TOPSYTURVY);
|
|
|
|
handle_keyswitch_event(mapped_key, row, col, key_state | TOPSYTURVY);
|
|
|
|
Keyboard.sendReport();
|
|
|
|
Keyboard.sendReport();
|
|
|
|
if (key_toggled_off(keyState))
|
|
|
|
if (key_toggled_off(key_state))
|
|
|
|
Keyboard.release(Key_LeftShift.keyCode);
|
|
|
|
Keyboard.release(Key_LeftShift.keyCode);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
Keyboard.release(Key_LeftShift.keyCode);
|
|
|
|
Keyboard.release(Key_LeftShift.keyCode);
|
|
|
|
Keyboard.release(Key_RightShift.keyCode);
|
|
|
|
Keyboard.release(Key_RightShift.keyCode);
|
|
|
|
Keyboard.sendReport();
|
|
|
|
Keyboard.sendReport();
|
|
|
|
handle_keyswitch_event(mappedKey, row, col, keyState | TOPSYTURVY);
|
|
|
|
handle_keyswitch_event(mapped_key, row, col, key_state | TOPSYTURVY);
|
|
|
|
Keyboard.sendReport();
|
|
|
|
Keyboard.sendReport();
|
|
|
|
|
|
|
|
|
|
|
|
if (bitRead(topsyTurvyModState, 0))
|
|
|
|
if (bitRead(mod_state_, 0))
|
|
|
|
Keyboard.press(Key_LeftShift.keyCode);
|
|
|
|
Keyboard.press(Key_LeftShift.keyCode);
|
|
|
|
if (bitRead(topsyTurvyModState, 1))
|
|
|
|
if (bitRead(mod_state_, 1))
|
|
|
|
Keyboard.press(Key_RightShift.keyCode);
|
|
|
|
Keyboard.press(Key_RightShift.keyCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return Key_NoKey;
|
|
|
|
return Key_NoKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace KaleidoscopePlugins
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
KaleidoscopePlugins::TopsyTurvy TopsyTurvy;
|
|
|
|
kaleidoscope::TopsyTurvy TopsyTurvy;
|
|
|
|