Interrupt-driven keypad interface library. Compatible with RTOS. Able to handle various keypad size below 4x4.

Dependencies:   keypad mbed

Revision:
1:1ae4a77af85b
Parent:
0:8209bcf62e0a
--- a/main.cpp	Mon Jan 30 09:40:01 2012 +0000
+++ b/main.cpp	Wed Jan 01 17:47:52 2014 +0000
@@ -1,53 +1,40 @@
 #include "mbed.h"
-#include "keypad.h"
 
-#define       KEYLEN    4
-#define       ENDKEY   15
-char          Buffer[KEYLEN];
-int           Index = 0;
+#include "Keypad.h"
+
+Serial        PC(USBTX, USBRX);
 
 // Define your own keypad values
-char Keytable[] = { '1', '2', '3', 'A',
-                    '4', '5', '6', 'B',
-                    '7', '8', '9', 'C',
-                    '*', '0', '#', 'D'
+char Keytable[] = { '1', '2', '3',   // r0
+                    '4', '5', '6',   // r1
+                    '7', '8', '9',   // r2
+                  // c0   c1   c2
                   };
 
-uint32_t cbAfterInput(uint32_t key) {
-    bool      finish = false;
-    
-    printf("Index:%d => Key:%c\n", Index, Keytable[key]);
+int32_t       Index = -1;
+int           State;
 
-    if (Index < KEYLEN - 1)
-    {
-        if (key != ENDKEY)  // Terminating key
-            Buffer[Index] = Keytable[key];
-        else // Terminating key is entered
-            finish = true;
-        Index++;
-    }
-
-    if (finish || (Index == KEYLEN - 1)) {
-        printf("Complete string = %s\n", Buffer);
-        memset(&Buffer, 0, KEYLEN);
-        Index = 0;
-    }
-
+uint32_t cbAfterInput(uint32_t index)
+{
+    Index = index;
     return 0;
 }
 
-void Sleep(void) {
-    __WFI();
-}
+int main()
+{
+    PC.printf("I am Demo Keypad\r\n");
+    
+    //             r0   r1   r2   r3   c0   c1   c2   c3
+    Keypad keypad(p21, p22,  NC,  NC, p23, p24,  NC,  NC);
+    keypad.attach(&cbAfterInput);
+    keypad.start();  // energize the columns c0-c3 of the keypad
 
-int main() {
-    memset(&Buffer, 0, KEYLEN);
-    Index = 0;
-    Keypad keypad(p25, p26, p27, p28, p21, p22, p23, p24);
-    keypad.CallAfterInput(&cbAfterInput);
-
-    keypad.Start();
     while (1) {
-        Sleep();
+        __wfi();
+        if (Index > -1) {
+            PC.printf("Interrupted");
+            PC.printf("Index:%d => Key:%c\r\n", Index, Keytable[Index]);
+            Index = -1;
+        }
     }
-}
\ No newline at end of file
+}