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.
Dependents: RA8875_KeyPadDemo PUB_RA8875_Keypad IAC_Final_Monil_copy
Keypad.h@0:9b0b4ae5b47a, 2016-02-08 (annotated)
- Committer:
- WiredHome
- Date:
- Mon Feb 08 02:38:43 2016 +0000
- Revision:
- 0:9b0b4ae5b47a
- Child:
- 1:7feeebbd8367
onscreen keypad
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
WiredHome | 0:9b0b4ae5b47a | 1 | |
WiredHome | 0:9b0b4ae5b47a | 2 | #ifndef KEYPAD_H |
WiredHome | 0:9b0b4ae5b47a | 3 | #define KEYPAD_H |
WiredHome | 0:9b0b4ae5b47a | 4 | #include "mbed.h" |
WiredHome | 0:9b0b4ae5b47a | 5 | #include "RA8875.h" |
WiredHome | 0:9b0b4ae5b47a | 6 | |
WiredHome | 0:9b0b4ae5b47a | 7 | /// A QWERTY keypad, intended to be coupled with the touchscreen, provides |
WiredHome | 0:9b0b4ae5b47a | 8 | /// on-screen data entry. |
WiredHome | 0:9b0b4ae5b47a | 9 | /// |
WiredHome | 0:9b0b4ae5b47a | 10 | /// This keypad takes over the bottom of the screen to show an onscreen keyboard. |
WiredHome | 0:9b0b4ae5b47a | 11 | /// It shows a prompt, and allows basic text entry, including backspace. It does |
WiredHome | 0:9b0b4ae5b47a | 12 | /// not allow more complex editing. |
WiredHome | 0:9b0b4ae5b47a | 13 | /// |
WiredHome | 0:9b0b4ae5b47a | 14 | /// Since it takes over a significant chunk of the screen, the parent application |
WiredHome | 0:9b0b4ae5b47a | 15 | /// must be prepared to redraw the underlying data when the keyboard is no longer |
WiredHome | 0:9b0b4ae5b47a | 16 | /// in use. Alternately, the parent application may choose to select an |
WiredHome | 0:9b0b4ae5b47a | 17 | /// alternate display layer, and then activate the keypad. |
WiredHome | 0:9b0b4ae5b47a | 18 | /// |
WiredHome | 0:9b0b4ae5b47a | 19 | class Keypad { |
WiredHome | 0:9b0b4ae5b47a | 20 | public: |
WiredHome | 0:9b0b4ae5b47a | 21 | /// Instantiator the Keypad object. |
WiredHome | 0:9b0b4ae5b47a | 22 | /// |
WiredHome | 0:9b0b4ae5b47a | 23 | /// Shows a keypad like this: |
WiredHome | 0:9b0b4ae5b47a | 24 | /// @code |
WiredHome | 0:9b0b4ae5b47a | 25 | /// Prompt: [Input text field here.......] |
WiredHome | 0:9b0b4ae5b47a | 26 | /// `123456... |
WiredHome | 0:9b0b4ae5b47a | 27 | /// qwertyui... |
WiredHome | 0:9b0b4ae5b47a | 28 | /// asdfgh... |
WiredHome | 0:9b0b4ae5b47a | 29 | /// zxcvb.... |
WiredHome | 0:9b0b4ae5b47a | 30 | /// [ space ] 000/020 |
WiredHome | 0:9b0b4ae5b47a | 31 | /// @endcode |
WiredHome | 0:9b0b4ae5b47a | 32 | /// The bottom right corner shows how many characters have been entered and how |
WiredHome | 0:9b0b4ae5b47a | 33 | /// many are permitted. |
WiredHome | 0:9b0b4ae5b47a | 34 | /// |
WiredHome | 0:9b0b4ae5b47a | 35 | /// @param[in] _ra is a reference to the hosting applications RA8875 display |
WiredHome | 0:9b0b4ae5b47a | 36 | /// object. This grants Keypad access to the display. |
WiredHome | 0:9b0b4ae5b47a | 37 | /// @param[in] fore is the foreground color which is for the keys, prompt, text |
WiredHome | 0:9b0b4ae5b47a | 38 | /// @param[in] back is the background color. |
WiredHome | 0:9b0b4ae5b47a | 39 | /// |
WiredHome | 0:9b0b4ae5b47a | 40 | Keypad(RA8875 & _ra, color_t fore = Blue, color_t back = White); |
WiredHome | 0:9b0b4ae5b47a | 41 | |
WiredHome | 0:9b0b4ae5b47a | 42 | /// Destructor for the Keypad object. |
WiredHome | 0:9b0b4ae5b47a | 43 | /// |
WiredHome | 0:9b0b4ae5b47a | 44 | ~Keypad(); |
WiredHome | 0:9b0b4ae5b47a | 45 | |
WiredHome | 0:9b0b4ae5b47a | 46 | /// get a string of text entered on the onscreen keypad. |
WiredHome | 0:9b0b4ae5b47a | 47 | /// |
WiredHome | 0:9b0b4ae5b47a | 48 | /// text entry is terminated by <enter> or <esc>. |
WiredHome | 0:9b0b4ae5b47a | 49 | /// |
WiredHome | 0:9b0b4ae5b47a | 50 | /// @param[inout] buffer is the provided buffer into which the string is written. |
WiredHome | 0:9b0b4ae5b47a | 51 | /// @param[in] size is the size of the buffer. |
WiredHome | 0:9b0b4ae5b47a | 52 | /// @param[in] prompt is the optional text to prompt the user. |
WiredHome | 0:9b0b4ae5b47a | 53 | /// @param[in] mask is the optional character, if non-zero, that is used to obscure |
WiredHome | 0:9b0b4ae5b47a | 54 | /// the text entry - for password purposes. |
WiredHome | 0:9b0b4ae5b47a | 55 | /// @returns true if text was entered. |
WiredHome | 0:9b0b4ae5b47a | 56 | /// @returns false if text was not entered (e.g. <esc> pressed). |
WiredHome | 0:9b0b4ae5b47a | 57 | /// |
WiredHome | 0:9b0b4ae5b47a | 58 | bool GetString(char * buffer, size_t size, const char * prompt = NULL, char mask = 0); |
WiredHome | 0:9b0b4ae5b47a | 59 | |
WiredHome | 0:9b0b4ae5b47a | 60 | /// Erase the area where the keypad panel was drawn |
WiredHome | 0:9b0b4ae5b47a | 61 | /// |
WiredHome | 0:9b0b4ae5b47a | 62 | /// This API is usually not necessary, since the parent application will generally |
WiredHome | 0:9b0b4ae5b47a | 63 | /// redraw the screen after getting the text information. This might be more useful |
WiredHome | 0:9b0b4ae5b47a | 64 | /// if the Keypad is placed onto an alternate layer. |
WiredHome | 0:9b0b4ae5b47a | 65 | /// |
WiredHome | 0:9b0b4ae5b47a | 66 | /// @param[in] fillcolor is the color with which to fill the keyboard area. |
WiredHome | 0:9b0b4ae5b47a | 67 | /// |
WiredHome | 0:9b0b4ae5b47a | 68 | void Erase(color_t fillcolor = Black); |
WiredHome | 0:9b0b4ae5b47a | 69 | |
WiredHome | 0:9b0b4ae5b47a | 70 | private: |
WiredHome | 0:9b0b4ae5b47a | 71 | /// Draw a key in the specified rectangle. Invert the colors if desired. |
WiredHome | 0:9b0b4ae5b47a | 72 | /// |
WiredHome | 0:9b0b4ae5b47a | 73 | /// @param[in] r is the rectangle defining the key. |
WiredHome | 0:9b0b4ae5b47a | 74 | /// @param[in] c is the character to draw. |
WiredHome | 0:9b0b4ae5b47a | 75 | /// @param[in] invert is the optional parameter to cause the presentation to be inverted. |
WiredHome | 0:9b0b4ae5b47a | 76 | /// |
WiredHome | 0:9b0b4ae5b47a | 77 | void DrawKey(rect_t r, char c, bool invert = false); |
WiredHome | 0:9b0b4ae5b47a | 78 | |
WiredHome | 0:9b0b4ae5b47a | 79 | /// Draw the entire keypad |
WiredHome | 0:9b0b4ae5b47a | 80 | /// |
WiredHome | 0:9b0b4ae5b47a | 81 | void DrawKeypad(void); |
WiredHome | 0:9b0b4ae5b47a | 82 | |
WiredHome | 0:9b0b4ae5b47a | 83 | /// Draw the entire input panel which includes the prompt, edit area and keyboard. |
WiredHome | 0:9b0b4ae5b47a | 84 | /// |
WiredHome | 0:9b0b4ae5b47a | 85 | /// @param[in] prompt is the text string to print to hint to the user what you |
WiredHome | 0:9b0b4ae5b47a | 86 | /// want them to enter the text for. It is good to keep this very brief. |
WiredHome | 0:9b0b4ae5b47a | 87 | /// |
WiredHome | 0:9b0b4ae5b47a | 88 | void DrawInputPanel(const char * prompt); |
WiredHome | 0:9b0b4ae5b47a | 89 | |
WiredHome | 0:9b0b4ae5b47a | 90 | /// isKeyTouched scans the keyboard for the point of touch. If the touch is |
WiredHome | 0:9b0b4ae5b47a | 91 | /// within the constraints of a key, that key is identifed. |
WiredHome | 0:9b0b4ae5b47a | 92 | /// |
WiredHome | 0:9b0b4ae5b47a | 93 | /// This API optionally provides the rectangle from which the touch occurred. |
WiredHome | 0:9b0b4ae5b47a | 94 | /// |
WiredHome | 0:9b0b4ae5b47a | 95 | /// @param[in] point is a pointer to a point_t, containing the touch coordinates. |
WiredHome | 0:9b0b4ae5b47a | 96 | /// @param[inout] rectTouched is a pointer to a rect_t. If this pointer is not NULL, |
WiredHome | 0:9b0b4ae5b47a | 97 | /// it will be filled in with the rectangle within which the touch |
WiredHome | 0:9b0b4ae5b47a | 98 | /// was detected. |
WiredHome | 0:9b0b4ae5b47a | 99 | /// returns the character at that location on the keyboard, or zero, if no key |
WiredHome | 0:9b0b4ae5b47a | 100 | /// was touched. |
WiredHome | 0:9b0b4ae5b47a | 101 | /// |
WiredHome | 0:9b0b4ae5b47a | 102 | char isKeyTouched(point_t * point, rect_t * rectTouched = NULL); |
WiredHome | 0:9b0b4ae5b47a | 103 | |
WiredHome | 0:9b0b4ae5b47a | 104 | /// Show the current edit buffer metrics - number of characters and the limit. |
WiredHome | 0:9b0b4ae5b47a | 105 | /// |
WiredHome | 0:9b0b4ae5b47a | 106 | void ShowBufferMetrics(void); |
WiredHome | 0:9b0b4ae5b47a | 107 | |
WiredHome | 0:9b0b4ae5b47a | 108 | RA8875 & ra; |
WiredHome | 0:9b0b4ae5b47a | 109 | bool shift; |
WiredHome | 0:9b0b4ae5b47a | 110 | char * pStart; |
WiredHome | 0:9b0b4ae5b47a | 111 | char * pNext; |
WiredHome | 0:9b0b4ae5b47a | 112 | int bufSize; |
WiredHome | 0:9b0b4ae5b47a | 113 | point_t userText; |
WiredHome | 0:9b0b4ae5b47a | 114 | color_t fore; |
WiredHome | 0:9b0b4ae5b47a | 115 | color_t back; |
WiredHome | 0:9b0b4ae5b47a | 116 | }; |
WiredHome | 0:9b0b4ae5b47a | 117 | |
WiredHome | 0:9b0b4ae5b47a | 118 | #endif |