aboutsummaryrefslogtreecommitdiff
path: root/common/action.c
diff options
context:
space:
mode:
authortmk <nobody@nowhere>2013-05-14 16:18:22 +0900
committertmk <nobody@nowhere>2013-05-14 16:19:40 +0900
commitff2d276b193632136c785d92ed01df48aea8461f (patch)
treebd8e7c789fbb7f191b4de31498160f05d2f80229 /common/action.c
parentd9c06db60006e2191d8b86e34f651644a54426b4 (diff)
downloadqmk_firmware-ff2d276b193632136c785d92ed01df48aea8461f.tar.gz
qmk_firmware-ff2d276b193632136c785d92ed01df48aea8461f.zip
Use dprint and dprintf for debug
Diffstat (limited to 'common/action.c')
-rw-r--r--common/action.c92
1 files changed, 45 insertions, 47 deletions
diff --git a/common/action.c b/common/action.c
index 065188744..c7c8f71f2 100644
--- a/common/action.c
+++ b/common/action.c
@@ -19,7 +19,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
19#include "keyboard.h" 19#include "keyboard.h"
20#include "mousekey.h" 20#include "mousekey.h"
21#include "command.h" 21#include "command.h"
22#include "debug.h"
23#include "led.h" 22#include "led.h"
24#include "action_layer.h" 23#include "action_layer.h"
25#include "action_tapping.h" 24#include "action_tapping.h"
@@ -27,12 +26,18 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
27#include "action_macro.h" 26#include "action_macro.h"
28#include "action.h" 27#include "action.h"
29 28
29#ifdef DEBUG_ACTION
30#include "debug.h"
31#else
32#include "nodebug.h"
33#endif
34
30 35
31void action_exec(keyevent_t event) 36void action_exec(keyevent_t event)
32{ 37{
33 if (!IS_NOEVENT(event)) { 38 if (!IS_NOEVENT(event)) {
34 debug("\n---- action_exec: start -----\n"); 39 dprint("\n---- action_exec: start -----\n");
35 debug("EVENT: "); debug_event(event); debug("\n"); 40 dprint("EVENT: "); debug_event(event); dprintln();
36 } 41 }
37 42
38 keyrecord_t record = { .event = event }; 43 keyrecord_t record = { .event = event };
@@ -42,7 +47,7 @@ void action_exec(keyevent_t event)
42#else 47#else
43 process_action(&record); 48 process_action(&record);
44 if (!IS_NOEVENT(record.event)) { 49 if (!IS_NOEVENT(record.event)) {
45 debug("processed: "); debug_record(record); debug("\n"); 50 dprint("processed: "); debug_record(record); dprintln();
46 } 51 }
47#endif 52#endif
48} 53}
@@ -57,12 +62,12 @@ void process_action(keyrecord_t *record)
57 if (IS_NOEVENT(event)) { return; } 62 if (IS_NOEVENT(event)) { return; }
58 63
59 action_t action = layer_switch_get_action(event.key); 64 action_t action = layer_switch_get_action(event.key);
60 debug("ACTION: "); debug_action(action); 65 dprint("ACTION: "); debug_action(action);
61#ifndef NO_ACTION_LAYER 66#ifndef NO_ACTION_LAYER
62 debug(" layer_state: "); layer_debug(); 67 dprint(" layer_state: "); layer_debug();
63 debug(" default_layer_state: "); default_layer_debug(); 68 dprint(" default_layer_state: "); default_layer_debug();
64#endif 69#endif
65 debug("\n"); 70 dprintln();
66 71
67 switch (action.kind.id) { 72 switch (action.kind.id) {
68 /* Key and Mods */ 73 /* Key and Mods */
@@ -98,37 +103,37 @@ void process_action(keyrecord_t *record)
98 // Oneshot modifier 103 // Oneshot modifier
99 if (event.pressed) { 104 if (event.pressed) {
100 if (tap_count == 0) { 105 if (tap_count == 0) {
101 debug("MODS_TAP: Oneshot: add_mods\n"); 106 dprint("MODS_TAP: Oneshot: add_mods\n");
102 add_mods(mods); 107 add_mods(mods);
103 } 108 }
104 else if (tap_count == 1) { 109 else if (tap_count == 1) {
105 debug("MODS_TAP: Oneshot: start\n"); 110 dprint("MODS_TAP: Oneshot: start\n");
106 oneshot_start(mods); 111 oneshot_start(mods);
107 } 112 }
108 else if (tap_count == TAPPING_TOGGLE) { 113 else if (tap_count == TAPPING_TOGGLE) {
109 debug("MODS_TAP: Oneshot: toggle\n"); 114 dprint("MODS_TAP: Oneshot: toggle\n");
110 oneshot_toggle(); 115 oneshot_toggle();
111 } 116 }
112 else { 117 else {
113 debug("MODS_TAP: Oneshot: cancel&add_mods\n"); 118 dprint("MODS_TAP: Oneshot: cancel&add_mods\n");
114 // double tap cancels oneshot and works as normal modifier. 119 // double tap cancels oneshot and works as normal modifier.
115 oneshot_cancel(); 120 oneshot_cancel();
116 add_mods(mods); 121 add_mods(mods);
117 } 122 }
118 } else { 123 } else {
119 if (tap_count == 0) { 124 if (tap_count == 0) {
120 debug("MODS_TAP: Oneshot: cancel/del_mods\n"); 125 dprint("MODS_TAP: Oneshot: cancel/del_mods\n");
121 // cancel oneshot on hold 126 // cancel oneshot on hold
122 oneshot_cancel(); 127 oneshot_cancel();
123 del_mods(mods); 128 del_mods(mods);
124 } 129 }
125 else if (tap_count == 1) { 130 else if (tap_count == 1) {
126 debug("MODS_TAP: Oneshot: del_mods\n"); 131 dprint("MODS_TAP: Oneshot: del_mods\n");
127 // retain Oneshot 132 // retain Oneshot
128 del_mods(mods); 133 del_mods(mods);
129 } 134 }
130 else { 135 else {
131 debug("MODS_TAP: Oneshot: del_mods\n"); 136 dprint("MODS_TAP: Oneshot: del_mods\n");
132 // cancel Mods 137 // cancel Mods
133 del_mods(mods); 138 del_mods(mods);
134 } 139 }
@@ -139,24 +144,24 @@ void process_action(keyrecord_t *record)
139 if (event.pressed) { 144 if (event.pressed) {
140 if (tap_count > 0) { 145 if (tap_count > 0) {
141 if (record->tap.interrupted) { 146 if (record->tap.interrupted) {
142 debug("MODS_TAP: Tap: Cancel: add_mods\n"); 147 dprint("MODS_TAP: Tap: Cancel: add_mods\n");
143 // ad hoc: set 0 to cancel tap 148 // ad hoc: set 0 to cancel tap
144 record->tap.count = 0; 149 record->tap.count = 0;
145 add_mods(mods); 150 add_mods(mods);
146 } else { 151 } else {
147 debug("MODS_TAP: Tap: register_code\n"); 152 dprint("MODS_TAP: Tap: register_code\n");
148 register_code(action.key.code); 153 register_code(action.key.code);
149 } 154 }
150 } else { 155 } else {
151 debug("MODS_TAP: No tap: add_mods\n"); 156 dprint("MODS_TAP: No tap: add_mods\n");
152 add_mods(mods); 157 add_mods(mods);
153 } 158 }
154 } else { 159 } else {
155 if (tap_count > 0) { 160 if (tap_count > 0) {
156 debug("MODS_TAP: Tap: unregister_code\n"); 161 dprint("MODS_TAP: Tap: unregister_code\n");
157 unregister_code(action.key.code); 162 unregister_code(action.key.code);
158 } else { 163 } else {
159 debug("MODS_TAP: No tap: add_mods\n"); 164 dprint("MODS_TAP: No tap: add_mods\n");
160 del_mods(mods); 165 del_mods(mods);
161 } 166 }
162 } 167 }
@@ -261,18 +266,18 @@ void process_action(keyrecord_t *record)
261 /* tap key */ 266 /* tap key */
262 if (event.pressed) { 267 if (event.pressed) {
263 if (tap_count > 0) { 268 if (tap_count > 0) {
264 debug("KEYMAP_TAP_KEY: Tap: register_code\n"); 269 dprint("KEYMAP_TAP_KEY: Tap: register_code\n");
265 register_code(action.layer_tap.code); 270 register_code(action.layer_tap.code);
266 } else { 271 } else {
267 debug("KEYMAP_TAP_KEY: No tap: On on press\n"); 272 dprint("KEYMAP_TAP_KEY: No tap: On on press\n");
268 layer_on(action.layer_tap.val); 273 layer_on(action.layer_tap.val);
269 } 274 }
270 } else { 275 } else {
271 if (tap_count > 0) { 276 if (tap_count > 0) {
272 debug("KEYMAP_TAP_KEY: Tap: unregister_code\n"); 277 dprint("KEYMAP_TAP_KEY: Tap: unregister_code\n");
273 unregister_code(action.layer_tap.code); 278 unregister_code(action.layer_tap.code);
274 } else { 279 } else {
275 debug("KEYMAP_TAP_KEY: No tap: Off on release\n"); 280 dprint("KEYMAP_TAP_KEY: No tap: Off on release\n");
276 layer_off(action.layer_tap.val); 281 layer_off(action.layer_tap.val);
277 } 282 }
278 } 283 }
@@ -448,40 +453,33 @@ bool is_tap_key(key_t key)
448 */ 453 */
449void debug_event(keyevent_t event) 454void debug_event(keyevent_t event)
450{ 455{
451 debug_hex16((event.key.row<<8) | event.key.col); 456 dprintf("%04X%c(%u)", (event.key.row<<8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time);
452 if (event.pressed) debug("d("); else debug("u(");
453 debug_dec(event.time); debug(")");
454} 457}
455 458
456void debug_record(keyrecord_t record) 459void debug_record(keyrecord_t record)
457{ 460{
458 debug_event(record.event); 461 debug_event(record.event);
459#ifndef NO_ACTION_TAPPING 462#ifndef NO_ACTION_TAPPING
460 debug(":"); debug_dec(record.tap.count); 463 dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' '));
461 if (record.tap.interrupted) debug("-");
462#endif 464#endif
463} 465}
464 466
465void debug_action(action_t action) 467void debug_action(action_t action)
466{ 468{
467 switch (action.kind.id) { 469 switch (action.kind.id) {
468 case ACT_LMODS: debug("ACT_LMODS"); break; 470 case ACT_LMODS: dprint("ACT_LMODS"); break;
469 case ACT_RMODS: debug("ACT_RMODS"); break; 471 case ACT_RMODS: dprint("ACT_RMODS"); break;
470 case ACT_LMODS_TAP: debug("ACT_LMODS_TAP"); break; 472 case ACT_LMODS_TAP: dprint("ACT_LMODS_TAP"); break;
471 case ACT_RMODS_TAP: debug("ACT_RMODS_TAP"); break; 473 case ACT_RMODS_TAP: dprint("ACT_RMODS_TAP"); break;
472 case ACT_USAGE: debug("ACT_USAGE"); break; 474 case ACT_USAGE: dprint("ACT_USAGE"); break;
473 case ACT_MOUSEKEY: debug("ACT_MOUSEKEY"); break; 475 case ACT_MOUSEKEY: dprint("ACT_MOUSEKEY"); break;
474 case ACT_LAYER: debug("ACT_LAYER"); break; 476 case ACT_LAYER: dprint("ACT_LAYER"); break;
475 case ACT_LAYER_TAP: debug("ACT_LAYER_TAP"); break; 477 case ACT_LAYER_TAP: dprint("ACT_LAYER_TAP"); break;
476 case ACT_LAYER_TAP1: debug("ACT_LAYER_TAP1"); break; 478 case ACT_LAYER_TAP1: dprint("ACT_LAYER_TAP1"); break;
477 case ACT_MACRO: debug("ACT_MACRO"); break; 479 case ACT_MACRO: dprint("ACT_MACRO"); break;
478 case ACT_COMMAND: debug("ACT_COMMAND"); break; 480 case ACT_COMMAND: dprint("ACT_COMMAND"); break;
479 case ACT_FUNCTION: debug("ACT_FUNCTION"); break; 481 case ACT_FUNCTION: dprint("ACT_FUNCTION"); break;
480 default: debug("UNKNOWN"); break; 482 default: dprint("UNKNOWN"); break;
481 } 483 }
482 debug("["); 484 dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff);
483 debug_hex4(action.kind.param>>8);
484 debug(":");
485 debug_hex8(action.kind.param & 0xff);
486 debug("]");
487} 485}