lcd lib
Dependencies: mbed LCD_DISCO_F469NI TS_DISCO_F469NI BSP_DISCO_F469NI EasyCAT_lib
F469GUI/F469_SLIDER.hpp@4:186727e0bdea, 2022-04-25 (annotated)
- Committer:
- haddad1995
- Date:
- Mon Apr 25 12:22:12 2022 +0000
- Revision:
- 4:186727e0bdea
- Parent:
- 0:ebf3f36f3a64
update;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wsteenberg | 0:ebf3f36f3a64 | 1 | /*----------------------------------------------------------- |
wsteenberg | 0:ebf3f36f3a64 | 2 | * F469_SLIDER Library v1.0 |
wsteenberg | 0:ebf3f36f3a64 | 3 | * Copyright (c) 2018 Wynand Steenberg |
wsteenberg | 0:ebf3f36f3a64 | 4 | * s216875730@mandela.ac.za |
wsteenberg | 0:ebf3f36f3a64 | 5 | * |
wsteenberg | 0:ebf3f36f3a64 | 6 | * |
wsteenberg | 0:ebf3f36f3a64 | 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
wsteenberg | 0:ebf3f36f3a64 | 8 | * of this software and associated documentation files (the "Software"), to deal |
wsteenberg | 0:ebf3f36f3a64 | 9 | * in the Software without restriction, including without limitation the rights |
wsteenberg | 0:ebf3f36f3a64 | 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
wsteenberg | 0:ebf3f36f3a64 | 11 | * copies of the Software, and to permit persons to whom the Software is |
wsteenberg | 0:ebf3f36f3a64 | 12 | * furnished to do so, subject to the following conditions: |
wsteenberg | 0:ebf3f36f3a64 | 13 | * |
wsteenberg | 0:ebf3f36f3a64 | 14 | * The above copyright notice and this permission notice shall be included in |
wsteenberg | 0:ebf3f36f3a64 | 15 | * all copies or substantial portions of the Software. |
wsteenberg | 0:ebf3f36f3a64 | 16 | * |
wsteenberg | 0:ebf3f36f3a64 | 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
wsteenberg | 0:ebf3f36f3a64 | 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
wsteenberg | 0:ebf3f36f3a64 | 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
wsteenberg | 0:ebf3f36f3a64 | 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
wsteenberg | 0:ebf3f36f3a64 | 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
wsteenberg | 0:ebf3f36f3a64 | 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
wsteenberg | 0:ebf3f36f3a64 | 23 | * THE SOFTWARE. |
wsteenberg | 0:ebf3f36f3a64 | 24 | *----------------------------------------------------------- |
wsteenberg | 0:ebf3f36f3a64 | 25 | */ |
wsteenberg | 0:ebf3f36f3a64 | 26 | |
wsteenberg | 0:ebf3f36f3a64 | 27 | #ifndef F469_SLIDER_HPP |
wsteenberg | 0:ebf3f36f3a64 | 28 | #define F469_SLIDER_HPP |
wsteenberg | 0:ebf3f36f3a64 | 29 | |
wsteenberg | 0:ebf3f36f3a64 | 30 | #include "mbed.h" |
wsteenberg | 0:ebf3f36f3a64 | 31 | #include <string> |
wsteenberg | 0:ebf3f36f3a64 | 32 | #include "TS_DISCO_F469NI.h" |
wsteenberg | 0:ebf3f36f3a64 | 33 | #include "LCD_DISCO_F469NI.h" |
wsteenberg | 0:ebf3f36f3a64 | 34 | #include "F469GUI.hpp" |
wsteenberg | 0:ebf3f36f3a64 | 35 | |
wsteenberg | 0:ebf3f36f3a64 | 36 | /** A Class library for using Sliders on the DISCO-F469NI Development board. The class |
wsteenberg | 0:ebf3f36f3a64 | 37 | * uses the existing BSP class created by Team ST. |
wsteenberg | 0:ebf3f36f3a64 | 38 | * |
wsteenberg | 0:ebf3f36f3a64 | 39 | * Example: |
wsteenberg | 0:ebf3f36f3a64 | 40 | * @code |
wsteenberg | 0:ebf3f36f3a64 | 41 | * #include "mbed.h" |
wsteenberg | 0:ebf3f36f3a64 | 42 | * #include "F469_SLIDER.hpp" |
wsteenberg | 0:ebf3f36f3a64 | 43 | * |
wsteenberg | 0:ebf3f36f3a64 | 44 | * DigitalOut led_green(LED1); |
wsteenberg | 0:ebf3f36f3a64 | 45 | * DigitalOut led_orange(LED2); |
wsteenberg | 0:ebf3f36f3a64 | 46 | * DigitalOut led_red(LED3); |
wsteenberg | 0:ebf3f36f3a64 | 47 | * DigitalOut led_blue(LED4); |
wsteenberg | 0:ebf3f36f3a64 | 48 | * |
wsteenberg | 0:ebf3f36f3a64 | 49 | * TS_DISCO_F469NI ts_; |
wsteenberg | 0:ebf3f36f3a64 | 50 | * LCD_DISCO_F469NI lcd_; |
wsteenberg | 0:ebf3f36f3a64 | 51 | * |
wsteenberg | 0:ebf3f36f3a64 | 52 | * |
wsteenberg | 0:ebf3f36f3a64 | 53 | * char char_SliderDisplayValue[4]; // String Value to display for the Slider Control value |
wsteenberg | 0:ebf3f36f3a64 | 54 | * uint16_t SliderDisplayValue_; // Variable used to access Slider Control Value in F469SLIDER.cpp |
wsteenberg | 0:ebf3f36f3a64 | 55 | * |
wsteenberg | 0:ebf3f36f3a64 | 56 | * int main() |
wsteenberg | 0:ebf3f36f3a64 | 57 | * { |
wsteenberg | 0:ebf3f36f3a64 | 58 | * led_green = 1; // Switch off all LEDs |
wsteenberg | 0:ebf3f36f3a64 | 59 | * led_orange = 1; |
wsteenberg | 0:ebf3f36f3a64 | 60 | * led_red = 1; |
wsteenberg | 0:ebf3f36f3a64 | 61 | * led_blue = 1; |
wsteenberg | 0:ebf3f36f3a64 | 62 | * |
wsteenberg | 0:ebf3f36f3a64 | 63 | * lcd_.Clear(LCD_COLOR_WHITE); // Set LCD Background colour |
wsteenberg | 0:ebf3f36f3a64 | 64 | * |
wsteenberg | 0:ebf3f36f3a64 | 65 | * Slider sld1(lcd_, ts_, 20, 350, 220, 40, 5, 1, 20, |
wsteenberg | 0:ebf3f36f3a64 | 66 | * LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 1, "Slider1", Font20); // Define sld1 slider |
wsteenberg | 0:ebf3f36f3a64 | 67 | * sld1.Render(); // Draw sld1 Slider |
wsteenberg | 0:ebf3f36f3a64 | 68 | * |
wsteenberg | 0:ebf3f36f3a64 | 69 | * Slider Slider2(lcd_, ts_, 300, 350, 300, 40, 50, 1, 100, |
wsteenberg | 0:ebf3f36f3a64 | 70 | * LCD_COLOR_BLUE, LCD_COLOR_YELLOW, 2, "Slider2", Font20); // Define Slider2 slider |
wsteenberg | 0:ebf3f36f3a64 | 71 | * Slider2.Render(); // Draw Slider2 Slider |
wsteenberg | 0:ebf3f36f3a64 | 72 | * |
wsteenberg | 0:ebf3f36f3a64 | 73 | * lcd_.SetTextColor(LCD_COLOR_BLACK); // Set Text colour to Black |
wsteenberg | 0:ebf3f36f3a64 | 74 | * lcd_.SetFont(&Font20); // Font size 20 |
wsteenberg | 0:ebf3f36f3a64 | 75 | * lcd_.DisplayStringAt(5, 5, (uint8_t *)"Slider driver for DISCO_F469", LEFT_MODE); // Display main header text |
wsteenberg | 0:ebf3f36f3a64 | 76 | * |
wsteenberg | 0:ebf3f36f3a64 | 77 | * while (true) // Main program loop |
wsteenberg | 0:ebf3f36f3a64 | 78 | * { |
wsteenberg | 0:ebf3f36f3a64 | 79 | * led_green = 1; // Switch off all LEDs |
wsteenberg | 0:ebf3f36f3a64 | 80 | * led_orange = 1; |
wsteenberg | 0:ebf3f36f3a64 | 81 | * led_red = 1; |
wsteenberg | 0:ebf3f36f3a64 | 82 | * led_blue = 1; |
wsteenberg | 0:ebf3f36f3a64 | 83 | * |
wsteenberg | 0:ebf3f36f3a64 | 84 | * if (sld1.Moved()) // Check if sld1 Slider was touched and run instructions if true |
wsteenberg | 0:ebf3f36f3a64 | 85 | * { |
wsteenberg | 0:ebf3f36f3a64 | 86 | * led_blue = 0; |
wsteenberg | 0:ebf3f36f3a64 | 87 | * lcd_.SetTextColor(LCD_COLOR_BLACK); |
wsteenberg | 0:ebf3f36f3a64 | 88 | * lcd_.FillRect(85, 265, 80, 40); // Draw border to display Slider Control Value |
wsteenberg | 0:ebf3f36f3a64 | 89 | * lcd_.SetTextColor(LCD_COLOR_WHITE); |
wsteenberg | 0:ebf3f36f3a64 | 90 | * lcd_.FillRect(95, 270, 60, 30); // Draw border to display Slider Control Value |
wsteenberg | 0:ebf3f36f3a64 | 91 | * |
wsteenberg | 0:ebf3f36f3a64 | 92 | * sprintf(char_SliderDisplayValue, "%3d", (int) SliderDisplayValue_); // Convert integer to text |
wsteenberg | 0:ebf3f36f3a64 | 93 | * lcd_.SetFont(&Font16); // Set Font size |
wsteenberg | 0:ebf3f36f3a64 | 94 | * lcd_.SetTextColor(LCD_COLOR_BLACK); // Set Font colour |
wsteenberg | 0:ebf3f36f3a64 | 95 | * lcd_.DisplayStringAt(100, 280, (uint8_t *)char_SliderDisplayValue, LEFT_MODE); // Write Slider Control Value to the LCD |
wsteenberg | 0:ebf3f36f3a64 | 96 | * |
wsteenberg | 0:ebf3f36f3a64 | 97 | * if (SliderDisplayValue_ < 10) // Slider Control Value decision |
wsteenberg | 0:ebf3f36f3a64 | 98 | * { |
wsteenberg | 0:ebf3f36f3a64 | 99 | * lcd_.DisplayStringAt(60, 330, (uint8_t *)" ", LEFT_MODE); // Overwrite previous text |
wsteenberg | 0:ebf3f36f3a64 | 100 | * lcd_.DisplayStringAt(60, 330, (uint8_t *)"SLIDER1 < 50%", LEFT_MODE); // Write text to LCD |
wsteenberg | 0:ebf3f36f3a64 | 101 | * } |
wsteenberg | 0:ebf3f36f3a64 | 102 | * else if (SliderDisplayValue_ == 10) // Slider Control Value decision |
wsteenberg | 0:ebf3f36f3a64 | 103 | * { |
wsteenberg | 0:ebf3f36f3a64 | 104 | * lcd_.DisplayStringAt(60, 330, (uint8_t *)" ", LEFT_MODE); // Overwrite previous text |
wsteenberg | 0:ebf3f36f3a64 | 105 | * lcd_.DisplayStringAt(60, 330, (uint8_t *)"SLIDER1 = 50%", LEFT_MODE); // Write text to LCD |
wsteenberg | 0:ebf3f36f3a64 | 106 | * } |
wsteenberg | 0:ebf3f36f3a64 | 107 | * else // Slider Control Value decision |
wsteenberg | 0:ebf3f36f3a64 | 108 | * { |
wsteenberg | 0:ebf3f36f3a64 | 109 | * lcd_.DisplayStringAt(60, 330, (uint8_t *)" ", LEFT_MODE); // Overwrite previous text |
wsteenberg | 0:ebf3f36f3a64 | 110 | * lcd_.DisplayStringAt(60, 330, (uint8_t *)"SLIDER1 > 50%", LEFT_MODE); // Write text to LCD |
wsteenberg | 0:ebf3f36f3a64 | 111 | * } |
wsteenberg | 0:ebf3f36f3a64 | 112 | * } // End sld1 instructions |
wsteenberg | 0:ebf3f36f3a64 | 113 | * |
wsteenberg | 0:ebf3f36f3a64 | 114 | * if (Slider2.Moved()) // Check if Slider2 Slider was touched and run instructions if true |
wsteenberg | 0:ebf3f36f3a64 | 115 | * { |
wsteenberg | 0:ebf3f36f3a64 | 116 | * led_green = 0; |
wsteenberg | 0:ebf3f36f3a64 | 117 | * lcd_.SetTextColor(LCD_COLOR_BLACK); |
wsteenberg | 0:ebf3f36f3a64 | 118 | * lcd_.FillRect(400, 265, 80, 40); // Draw border to display Slider Control Value |
wsteenberg | 0:ebf3f36f3a64 | 119 | * lcd_.SetTextColor(LCD_COLOR_WHITE); |
wsteenberg | 0:ebf3f36f3a64 | 120 | * lcd_.FillRect(410, 270, 60, 30); // Draw border to display Slider Control Value |
wsteenberg | 0:ebf3f36f3a64 | 121 | * |
wsteenberg | 0:ebf3f36f3a64 | 122 | * sprintf(char_SliderDisplayValue, "%3d", (int) SliderDisplayValue_); // Convert integer to text |
wsteenberg | 0:ebf3f36f3a64 | 123 | * lcd_.SetFont(&Font16); // Set Font size |
wsteenberg | 0:ebf3f36f3a64 | 124 | * lcd_.SetTextColor(LCD_COLOR_BLACK); // Set Font colour |
wsteenberg | 0:ebf3f36f3a64 | 125 | * lcd_.DisplayStringAt(415, 280, (uint8_t *)char_SliderDisplayValue, LEFT_MODE); // Write Slider Control Value to the LCD |
wsteenberg | 0:ebf3f36f3a64 | 126 | * } |
wsteenberg | 0:ebf3f36f3a64 | 127 | * |
wsteenberg | 0:ebf3f36f3a64 | 128 | * wait(0.02f); |
wsteenberg | 0:ebf3f36f3a64 | 129 | * } // End Main program loop |
wsteenberg | 0:ebf3f36f3a64 | 130 | * } // End Main program |
wsteenberg | 0:ebf3f36f3a64 | 131 | * @endcode |
wsteenberg | 0:ebf3f36f3a64 | 132 | */ |
wsteenberg | 0:ebf3f36f3a64 | 133 | |
wsteenberg | 0:ebf3f36f3a64 | 134 | class Slider |
wsteenberg | 0:ebf3f36f3a64 | 135 | { |
wsteenberg | 0:ebf3f36f3a64 | 136 | public: |
wsteenberg | 0:ebf3f36f3a64 | 137 | //! Constructor |
wsteenberg | 0:ebf3f36f3a64 | 138 | Slider(LCD_DISCO_F469NI &lcd, TS_DISCO_F469NI &ts, |
wsteenberg | 0:ebf3f36f3a64 | 139 | uint16_t x, uint16_t y, uint16_t width, uint16_t height, |
wsteenberg | 0:ebf3f36f3a64 | 140 | uint16_t value_C, uint16_t min, uint16_t max, |
wsteenberg | 0:ebf3f36f3a64 | 141 | uint32_t sliderColour, uint32_t changeColour, |
wsteenberg | 0:ebf3f36f3a64 | 142 | int style, const string label = "", sFONT &fonts = Font12, |
wsteenberg | 0:ebf3f36f3a64 | 143 | uint32_t textColour = LCD_COLOR_WHITE) |
wsteenberg | 0:ebf3f36f3a64 | 144 | : lcd_(lcd), ts_(ts), SliderX_(x), SliderY_(y), SliderW_(width), SliderH_(height), |
wsteenberg | 0:ebf3f36f3a64 | 145 | valueControl_(value_C), Min_ (min), Max_ (max), |
wsteenberg | 0:ebf3f36f3a64 | 146 | SLIDER_COLOUR_(sliderColour), CHANGE_COLOUR_(changeColour), |
wsteenberg | 0:ebf3f36f3a64 | 147 | STYLE_(style), LABEL_(label), FONTS_(&fonts), FONT_WIDTH_(fonts.Width), |
wsteenberg | 0:ebf3f36f3a64 | 148 | FONT_HEIGHT_(fonts.Height), active_(true) |
wsteenberg | 0:ebf3f36f3a64 | 149 | { Render(); } |
wsteenberg | 0:ebf3f36f3a64 | 150 | |
wsteenberg | 0:ebf3f36f3a64 | 151 | /** |
wsteenberg | 0:ebf3f36f3a64 | 152 | * @brief Draw Slider. |
wsteenberg | 0:ebf3f36f3a64 | 153 | * |
wsteenberg | 0:ebf3f36f3a64 | 154 | */ |
wsteenberg | 0:ebf3f36f3a64 | 155 | void Render(); |
wsteenberg | 0:ebf3f36f3a64 | 156 | |
wsteenberg | 0:ebf3f36f3a64 | 157 | /** |
wsteenberg | 0:ebf3f36f3a64 | 158 | * @brief Service Slider. |
wsteenberg | 0:ebf3f36f3a64 | 159 | * |
wsteenberg | 0:ebf3f36f3a64 | 160 | */ |
wsteenberg | 0:ebf3f36f3a64 | 161 | void Service(); |
wsteenberg | 0:ebf3f36f3a64 | 162 | |
wsteenberg | 0:ebf3f36f3a64 | 163 | /** |
wsteenberg | 0:ebf3f36f3a64 | 164 | * @brief Check touch detected on Slider. |
wsteenberg | 0:ebf3f36f3a64 | 165 | * |
wsteenberg | 0:ebf3f36f3a64 | 166 | */ |
wsteenberg | 0:ebf3f36f3a64 | 167 | bool Moved(); |
wsteenberg | 0:ebf3f36f3a64 | 168 | |
wsteenberg | 0:ebf3f36f3a64 | 169 | /** |
wsteenberg | 0:ebf3f36f3a64 | 170 | * @brief Check if touch is on Slider. |
wsteenberg | 0:ebf3f36f3a64 | 171 | * |
wsteenberg | 0:ebf3f36f3a64 | 172 | */ |
wsteenberg | 0:ebf3f36f3a64 | 173 | bool SliderBoundaryCheck(); |
wsteenberg | 0:ebf3f36f3a64 | 174 | |
wsteenberg | 0:ebf3f36f3a64 | 175 | /** |
wsteenberg | 0:ebf3f36f3a64 | 176 | * @brief Check previous state of Slider. |
wsteenberg | 0:ebf3f36f3a64 | 177 | * |
wsteenberg | 0:ebf3f36f3a64 | 178 | */ |
wsteenberg | 0:ebf3f36f3a64 | 179 | static TS_StateTypeDef GottenState() |
wsteenberg | 0:ebf3f36f3a64 | 180 | { return state_; } |
wsteenberg | 0:ebf3f36f3a64 | 181 | |
wsteenberg | 0:ebf3f36f3a64 | 182 | /** |
wsteenberg | 0:ebf3f36f3a64 | 183 | * @brief Set or reset multi-touch. |
wsteenberg | 0:ebf3f36f3a64 | 184 | * |
wsteenberg | 0:ebf3f36f3a64 | 185 | */ |
wsteenberg | 0:ebf3f36f3a64 | 186 | static void SetMultiTouch(bool tf) { multiTouch = tf; } |
wsteenberg | 0:ebf3f36f3a64 | 187 | |
wsteenberg | 0:ebf3f36f3a64 | 188 | |
wsteenberg | 0:ebf3f36f3a64 | 189 | private: |
wsteenberg | 0:ebf3f36f3a64 | 190 | LCD_DISCO_F469NI &lcd_; |
wsteenberg | 0:ebf3f36f3a64 | 191 | TS_DISCO_F469NI &ts_; |
wsteenberg | 0:ebf3f36f3a64 | 192 | |
wsteenberg | 0:ebf3f36f3a64 | 193 | const uint16_t SliderX_, SliderY_, SliderW_, SliderH_, valueControl_, Min_, Max_; |
wsteenberg | 0:ebf3f36f3a64 | 194 | const uint32_t SLIDER_COLOUR_; // original color |
wsteenberg | 0:ebf3f36f3a64 | 195 | const uint32_t CHANGE_COLOUR_; // colour to change to color |
wsteenberg | 0:ebf3f36f3a64 | 196 | const int STYLE_; // Slider style |
wsteenberg | 0:ebf3f36f3a64 | 197 | const string LABEL_; // Slider label |
wsteenberg | 0:ebf3f36f3a64 | 198 | sFONT *const FONTS_; |
wsteenberg | 0:ebf3f36f3a64 | 199 | const uint16_t FONT_WIDTH_; |
wsteenberg | 0:ebf3f36f3a64 | 200 | const uint16_t FONT_HEIGHT_; |
wsteenberg | 0:ebf3f36f3a64 | 201 | bool active_; // Slider active boolean |
wsteenberg | 0:ebf3f36f3a64 | 202 | |
wsteenberg | 0:ebf3f36f3a64 | 203 | static TS_StateTypeDef state_; |
wsteenberg | 0:ebf3f36f3a64 | 204 | static bool multiTouch; |
wsteenberg | 0:ebf3f36f3a64 | 205 | |
wsteenberg | 0:ebf3f36f3a64 | 206 | /** |
wsteenberg | 0:ebf3f36f3a64 | 207 | * @brief Disallow copy constructor and assignment operator. |
wsteenberg | 0:ebf3f36f3a64 | 208 | * |
wsteenberg | 0:ebf3f36f3a64 | 209 | */ |
wsteenberg | 0:ebf3f36f3a64 | 210 | Slider(const Slider&); |
wsteenberg | 0:ebf3f36f3a64 | 211 | Slider& operator=(const Slider&); |
wsteenberg | 0:ebf3f36f3a64 | 212 | }; |
wsteenberg | 0:ebf3f36f3a64 | 213 | #endif // F469_SLIDER_HPP |