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

Revision:
12:a89096944f20
Parent:
11:3c6366ea1021
Child:
13:811a5c5b3fd6
--- a/UI.cpp	Mon Nov 16 23:29:15 2015 +0000
+++ b/UI.cpp	Sun Jan 31 01:02:36 2016 +0000
@@ -3,6 +3,11 @@
 #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"
+#include "Images/ic_slideshow_white_48dp_1x.h"
+#include "Images/ic_visibility_off_white_48dp_1x.h"
+#include "Images/ic_visibility_white_48dp_1x.h"
+#include "Images/ic_equalizer_white_48dp_1x.h"
+#include "Images/ic_settings_white_48dp_1x.h"
 
 #define CLIENT_COLOR_BG                 ((uint32_t)0xFF000000)
 #define CLIENT_COLOR_FG                 ((uint32_t)0xFFD0D0D0)
@@ -16,6 +21,9 @@
 
 #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 BUTTON_WIDTH                    100
 #define BUTTON_HEIGHT                   60
@@ -52,7 +60,7 @@
 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 }, { "Slideshow", NULL }, { "Adjust\nTimers", ic_notifications_none_white_48dp_1x }, { "Lights On", NULL }, { "Lights Off", NULL }, { "Color Test", NULL }
+    { "Clock", ic_query_builder_white_48dp_1x }, { "Clock\nWith Words", ic_query_builder_white_48dp_1x }, { "Slideshow", ic_slideshow_white_48dp_1x }, { "Adjust\nTimers", ic_notifications_none_white_48dp_1x }, { "Adjust\nClock", ic_settings_white_48dp_1x }, { "Lights\nOn", ic_visibility_white_48dp_1x }, { "Lights\nOff", ic_visibility_off_white_48dp_1x }, { "My Color", ic_equalizer_white_48dp_1x }
 };
 
 //
@@ -336,7 +344,6 @@
 {
     char                        buffer[100];
     struct tm                   *tmStruct;
-    time_t                      timeValue;
 
     if (initial==true)
     {
@@ -349,8 +356,7 @@
     uiLcd.SetFont(&display_font_12x22);
     uiLcd.SetBackColor(CLOCK_COLOR_BG);
     uiLcd.SetTextColor(CLOCK_COLOR_FG);
-    timeValue=time(NULL);
-    tmStruct=localtime(&timeValue);
+    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);
 }
@@ -401,45 +407,86 @@
 //
 // slideshow
 //
+void UI_ShowSlideshowFade(uint8_t from,uint8_t to)
+{
+    if (from<to)
+    {
+        while (from<to)
+        {
+            uiLcd.SetTransparency(0,from);
+            
+            wait_ms(30);
+
+            if ((to-from)<SLIDESHOW_FADE_STEP)
+                break;
+
+            from+=SLIDESHOW_FADE_STEP;
+        }
+    }
+    else
+    {
+        while (from>to)
+        {
+            uiLcd.SetTransparency(0,from);
+
+            wait_ms(30);
+            
+            if ((from-to)<SLIDESHOW_FADE_STEP)
+                break;
+
+            from-=SLIDESHOW_FADE_STEP;
+        }
+    }
+
+    uiLcd.SetTransparency(0,to);
+}
+
 void UI_ShowSlideshow(bool initial)
 {
     char                        buffer[100];
     struct tm                   *tmStruct;
-    time_t                      timeValue;
 
-    timeValue=time(NULL);
-    tmStruct=localtime(&timeValue);
+    RTC_Get(&tmStruct);
 
-    if (((tmStruct->tm_sec / 15)!=lastSlideshowTick) || (initial==true))
+    if (((tmStruct->tm_sec / SLIDESHOW_TIMEOUT)!=lastSlideshowTick) || (initial==true))
     {
-        lastSlideshowTick=(tmStruct->tm_sec / 15);
+        lastSlideshowTick=(tmStruct->tm_sec / SLIDESHOW_TIMEOUT);
 
-        // fill background
-        uiLcd.SetTextColor(SLIDESHOW_COLOR_BG);
+        // fill background with transparent color
+        uiLcd.SetTextColor(0x00000000);
         uiLcd.FillRect(0,0,uiLcd.GetXSize(),uiLcd.GetYSize());
-/*
-uiLcd.SelectLayer(1);
-uiLcd.Clear(LCD_COLOR_BLACK);
-*/
-        // show picture
-        SD_ShowRandomPicture();
-/*
-uiLcd.SetLayerVisible(1,ENABLE);
-uiLcd.SetTransparency(1,0x80);
-uiLcd.SelectLayer(0);
-*/
+
         // 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);
+
+        // hide picture layer
+        if (initial==true)
+            uiLcd.SetTransparency(0,0);
+        else
+            UI_ShowSlideshowFade(SLIDESHOW_TRANSPARENCY,0);
+        uiLcd.SelectLayer(0);
+        // clear old picture
+        uiLcd.Clear(LCD_COLOR_BLACK);
+
+        // load picture
+        SD_ShowRandomPicture();
+
+        // show new picture
+        if (initial==true)
+            uiLcd.SetLayerVisible(0,ENABLE);
+        UI_ShowSlideshowFade(0,SLIDESHOW_TRANSPARENCY);
+        uiLcd.SelectLayer(1);
     }
 }
 
 void UI_ClickSlideshow(uint16_t x,uint16_t y)
 {
     // exit view
+    uiLcd.SetLayerVisible(0,DISABLE);
     UI_Show(&uiMain);
 }
 
@@ -461,7 +508,8 @@
             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,":");
+            if (uiCurrent->data.valueAdjust.isTime==true)
+                UI_ShowDisplayTextCenter(132,92,BUTTON_WIDTH,BUTTON_HEIGHT,":");
 
             UI_ShowDrawButton(60+(0*(BUTTON_WIDTH+15)),140,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
             UI_ShowDrawButton(205+(0*(BUTTON_WIDTH+15)),140,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
@@ -479,6 +527,34 @@
             UI_ShowDrawButton(17+(2*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
             UI_ShowDrawButton(17+(3*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
         }
+        else if (uiCurrent->data.valueAdjust.count==3)
+        {
+            if (uiCurrent->data.valueAdjust.isTime==true)
+            {
+                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,125,BUTTON_WIDTH,BUTTON_HEIGHT,":");
+
+                UI_ShowDrawButton(60+(0*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
+                UI_ShowDrawButton(205+(0*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
+                UI_ShowDrawButton(205+(1*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
+            }
+            else
+            {
+                UI_ShowDrawButton(74+(0*(BUTTON_WIDTH+15)),40,BUTTON_WIDTH,BUTTON_HEIGHT,"+");
+                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_ShowDrawButton(74+(0*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
+                UI_ShowDrawButton(74+(1*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
+                UI_ShowDrawButton(74+(2*(BUTTON_WIDTH+15)),205,BUTTON_WIDTH,BUTTON_HEIGHT,"-");
+            }
+        }
     }
 
     uiLcd.SetBackColor(CLIENT_COLOR_BG);
@@ -544,6 +620,31 @@
         snprintf(buffer,sizeof(buffer),"0x%02X",uiCurrent->data.valueAdjust.values[3]);
         UI_ShowDisplayTextCenter(17+(3*(BUTTON_WIDTH+15)),125,BUTTON_WIDTH,BUTTON_HEIGHT,buffer);
     }
+    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[1]);
+            UI_ShowDisplayTextCenter(205+(0*(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);
+        }
+        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[1]);
+            UI_ShowDisplayTextCenter(74+(1*(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);
+        }
+    }
 }
 
 void UI_ClickValueAdjust(uint16_t x,uint16_t y)
@@ -557,7 +658,7 @@
     {
         if ((y>=40) && (y<(40+BUTTON_HEIGHT)))
         {
-            if ((x>=(60+(0*(BUTTON_WIDTH+15)))) && (x<(17+(0*(BUTTON_WIDTH+15))+BUTTON_WIDTH)))
+            if ((x>=(60+(0*(BUTTON_WIDTH+15)))) && (x<(60+(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;
@@ -616,6 +717,51 @@
                 index=7;
         }
     }
+    else if (uiCurrent->data.valueAdjust.count==3)
+    {
+        if (uiCurrent->data.valueAdjust.isTime==true)
+        {
+            if ((y>=40) && (y<(40+BUTTON_HEIGHT)))
+            {
+                if ((x>=(60+(0*(BUTTON_WIDTH+15)))) && (x<(60+(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>=205) && (y<(205+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>=40) && (y<(40+BUTTON_HEIGHT)))
+            {
+                if ((x>=(74+(0*(BUTTON_WIDTH+15)))) && (x<(74+(0*(BUTTON_WIDTH+15))+BUTTON_WIDTH)))
+                    index=0;
+                else if ((x>=(74+(1*(BUTTON_WIDTH+15)))) && (x<(74+(1*(BUTTON_WIDTH+15))+BUTTON_WIDTH)))
+                    index=1;
+                else if ((x>=(74+(2*(BUTTON_WIDTH+15)))) && (x<(74+(2*(BUTTON_WIDTH+15))+BUTTON_WIDTH)))
+                    index=2;
+            }
+            else if ((y>=205) && (y<(205+BUTTON_HEIGHT)))
+            {
+                if ((x>=(74+(0*(BUTTON_WIDTH+15)))) && (x<(74+(0*(BUTTON_WIDTH+15))+BUTTON_WIDTH)))
+                    index=3;
+                else if ((x>=(74+(1*(BUTTON_WIDTH+15)))) && (x<(74+(1*(BUTTON_WIDTH+15))+BUTTON_WIDTH)))
+                    index=4;
+                else if ((x>=(74+(2*(BUTTON_WIDTH+15)))) && (x<(74+(2*(BUTTON_WIDTH+15))+BUTTON_WIDTH)))
+                    index=5;
+            }
+        }
+    }
 
     if (index!=-1)
         uiCurrent->handler(UR_CLICK,index,uiCurrent);
@@ -632,6 +778,9 @@
     uiLastTouchY=0;
 
     uiLcd.Init();
+    // layer 0: slideshow pictures
+    // layer 1: all other ui
+    uiLcd.SelectLayer(1);
     uiLcd.Clear(COLOR_BG);
 
     if (uiTs.Init(uiLcd.GetXSize(),uiLcd.GetYSize())==TS_OK)
@@ -668,7 +817,6 @@
 {
     char                        buffer[100];
     struct tm                   *tmStruct;
-    time_t                      timeValue;
 
     if (initial==true)
     {
@@ -687,8 +835,7 @@
     uiLcd.SetFont(&display_font_12x22);
     uiLcd.SetBackColor(HEADER_COLOR_BG);
     uiLcd.SetTextColor(HEADER_COLOR_FG);
-    timeValue=time(NULL);
-    tmStruct=localtime(&timeValue);
+    RTC_Get(&tmStruct);
     snprintf(buffer,sizeof(buffer),"%u:%02u",tmStruct->tm_hour,tmStruct->tm_min);
     uiLcd.DisplayStringAt(0,3,(uint8_t *)buffer,CENTER_MODE);