Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI
SecurityUnlockDemo-Keypad.cpp@5:5c507689ae66, 2019-06-05 (annotated)
- Committer:
- Damotclese
- Date:
- Wed Jun 05 02:27:51 2019 +0000
- Revision:
- 5:5c507689ae66
- Parent:
- 3:0e554d8d5a19
I put a pizza BMP on the screen;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Damotclese | 1:316582aec4fb | 1 | |
| Damotclese | 1:316582aec4fb | 2 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 3 | // SecurityUnlockDemo-Keypad.cpp |
| Damotclese | 1:316582aec4fb | 4 | // |
| Damotclese | 1:316582aec4fb | 5 | // Fredric L. Rice, June 2019 |
| Damotclese | 1:316582aec4fb | 6 | // |
| Damotclese | 1:316582aec4fb | 7 | // This module maintains the code which performs the keypad functionality |
| Damotclese | 1:316582aec4fb | 8 | // |
| Damotclese | 1:316582aec4fb | 9 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 10 | |
| Damotclese | 1:316582aec4fb | 11 | #include "mbed.h" // The mbed operating system |
| Damotclese | 1:316582aec4fb | 12 | #include "LCD_DISCO_F429ZI.h" // For controlling the LCD |
| Damotclese | 1:316582aec4fb | 13 | #include "TS_DISCO_F429ZI.h" // For controlling the touch screen |
| Damotclese | 1:316582aec4fb | 14 | #include "SecurityUnlockDemo-Main.h" // Bring in the main module |
| Damotclese | 1:316582aec4fb | 15 | #include "SecurityUnlockDemo-Keypad.h" // Always include our own header |
| Damotclese | 5:5c507689ae66 | 16 | #include "PizzaBMPHeader.h" // For the Pizza BMP file |
| Damotclese | 1:316582aec4fb | 17 | |
| Damotclese | 1:316582aec4fb | 18 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 19 | // Describe data which is defined externally that we may access |
| Damotclese | 1:316582aec4fb | 20 | // |
| Damotclese | 1:316582aec4fb | 21 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 22 | |
| Damotclese | 1:316582aec4fb | 23 | // We may be accessing the LCD |
| Damotclese | 1:316582aec4fb | 24 | extern LCD_DISCO_F429ZI st_lcd; |
| Damotclese | 1:316582aec4fb | 25 | |
| Damotclese | 1:316582aec4fb | 26 | // We may be accessing the touch screen |
| Damotclese | 1:316582aec4fb | 27 | extern TS_DISCO_F429ZI st_touchScreen; |
| Damotclese | 1:316582aec4fb | 28 | |
| Damotclese | 1:316582aec4fb | 29 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 30 | // Define local data storage |
| Damotclese | 1:316582aec4fb | 31 | // |
| Damotclese | 1:316582aec4fb | 32 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 33 | |
| Damotclese | 1:316582aec4fb | 34 | // In this demonstration we define two access levels, access level 1 |
| Damotclese | 1:316582aec4fb | 35 | // grants full access to all functionality whereas access level 2 is |
| Damotclese | 1:316582aec4fb | 36 | // for accessing less functionality |
| Damotclese | 5:5c507689ae66 | 37 | static const uint8_t * ACCESS_LEVEL_1 = "3141"; |
| Damotclese | 1:316582aec4fb | 38 | static const uint8_t * ACCESS_LEVEL_2 = "2040"; |
| Damotclese | 1:316582aec4fb | 39 | |
| Damotclese | 1:316582aec4fb | 40 | // When we build the keypad screen, we use the data in this table |
| Damotclese | 1:316582aec4fb | 41 | // to position the touch keys rather than use math to determine |
| Damotclese | 1:316582aec4fb | 42 | // their locations. The reason why we do this is so that we can |
| Damotclese | 1:316582aec4fb | 43 | // use this table to determine which key was pressed on the touch |
| Damotclese | 1:316582aec4fb | 44 | // screen, but also we may want to place some keys offset from |
| Damotclese | 1:316582aec4fb | 45 | // others. A table gives us greater control over key location. |
| Damotclese | 1:316582aec4fb | 46 | // We place 10 pixels between each keypad. |
| Damotclese | 1:316582aec4fb | 47 | static KeypadLocation_t st_KeypadInformation[] = |
| Damotclese | 1:316582aec4fb | 48 | { |
| Damotclese | 1:316582aec4fb | 49 | // X, Y, H, W, Character |
| Damotclese | 1:316582aec4fb | 50 | { KEYPAD_LEFT_MARGIN + 0, KEYPAD_TOP_MARGIN + 0, 40, 40, '1' }, |
| Damotclese | 1:316582aec4fb | 51 | { KEYPAD_LEFT_MARGIN + 60, KEYPAD_TOP_MARGIN + 0, 40, 40, '2' }, |
| Damotclese | 1:316582aec4fb | 52 | { KEYPAD_LEFT_MARGIN + 120, KEYPAD_TOP_MARGIN + 0, 40, 40, '3' }, |
| Damotclese | 1:316582aec4fb | 53 | { KEYPAD_LEFT_MARGIN + 0, KEYPAD_TOP_MARGIN + 60, 40, 40, '4' }, |
| Damotclese | 1:316582aec4fb | 54 | { KEYPAD_LEFT_MARGIN + 60, KEYPAD_TOP_MARGIN + 60, 40, 40, '5' }, |
| Damotclese | 1:316582aec4fb | 55 | { KEYPAD_LEFT_MARGIN + 120, KEYPAD_TOP_MARGIN + 60, 40, 40, '6' }, |
| Damotclese | 1:316582aec4fb | 56 | { KEYPAD_LEFT_MARGIN + 0, KEYPAD_TOP_MARGIN + 120, 40, 40, '7' }, |
| Damotclese | 1:316582aec4fb | 57 | { KEYPAD_LEFT_MARGIN + 60, KEYPAD_TOP_MARGIN + 120, 40, 40, '8' }, |
| Damotclese | 1:316582aec4fb | 58 | { KEYPAD_LEFT_MARGIN + 120, KEYPAD_TOP_MARGIN + 120, 40, 40, '9' }, |
| Damotclese | 1:316582aec4fb | 59 | { KEYPAD_LEFT_MARGIN + 0, KEYPAD_TOP_MARGIN + 180, 40, 40, 'C' }, |
| Damotclese | 1:316582aec4fb | 60 | { KEYPAD_LEFT_MARGIN + 60, KEYPAD_TOP_MARGIN + 180, 40, 40, '0' }, |
| Damotclese | 1:316582aec4fb | 61 | { KEYPAD_LEFT_MARGIN + 120, KEYPAD_TOP_MARGIN + 180, 40, 40, 'E' }, |
| Damotclese | 1:316582aec4fb | 62 | { 0, 0, 0, 0, '+' } // End of table |
| Damotclese | 1:316582aec4fb | 63 | } ; |
| Damotclese | 1:316582aec4fb | 64 | |
| Damotclese | 1:316582aec4fb | 65 | // We allow a maximum number of keys to be entered for the access code |
| Damotclese | 1:316582aec4fb | 66 | static uint8_t au8_enteredKeys[MAX_SECURITY_DIGITS + 1]; |
| Damotclese | 1:316582aec4fb | 67 | |
| Damotclese | 1:316582aec4fb | 68 | // We keep track of the number of digits entered for the access code |
| Damotclese | 1:316582aec4fb | 69 | static uint8_t u8_enteredKeyCount; |
| Damotclese | 1:316582aec4fb | 70 | |
| Damotclese | 1:316582aec4fb | 71 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 72 | // KeypadInit() |
| Damotclese | 1:316582aec4fb | 73 | // |
| Damotclese | 1:316582aec4fb | 74 | // Initializes this module's locally-held data |
| Damotclese | 1:316582aec4fb | 75 | // |
| Damotclese | 1:316582aec4fb | 76 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 77 | void KeypadInit(void) |
| Damotclese | 1:316582aec4fb | 78 | { |
| Damotclese | 1:316582aec4fb | 79 | // Initialize locall-held data in this module |
| Damotclese | 1:316582aec4fb | 80 | u8_enteredKeyCount = 0; |
| Damotclese | 1:316582aec4fb | 81 | } |
| Damotclese | 1:316582aec4fb | 82 | |
| Damotclese | 1:316582aec4fb | 83 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 84 | // KeypadDisplayEnteredKeys() |
| Damotclese | 1:316582aec4fb | 85 | // |
| Damotclese | 1:316582aec4fb | 86 | // This function will display the entered keys, if any, on the display |
| Damotclese | 1:316582aec4fb | 87 | // on the line defined for the entered keys. It will center the |
| Damotclese | 1:316582aec4fb | 88 | // characters. |
| Damotclese | 1:316582aec4fb | 89 | // |
| Damotclese | 1:316582aec4fb | 90 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 91 | static void KeypadDisplayEnteredKeys(void) |
| Damotclese | 1:316582aec4fb | 92 | { |
| Damotclese | 1:316582aec4fb | 93 | // Display the accumulated security code digits |
| Damotclese | 1:316582aec4fb | 94 | st_lcd.DisplayStringAt(1, LINE(ENTERED_KEYS_LINE), au8_enteredKeys, CENTER_MODE); |
| Damotclese | 1:316582aec4fb | 95 | } |
| Damotclese | 1:316582aec4fb | 96 | |
| Damotclese | 1:316582aec4fb | 97 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 98 | // KeypadProcessEntryCode() |
| Damotclese | 1:316582aec4fb | 99 | // |
| Damotclese | 1:316582aec4fb | 100 | // This function will: |
| Damotclese | 1:316582aec4fb | 101 | // o Check the size of Level 1 access to see if it matches the |
| Damotclese | 1:316582aec4fb | 102 | // number of characters that were entered |
| Damotclese | 1:316582aec4fb | 103 | // o Check to see if the Level 1 access code matches the digits |
| Damotclese | 1:316582aec4fb | 104 | // entered |
| Damotclese | 1:316582aec4fb | 105 | // o Grant Access Level 1 if both the size and the digits match |
| Damotclese | 1:316582aec4fb | 106 | // |
| Damotclese | 1:316582aec4fb | 107 | // o Check the size of Level 2 access to see if it matches the |
| Damotclese | 1:316582aec4fb | 108 | // number of characters that were entered |
| Damotclese | 1:316582aec4fb | 109 | // o Check to see if the Level 2 access code matches the digits |
| Damotclese | 1:316582aec4fb | 110 | // entered |
| Damotclese | 1:316582aec4fb | 111 | // o Grant Access Level 2 if both the size and the digits match |
| Damotclese | 1:316582aec4fb | 112 | // |
| Damotclese | 1:316582aec4fb | 113 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 114 | static void KeypadProcessEntryCode(uint8_t u8_originalKeyCount) |
| Damotclese | 1:316582aec4fb | 115 | { |
| Damotclese | 1:316582aec4fb | 116 | // See if the access code that was entered is level 1 |
| Damotclese | 1:316582aec4fb | 117 | if (strlen((char *)ACCESS_LEVEL_1) == u8_originalKeyCount) |
| Damotclese | 1:316582aec4fb | 118 | { |
| Damotclese | 1:316582aec4fb | 119 | // Do the digits entered match the level 1 access code? |
| Damotclese | 1:316582aec4fb | 120 | if (! memcmp(ACCESS_LEVEL_1, au8_enteredKeys, u8_originalKeyCount)) |
| Damotclese | 1:316582aec4fb | 121 | { |
| Damotclese | 1:316582aec4fb | 122 | // It does so grant access level 1 |
| Damotclese | 1:316582aec4fb | 123 | MainGrantAccess(1); |
| Damotclese | 1:316582aec4fb | 124 | return; |
| Damotclese | 1:316582aec4fb | 125 | } |
| Damotclese | 1:316582aec4fb | 126 | } |
| Damotclese | 1:316582aec4fb | 127 | |
| Damotclese | 1:316582aec4fb | 128 | // That did not grant access, see if the entered value is level 2 |
| Damotclese | 1:316582aec4fb | 129 | if (strlen((char *)ACCESS_LEVEL_2) == u8_originalKeyCount) |
| Damotclese | 1:316582aec4fb | 130 | { |
| Damotclese | 1:316582aec4fb | 131 | // Do the digits entered match the level 2 access code? |
| Damotclese | 1:316582aec4fb | 132 | if (! memcmp(ACCESS_LEVEL_2, au8_enteredKeys, u8_originalKeyCount)) |
| Damotclese | 1:316582aec4fb | 133 | { |
| Damotclese | 1:316582aec4fb | 134 | // It does so grant access level 1 |
| Damotclese | 1:316582aec4fb | 135 | MainGrantAccess(2); |
| Damotclese | 1:316582aec4fb | 136 | return; |
| Damotclese | 1:316582aec4fb | 137 | } |
| Damotclese | 1:316582aec4fb | 138 | } |
| Damotclese | 1:316582aec4fb | 139 | } |
| Damotclese | 1:316582aec4fb | 140 | |
| Damotclese | 1:316582aec4fb | 141 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 142 | // KeypadProcessKeypadKey() |
| Damotclese | 1:316582aec4fb | 143 | // |
| Damotclese | 1:316582aec4fb | 144 | // This function will: |
| Damotclese | 1:316582aec4fb | 145 | // o Store the number of characters that have been entered, if any |
| Damotclese | 1:316582aec4fb | 146 | // |
| Damotclese | 1:316582aec4fb | 147 | // o Check to see if the character that is passed to the function |
| Damotclese | 1:316582aec4fb | 148 | // is a 'C' for Clear |
| Damotclese | 1:316582aec4fb | 149 | // o Clear the line of entered digits, if any |
| Damotclese | 1:316582aec4fb | 150 | // o Set the acquired character count to zero |
| Damotclese | 1:316582aec4fb | 151 | // |
| Damotclese | 1:316582aec4fb | 152 | // o Check ti see if the character entered is an 'E' for Enter |
| Damotclese | 1:316582aec4fb | 153 | // o Clear the line of any entered digits, if any |
| Damotclese | 1:316582aec4fb | 154 | // o Set the acquired character count to zero |
| Damotclese | 1:316582aec4fb | 155 | // o Call a function which evaluates the digits that have been |
| Damotclese | 1:316582aec4fb | 156 | // entered, if any |
| Damotclese | 1:316582aec4fb | 157 | // |
| Damotclese | 1:316582aec4fb | 158 | // o Checks ti see if there is room to store the newly-entered |
| Damotclese | 1:316582aec4fb | 159 | // digit in the accumulation buffer |
| Damotclese | 1:316582aec4fb | 160 | // o Stores the character in to the buffer andincrements the |
| Damotclese | 1:316582aec4fb | 161 | // entered digit counter |
| Damotclese | 1:316582aec4fb | 162 | // o Ensures that the string of entered digits is NULL terminated |
| Damotclese | 1:316582aec4fb | 163 | // o Calls a function which displays the entered digits |
| Damotclese | 1:316582aec4fb | 164 | // |
| Damotclese | 1:316582aec4fb | 165 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 166 | static void KeypadProcessKeypadKey(uint8_t u8_thisKeyASCIICharacter) |
| Damotclese | 1:316582aec4fb | 167 | { |
| Damotclese | 1:316582aec4fb | 168 | uint8_t u8_originalKeyCount = u8_enteredKeyCount; |
| Damotclese | 1:316582aec4fb | 169 | // Is the key a C for Clear? |
| Damotclese | 1:316582aec4fb | 170 | |
| Damotclese | 1:316582aec4fb | 171 | if ('C' == u8_thisKeyASCIICharacter) |
| Damotclese | 1:316582aec4fb | 172 | { |
| Damotclese | 1:316582aec4fb | 173 | // It is, so clear the display line of accumulated characters |
| Damotclese | 1:316582aec4fb | 174 | st_lcd.ClearStringLine(ENTERED_KEYS_LINE); |
| Damotclese | 1:316582aec4fb | 175 | |
| Damotclese | 1:316582aec4fb | 176 | // Discard our accumulated digit count |
| Damotclese | 1:316582aec4fb | 177 | u8_enteredKeyCount = 0; |
| Damotclese | 1:316582aec4fb | 178 | } |
| Damotclese | 1:316582aec4fb | 179 | |
| Damotclese | 1:316582aec4fb | 180 | // Is the character that was pressed en E for Enter? |
| Damotclese | 1:316582aec4fb | 181 | else if ('E' == u8_thisKeyASCIICharacter) |
| Damotclese | 1:316582aec4fb | 182 | { |
| Damotclese | 1:316582aec4fb | 183 | // It is, so before we process the code, clear the entered digits |
| Damotclese | 1:316582aec4fb | 184 | st_lcd.ClearStringLine(ENTERED_KEYS_LINE); |
| Damotclese | 1:316582aec4fb | 185 | |
| Damotclese | 1:316582aec4fb | 186 | // Discard our accumulated digit count |
| Damotclese | 1:316582aec4fb | 187 | u8_enteredKeyCount = 0; |
| Damotclese | 1:316582aec4fb | 188 | |
| Damotclese | 1:316582aec4fb | 189 | // Process the entry code |
| Damotclese | 1:316582aec4fb | 190 | KeypadProcessEntryCode(u8_originalKeyCount); |
| Damotclese | 1:316582aec4fb | 191 | } |
| Damotclese | 1:316582aec4fb | 192 | |
| Damotclese | 1:316582aec4fb | 193 | // Anything else we assume is a numertic digit |
| Damotclese | 1:316582aec4fb | 194 | else |
| Damotclese | 1:316582aec4fb | 195 | { |
| Damotclese | 1:316582aec4fb | 196 | // Do we have room for more digits? |
| Damotclese | 1:316582aec4fb | 197 | if (u8_enteredKeyCount < MAX_SECURITY_DIGITS) |
| Damotclese | 1:316582aec4fb | 198 | { |
| Damotclese | 1:316582aec4fb | 199 | // Store the entered digit in to the accumulated key buffer |
| Damotclese | 1:316582aec4fb | 200 | au8_enteredKeys[u8_enteredKeyCount++] = u8_thisKeyASCIICharacter; |
| Damotclese | 1:316582aec4fb | 201 | |
| Damotclese | 1:316582aec4fb | 202 | // Make sure that the character string is NULL terminated |
| Damotclese | 1:316582aec4fb | 203 | au8_enteredKeys[u8_enteredKeyCount] = 0x00; |
| Damotclese | 1:316582aec4fb | 204 | |
| Damotclese | 1:316582aec4fb | 205 | // Update the display with the new key value |
| Damotclese | 1:316582aec4fb | 206 | KeypadDisplayEnteredKeys(); |
| Damotclese | 1:316582aec4fb | 207 | } |
| Damotclese | 1:316582aec4fb | 208 | } |
| Damotclese | 1:316582aec4fb | 209 | } |
| Damotclese | 1:316582aec4fb | 210 | |
| Damotclese | 1:316582aec4fb | 211 | // ---------------------------------------------------------------------- |
| Damotclese | 3:0e554d8d5a19 | 212 | // KeypadFlashThisKey() |
| Damotclese | 3:0e554d8d5a19 | 213 | // |
| Damotclese | 3:0e554d8d5a19 | 214 | // The key that was touched and whose index got passed to this function |
| Damotclese | 3:0e554d8d5a19 | 215 | // is written in YELLOW and then restored to its original displayed |
| Damotclese | 3:0e554d8d5a19 | 216 | // graphic with one quarter of a second between. |
| Damotclese | 3:0e554d8d5a19 | 217 | // |
| Damotclese | 3:0e554d8d5a19 | 218 | // ---------------------------------------------------------------------- |
| Damotclese | 3:0e554d8d5a19 | 219 | static void KeypadFlashThisKey(uint8_t u8_thisKeyPadItem) |
| Damotclese | 3:0e554d8d5a19 | 220 | { |
| Damotclese | 3:0e554d8d5a19 | 221 | // Set everything to YELLOW |
| Damotclese | 3:0e554d8d5a19 | 222 | st_lcd.SetBackColor(LCD_COLOR_YELLOW); |
| Damotclese | 3:0e554d8d5a19 | 223 | st_lcd.SetTextColor(LCD_COLOR_YELLOW); |
| Damotclese | 3:0e554d8d5a19 | 224 | |
| Damotclese | 3:0e554d8d5a19 | 225 | // Draw the rectangle as all yellow |
| Damotclese | 3:0e554d8d5a19 | 226 | st_lcd.FillRect(st_KeypadInformation[u8_thisKeyPadItem].u16_screenXLocation, |
| Damotclese | 3:0e554d8d5a19 | 227 | st_KeypadInformation[u8_thisKeyPadItem].u16_screenYLocation, |
| Damotclese | 3:0e554d8d5a19 | 228 | st_KeypadInformation[u8_thisKeyPadItem].u16_keyHeight, |
| Damotclese | 3:0e554d8d5a19 | 229 | st_KeypadInformation[u8_thisKeyPadItem].u16_keyWidth); |
| Damotclese | 3:0e554d8d5a19 | 230 | |
| Damotclese | 3:0e554d8d5a19 | 231 | // Wait for one quarter of a second |
| Damotclese | 3:0e554d8d5a19 | 232 | wait(0.25); |
| Damotclese | 3:0e554d8d5a19 | 233 | |
| Damotclese | 3:0e554d8d5a19 | 234 | // Restore the normal colors |
| Damotclese | 3:0e554d8d5a19 | 235 | st_lcd.SetBackColor(LCD_COLOR_WHITE); |
| Damotclese | 3:0e554d8d5a19 | 236 | st_lcd.SetTextColor(LCD_COLOR_BLUE); |
| Damotclese | 3:0e554d8d5a19 | 237 | |
| Damotclese | 3:0e554d8d5a19 | 238 | // Draw the rectangle with its regular color and text |
| Damotclese | 3:0e554d8d5a19 | 239 | st_lcd.FillRect(st_KeypadInformation[u8_thisKeyPadItem].u16_screenXLocation, |
| Damotclese | 3:0e554d8d5a19 | 240 | st_KeypadInformation[u8_thisKeyPadItem].u16_screenYLocation, |
| Damotclese | 3:0e554d8d5a19 | 241 | st_KeypadInformation[u8_thisKeyPadItem].u16_keyHeight, |
| Damotclese | 3:0e554d8d5a19 | 242 | st_KeypadInformation[u8_thisKeyPadItem].u16_keyWidth); |
| Damotclese | 3:0e554d8d5a19 | 243 | |
| Damotclese | 3:0e554d8d5a19 | 244 | // Display the character near the lower right corner of the rectangle |
| Damotclese | 3:0e554d8d5a19 | 245 | st_lcd.DisplayChar( |
| Damotclese | 3:0e554d8d5a19 | 246 | st_KeypadInformation[u8_thisKeyPadItem].u16_screenXLocation + |
| Damotclese | 3:0e554d8d5a19 | 247 | (st_KeypadInformation[u8_thisKeyPadItem].u16_keyHeight / 2) + 6, |
| Damotclese | 3:0e554d8d5a19 | 248 | st_KeypadInformation[u8_thisKeyPadItem].u16_screenYLocation + |
| Damotclese | 3:0e554d8d5a19 | 249 | (st_KeypadInformation[u8_thisKeyPadItem].u16_keyWidth / 2) + 2, |
| Damotclese | 3:0e554d8d5a19 | 250 | st_KeypadInformation[u8_thisKeyPadItem].u8_keyASCIICharacter); |
| Damotclese | 3:0e554d8d5a19 | 251 | } |
| Damotclese | 3:0e554d8d5a19 | 252 | |
| Damotclese | 3:0e554d8d5a19 | 253 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 254 | // KeypadHandleKeyPress() |
| Damotclese | 1:316582aec4fb | 255 | // |
| Damotclese | 1:316582aec4fb | 256 | // When a key is pressed, the X and Y coordinates of the position where |
| Damotclese | 1:316582aec4fb | 257 | // the LCD was touched gets passed to this function. |
| Damotclese | 1:316582aec4fb | 258 | // |
| Damotclese | 1:316582aec4fb | 259 | // The function steps throug each of the keys defined in the keypad |
| Damotclese | 1:316582aec4fb | 260 | // map, checking an area bounded by the beginning X and Y coordinates |
| Damotclese | 1:316582aec4fb | 261 | // of the keys, and by that position plus the height and width of |
| Damotclese | 1:316582aec4fb | 262 | // trhe key. |
| Damotclese | 1:316582aec4fb | 263 | // |
| Damotclese | 1:316582aec4fb | 264 | // If the touch screen position that was touched matches the area of |
| Damotclese | 1:316582aec4fb | 265 | // a known key, a function is called to process the new key. |
| Damotclese | 1:316582aec4fb | 266 | // |
| Damotclese | 1:316582aec4fb | 267 | // If a position of the screen was touched that does not match any |
| Damotclese | 1:316582aec4fb | 268 | // known key position, the function ignores the screen touch. |
| Damotclese | 1:316582aec4fb | 269 | // |
| Damotclese | 1:316582aec4fb | 270 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 271 | void KeypadHandleKeyPress(uint16_t u16_screenX, uint16_t u16_screenY) |
| Damotclese | 1:316582aec4fb | 272 | { |
| Damotclese | 1:316582aec4fb | 273 | uint16_t u16_keyMinimumX = 0; |
| Damotclese | 1:316582aec4fb | 274 | uint16_t u16_keyMaximumX = 0; |
| Damotclese | 1:316582aec4fb | 275 | uint16_t u16_keyMinimumY = 0; |
| Damotclese | 1:316582aec4fb | 276 | uint16_t u16_keyMaximumY = 0; |
| Damotclese | 1:316582aec4fb | 277 | uint8_t u8_keyPadItem = 0; |
| Damotclese | 1:316582aec4fb | 278 | |
| Damotclese | 1:316582aec4fb | 279 | // Step through the keys to check until we reach an entry that's zero |
| Damotclese | 1:316582aec4fb | 280 | while(0 != st_KeypadInformation[u8_keyPadItem].u16_screenXLocation) |
| Damotclese | 1:316582aec4fb | 281 | { |
| Damotclese | 1:316582aec4fb | 282 | // Calculate the boundaries of this key |
| Damotclese | 1:316582aec4fb | 283 | u16_keyMinimumX = st_KeypadInformation[u8_keyPadItem].u16_screenXLocation; |
| Damotclese | 1:316582aec4fb | 284 | u16_keyMaximumX = u16_keyMinimumX + st_KeypadInformation[u8_keyPadItem].u16_keyHeight; |
| Damotclese | 1:316582aec4fb | 285 | u16_keyMinimumY = st_KeypadInformation[u8_keyPadItem].u16_screenYLocation; |
| Damotclese | 1:316582aec4fb | 286 | u16_keyMaximumY = u16_keyMinimumY + st_KeypadInformation[u8_keyPadItem].u16_keyWidth; |
| Damotclese | 1:316582aec4fb | 287 | |
| Damotclese | 1:316582aec4fb | 288 | // Is this the key that was pressed? |
| Damotclese | 1:316582aec4fb | 289 | if (u16_screenX > u16_keyMinimumX && u16_screenX < u16_keyMaximumX) |
| Damotclese | 1:316582aec4fb | 290 | { |
| Damotclese | 1:316582aec4fb | 291 | if (u16_screenY > u16_keyMinimumY && u16_screenY < u16_keyMaximumY) |
| Damotclese | 1:316582aec4fb | 292 | { |
| Damotclese | 3:0e554d8d5a19 | 293 | // Flash the key that was pressed |
| Damotclese | 3:0e554d8d5a19 | 294 | KeypadFlashThisKey(u8_keyPadItem); |
| Damotclese | 3:0e554d8d5a19 | 295 | |
| Damotclese | 3:0e554d8d5a19 | 296 | // Process the key that was pressed |
| Damotclese | 1:316582aec4fb | 297 | KeypadProcessKeypadKey(st_KeypadInformation[u8_keyPadItem].u8_keyASCIICharacter); |
| Damotclese | 1:316582aec4fb | 298 | |
| Damotclese | 1:316582aec4fb | 299 | // We are finished searching |
| Damotclese | 1:316582aec4fb | 300 | break; |
| Damotclese | 1:316582aec4fb | 301 | } |
| Damotclese | 1:316582aec4fb | 302 | } |
| Damotclese | 1:316582aec4fb | 303 | |
| Damotclese | 1:316582aec4fb | 304 | // Check the next possible key area |
| Damotclese | 1:316582aec4fb | 305 | u8_keyPadItem++; |
| Damotclese | 1:316582aec4fb | 306 | } |
| Damotclese | 1:316582aec4fb | 307 | } |
| Damotclese | 1:316582aec4fb | 308 | |
| Damotclese | 1:316582aec4fb | 309 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 310 | // KeypadDrawKeypad() |
| Damotclese | 1:316582aec4fb | 311 | // |
| Damotclese | 1:316582aec4fb | 312 | // This function will set the LCD background to WHITE and set the |
| Damotclese | 1:316582aec4fb | 313 | // default text color to BLUE, thehn it will display information about |
| Damotclese | 1:316582aec4fb | 314 | // what theoperator should do, then the keypad is constructed on the |
| Damotclese | 1:316582aec4fb | 315 | // display using the information in the keypad map. |
| Damotclese | 1:316582aec4fb | 316 | // |
| Damotclese | 1:316582aec4fb | 317 | // ---------------------------------------------------------------------- |
| Damotclese | 1:316582aec4fb | 318 | void KeypadDrawKeypad(void) |
| Damotclese | 1:316582aec4fb | 319 | { |
| Damotclese | 1:316582aec4fb | 320 | uint8_t u8_keyPadItem = 0; |
| Damotclese | 1:316582aec4fb | 321 | |
| Damotclese | 1:316582aec4fb | 322 | // For the keypad, we want the entire screen to be this color |
| Damotclese | 1:316582aec4fb | 323 | st_lcd.SetBackColor(LCD_COLOR_WHITE); |
| Damotclese | 1:316582aec4fb | 324 | |
| Damotclese | 1:316582aec4fb | 325 | // For the keypad's general text we want characters to be this color |
| Damotclese | 1:316582aec4fb | 326 | st_lcd.SetTextColor(LCD_COLOR_BLUE); |
| Damotclese | 1:316582aec4fb | 327 | |
| Damotclese | 5:5c507689ae66 | 328 | // Display pizza |
| Damotclese | 5:5c507689ae66 | 329 | st_lcd.DrawBitmap(1, 60, st_PizzaBMP); |
| Damotclese | 5:5c507689ae66 | 330 | |
| Damotclese | 1:316582aec4fb | 331 | // Build the ketypad display |
| Damotclese | 1:316582aec4fb | 332 | st_lcd.DisplayStringAt(1, LINE(0), (uint8_t *)"Enter access code or", CENTER_MODE); |
| Damotclese | 1:316582aec4fb | 333 | st_lcd.DisplayStringAt(1, LINE(1), (uint8_t *)"use the Moorse Code", CENTER_MODE); |
| Damotclese | 1:316582aec4fb | 334 | st_lcd.DisplayStringAt(1, LINE(2), (uint8_t *)"push button to unlock", CENTER_MODE); |
| Damotclese | 1:316582aec4fb | 335 | |
| Damotclese | 1:316582aec4fb | 336 | // Step through the keys to plot until we reach an entry that's zero |
| Damotclese | 1:316582aec4fb | 337 | while(0 != st_KeypadInformation[u8_keyPadItem].u16_screenXLocation) |
| Damotclese | 1:316582aec4fb | 338 | { |
| Damotclese | 1:316582aec4fb | 339 | // Draw the rectangle |
| Damotclese | 1:316582aec4fb | 340 | st_lcd.FillRect(st_KeypadInformation[u8_keyPadItem].u16_screenXLocation, |
| Damotclese | 1:316582aec4fb | 341 | st_KeypadInformation[u8_keyPadItem].u16_screenYLocation, |
| Damotclese | 1:316582aec4fb | 342 | st_KeypadInformation[u8_keyPadItem].u16_keyHeight, |
| Damotclese | 1:316582aec4fb | 343 | st_KeypadInformation[u8_keyPadItem].u16_keyWidth); |
| Damotclese | 1:316582aec4fb | 344 | |
| Damotclese | 1:316582aec4fb | 345 | // Display the character near the lower right corner of the rectangle |
| Damotclese | 1:316582aec4fb | 346 | st_lcd.DisplayChar( |
| Damotclese | 1:316582aec4fb | 347 | st_KeypadInformation[u8_keyPadItem].u16_screenXLocation + |
| Damotclese | 1:316582aec4fb | 348 | (st_KeypadInformation[u8_keyPadItem].u16_keyHeight / 2) + 6, |
| Damotclese | 1:316582aec4fb | 349 | st_KeypadInformation[u8_keyPadItem].u16_screenYLocation + |
| Damotclese | 1:316582aec4fb | 350 | (st_KeypadInformation[u8_keyPadItem].u16_keyWidth / 2) + 2, |
| Damotclese | 1:316582aec4fb | 351 | st_KeypadInformation[u8_keyPadItem].u8_keyASCIICharacter); |
| Damotclese | 1:316582aec4fb | 352 | |
| Damotclese | 1:316582aec4fb | 353 | // Go to the next keypad to create |
| Damotclese | 1:316582aec4fb | 354 | u8_keyPadItem++; |
| Damotclese | 1:316582aec4fb | 355 | } |
| Damotclese | 1:316582aec4fb | 356 | } |
| Damotclese | 1:316582aec4fb | 357 | |
| Damotclese | 1:316582aec4fb | 358 | // End of file |
| Damotclese | 1:316582aec4fb | 359 |