Class library for a touchscreen-based keypad for the LCD display present on the DISCO_F429ZI board.
Dependents: WIRE-BANDING_FT810 WIRE-BANDING_copy
KEYPAD_DISCO_F429ZI.cpp@4:9d6ea6fbb67f, 2016-05-10 (annotated)
- Committer:
- grantphillips
- Date:
- Tue May 10 21:02:52 2016 +0000
- Revision:
- 4:9d6ea6fbb67f
- Parent:
- 3:5f2fa06a0492
v1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
grantphillips | 0:8cc22acc00d2 | 1 | #include "KEYPAD_DISCO_F429ZI.h" |
grantphillips | 0:8cc22acc00d2 | 2 | #include "mbed.h" |
grantphillips | 0:8cc22acc00d2 | 3 | #include "TS_DISCO_F429ZI.h" |
grantphillips | 0:8cc22acc00d2 | 4 | #include "LCD_DISCO_F429ZI.h" |
grantphillips | 0:8cc22acc00d2 | 5 | |
grantphillips | 0:8cc22acc00d2 | 6 | |
grantphillips | 0:8cc22acc00d2 | 7 | KEYPAD_DISCO_F429ZI::KEYPAD_DISCO_F429ZI() { |
grantphillips | 0:8cc22acc00d2 | 8 | LastKey=0; |
grantphillips | 0:8cc22acc00d2 | 9 | ReadKeyState = 0; |
grantphillips | 4:9d6ea6fbb67f | 10 | MsgBColor = LCD_COLOR_BLACK; |
grantphillips | 4:9d6ea6fbb67f | 11 | MsgFColor = LCD_COLOR_WHITE; |
grantphillips | 0:8cc22acc00d2 | 12 | OutBColor = LCD_COLOR_WHITE; |
grantphillips | 0:8cc22acc00d2 | 13 | OutFColor = LCD_COLOR_BLACK; |
grantphillips | 0:8cc22acc00d2 | 14 | BackColor = LCD_COLOR_BLACK; |
grantphillips | 0:8cc22acc00d2 | 15 | KeyBColor = LCD_COLOR_WHITE; |
grantphillips | 0:8cc22acc00d2 | 16 | KeyFColor = LCD_COLOR_BLACK; |
grantphillips | 0:8cc22acc00d2 | 17 | KeyPressColor = LCD_COLOR_GRAY; |
grantphillips | 0:8cc22acc00d2 | 18 | KeysTopY=110; |
grantphillips | 0:8cc22acc00d2 | 19 | |
grantphillips | 0:8cc22acc00d2 | 20 | Keys[0][0] = '1'; |
grantphillips | 0:8cc22acc00d2 | 21 | Keys[0][1] = '2'; |
grantphillips | 0:8cc22acc00d2 | 22 | Keys[0][2] = '3'; |
grantphillips | 0:8cc22acc00d2 | 23 | Keys[0][3] = 'A'; |
grantphillips | 0:8cc22acc00d2 | 24 | Keys[1][0] = '4'; |
grantphillips | 0:8cc22acc00d2 | 25 | Keys[1][1] = '5'; |
grantphillips | 0:8cc22acc00d2 | 26 | Keys[1][2] = '6'; |
grantphillips | 0:8cc22acc00d2 | 27 | Keys[1][3] = 'B'; |
grantphillips | 0:8cc22acc00d2 | 28 | Keys[2][0] = '7'; |
grantphillips | 0:8cc22acc00d2 | 29 | Keys[2][1] = '8'; |
grantphillips | 0:8cc22acc00d2 | 30 | Keys[2][2] = '9'; |
grantphillips | 0:8cc22acc00d2 | 31 | Keys[2][3] = 'C'; |
grantphillips | 0:8cc22acc00d2 | 32 | Keys[3][0] = '*'; |
grantphillips | 0:8cc22acc00d2 | 33 | Keys[3][1] = '0'; |
grantphillips | 0:8cc22acc00d2 | 34 | Keys[3][2] = '#'; |
grantphillips | 0:8cc22acc00d2 | 35 | Keys[3][3] = 'D'; |
grantphillips | 0:8cc22acc00d2 | 36 | } |
grantphillips | 0:8cc22acc00d2 | 37 | |
grantphillips | 0:8cc22acc00d2 | 38 | |
grantphillips | 0:8cc22acc00d2 | 39 | void KEYPAD_DISCO_F429ZI::Show(int MessageBoxEnable, int OutBoxEnable) { |
grantphillips | 0:8cc22acc00d2 | 40 | uint16_t x, y; |
grantphillips | 0:8cc22acc00d2 | 41 | uint8_t row, col; |
grantphillips | 0:8cc22acc00d2 | 42 | |
grantphillips | 0:8cc22acc00d2 | 43 | if(MessageBoxEnable > 0) |
grantphillips | 0:8cc22acc00d2 | 44 | MessageBoxEnabledFlag = 1; |
grantphillips | 0:8cc22acc00d2 | 45 | else |
grantphillips | 0:8cc22acc00d2 | 46 | MessageBoxEnabledFlag = 0; |
grantphillips | 0:8cc22acc00d2 | 47 | |
grantphillips | 0:8cc22acc00d2 | 48 | if(OutBoxEnable > 0) |
grantphillips | 0:8cc22acc00d2 | 49 | OutBoxEnabledFlag = 1; |
grantphillips | 0:8cc22acc00d2 | 50 | else |
grantphillips | 0:8cc22acc00d2 | 51 | OutBoxEnabledFlag = 0; |
grantphillips | 0:8cc22acc00d2 | 52 | |
grantphillips | 0:8cc22acc00d2 | 53 | lcd.Clear(BackColor); |
grantphillips | 0:8cc22acc00d2 | 54 | |
grantphillips | 0:8cc22acc00d2 | 55 | /* Display Message textbox */ |
grantphillips | 0:8cc22acc00d2 | 56 | if(MessageBoxEnabledFlag) { |
grantphillips | 0:8cc22acc00d2 | 57 | lcd.SetFont(&Font16); |
grantphillips | 0:8cc22acc00d2 | 58 | lcd.SetBackColor(MsgBColor); |
grantphillips | 0:8cc22acc00d2 | 59 | lcd.SetTextColor(MsgFColor); |
grantphillips | 0:8cc22acc00d2 | 60 | lcd.DisplayStringAt(4, LINE(0)+4,(uint8_t *) " ", LEFT_MODE); |
grantphillips | 0:8cc22acc00d2 | 61 | lcd.DisplayStringAt(4, LINE(1)+4,(uint8_t *) " ", LEFT_MODE); |
grantphillips | 0:8cc22acc00d2 | 62 | lcd.SetTextColor(MsgBColor); |
grantphillips | 0:8cc22acc00d2 | 63 | lcd.FillRect(0,0,240,4); //top filler |
grantphillips | 0:8cc22acc00d2 | 64 | lcd.FillRect(0,LINE(0),4,36); //left filler |
grantphillips | 0:8cc22acc00d2 | 65 | lcd.FillRect(235,LINE(0),5,36); //right filler |
grantphillips | 0:8cc22acc00d2 | 66 | } |
grantphillips | 0:8cc22acc00d2 | 67 | |
grantphillips | 0:8cc22acc00d2 | 68 | /* Display Output textbox */ |
grantphillips | 0:8cc22acc00d2 | 69 | if(OutBoxEnabledFlag) { |
grantphillips | 0:8cc22acc00d2 | 70 | lcd.SetFont(&Font24); |
grantphillips | 0:8cc22acc00d2 | 71 | lcd.SetBackColor(OutBColor); |
grantphillips | 0:8cc22acc00d2 | 72 | lcd.SetTextColor(OutFColor); |
grantphillips | 0:8cc22acc00d2 | 73 | lcd.DisplayStringAt(1,LINE(2),(uint8_t *) " ", LEFT_MODE); |
grantphillips | 0:8cc22acc00d2 | 74 | lcd.SetTextColor(OutBColor); |
grantphillips | 0:8cc22acc00d2 | 75 | lcd.FillRect(1,LINE(2)-4,238,5); //top filler |
grantphillips | 0:8cc22acc00d2 | 76 | lcd.DrawVLine(0,LINE(2)-4,28); //left filler |
grantphillips | 0:8cc22acc00d2 | 77 | lcd.DrawVLine(239,LINE(2)-4,28); //right filler |
grantphillips | 0:8cc22acc00d2 | 78 | } |
grantphillips | 0:8cc22acc00d2 | 79 | |
grantphillips | 0:8cc22acc00d2 | 80 | /* Draw buttons */ |
grantphillips | 0:8cc22acc00d2 | 81 | lcd.SetTextColor(KeyBColor); |
grantphillips | 0:8cc22acc00d2 | 82 | for(y=KeysTopY; y<=KeysTopY+180; y=y+60) |
grantphillips | 0:8cc22acc00d2 | 83 | for(x=30; x<=210; x=x+60) |
grantphillips | 0:8cc22acc00d2 | 84 | lcd.FillCircle(x,y,25); |
grantphillips | 0:8cc22acc00d2 | 85 | |
grantphillips | 0:8cc22acc00d2 | 86 | /* Draw button text */ |
grantphillips | 0:8cc22acc00d2 | 87 | lcd.SetFont(&Font24); |
grantphillips | 0:8cc22acc00d2 | 88 | lcd.SetTextColor(KeyFColor); |
grantphillips | 0:8cc22acc00d2 | 89 | lcd.SetBackColor(KeyBColor); |
grantphillips | 0:8cc22acc00d2 | 90 | row=0; |
grantphillips | 0:8cc22acc00d2 | 91 | for(y=KeysTopY; y<=KeysTopY+180; y=y+60) |
grantphillips | 0:8cc22acc00d2 | 92 | { |
grantphillips | 0:8cc22acc00d2 | 93 | col=0; |
grantphillips | 0:8cc22acc00d2 | 94 | for(x=30; x<=210; x=x+60) |
grantphillips | 0:8cc22acc00d2 | 95 | { |
grantphillips | 0:8cc22acc00d2 | 96 | lcd.DisplayChar(x-8, y-8, Keys[row][col]); |
grantphillips | 0:8cc22acc00d2 | 97 | col++; |
grantphillips | 0:8cc22acc00d2 | 98 | } |
grantphillips | 0:8cc22acc00d2 | 99 | row++; |
grantphillips | 0:8cc22acc00d2 | 100 | } |
grantphillips | 0:8cc22acc00d2 | 101 | |
grantphillips | 0:8cc22acc00d2 | 102 | ts.Init(240, 320); |
grantphillips | 0:8cc22acc00d2 | 103 | } |
grantphillips | 0:8cc22acc00d2 | 104 | |
grantphillips | 0:8cc22acc00d2 | 105 | char KEYPAD_DISCO_F429ZI::ReadKey() { |
grantphillips | 0:8cc22acc00d2 | 106 | uint16_t x, y; |
grantphillips | 0:8cc22acc00d2 | 107 | TS_StateTypeDef TS_State; |
grantphillips | 0:8cc22acc00d2 | 108 | |
grantphillips | 0:8cc22acc00d2 | 109 | ts.GetState(&TS_State); |
grantphillips | 0:8cc22acc00d2 | 110 | |
grantphillips | 0:8cc22acc00d2 | 111 | switch(ReadKeyState) { |
grantphillips | 0:8cc22acc00d2 | 112 | case 0: { //wait for key press |
grantphillips | 0:8cc22acc00d2 | 113 | if (TS_State.TouchDetected) { //if the screen was touched |
grantphillips | 0:8cc22acc00d2 | 114 | x = TS_State.X; //read the x value |
grantphillips | 0:8cc22acc00d2 | 115 | y = TS_State.Y; //read the y value |
grantphillips | 0:8cc22acc00d2 | 116 | if((x > 3) && (x <= 60) && (y > KeysTopY - 30) && (y <= KeysTopY + 30)) { //row0, col0 |
grantphillips | 0:8cc22acc00d2 | 117 | row=0;col=0; |
grantphillips | 0:8cc22acc00d2 | 118 | LastkeyX = 30; |
grantphillips | 0:8cc22acc00d2 | 119 | LastkeyY = KeysTopY; |
grantphillips | 0:8cc22acc00d2 | 120 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 121 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 122 | } |
grantphillips | 0:8cc22acc00d2 | 123 | else if((x > 60) && (x <= 120) && (y > KeysTopY - 30) && (y <= KeysTopY + 30)) { //row0, col1 |
grantphillips | 0:8cc22acc00d2 | 124 | row=0;col=1; |
grantphillips | 0:8cc22acc00d2 | 125 | LastkeyX = 90; |
grantphillips | 0:8cc22acc00d2 | 126 | LastkeyY = KeysTopY; |
grantphillips | 0:8cc22acc00d2 | 127 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 128 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 129 | } |
grantphillips | 0:8cc22acc00d2 | 130 | else if((x > 120) && (x <= 180) && (y > KeysTopY - 30) && (y <= KeysTopY + 30)) { //row0, col2 |
grantphillips | 0:8cc22acc00d2 | 131 | row=0;col=2; |
grantphillips | 0:8cc22acc00d2 | 132 | LastkeyX = 150; |
grantphillips | 0:8cc22acc00d2 | 133 | LastkeyY = KeysTopY; |
grantphillips | 0:8cc22acc00d2 | 134 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 135 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 136 | } |
grantphillips | 0:8cc22acc00d2 | 137 | else if((x > 180) && (x <= 237) && (y > KeysTopY - 30) && (y <= KeysTopY + 30)) { //row0, col3 |
grantphillips | 0:8cc22acc00d2 | 138 | row=0;col=3; |
grantphillips | 0:8cc22acc00d2 | 139 | LastkeyX = 210; |
grantphillips | 0:8cc22acc00d2 | 140 | LastkeyY = KeysTopY; |
grantphillips | 0:8cc22acc00d2 | 141 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 142 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 143 | } |
grantphillips | 0:8cc22acc00d2 | 144 | |
grantphillips | 0:8cc22acc00d2 | 145 | if((x > 3) && (x <= 60) && (y > KeysTopY + 30) && (y <= KeysTopY + 90)) { //row1, col0 |
grantphillips | 0:8cc22acc00d2 | 146 | row=1;col=0; |
grantphillips | 0:8cc22acc00d2 | 147 | LastkeyX = 30; |
grantphillips | 0:8cc22acc00d2 | 148 | LastkeyY = KeysTopY+60; |
grantphillips | 0:8cc22acc00d2 | 149 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 150 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 151 | } |
grantphillips | 0:8cc22acc00d2 | 152 | else if((x > 60) && (x <= 120) && (y > KeysTopY + 30) && (y <= KeysTopY + 90)) { //row1, col1 |
grantphillips | 0:8cc22acc00d2 | 153 | row=1;col=1; |
grantphillips | 0:8cc22acc00d2 | 154 | LastkeyX = 90; |
grantphillips | 0:8cc22acc00d2 | 155 | LastkeyY = KeysTopY+60; |
grantphillips | 0:8cc22acc00d2 | 156 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 157 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 158 | } |
grantphillips | 0:8cc22acc00d2 | 159 | else if((x > 120) && (x <= 180) && (y > KeysTopY + 30) && (y <= KeysTopY + 90)) { //row1, col2 |
grantphillips | 0:8cc22acc00d2 | 160 | row=1;col=2; |
grantphillips | 0:8cc22acc00d2 | 161 | LastkeyX = 150; |
grantphillips | 0:8cc22acc00d2 | 162 | LastkeyY = KeysTopY+60; |
grantphillips | 0:8cc22acc00d2 | 163 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 164 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 165 | } |
grantphillips | 0:8cc22acc00d2 | 166 | else if((x > 180) && (x <= 237) && (y > KeysTopY + 30) && (y <= KeysTopY + 90)) { //row1, col3 |
grantphillips | 0:8cc22acc00d2 | 167 | row=1;col=3; |
grantphillips | 0:8cc22acc00d2 | 168 | LastkeyX = 210; |
grantphillips | 0:8cc22acc00d2 | 169 | LastkeyY = KeysTopY+60; |
grantphillips | 0:8cc22acc00d2 | 170 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 171 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 172 | } |
grantphillips | 0:8cc22acc00d2 | 173 | |
grantphillips | 0:8cc22acc00d2 | 174 | if((x > 3) && (x <= 60) && (y > KeysTopY + 90) && (y <= KeysTopY + 150)) { //row2, col0 |
grantphillips | 0:8cc22acc00d2 | 175 | row=2;col=0; |
grantphillips | 0:8cc22acc00d2 | 176 | LastkeyX = 30; |
grantphillips | 0:8cc22acc00d2 | 177 | LastkeyY = KeysTopY+120; |
grantphillips | 0:8cc22acc00d2 | 178 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 179 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 180 | } |
grantphillips | 0:8cc22acc00d2 | 181 | else if((x > 60) && (x <= 120) && (y > KeysTopY + 90) && (y <= KeysTopY + 150)) { //row2, col1 |
grantphillips | 0:8cc22acc00d2 | 182 | row=2;col=1; |
grantphillips | 0:8cc22acc00d2 | 183 | LastkeyX = 90; |
grantphillips | 0:8cc22acc00d2 | 184 | LastkeyY = KeysTopY+120; |
grantphillips | 0:8cc22acc00d2 | 185 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 186 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 187 | } |
grantphillips | 0:8cc22acc00d2 | 188 | else if((x > 120) && (x <= 180) && (y > KeysTopY + 90) && (y <= KeysTopY + 150)) { //row2, col2 |
grantphillips | 0:8cc22acc00d2 | 189 | row=2;col=2; |
grantphillips | 0:8cc22acc00d2 | 190 | LastkeyX = 150; |
grantphillips | 0:8cc22acc00d2 | 191 | LastkeyY = KeysTopY+120; |
grantphillips | 0:8cc22acc00d2 | 192 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 193 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 194 | } |
grantphillips | 0:8cc22acc00d2 | 195 | else if((x > 180) && (x <= 237) && (y > KeysTopY + 90) && (y <= KeysTopY + 150)) { //row2, col3 |
grantphillips | 0:8cc22acc00d2 | 196 | row=2;col=3; |
grantphillips | 0:8cc22acc00d2 | 197 | LastkeyX = 210; |
grantphillips | 0:8cc22acc00d2 | 198 | LastkeyY = KeysTopY+120; |
grantphillips | 0:8cc22acc00d2 | 199 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 200 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 201 | } |
grantphillips | 0:8cc22acc00d2 | 202 | |
grantphillips | 0:8cc22acc00d2 | 203 | if((x > 3) && (x <= 60) && (y > KeysTopY + 150) && (y <= KeysTopY + 210)) { //row3, col0 |
grantphillips | 0:8cc22acc00d2 | 204 | row=3;col=0; |
grantphillips | 0:8cc22acc00d2 | 205 | LastkeyX = 30; |
grantphillips | 0:8cc22acc00d2 | 206 | LastkeyY = KeysTopY+180; |
grantphillips | 0:8cc22acc00d2 | 207 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 208 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 209 | } |
grantphillips | 0:8cc22acc00d2 | 210 | else if((x > 60) && (x <= 120) && (y > KeysTopY + 150) && (y <= KeysTopY + 210)) { //row3, col1 |
grantphillips | 0:8cc22acc00d2 | 211 | row=3;col=1; |
grantphillips | 0:8cc22acc00d2 | 212 | LastkeyX = 90; |
grantphillips | 0:8cc22acc00d2 | 213 | LastkeyY = KeysTopY+180; |
grantphillips | 0:8cc22acc00d2 | 214 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 215 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 216 | } |
grantphillips | 0:8cc22acc00d2 | 217 | else if((x > 120) && (x <= 180) && (y > KeysTopY + 150) && (y <= KeysTopY + 210)) { //row3, col2 |
grantphillips | 0:8cc22acc00d2 | 218 | row=3;col=2; |
grantphillips | 0:8cc22acc00d2 | 219 | LastkeyX = 150; |
grantphillips | 0:8cc22acc00d2 | 220 | LastkeyY = KeysTopY+180; |
grantphillips | 0:8cc22acc00d2 | 221 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 222 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 223 | } |
grantphillips | 0:8cc22acc00d2 | 224 | else if((x > 180) && (x <= 237) && (y > KeysTopY + 150) && (y <= KeysTopY + 210)) { //row3, col3 |
grantphillips | 0:8cc22acc00d2 | 225 | row=3;col=3; |
grantphillips | 0:8cc22acc00d2 | 226 | LastkeyX = 210; |
grantphillips | 0:8cc22acc00d2 | 227 | LastkeyY = KeysTopY+180; |
grantphillips | 0:8cc22acc00d2 | 228 | LastKey = Keys[row][col]; |
grantphillips | 0:8cc22acc00d2 | 229 | ReadKeyState = 10; |
grantphillips | 0:8cc22acc00d2 | 230 | } |
grantphillips | 0:8cc22acc00d2 | 231 | |
grantphillips | 0:8cc22acc00d2 | 232 | |
grantphillips | 0:8cc22acc00d2 | 233 | // else |
grantphillips | 0:8cc22acc00d2 | 234 | // { |
grantphillips | 0:8cc22acc00d2 | 235 | // //do nothing when not incorrect touch position |
grantphillips | 0:8cc22acc00d2 | 236 | // } |
grantphillips | 0:8cc22acc00d2 | 237 | } |
grantphillips | 0:8cc22acc00d2 | 238 | } break; |
grantphillips | 0:8cc22acc00d2 | 239 | |
grantphillips | 0:8cc22acc00d2 | 240 | |
grantphillips | 0:8cc22acc00d2 | 241 | case 10: { //draw button darker |
grantphillips | 0:8cc22acc00d2 | 242 | lcd.SetFont(&Font24); |
grantphillips | 0:8cc22acc00d2 | 243 | lcd.SetTextColor(KeyPressColor); |
grantphillips | 0:8cc22acc00d2 | 244 | lcd.FillCircle(LastkeyX,LastkeyY,25); |
grantphillips | 0:8cc22acc00d2 | 245 | lcd.SetTextColor(KeyFColor); |
grantphillips | 0:8cc22acc00d2 | 246 | lcd.SetBackColor(KeyPressColor); |
grantphillips | 0:8cc22acc00d2 | 247 | lcd.DisplayChar(LastkeyX-8, LastkeyY-8, Keys[row][col]); |
grantphillips | 0:8cc22acc00d2 | 248 | |
grantphillips | 0:8cc22acc00d2 | 249 | ReadKeyState = 20; |
grantphillips | 0:8cc22acc00d2 | 250 | } break; |
grantphillips | 0:8cc22acc00d2 | 251 | |
grantphillips | 0:8cc22acc00d2 | 252 | |
grantphillips | 0:8cc22acc00d2 | 253 | case 20: { //wait for key to be released |
grantphillips | 0:8cc22acc00d2 | 254 | if(TS_State.TouchDetected == 0) |
grantphillips | 0:8cc22acc00d2 | 255 | ReadKeyState = 30; |
grantphillips | 0:8cc22acc00d2 | 256 | } break; |
grantphillips | 0:8cc22acc00d2 | 257 | |
grantphillips | 0:8cc22acc00d2 | 258 | |
grantphillips | 0:8cc22acc00d2 | 259 | case 30: //draw key normal again |
grantphillips | 0:8cc22acc00d2 | 260 | { |
grantphillips | 0:8cc22acc00d2 | 261 | lcd.SetFont(&Font24); |
grantphillips | 0:8cc22acc00d2 | 262 | lcd.SetTextColor(KeyBColor); |
grantphillips | 0:8cc22acc00d2 | 263 | lcd.FillCircle(LastkeyX,LastkeyY,25); |
grantphillips | 0:8cc22acc00d2 | 264 | lcd.SetTextColor(KeyFColor); |
grantphillips | 0:8cc22acc00d2 | 265 | lcd.SetBackColor(KeyBColor); |
grantphillips | 0:8cc22acc00d2 | 266 | lcd.DisplayChar(LastkeyX-8, LastkeyY-8, Keys[row][col]); |
grantphillips | 0:8cc22acc00d2 | 267 | |
grantphillips | 0:8cc22acc00d2 | 268 | LastKey = 0; |
grantphillips | 0:8cc22acc00d2 | 269 | ReadKeyState = 0; |
grantphillips | 0:8cc22acc00d2 | 270 | } break; |
grantphillips | 0:8cc22acc00d2 | 271 | } |
grantphillips | 0:8cc22acc00d2 | 272 | |
grantphillips | 0:8cc22acc00d2 | 273 | wait(0.01); //to allow for contact bounce |
grantphillips | 0:8cc22acc00d2 | 274 | |
grantphillips | 0:8cc22acc00d2 | 275 | return LastKey; |
grantphillips | 0:8cc22acc00d2 | 276 | } |
grantphillips | 2:51f454b7c9ab | 277 | |
grantphillips | 2:51f454b7c9ab | 278 | void KEYPAD_DISCO_F429ZI::WriteMsgBoxLine(int LineNum, char *text) { |
grantphillips | 2:51f454b7c9ab | 279 | if(MessageBoxEnabledFlag) { |
grantphillips | 2:51f454b7c9ab | 280 | if((LineNum < 0) || (LineNum > 1)) |
grantphillips | 2:51f454b7c9ab | 281 | LineNum = 0; |
grantphillips | 2:51f454b7c9ab | 282 | lcd.SetFont(&Font16); |
grantphillips | 2:51f454b7c9ab | 283 | lcd.SetBackColor(MsgBColor); |
grantphillips | 2:51f454b7c9ab | 284 | lcd.SetTextColor(MsgFColor); |
grantphillips | 2:51f454b7c9ab | 285 | lcd.DisplayStringAt(4, LINE(LineNum)+4,(uint8_t *) text, LEFT_MODE); |
grantphillips | 2:51f454b7c9ab | 286 | } |
grantphillips | 2:51f454b7c9ab | 287 | } |
grantphillips | 3:5f2fa06a0492 | 288 | |
grantphillips | 2:51f454b7c9ab | 289 | void KEYPAD_DISCO_F429ZI::WriteOutBox(char *text) { |
grantphillips | 2:51f454b7c9ab | 290 | if(OutBoxEnabledFlag) { |
grantphillips | 2:51f454b7c9ab | 291 | lcd.SetFont(&Font24); |
grantphillips | 2:51f454b7c9ab | 292 | lcd.SetBackColor(OutBColor); |
grantphillips | 2:51f454b7c9ab | 293 | lcd.SetTextColor(OutFColor); |
grantphillips | 2:51f454b7c9ab | 294 | lcd.DisplayStringAt(1,LINE(2),(uint8_t *) text, LEFT_MODE); |
grantphillips | 2:51f454b7c9ab | 295 | } |
grantphillips | 2:51f454b7c9ab | 296 | } |
grantphillips | 2:51f454b7c9ab | 297 | |
grantphillips | 3:5f2fa06a0492 | 298 | void KEYPAD_DISCO_F429ZI::SetKeys(char (*keymap)[4]) { |
grantphillips | 3:5f2fa06a0492 | 299 | int i, j; |
grantphillips | 3:5f2fa06a0492 | 300 | |
grantphillips | 3:5f2fa06a0492 | 301 | for(i=0; i<=3; i++) |
grantphillips | 3:5f2fa06a0492 | 302 | for(j=0; j<=3; j++) |
grantphillips | 3:5f2fa06a0492 | 303 | Keys[i][j] = keymap[i][j]; |
grantphillips | 3:5f2fa06a0492 | 304 | } |
grantphillips | 3:5f2fa06a0492 | 305 | |
grantphillips | 2:51f454b7c9ab | 306 | void KEYPAD_DISCO_F429ZI::SetKeyForeColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 307 | KeyFColor = color; |
grantphillips | 2:51f454b7c9ab | 308 | } |
grantphillips | 2:51f454b7c9ab | 309 | |
grantphillips | 2:51f454b7c9ab | 310 | void KEYPAD_DISCO_F429ZI::SetKeyBackColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 311 | KeyBColor = color; |
grantphillips | 2:51f454b7c9ab | 312 | } |
grantphillips | 2:51f454b7c9ab | 313 | |
grantphillips | 2:51f454b7c9ab | 314 | void KEYPAD_DISCO_F429ZI::SetKeyPressColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 315 | KeyPressColor = color; |
grantphillips | 2:51f454b7c9ab | 316 | } |
grantphillips | 2:51f454b7c9ab | 317 | |
grantphillips | 2:51f454b7c9ab | 318 | void KEYPAD_DISCO_F429ZI::SetMsgBoxForeColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 319 | MsgFColor = color; |
grantphillips | 2:51f454b7c9ab | 320 | } |
grantphillips | 2:51f454b7c9ab | 321 | |
grantphillips | 2:51f454b7c9ab | 322 | void KEYPAD_DISCO_F429ZI::SetMsgBoxBackColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 323 | MsgBColor = color; |
grantphillips | 2:51f454b7c9ab | 324 | } |
grantphillips | 2:51f454b7c9ab | 325 | |
grantphillips | 2:51f454b7c9ab | 326 | void KEYPAD_DISCO_F429ZI::SetOutBoxForeColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 327 | OutFColor = color; |
grantphillips | 2:51f454b7c9ab | 328 | } |
grantphillips | 2:51f454b7c9ab | 329 | |
grantphillips | 2:51f454b7c9ab | 330 | void KEYPAD_DISCO_F429ZI::SetOutBoxBackColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 331 | OutBColor = color; |
grantphillips | 2:51f454b7c9ab | 332 | } |
grantphillips | 2:51f454b7c9ab | 333 | |
grantphillips | 2:51f454b7c9ab | 334 | void KEYPAD_DISCO_F429ZI::SetBackColor(uint32_t color) { |
grantphillips | 2:51f454b7c9ab | 335 | BackColor = color; |
grantphillips | 2:51f454b7c9ab | 336 | } |