Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BSP_DISCO_F746NG_patch_fixed LCD_DISCO_F746NG TS_DISCO_F746NG FATFileSystem TinyJpgDec_interwork mbed-src
Revision 2:80026d18fcf3, committed 2015-10-29
- Comitter:
- the_sz
- Date:
- Thu Oct 29 12:59:54 2015 +0000
- Parent:
- 1:35e2ad5cd1fe
- Child:
- 3:ecf7f1f8d749
- Commit message:
- initial ui
Changed in this revision
--- a/OnBoardLED.cpp Thu Oct 29 05:00:04 2015 +0000
+++ b/OnBoardLED.cpp Thu Oct 29 12:59:54 2015 +0000
@@ -1,14 +1,15 @@
#include "WakeupLight.h"
-DigitalOut onBoardLED(LED1);
Ticker onBoardLEDTicker;
void OnBoardLED_Callback()
{
- onBoardLED=!onBoardLED;
+ BSP_LED_Toggle(LED_GREEN);
}
void OnBoardLED_Init(void)
{
+ BSP_LED_Init(LED_GREEN);
+
onBoardLEDTicker.attach(&OnBoardLED_Callback,0.3);
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/UI.cpp Thu Oct 29 12:59:54 2015 +0000
@@ -0,0 +1,233 @@
+#include "WakeupLight.h"
+
+#define CLIENT_COLOR_BG ((uint32_t)0xFF602020)
+#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 CLOCK_COLOR_BG ((uint32_t)0xFF000000)
+#define CLOCK_COLOR_FG ((uint32_t)0xFF707070)
+
+#define COLOR_BG ((uint32_t)0xFF000000)
+
+LCD_DISCO_F746NG uiLcd;
+TS_DISCO_F746NG uiTs;
+int32_t uiCounter=0;
+UI_STRUCT *uiCurrent=NULL;
+
+//
+// helper function
+//
+void UI_ShowClearClientRect(void)
+{
+ uiLcd.SetTextColor(CLIENT_COLOR_BG);
+ uiLcd.FillRect(0,HEADER_HEIGHT,uiLcd.GetXSize()-1,uiLcd.GetYSize()-1);
+}
+
+//
+// box list
+//
+void UI_ShowBoxList(bool initial)
+{
+ if (initial==true)
+ {
+ // fill background
+ UI_ShowClearClientRect();
+ }
+}
+
+void UI_ClickBoxList(uint16_t x,uint16_t y)
+{
+ // detect at which block was clicked
+}
+
+//
+// message box
+//
+void UI_ShowMessageBox(bool initial)
+{
+ if (initial==true)
+ {
+ // fill background
+ UI_ShowClearClientRect();
+ }
+}
+
+void UI_ClickMessageBox(uint16_t x,uint16_t y)
+{
+ // detect at which button was clicked
+}
+
+//
+// clock
+//
+void UI_ShowClock(bool initial)
+{
+ char buffer[100];
+
+ if (initial==true)
+ {
+ // fill background
+ uiLcd.SetTextColor(CLOCK_COLOR_BG);
+ uiLcd.FillRect(0,0,uiLcd.GetXSize()-1,uiLcd.GetYSize()-1);
+ }
+
+ // show clock
+ uiLcd.SetFont(&display_font_12x22);
+ uiLcd.SetBackColor(CLOCK_COLOR_BG);
+ uiLcd.SetTextColor(CLOCK_COLOR_FG);
+ snprintf(buffer,sizeof(buffer),"ABC %u",uiCounter);
+ uiCounter++;
+ uiLcd.DisplayStringAt(0,100,(uint8_t *)buffer,CENTER_MODE);
+}
+
+void UI_ClickClock(uint16_t x,uint16_t y)
+{
+ // exit view
+}
+
+//
+// clock in words
+//
+void UI_ShowClockInWords(bool initial)
+{
+ if (initial==true)
+ {
+ // fill background
+ UI_ShowClearClientRect();
+ }
+
+ // 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);
+
+ // draw charset
+ /*
+ int x;
+ for (x=0x80;x<=0xFF;x++)
+ {
+ uiLcd.DisplayChar(1+(((x-0x80) % 16)*14),30+(((x-0x80)/16)*20),x);
+ }
+ */
+}
+
+void UI_ClickClockInWords(uint16_t x,uint16_t y)
+{
+ // exit view
+}
+
+//
+// timer adjust
+//
+void UI_ShowTimerAdjust(bool initial)
+{
+ if (initial==true)
+ {
+ // fill background
+ UI_ShowClearClientRect();
+ }
+}
+
+void UI_ClickTimerAdjust(uint16_t x,uint16_t y)
+{
+ // detect at which button was clicked
+}
+
+//
+// common
+//
+void UI_Init(void)
+{
+ uiCurrent=NULL;
+
+ uiLcd.Init();
+ uiLcd.Clear(COLOR_BG);
+
+ if (uiTs.Init(uiLcd.GetXSize(),uiLcd.GetYSize())==TS_OK)
+ DPrintf("UI_Init: Size: %ux%u.\r\n",uiLcd.GetXSize(),uiLcd.GetYSize());
+ else
+ DPrintf("UI_Init: Can't init touch screen.\r\n");
+}
+
+void UI_ShowChrome(bool initial)
+{
+ char buffer[100];
+
+ if (initial==true)
+ {
+ // fill background
+ uiLcd.SetTextColor(HEADER_COLOR_BG);
+ uiLcd.FillRect(0,0,uiLcd.GetXSize()-1,HEADER_HEIGHT);
+ }
+
+ // show clock
+ uiLcd.SetFont(&display_font_12x22);
+ uiLcd.SetBackColor(HEADER_COLOR_BG);
+ uiLcd.SetTextColor(HEADER_COLOR_FG);
+ snprintf(buffer,sizeof(buffer),"ABC %u",uiCounter);
+ uiCounter++;
+ uiLcd.DisplayStringAt(0,3,(uint8_t *)buffer,CENTER_MODE);
+
+ // show next alarm
+}
+
+void UI_Update(bool initial)
+{
+ if ((uiCurrent->flags & UI_FLAG_NEEDS_CHROME)!=0)
+ UI_ShowChrome(initial);
+
+ if ((uiCurrent->flags & UI_FLAG_TYPE_BOX_LIST)!=0)
+ UI_ShowBoxList(initial);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_MESSAGE_BOX)!=0)
+ UI_ShowMessageBox(initial);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK)!=0)
+ UI_ShowClock(initial);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK_IN_WORDS)!=0)
+ UI_ShowClockInWords(initial);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_TIMER_ADJUST)!=0)
+ UI_ShowTimerAdjust(initial);
+}
+
+void UI_Show(UI_STRUCT *ui)
+{
+ uiCurrent=ui;
+
+ UI_Update(true);
+}
+
+void UI_Click(uint16_t x,uint16_t y)
+{
+ if ((uiCurrent->flags & UI_FLAG_TYPE_BOX_LIST)!=0)
+ UI_ClickBoxList(x,y);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_MESSAGE_BOX)!=0)
+ UI_ClickMessageBox(x,y);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK)!=0)
+ UI_ClickClock(x,y);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_CLOCK_IN_WORDS)!=0)
+ UI_ClickClockInWords(x,y);
+ else if ((uiCurrent->flags & UI_FLAG_TYPE_TIMER_ADJUST)!=0)
+ UI_ClickTimerAdjust(x,y);
+}
+
+void UI_Poll(void)
+{
+ TS_StateTypeDef tsState;
+
+ uiTs.GetState(&tsState);
+ if (tsState.touchDetected>0)
+ {
+ DPrintf("UI_Poll: #%u - %ux%u.\r\n",tsState.touchDetected,tsState.touchX[0],tsState.touchY[0]);
+ UI_Click(tsState.touchX[0],tsState.touchY[0]);
+ }
+
+ if (uiCurrent!=NULL)
+ UI_Update(false);
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/UI.h Thu Oct 29 12:59:54 2015 +0000
@@ -0,0 +1,45 @@
+#ifndef __UI_h
+#define __UI_h
+
+#define UI_FLAG_TYPE_BOX_LIST (0x01 | UI_FLAG_NEEDS_CHROME)
+#define UI_FLAG_TYPE_MESSAGE_BOX (0x02 | UI_FLAG_NEEDS_CHROME)
+#define UI_FLAG_TYPE_CLOCK 0x04
+#define UI_FLAG_TYPE_CLOCK_IN_WORDS (0x08 | UI_FLAG_NEEDS_CHROME)
+#define UI_FLAG_TYPE_TIMER_ADJUST (0x10 | UI_FLAG_NEEDS_CHROME)
+#define UI_FLAG_NEEDS_CHROME 0x20
+
+typedef struct
+{
+ int8_t flags; // UI_FLAG_...
+
+ union
+ {
+ struct
+ {
+ } boxList;
+
+ struct
+ {
+ } messageBox;
+
+ struct
+ {
+ } clock;
+
+ struct
+ {
+ } clockInWords;
+
+ struct
+ {
+ } timerAdjust;
+
+ } data;
+
+} UI_STRUCT;
+
+void UI_Init(void);
+void UI_Poll(void);
+void UI_Show(UI_STRUCT *ui);
+
+#endif
--- a/WakeupLight.h Thu Oct 29 05:00:04 2015 +0000 +++ b/WakeupLight.h Thu Oct 29 12:59:54 2015 +0000 @@ -2,11 +2,13 @@ #define __WakeupLight_h #include "mbed.h" +#include "stm32746g_discovery.h" #include "TS_DISCO_F746NG.h" #include "LCD_DISCO_F746NG.h" #include "OnBoardLED.h" #include "LED.h" +#include "UI.h" #include "Fonts/display_fonts.h" #include "debug.h"
--- a/main.cpp Thu Oct 29 05:00:04 2015 +0000
+++ b/main.cpp Thu Oct 29 12:59:54 2015 +0000
@@ -1,34 +1,26 @@
#include "WakeupLight.h"
-LCD_DISCO_F746NG lcd;
-TS_DISCO_F746NG ts;
+ UI_STRUCT ui;
int main()
{
- char buffer[100];
- int counter=0;
-
debug_Init();
- DPrintf("WakeupLight.\r\n");
+ DPrintf("WakeupLight - Hardware v%08X.\r\n",BSP_GetVersion());
OnBoardLED_Init();
LED_Init();
- BSP_LCD_SetTextColor(LCD_COLOR_RED);
- BSP_LCD_SetBackColor(LCD_COLOR_BLACK);
+ UI_Init();
- BSP_LCD_SetFont(&display_font_12x22);
-
- LED_StartAnimation(LAE_WAKEUP);
+ //LED_StartAnimation(LAE_WAKEUP);
- while(1)
- {
- wait(0.2);
+ ui.flags=UI_FLAG_TYPE_CLOCK;
+ UI_Show(&ui);
- snprintf(buffer,sizeof(buffer),"ABC %u",counter);
- counter++;
- lcd.DisplayStringAt(0, LINE(1), (uint8_t *)buffer, CENTER_MODE);
+ for (;;)
+ {
+ UI_Poll();
}
}