This is a demonstration program which draws a keypad on the LCD and uses the touch screen to allow an operator to key-in an access code. Two possible codes are allowed to grant to different levels of access. Additionally the push button is used to allow an operator to send Moorse Code pulses in to the device which is checked against two characters to determine if there was a match, and if so, access is granted.

Dependencies:   LCD_DISCO_F429ZI mbed TS_DISCO_F429ZI mbed-os BSP_DISCO_F429ZI

Also draws a mushroom on the screen and animates it.

Committer:
Damotclese
Date:
Mon Jun 03 21:56:36 2019 +0000
Revision:
3:0e554d8d5a19
Parent:
1:316582aec4fb
Child:
5:5c507689ae66
When the keypad keys are touched, they flash YELLOW for a quarter of a second now;

Who changed what in which revision?

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