David Smart / Keypad

Dependents:   RA8875_KeyPadDemo PUB_RA8875_Keypad IAC_Final_Monil_copy

Revision:
0:9b0b4ae5b47a
Child:
1:7feeebbd8367
diff -r 000000000000 -r 9b0b4ae5b47a Keypad.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Keypad.h	Mon Feb 08 02:38:43 2016 +0000
@@ -0,0 +1,118 @@
+
+#ifndef KEYPAD_H
+#define KEYPAD_H
+#include "mbed.h"
+#include "RA8875.h"
+
+/// A QWERTY keypad, intended to be coupled with the touchscreen, provides
+/// on-screen data entry.
+///
+/// This keypad takes over the bottom of the screen to show an onscreen keyboard.
+/// It shows a prompt, and allows basic text entry, including backspace. It does
+/// not allow more complex editing.
+///
+/// Since it takes over a significant chunk of the screen, the parent application
+/// must be prepared to redraw the underlying data when the keyboard is no longer
+/// in use. Alternately, the parent application may choose to select an 
+/// alternate display layer, and then activate the keypad.
+///
+class Keypad {
+public:
+    /// Instantiator the Keypad object.
+    ///
+    /// Shows a keypad like this:
+    /// @code
+    /// Prompt: [Input text field here.......]
+    /// `123456...
+    ///  qwertyui...
+    ///   asdfgh...
+    ///    zxcvb....
+    ///           [ space   ]         000/020
+    /// @endcode
+    /// The bottom right corner shows how many characters have been entered and how
+    /// many are permitted.
+    ///
+    /// @param[in] _ra is a reference to the hosting applications RA8875 display
+    ///            object. This grants Keypad access to the display.
+    /// @param[in] fore is the foreground color which is for the keys, prompt, text
+    /// @param[in] back is the background color.
+    ///
+    Keypad(RA8875 & _ra, color_t fore = Blue, color_t back = White);
+    
+    /// Destructor for the Keypad object.
+    ///
+    ~Keypad();
+
+    /// get a string of text entered on the onscreen keypad.
+    ///
+    /// text entry is terminated by <enter> or <esc>.
+    ///
+    /// @param[inout] buffer is the provided buffer into which the string is written.
+    /// @param[in] size is the size of the buffer.
+    /// @param[in] prompt is the optional text to prompt the user.
+    /// @param[in] mask is the optional character, if non-zero, that is used to obscure
+    ///            the text entry - for password purposes.
+    /// @returns true if text was entered.
+    /// @returns false if text was not entered (e.g. <esc> pressed).
+    ///
+    bool GetString(char * buffer, size_t size, const char * prompt = NULL, char mask = 0);
+
+    /// Erase the area where the keypad panel was drawn
+    /// 
+    /// This API is usually not necessary, since the parent application will generally
+    /// redraw the screen after getting the text information. This might be more useful
+    /// if the Keypad is placed onto an alternate layer.
+    ///
+    /// @param[in] fillcolor is the color with which to fill the keyboard area.
+    ///
+    void Erase(color_t fillcolor = Black);
+
+private:
+    /// Draw a key in the specified rectangle. Invert the colors if desired.
+    ///
+    /// @param[in] r is the rectangle defining the key.
+    /// @param[in] c is the character to draw.
+    /// @param[in] invert is the optional parameter to cause the presentation to be inverted.
+    ///
+    void DrawKey(rect_t r, char c, bool invert = false);
+
+    /// Draw the entire keypad
+    ///
+    void DrawKeypad(void);
+    
+    /// Draw the entire input panel which includes the prompt, edit area and keyboard.
+    ///
+    /// @param[in] prompt is the text string to print to hint to the user what you
+    ///            want them to enter the text for. It is good to keep this very brief.
+    ///
+    void DrawInputPanel(const char * prompt);
+
+    /// isKeyTouched scans the keyboard for the point of touch. If the touch is
+    /// within the constraints of a key, that key is identifed.
+    ///
+    /// This API optionally provides the rectangle from which the touch occurred.
+    ///
+    /// @param[in] point is a pointer to a point_t, containing the touch coordinates.
+    /// @param[inout] rectTouched is a pointer to a rect_t. If this pointer is not NULL,
+    ///               it will be filled in with the rectangle within which the touch
+    ///               was detected.
+    /// returns the character at that location on the keyboard, or zero, if no key
+    ///         was touched.
+    ///
+    char isKeyTouched(point_t * point, rect_t * rectTouched = NULL);
+
+    /// Show the current edit buffer metrics - number of characters and the limit.
+    ///
+    void ShowBufferMetrics(void);
+
+    RA8875 & ra;
+    bool shift;
+    char * pStart;
+    char * pNext;
+    int bufSize;
+    point_t userText;
+    color_t fore;
+    color_t back;
+};
+
+#endif
\ No newline at end of file