aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_unicode_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
-rw-r--r--quantum/process_keycode/process_unicode_common.c115
1 files changed, 115 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
new file mode 100644
index 000000000..1dbdec3e7
--- /dev/null
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -0,0 +1,115 @@
1/* Copyright 2017 Jack Humbert
2 *
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.
7 *
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.
12 *
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/>.
15 */
16
17#include "process_unicode_common.h"
18
19static uint8_t input_mode;
20uint8_t mods;
21
22void set_unicode_input_mode(uint8_t os_target)
23{
24 input_mode = os_target;
25 eeprom_update_byte(EECONFIG_UNICODEMODE, os_target);
26}
27
28uint8_t get_unicode_input_mode(void) {
29 return input_mode;
30}
31
32__attribute__((weak))
33void unicode_input_start (void) {
34 // save current mods
35 mods = keyboard_report->mods;
36
37 // unregister all mods to start from clean state
38 if (mods & MOD_BIT(KC_LSFT)) unregister_code(KC_LSFT);
39 if (mods & MOD_BIT(KC_RSFT)) unregister_code(KC_RSFT);
40 if (mods & MOD_BIT(KC_LCTL)) unregister_code(KC_LCTL);
41 if (mods & MOD_BIT(KC_RCTL)) unregister_code(KC_RCTL);
42 if (mods & MOD_BIT(KC_LALT)) unregister_code(KC_LALT);
43 if (mods & MOD_BIT(KC_RALT)) unregister_code(KC_RALT);
44 if (mods & MOD_BIT(KC_LGUI)) unregister_code(KC_LGUI);
45 if (mods & MOD_BIT(KC_RGUI)) unregister_code(KC_RGUI);
46
47 switch(input_mode) {
48 case UC_OSX:
49 register_code(KC_LALT);
50 break;
51 case UC_LNX:
52 register_code(KC_LCTL);
53 register_code(KC_LSFT);
54 register_code(KC_U);
55 unregister_code(KC_U);
56 unregister_code(KC_LSFT);
57 unregister_code(KC_LCTL);
58 break;
59 case UC_WIN:
60 register_code(KC_LALT);
61 register_code(KC_PPLS);
62 unregister_code(KC_PPLS);
63 break;
64 case UC_WINC:
65 register_code(KC_RALT);
66 unregister_code(KC_RALT);
67 register_code(KC_U);
68 unregister_code(KC_U);
69 }
70 wait_ms(UNICODE_TYPE_DELAY);
71}
72
73__attribute__((weak))
74void unicode_input_finish (void) {
75 switch(input_mode) {
76 case UC_OSX:
77 case UC_WIN:
78 unregister_code(KC_LALT);
79 break;
80 case UC_LNX:
81 register_code(KC_SPC);
82 unregister_code(KC_SPC);
83 break;
84 }
85
86 // reregister previously set mods
87 if (mods & MOD_BIT(KC_LSFT)) register_code(KC_LSFT);
88 if (mods & MOD_BIT(KC_RSFT)) register_code(KC_RSFT);
89 if (mods & MOD_BIT(KC_LCTL)) register_code(KC_LCTL);
90 if (mods & MOD_BIT(KC_RCTL)) register_code(KC_RCTL);
91 if (mods & MOD_BIT(KC_LALT)) register_code(KC_LALT);
92 if (mods & MOD_BIT(KC_RALT)) register_code(KC_RALT);
93 if (mods & MOD_BIT(KC_LGUI)) register_code(KC_LGUI);
94 if (mods & MOD_BIT(KC_RGUI)) register_code(KC_RGUI);
95}
96
97__attribute__((weak))
98uint16_t hex_to_keycode(uint8_t hex)
99{
100 if (hex == 0x0) {
101 return KC_0;
102 } else if (hex < 0xA) {
103 return KC_1 + (hex - 0x1);
104 } else {
105 return KC_A + (hex - 0xA);
106 }
107}
108
109void register_hex(uint16_t hex) {
110 for(int i = 3; i >= 0; i--) {
111 uint8_t digit = ((hex >> (i*4)) & 0xF);
112 register_code(hex_to_keycode(digit));
113 unregister_code(hex_to_keycode(digit));
114 }
115}