aboutsummaryrefslogtreecommitdiff
path: root/keyboards/thevankeyboards/minivan/keymaps/josjoha/unicode_macros.c
diff options
context:
space:
mode:
Diffstat (limited to 'keyboards/thevankeyboards/minivan/keymaps/josjoha/unicode_macros.c')
-rw-r--r--keyboards/thevankeyboards/minivan/keymaps/josjoha/unicode_macros.c183
1 files changed, 130 insertions, 53 deletions
diff --git a/keyboards/thevankeyboards/minivan/keymaps/josjoha/unicode_macros.c b/keyboards/thevankeyboards/minivan/keymaps/josjoha/unicode_macros.c
index f21379248..d711c86f9 100644
--- a/keyboards/thevankeyboards/minivan/keymaps/josjoha/unicode_macros.c
+++ b/keyboards/thevankeyboards/minivan/keymaps/josjoha/unicode_macros.c
@@ -38,74 +38,70 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
38 38
39#define DIV10POINT TRUE // suggest to function write_number, to divide by 10 and print as a fraction: N.N 39#define DIV10POINT TRUE // suggest to function write_number, to divide by 10 and print as a fraction: N.N
40 40
41// Converts integer value to Unicode. Also handles 'descramble' Unicode mode for DVORAK_DESCRAMBLE_HALF. 41// Gives Unicode code points to the relevant QMK functions.
42// Unicode is a hexadecimal string (character) representation of the value, with a pre- and post-fix. 42// Handles Dvorak 'descramble' Unicode mode, if compiled (only tested on Linux).
43void unicode_hex2output (long unsigned int unshifted, long unsigned int shifted) { 43void unicode_hex2output (long unsigned int unshifted, long unsigned int shifted) {
44 44
45 long unsigned int input; // which argument to work on 45 long unsigned int input; // which argument to work on
46 char output[10] ; // will hold the ascii for output 46
47# ifdef DVORAK_DESCRAMBLE // Do the letter descramble if needed.
48
49 char output[10]; // will hold the ascii for output
47 int index; // count backwards 'to left' in the string 50 int index; // count backwards 'to left' in the string
48 long unsigned int bitmove; // move computation to next digit. 51 long unsigned int bitmove; // move computation to next digit.
49 long unsigned int work; // temporary value for computation 52 long unsigned int work; // temporary value for computation
50 53
54# endif
51 55
52 // What to work on 56 // What to work on
53 if(shift_ison) input = shifted; // Trying to get everything possible here in this function, to reduce firmware size. 57 if(shift_ison) input = shifted; // Trying to get everything possible here in this function, to reduce firmware size.
54 else input = unshifted; 58 else input = unshifted;
55 59
56 //if (input < 0) input *= -1; // positive value 60# ifndef DVORAK_DESCRAMBLE // Only normal mode
57 61
58 // Take the hex value 4 bits at a time, starting with the least significant, convert to ascii, store 62 register_unicode ( (uint32_t) input ) ;
59 index = 9; 63
60 output[index] = '\0'; // terminator 64# else
61 bitmove = 0x1; 65
62 while ((work = (input / bitmove)) && (index >= 0)) { 66 if(_FULL_ != alternate){
63 index --; 67
64 work &= 0xF; 68 register_unicode ( (uint32_t) input ) ; // normal Unicode mode
65 if (work < 0xA){ // numbers 69
66 output[index] = work + 0x30; // pad to ASCII 70 }else{ // Special Dvorak-descramble mode: 0-9=0-9, a=a, b=n, c=i, d=h, e=d, f=y
67 }else{ // alphas 71
68# ifdef DVORAK_DESCRAMBLE_HALF // Do the letter descramble if needed. 72 // Take the hex value 4 bits at a time, starting with the least significant, convert to ascii, store
69 if(_FULL_ == alternate){ // 0-9=0-9, a=a, b=n, c=i, d=h, e=d, f=y 73 index = 9;
74 output[index] = '\0'; // terminator
75 bitmove = 0x1;
76 while ((work = (input / bitmove)) && (index >= 0)) {
77 index --;
78 work &= 0xF;
79 if (work < 0xA){ // numbers
80 output[index] = work + 0x30; // pad to ASCII
81 }else{ // alphas
70 if (0xA == work) output[index] = 'a'; 82 if (0xA == work) output[index] = 'a';
71 if (0xB == work) output[index] = 'n'; 83 if (0xB == work) output[index] = 'n';
72 if (0xC == work) output[index] = 'i'; 84 if (0xC == work) output[index] = 'i';
73 if (0xD == work) output[index] = 'h'; 85 if (0xD == work) output[index] = 'h';
74 if (0xE == work) output[index] = 'd'; 86 if (0xE == work) output[index] = 'd';
75 if (0xF == work) output[index] = 'y'; 87 if (0xF == work) output[index] = 'y';
76 }else{
77 output[index] = work - 9 + 0x40; // normal mode
78 } 88 }
79# else // The above is not relevant for anything else. 89 bitmove *= 0x10; // next digit
80 output[index] = work - 9 + 0x40; // normal mode
81# endif
82 } 90 }
83 bitmove *= 0x10; // next digit 91
84 } 92 SEND_STRING ( SS_DOWN(X_LCTRL) SS_DOWN(X_LSHIFT) "f" SS_UP(X_LSHIFT) SS_UP(X_LCTRL) ); // lead-in for Unicode on Linux, 'descramble' mode
85
86 // Put character(s) out in correct mode
87# ifdef DVORAK_DESCRAMBLE_HALF // Do the letter descramble if needed.
88 if (_FULL_ == alternate) { // This is the special 'descramble' output mode for a computer already set to Dvorak
89
90 SEND_STRING ( SS_DOWN(X_LCTRL) SS_DOWN(X_LSHIFT) "f" SS_UP(X_LSHIFT) SS_UP(X_LCTRL) ) ; // lead-in for Unicode on Linux, 'descramble' mode
91 send_string (output + index); // pointer to argument with formatted string 93 send_string (output + index); // pointer to argument with formatted string
92 SEND_STRING ( " " ) ; // Ends the Unicode numerical input mode, replacing input with desired character (Linux) 94 SEND_STRING ( " " ); // Ends the Unicode numerical input mode
93
94 }else{
95 // normal QMK Unicode output mode
96 send_unicode_hex_string (output + index); // pointer argument
97 } 95 }
98 96
99# else 97# endif // DVORAK_DESCRAMBLE mode for that Base layer & mode setting is compiled in
100 send_unicode_hex_string (output + index); // pointer argument
101# endif
102 98
103} 99}
104 100
105 101
106// Wrapper for unicode keys that do have the same on shift. 102// Wrapper for unicode keys that do have the same on shift.
107void unicode_hex2output_single (long unsigned int either) { 103void unicode_hex2output_single (long unsigned int either) {
108 unicode_hex2output (either, either) ; 104 unicode_hex2output (either, either);
109} 105}
110 106
111 107
@@ -144,6 +140,11 @@ enum custom_keycodes {
144 CHOLTAP_LSHFT, // Go to <configurable> layer, or shift modifier. 140 CHOLTAP_LSHFT, // Go to <configurable> layer, or shift modifier.
145 CHOLTAP_LAYR, // Go to _RAR layer, or right arrow 141 CHOLTAP_LAYR, // Go to _RAR layer, or right arrow
146 142
143// Shifts which on tap produce a key
144
145 RSFT_TILDE,
146 LSFT_DASH,
147
147// Special macro to make F-keys one-shot or not. 148// Special macro to make F-keys one-shot or not.
148 _FUN_STAY, 149 _FUN_STAY,
149 150
@@ -378,7 +379,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
378 && 379 &&
379 (keycode != CHOLTAP_ACCE) // _ACC layer (and others) 380 (keycode != CHOLTAP_ACCE) // _ACC layer (and others)
380 && 381 &&
381 (keycode != CHOLTAP_LAYR)) { // _RAR layer, or RAlt/Alt-Gr 382 (keycode != RSFT_TILDE) // Shift on _NSY
383 &&
384 (keycode != LSFT_DASH) // Shift on _NSY
385 &&
386 (keycode != CHOLTAP_LAYR))
387 { // _RAR layer, or RAlt/Alt-Gr
382 isolate_trigger = FALSE; // another key was pressed 388 isolate_trigger = FALSE; // another key was pressed
383 } 389 }
384 } 390 }
@@ -437,7 +443,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
437 added += write_number ((long int)((speed*12)/10), FALSE); // writes the speed 443 added += write_number ((long int)((speed*12)/10), FALSE); // writes the speed
438 send_string ("wpm"); // +3 character written 444 send_string ("wpm"); // +3 character written
439 if (0 != speed_batches) { 445 if (0 != speed_batches) {
440 long int average_times_ten ; 446 long int average_times_ten;
441 average_times_ten =(long int) ((speed_add * 12) / speed_batches); // *12 converts k/s to wpm 447 average_times_ten =(long int) ((speed_add * 12) / speed_batches); // *12 converts k/s to wpm
442 448
443 send_string (";"); // +① '' 449 send_string (";"); // +① ''
@@ -458,7 +464,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
458 added += write_number ((long int)(speed/10), FALSE); // writes the speed 464 added += write_number ((long int)(speed/10), FALSE); // writes the speed
459 send_string ("k/s"); // +3 character written 465 send_string ("k/s"); // +3 character written
460 if (0 != speed_batches) { 466 if (0 != speed_batches) {
461 long int average_times_ten ; 467 long int average_times_ten;
462 average_times_ten =(long int) (speed_add / speed_batches); 468 average_times_ten =(long int) (speed_add / speed_batches);
463 469
464 send_string (";"); // +① '' 470 send_string (";"); // +① ''
@@ -625,7 +631,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
625 }else{ // key up 631 }else{ // key up
626 632
627 // Cycles through the modes 633 // Cycles through the modes
628# ifdef DVORAK_DESCRAMBLE_HALF // version Dvorak+Dvorak-descramble has 3 modes 634# ifdef DVORAK_DESCRAMBLE // version Dvorak+Dvorak-descramble has 3 modes
629 if (_NORMAL_ == alternate) { 635 if (_NORMAL_ == alternate) {
630 alternate = _FULL_;// alternate layers 636 alternate = _FULL_;// alternate layers
631 default_layer_set (_ALT_BASE_MASK); // This is needed only for a rare case, 637 default_layer_set (_ALT_BASE_MASK); // This is needed only for a rare case,
@@ -662,7 +668,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
662 }else{ // key up 668 }else{ // key up
663 669
664 // Cycles through the modes 670 // Cycles through the modes
665# ifdef DVORAK_DESCRAMBLE_HALF // version Dvorak+Dvorak-descramble has 3 modes 671# ifdef DVORAK_DESCRAMBLE // version Dvorak+Dvorak-descramble has 3 modes
666 if (_NORMAL_ == alternate) { 672 if (_NORMAL_ == alternate) {
667 alternate = _FULL_;// alternate layers 673 alternate = _FULL_;// alternate layers
668 default_layer_set (_ALT_BASE_MASK); 674 default_layer_set (_ALT_BASE_MASK);
@@ -701,8 +707,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
701 // On BASE itself, that key is <Escape>. 707 // On BASE itself, that key is <Escape>.
702 if (record->event.pressed) { // key down 708 if (record->event.pressed) { // key down
703 ; 709 ;
704 } 710 }else{ // key up
705 else { // key up
706 if (alternate) { // go to the alternate version (bit of a hack maybe, but all alternate 711 if (alternate) { // go to the alternate version (bit of a hack maybe, but all alternate
707 // ... modes are non-zero) 712 // ... modes are non-zero)
708 layer_move (_ALT_BASE); 713 layer_move (_ALT_BASE);
@@ -715,8 +720,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
715 case CTO_NUMS: // activates number-symbols layer 720 case CTO_NUMS: // activates number-symbols layer
716 if (record->event.pressed) { // key down 721 if (record->event.pressed) { // key down
717 ; 722 ;
718 } 723 }else{ // key up, so that upon key down the target layer isn't already activated, triggering that key on up
719 else { // key up, so that upon key down the target layer isn't already activated, triggering that key on up
720 if (alternate) { // go to the alternate version 724 if (alternate) { // go to the alternate version
721 layer_move (_ALT_NSY); 725 layer_move (_ALT_NSY);
722 }else{ 726 }else{
@@ -728,8 +732,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
728 case CTO_ACCE: // Unicode layer 732 case CTO_ACCE: // Unicode layer
729 if (record->event.pressed) { // key down 733 if (record->event.pressed) { // key down
730 ; 734 ;
731 } 735 }else{ // key up
732 else { // key up
733 736
734# ifndef REMOVE_ACC // This cuts out the whole _ACC layer. 737# ifndef REMOVE_ACC // This cuts out the whole _ACC layer.
735 layer_move (_ACC); // activates normal accented layer 738 layer_move (_ACC); // activates normal accented layer
@@ -745,8 +748,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
745 case CTO_DRAW: // Unicode layer 748 case CTO_DRAW: // Unicode layer
746 if (record->event.pressed) { // key down 749 if (record->event.pressed) { // key down
747 ; 750 ;
748 } 751 }else{ // key up
749 else { // key up
750 752
751# ifndef REMOVE_DRA // This cuts out the whole _DRA layer. 753# ifndef REMOVE_DRA // This cuts out the whole _DRA layer.
752 layer_move (_DRA); // activates normal accented layer 754 layer_move (_DRA); // activates normal accented layer
@@ -1011,7 +1013,7 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
1011 // Held medium long: _PAD, long: _MOV. 1013 // Held medium long: _PAD, long: _MOV.
1012 // The reason to have a switch to _MOV on the left hand, is to be able to reach arrows on a toggle, 1014 // The reason to have a switch to _MOV on the left hand, is to be able to reach arrows on a toggle,
1013 // all by the left hand, when the right hand is on the mouse. 1015 // all by the left hand, when the right hand is on the mouse.
1014 if ((timer_elapsed (key_timer) <= 200)) { // tapped medium-long (milliseconds) 1016 if ((timer_elapsed (key_timer) <= 200)) { // tapped short (milliseconds)
1015 1017
1016# ifndef SWITCH_RSHIFT_FUN_RAR // user config to reverse what this key its timing toggles to 1018# ifndef SWITCH_RSHIFT_FUN_RAR // user config to reverse what this key its timing toggles to
1017 1019
@@ -1100,6 +1102,81 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
1100 } 1102 }
1101 break; 1103 break;
1102 1104
1105/*
1106 case RSFT_TILDE:
1107
1108 if (record->event.pressed) { // key down
1109
1110 SEND_STRING (SS_DOWN (X_RSFT));
1111 shift_ison = 1; // shift depressed
1112
1113 key_timer = timer_read ();
1114 isolate_trigger = TRUE; // keep track of whether another key gets pressed until key-up
1115
1116 }else{ // key up
1117
1118 SEND_STRING (SS_UP (X_RSFT));
1119 shift_ison = 0; // shift released
1120
1121 if (isolate_trigger) { // no other key was hit since key down
1122
1123
1124 // Held medium long: _PAD, long: _MOV.
1125 // The reason to have a switch to _MOV on the left hand, is to be able to reach arrows on a toggle,
1126 // all by the left hand, when the right hand is on the mouse.
1127 if ((timer_elapsed (key_timer) <= 200)) { // tapped short (milliseconds)
1128
1129 SEND_STRING ("~");
1130
1131 }
1132 }
1133 }
1134 break;
1135*/
1136
1137 case RSFT_TILDE: // firmware size optimization, saves 36 bytes
1138 case LSFT_DASH:
1139
1140 if (record->event.pressed) { // key down
1141
1142 if (RSFT_TILDE == keycode) { // this is probably not needed, both can be left or right shift
1143 SEND_STRING (SS_DOWN (X_RSFT));
1144 }else{
1145 SEND_STRING (SS_DOWN (X_LSFT));
1146 }
1147 shift_ison = 1; // shift depressed
1148
1149 key_timer = timer_read ();
1150 isolate_trigger = TRUE; // keep track of whether another key gets pressed until key-up
1151
1152 }else{ // key up
1153
1154 if (RSFT_TILDE == keycode) {
1155 SEND_STRING (SS_UP (X_RSFT));
1156 }else{
1157 SEND_STRING (SS_UP (X_LSFT));
1158 }
1159
1160 shift_ison = 0; // shift released
1161
1162 if (isolate_trigger) { // no other key was hit since key down
1163
1164
1165 // Held medium long: _PAD, long: _MOV.
1166 // The reason to have a switch to _MOV on the left hand, is to be able to reach arrows on a toggle,
1167 // all by the left hand, when the right hand is on the mouse.
1168 if ((timer_elapsed (key_timer) <= 200)) { // tapped short (milliseconds)
1169
1170 if (RSFT_TILDE == keycode) {
1171 SEND_STRING ("~");
1172 }else{
1173 SEND_STRING ("-");
1174 }
1175 }
1176 }
1177 }
1178 break;
1179
1103 case _FUN_STAY: // toggles if the f-keys return _FUN layer to BASE after one press 1180 case _FUN_STAY: // toggles if the f-keys return _FUN layer to BASE after one press
1104 if (record->event.pressed) { // key down 1181 if (record->event.pressed) { // key down
1105 1182