Demo of the RA8875 Keypad to enter a username and password.
Dependencies: mbed RA8875 Keypad
Revision 2:117fb9168afc, committed 2016-03-05
- Comitter:
- WiredHome
- Date:
- Sat Mar 05 16:23:10 2016 +0000
- Parent:
- 1:0fea662d1826
- Child:
- 3:954431ea9b0d
- Commit message:
- Keypad Demo shows QWERTY, password entry, user defined numeric style, floating (to your choice of location on the screen) and compressed, where it sizes the keys based on your settings.
Changed in this revision
--- a/Keypad.lib Fri Mar 04 12:24:32 2016 +0000 +++ b/Keypad.lib Sat Mar 05 16:23:10 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/WiredHome/code/Keypad/#7feeebbd8367 +https://developer.mbed.org/users/WiredHome/code/Keypad/#6d05764dfde7
--- a/RA8875.lib Fri Mar 04 12:24:32 2016 +0000 +++ b/RA8875.lib Sat Mar 05 16:23:10 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/WiredHome/code/RA8875/#c80828f5dea4 +http://mbed.org/users/WiredHome/code/RA8875/#f9ccffcb84f1
--- a/main.cpp Fri Mar 04 12:24:32 2016 +0000 +++ b/main.cpp Sat Mar 05 16:23:10 2016 +0000 @@ -32,6 +32,7 @@ }; + void CalibrateTS(void) { FILE * fh; @@ -67,54 +68,101 @@ } } + +void UsernameAndPasswordTest(void) { + char name1[20]; + char name2[20]; + + kp.SetKeyboard(); + lcd.puts(0,20, "Enter username and password\r\n"); + if (kp.GetString(name1, sizeof(name1), "Username:")) { + //lcd.printf("username: %s\r\n", name1); + if (kp.GetString(name2, sizeof(name2), "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"); + } +} + + +void CalculatorKeypadTest(void) { + char name1[20]; + + kp.SetKeyboard(&altkeyboard, '='); + if (kp.GetString(name1, sizeof(name1), "Calc:")) { + lcd.foreground(BrightRed); + lcd.background(Black); + lcd.cls(); + lcd.SetTextCursor(0,40); + lcd.printf("Calculator: %s\r\n", name1); + } +} + +void FloatingSmallQWERTYTest(loc_t x, loc_t y, dim_t w, dim_t h) { + Keypad::keyboard_t tiny; + char name1[10]; + + // copy definition and then resize it + memcpy(&tiny, kp.GetInternalKeypad(), sizeof(Keypad::keyboard_t)); + tiny.x = x; tiny.y = y; + tiny.width = w; tiny.height=h; + + // now select this tiny keyboard + kp.SetKeyboard(&tiny); + if (kp.GetString(name1, sizeof(name1), "Cprs:")) { + lcd.foreground(BrightRed); + lcd.background(Black); + lcd.cls(); + lcd.SetTextCursor(0,40); + lcd.printf("Compressed: %s\r\n", name1); + } +} + + + + int main() { - char name1[20], name2[20]; - bool toggle = false; + int testNum = 2; // starting test pc.baud(460800); // I like a snappy terminal, so crank it up! pc.printf("\r\nDev Keypad - Build " __DATE__ " " __TIME__ "\r\n"); lcd.init(); - lcd.foreground(Yellow); - lcd.background(Black); - lcd.puts(0,0, "RA8875 Soft Fonts - Build " __DATE__ " " __TIME__ "\r\n"); InitTS(); while(1) { lcd.foreground(Yellow); lcd.background(Black); lcd.cls(); - 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.SetTextCursor(0,40); - lcd.printf("Calculator: %s\r\n", name1); - } + lcd.puts(0,0, "Dev Keypad - Build " __DATE__ " " __TIME__ "\r\n"); + switch (testNum) { + default: + case 0: + testNum = 0; // capture the overflow and start over... + UsernameAndPasswordTest(); + break; + case 1: + CalculatorKeypadTest(); + break; + case 2: + FloatingSmallQWERTYTest(50,0, 200,0); // horizontally in by 50, width 200, extend to bottom of screen + break; + case 3: + FloatingSmallQWERTYTest(75, 100, 220, 6 * (lcd.fontheight()+4)); // floating with the top at x=75, y=100 + break; } - toggle = !toggle; + testNum++; wait(5); } } +