Переглянути джерело

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
Drashna Jaelre 6 роки тому
батько
коміт
7222e3691b

+ 3 - 3
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);

+ 1 - 6
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();

+ 11 - 6
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) {

+ 1 - 0
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);

+ 1 - 0
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;