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:
- 7:dc29f6647486
- Parent:
- 6:aa51cc3b9f90
- Child:
- 9:fe2c9b3a312b
--- a/UI.cpp Tue Nov 10 22:39:50 2015 +0000 +++ b/UI.cpp Thu Nov 12 21:21:48 2015 +0000 @@ -1,48 +1,51 @@ #include "WakeupLight.h" -#include "Images/ic_alarm_white_48dp_1x.h" #include "Images/ic_navigate_before_white_24dp_1x.h" #include "Images/ic_notifications_none_white_48dp_1x.h" #include "Images/ic_query_builder_white_48dp_1x.h" -#define CLIENT_COLOR_BG ((uint32_t)0xFF000000) -#define CLIENT_COLOR_FG ((uint32_t)0xFFD0D0D0) +#define CLIENT_COLOR_BG ((uint32_t)0xFF000000) +#define CLIENT_COLOR_FG ((uint32_t)0xFFD0D0D0) -#define HEADER_HEIGHT 25 -#define HEADER_COLOR_BG ((uint32_t)0xFF404040) -#define HEADER_COLOR_FG ((uint32_t)0xFFD3D3D3) +#define HEADER_HEIGHT 25 +#define HEADER_COLOR_BG ((uint32_t)0xFF404040) +#define HEADER_COLOR_FG ((uint32_t)0xFFD3D3D3) + +#define CLOCK_COLOR_BG ((uint32_t)0xFF000000) +#define CLOCK_COLOR_FG ((uint32_t)0xFF707070) -#define CLOCK_COLOR_BG ((uint32_t)0xFF000000) -#define CLOCK_COLOR_FG ((uint32_t)0xFF707070) - -#define BUTTON_WIDTH 100 -#define BUTTON_HEIGHT 60 -#define BUTTON_COLOR_BG ((uint32_t)0x00000000) -#define BUTTON_COLOR_FG CLIENT_COLOR_FG -#define BUTTON_COLOR_BG_START 0x0C2696 -#define BUTTON_COLOR_BG_END 0x07185E - -#define COLOR_BG ((uint32_t)0xFF000000) +#define BUTTON_WIDTH 100 +#define BUTTON_HEIGHT 60 +#define BUTTON_SMALL_WIDTH 50 +#define BUTTON_SMALL_HEIGHT 40 +#define BUTTON_COLOR_BG ((uint32_t)0x00000000) +#define BUTTON_COLOR_FG CLIENT_COLOR_FG +#define BUTTON_COLOR_BG_START 0x0C2696 +#define BUTTON_COLOR_BG_END 0x07185E +#define BUTTON_COLOR_BG_START_INACTIVE 0x515151 +#define BUTTON_COLOR_BG_END_INACTIVE 0x333333 -#define MAX_BOXES_PER_LINE 3 -#define BOX_SPACING 10 -#define BOX_TEXT_SPACING 10 -#define BOX_COLOR_BG BUTTON_COLOR_BG -#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 COLOR_BG ((uint32_t)0xFF000000) + +#define MAX_BOXES_PER_LINE 3 +#define BOX_SPACING 10 +#define BOX_TEXT_SPACING 10 +#define BOX_COLOR_BG BUTTON_COLOR_BG +#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 -LCD_DISCO_F746NG uiLcd; -TS_DISCO_F746NG uiTs; -uint16_t uiLastTouchX; -uint16_t uiLastTouchY; -UI_STRUCT *uiCurrent=NULL; -UI_STRUCT uiClock; -UI_STRUCT uiClockInWords; -UI_STRUCT uiColorTest; -UI_STRUCT uiWakeup; -UI_STRUCT uiMain; -UI_BOX_LIST_ITEM_STRUCT uiMainItems[]= +LCD_DISCO_F746NG uiLcd; +TS_DISCO_F746NG uiTs; +uint16_t uiLastTouchX; +uint16_t uiLastTouchY; +UI_STRUCT *uiCurrent=NULL; +UI_STRUCT uiClock; +UI_STRUCT uiClockInWords; +UI_STRUCT uiColorTest; +UI_STRUCT uiWakeup; +UI_STRUCT uiMain; +static UI_BOX_LIST_ITEM_STRUCT uiMainItems[]= { { "Clock", ic_query_builder_white_48dp_1x }, { "Clock\nWith Words", ic_query_builder_white_48dp_1x }, { "Adjust\nTimers", ic_notifications_none_white_48dp_1x }, { "Lights On", NULL }, { "Lights Off", NULL }, { "Color Test", NULL } }; @@ -92,7 +95,7 @@ charWidth=uiLcd.GetFont()->Width; x+=((width-(strlen(text)*charWidth))/2); - y+=((height-charHeight)/2); + y+=(((height-charHeight)/2)+3); // +3 to have it more centered while ((*text)!='\0') { @@ -138,17 +141,25 @@ } } -void UI_ShowDrawButton(uint16_t x,uint16_t y,char *text) +void UI_ShowDrawButtonEx(uint16_t x,uint16_t y,uint16_t width,uint16_t height,char *text,bool active) { // paint button background - UI_ShowDrawGradientButton(x,y,BUTTON_WIDTH,BUTTON_HEIGHT,BUTTON_COLOR_BG_START,BUTTON_COLOR_BG_END); + if (active==true) + UI_ShowDrawGradientButton(x,y,width,height,BUTTON_COLOR_BG_START,BUTTON_COLOR_BG_END); + else + 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,BUTTON_WIDTH,BUTTON_HEIGHT,text); + UI_ShowDisplayTextCenter(x,y,width,height,text); +} + +void UI_ShowDrawButton(uint16_t x,uint16_t y,uint16_t width,uint16_t height,char *text) +{ + UI_ShowDrawButtonEx(x,y,width,height,text,true); } void UI_DrawBitmapWithAlpha(uint32_t Xpos,uint32_t Ypos,uint8_t *pbmp) @@ -272,8 +283,6 @@ // 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); -// uiLcd.DrawBitmap(0,0,uiCurrent->data.boxList.items[box].image); -// uiLcd.DrawBitmap(startX+width-BOX_SPACING-48,startY+height-BOX_SPACING-48,uiCurrent->data.boxList.items[box].image); } } } @@ -418,24 +427,82 @@ // fill background UI_ShowClearClientRect(); - if (uiCurrent->data.valueAdjust.count==4) + if (uiCurrent->data.valueAdjust.count==10) { - UI_ShowDrawButton(17+(0*(BUTTON_WIDTH+15)),40,"+"); - UI_ShowDrawButton(17+(1*(BUTTON_WIDTH+15)),40,"+"); - UI_ShowDrawButton(17+(2*(BUTTON_WIDTH+15)),40,"+"); - UI_ShowDrawButton(17+(3*(BUTTON_WIDTH+15)),40,"+"); + UI_ShowDrawButton(60+(0*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); + 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,92,BUTTON_WIDTH,BUTTON_HEIGHT,":"); - UI_ShowDrawButton(17+(0*(BUTTON_WIDTH+15)),205,"-"); - UI_ShowDrawButton(17+(1*(BUTTON_WIDTH+15)),205,"-"); - UI_ShowDrawButton(17+(2*(BUTTON_WIDTH+15)),205,"-"); - UI_ShowDrawButton(17+(3*(BUTTON_WIDTH+15)),205,"-"); + UI_ShowDrawButton(60+(0*(BUTTON_WIDTH+15)),140,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); + UI_ShowDrawButton(205+(0*(BUTTON_WIDTH+15)),140,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); + UI_ShowDrawButton(205+(1*(BUTTON_WIDTH+15)),140,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); + } + else if (uiCurrent->data.valueAdjust.count==4) + { + UI_ShowDrawButton(17+(0*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); + UI_ShowDrawButton(17+(1*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); + UI_ShowDrawButton(17+(2*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); + UI_ShowDrawButton(17+(3*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+"); + + UI_ShowDrawButton(17+(0*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); + UI_ShowDrawButton(17+(1*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); + UI_ShowDrawButton(17+(2*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); + UI_ShowDrawButton(17+(3*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-"); } } uiLcd.SetBackColor(CLIENT_COLOR_BG); uiLcd.SetTextColor(CLIENT_COLOR_FG); - if (uiCurrent->data.valueAdjust.count==4) + 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),"%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[2]); + UI_ShowDisplayTextCenter(205+(1*(BUTTON_WIDTH+15)),92,BUTTON_WIDTH,BUTTON_HEIGHT,buffer); + + if (uiCurrent->data.valueAdjust.values[3]==1) + UI_ShowDrawButton(17+(0*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Mo"); + else + UI_ShowDrawButtonEx(17+(0*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Mo",false); + + if (uiCurrent->data.valueAdjust.values[4]==1) + UI_ShowDrawButton(17+(1*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Di"); + else + UI_ShowDrawButtonEx(17+(1*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Di",false); + + if (uiCurrent->data.valueAdjust.values[5]==1) + UI_ShowDrawButton(17+(2*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Mi"); + else + UI_ShowDrawButtonEx(17+(2*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Mi",false); + + if (uiCurrent->data.valueAdjust.values[6]==1) + UI_ShowDrawButton(17+(3*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Do"); + else + UI_ShowDrawButtonEx(17+(3*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Do",false); + + if (uiCurrent->data.valueAdjust.values[7]==1) + UI_ShowDrawButton(17+(4*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Fr"); + else + UI_ShowDrawButtonEx(17+(4*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Fr",false); + + if (uiCurrent->data.valueAdjust.values[8]==1) + UI_ShowDrawButton(17+(5*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Sa"); + else + UI_ShowDrawButtonEx(17+(5*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"Sa",false); + + if (uiCurrent->data.valueAdjust.values[9]==1) + UI_ShowDrawButton(17+(6*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"So"); + else + UI_ShowDrawButtonEx(17+(6*(BUTTON_SMALL_WIDTH+15)),215,BUTTON_SMALL_WIDTH,BUTTON_SMALL_HEIGHT,"So",false); + } + 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); @@ -458,7 +525,45 @@ // detect at which button was clicked index=-1; - if (uiCurrent->data.valueAdjust.count==4) + if (uiCurrent->data.valueAdjust.count==10) + { + if ((y>=40) && (y<(40+BUTTON_HEIGHT))) + { + if ((x>=(60+(0*(BUTTON_WIDTH+15)))) && (x<(17+(0*(BUTTON_WIDTH+15))+BUTTON_WIDTH))) + index=0; + else if ((x>=(205+(0*(BUTTON_WIDTH+15)))) && (x<(205+(0*(BUTTON_WIDTH+15))+BUTTON_WIDTH))) + index=1; + else if ((x>=(205+(1*(BUTTON_WIDTH+15)))) && (x<(205+(1*(BUTTON_WIDTH+15))+BUTTON_WIDTH))) + index=2; + } + else if ((y>=140) && (y<(140+BUTTON_HEIGHT))) + { + if ((x>=(60+(0*(BUTTON_WIDTH+15)))) && (x<(60+(0*(BUTTON_WIDTH+15))+BUTTON_WIDTH))) + index=3; + else if ((x>=(205+(0*(BUTTON_WIDTH+15)))) && (x<(205+(0*(BUTTON_WIDTH+15))+BUTTON_WIDTH))) + index=4; + else if ((x>=(205+(1*(BUTTON_WIDTH+15)))) && (x<(205+(1*(BUTTON_WIDTH+15))+BUTTON_WIDTH))) + index=5; + } + else if ((y>=215) && (y<(215+BUTTON_SMALL_HEIGHT))) + { + if ((x>=(17+(0*(BUTTON_SMALL_WIDTH+15)))) && (x<(17+(0*(BUTTON_SMALL_WIDTH+15))+BUTTON_SMALL_WIDTH))) + index=6; + else if ((x>=(17+(1*(BUTTON_SMALL_WIDTH+15)))) && (x<(17+(1*(BUTTON_SMALL_WIDTH+15))+BUTTON_SMALL_WIDTH))) + index=7; + else if ((x>=(17+(2*(BUTTON_SMALL_WIDTH+15)))) && (x<(17+(2*(BUTTON_SMALL_WIDTH+15))+BUTTON_SMALL_WIDTH))) + index=8; + else if ((x>=(17+(3*(BUTTON_SMALL_WIDTH+15)))) && (x<(17+(3*(BUTTON_SMALL_WIDTH+15))+BUTTON_SMALL_WIDTH))) + index=9; + else if ((x>=(17+(4*(BUTTON_SMALL_WIDTH+15)))) && (x<(17+(4*(BUTTON_SMALL_WIDTH+15))+BUTTON_SMALL_WIDTH))) + index=10; + else if ((x>=(17+(5*(BUTTON_SMALL_WIDTH+15)))) && (x<(17+(5*(BUTTON_SMALL_WIDTH+15))+BUTTON_SMALL_WIDTH))) + index=11; + else if ((x>=(17+(6*(BUTTON_SMALL_WIDTH+15)))) && (x<(17+(6*(BUTTON_SMALL_WIDTH+15))+BUTTON_SMALL_WIDTH))) + index=12; + } + } + else if (uiCurrent->data.valueAdjust.count==4) { if ((y>=40) && (y<(40+BUTTON_HEIGHT))) { @@ -513,9 +618,6 @@ uiClockInWords.flags=UI_FLAG_TYPE_CLOCK_IN_WORDS; uiClockInWords.handler=NULL; - uiWakeup.flags=UI_FLAG_TYPE_BOX_LIST; - uiWakeup.handler=UI_WakeupHandler; - uiColorTest.flags=UI_FLAG_TYPE_VALUE_ADJUST; uiColorTest.handler=UI_ColorTestHandler; uiColorTest.data.valueAdjust.count=4;