1 /* Copyright 2017 Jack Humbert
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "process_unicode_common.h"
20 static uint8_t input_mode;
23 void set_unicode_input_mode(uint8_t os_target)
25 input_mode = os_target;
26 eeprom_update_byte(EECONFIG_UNICODEMODE, os_target);
29 uint8_t get_unicode_input_mode(void) {
34 void unicode_input_start (void) {
36 mods = keyboard_report->mods;
38 // unregister all mods to start from clean state
39 if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
40 if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
41 if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
42 if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
43 if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
44 if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
45 if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
46 if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
50 register_code(KC_LALT);
53 register_code(KC_RALT);
56 register_code(KC_LCTL);
57 register_code(KC_LSFT);
59 unregister_code(KC_U);
60 unregister_code(KC_LSFT);
61 unregister_code(KC_LCTL);
64 register_code(KC_LALT);
65 register_code(KC_PPLS);
66 unregister_code(KC_PPLS);
69 register_code(KC_RALT);
70 unregister_code(KC_RALT);
72 unregister_code(KC_U);
74 wait_ms(UNICODE_TYPE_DELAY);
78 void unicode_input_finish (void) {
82 unregister_code(KC_LALT);
85 unregister_code(KC_RALT);
88 register_code(KC_SPC);
89 unregister_code(KC_SPC);
93 // reregister previously set mods
94 if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
95 if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
96 if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
97 if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
98 if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
99 if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
100 if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
101 if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
104 __attribute__((weak))
105 uint16_t hex_to_keycode(uint8_t hex)
109 } else if (hex < 0xA) {
110 return KC_1 + (hex - 0x1);
112 return KC_A + (hex - 0xA);
116 void register_hex(uint16_t hex) {
117 for(int i = 3; i >= 0; i--) {
118 uint8_t digit = ((hex >> (i*4)) & 0xF);
119 register_code(hex_to_keycode(digit));
120 unregister_code(hex_to_keycode(digit));