Wakeup Light with touch user interface, anti-aliased Font, SD card access and RTC usage on STM32F746NG-DISCO board
Dependencies: BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src
UI.cpp@2:80026d18fcf3, 2015-10-29 (annotated)
- Committer:
- the_sz
- Date:
- Thu Oct 29 12:59:54 2015 +0000
- Revision:
- 2:80026d18fcf3
- Child:
- 3:ecf7f1f8d749
initial ui
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
the_sz | 2:80026d18fcf3 | 1 | #include "WakeupLight.h" |
the_sz | 2:80026d18fcf3 | 2 | |
the_sz | 2:80026d18fcf3 | 3 | #define CLIENT_COLOR_BG ((uint32_t)0xFF602020) |
the_sz | 2:80026d18fcf3 | 4 | #define CLIENT_COLOR_FG ((uint32_t)0xFFD0D0D0) |
the_sz | 2:80026d18fcf3 | 5 | |
the_sz | 2:80026d18fcf3 | 6 | #define HEADER_HEIGHT 25 |
the_sz | 2:80026d18fcf3 | 7 | #define HEADER_COLOR_BG ((uint32_t)0xFF404040) |
the_sz | 2:80026d18fcf3 | 8 | #define HEADER_COLOR_FG ((uint32_t)0xFFD3D3D3) |
the_sz | 2:80026d18fcf3 | 9 | |
the_sz | 2:80026d18fcf3 | 10 | #define CLOCK_COLOR_BG ((uint32_t)0xFF000000) |
the_sz | 2:80026d18fcf3 | 11 | #define CLOCK_COLOR_FG ((uint32_t)0xFF707070) |
the_sz | 2:80026d18fcf3 | 12 | |
the_sz | 2:80026d18fcf3 | 13 | #define COLOR_BG ((uint32_t)0xFF000000) |
the_sz | 2:80026d18fcf3 | 14 | |
the_sz | 2:80026d18fcf3 | 15 | LCD_DISCO_F746NG uiLcd; |
the_sz | 2:80026d18fcf3 | 16 | TS_DISCO_F746NG uiTs; |
the_sz | 2:80026d18fcf3 | 17 | int32_t uiCounter=0; |
the_sz | 2:80026d18fcf3 | 18 | UI_STRUCT *uiCurrent=NULL; |
the_sz | 2:80026d18fcf3 | 19 | |
the_sz | 2:80026d18fcf3 | 20 | // |
the_sz | 2:80026d18fcf3 | 21 | // helper function |
the_sz | 2:80026d18fcf3 | 22 | // |
the_sz | 2:80026d18fcf3 | 23 | void UI_ShowClearClientRect(void) |
the_sz | 2:80026d18fcf3 | 24 | { |
the_sz | 2:80026d18fcf3 | 25 | uiLcd.SetTextColor(CLIENT_COLOR_BG); |
the_sz | 2:80026d18fcf3 | 26 | uiLcd.FillRect(0,HEADER_HEIGHT,uiLcd.GetXSize()-1,uiLcd.GetYSize()-1); |
the_sz | 2:80026d18fcf3 | 27 | } |
the_sz | 2:80026d18fcf3 | 28 | |
the_sz | 2:80026d18fcf3 | 29 | // |
the_sz | 2:80026d18fcf3 | 30 | // box list |
the_sz | 2:80026d18fcf3 | 31 | // |
the_sz | 2:80026d18fcf3 | 32 | void UI_ShowBoxList(bool initial) |
the_sz | 2:80026d18fcf3 | 33 | { |
the_sz | 2:80026d18fcf3 | 34 | if (initial==true) |
the_sz | 2:80026d18fcf3 | 35 | { |
the_sz | 2:80026d18fcf3 | 36 | // fill background |
the_sz | 2:80026d18fcf3 | 37 | UI_ShowClearClientRect(); |
the_sz | 2:80026d18fcf3 | 38 | } |
the_sz | 2:80026d18fcf3 | 39 | } |
the_sz | 2:80026d18fcf3 | 40 | |
the_sz | 2:80026d18fcf3 | 41 | void UI_ClickBoxList(uint16_t x,uint16_t y) |
the_sz | 2:80026d18fcf3 | 42 | { |
the_sz | 2:80026d18fcf3 | 43 | // detect at which block was clicked |
the_sz | 2:80026d18fcf3 | 44 | } |
the_sz | 2:80026d18fcf3 | 45 | |
the_sz | 2:80026d18fcf3 | 46 | // |
the_sz | 2:80026d18fcf3 | 47 | // message box |
the_sz | 2:80026d18fcf3 | 48 | // |
the_sz | 2:80026d18fcf3 | 49 | void UI_ShowMessageBox(bool initial) |
the_sz | 2:80026d18fcf3 | 50 | { |
the_sz | 2:80026d18fcf3 | 51 | if (initial==true) |
the_sz | 2:80026d18fcf3 | 52 | { |
the_sz | 2:80026d18fcf3 | 53 | // fill background |
the_sz | 2:80026d18fcf3 | 54 | UI_ShowClearClientRect(); |
the_sz | 2:80026d18fcf3 | 55 | } |
the_sz | 2:80026d18fcf3 | 56 | } |
the_sz | 2:80026d18fcf3 | 57 | |
the_sz | 2:80026d18fcf3 | 58 | void UI_ClickMessageBox(uint16_t x,uint16_t y) |
the_sz | 2:80026d18fcf3 | 59 | { |
the_sz | 2:80026d18fcf3 | 60 | // detect at which button was clicked |
the_sz | 2:80026d18fcf3 | 61 | } |
the_sz | 2:80026d18fcf3 | 62 | |
the_sz | 2:80026d18fcf3 | 63 | // |
the_sz | 2:80026d18fcf3 | 64 | // clock |
the_sz | 2:80026d18fcf3 | 65 | // |
the_sz | 2:80026d18fcf3 | 66 | void UI_ShowClock(bool initial) |
the_sz | 2:80026d18fcf3 | 67 | { |
the_sz | 2:80026d18fcf3 | 68 | char buffer[100]; |
the_sz | 2:80026d18fcf3 | 69 | |
the_sz | 2:80026d18fcf3 | 70 | if (initial==true) |
the_sz | 2:80026d18fcf3 | 71 | { |
the_sz | 2:80026d18fcf3 | 72 | // fill background |
the_sz | 2:80026d18fcf3 | 73 | uiLcd.SetTextColor(CLOCK_COLOR_BG); |
the_sz | 2:80026d18fcf3 | 74 | uiLcd.FillRect(0,0,uiLcd.GetXSize()-1,uiLcd.GetYSize()-1); |
the_sz | 2:80026d18fcf3 | 75 | } |
the_sz | 2:80026d18fcf3 | 76 | |
the_sz | 2:80026d18fcf3 | 77 | // show clock |
the_sz | 2:80026d18fcf3 | 78 | uiLcd.SetFont(&display_font_12x22); |
the_sz | 2:80026d18fcf3 | 79 | uiLcd.SetBackColor(CLOCK_COLOR_BG); |
the_sz | 2:80026d18fcf3 | 80 | uiLcd.SetTextColor(CLOCK_COLOR_FG); |
the_sz | 2:80026d18fcf3 | 81 | snprintf(buffer,sizeof(buffer),"ABC %u",uiCounter); |
the_sz | 2:80026d18fcf3 | 82 | uiCounter++; |
the_sz | 2:80026d18fcf3 | 83 | uiLcd.DisplayStringAt(0,100,(uint8_t *)buffer,CENTER_MODE); |
the_sz | 2:80026d18fcf3 | 84 | } |
the_sz | 2:80026d18fcf3 | 85 | |
the_sz | 2:80026d18fcf3 | 86 | void UI_ClickClock(uint16_t x,uint16_t y) |
the_sz | 2:80026d18fcf3 | 87 | { |
the_sz | 2:80026d18fcf3 | 88 | // exit view |
the_sz | 2:80026d18fcf3 | 89 | } |
the_sz | 2:80026d18fcf3 | 90 | |
the_sz | 2:80026d18fcf3 | 91 | // |
the_sz | 2:80026d18fcf3 | 92 | // clock in words |
the_sz | 2:80026d18fcf3 | 93 | // |
the_sz | 2:80026d18fcf3 | 94 | void UI_ShowClockInWords(bool initial) |
the_sz | 2:80026d18fcf3 | 95 | { |
the_sz | 2:80026d18fcf3 | 96 | if (initial==true) |
the_sz | 2:80026d18fcf3 | 97 | { |
the_sz | 2:80026d18fcf3 | 98 | // fill background |
the_sz | 2:80026d18fcf3 | 99 | UI_ShowClearClientRect(); |
the_sz | 2:80026d18fcf3 | 100 | } |
the_sz | 2:80026d18fcf3 | 101 | |
the_sz | 2:80026d18fcf3 | 102 | // show clock in words |
the_sz | 2:80026d18fcf3 | 103 | uiLcd.SetFont(&display_font_12x22); |
the_sz | 2:80026d18fcf3 | 104 | uiLcd.SetBackColor(CLIENT_COLOR_BG); |
the_sz | 2:80026d18fcf3 | 105 | uiLcd.SetTextColor(CLIENT_COLOR_FG); |
the_sz | 2:80026d18fcf3 | 106 | uiLcd.DisplayStringAt(5,30,(uint8_t *)"UM F\x9ANF ZEHN VIERTEL HALB",LEFT_MODE); |
the_sz | 2:80026d18fcf3 | 107 | uiLcd.DisplayStringAt(5,60,(uint8_t *)"NACH VOR",LEFT_MODE); |
the_sz | 2:80026d18fcf3 | 108 | uiLcd.DisplayStringAt(5,90,(uint8_t *)"EINS ZWEI DREI VIER",LEFT_MODE); |
the_sz | 2:80026d18fcf3 | 109 | uiLcd.DisplayStringAt(5,120,(uint8_t *)"F\x9ANF SECHS SIEBEN ACHT",LEFT_MODE); |
the_sz | 2:80026d18fcf3 | 110 | uiLcd.DisplayStringAt(5,150,(uint8_t *)"NEUN ZEHN ELF ZW\x99LF",LEFT_MODE); |
the_sz | 2:80026d18fcf3 | 111 | |
the_sz | 2:80026d18fcf3 | 112 | // draw charset |
the_sz | 2:80026d18fcf3 | 113 | /* |
the_sz | 2:80026d18fcf3 | 114 | int x; |
the_sz | 2:80026d18fcf3 | 115 | for (x=0x80;x<=0xFF;x++) |
the_sz | 2:80026d18fcf3 | 116 | { |
the_sz | 2:80026d18fcf3 | 117 | uiLcd.DisplayChar(1+(((x-0x80) % 16)*14),30+(((x-0x80)/16)*20),x); |
the_sz | 2:80026d18fcf3 | 118 | } |
the_sz | 2:80026d18fcf3 | 119 | */ |
the_sz | 2:80026d18fcf3 | 120 | } |
the_sz | 2:80026d18fcf3 | 121 | |
the_sz | 2:80026d18fcf3 | 122 | void UI_ClickClockInWords(uint16_t x,uint16_t y) |
the_sz | 2:80026d18fcf3 | 123 | { |
the_sz | 2:80026d18fcf3 | 124 | // exit view |
the_sz | 2:80026d18fcf3 | 125 | } |
the_sz | 2:80026d18fcf3 | 126 | |
the_sz | 2:80026d18fcf3 | 127 | // |
the_sz | 2:80026d18fcf3 | 128 | // timer adjust |
the_sz | 2:80026d18fcf3 | 129 | // |
the_sz | 2:80026d18fcf3 | 130 | void UI_ShowTimerAdjust(bool initial) |
the_sz | 2:80026d18fcf3 | 131 | { |
the_sz | 2:80026d18fcf3 | 132 | if (initial==true) |
the_sz | 2:80026d18fcf3 | 133 | { |
the_sz | 2:80026d18fcf3 | 134 | // fill background |
the_sz | 2:80026d18fcf3 | 135 | UI_ShowClearClientRect(); |
the_sz | 2:80026d18fcf3 | 136 | } |
the_sz | 2:80026d18fcf3 | 137 | } |
the_sz | 2:80026d18fcf3 | 138 | |
the_sz | 2:80026d18fcf3 | 139 | void UI_ClickTimerAdjust(uint16_t x,uint16_t y) |
the_sz | 2:80026d18fcf3 | 140 | { |
the_sz | 2:80026d18fcf3 | 141 | // detect at which button was clicked |
the_sz | 2:80026d18fcf3 | 142 | } |
the_sz | 2:80026d18fcf3 | 143 | |
the_sz | 2:80026d18fcf3 | 144 | // |
the_sz | 2:80026d18fcf3 | 145 | // common |
the_sz | 2:80026d18fcf3 | 146 | // |
the_sz | 2:80026d18fcf3 | 147 | void UI_Init(void) |
the_sz | 2:80026d18fcf3 | 148 | { |
the_sz | 2:80026d18fcf3 | 149 | uiCurrent=NULL; |
the_sz | 2:80026d18fcf3 | 150 | |
the_sz | 2:80026d18fcf3 | 151 | uiLcd.Init(); |
the_sz | 2:80026d18fcf3 | 152 | uiLcd.Clear(COLOR_BG); |
the_sz | 2:80026d18fcf3 | 153 | |
the_sz | 2:80026d18fcf3 | 154 | if (uiTs.Init(uiLcd.GetXSize(),uiLcd.GetYSize())==TS_OK) |
the_sz | 2:80026d18fcf3 | 155 | DPrintf("UI_Init: Size: %ux%u.\r\n",uiLcd.GetXSize(),uiLcd.GetYSize()); |
the_sz | 2:80026d18fcf3 | 156 | else |
the_sz | 2:80026d18fcf3 | 157 | DPrintf("UI_Init: Can't init touch screen.\r\n"); |
the_sz | 2:80026d18fcf3 | 158 | } |
the_sz | 2:80026d18fcf3 | 159 | |
the_sz | 2:80026d18fcf3 | 160 | void UI_ShowChrome(bool initial) |
the_sz | 2:80026d18fcf3 | 161 | { |
the_sz | 2:80026d18fcf3 | 162 | char buffer[100]; |
the_sz | 2:80026d18fcf3 | 163 | |
the_sz | 2:80026d18fcf3 | 164 | if (initial==true) |
the_sz | 2:80026d18fcf3 | 165 | { |
the_sz | 2:80026d18fcf3 | 166 | // fill background |
the_sz | 2:80026d18fcf3 | 167 | uiLcd.SetTextColor(HEADER_COLOR_BG); |
the_sz | 2:80026d18fcf3 | 168 | uiLcd.FillRect(0,0,uiLcd.GetXSize()-1,HEADER_HEIGHT); |
the_sz | 2:80026d18fcf3 | 169 | } |
the_sz | 2:80026d18fcf3 | 170 | |
the_sz | 2:80026d18fcf3 | 171 | // show clock |
the_sz | 2:80026d18fcf3 | 172 | uiLcd.SetFont(&display_font_12x22); |
the_sz | 2:80026d18fcf3 | 173 | uiLcd.SetBackColor(HEADER_COLOR_BG); |
the_sz | 2:80026d18fcf3 | 174 | uiLcd.SetTextColor(HEADER_COLOR_FG); |
the_sz | 2:80026d18fcf3 | 175 | snprintf(buffer,sizeof(buffer),"ABC %u",uiCounter); |
the_sz | 2:80026d18fcf3 | 176 | uiCounter++; |
the_sz | 2:80026d18fcf3 | 177 | uiLcd.DisplayStringAt(0,3,(uint8_t *)buffer,CENTER_MODE); |
the_sz | 2:80026d18fcf3 | 178 | |
the_sz | 2:80026d18fcf3 | 179 | // show next alarm |
the_sz | 2:80026d18fcf3 | 180 | } |
the_sz | 2:80026d18fcf3 | 181 | |
the_sz | 2:80026d18fcf3 | 182 | void UI_Update(bool initial) |
the_sz | 2:80026d18fcf3 | 183 | { |
the_sz | 2:80026d18fcf3 | 184 | if ((uiCurrent->flags & UI_FLAG_NEEDS_CHROME)!=0) |
the_sz | 2:80026d18fcf3 | 185 | UI_ShowChrome(initial); |
the_sz | 2:80026d18fcf3 | 186 | |
the_sz | 2:80026d18fcf3 | 187 | if ((uiCurrent->flags & UI_FLAG_TYPE_BOX_LIST)!=0) |
the_sz | 2:80026d18fcf3 | 188 | UI_ShowBoxList(initial); |
the_sz | 2:80026d18fcf3 | 189 | else if ((uiCurrent->flags & UI_FLAG_TYPE_MESSAGE_BOX)!=0) |
the_sz | 2:80026d18fcf3 | 190 | UI_ShowMessageBox(initial); |
the_sz | 2:80026d18fcf3 | 191 | else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK)!=0) |
the_sz | 2:80026d18fcf3 | 192 | UI_ShowClock(initial); |
the_sz | 2:80026d18fcf3 | 193 | else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK_IN_WORDS)!=0) |
the_sz | 2:80026d18fcf3 | 194 | UI_ShowClockInWords(initial); |
the_sz | 2:80026d18fcf3 | 195 | else if ((uiCurrent->flags & UI_FLAG_TYPE_TIMER_ADJUST)!=0) |
the_sz | 2:80026d18fcf3 | 196 | UI_ShowTimerAdjust(initial); |
the_sz | 2:80026d18fcf3 | 197 | } |
the_sz | 2:80026d18fcf3 | 198 | |
the_sz | 2:80026d18fcf3 | 199 | void UI_Show(UI_STRUCT *ui) |
the_sz | 2:80026d18fcf3 | 200 | { |
the_sz | 2:80026d18fcf3 | 201 | uiCurrent=ui; |
the_sz | 2:80026d18fcf3 | 202 | |
the_sz | 2:80026d18fcf3 | 203 | UI_Update(true); |
the_sz | 2:80026d18fcf3 | 204 | } |
the_sz | 2:80026d18fcf3 | 205 | |
the_sz | 2:80026d18fcf3 | 206 | void UI_Click(uint16_t x,uint16_t y) |
the_sz | 2:80026d18fcf3 | 207 | { |
the_sz | 2:80026d18fcf3 | 208 | if ((uiCurrent->flags & UI_FLAG_TYPE_BOX_LIST)!=0) |
the_sz | 2:80026d18fcf3 | 209 | UI_ClickBoxList(x,y); |
the_sz | 2:80026d18fcf3 | 210 | else if ((uiCurrent->flags & UI_FLAG_TYPE_MESSAGE_BOX)!=0) |
the_sz | 2:80026d18fcf3 | 211 | UI_ClickMessageBox(x,y); |
the_sz | 2:80026d18fcf3 | 212 | else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK)!=0) |
the_sz | 2:80026d18fcf3 | 213 | UI_ClickClock(x,y); |
the_sz | 2:80026d18fcf3 | 214 | else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK_IN_WORDS)!=0) |
the_sz | 2:80026d18fcf3 | 215 | UI_ClickClockInWords(x,y); |
the_sz | 2:80026d18fcf3 | 216 | else if ((uiCurrent->flags & UI_FLAG_TYPE_TIMER_ADJUST)!=0) |
the_sz | 2:80026d18fcf3 | 217 | UI_ClickTimerAdjust(x,y); |
the_sz | 2:80026d18fcf3 | 218 | } |
the_sz | 2:80026d18fcf3 | 219 | |
the_sz | 2:80026d18fcf3 | 220 | void UI_Poll(void) |
the_sz | 2:80026d18fcf3 | 221 | { |
the_sz | 2:80026d18fcf3 | 222 | TS_StateTypeDef tsState; |
the_sz | 2:80026d18fcf3 | 223 | |
the_sz | 2:80026d18fcf3 | 224 | uiTs.GetState(&tsState); |
the_sz | 2:80026d18fcf3 | 225 | if (tsState.touchDetected>0) |
the_sz | 2:80026d18fcf3 | 226 | { |
the_sz | 2:80026d18fcf3 | 227 | DPrintf("UI_Poll: #%u - %ux%u.\r\n",tsState.touchDetected,tsState.touchX[0],tsState.touchY[0]); |
the_sz | 2:80026d18fcf3 | 228 | UI_Click(tsState.touchX[0],tsState.touchY[0]); |
the_sz | 2:80026d18fcf3 | 229 | } |
the_sz | 2:80026d18fcf3 | 230 | |
the_sz | 2:80026d18fcf3 | 231 | if (uiCurrent!=NULL) |
the_sz | 2:80026d18fcf3 | 232 | UI_Update(false); |
the_sz | 2:80026d18fcf3 | 233 | } |