Demo of the RA8875 Keypad to enter a username and password.

Dependencies:   mbed RA8875 Keypad

Files at this revision

API Documentation at this revision

Comitter:
WiredHome
Date:
Fri Mar 04 12:24:32 2016 +0000
Parent:
0:5cf0d5f4ab84
Child:
2:117fb9168afc
Commit message:
Added a demo of a numeric keypad. It only returns the string entered, but the demo keypad is calculator-like.

Changed in this revision

Keypad.lib Show annotated file Show diff for this revision Revisions of this file
RA8875.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/Keypad.lib	Mon Feb 08 02:47:49 2016 +0000
+++ b/Keypad.lib	Fri Mar 04 12:24:32 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/users/WiredHome/code/Keypad/#9b0b4ae5b47a
+https://developer.mbed.org/users/WiredHome/code/Keypad/#7feeebbd8367
--- a/RA8875.lib	Mon Feb 08 02:47:49 2016 +0000
+++ b/RA8875.lib	Fri Mar 04 12:24:32 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/WiredHome/code/RA8875/#8d1d3832a215
+http://mbed.org/users/WiredHome/code/RA8875/#c80828f5dea4
--- a/main.cpp	Mon Feb 08 02:47:49 2016 +0000
+++ b/main.cpp	Fri Mar 04 12:24:32 2016 +0000
@@ -8,6 +8,29 @@
 RA8875 lcd(p5, p6, p7, p12, NC, "tft");    // MOSI, MISO, SCK, /ChipSelect, /reset, name
 Keypad kp(lcd);
 
+// 789 /(
+// 456 *)
+// 123 -
+// 00. +=
+const char numberkeys[] = {
+    5,'\x01', 10,'7',10,'8',10,'9', 5,'\x01', 10,'/',10,'(', 0,0,
+    5,'\x01', 10,'4',10,'5',10,'6', 5,'\x01', 10,'*',10,')', 0,0,
+    5,'\x01', 10,'1',10,'2',10,'3', 5,'\x01', 10,'-',10,KYBD_SYM_BS, 0,0,
+    5,'\x01', 20,'0',       10,'.', 5,'\x01', 10,'+',10,'=', 0,0,
+    0,0
+};
+
+const Keypad::keyboard_t altkeyboard = {
+    100,        // x=100; left edge
+    0,          // y=0; computed from bottom up
+    240,        // width=240
+    0,          // height=0; bottom of screen justified
+    4,          // rows
+    6,          // columns
+    numberkeys, // pointer to the keypad
+    numberkeys
+};
+
 
 void CalibrateTS(void)
 {
@@ -47,6 +70,7 @@
 int main()
 {
     char name1[20], name2[20];
+    bool toggle = false;
 
     pc.baud(460800);                            // I like a snappy terminal, so crank it up!
     pc.printf("\r\nDev Keypad - Build " __DATE__ " " __TIME__ "\r\n");
@@ -60,24 +84,37 @@
         lcd.foreground(Yellow);
         lcd.background(Black);
         lcd.cls();
-        lcd.puts(0,20, "Enter username and password\r\n");
-        if (kp.GetString(name1, 20, "Username:")) {
-            lcd.printf("username: %s\r\n", name1);
-            if (kp.GetString(name2, 20, "Password:", '*')) {
-                lcd.printf("password: %s\r\n", name2);
+        if (!toggle) {
+            kp.SetKeyboard();
+            lcd.puts(0,20, "Enter username and password\r\n");
+            if (kp.GetString(name1, 20, "Username:")) {
+                //lcd.printf("username: %s\r\n", name1);
+                if (kp.GetString(name2, 20, "Password:", '*')) {
+                    //lcd.printf("password: %s\r\n", name2);
+                    kp.Erase();
+                    lcd.foreground(BrightRed);
+                    lcd.background(Black);
+                    lcd.cls();
+                    lcd.SetTextFontSize(2);
+                    lcd.SetTextCursor(0,30);
+                    lcd.printf("username: %s\r\npassword: %s\r\n", name1, name2);
+                    lcd.SetTextFontSize();
+                }
+            } else {
                 kp.Erase();
+                pc.printf("<esc>\r\n");
+            }
+        } else {
+            kp.SetKeyboard(&altkeyboard, '=');
+            if (kp.GetString(name1, 20, "Calc:")) {
                 lcd.foreground(BrightRed);
                 lcd.background(Black);
                 lcd.cls();
-                lcd.SetTextFontSize(2);
-                lcd.SetTextCursor(0,30);
-                lcd.printf("username: %s\r\npassword: %s\r\n", name1, name2);
-                lcd.SetTextFontSize();
+                lcd.SetTextCursor(0,40);
+                lcd.printf("Calculator: %s\r\n", name1);
             }
-        } else {
-            kp.Erase();
-            pc.printf("<esc>\r\n");
         }
+        toggle = !toggle;
         wait(5);
     }
 }
--- a/mbed.bld	Mon Feb 08 02:47:49 2016 +0000
+++ b/mbed.bld	Fri Mar 04 12:24:32 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/f141b2784e32
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/87f2f5183dfb
\ No newline at end of file