Class library for a touchscreen-based keypad for the LCD display present on the DISCO_F429ZI board.

Dependents:   WIRE-BANDING_FT810 WIRE-BANDING_copy

Committer:
grantphillips
Date:
Sun May 08 21:11:54 2016 +0000
Revision:
3:5f2fa06a0492
Parent:
2:51f454b7c9ab
Child:
4:9d6ea6fbb67f
v1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
grantphillips 0:8cc22acc00d2 1 /* KEYPAD_DISCO_F429ZI Library v1.0
grantphillips 0:8cc22acc00d2 2 * Copyright (c) 2016 Grant Phillips
grantphillips 0:8cc22acc00d2 3 * grant.phillips@nmmu.ac.za
grantphillips 0:8cc22acc00d2 4 *
grantphillips 0:8cc22acc00d2 5 *
grantphillips 0:8cc22acc00d2 6 * Permission is hereby granted, free of charge, to any person obtaining a copy
grantphillips 0:8cc22acc00d2 7 * of this software and associated documentation files (the "Software"), to deal
grantphillips 0:8cc22acc00d2 8 * in the Software without restriction, including without limitation the rights
grantphillips 0:8cc22acc00d2 9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
grantphillips 0:8cc22acc00d2 10 * copies of the Software, and to permit persons to whom the Software is
grantphillips 0:8cc22acc00d2 11 * furnished to do so, subject to the following conditions:
grantphillips 0:8cc22acc00d2 12 *
grantphillips 0:8cc22acc00d2 13 * The above copyright notice and this permission notice shall be included in
grantphillips 0:8cc22acc00d2 14 * all copies or substantial portions of the Software.
grantphillips 0:8cc22acc00d2 15 *
grantphillips 0:8cc22acc00d2 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
grantphillips 0:8cc22acc00d2 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
grantphillips 0:8cc22acc00d2 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
grantphillips 0:8cc22acc00d2 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
grantphillips 0:8cc22acc00d2 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
grantphillips 0:8cc22acc00d2 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
grantphillips 0:8cc22acc00d2 22 * THE SOFTWARE.
grantphillips 0:8cc22acc00d2 23 */
grantphillips 0:8cc22acc00d2 24
grantphillips 0:8cc22acc00d2 25 #ifndef KEYPAD_DISCO_F429ZI_H
grantphillips 0:8cc22acc00d2 26 #define KEYPAD_DISCO_F429ZI_H
grantphillips 0:8cc22acc00d2 27
grantphillips 0:8cc22acc00d2 28 #include "mbed.h"
grantphillips 0:8cc22acc00d2 29 #include "TS_DISCO_F429ZI.h"
grantphillips 0:8cc22acc00d2 30 #include "LCD_DISCO_F429ZI.h"
grantphillips 0:8cc22acc00d2 31
grantphillips 3:5f2fa06a0492 32 /** Class library for a touchscreen-based 4x4 keypad for the LCD display present on the DISCO_F429ZI board.
grantphillips 2:51f454b7c9ab 33 * It requires the TS_DISCO_F429ZI and LCD_DISCO_F429ZI to also be imported into the program.
grantphillips 0:8cc22acc00d2 34 *
grantphillips 0:8cc22acc00d2 35 * Example:
grantphillips 0:8cc22acc00d2 36 * @code
grantphillips 0:8cc22acc00d2 37 * #include "mbed.h"
grantphillips 0:8cc22acc00d2 38 * #include "HCSR04.h"
grantphillips 0:8cc22acc00d2 39 *
grantphillips 0:8cc22acc00d2 40 * HCSR04 distance(PB_8, PA_1);
grantphillips 0:8cc22acc00d2 41 *
grantphillips 0:8cc22acc00d2 42 * int main() {
grantphillips 0:8cc22acc00d2 43 * while(1){
grantphillips 0:8cc22acc00d2 44 * SWO.printf("Distance = %d (us) %f (cm)\n", distance.read_us(), distance.read_cm());
grantphillips 0:8cc22acc00d2 45 * }
grantphillips 0:8cc22acc00d2 46 * }
grantphillips 0:8cc22acc00d2 47 * @endcode
grantphillips 0:8cc22acc00d2 48 */
grantphillips 0:8cc22acc00d2 49
grantphillips 0:8cc22acc00d2 50 class KEYPAD_DISCO_F429ZI {
grantphillips 0:8cc22acc00d2 51 public:
grantphillips 0:8cc22acc00d2 52 /** Create a KEYPAD_DISCO_F429ZI object.
grantphillips 0:8cc22acc00d2 53 */
grantphillips 0:8cc22acc00d2 54 KEYPAD_DISCO_F429ZI();
grantphillips 0:8cc22acc00d2 55
grantphillips 1:1db4c6c394bb 56 /** Draws the keys for the keypad and the Message Box and Output Box areas if enabled.
grantphillips 1:1db4c6c394bb 57 * @param
grantphillips 1:1db4c6c394bb 58 * MessageBoxEnable Enable (=1) or disable(=0 the drawing of a Message Box area on the keypad screen.
grantphillips 1:1db4c6c394bb 59 * OutBoxEnable Enable (=1) or disable(=0 the drawing of a Output Box area on the keypad screen.
grantphillips 0:8cc22acc00d2 60 */
grantphillips 0:8cc22acc00d2 61 void Show(int MessageBoxEnable, int OutBoxEnable);
grantphillips 0:8cc22acc00d2 62
grantphillips 0:8cc22acc00d2 63 /** Return the current key pressed on the keypad.
grantphillips 0:8cc22acc00d2 64 * @param
grantphillips 0:8cc22acc00d2 65 * None
grantphillips 0:8cc22acc00d2 66 * @return
grantphillips 0:8cc22acc00d2 67 * ASCII character of the key pressed. Will be NULL ('/0') if no key is pressed.
grantphillips 0:8cc22acc00d2 68 */
grantphillips 0:8cc22acc00d2 69 char ReadKey();
grantphillips 0:8cc22acc00d2 70
grantphillips 2:51f454b7c9ab 71 /** Writes text (21 characters max) to one of the two lines of the Message Box area if it is enabled in Show().
grantphillips 2:51f454b7c9ab 72 * @param
grantphillips 2:51f454b7c9ab 73 * LineNum The line number to to where the text must be displayed (0 or 1).
grantphillips 2:51f454b7c9ab 74 * text String to display.
grantphillips 2:51f454b7c9ab 75 */
grantphillips 2:51f454b7c9ab 76 void WriteMsgBoxLine(int LineNum, char *text);
grantphillips 2:51f454b7c9ab 77
grantphillips 2:51f454b7c9ab 78 /** Writes text (14 characters max) to the Output Box area if it is enabled in Show().
grantphillips 2:51f454b7c9ab 79 * @param
grantphillips 2:51f454b7c9ab 80 * text String to display.
grantphillips 2:51f454b7c9ab 81 */
grantphillips 2:51f454b7c9ab 82 void WriteOutBox(char *text);
grantphillips 2:51f454b7c9ab 83
grantphillips 3:5f2fa06a0492 84 /** Sets the ASCII characters for each key on the 4x4 keypad.
grantphillips 3:5f2fa06a0492 85 * @param
grantphillips 3:5f2fa06a0492 86 * keymap Pointer to a two-dimensional array (array[3][3]) with ASCII characters for eahc key.
grantphillips 3:5f2fa06a0492 87 */
grantphillips 3:5f2fa06a0492 88 void SetKeys(char (*keymap)[4]);
grantphillips 3:5f2fa06a0492 89
grantphillips 2:51f454b7c9ab 90 /** Sets the foreground color for the keypad keys.
grantphillips 2:51f454b7c9ab 91 * @param
grantphillips 2:51f454b7c9ab 92 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 93 */
grantphillips 2:51f454b7c9ab 94 void SetKeyForeColor(uint32_t color);
grantphillips 2:51f454b7c9ab 95
grantphillips 2:51f454b7c9ab 96 /** Sets the background color for the keypad keys.
grantphillips 2:51f454b7c9ab 97 * @param
grantphillips 2:51f454b7c9ab 98 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 99 */
grantphillips 2:51f454b7c9ab 100 void SetKeyBackColor(uint32_t color);
grantphillips 2:51f454b7c9ab 101
grantphillips 2:51f454b7c9ab 102 /** Sets the background color for the keypad keys when it is pressed.
grantphillips 2:51f454b7c9ab 103 * @param
grantphillips 2:51f454b7c9ab 104 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 105 */
grantphillips 2:51f454b7c9ab 106 void SetKeyPressColor(uint32_t color);
grantphillips 2:51f454b7c9ab 107
grantphillips 2:51f454b7c9ab 108 /** Sets the foreground color for the Message Box area.
grantphillips 2:51f454b7c9ab 109 * @param
grantphillips 2:51f454b7c9ab 110 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 111 */
grantphillips 2:51f454b7c9ab 112 void SetMsgBoxForeColor(uint32_t color);
grantphillips 2:51f454b7c9ab 113
grantphillips 2:51f454b7c9ab 114 /** Sets the background color for the Message Box area.
grantphillips 2:51f454b7c9ab 115 * @param
grantphillips 2:51f454b7c9ab 116 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 117 */
grantphillips 2:51f454b7c9ab 118 void SetMsgBoxBackColor(uint32_t color);
grantphillips 2:51f454b7c9ab 119
grantphillips 2:51f454b7c9ab 120 /** Sets the foreground color for the Output Box area.
grantphillips 2:51f454b7c9ab 121 * @param
grantphillips 2:51f454b7c9ab 122 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 123 */
grantphillips 2:51f454b7c9ab 124 void SetOutBoxForeColor(uint32_t color);
grantphillips 2:51f454b7c9ab 125
grantphillips 2:51f454b7c9ab 126 /** Sets the background color for the Output Box area.
grantphillips 2:51f454b7c9ab 127 * @param
grantphillips 2:51f454b7c9ab 128 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 129 */
grantphillips 2:51f454b7c9ab 130 void SetOutBoxBackColor(uint32_t color);
grantphillips 2:51f454b7c9ab 131
grantphillips 2:51f454b7c9ab 132 /** Sets the background color for the whole keypad area.
grantphillips 2:51f454b7c9ab 133 * @param
grantphillips 2:51f454b7c9ab 134 * color The color constant or code ARGB(8-8-8-8).
grantphillips 2:51f454b7c9ab 135 */
grantphillips 2:51f454b7c9ab 136 void SetBackColor(uint32_t color);
grantphillips 0:8cc22acc00d2 137
grantphillips 0:8cc22acc00d2 138 private:
grantphillips 0:8cc22acc00d2 139 LCD_DISCO_F429ZI lcd;
grantphillips 0:8cc22acc00d2 140 TS_DISCO_F429ZI ts;
grantphillips 0:8cc22acc00d2 141 uint16_t LastkeyX, LastkeyY;
grantphillips 0:8cc22acc00d2 142 uint8_t LastKey;
grantphillips 0:8cc22acc00d2 143 uint8_t ReadKeyState;
grantphillips 0:8cc22acc00d2 144 uint16_t KeysTopY;
grantphillips 0:8cc22acc00d2 145 uint8_t row, col;
grantphillips 3:5f2fa06a0492 146 char Keys[4][4];
grantphillips 0:8cc22acc00d2 147 uint32_t MsgBColor, MsgFColor;
grantphillips 0:8cc22acc00d2 148 uint32_t OutBColor, OutFColor;
grantphillips 0:8cc22acc00d2 149 uint32_t KeyBColor, KeyFColor, KeyPressColor;
grantphillips 0:8cc22acc00d2 150 uint32_t BackColor;
grantphillips 0:8cc22acc00d2 151 int MessageBoxEnabledFlag, OutBoxEnabledFlag;
grantphillips 0:8cc22acc00d2 152 };
grantphillips 0:8cc22acc00d2 153
grantphillips 0:8cc22acc00d2 154 #endif