repeating Fn key: press twice quickly to repeat.

This commit is contained in:
tmk 2010-11-04 01:08:24 +09:00
parent a31b31e717
commit 89feab2301

48
layer.c
View file

@ -43,6 +43,11 @@
* Fn key send ___|~~~~~~~~~|_____________
* other key press ~~~~~~~|___________________
* other key send ~~~~~~~|___________________
*
* 6. press Fn twice quickly and keep holding down.(repeat)
* Layer sw ___________________________
* Fn key press ___|~|____|~~~~~~~~~~~~~~~~
* Fn key send _____|~|__|~~~~~~~~~~~~~~~~
*/
// LAYER_ENTER_DELAY: prevent from moving new layer
@ -70,17 +75,17 @@ void layer_switching(uint8_t fn_bits)
{
// layer switching
static uint8_t new_layer = 0;
static uint8_t last_bits = 0;
static uint8_t last_fn = 0;
static uint8_t last_mods = 0;
static uint16_t last_timer = 0;
static uint8_t sent_fn = 0;
if (fn_bits == last_bits) { // Fn key is not changed
if (fn_bits == last_fn) { // Fn key is not changed
if (current_layer != new_layer) {
// not switch layer yet
if (timer_elapsed(last_timer) > LAYER_ENTER_DELAY) {
debug("Fn case: 1,2,3(switch layer)\n");
// case: 1,2,3
// switch layer after LAYER_ENTER_DELAY elapse
current_layer = new_layer;
debug("timer_elapsed: "); debug_hex16(timer_elapsed(last_timer)); debug("\n");
debug("switch layer: "); debug_hex(current_layer); debug("\n");
@ -90,55 +95,58 @@ void layer_switching(uint8_t fn_bits)
// send only Fn key first
usb_keyboard_swap_report();
usb_keyboard_clear_report();
usb_keyboard_add_code(keymap_fn_keycode(last_bits));
usb_keyboard_add_code(keymap_fn_keycode(last_fn));
usb_keyboard_set_mods(last_mods);
usb_keyboard_send();
usb_keyboard_swap_report();
// add Fn key to send with other keys
usb_keyboard_add_code(keymap_fn_keycode(last_bits));
// cancel layer switching
usb_keyboard_add_code(keymap_fn_keycode(last_fn));
new_layer = 0;
sent_fn = last_fn;
}
} else {
if (fn_bits && new_layer == 0) {
// case: 4,5
// send Fn key
usb_keyboard_add_code(keymap_fn_keycode(last_bits));
// case: 4,5,6
usb_keyboard_add_code(keymap_fn_keycode(last_fn));
sent_fn = last_fn;
}
}
} else { // Fn key is changed
if (fn_bits == 0) { // Fn key is released(falling edge)
if (!layer_used && timer_elapsed(last_timer) < LAYER_SEND_FN_TERM) {
debug("Fn case: 2(send Fn)\n");
// send Fn key (case: 2[no layer used],3)
// case: 2
usb_keyboard_swap_report();
usb_keyboard_clear_report();
usb_keyboard_add_code(keymap_fn_keycode(last_bits));
usb_keyboard_add_code(keymap_fn_keycode(last_fn));
usb_keyboard_set_mods(last_mods);
usb_keyboard_send();
usb_keyboard_swap_report();
sent_fn = last_fn;
}
debug("Fn case: 1,2,3,4,5(return to default layer)\n");
// return to default layer(case: 1,2,3,4,5)
debug("Fn case: 1,2,3,4,5,6(return to default layer)\n");
new_layer = 0;
current_layer = 0;
} else { // Fn Key is pressed(rising edge)
if (!usb_keyboard_has_key()) {
if (usb_keyboard_has_key() ||
(fn_bits == sent_fn &&timer_elapsed(last_timer) < LAYER_ENTER_DELAY)) {
debug("Fn case: 5,6(add Fn to repeat)\n");
usb_keyboard_add_code(keymap_fn_keycode(fn_bits));
sent_fn = fn_bits;
} else {
debug("Fn case: 1,2,3,4(ready for switching layer)\n");
// ready for switching layer(case: 1,2,3,4)
new_layer = keymap_fn_layer(fn_bits);
} else {
debug("Fn case: 5(add Fn to report)\n");
// add Fn key to send with other keys(case: 5)
usb_keyboard_add_code(keymap_fn_keycode(fn_bits));
sent_fn = 0;
}
}
layer_used = false;
last_bits = fn_bits;
last_fn = fn_bits;
last_mods = usb_keyboard_mods;
last_timer = timer_read();
debug("new_layer: "); debug_hex(new_layer); debug("\n");
debug("last_bits: "); debug_bin(last_bits); debug("\n");
debug("last_fn: "); debug_bin(last_fn); debug("\n");
debug("last_mods: "); debug_hex(last_mods); debug("\n");
debug("last_timer: "); debug_hex16(last_timer); debug("\n");
}