2 Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 #include "layer_switch.h"
27 #include "action_macro.h"
31 static void process_action(keyrecord_t
*record
);
32 static bool process_tapping(keyrecord_t
*record
);
33 static void waiting_buffer_scan_tap(void);
35 static void debug_event(keyevent_t event
);
36 static void debug_record(keyrecord_t record
);
37 static void debug_action(action_t action
);
38 static void debug_tapping_key(void);
39 static void debug_waiting_buffer(void);
45 /* period of tapping(ms) */
47 #define TAPPING_TERM 200
50 /* tap count needed for toggling a feature */
51 #ifndef TAPPING_TOGGLE
52 #define TAPPING_TOGGLE 5
55 /* stores a key event of current tap. */
56 static keyrecord_t tapping_key
= {};
58 #define IS_TAPPING() !IS_NOEVENT(tapping_key.event)
59 #define IS_TAPPING_PRESSED() (IS_TAPPING() && tapping_key.event.pressed)
60 #define IS_TAPPING_RELEASED() (IS_TAPPING() && !tapping_key.event.pressed)
61 #define IS_TAPPING_KEY(k) (IS_TAPPING() && KEYEQ(tapping_key.event.key, (k)))
62 #define WITHIN_TAPPING_TERM(e) (TIMER_DIFF_16(e.time, tapping_key.event.time) < TAPPING_TERM)
68 * stores key events waiting for settling current tap.
70 #define WAITING_BUFFER_SIZE 8
71 static keyrecord_t waiting_buffer
[WAITING_BUFFER_SIZE
] = {};
73 /* point to empty cell to enq */
74 static uint8_t waiting_buffer_head
= 0;
76 /* point to the oldest data cell to deq */
77 static uint8_t waiting_buffer_tail
= 0;
79 static bool waiting_buffer_enq(keyrecord_t record
)
81 if (IS_NOEVENT(record
.event
)) {
85 if ((waiting_buffer_head
+ 1) % WAITING_BUFFER_SIZE
== waiting_buffer_tail
) {
86 debug("waiting_buffer_enq: Over flow.\n");
90 waiting_buffer
[waiting_buffer_head
] = record
;
91 waiting_buffer_head
= (waiting_buffer_head
+ 1) % WAITING_BUFFER_SIZE
;
93 debug("waiting_buffer_enq: "); debug_waiting_buffer();
97 static void waiting_buffer_clear(void)
99 waiting_buffer_head
= 0;
100 waiting_buffer_tail
= 0;
103 #if TAPPING_TERM >= 500
104 static bool waiting_buffer_typed(keyevent_t event
)
106 for (uint8_t i
= waiting_buffer_tail
; i
!= waiting_buffer_head
; i
= (i
+ 1) % WAITING_BUFFER_SIZE
) {
107 if (KEYEQ(event
.key
, waiting_buffer
[i
].event
.key
) && event
.pressed
!= waiting_buffer
[i
].event
.pressed
) {
115 bool waiting_buffer_has_anykey_pressed(void)
117 for (uint8_t i
= waiting_buffer_tail
; i
!= waiting_buffer_head
; i
= (i
+ 1) % WAITING_BUFFER_SIZE
) {
118 if (waiting_buffer
[i
].event
.pressed
) return true;
126 * Problem: Want to capitalize like 'The' but the result tends to be 'THe'.
127 * Solution: Oneshot modifier have its effect on only one key coming next.
128 * Tap Shift, then type 't', 'h' and 'e'. Not need to hold Shift key.
130 * Hold: works as normal modifier.
131 * Tap: one shot modifier.
132 * 2 Tap: cancel one shot modifier.
133 * 5-Tap: toggles enable/disable oneshot feature.
142 static void oneshot_start(uint8_t mods
, uint16_t time
)
144 oneshot_state
.mods
= mods
;
145 oneshot_state
.time
= time
;
146 oneshot_state
.ready
= true;
149 static void oneshot_cancel(void)
151 oneshot_state
.mods
= 0;
152 oneshot_state
.time
= 0;
153 oneshot_state
.ready
= false;
156 static void oneshot_toggle(void)
158 oneshot_state
.disabled
= !oneshot_state
.disabled
;
163 void action_exec(keyevent_t event
)
165 if (!IS_NOEVENT(event
)) {
166 debug("\n---- action_exec: start -----\n");
167 debug("EVENT: "); debug_event(event
); debug("\n");
170 keyrecord_t record
= { .event
= event
};
172 // pre-process on tapping
173 if (process_tapping(&record
)) {
174 if (!IS_NOEVENT(record
.event
)) {
175 debug("processed: "); debug_record(record
); debug("\n");
179 if (!waiting_buffer_enq(record
)) {
180 // clear all in case of overflow.
181 debug("OVERFLOW: CLEAR ALL STATES\n");
183 waiting_buffer_clear();
184 tapping_key
= (keyrecord_t
){};
188 // process waiting_buffer
189 if (!IS_NOEVENT(event
) && waiting_buffer_head
!= waiting_buffer_tail
) {
190 debug("---- action_exec: process waiting_buffer -----\n");
193 for (; waiting_buffer_tail
!= waiting_buffer_head
; waiting_buffer_tail
= (waiting_buffer_tail
+ 1) % WAITING_BUFFER_SIZE
) {
194 if (process_tapping(&waiting_buffer
[waiting_buffer_tail
])) {
195 debug("processed: waiting_buffer["); debug_dec(waiting_buffer_tail
); debug("] = ");
196 debug_record(waiting_buffer
[waiting_buffer_tail
]); debug("\n\n");
201 if (!IS_NOEVENT(event
)) {
206 static void process_action(keyrecord_t
*record
)
208 keyevent_t event
= record
->event
;
209 uint8_t tap_count
= record
->tap_count
;
211 if (IS_NOEVENT(event
)) { return; }
213 action_t action
= layer_switch_get_action(event
.key
);
214 debug("ACTION: "); debug_action(action
);
215 debug(" overlays: "); overlay_debug();
216 debug(" keymaps: "); keymap_debug();
217 debug(" default_layer: "); debug_dec(default_layer
); debug("\n");
219 switch (action
.kind
.id
) {
224 uint8_t mods
= (action
.kind
.id
== ACT_LMODS
) ? action
.key
.mods
:
227 uint8_t tmp_mods
= host_get_mods();
230 host_send_keyboard_report();
232 register_code(action
.key
.code
);
233 if (mods
&& action
.key
.code
) {
234 host_set_mods(tmp_mods
);
235 host_send_keyboard_report();
238 if (mods
&& !action
.key
.code
) {
240 host_send_keyboard_report();
242 unregister_code(action
.key
.code
);
249 uint8_t mods
= (action
.kind
.id
== ACT_LMODS_TAP
) ? action
.key
.mods
:
251 switch (action
.layer
.code
) {
255 if (tap_count
== 0) {
256 debug("MODS_TAP: Oneshot: add_mods\n");
259 else if (tap_count
== 1) {
260 debug("MODS_TAP: Oneshot: start\n");
261 oneshot_start(mods
, event
.time
);
263 else if (tap_count
== TAPPING_TOGGLE
) {
264 debug("MODS_TAP: Oneshot: toggle\n");
268 debug("MODS_TAP: Oneshot: cancel&add_mods\n");
269 // double tap cancels oneshot and works as normal modifier.
274 if (tap_count
== 0) {
275 debug("MODS_TAP: Oneshot: cancel/del_mods\n");
276 // cancel oneshot on hold
280 else if (tap_count
== 1) {
281 debug("MODS_TAP: Oneshot: del_mods\n");
286 debug("MODS_TAP: Oneshot: del_mods\n");
295 if (waiting_buffer_has_anykey_pressed()) {
296 debug("MODS_TAP: Tap: Cancel: add_mods\n");
297 // ad hoc: set 0 to cancel tap
298 record
->tap_count
= 0;
301 debug("MODS_TAP: Tap: register_code\n");
302 register_code(action
.key
.code
);
305 debug("MODS_TAP: No tap: add_mods\n");
310 debug("MODS_TAP: Tap: unregister_code\n");
311 unregister_code(action
.key
.code
);
313 debug("MODS_TAP: No tap: add_mods\n");
322 /* other HID usage */
324 #ifdef EXTRAKEY_ENABLE
325 switch (action
.usage
.page
) {
328 host_system_send(action
.usage
.code
);
335 host_consumer_send(action
.usage
.code
);
337 host_consumer_send(0);
346 #ifdef MOUSEKEY_ENABLE
348 mousekey_on(action
.key
.code
);
351 mousekey_off(action
.key
.code
);
358 switch (action
.layer
.code
) {
361 switch (action
.layer
.val
& 0x03) {
373 if (!event
.pressed
) {
384 /* Keymap Reset default layer */
385 case (OP_RESET
| ON_PRESS
):
389 default_layer_set(action
.layer
.val
);
392 case (OP_RESET
| ON_RELEASE
):
393 if (!event
.pressed
) {
396 default_layer_set(action
.layer
.val
);
399 case (OP_RESET
| ON_BOTH
):
402 default_layer_set(action
.layer
.val
);
405 /* Keymap Bit invert */
407 /* with tap toggle */
409 if (tap_count
< TAPPING_TOGGLE
) {
410 debug("KEYMAP_INV: tap toggle(press).\n");
411 keymap_invert(action
.layer
.val
);
414 if (tap_count
<= TAPPING_TOGGLE
) {
415 debug("KEYMAP_INV: tap toggle(release).\n");
416 keymap_invert(action
.layer
.val
);
420 case (OP_INV
| ON_PRESS
):
422 keymap_invert(action
.layer
.val
);
425 case (OP_INV
| ON_RELEASE
):
426 if (!event
.pressed
) {
427 keymap_invert(action
.layer
.val
);
430 case (OP_INV
| ON_BOTH
):
431 keymap_invert(action
.layer
.val
);
437 keymap_on(action
.layer
.val
);
439 keymap_off(action
.layer
.val
);
442 case (OP_ON
| ON_PRESS
):
444 keymap_on(action
.layer
.val
);
447 case (OP_ON
| ON_RELEASE
):
448 if (!event
.pressed
) {
449 keymap_on(action
.layer
.val
);
452 case (OP_ON
| ON_BOTH
):
453 keymap_on(action
.layer
.val
);
459 keymap_off(action
.layer
.val
);
461 keymap_on(action
.layer
.val
);
464 case (OP_OFF
| ON_PRESS
):
466 keymap_off(action
.layer
.val
);
469 case (OP_OFF
| ON_RELEASE
):
470 if (!event
.pressed
) {
471 keymap_off(action
.layer
.val
);
474 case (OP_OFF
| ON_BOTH
):
475 keymap_off(action
.layer
.val
);
481 keymap_set(action
.layer
.val
);
486 case (OP_SET
| ON_PRESS
):
488 keymap_set(action
.layer
.val
);
491 case (OP_SET
| ON_RELEASE
):
492 if (!event
.pressed
) {
493 keymap_set(action
.layer
.val
);
496 case (OP_SET
| ON_BOTH
):
497 keymap_set(action
.layer
.val
);
500 /* Keymap Bit invert with tap key */
504 debug("KEYMAP_TAP_KEY: Tap: register_code\n");
505 register_code(action
.layer
.code
);
507 debug("KEYMAP_TAP_KEY: No tap: On on press\n");
508 keymap_on(action
.layer
.val
);
512 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n");
513 unregister_code(action
.layer
.code
);
515 debug("KEYMAP_TAP_KEY: No tap: Off on release\n");
516 keymap_off(action
.layer
.val
);
524 switch (action
.layer
.code
) {
525 // Overlay Invert bit4
527 if (action
.layer
.val
== 0) {
530 overlay_set(overlay_stat
^ action
.layer
.val
);
534 if (action
.layer
.val
== 0) {
535 if (event
.pressed
) overlay_clear();
537 overlay_set(overlay_stat
^ action
.layer
.val
<<4);
541 if (action
.layer
.val
== 0) {
542 if (!event
.pressed
) overlay_clear();
544 overlay_set(overlay_stat
^ action
.layer
.val
<<8);
548 if (action
.layer
.val
== 0) {
551 overlay_set(overlay_stat
^ action
.layer
.val
<<12);
555 /* Overlay Bit invert */
557 /* with tap toggle */
559 if (tap_count
< TAPPING_TOGGLE
) {
560 debug("OVERLAY_INV: tap toggle(press).\n");
561 overlay_invert(action
.layer
.val
);
564 if (tap_count
<= TAPPING_TOGGLE
) {
565 debug("OVERLAY_INV: tap toggle(release).\n");
566 overlay_invert(action
.layer
.val
);
570 case (OP_INV
| ON_PRESS
):
572 overlay_invert(action
.layer
.val
);
575 case (OP_INV
| ON_RELEASE
):
576 if (!event
.pressed
) {
577 overlay_invert(action
.layer
.val
);
580 case (OP_INV
| ON_BOTH
):
581 overlay_invert(action
.layer
.val
);
587 overlay_on(action
.layer
.val
);
589 overlay_off(action
.layer
.val
);
592 case (OP_ON
| ON_PRESS
):
594 overlay_on(action
.layer
.val
);
597 case (OP_ON
| ON_RELEASE
):
598 if (!event
.pressed
) {
599 overlay_on(action
.layer
.val
);
602 case (OP_ON
| ON_BOTH
):
603 overlay_on(action
.layer
.val
);
606 /* Overlay Bit off */
609 overlay_off(action
.layer
.val
);
611 overlay_on(action
.layer
.val
);
614 case (OP_OFF
| ON_PRESS
):
616 overlay_off(action
.layer
.val
);
619 case (OP_OFF
| ON_RELEASE
):
620 if (!event
.pressed
) {
621 overlay_off(action
.layer
.val
);
624 case (OP_OFF
| ON_BOTH
):
625 overlay_off(action
.layer
.val
);
628 /* Overlay Bit set */
631 overlay_move(action
.layer
.val
);
636 case (OP_SET
| ON_PRESS
):
638 overlay_move(action
.layer
.val
);
641 case (OP_SET
| ON_RELEASE
):
642 if (!event
.pressed
) {
643 overlay_move(action
.layer
.val
);
646 case (OP_SET
| ON_BOTH
):
647 overlay_move(action
.layer
.val
);
650 /* Overlay Bit invert with tap key */
654 debug("OVERLAY_TAP_KEY: Tap: register_code\n");
655 register_code(action
.layer
.code
);
657 debug("OVERLAY_TAP_KEY: No tap: On on press\n");
658 overlay_on(action
.layer
.val
);
662 debug("OVERLAY_TAP_KEY: Tap: unregister_code\n");
663 unregister_code(action
.layer
.code
);
665 debug("OVERLAY_TAP_KEY: No tap: Off on release\n");
666 overlay_off(action
.layer
.val
);
675 action_macro_play(action_get_macro(record
, action
.func
.id
, action
.func
.opt
));
680 action_function(record
, action
.func
.id
, action
.func
.opt
);
689 * Rule: Tap key is typed(pressed and released) within TAPPING_TERM.
690 * (without interfering by typing other key)
692 /* return true when key event is processed or consumed. */
693 static bool process_tapping(keyrecord_t
*keyp
)
695 keyevent_t event
= keyp
->event
;
698 if (IS_TAPPING_PRESSED()) {
699 if (WITHIN_TAPPING_TERM(event
)) {
700 if (tapping_key
.tap_count
== 0) {
701 if (IS_TAPPING_KEY(event
.key
) && !event
.pressed
) {
703 debug("Tapping: First tap(0->1).\n");
704 tapping_key
.tap_count
= 1;
706 process_action(&tapping_key
);
709 keyp
->tap_count
= tapping_key
.tap_count
;
712 #if TAPPING_TERM >= 500
713 /* This can prevent from typing some tap keys in a row at a time. */
714 else if (!event
.pressed
&& waiting_buffer_typed(event
)) {
715 // other key typed. not tap.
716 debug("Tapping: End. No tap. Interfered by typing key\n");
717 process_action(&tapping_key
);
718 tapping_key
= (keyrecord_t
){};
726 // other key events shall be enq'd till tapping state settles.
732 if (IS_TAPPING_KEY(event
.key
) && !event
.pressed
) {
733 debug("Tapping: Tap release("); debug_dec(tapping_key
.tap_count
); debug(")\n");
734 keyp
->tap_count
= tapping_key
.tap_count
;
735 process_action(keyp
);
740 else if (is_tap_key(keyp
->event
.key
) && event
.pressed
) {
741 if (tapping_key
.tap_count
> 1) {
742 debug("Tapping: Start new tap with releasing last tap(>1).\n");
744 process_action(&(keyrecord_t
){
745 .tap_count
= tapping_key
.tap_count
,
746 .event
.key
= tapping_key
.event
.key
,
747 .event
.time
= event
.time
,
748 .event
.pressed
= false
751 debug("Tapping: Start while last tap(1).\n");
754 waiting_buffer_scan_tap();
759 if (!IS_NOEVENT(keyp
->event
)) {
760 debug("Tapping: key event while last tap(>0).\n");
762 process_action(keyp
);
767 // after TAPPING_TERM
769 if (tapping_key
.tap_count
== 0) {
770 debug("Tapping: End. Timeout. Not tap(0): ");
771 debug_event(event
); debug("\n");
772 process_action(&tapping_key
);
773 tapping_key
= (keyrecord_t
){};
777 if (IS_TAPPING_KEY(event
.key
) && !event
.pressed
) {
778 debug("Tapping: End. last timeout tap release(>0).");
779 keyp
->tap_count
= tapping_key
.tap_count
;
780 process_action(keyp
);
781 tapping_key
= (keyrecord_t
){};
784 else if (is_tap_key(keyp
->event
.key
) && event
.pressed
) {
785 if (tapping_key
.tap_count
> 1) {
786 debug("Tapping: Start new tap with releasing last timeout tap(>1).\n");
788 process_action(&(keyrecord_t
){
789 .tap_count
= tapping_key
.tap_count
,
790 .event
.key
= tapping_key
.event
.key
,
791 .event
.time
= event
.time
,
792 .event
.pressed
= false
795 debug("Tapping: Start while last timeout tap(1).\n");
798 waiting_buffer_scan_tap();
803 if (!IS_NOEVENT(keyp
->event
)) {
804 debug("Tapping: key event while last timeout tap(>0).\n");
806 process_action(keyp
);
811 } else if (IS_TAPPING_RELEASED()) {
812 if (WITHIN_TAPPING_TERM(event
)) {
813 if (tapping_key
.tap_count
> 0 && IS_TAPPING_KEY(event
.key
) && event
.pressed
) {
815 keyp
->tap_count
= tapping_key
.tap_count
+ 1;
816 debug("Tapping: Tap press("); debug_dec(keyp
->tap_count
); debug(")\n");
817 process_action(keyp
);
821 } else if (event
.pressed
&& is_tap_key(event
.key
)) {
822 // Sequential tap can be interfered with other tap key.
823 debug("Tapping: Start with interfering other tap.\n");
825 waiting_buffer_scan_tap();
829 if (!IS_NOEVENT(keyp
->event
)) debug("Tapping: other key just after tap.\n");
830 process_action(keyp
);
834 // timeout. no sequential tap.
835 debug("Tapping: End(Timeout after releasing last tap): ");
836 debug_event(event
); debug("\n");
837 tapping_key
= (keyrecord_t
){};
842 // not tapping satate
844 if (event
.pressed
&& is_tap_key(event
.key
)) {
845 debug("Tapping: Start(Press tap key).\n");
847 waiting_buffer_scan_tap();
851 process_action(keyp
);
857 /* scan buffer for tapping */
858 static void waiting_buffer_scan_tap(void)
860 // tapping already is settled
861 if (tapping_key
.tap_count
> 0) return;
862 // invalid state: tapping_key released && tap_count == 0
863 if (!tapping_key
.event
.pressed
) return;
865 for (uint8_t i
= waiting_buffer_tail
; i
!= waiting_buffer_head
; i
= (i
+ 1) % WAITING_BUFFER_SIZE
) {
866 if (IS_TAPPING_KEY(waiting_buffer
[i
].event
.key
) &&
867 !waiting_buffer
[i
].event
.pressed
&&
868 WITHIN_TAPPING_TERM(waiting_buffer
[i
].event
)) {
869 tapping_key
.tap_count
= 1;
870 waiting_buffer
[i
].tap_count
= 1;
871 process_action(&tapping_key
);
873 debug("waiting_buffer_scan_tap: found at ["); debug_dec(i
); debug("]\n");
874 debug_waiting_buffer();
883 * Utilities for actions.
885 void register_code(uint8_t code
)
890 else if IS_KEY(code
) {
891 // TODO: should push command_proc out of this block?
892 if (command_proc(code
)) return;
894 if (oneshot_state
.mods
&& oneshot_state
.ready
&& !oneshot_state
.disabled
) {
895 uint8_t tmp_mods
= host_get_mods();
896 host_add_mods(oneshot_state
.mods
);
898 host_send_keyboard_report();
900 host_set_mods(tmp_mods
);
901 oneshot_state
.ready
= false;
904 host_send_keyboard_report();
907 else if IS_MOD(code
) {
908 host_add_mods(MOD_BIT(code
));
909 host_send_keyboard_report();
913 void unregister_code(uint8_t code
)
917 host_send_keyboard_report();
919 else if IS_MOD(code
) {
920 host_del_mods(MOD_BIT(code
));
921 host_send_keyboard_report();
925 void add_mods(uint8_t mods
)
929 host_send_keyboard_report();
933 void del_mods(uint8_t mods
)
937 host_send_keyboard_report();
941 void set_mods(uint8_t mods
)
944 host_send_keyboard_report();
947 void clear_keyboard(void)
950 clear_keyboard_but_mods();
953 void clear_keyboard_but_mods(void)
956 host_send_keyboard_report();
957 #ifdef MOUSEKEY_ENABLE
961 #ifdef EXTRAKEY_ENABLE
963 host_consumer_send(0);
967 bool sending_anykey(void)
969 return (host_has_anykey() || host_mouse_in_use() ||
970 host_last_sysytem_report() || host_last_consumer_report());
973 bool is_tap_key(key_t key
)
975 action_t action
= layer_switch_get_action(key
);
977 switch (action
.kind
.id
) {
983 switch (action
.layer
.code
) {
984 case 0x04 ... 0xEF: /* tap key */
991 if (action
.func
.opt
& FUNC_TAP
) { return true; }
1001 static void debug_event(keyevent_t event
)
1003 debug_hex16((event
.key
.row
<<8) | event
.key
.col
);
1004 if (event
.pressed
) debug("d("); else debug("u(");
1005 debug_dec(event
.time
); debug(")");
1007 static void debug_record(keyrecord_t record
)
1009 debug_event(record
.event
); debug(":"); debug_dec(record
.tap_count
);
1011 static void debug_action(action_t action
)
1013 switch (action
.kind
.id
) {
1014 case ACT_LMODS
: debug("ACT_LMODS"); break;
1015 case ACT_RMODS
: debug("ACT_RMODS"); break;
1016 case ACT_LMODS_TAP
: debug("ACT_LMODS_TAP"); break;
1017 case ACT_RMODS_TAP
: debug("ACT_RMODS_TAP"); break;
1018 case ACT_USAGE
: debug("ACT_USAGE"); break;
1019 case ACT_MOUSEKEY
: debug("ACT_MOUSEKEY"); break;
1020 case ACT_KEYMAP
: debug("ACT_KEYMAP"); break;
1021 case ACT_OVERLAY
: debug("ACT_OVERLAY"); break;
1022 case ACT_MACRO
: debug("ACT_MACRO"); break;
1023 case ACT_COMMAND
: debug("ACT_COMMAND"); break;
1024 case ACT_FUNCTION
: debug("ACT_FUNCTION"); break;
1025 default: debug("UNKNOWN"); break;
1028 debug_hex4(action
.kind
.param
>>8);
1030 debug_hex8(action
.kind
.param
& 0xff);
1033 static void debug_tapping_key(void)
1035 debug("TAPPING_KEY="); debug_record(tapping_key
); debug("\n");
1037 static void debug_waiting_buffer(void)
1040 for (uint8_t i
= waiting_buffer_tail
; i
!= waiting_buffer_head
; i
= (i
+ 1) % WAITING_BUFFER_SIZE
) {
1041 debug("["); debug_dec(i
); debug("]="); debug_record(waiting_buffer
[i
]); debug(" ");