diff options
Diffstat (limited to 'quantum/process_keycode')
| -rw-r--r-- | quantum/process_keycode/process_unicode.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index 26571ea03..cecfaeee9 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c | |||
| @@ -16,8 +16,88 @@ | |||
| 16 | #include "process_unicode.h" | 16 | #include "process_unicode.h" |
| 17 | #include "action_util.h" | 17 | #include "action_util.h" |
| 18 | 18 | ||
| 19 | static uint8_t input_mode; | ||
| 20 | static uint8_t first_flag = 0; | ||
| 21 | |||
| 22 | __attribute__((weak)) | ||
| 23 | uint16_t hex_to_keycode(uint8_t hex) | ||
| 24 | { | ||
| 25 | if (hex == 0x0) { | ||
| 26 | return KC_0; | ||
| 27 | } else if (hex < 0xA) { | ||
| 28 | return KC_1 + (hex - 0x1); | ||
| 29 | } else { | ||
| 30 | return KC_A + (hex - 0xA); | ||
| 31 | } | ||
| 32 | } | ||
| 33 | |||
| 34 | void set_unicode_input_mode(uint8_t os_target) | ||
| 35 | { | ||
| 36 | input_mode = os_target; | ||
| 37 | eeprom_update_byte(EECONFIG_UNICODEMODE, os_target); | ||
| 38 | } | ||
| 39 | |||
| 40 | uint8_t get_unicode_input_mode(void) { | ||
| 41 | return input_mode; | ||
| 42 | } | ||
| 43 | |||
| 44 | __attribute__((weak)) | ||
| 45 | void unicode_input_start (void) { | ||
| 46 | switch(input_mode) { | ||
| 47 | case UC_OSX: | ||
| 48 | register_code(KC_LALT); | ||
| 49 | break; | ||
| 50 | case UC_LNX: | ||
| 51 | register_code(KC_LCTL); | ||
| 52 | register_code(KC_LSFT); | ||
| 53 | register_code(KC_U); | ||
| 54 | unregister_code(KC_U); | ||
| 55 | unregister_code(KC_LSFT); | ||
| 56 | unregister_code(KC_LCTL); | ||
| 57 | break; | ||
| 58 | case UC_WIN: | ||
| 59 | register_code(KC_LALT); | ||
| 60 | register_code(KC_PPLS); | ||
| 61 | unregister_code(KC_PPLS); | ||
| 62 | break; | ||
| 63 | case UC_WINC: | ||
| 64 | register_code(KC_RALT); | ||
| 65 | unregister_code(KC_RALT); | ||
| 66 | register_code(KC_U); | ||
| 67 | unregister_code(KC_U); | ||
| 68 | } | ||
| 69 | wait_ms(UNICODE_TYPE_DELAY); | ||
| 70 | } | ||
| 71 | |||
| 72 | __attribute__((weak)) | ||
| 73 | void unicode_input_finish (void) { | ||
| 74 | switch(input_mode) { | ||
| 75 | case UC_OSX: | ||
| 76 | case UC_WIN: | ||
| 77 | unregister_code(KC_LALT); | ||
| 78 | break; | ||
| 79 | case UC_LNX: | ||
| 80 | register_code(KC_SPC); | ||
| 81 | unregister_code(KC_SPC); | ||
| 82 | break; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | |||
| 86 | void register_hex(uint16_t hex) { | ||
| 87 | for(int i = 3; i >= 0; i--) { | ||
| 88 | uint8_t digit = ((hex >> (i*4)) & 0xF); | ||
| 89 | register_code(hex_to_keycode(digit)); | ||
| 90 | unregister_code(hex_to_keycode(digit)); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | |||
| 94 | |||
| 19 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { | 95 | bool process_unicode(uint16_t keycode, keyrecord_t *record) { |
| 20 | if (keycode > QK_UNICODE && record->event.pressed) { | 96 | if (keycode > QK_UNICODE && record->event.pressed) { |
| 97 | if (first_flag == 0) { | ||
| 98 | set_unicode_input_mode(eeprom_read_byte(EECONFIG_UNICODEMODE)); | ||
| 99 | first_flag = 1; | ||
| 100 | } | ||
| 21 | uint16_t unicode = keycode & 0x7FFF; | 101 | uint16_t unicode = keycode & 0x7FFF; |
| 22 | unicode_input_start(); | 102 | unicode_input_start(); |
| 23 | register_hex(unicode); | 103 | register_hex(unicode); |
