diff options
| author | tmk <nobody@nowhere> | 2011-05-04 21:19:34 +0900 |
|---|---|---|
| committer | tmk <nobody@nowhere> | 2011-05-04 21:19:34 +0900 |
| commit | a6b31e950fe8de3dc4888e2f90a4001a6caee483 (patch) | |
| tree | 4cacf14e4858946760202ef8545aff879bf54eba | |
| parent | b0b6c333320216492ea63979e9a01f5c4cb090db (diff) | |
| download | qmk_firmware-a6b31e950fe8de3dc4888e2f90a4001a6caee483.tar.gz qmk_firmware-a6b31e950fe8de3dc4888e2f90a4001a6caee483.zip | |
fix bug: send Fn key even after the layer is used.
| -rw-r--r-- | layer.c | 23 |
1 files changed, 11 insertions, 12 deletions
| @@ -52,7 +52,7 @@ | |||
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | // LAYER_ENTER_DELAY: prevent from moving new layer | 54 | // LAYER_ENTER_DELAY: prevent from moving new layer |
| 55 | #define LAYER_ENTER_DELAY 10 | 55 | #define LAYER_ENTER_DELAY 5 |
| 56 | 56 | ||
| 57 | // LAYER_SEND_FN_TERM: send keycode if release key in this term | 57 | // LAYER_SEND_FN_TERM: send keycode if release key in this term |
| 58 | #define LAYER_SEND_FN_TERM 40 | 58 | #define LAYER_SEND_FN_TERM 40 |
| @@ -76,7 +76,7 @@ uint8_t layer_get_keycode(uint8_t row, uint8_t col) | |||
| 76 | } | 76 | } |
| 77 | 77 | ||
| 78 | // bit substract b from a | 78 | // bit substract b from a |
| 79 | #define BIT_SUBT(a, b) (a&(a^b)) | 79 | #define BIT_SUBST(a, b) (a&(a^b)) |
| 80 | void layer_switching(uint8_t fn_bits) | 80 | void layer_switching(uint8_t fn_bits) |
| 81 | { | 81 | { |
| 82 | // layer switching | 82 | // layer switching |
| @@ -90,7 +90,7 @@ void layer_switching(uint8_t fn_bits) | |||
| 90 | // do nothing | 90 | // do nothing |
| 91 | } else { | 91 | } else { |
| 92 | if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { | 92 | if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { |
| 93 | uint8_t _layer_to_switch = new_layer(BIT_SUBT(fn_bits, sent_fn)); | 93 | uint8_t _layer_to_switch = new_layer(BIT_SUBST(fn_bits, sent_fn)); |
| 94 | if (current_layer != _layer_to_switch) { // not switch layer yet | 94 | if (current_layer != _layer_to_switch) { // not switch layer yet |
| 95 | debug("Fn case: 1,2,3(LAYER_ENTER_DELAY passed)\n"); | 95 | debug("Fn case: 1,2,3(LAYER_ENTER_DELAY passed)\n"); |
| 96 | debug("Switch Layer: "); debug_hex(current_layer); | 96 | debug("Switch Layer: "); debug_hex(current_layer); |
| @@ -100,7 +100,7 @@ void layer_switching(uint8_t fn_bits) | |||
| 100 | } | 100 | } |
| 101 | } else { | 101 | } else { |
| 102 | if (host_has_anykey()) { // other keys is pressed | 102 | if (host_has_anykey()) { // other keys is pressed |
| 103 | uint8_t _fn_to_send = BIT_SUBT(fn_bits, sent_fn); | 103 | uint8_t _fn_to_send = BIT_SUBST(fn_bits, sent_fn); |
| 104 | if (_fn_to_send) { | 104 | if (_fn_to_send) { |
| 105 | debug("Fn case: 4(send Fn before other key pressed)\n"); | 105 | debug("Fn case: 4(send Fn before other key pressed)\n"); |
| 106 | // send only Fn key first | 106 | // send only Fn key first |
| @@ -127,27 +127,26 @@ void layer_switching(uint8_t fn_bits) | |||
| 127 | debug("last_timer: "); debug_hex16(last_timer); debug("\n"); | 127 | debug("last_timer: "); debug_hex16(last_timer); debug("\n"); |
| 128 | 128 | ||
| 129 | // pressed Fn | 129 | // pressed Fn |
| 130 | if ((fn_changed = BIT_SUBT(fn_bits, last_fn))) { | 130 | if ((fn_changed = BIT_SUBST(fn_bits, last_fn))) { |
| 131 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); | 131 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); |
| 132 | if (host_has_anykey()) { | 132 | if (host_has_anykey()) { |
| 133 | debug("Fn case: 5(pressed Fn with other key)\n"); | 133 | debug("Fn case: 5(pressed Fn with other key)\n"); |
| 134 | sent_fn |= fn_changed; | 134 | sent_fn |= fn_changed; |
| 135 | } else if (fn_changed & sent_fn) { // pressed same Fn in a row | 135 | } else if (fn_changed & sent_fn) { // pressed same Fn in a row |
| 136 | if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { | 136 | if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { |
| 137 | debug("Fn case: 6(repate2)\n"); | 137 | debug("Fn case: 6(not repeat)\n"); |
| 138 | // time passed: not repeate | 138 | // time passed: not repeate |
| 139 | sent_fn &= ~fn_changed; | 139 | sent_fn &= ~fn_changed; |
| 140 | } else { | 140 | } else { |
| 141 | debug("Fn case: 6(repate)\n"); | 141 | debug("Fn case: 6(repeat)\n"); |
| 142 | } | 142 | } |
| 143 | } | 143 | } |
| 144 | } | 144 | } |
| 145 | // released Fn | 145 | // released Fn |
| 146 | if ((fn_changed = BIT_SUBT(last_fn, fn_bits))) { | 146 | if ((fn_changed = BIT_SUBST(last_fn, fn_bits))) { |
| 147 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); | 147 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); |
| 148 | if (timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) { | 148 | if (timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) { |
| 149 | //if (!layer_used && BIT_SUBT(fn_changed, sent_fn)) { // layer not used && Fn not sent | 149 | if (!layer_used && BIT_SUBST(fn_changed, sent_fn)) { |
| 150 | if (BIT_SUBT(fn_changed, sent_fn)) { // layer not used && Fn not sent | ||
| 151 | debug("Fn case: 2(send Fn one shot: released Fn during LAYER_SEND_FN_TERM)\n"); | 150 | debug("Fn case: 2(send Fn one shot: released Fn during LAYER_SEND_FN_TERM)\n"); |
| 152 | // send only Fn key first | 151 | // send only Fn key first |
| 153 | host_swap_keyboard_report(); | 152 | host_swap_keyboard_report(); |
| @@ -160,11 +159,11 @@ void layer_switching(uint8_t fn_bits) | |||
| 160 | } | 159 | } |
| 161 | } | 160 | } |
| 162 | debug("Switch Layer(released Fn): "); debug_hex(current_layer); | 161 | debug("Switch Layer(released Fn): "); debug_hex(current_layer); |
| 163 | current_layer = new_layer(BIT_SUBT(fn_bits, sent_fn)); | 162 | current_layer = new_layer(BIT_SUBST(fn_bits, sent_fn)); |
| 164 | layer_used = false; | ||
| 165 | debug(" -> "); debug_hex(current_layer); debug("\n"); | 163 | debug(" -> "); debug_hex(current_layer); debug("\n"); |
| 166 | } | 164 | } |
| 167 | 165 | ||
| 166 | layer_used = false; | ||
| 168 | last_fn = fn_bits; | 167 | last_fn = fn_bits; |
| 169 | last_mods = keyboard_report->mods; | 168 | last_mods = keyboard_report->mods; |
| 170 | last_timer = timer_read(); | 169 | last_timer = timer_read(); |
