aboutsummaryrefslogtreecommitdiff
path: root/common/action.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-01-28 11:30:23 +0900
committertmk <nobody@nowhere>2013-01-28 11:30:23 +0900
commit854c803fdda30d7f7905c18d777ea85cac9b74d9 (patch)
tree4039718dd8412af86992288bc9ac7ac996078353 /common/action.c
parentbfd7fe586297d70f824a402fd476c3daa889fa56 (diff)
downloadqmk_firmware-854c803fdda30d7f7905c18d777ea85cac9b74d9.tar.gz
qmk_firmware-854c803fdda30d7f7905c18d777ea85cac9b74d9.zip
Add tap toggle feature to action.
Diffstat (limited to 'common/action.c')
-rw-r--r--common/action.c162
1 files changed, 127 insertions, 35 deletions
diff --git a/common/action.c b/common/action.c
index 22f0bf0a0..4b3b1dd68 100644
--- a/common/action.c
+++ b/common/action.c
@@ -19,6 +19,8 @@ uint8_t current_layer = 0;
19 19
20/* tap term(ms) */ 20/* tap term(ms) */
21#define TAP_TERM 200 21#define TAP_TERM 200
22/* number of tap which fires toggle feature */
23#define TAP_TOGGLE 5
22 24
23/* This counts up when tap occurs */ 25/* This counts up when tap occurs */
24uint8_t tap_count = 0; 26uint8_t tap_count = 0;
@@ -59,10 +61,11 @@ static bool waiting_buffer_enq(keyrecord_t record)
59 waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE; 61 waiting_buffer_head = (waiting_buffer_head + 1) % WAITING_BUFFER_SIZE;
60 return true; 62 return true;
61} 63}
64/*
62static keyrecord_t waiting_buffer_deq(void) 65static keyrecord_t waiting_buffer_deq(void)
63{ 66{
64 if (waiting_buffer_head == waiting_buffer_tail) { 67 if (waiting_buffer_head == waiting_buffer_tail) {
65 return (keyrecord_t){}; 68 return (keyrecord_t){}; // ???
66 } 69 }
67 uint8_t last_tail = waiting_buffer_tail; 70 uint8_t last_tail = waiting_buffer_tail;
68 waiting_buffer_tail = waiting_buffer_tail + 1 % WAITING_BUFFER_SIZE; 71 waiting_buffer_tail = waiting_buffer_tail + 1 % WAITING_BUFFER_SIZE;
@@ -72,6 +75,7 @@ static bool waiting_buffer_is_empty(void)
72{ 75{
73 return (waiting_buffer_head == waiting_buffer_tail); 76 return (waiting_buffer_head == waiting_buffer_tail);
74} 77}
78*/
75static void waiting_buffer_clear(void) 79static void waiting_buffer_clear(void)
76{ 80{
77 waiting_buffer_head = 0; 81 waiting_buffer_head = 0;
@@ -93,9 +97,7 @@ static bool waiting_buffer_has_anykey_pressed(void)
93 } 97 }
94 return false; 98 return false;
95} 99}
96static void waiting_buffer_process(void) 100
97{
98}
99 101
100/* Oneshot modifier 102/* Oneshot modifier
101 * 103 *
@@ -270,6 +272,7 @@ void action_exec(keyevent_t event)
270 if (!IS_NOEVENT(record.event)) debug("processed.\n"); 272 if (!IS_NOEVENT(record.event)) debug("processed.\n");
271 } else { 273 } else {
272 if (!IS_NOEVENT(record.event)) debug("enqueued.\n"); 274 if (!IS_NOEVENT(record.event)) debug("enqueued.\n");
275 // enqueue
273 if (!waiting_buffer_enq(record)) { 276 if (!waiting_buffer_enq(record)) {
274 // clear all in case of overflow. 277 // clear all in case of overflow.
275 clear_keyboard(); 278 clear_keyboard();
@@ -278,7 +281,6 @@ void action_exec(keyevent_t event)
278 } 281 }
279 } 282 }
280 283
281 // TODO: need to process every time?
282 // process waiting_buffer 284 // process waiting_buffer
283 for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) { 285 for (; waiting_buffer_tail != waiting_buffer_head; waiting_buffer_tail = (waiting_buffer_tail + 1) % WAITING_BUFFER_SIZE) {
284 if (process_tap(&waiting_buffer[waiting_buffer_tail])) { 286 if (process_tap(&waiting_buffer[waiting_buffer_tail])) {
@@ -292,7 +294,6 @@ void action_exec(keyevent_t event)
292 294
293static void process(keyrecord_t *record) 295static void process(keyrecord_t *record)
294{ 296{
295 // TODO: use record
296 keyevent_t event = record->event; 297 keyevent_t event = record->event;
297 uint8_t tap_count = record->tap_count; 298 uint8_t tap_count = record->tap_count;
298 299
@@ -450,9 +451,20 @@ static void process(keyrecord_t *record)
450 } 451 }
451 break; 452 break;
452 case 0xF0: 453 case 0xF0:
453 // TODO: tap toggle 454 // tap toggle
455 if (event.pressed) {
456 if (tap_count < TAP_TOGGLE) {
457 layer_switch(action.layer.opt);
458 }
459 } else {
460 if (tap_count >= TAP_TOGGLE) {
461 debug("LAYER_PRESSED: tap toggle.\n");
462 layer_switch(action.layer.opt);
463 }
464 }
454 break; 465 break;
455 case 0xFF: 466 case 0xFF:
467 // change default layer
456 if (event.pressed) { 468 if (event.pressed) {
457 default_layer = action.layer.opt; 469 default_layer = action.layer.opt;
458 layer_switch(default_layer); 470 layer_switch(default_layer);
@@ -461,30 +473,15 @@ static void process(keyrecord_t *record)
461 default: 473 default:
462 // with tap key 474 // with tap key
463 if (event.pressed) { 475 if (event.pressed) {
464 if (IS_TAPPING_KEY(event.key)) { 476 if (tap_count > 0) {
465 if (tap_count > 0) {
466 debug("LAYER_PRESSED: Tap: register_code\n");
467 register_code(action.layer.code);
468 } else {
469 debug("LAYER_PRESSED: No tap: layer_switch\n");
470 layer_switch(action.layer.opt);
471 }
472 } else {
473 // TODO: while other key tapping
474 debug("LAYER_PRESSED: No tap: layer_switch\n");
475 layer_switch(action.layer.opt);
476 }
477/*
478 if (IS_TAPPING_KEY(event.key) && tap_count > 0) {
479 debug("LAYER_PRESSED: Tap: register_code\n"); 477 debug("LAYER_PRESSED: Tap: register_code\n");
480 register_code(action.layer.code); 478 register_code(action.layer.code);
481 } else { 479 } else {
482 debug("LAYER_PRESSED: No tap: layer_switch\n"); 480 debug("LAYER_PRESSED: No tap: layer_switch\n");
483 layer_switch(action.layer.opt); 481 layer_switch(action.layer.opt);
484 } 482 }
485*/
486 } else { 483 } else {
487 if (IS_TAPPING_KEY(event.key) && tap_count > 0) { 484 if (tap_count > 0) {
488 debug("LAYER_PRESSED: Tap: unregister_code\n"); 485 debug("LAYER_PRESSED: Tap: unregister_code\n");
489 unregister_code(action.layer.code); 486 unregister_code(action.layer.code);
490 } else { 487 } else {
@@ -502,16 +499,43 @@ static void process(keyrecord_t *record)
502 } 499 }
503 break; 500 break;
504 case 0xF0: 501 case 0xF0:
505 // Ignored. LAYER_RELEASED with tap toggle is invalid action. 502 // tap toggle
503 if (event.pressed) {
504 if (tap_count >= TAP_TOGGLE) {
505 debug("LAYER_RELEASED: tap toggle.\n");
506 layer_switch(action.layer.opt);
507 }
508 } else {
509 if (tap_count < TAP_TOGGLE) {
510 layer_switch(action.layer.opt);
511 }
512 }
506 break; 513 break;
507 case 0xFF: 514 case 0xFF:
515 // change default layer
508 if (!event.pressed) { 516 if (!event.pressed) {
509 default_layer = action.layer.opt; 517 default_layer = action.layer.opt;
510 layer_switch(default_layer); 518 layer_switch(default_layer);
511 } 519 }
512 break; 520 break;
513 default: 521 default:
514 // Ignored. LAYER_RELEASED with tap key is invalid action. 522 // with tap key
523 if (event.pressed) {
524 if (tap_count > 0) {
525 debug("LAYER_RELEASED: Tap: register_code\n");
526 register_code(action.layer.code);
527 } else {
528 debug("LAYER_RELEASED: No tap: NO ACTION\n");
529 }
530 } else {
531 if (tap_count > 0) {
532 debug("LAYER_RELEASED: Tap: unregister_code\n");
533 unregister_code(action.layer.code);
534 } else {
535 debug("LAYER_RELEASED: No tap: layer_switch\n");
536 layer_switch(action.layer.opt);
537 }
538 }
515 break; 539 break;
516 } 540 }
517 break; 541 break;
@@ -525,7 +549,21 @@ static void process(keyrecord_t *record)
525 } 549 }
526 break; 550 break;
527 case 0xF0: 551 case 0xF0:
528 // TODO: tap toggle 552 // tap toggle
553 if (event.pressed) {
554 if (tap_count < TAP_TOGGLE) {
555 debug("LAYER_BIT: tap toggle(press).\n");
556 layer_switch(current_layer | action.layer.opt);
557 }
558 } else {
559 if (tap_count < TAP_TOGGLE) {
560 debug("LAYER_BIT: tap toggle(release).\n");
561 layer_switch(current_layer & ~action.layer.opt);
562 } else {
563 debug("LAYER_BIT: tap toggle.\n");
564 layer_switch(current_layer | action.layer.opt);
565 }
566 }
529 break; 567 break;
530 case 0xFF: 568 case 0xFF:
531 // change default layer 569 // change default layer
@@ -558,6 +596,7 @@ static void process(keyrecord_t *record)
558 } 596 }
559 break; 597 break;
560 } 598 }
599 break;
561 case ACT_LAYER_EXT: 600 case ACT_LAYER_EXT:
562 switch (action.layer.opt) { 601 switch (action.layer.opt) {
563 case 0x00: 602 case 0x00:
@@ -569,16 +608,43 @@ static void process(keyrecord_t *record)
569 } 608 }
570 break; 609 break;
571 case 0xF0: 610 case 0xF0:
572 // TODO: tap toggle 611 // tap toggle
612 if (event.pressed) {
613 if (tap_count < TAP_TOGGLE) {
614 layer_switch(default_layer);
615 }
616 } else {
617 if (tap_count >= TAP_TOGGLE) {
618 debug("LAYER_EXT_PRESSED: tap toggle.\n");
619 layer_switch(default_layer);
620 }
621 }
573 break; 622 break;
574 case 0xFF: 623 case 0xFF:
624 // change default layer
575 if (event.pressed) { 625 if (event.pressed) {
576 default_layer = current_layer; 626 default_layer = current_layer;
577 layer_switch(default_layer); 627 layer_switch(default_layer);
578 } 628 }
579 break; 629 break;
580 default: 630 default:
581 // TODO: tap key 631 // with tap key
632 if (event.pressed) {
633 if (tap_count > 0) {
634 debug("LAYER_EXT_PRESSED: Tap: register_code\n");
635 register_code(action.layer.code);
636 } else {
637 debug("LAYER_EXT_PRESSED: No tap: layer_switch\n");
638 layer_switch(default_layer);
639 }
640 } else {
641 if (tap_count > 0) {
642 debug("LAYER_EXT_PRESSED: Tap: unregister_code\n");
643 unregister_code(action.layer.code);
644 } else {
645 debug("LAYER_EXT_PRESSED: No tap: NO ACTION\n");
646 }
647 }
582 break; 648 break;
583 } 649 }
584 break; 650 break;
@@ -590,17 +656,43 @@ static void process(keyrecord_t *record)
590 layer_switch(default_layer); 656 layer_switch(default_layer);
591 } 657 }
592 break; 658 break;
659 case 0xF0:
660 // tap toggle
661 if (event.pressed) {
662 if (tap_count >= TAP_TOGGLE) {
663 debug("LAYER_EXT_RELEASED: tap toggle.\n");
664 layer_switch(default_layer);
665 }
666 } else {
667 if (tap_count < TAP_TOGGLE) {
668 layer_switch(default_layer);
669 }
670 }
671 break;
593 case 0xFF: 672 case 0xFF:
673 // change default layer
594 if (!event.pressed) { 674 if (!event.pressed) {
595 default_layer = current_layer; 675 default_layer = current_layer;
596 layer_switch(default_layer); 676 layer_switch(default_layer);
597 } 677 }
598 break; 678 break;
599 case 0xF0:
600 default: 679 default:
601 // Ignore tap. 680 // with tap key
602 if (!event.pressed) { 681 if (event.pressed) {
603 layer_switch(default_layer); 682 if (tap_count > 0) {
683 debug("LAYER_EXT_RELEASED: Tap: register_code\n");
684 register_code(action.layer.code);
685 } else {
686 debug("LAYER_EXT_RELEASED: No tap: NO ACTION\n");
687 }
688 } else {
689 if (tap_count > 0) {
690 debug("LAYER_EXT_RELEASED: Tap: unregister_code\n");
691 unregister_code(action.layer.code);
692 } else {
693 debug("LAYER_EXT_RELEASED: No tap: layer_switch\n");
694 layer_switch(default_layer);
695 }
604 } 696 }
605 break; 697 break;
606 } 698 }