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
Diff: UI.cpp
- Revision:
- 13:811a5c5b3fd6
- Parent:
- 12:a89096944f20
- Child:
- 14:2044ad5cd3fe
diff -r a89096944f20 -r 811a5c5b3fd6 UI.cpp --- a/UI.cpp Sun Jan 31 01:02:36 2016 +0000 +++ b/UI.cpp Sun Jan 31 17:45:50 2016 +0000 @@ -9,21 +9,27 @@ #include "Images/ic_equalizer_white_48dp_1x.h" #include "Images/ic_settings_white_48dp_1x.h" +#define DEFAULT_FONT &lucidaSansUnicode_18ptFontInfo + #define CLIENT_COLOR_BG ((uint32_t)0xFF000000) #define CLIENT_COLOR_FG ((uint32_t)0xFFD0D0D0) +#define CLIENT_FONT DEFAULT_FONT #define HEADER_HEIGHT 25 #define HEADER_COLOR_BG ((uint32_t)0xFF404040) #define HEADER_COLOR_FG ((uint32_t)0xFFD3D3D3) +#define HEADER_FONT DEFAULT_FONT #define CLOCK_COLOR_BG ((uint32_t)0xFF000000) #define CLOCK_COLOR_FG ((uint32_t)0xFF707070) +#define CLOCK_FONT DEFAULT_FONT #define SLIDESHOW_COLOR_BG ((uint32_t)0xFF000000) #define SLIDESHOW_COLOR_FG ((uint32_t)0xFF707070) #define SLIDESHOW_TRANSPARENCY 128 #define SLIDESHOW_FADE_STEP 5 #define SLIDESHOW_TIMEOUT 15 +#define SLIDESHOW_FONT DEFAULT_FONT #define BUTTON_WIDTH 100 #define BUTTON_HEIGHT 60 @@ -35,6 +41,7 @@ #define BUTTON_COLOR_BG_END 0x07185E #define BUTTON_COLOR_BG_START_INACTIVE 0x515151 #define BUTTON_COLOR_BG_END_INACTIVE 0x333333 +#define BUTTON_FONT DEFAULT_FONT #define COLOR_BG ((uint32_t)0xFF000000) @@ -45,6 +52,7 @@ #define BOX_COLOR_FG CLIENT_COLOR_FG #define BOX_COLOR_BG_START BUTTON_COLOR_BG_START #define BOX_COLOR_BG_END BUTTON_COLOR_BG_END +#define BOX_FONT DEFAULT_FONT LCD_DISCO_F746NG uiLcd; TS_DISCO_F746NG uiTs; @@ -72,51 +80,34 @@ uiLcd.FillRect(0,HEADER_HEIGHT,uiLcd.GetXSize(),uiLcd.GetYSize()-HEADER_HEIGHT); } -void UI_ShowDisplayText(int16_t x,int16_t y,char *text) +void UI_ShowDisplayText(int16_t x,int16_t y,char *text,const FONT_INFO *pFont,uint32_t colorText,uint32_t colorBack) { int16_t xStart; - int16_t charWidth; - int16_t charHeight; xStart=x; - charHeight=uiLcd.GetFont()->Height+3; - charWidth=uiLcd.GetFont()->Width; - + while ((*text)!='\0') { if ((*text)=='\n') { - y+=charHeight; + y+=FontX_GetHeight(pFont); x=xStart; } else { - uiLcd.DisplayChar(x,y,*text); - x+=charWidth; + x+=FontX_DisplayChar(x,y,*text,pFont,colorText,colorBack); } text++; } } -void UI_ShowDisplayTextCenter(int16_t x,int16_t y,int16_t width,int16_t height,char *text) +void UI_ShowDisplayTextCenter(int16_t x,int16_t y,int16_t width,int16_t height,char *text,const FONT_INFO *pFont,uint32_t colorText,uint32_t colorBack) { - int16_t charWidth; - int16_t charHeight; - - charHeight=uiLcd.GetFont()->Height+3; - charWidth=uiLcd.GetFont()->Width; + if (height!=-1) + y+=(height-FontX_GetHeight(pFont))/2; - x+=((width-(strlen(text)*charWidth))/2); - y+=(((height-charHeight)/2)+3); // +3 to have it more centered - - while ((*text)!='\0') - { - uiLcd.DisplayChar(x,y,*text); - x+=charWidth; - - text++; - } + FontX_DisplayStringAt(x,y,width,text,ALIGN_CENTER,pFont,colorText,colorBack); } void UI_ShowDrawGradientButton(uint16_t x,uint16_t y,uint16_t width,uint16_t height,uint32_t colorStart,uint32_t colorEnd) @@ -163,11 +154,7 @@ UI_ShowDrawGradientButton(x,y,width,height,BUTTON_COLOR_BG_START_INACTIVE,BUTTON_COLOR_BG_END_INACTIVE); // paint button text - uiLcd.SetFont(&display_font_12x22); - uiLcd.SetBackColor(BUTTON_COLOR_BG); - uiLcd.SetTextColor(BUTTON_COLOR_FG); - - UI_ShowDisplayTextCenter(x,y,width,height,text); + UI_ShowDisplayTextCenter(x,y,width,height,text,BUTTON_FONT,BUTTON_COLOR_FG,BUTTON_COLOR_BG); } void UI_ShowDrawButton(uint16_t x,uint16_t y,uint16_t width,uint16_t height,char *text) @@ -288,11 +275,8 @@ UI_ShowDrawGradientButton(startX,startY,width-BOX_SPACING,height-BOX_SPACING,BOX_COLOR_BG_START,BOX_COLOR_BG_END); // paint box text - uiLcd.SetFont(&display_font_12x22); - uiLcd.SetBackColor(BOX_COLOR_BG); - uiLcd.SetTextColor(BOX_COLOR_FG); - UI_ShowDisplayText(startX+BOX_TEXT_SPACING,startY+BOX_TEXT_SPACING,uiCurrent->data.boxList.items[box].name); - + UI_ShowDisplayText(startX+BOX_TEXT_SPACING,startY+BOX_TEXT_SPACING,uiCurrent->data.boxList.items[box].name,BOX_FONT,BOX_COLOR_FG,BOX_COLOR_BG); + // draw icon if (uiCurrent->data.boxList.items[box].image!=NULL) UI_DrawBitmapWithAlpha(startX+width-BOX_SPACING-48,startY+height-BOX_SPACING-48,uiCurrent->data.boxList.items[box].image); @@ -353,12 +337,10 @@ } // show clock - uiLcd.SetFont(&display_font_12x22); - uiLcd.SetBackColor(CLOCK_COLOR_BG); - uiLcd.SetTextColor(CLOCK_COLOR_FG); RTC_Get(&tmStruct); - snprintf(buffer,sizeof(buffer),"%u:%02u:%02u",tmStruct->tm_hour,tmStruct->tm_min,tmStruct->tm_sec); - uiLcd.DisplayStringAt(0,100,(uint8_t *)buffer,CENTER_MODE); + snprintf(buffer,sizeof(buffer)," %u:%02u:%02u ",tmStruct->tm_hour,tmStruct->tm_min,tmStruct->tm_sec); + + UI_ShowDisplayTextCenter(0,100,uiLcd.GetXSize(),-1,buffer,CLOCK_FONT,CLOCK_COLOR_FG,CLOCK_COLOR_BG); } void UI_ClickClock(uint16_t x,uint16_t y) @@ -379,21 +361,18 @@ } // show clock in words - uiLcd.SetFont(&display_font_12x22); - uiLcd.SetBackColor(CLIENT_COLOR_BG); - uiLcd.SetTextColor(CLIENT_COLOR_FG); - uiLcd.DisplayStringAt(5,30,(uint8_t *)"UM F\x9ANF ZEHN VIERTEL HALB",LEFT_MODE); - uiLcd.DisplayStringAt(5,60,(uint8_t *)"NACH VOR",LEFT_MODE); - uiLcd.DisplayStringAt(5,90,(uint8_t *)"EINS ZWEI DREI VIER",LEFT_MODE); - uiLcd.DisplayStringAt(5,120,(uint8_t *)"F\x9ANF SECHS SIEBEN ACHT",LEFT_MODE); - uiLcd.DisplayStringAt(5,150,(uint8_t *)"NEUN ZEHN ELF ZW\x99LF",LEFT_MODE); + UI_ShowDisplayText(5,30,"UM F\x9ANF ZEHN VIERTEL HALB",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); + UI_ShowDisplayText(5,60,"NACH VOR",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); + UI_ShowDisplayText(5,90,"EINS ZWEI DREI VIER",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); + UI_ShowDisplayText(5,120,"F\x9ANF SECHS SIEBEN ACHT",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); + UI_ShowDisplayText(5,150,"NEUN ZEHN ELF ZW\x99LF",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); + /* // draw charset - /* int x; - for (x=0x80;x<=0xFF;x++) + for (x=0x0;x<=0x7f;x++) { - uiLcd.DisplayChar(1+(((x-0x80) % 16)*14),30+(((x-0x80)/16)*20),x); + FontX_DisplayChar(1+(((x-0x0) % 16)*14),30+(((x-0x0)/16)*20),x,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); } */ } @@ -457,11 +436,8 @@ uiLcd.FillRect(0,0,uiLcd.GetXSize(),uiLcd.GetYSize()); // show clock - uiLcd.SetFont(&display_font_12x22); - uiLcd.SetBackColor(0x00000000); - uiLcd.SetTextColor(SLIDESHOW_COLOR_FG); snprintf(buffer,sizeof(buffer),"%u:%02u",tmStruct->tm_hour,tmStruct->tm_min); - uiLcd.DisplayStringAt(30,220,(uint8_t *)buffer,RIGHT_MODE); + FontX_DisplayStringAt(30,220,uiLcd.GetXSize(),buffer,ALIGN_RIGHT,SLIDESHOW_FONT,SLIDESHOW_COLOR_FG,0x00000000); // hide picture layer if (initial==true) @@ -509,7 +485,7 @@ UI_ShowDrawButton(205+(1*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); if (uiCurrent->data.valueAdjust.isTime==true) - UI_ShowDisplayTextCenter(132,92,BUTTON_WIDTH,BUTTON_HEIGHT,":"); + UI_ShowDisplayTextCenter(132,92,BUTTON_WIDTH,BUTTON_HEIGHT,":",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); UI_ShowDrawButton(60+(0*(BUTTON_WIDTH+15)),140,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); UI_ShowDrawButton(205+(0*(BUTTON_WIDTH+15)),140,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); @@ -535,7 +511,7 @@ UI_ShowDrawButton(205+(0*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); UI_ShowDrawButton(205+(1*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); - UI_ShowDisplayTextCenter(132,125,BUTTON_WIDTH,BUTTON_HEIGHT,":"); + UI_ShowDisplayTextCenter(132,125,BUTTON_WIDTH,BUTTON_HEIGHT,":",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); UI_ShowDrawButton(60+(0*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); UI_ShowDrawButton(205+(0*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); @@ -547,8 +523,8 @@ UI_ShowDrawButton(74+(1*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); UI_ShowDrawButton(74+(2*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); - UI_ShowDisplayTextCenter(130,125,BUTTON_WIDTH,BUTTON_HEIGHT,"."); - UI_ShowDisplayTextCenter(246,125,BUTTON_WIDTH,BUTTON_HEIGHT,"."); + UI_ShowDisplayTextCenter(130,125,BUTTON_WIDTH,BUTTON_HEIGHT,".",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); + UI_ShowDisplayTextCenter(246,125,BUTTON_WIDTH,BUTTON_HEIGHT,".",CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); UI_ShowDrawButton(74+(0*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); UI_ShowDrawButton(74+(1*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); @@ -557,19 +533,16 @@ } } - uiLcd.SetBackColor(CLIENT_COLOR_BG); - uiLcd.SetTextColor(CLIENT_COLOR_FG); - if (uiCurrent->data.valueAdjust.count==10) { - snprintf(buffer,sizeof(buffer),"% 2u",uiCurrent->data.valueAdjust.values[0]); - UI_ShowDisplayTextCenter(60+(0*(BUTTON_WIDTH+15)),92,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[0]); + UI_ShowDisplayTextCenter(60+(0*(BUTTON_WIDTH+15)),92,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer),"%u",uiCurrent->data.valueAdjust.values[1]); - UI_ShowDisplayTextCenter(205+(0*(BUTTON_WIDTH+15)),92,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," %u ",uiCurrent->data.valueAdjust.values[1]); + UI_ShowDisplayTextCenter(205+(0*(BUTTON_WIDTH+15)),92,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer),"%u",uiCurrent->data.valueAdjust.values[2]); - UI_ShowDisplayTextCenter(205+(1*(BUTTON_WIDTH+15)),92,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," %u ",uiCurrent->data.valueAdjust.values[2]); + UI_ShowDisplayTextCenter(205+(1*(BUTTON_WIDTH+15)),92,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); if (uiCurrent->data.valueAdjust.values[3]==1) UI_ShowDrawButton(17+(0*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Mo"); @@ -608,41 +581,41 @@ } else if (uiCurrent->data.valueAdjust.count==4) { - snprintf(buffer,sizeof(buffer),"0x%02X",uiCurrent->data.valueAdjust.values[0]); - UI_ShowDisplayTextCenter(17+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," 0x%02X ",uiCurrent->data.valueAdjust.values[0]); + UI_ShowDisplayTextCenter(17+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer),"0x%02X",uiCurrent->data.valueAdjust.values[1]); - UI_ShowDisplayTextCenter(17+(1*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," 0x%02X ",uiCurrent->data.valueAdjust.values[1]); + UI_ShowDisplayTextCenter(17+(1*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer),"0x%02X",uiCurrent->data.valueAdjust.values[2]); - UI_ShowDisplayTextCenter(17+(2*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," 0x%02X ",uiCurrent->data.valueAdjust.values[2]); + UI_ShowDisplayTextCenter(17+(2*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer),"0x%02X",uiCurrent->data.valueAdjust.values[3]); - UI_ShowDisplayTextCenter(17+(3*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," 0x%02X ",uiCurrent->data.valueAdjust.values[3]); + UI_ShowDisplayTextCenter(17+(3*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); } else if (uiCurrent->data.valueAdjust.count==3) { if (uiCurrent->data.valueAdjust.isTime==true) { - snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[0]); - UI_ShowDisplayTextCenter(60+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[0]); + UI_ShowDisplayTextCenter(60+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[1]); - UI_ShowDisplayTextCenter(205+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[1]); + UI_ShowDisplayTextCenter(205+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[2]); - UI_ShowDisplayTextCenter(205+(1*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[2]); + UI_ShowDisplayTextCenter(205+(1*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); } else { - snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[0]); - UI_ShowDisplayTextCenter(74+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[0]); + UI_ShowDisplayTextCenter(74+(0*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[1]); - UI_ShowDisplayTextCenter(74+(1*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," % 2u ",uiCurrent->data.valueAdjust.values[1]); + UI_ShowDisplayTextCenter(74+(1*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); - snprintf(buffer,sizeof(buffer)," %02u ",uiCurrent->data.valueAdjust.values[2]); - UI_ShowDisplayTextCenter(74+(2*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + snprintf(buffer,sizeof(buffer)," %02u ",uiCurrent->data.valueAdjust.values[2]); + UI_ShowDisplayTextCenter(74+(2*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer,CLIENT_FONT,CLIENT_COLOR_FG,CLIENT_COLOR_BG); } } } @@ -824,20 +797,14 @@ uiLcd.SetTextColor(HEADER_COLOR_BG); uiLcd.FillRect(0,0,uiLcd.GetXSize(),HEADER_HEIGHT); - uiLcd.SetFont(&display_font_12x22); - uiLcd.SetBackColor(HEADER_COLOR_BG); - uiLcd.SetTextColor(HEADER_COLOR_FG); if ((uiCurrent->flags & UI_FLAG_HAS_BACK_BUTTON)!=0) UI_DrawBitmapWithAlpha(0,1,ic_navigate_before_white_24dp_1x); } // show clock - uiLcd.SetFont(&display_font_12x22); - uiLcd.SetBackColor(HEADER_COLOR_BG); - uiLcd.SetTextColor(HEADER_COLOR_FG); RTC_Get(&tmStruct); - snprintf(buffer,sizeof(buffer),"%u:%02u",tmStruct->tm_hour,tmStruct->tm_min); - uiLcd.DisplayStringAt(0,3,(uint8_t *)buffer,CENTER_MODE); + snprintf(buffer,sizeof(buffer)," %u:%02u ",tmStruct->tm_hour,tmStruct->tm_min); + UI_ShowDisplayTextCenter(0,0,uiLcd.GetXSize(),-1,buffer,HEADER_FONT,HEADER_COLOR_FG,HEADER_COLOR_BG); // show next alarm //XXX