]> git.donarmstrong.com Git - qmk_firmware.git/blobdiff - quantum/process_keycode/process_unicode.c
Merge pull request #813 from fredizzimo/add_cluecard_rgb_effects
[qmk_firmware.git] / quantum / process_keycode / process_unicode.c
index 8a650930080b64ca06482614039bf2a06e4bed85..6a30afe2933125f034f0eb3779a16ddf374f1704 100644 (file)
@@ -2,6 +2,7 @@
 
 static uint8_t input_mode;
 
+__attribute__((weak))
 uint16_t hex_to_keycode(uint8_t hex)
 {
   if (hex == 0x0) {
@@ -18,6 +19,11 @@ void set_unicode_input_mode(uint8_t os_target)
   input_mode = os_target;
 }
 
+uint8_t get_unicode_input_mode(void) {
+  return input_mode;
+}
+
+__attribute__((weak))
 void unicode_input_start (void) {
   switch(input_mode) {
   case UC_OSX:
@@ -37,8 +43,10 @@ void unicode_input_start (void) {
     unregister_code(KC_PPLS);
     break;
   }
+  wait_ms(UNICODE_TYPE_DELAY);
 }
 
+__attribute__((weak))
 void unicode_input_finish (void) {
   switch(input_mode) {
   case UC_OSX:
@@ -71,10 +79,17 @@ bool process_unicode(uint16_t keycode, keyrecord_t *record) {
 }
 
 #ifdef UCIS_ENABLE
+qk_ucis_state_t qk_ucis_state;
+
 void qk_ucis_start(void) {
   qk_ucis_state.count = 0;
   qk_ucis_state.in_progress = true;
 
+  qk_ucis_start_user();
+}
+
+__attribute__((weak))
+void qk_ucis_start_user(void) {
   unicode_input_start();
   register_hex(0x2328);
   unicode_input_finish();
@@ -104,13 +119,50 @@ void qk_ucis_symbol_fallback (void) {
     uint8_t code = qk_ucis_state.codes[i];
     register_code(code);
     unregister_code(code);
+    wait_ms(UNICODE_TYPE_DELAY);
+  }
+}
+
+void register_ucis(const char *hex) {
+  for(int i = 0; hex[i]; i++) {
+    uint8_t kc = 0;
+    char c = hex[i];
+
+    switch (c) {
+    case '0':
+      kc = KC_0;
+      break;
+    case '1' ... '9':
+      kc = c - '1' + KC_1;
+      break;
+    case 'a' ... 'f':
+      kc = c - 'a' + KC_A;
+      break;
+    case 'A' ... 'F':
+      kc = c - 'A' + KC_A;
+      break;
+    }
+
+    if (kc) {
+      register_code (kc);
+      unregister_code (kc);
+      wait_ms (UNICODE_TYPE_DELAY);
+    }
   }
 }
 
-bool process_record_ucis (uint16_t keycode, keyrecord_t *record) {
+bool process_ucis (uint16_t keycode, keyrecord_t *record) {
   uint8_t i;
 
-  if (!qk_ucis_state.in_progress || !record->event.pressed)
+  if (!qk_ucis_state.in_progress)
+    return true;
+
+  if (qk_ucis_state.count >= UCIS_MAX_SYMBOL_LENGTH &&
+      !(keycode == KC_BSPC || keycode == KC_ESC || keycode == KC_SPC || keycode == KC_ENT)) {
+    return false;
+  }
+
+  if (!record->event.pressed)
     return true;
 
   qk_ucis_state.codes[qk_ucis_state.count] = keycode;
@@ -132,6 +184,7 @@ bool process_record_ucis (uint16_t keycode, keyrecord_t *record) {
     for (i = qk_ucis_state.count; i > 0; i--) {
       register_code (KC_BSPC);
       unregister_code (KC_BSPC);
+      wait_ms(UNICODE_TYPE_DELAY);
     }
 
     if (keycode == KC_ESC) {
@@ -143,9 +196,7 @@ bool process_record_ucis (uint16_t keycode, keyrecord_t *record) {
     for (i = 0; ucis_symbol_table[i].symbol; i++) {
       if (is_uni_seq (ucis_symbol_table[i].symbol)) {
         symbol_found = true;
-        for (uint8_t j = 0; ucis_symbol_table[i].codes[j]; j++) {
-          register_hex(ucis_symbol_table[i].codes[j]);
-        }
+        register_ucis(ucis_symbol_table[i].code + 2);
         break;
       }
     }