From 7222e3691b18128c4822f6bb5db008010f5e41dd Mon Sep 17 00:00:00 2001 From: Drashna Jaelre Date: Thu, 18 Oct 2018 21:35:15 -0700 Subject: Fix Unicode EEPROM handling so it is consistent. (#4066) * Fix Unicode EEPROM handling so it's consistant * Remove changes to my userspace * Optimize variables used * fix functions * additional cleanup * Add False Flag * rename function --- quantum/process_keycode/process_ucis.c | 6 +++--- quantum/process_keycode/process_unicode.c | 7 +------ quantum/process_keycode/process_unicode_common.c | 17 +++++++++++------ quantum/process_keycode/process_unicode_common.h | 1 + quantum/process_keycode/process_unicodemap.c | 1 + 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/quantum/process_keycode/process_ucis.c b/quantum/process_keycode/process_ucis.c index 5de2e41fc3..380199771d 100644 --- a/quantum/process_keycode/process_ucis.c +++ b/quantum/process_keycode/process_ucis.c @@ -93,7 +93,7 @@ void register_ucis(const char *hex) { } bool process_ucis (uint16_t keycode, keyrecord_t *record) { - uint8_t i; + unicode_input_mode_init(); if (!qk_ucis_state.in_progress) return true; @@ -122,7 +122,7 @@ bool process_ucis (uint16_t keycode, keyrecord_t *record) { if (keycode == KC_ENT || keycode == KC_SPC || keycode == KC_ESC) { bool symbol_found = false; - for (i = qk_ucis_state.count; i > 0; i--) { + for (uint8_t i = qk_ucis_state.count; i > 0; i--) { register_code (KC_BSPC); unregister_code (KC_BSPC); wait_ms(UNICODE_TYPE_DELAY); @@ -134,7 +134,7 @@ bool process_ucis (uint16_t keycode, keyrecord_t *record) { } unicode_input_start(); - for (i = 0; ucis_symbol_table[i].symbol; i++) { + for (uint8_t i = 0; ucis_symbol_table[i].symbol; i++) { if (is_uni_seq (ucis_symbol_table[i].symbol)) { symbol_found = true; register_ucis(ucis_symbol_table[i].code + 2); diff --git a/quantum/process_keycode/process_unicode.c b/quantum/process_keycode/process_unicode.c index fd008eca12..f39c4a36e1 100644 --- a/quantum/process_keycode/process_unicode.c +++ b/quantum/process_keycode/process_unicode.c @@ -17,15 +17,10 @@ #include "action_util.h" #include "eeprom.h" -static uint8_t first_flag = 0; - bool process_unicode(uint16_t keycode, keyrecord_t *record) { if (keycode > QK_UNICODE && record->event.pressed) { - if (first_flag == 0) { - set_unicode_input_mode(eeprom_read_byte(EECONFIG_UNICODEMODE)); - first_flag = 1; - } uint16_t unicode = keycode & 0x7FFF; + unicode_input_mode_init(); unicode_input_start(); register_hex(unicode); unicode_input_finish(); diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c index e6620b7ea9..4285d20a19 100644 --- a/quantum/process_keycode/process_unicode_common.c +++ b/quantum/process_keycode/process_unicode_common.c @@ -22,8 +22,7 @@ static uint8_t input_mode; uint8_t mods; -void set_unicode_input_mode(uint8_t os_target) -{ +void set_unicode_input_mode(uint8_t os_target) { input_mode = os_target; eeprom_update_byte(EECONFIG_UNICODEMODE, os_target); } @@ -32,6 +31,14 @@ uint8_t get_unicode_input_mode(void) { return input_mode; } +void unicode_input_mode_init(void) { + static bool first_flag = false; + if (!first_flag) { + input_mode = eeprom_read_byte(EECONFIG_UNICODEMODE); + first_flag = true; + } +} + __attribute__((weak)) void unicode_input_start (void) { // save current mods @@ -104,8 +111,7 @@ void unicode_input_finish (void) { } __attribute__((weak)) -uint16_t hex_to_keycode(uint8_t hex) -{ +uint16_t hex_to_keycode(uint8_t hex) { if (hex == 0x0) { return KC_0; } else if (hex < 0xA) { @@ -123,8 +129,7 @@ void register_hex(uint16_t hex) { } } -void send_unicode_hex_string(const char *str) -{ +void send_unicode_hex_string(const char *str) { if (!str) { return; } // Safety net while (*str) { diff --git a/quantum/process_keycode/process_unicode_common.h b/quantum/process_keycode/process_unicode_common.h index 814b60c573..e78e1cec6c 100644 --- a/quantum/process_keycode/process_unicode_common.h +++ b/quantum/process_keycode/process_unicode_common.h @@ -28,6 +28,7 @@ static uint8_t input_mode; void set_unicode_input_mode(uint8_t os_target); uint8_t get_unicode_input_mode(void); +void unicode_input_mode_init(void); void unicode_input_start(void); void unicode_input_finish(void); void register_hex(uint16_t hex); diff --git a/quantum/process_keycode/process_unicodemap.c b/quantum/process_keycode/process_unicodemap.c index 47c27b9117..ab5717ba3a 100644 --- a/quantum/process_keycode/process_unicodemap.c +++ b/quantum/process_keycode/process_unicodemap.c @@ -45,6 +45,7 @@ __attribute__((weak)) void unicode_map_input_error() {} bool process_unicode_map(uint16_t keycode, keyrecord_t *record) { + unicode_input_mode_init(); uint8_t input_mode = get_unicode_input_mode(); if ((keycode & QK_UNICODE_MAP) == QK_UNICODE_MAP && record->event.pressed) { const uint32_t* map = unicode_map; -- cgit v1.2.1