School project.
Dependencies: Timezone NTPClient BSP_DISCO_F746NG Grove_temperature
lcd_functions.h@15:638e65c37d58, 2021-01-19 (annotated)
- Committer:
- tuxx0046
- Date:
- Tue Jan 19 10:05:13 2021 +0000
- Revision:
- 15:638e65c37d58
- Parent:
- 13:41debc0b9063
- Child:
- 16:296d68305630
Updated the main_functions and lcd_functions.; Connected all of the functions to have a working program.; Updated some comments and documentation.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tuxx0046 | 3:02e7aac23ff9 | 1 | /** |
tuxx0046 | 10:137cf2c92871 | 2 | @file lcd_functions.h |
tuxx0046 | 10:137cf2c92871 | 3 | @author Tu Tri Huynh |
tuxx0046 | 10:137cf2c92871 | 4 | @date January 13, 2021 |
tuxx0046 | 13:41debc0b9063 | 5 | @brief This file contains functions for the LCD display. The display is visually divided into four equal parts to output different things. |
tuxx0046 | 10:137cf2c92871 | 6 | @section Useful information |
tuxx0046 | 3:02e7aac23ff9 | 7 | LCD size is (480, 272) |
tuxx0046 | 10:137cf2c92871 | 8 | Available font sizes are Font8, Font12, Font16, Font20 or Font24 |
tuxx0046 | 10:137cf2c92871 | 9 | */ |
tuxx0046 | 3:02e7aac23ff9 | 10 | |
tuxx0046 | 3:02e7aac23ff9 | 11 | #include "stm32746g_discovery_lcd.h" |
tuxx0046 | 3:02e7aac23ff9 | 12 | |
tuxx0046 | 4:1a12157689a7 | 13 | /** |
tuxx0046 | 4:1a12157689a7 | 14 | This function will initialize the LCD for use |
tuxx0046 | 13:41debc0b9063 | 15 | 1/13/2021 |
tuxx0046 | 4:1a12157689a7 | 16 | */ |
tuxx0046 | 3:02e7aac23ff9 | 17 | void lcd_initialize() |
tuxx0046 | 3:02e7aac23ff9 | 18 | { |
tuxx0046 | 3:02e7aac23ff9 | 19 | BSP_LCD_Init(); |
tuxx0046 | 4:1a12157689a7 | 20 | BSP_LCD_LayerDefaultInit(LTDC_ACTIVE_LAYER, LCD_FB_START_ADDRESS); |
tuxx0046 | 4:1a12157689a7 | 21 | BSP_LCD_SelectLayer(LTDC_ACTIVE_LAYER); |
tuxx0046 | 4:1a12157689a7 | 22 | } |
tuxx0046 | 4:1a12157689a7 | 23 | |
tuxx0046 | 13:41debc0b9063 | 24 | |
tuxx0046 | 3:02e7aac23ff9 | 25 | |
tuxx0046 | 4:1a12157689a7 | 26 | /** |
tuxx0046 | 13:41debc0b9063 | 27 | This function will run a screen that tells user to configure the unit |
tuxx0046 | 13:41debc0b9063 | 28 | 1/13/2021 |
tuxx0046 | 4:1a12157689a7 | 29 | */ |
tuxx0046 | 4:1a12157689a7 | 30 | void lcd_show_setup_screen() |
tuxx0046 | 4:1a12157689a7 | 31 | { |
tuxx0046 | 4:1a12157689a7 | 32 | /// Clears the LCD with specified color |
tuxx0046 | 4:1a12157689a7 | 33 | BSP_LCD_Clear(LCD_COLOR_BLACK); |
tuxx0046 | 4:1a12157689a7 | 34 | BSP_LCD_SetBackColor(LCD_COLOR_BLACK); |
tuxx0046 | 4:1a12157689a7 | 35 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 4:1a12157689a7 | 36 | BSP_LCD_SetFont(&Font24); |
tuxx0046 | 4:1a12157689a7 | 37 | BSP_LCD_DisplayStringAt(0, 50, (uint8_t *)"SETUP", CENTER_MODE); |
tuxx0046 | 4:1a12157689a7 | 38 | BSP_LCD_SetFont(&Font16); |
tuxx0046 | 10:137cf2c92871 | 39 | BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)"Please configure the unit", CENTER_MODE); |
tuxx0046 | 4:1a12157689a7 | 40 | } |
tuxx0046 | 4:1a12157689a7 | 41 | |
tuxx0046 | 4:1a12157689a7 | 42 | /** |
tuxx0046 | 4:1a12157689a7 | 43 | This function will runs the startup screen with project- and developer-name |
tuxx0046 | 13:41debc0b9063 | 44 | 1/13/2021 |
tuxx0046 | 4:1a12157689a7 | 45 | */ |
tuxx0046 | 3:02e7aac23ff9 | 46 | void lcd_show_startup_screen() |
tuxx0046 | 3:02e7aac23ff9 | 47 | { |
tuxx0046 | 3:02e7aac23ff9 | 48 | BSP_LCD_Clear(LCD_COLOR_BLACK); |
tuxx0046 | 3:02e7aac23ff9 | 49 | BSP_LCD_SetBackColor(LCD_COLOR_BLACK); |
tuxx0046 | 3:02e7aac23ff9 | 50 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
tuxx0046 | 3:02e7aac23ff9 | 51 | BSP_LCD_DisplayStringAt(0, 100, (uint8_t *)"Light Control System", CENTER_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 52 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 53 | BSP_LCD_DisplayStringAt(0, 200, (uint8_t *)"by Tu Tri Huynh", CENTER_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 54 | HAL_Delay(3000); |
tuxx0046 | 3:02e7aac23ff9 | 55 | } |
tuxx0046 | 3:02e7aac23ff9 | 56 | |
tuxx0046 | 4:1a12157689a7 | 57 | /** |
tuxx0046 | 4:1a12157689a7 | 58 | Sets up the upper left part of screen |
tuxx0046 | 13:41debc0b9063 | 59 | 1/18/2021 |
tuxx0046 | 3:02e7aac23ff9 | 60 | */ |
tuxx0046 | 3:02e7aac23ff9 | 61 | void lcd_upper_left() |
tuxx0046 | 3:02e7aac23ff9 | 62 | { |
tuxx0046 | 13:41debc0b9063 | 63 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
tuxx0046 | 3:02e7aac23ff9 | 64 | BSP_LCD_FillRect(0, 0, 240, 136); |
tuxx0046 | 3:02e7aac23ff9 | 65 | } |
tuxx0046 | 3:02e7aac23ff9 | 66 | |
tuxx0046 | 13:41debc0b9063 | 67 | /** |
tuxx0046 | 13:41debc0b9063 | 68 | Update the content of the upper left part of display. |
tuxx0046 | 13:41debc0b9063 | 69 | 1/18/2021 |
tuxx0046 | 13:41debc0b9063 | 70 | */ |
tuxx0046 | 13:41debc0b9063 | 71 | void lcd_update_upper_left() |
tuxx0046 | 13:41debc0b9063 | 72 | { |
tuxx0046 | 15:638e65c37d58 | 73 | BSP_LCD_SetBackColor(LCD_COLOR_ORANGE); |
tuxx0046 | 15:638e65c37d58 | 74 | BSP_LCD_SetTextColor(LCD_COLOR_BLUE); |
tuxx0046 | 15:638e65c37d58 | 75 | BSP_LCD_SetFont(&Font24); |
tuxx0046 | 15:638e65c37d58 | 76 | BSP_LCD_DisplayStringAt(50, 55, (uint8_t *)"TIME HERE", LEFT_MODE); |
tuxx0046 | 13:41debc0b9063 | 77 | } |
tuxx0046 | 13:41debc0b9063 | 78 | |
tuxx0046 | 13:41debc0b9063 | 79 | /** |
tuxx0046 | 13:41debc0b9063 | 80 | Sets up the upper right part of display |
tuxx0046 | 13:41debc0b9063 | 81 | 1/18/2021 |
tuxx0046 | 13:41debc0b9063 | 82 | */ |
tuxx0046 | 3:02e7aac23ff9 | 83 | void lcd_upper_right() |
tuxx0046 | 3:02e7aac23ff9 | 84 | { |
tuxx0046 | 3:02e7aac23ff9 | 85 | BSP_LCD_SetBackColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 86 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 3:02e7aac23ff9 | 87 | BSP_LCD_FillRect(240, 0, 240, 136); |
tuxx0046 | 15:638e65c37d58 | 88 | BSP_LCD_SetBackColor(LCD_COLOR_WHITE); |
tuxx0046 | 15:638e65c37d58 | 89 | BSP_LCD_SetTextColor(LCD_COLOR_DARKYELLOW); |
tuxx0046 | 15:638e65c37d58 | 90 | BSP_LCD_SetFont(&Font20); |
tuxx0046 | 15:638e65c37d58 | 91 | BSP_LCD_DisplayStringAt(5, 16, (uint8_t *)"Light settings", RIGHT_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 92 | } |
tuxx0046 | 3:02e7aac23ff9 | 93 | |
tuxx0046 | 13:41debc0b9063 | 94 | /** Update the content of the upper right part of display. |
tuxx0046 | 15:638e65c37d58 | 95 | @param light_reading The intensity level of registered light in percentage |
tuxx0046 | 15:638e65c37d58 | 96 | @param rotary_reading The current position of rotary sensor in percentage |
tuxx0046 | 13:41debc0b9063 | 97 | 1/18/2021 |
tuxx0046 | 13:41debc0b9063 | 98 | */ |
tuxx0046 | 13:41debc0b9063 | 99 | void lcd_update_upper_right(int light_reading, int rotary_reading) |
tuxx0046 | 3:02e7aac23ff9 | 100 | { |
tuxx0046 | 15:638e65c37d58 | 101 | BSP_LCD_SetBackColor(LCD_COLOR_WHITE); |
tuxx0046 | 15:638e65c37d58 | 102 | BSP_LCD_SetTextColor(LCD_COLOR_DARKYELLOW); |
tuxx0046 | 4:1a12157689a7 | 103 | BSP_LCD_SetFont(&Font16); |
tuxx0046 | 15:638e65c37d58 | 104 | char light_to_lcd[30]; |
tuxx0046 | 15:638e65c37d58 | 105 | char rotary_to_lcd[30]; |
tuxx0046 | 15:638e65c37d58 | 106 | sprintf(light_to_lcd, "Light intensity: %3i%%", light_reading); |
tuxx0046 | 15:638e65c37d58 | 107 | sprintf(rotary_to_lcd, "Rotary turned: %3i%%", rotary_reading); |
tuxx0046 | 15:638e65c37d58 | 108 | |
tuxx0046 | 15:638e65c37d58 | 109 | BSP_LCD_DisplayStringAt(0, 46, (uint8_t *)light_to_lcd, RIGHT_MODE); |
tuxx0046 | 15:638e65c37d58 | 110 | BSP_LCD_DisplayStringAt(0, 70, (uint8_t *)rotary_to_lcd, RIGHT_MODE); |
tuxx0046 | 13:41debc0b9063 | 111 | } |
tuxx0046 | 13:41debc0b9063 | 112 | |
tuxx0046 | 13:41debc0b9063 | 113 | /** |
tuxx0046 | 13:41debc0b9063 | 114 | Sets up the lower left part of display |
tuxx0046 | 13:41debc0b9063 | 115 | 1/13/2021 |
tuxx0046 | 13:41debc0b9063 | 116 | */ |
tuxx0046 | 13:41debc0b9063 | 117 | void lcd_lower_left() |
tuxx0046 | 13:41debc0b9063 | 118 | { |
tuxx0046 | 13:41debc0b9063 | 119 | BSP_LCD_SetBackColor(LCD_COLOR_DARKMAGENTA); |
tuxx0046 | 13:41debc0b9063 | 120 | BSP_LCD_SetTextColor(LCD_COLOR_DARKMAGENTA); |
tuxx0046 | 13:41debc0b9063 | 121 | BSP_LCD_FillRect(0, 136, 240, 136); |
tuxx0046 | 13:41debc0b9063 | 122 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 13:41debc0b9063 | 123 | BSP_LCD_SetFont(&Font20); |
tuxx0046 | 13:41debc0b9063 | 124 | BSP_LCD_DisplayStringAt(5, 160, (uint8_t *)"Location", LEFT_MODE); |
tuxx0046 | 3:02e7aac23ff9 | 125 | } |
tuxx0046 | 3:02e7aac23ff9 | 126 | |
tuxx0046 | 13:41debc0b9063 | 127 | /** |
tuxx0046 | 13:41debc0b9063 | 128 | Updates the content of the lower left area of the display |
tuxx0046 | 13:41debc0b9063 | 129 | @building[] Name of the building |
tuxx0046 | 13:41debc0b9063 | 130 | @room[] Name of the room |
tuxx0046 | 13:41debc0b9063 | 131 | 1/18/2021 |
tuxx0046 | 13:41debc0b9063 | 132 | */ |
tuxx0046 | 13:41debc0b9063 | 133 | void lcd_update_lower_left(char building[], char room[]) |
tuxx0046 | 13:41debc0b9063 | 134 | { |
tuxx0046 | 13:41debc0b9063 | 135 | BSP_LCD_SetBackColor(LCD_COLOR_DARKMAGENTA); |
tuxx0046 | 13:41debc0b9063 | 136 | BSP_LCD_SetTextColor(LCD_COLOR_WHITE); |
tuxx0046 | 13:41debc0b9063 | 137 | BSP_LCD_SetFont(&Font12); |
tuxx0046 | 13:41debc0b9063 | 138 | BSP_LCD_DisplayStringAt(35, 200, (uint8_t *)building, LEFT_MODE); |
tuxx0046 | 13:41debc0b9063 | 139 | BSP_LCD_DisplayStringAt(35, 220, (uint8_t *)room, LEFT_MODE); |
tuxx0046 | 13:41debc0b9063 | 140 | } |
tuxx0046 | 13:41debc0b9063 | 141 | |
tuxx0046 | 13:41debc0b9063 | 142 | /** |
tuxx0046 | 13:41debc0b9063 | 143 | Sets up the lower right part of display |
tuxx0046 | 13:41debc0b9063 | 144 | 1/18/2021 |
tuxx0046 | 13:41debc0b9063 | 145 | */ |
tuxx0046 | 3:02e7aac23ff9 | 146 | void lcd_lower_right() |
tuxx0046 | 3:02e7aac23ff9 | 147 | { |
tuxx0046 | 3:02e7aac23ff9 | 148 | BSP_LCD_SetTextColor(LCD_COLOR_CYAN); |
tuxx0046 | 3:02e7aac23ff9 | 149 | BSP_LCD_FillRect(240, 136, 240, 136); |
tuxx0046 | 13:41debc0b9063 | 150 | BSP_LCD_SetBackColor(LCD_COLOR_CYAN); |
tuxx0046 | 13:41debc0b9063 | 151 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
tuxx0046 | 13:41debc0b9063 | 152 | BSP_LCD_SetFont(&Font20); |
tuxx0046 | 13:41debc0b9063 | 153 | BSP_LCD_DisplayStringAt(5, 160, (uint8_t *)"Temperature", RIGHT_MODE); |
tuxx0046 | 13:41debc0b9063 | 154 | } |
tuxx0046 | 13:41debc0b9063 | 155 | |
tuxx0046 | 13:41debc0b9063 | 156 | /** Update the content of the lower right part of display. |
tuxx0046 | 15:638e65c37d58 | 157 | @param temp The temperature reading from the thermal sensor |
tuxx0046 | 15:638e65c37d58 | 158 | @param is_fahrenheit The bool value to determine if temperature unit should switch to fahrenheit or not |
tuxx0046 | 13:41debc0b9063 | 159 | 1/18/2021 |
tuxx0046 | 13:41debc0b9063 | 160 | */ |
tuxx0046 | 13:41debc0b9063 | 161 | void lcd_update_lower_right(float temp, bool is_fahrenheit) |
tuxx0046 | 13:41debc0b9063 | 162 | { |
tuxx0046 | 13:41debc0b9063 | 163 | char temp_text[30]; |
tuxx0046 | 13:41debc0b9063 | 164 | if (is_fahrenheit == true) |
tuxx0046 | 13:41debc0b9063 | 165 | { |
tuxx0046 | 13:41debc0b9063 | 166 | float fahrenheit = helper_convert_celsius_to_fahrenheit(temp); |
tuxx0046 | 13:41debc0b9063 | 167 | sprintf(temp_text, "%3.0f F", fahrenheit); |
tuxx0046 | 13:41debc0b9063 | 168 | } |
tuxx0046 | 13:41debc0b9063 | 169 | else |
tuxx0046 | 13:41debc0b9063 | 170 | { |
tuxx0046 | 13:41debc0b9063 | 171 | sprintf(temp_text, "%2.0f C", temp); |
tuxx0046 | 13:41debc0b9063 | 172 | } |
tuxx0046 | 13:41debc0b9063 | 173 | BSP_LCD_SetBackColor(LCD_COLOR_CYAN); |
tuxx0046 | 13:41debc0b9063 | 174 | BSP_LCD_SetTextColor(LCD_COLOR_ORANGE); |
tuxx0046 | 13:41debc0b9063 | 175 | BSP_LCD_SetFont(&Font24); |
tuxx0046 | 13:41debc0b9063 | 176 | BSP_LCD_DisplayStringAt(35, 210, (uint8_t *)temp_text, RIGHT_MODE); |
tuxx0046 | 13:41debc0b9063 | 177 | BSP_LCD_DrawCircle(421, 214, 3); |
tuxx0046 | 3:02e7aac23ff9 | 178 | } |
tuxx0046 | 3:02e7aac23ff9 | 179 | |
tuxx0046 | 3:02e7aac23ff9 | 180 | // Shows the main screen |
tuxx0046 | 3:02e7aac23ff9 | 181 | void lcd_show_main_screen() |
tuxx0046 | 3:02e7aac23ff9 | 182 | { |
tuxx0046 | 3:02e7aac23ff9 | 183 | BSP_LCD_Clear(LCD_COLOR_DARKBLUE); // Clear with color |
tuxx0046 | 3:02e7aac23ff9 | 184 | lcd_upper_left(); |
tuxx0046 | 15:638e65c37d58 | 185 | lcd_lower_left(); |
tuxx0046 | 15:638e65c37d58 | 186 | lcd_upper_right(); |
tuxx0046 | 3:02e7aac23ff9 | 187 | lcd_lower_right(); |
tuxx0046 | 13:41debc0b9063 | 188 | } |
tuxx0046 | 13:41debc0b9063 | 189 | |
tuxx0046 | 13:41debc0b9063 | 190 | /** |
tuxx0046 | 13:41debc0b9063 | 191 | This function will print LCD size in console terminal |
tuxx0046 | 13:41debc0b9063 | 192 | @date 1/13/2021 |
tuxx0046 | 13:41debc0b9063 | 193 | */ |
tuxx0046 | 13:41debc0b9063 | 194 | void lcd_get_screen_size() |
tuxx0046 | 13:41debc0b9063 | 195 | { |
tuxx0046 | 13:41debc0b9063 | 196 | printf("LCD X size : %zu\n\r",BSP_LCD_GetXSize()); //result: 480 |
tuxx0046 | 13:41debc0b9063 | 197 | printf("LCD Y size : %zu\n\r",BSP_LCD_GetYSize()); //result: 272 |
tuxx0046 | 3:02e7aac23ff9 | 198 | } |