From 3b2ea5dbc8876a51eb7a061fb7acbe0bc43918a2 Mon Sep 17 00:00:00 2001 From: knolax <1339802534.kk@gmail.com> Date: Fri, 29 Dec 2017 18:49:54 -0500 Subject: added DEBUGMODE macro to enable/disable debug prints` --- skey.c | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/skey.c b/skey.c index 86ac5ae..1b2257b 100644 --- a/skey.c +++ b/skey.c @@ -13,6 +13,10 @@ */ #define USE_GPIO 1 /* + * toggles debug mode, + */ +#define DEBUGMODE 1 +/* * On the prototype model, the diodes were soldered backwards, so that the * negative ends were facing the cpins. * as outputs they seem to opendrain(transistor to high, resistor to low) @@ -170,13 +174,13 @@ int processkey(int row, int column, int state) { break; } if ((KEYSTATE_PHYS & keystate[row][column])) { - printk(KERN_DEBUG "skey: previous KEYSTATE_PHYS for r:%d,c:%d was %d\n", row, column, (KEYSTATE_PHYS & keystate[row][column])); + if(DEBUGMODE){printk(KERN_DEBUG "skey: previous KEYSTATE_PHYS for r:%d,c:%d was %d\n", row, column, (KEYSTATE_PHYS & keystate[row][column]));} } //falling edge if ((KEYSTATE_PHYS & keystate[row][column]) && !state) { - printk(KERN_DEBUG "skey: falling edge detected for r:%d,c:%d\n", row, column); + if(DEBUGMODE){printk(KERN_DEBUG "skey: falling edge detected for r:%d,c:%d\n", row, column);} if (!stickymode) { - printk(KERN_DEBUG "skey: stickymode off with falling edge, reporting key up with keycode %d\n", skey_keymap[current_keymap][row][column]); + if(DEBUGMODE){printk(KERN_DEBUG "skey: stickymode off with falling edge, reporting key up with keycode %d\n", skey_keymap[current_keymap][row][column]);} //reports key up input_report_key(skey_dev, skey_keymap[current_keymap][row][column], 0); input_sync(skey_dev); @@ -184,38 +188,38 @@ int processkey(int row, int column, int state) { } //rising edge }else if (!(KEYSTATE_PHYS & keystate[row][column]) && state) { - printk(KERN_DEBUG "skey: rising edge detected for r:%d,c:%d\n", row, column); + if(DEBUGMODE){printk(KERN_DEBUG "skey: rising edge detected for r:%d,c:%d\n", row, column);} /* *handles keys that have special behavior, and to which stickykey do not apply * if sticky keys don't apply then only the falling edge applies */ switch (skey_keymap[current_keymap][row][column]) { case KEY_ALPHAMAP: - printk(KERN_DEBUG "skey: changing to keymap ALPHA\n"); + if(DEBUGMODE){printk(KERN_DEBUG "skey: changing to keymap ALPHA\n");} current_keymap = 0; return 0; break; case KEY_NUMBERMAP: - printk(KERN_DEBUG "skey: changing to keymap NUM\n"); + if(DEBUGMODE){printk(KERN_DEBUG "skey: changing to keymap NUM\n");} current_keymap = 1; return 0; break; case KEY_SPECIALMAP: - printk(KERN_DEBUG "skey: changing to keymap SPECIAL\n"); + if(DEBUGMODE){printk(KERN_DEBUG "skey: changing to keymap SPECIAL\n");} current_keymap = 2; return 0; break; case KEY_STICKYMAP: - printk(KERN_DEBUG "skey: toggling stickymode\n"); + if(DEBUGMODE){printk(KERN_DEBUG "skey: toggling stickymode\n");} stickymode = !stickymode; if (!stickymode) { clearkeystate(); - printk(KERN_DEBUG "skey: cleaned stickmode states\n"); + if(DEBUGMODE){printk(KERN_DEBUG "skey: cleaned stickmode states\n");} } return 0; break; case KEY_MS_2ND: - printk(KERN_DEBUG "skey: toggling MS_2ND\n"); + if(DEBUGMODE){printk(KERN_DEBUG "skey: toggling MS_2ND\n");} if (current_keymap == 2) { current_keymap = 3; } else if (current_keymap == 3) { @@ -256,17 +260,17 @@ int processkey(int row, int column, int state) { } //if it's stickymode, toggle the state stored and send corresponding vent if (stickymode) { - printk(KERN_DEBUG "skey: stickymoe on with rising edge\n"); + if(DEBUGMODE){printk(KERN_DEBUG "skey: stickymoe on with rising edge\n");} //it was high before, so now it's being toggled off if (keystate[row][column] & keystate_bitmask) { - printk(KERN_DEBUG "skey: stickymode sending key up with code %d\n", skey_keymap[current_keymap][row][column]); + if(DEBUGMODE){printk(KERN_DEBUG "skey: stickymode sending key up with code %d\n", skey_keymap[current_keymap][row][column]);} input_report_key(skey_dev, skey_keymap[current_keymap][row][column], 0); input_sync(skey_dev); keystate[row][column] = (~keystate_bitmask) & keystate[row][column]; //it was low before, so now it's being toggled on } else { - printk(KERN_DEBUG "skey: stickymode sending key down with code %d\n", skey_keymap[current_keymap][row][column]); + if(DEBUGMODE){printk(KERN_DEBUG "skey: stickymode sending key down with code %d\n", skey_keymap[current_keymap][row][column]);} input_report_key(skey_dev, skey_keymap[current_keymap][row][column], 1); input_sync(skey_dev); keystate[row][column] = keystate_bitmask | keystate[row][column]; @@ -274,7 +278,7 @@ int processkey(int row, int column, int state) { } //otherwise just send a key down event } else { - printk(KERN_DEBUG "skey:skey rising edge w/o stickymode, sending key down with keycode %d\n", skey_keymap[current_keymap][row][column]); + if(DEBUGMODE){printk(KERN_DEBUG "skey:skey rising edge w/o stickymode, sending key down with keycode %d\n", skey_keymap[current_keymap][row][column]);} input_report_key(skey_dev, skey_keymap[current_keymap][row][column], 1); input_sync(skey_dev); } @@ -318,7 +322,7 @@ int skey_update_thread (void *data) { while (column_index < 10) { if (gpio_get_value_cansleep(column_pins[column_index])) { processkey(row_index, column_index, 1); - printk(KERN_DEBUG "skey:button pressed at r:%d,c:%d\n", row_index, column_index); + if(DEBUGMODE){printk(KERN_DEBUG "skey:button pressed at r:%d,c:%d\n", row_index, column_index);} } else { processkey(row_index, column_index, 0); } -- cgit v1.1