From 81bb9d772d9efb87f63f2c617211deb4423ff844 Mon Sep 17 00:00:00 2001 From: Jacob Alexander Date: Mon, 21 Mar 2011 16:06:01 -0700 Subject: [PATCH] Working keypad switch code detection. --- main.c | 57 +++++++++++++++++++++++---------------------------------- 1 file changed, 23 insertions(+), 34 deletions(-) diff --git a/main.c b/main.c index 1777988..28b372b 100644 --- a/main.c +++ b/main.c @@ -209,9 +209,9 @@ // Keypad detection -// Each switch has it's own detection line +// Each switch has it's own detection line, inverse logic #define KEYPAD_DETECT(test,switch_code) \ - if ( test ) { \ + if ( !(test) ) { \ keypadDetectArray[switch_code]++; \ } \ @@ -336,18 +336,14 @@ inline void pinSetup(void) void keyPressDetection( uint8_t *keys, uint8_t *validKeys) { for ( uint8_t key = 0; key < KEYBOARD_SIZE + 1; key++ ) { - //phex(keyDetectArray[key]); - //print ("|"); - if ( keyDetectArray[key] & (1 << 7) ) { - //print("0x"); - //phex( key ); + if ( keys[key] & (1 << 7) ) { pint8( key ); print(" "); // Too many keys - if ( validKeys == 6 ) + if ( *validKeys == 6 ) break; - keyboard_keys[validKeys++] = defaultMap[key]; + keyboard_keys[*validKeys++] = defaultMap[key]; } } } @@ -399,22 +395,22 @@ int main( void ) continue; // Check Keypad keys - KEYPAD_DETECT(PINA & (1 << 0,1)) - KEYPAD_DETECT(PINA & (1 << 1,1)) - KEYPAD_DETECT(PINA & (1 << 2,1)) - KEYPAD_DETECT(PINA & (1 << 3,1)) - KEYPAD_DETECT(PINA & (1 << 4,1)) - KEYPAD_DETECT(PINA & (1 << 5,1)) - KEYPAD_DETECT(PINA & (1 << 6,1)) - KEYPAD_DETECT(PINA & (1 << 7,1)) - KEYPAD_DETECT(PINF & (1 << 0,1)) - KEYPAD_DETECT(PINF & (1 << 1,1)) - KEYPAD_DETECT(PINF & (1 << 2,1)) - KEYPAD_DETECT(PINF & (1 << 3,1)) - KEYPAD_DETECT(PINF & (1 << 4,1)) - KEYPAD_DETECT(PINF & (1 << 5,1)) - KEYPAD_DETECT(PINF & (1 << 6,1)) - KEYPAD_DETECT(PINF & (1 << 7,1)) + KEYPAD_DETECT(PINA & (1 << 0),11) + KEYPAD_DETECT(PINA & (1 << 1),3) + KEYPAD_DETECT(PINA & (1 << 2),7) + KEYPAD_DETECT(PINA & (1 << 3),4) + KEYPAD_DETECT(PINA & (1 << 4),15) + KEYPAD_DETECT(PINA & (1 << 5),6) + KEYPAD_DETECT(PINA & (1 << 6),2) + KEYPAD_DETECT(PINA & (1 << 7),10) + KEYPAD_DETECT(PINF & (1 << 0),8) + KEYPAD_DETECT(PINF & (1 << 1),12) + KEYPAD_DETECT(PINF & (1 << 2),16) + KEYPAD_DETECT(PINF & (1 << 3),13) + KEYPAD_DETECT(PINF & (1 << 4),1) + KEYPAD_DETECT(PINF & (1 << 5),5) + KEYPAD_DETECT(PINF & (1 << 6),9) + KEYPAD_DETECT(PINF & (1 << 7),14) // Check count to see if the sample threshold may have been reached, otherwise collect more data count++; @@ -435,8 +431,8 @@ int main( void ) // Detect Valid Keypresses - TODO uint8_t validKeys = 0; - keyPressDetection( &keyDetectArray, &validKeys ); - //keyPressDetection( &keypadDetectArray, &validKeys ); + keyPressDetection( keyDetectArray, &validKeys ); + keyPressDetection( keypadDetectArray, &validKeys ); print(":\n"); // TODO undo potentially old keys @@ -444,13 +440,6 @@ int main( void ) keyboard_keys[c] = 0; - // Debugging Output - //phex(PINA); - //phex(PINF); - //print("\n"); - - - // Print out the current keys pressed /* if ( keyDetectCount > 0 ) {