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

Dependents:   WIRE-BANDING_FT810 WIRE-BANDING_copy

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers KEYPAD_DISCO_F429ZI.h Source File

KEYPAD_DISCO_F429ZI.h

00001 /* KEYPAD_DISCO_F429ZI Library v1.0
00002  * Copyright (c) 2016 Grant Phillips
00003  * grant.phillips@nmmu.ac.za
00004  *
00005  *
00006  * Permission is hereby granted, free of charge, to any person obtaining a copy
00007  * of this software and associated documentation files (the "Software"), to deal
00008  * in the Software without restriction, including without limitation the rights
00009  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00010  * copies of the Software, and to permit persons to whom the Software is
00011  * furnished to do so, subject to the following conditions:
00012  *
00013  * The above copyright notice and this permission notice shall be included in
00014  * all copies or substantial portions of the Software.
00015  *
00016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00019  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00020  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00021  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00022  * THE SOFTWARE.
00023  */
00024  
00025 #ifndef KEYPAD_DISCO_F429ZI_H
00026 #define KEYPAD_DISCO_F429ZI_H
00027  
00028 #include "mbed.h"
00029 #include "TS_DISCO_F429ZI.h"
00030 #include "LCD_DISCO_F429ZI.h"
00031 
00032 /** Class library for a touchscreen-based 4x4 keypad for the LCD display present on the DISCO_F429ZI board. 
00033  * It requires the TS_DISCO_F429ZI and LCD_DISCO_F429ZI to also be imported into the program.
00034  *
00035  * Example:
00036  * @code
00037  * #include "mbed.h"
00038  * #include "TS_DISCO_F429ZI.h"
00039  * #include "LCD_DISCO_F429ZI.h"
00040  * #include "KEYPAD_DISCO_F429ZI.h"
00041  * 
00042  * KEYPAD_DISCO_F429ZI keypad;
00043  *                            
00044  * int main() {
00045  *     char buf[20];
00046  *     char k, key;
00047  *     
00048  *     keypad.Show(1, 1);                              //Display the keypad, enable the Message and Output Box areas
00049  *     keypad.WriteMsgBoxLine(0, "Press any key...");  //display a message in the
00050  *     keypad.WriteMsgBoxLine(1, "----------------");  //Message Box area of the keypad
00051  *    
00052  *     while(1) {
00053  *         k = keypad.ReadKey();                       //read the current key pressed
00054  *         if(k != '\0') {                             //if a key is pressed
00055  *             key = k;                                //store the key in a variable
00056  *             do                                      //read until key is released
00057  *                 k = keypad.ReadKey();
00058  *             while(k != '\0');
00059  *             sprintf(buf, "%c was pressed", key);    
00060  *             keypad.WriteOutBox(buf);                //display result in Output Box area of keypad
00061  *         }
00062  *     }
00063  * }
00064  * @endcode
00065  */
00066  
00067 class KEYPAD_DISCO_F429ZI {
00068   public:
00069     /** Create a KEYPAD_DISCO_F429ZI object.
00070     */
00071     KEYPAD_DISCO_F429ZI();
00072     
00073     /** Draws the keys for the keypad and the Message Box and Output Box areas if enabled.
00074     * @param 
00075     *     MessageBoxEnable Enable (=1) or disable(=0 the drawing of a Message Box area on the keypad screen.
00076     *     OutBoxEnable Enable (=1) or disable(=0 the drawing of a Output Box area on the keypad screen.
00077     */
00078     void Show(int MessageBoxEnable, int OutBoxEnable);
00079     
00080     /** Return the current key pressed on the keypad.
00081     * @param 
00082     *     None
00083     * @return
00084     *     ASCII character of the key pressed.  Will be NULL ('/0') if no key is pressed.
00085     */
00086     char ReadKey();
00087 
00088     /** Writes text (21 characters max) to one of the two lines of the Message Box area if it is enabled in Show().
00089     * @param 
00090     *     LineNum The line number to to where the text must be displayed (0 or 1).
00091     *     text String to display.
00092     */
00093     void WriteMsgBoxLine(int LineNum, char *text);
00094     
00095     /** Writes text (14 characters max) to the Output Box area if it is enabled in Show().
00096     * @param 
00097     *     text String to display.
00098     */
00099     void WriteOutBox(char *text);
00100     
00101     /** Sets the ASCII characters for each key on the 4x4 keypad.
00102     * @param 
00103     *     keymap Pointer to a two-dimensional array (array[4][4]) with ASCII characters for each key.
00104     */
00105     void SetKeys(char (*keymap)[4]);
00106     
00107     /** Sets the foreground color for the keypad keys.
00108     * @param 
00109     *     color The color constant or code ARGB(8-8-8-8).
00110     */
00111     void SetKeyForeColor(uint32_t color);
00112     
00113     /** Sets the background color for the keypad keys.
00114     * @param 
00115     *     color The color constant or code ARGB(8-8-8-8).
00116     */
00117     void SetKeyBackColor(uint32_t color);
00118     
00119     /** Sets the background color for the keypad keys when it is pressed.
00120     * @param 
00121     *     color The color constant or code ARGB(8-8-8-8).
00122     */
00123     void SetKeyPressColor(uint32_t color);
00124     
00125     /** Sets the foreground color for the Message Box area.
00126     * @param 
00127     *     color The color constant or code ARGB(8-8-8-8).
00128     */
00129     void SetMsgBoxForeColor(uint32_t color);
00130     
00131     /** Sets the background color for the Message Box area.
00132     * @param 
00133     *     color The color constant or code ARGB(8-8-8-8).
00134     */
00135     void SetMsgBoxBackColor(uint32_t color);
00136     
00137     /** Sets the foreground color for the Output Box area.
00138     * @param 
00139     *     color The color constant or code ARGB(8-8-8-8).
00140     */
00141     void SetOutBoxForeColor(uint32_t color);
00142     
00143     /** Sets the background color for the Output Box area.
00144     * @param 
00145     *     color The color constant or code ARGB(8-8-8-8).
00146     */
00147     void SetOutBoxBackColor(uint32_t color);
00148     
00149     /** Sets the background color for the whole keypad area.
00150     * @param 
00151     *     color The color constant or code ARGB(8-8-8-8).
00152     */
00153     void SetBackColor(uint32_t color);
00154  
00155   private:
00156     LCD_DISCO_F429ZI lcd;
00157     TS_DISCO_F429ZI ts;
00158     uint16_t LastkeyX, LastkeyY;  
00159     uint8_t LastKey;
00160     uint8_t ReadKeyState;
00161     uint16_t KeysTopY;
00162     uint8_t row, col;
00163     char Keys[4][4];
00164     uint32_t MsgBColor, MsgFColor;
00165     uint32_t OutBColor, OutFColor;
00166     uint32_t KeyBColor, KeyFColor, KeyPressColor;
00167     uint32_t BackColor;
00168     int MessageBoxEnabledFlag, OutBoxEnabledFlag;
00169 };
00170  
00171 #endif