diff options
Diffstat (limited to 'layer.c')
| -rw-r--r--[-rwxr-xr-x] | layer.c | 44 |
1 files changed, 25 insertions, 19 deletions
| @@ -25,7 +25,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 25 | 25 | ||
| 26 | /* | 26 | /* |
| 27 | * Parameters: | 27 | * Parameters: |
| 28 | * ENTER_DELAY |=======| | 28 | * SWITCH_DELAY |=======| |
| 29 | * SEND_FN_TERM |================| | 29 | * SEND_FN_TERM |================| |
| 30 | * | 30 | * |
| 31 | * Fn key processing cases: | 31 | * Fn key processing cases: |
| @@ -49,7 +49,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 49 | * other key press _____________|~~|__________ | 49 | * other key press _____________|~~|__________ |
| 50 | * other key send _____________|~~|__________ | 50 | * other key send _____________|~~|__________ |
| 51 | * | 51 | * |
| 52 | * 4. press other key during ENTER_DELAY. | 52 | * 4. press other key during SWITCH_DELAY. |
| 53 | * Layer sw ___________________________ | 53 | * Layer sw ___________________________ |
| 54 | * Fn key press ___|~~~~~~~~~|_____________ | 54 | * Fn key press ___|~~~~~~~~~|_____________ |
| 55 | * Fn key send ______|~~~~~~|_____________ | 55 | * Fn key send ______|~~~~~~|_____________ |
| @@ -69,11 +69,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
| 69 | * Fn key send _____|~|__|~~~~~~~~~~~~~~~~ | 69 | * Fn key send _____|~|__|~~~~~~~~~~~~~~~~ |
| 70 | */ | 70 | */ |
| 71 | 71 | ||
| 72 | // LAYER_ENTER_DELAY: prevent from moving new layer | 72 | // LAYER_SWITCH_DELAY: prevent from moving to new layer |
| 73 | #define LAYER_ENTER_DELAY 150 | 73 | #ifndef LAYER_SWITCH_DELAY |
| 74 | # define LAYER_SWITCH_DELAY 150 | ||
| 75 | #endif | ||
| 74 | 76 | ||
| 75 | // LAYER_SEND_FN_TERM: send keycode if release key in this term | 77 | // LAYER_SEND_FN_TERM: send keycode if release key in this term |
| 76 | #define LAYER_SEND_FN_TERM 500 | 78 | #ifndef LAYER_SEND_FN_TERM |
| 79 | # define LAYER_SEND_FN_TERM 500 | ||
| 80 | #endif | ||
| 77 | 81 | ||
| 78 | 82 | ||
| 79 | uint8_t default_layer = 0; | 83 | uint8_t default_layer = 0; |
| @@ -107,10 +111,11 @@ void layer_switching(uint8_t fn_bits) | |||
| 107 | if (fn_bits == 0) { | 111 | if (fn_bits == 0) { |
| 108 | // do nothing | 112 | // do nothing |
| 109 | } else { | 113 | } else { |
| 110 | if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { | 114 | if (!keymap_fn_keycode(BIT_SUBST(fn_bits, sent_fn)) || |
| 115 | timer_elapsed(last_timer) > LAYER_SWITCH_DELAY) { | ||
| 111 | uint8_t _layer_to_switch = new_layer(BIT_SUBST(fn_bits, sent_fn)); | 116 | uint8_t _layer_to_switch = new_layer(BIT_SUBST(fn_bits, sent_fn)); |
| 112 | if (current_layer != _layer_to_switch) { // not switch layer yet | 117 | if (current_layer != _layer_to_switch) { // not switch layer yet |
| 113 | debug("Fn case: 1,2,3(LAYER_ENTER_DELAY passed)\n"); | 118 | debug("Fn case: 1,2,3(LAYER_SWITCH_DELAY passed)\n"); |
| 114 | debug("Switch Layer: "); debug_hex(current_layer); | 119 | debug("Switch Layer: "); debug_hex(current_layer); |
| 115 | current_layer = _layer_to_switch; | 120 | current_layer = _layer_to_switch; |
| 116 | layer_used = false; | 121 | layer_used = false; |
| @@ -120,14 +125,14 @@ void layer_switching(uint8_t fn_bits) | |||
| 120 | if (host_has_anykey()) { // other keys is pressed | 125 | if (host_has_anykey()) { // other keys is pressed |
| 121 | uint8_t _fn_to_send = BIT_SUBST(fn_bits, sent_fn); | 126 | uint8_t _fn_to_send = BIT_SUBST(fn_bits, sent_fn); |
| 122 | if (_fn_to_send) { | 127 | if (_fn_to_send) { |
| 123 | debug("Fn case: 4(send Fn before other key pressed)\n"); | 128 | debug("Fn case: 4(press other key during SWITCH_DELAY.)\n"); |
| 124 | // send only Fn key first | 129 | // send only Fn key first |
| 125 | host_swap_keyboard_report(); | 130 | uint8_t tmp_mods = keyboard_report->mods; |
| 126 | host_clear_keyboard_report(); | 131 | host_add_code(keymap_fn_keycode(_fn_to_send)); |
| 127 | host_set_mods(last_mods); | 132 | host_set_mods(last_mods); |
| 128 | host_add_code(keymap_fn_keycode(_fn_to_send)); // TODO: do all Fn keys | ||
| 129 | host_send_keyboard_report(); | 133 | host_send_keyboard_report(); |
| 130 | host_swap_keyboard_report(); | 134 | host_set_mods(tmp_mods); |
| 135 | host_del_code(keymap_fn_keycode(_fn_to_send)); | ||
| 131 | sent_fn |= _fn_to_send; | 136 | sent_fn |= _fn_to_send; |
| 132 | } | 137 | } |
| 133 | } | 138 | } |
| @@ -143,15 +148,16 @@ void layer_switching(uint8_t fn_bits) | |||
| 143 | debug("last_fn: "); debug_bin(last_fn); debug("\n"); | 148 | debug("last_fn: "); debug_bin(last_fn); debug("\n"); |
| 144 | debug("last_mods: "); debug_hex(last_mods); debug("\n"); | 149 | debug("last_mods: "); debug_hex(last_mods); debug("\n"); |
| 145 | debug("last_timer: "); debug_hex16(last_timer); debug("\n"); | 150 | debug("last_timer: "); debug_hex16(last_timer); debug("\n"); |
| 151 | debug("timer_count: "); debug_hex16(timer_count); debug("\n"); | ||
| 146 | 152 | ||
| 147 | // pressed Fn | 153 | // pressed Fn |
| 148 | if ((fn_changed = BIT_SUBST(fn_bits, last_fn))) { | 154 | if ((fn_changed = BIT_SUBST(fn_bits, last_fn))) { |
| 149 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); | 155 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); |
| 150 | if (host_has_anykey()) { | 156 | if (host_has_anykey()) { |
| 151 | debug("Fn case: 5(pressed Fn with other key)\n"); | 157 | debug("Fn case: 5(pressed Fn with other key)\n"); |
| 152 | sent_fn |= fn_changed; | 158 | sent_fn |= fn_changed; |
| 153 | } else if (fn_changed & sent_fn) { // pressed same Fn in a row | 159 | } else if (fn_changed & sent_fn) { // pressed same Fn in a row |
| 154 | if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) { | 160 | if (timer_elapsed(last_timer) > LAYER_SEND_FN_TERM) { |
| 155 | debug("Fn case: 6(not repeat)\n"); | 161 | debug("Fn case: 6(not repeat)\n"); |
| 156 | // time passed: not repeate | 162 | // time passed: not repeate |
| 157 | sent_fn &= ~fn_changed; | 163 | sent_fn &= ~fn_changed; |
| @@ -162,17 +168,17 @@ void layer_switching(uint8_t fn_bits) | |||
| 162 | } | 168 | } |
| 163 | // released Fn | 169 | // released Fn |
| 164 | if ((fn_changed = BIT_SUBST(last_fn, fn_bits))) { | 170 | if ((fn_changed = BIT_SUBST(last_fn, fn_bits))) { |
| 165 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); | 171 | debug("fn_changed: "); debug_bin(fn_changed); debug("\n"); |
| 166 | if (timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) { | 172 | if (timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) { |
| 167 | if (!layer_used && BIT_SUBST(fn_changed, sent_fn)) { | 173 | if (!layer_used && BIT_SUBST(fn_changed, sent_fn)) { |
| 168 | debug("Fn case: 2(send Fn one shot: released Fn during LAYER_SEND_FN_TERM)\n"); | 174 | debug("Fn case: 2(send Fn one shot: released Fn during LAYER_SEND_FN_TERM)\n"); |
| 169 | // send only Fn key first | 175 | // send only Fn key first |
| 170 | host_swap_keyboard_report(); | 176 | uint8_t tmp_mods = keyboard_report->mods; |
| 171 | host_clear_keyboard_report(); | 177 | host_add_code(keymap_fn_keycode(fn_changed)); |
| 172 | host_set_mods(last_mods); | 178 | host_set_mods(last_mods); |
| 173 | host_add_code(keymap_fn_keycode(fn_changed)); // TODO: do all Fn keys | ||
| 174 | host_send_keyboard_report(); | 179 | host_send_keyboard_report(); |
| 175 | host_swap_keyboard_report(); | 180 | host_set_mods(tmp_mods); |
| 181 | host_del_code(keymap_fn_keycode(fn_changed)); | ||
| 176 | sent_fn |= fn_changed; | 182 | sent_fn |= fn_changed; |
| 177 | } | 183 | } |
| 178 | } | 184 | } |
