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

Committer:
the_sz
Date:
Sun Jan 31 17:45:50 2016 +0000
Revision:
13:811a5c5b3fd6
Parent:
5:13c70bcde7f6
pre-font-alias

Who changed what in which revision?

UserRevisionLine numberNew contents of line
the_sz 1:35e2ad5cd1fe 1 #include "WakeupLight.h"
the_sz 1:35e2ad5cd1fe 2
the_sz 1:35e2ad5cd1fe 3 #define LED_PERIOD 10
the_sz 1:35e2ad5cd1fe 4
the_sz 1:35e2ad5cd1fe 5 PwmOut ledBlue(PB_15);
the_sz 1:35e2ad5cd1fe 6 PwmOut ledRed(PH_6);
the_sz 1:35e2ad5cd1fe 7 PwmOut ledGreen(PB_4);
the_sz 1:35e2ad5cd1fe 8 PwmOut ledWhite(PA_15);
the_sz 1:35e2ad5cd1fe 9 Ticker ledTicker;
the_sz 1:35e2ad5cd1fe 10 int32_t ledAnimationStep;
the_sz 1:35e2ad5cd1fe 11 LED_ANIMATION_ENUM ledAnimation;
the_sz 1:35e2ad5cd1fe 12
the_sz 1:35e2ad5cd1fe 13 void LED_SetColor(int32_t color)
the_sz 1:35e2ad5cd1fe 14 {
the_sz 1:35e2ad5cd1fe 15 DPrintfCore("LED_SetColor: 0x%08X.\r\n",color);
the_sz 1:35e2ad5cd1fe 16
the_sz 1:35e2ad5cd1fe 17 ledRed.write(1.0 * COLOR_RED(color) / 255.0);
the_sz 1:35e2ad5cd1fe 18 ledGreen.write(1.0 * COLOR_GREEN(color) / 255.0);
the_sz 1:35e2ad5cd1fe 19 ledBlue.write(1.0 * COLOR_BLUE(color) / 255.0);
the_sz 1:35e2ad5cd1fe 20 ledWhite.write(1.0 * COLOR_WHITE(color) / 255.0);
the_sz 1:35e2ad5cd1fe 21 }
the_sz 1:35e2ad5cd1fe 22
the_sz 1:35e2ad5cd1fe 23 void LED_Callback()
the_sz 1:35e2ad5cd1fe 24 {
the_sz 1:35e2ad5cd1fe 25 int32_t color;
the_sz 1:35e2ad5cd1fe 26
the_sz 1:35e2ad5cd1fe 27 DPrintfCore("LED_Callback: Animation: %u, Step: %u.\r\n",ledAnimation,ledAnimationStep);
the_sz 1:35e2ad5cd1fe 28
the_sz 1:35e2ad5cd1fe 29 if (ledAnimation==LAE_WAKEUP)
the_sz 1:35e2ad5cd1fe 30 {
the_sz 1:35e2ad5cd1fe 31 if (ledAnimationStep<255)
the_sz 1:35e2ad5cd1fe 32 {
the_sz 1:35e2ad5cd1fe 33 ledAnimationStep++;
the_sz 1:35e2ad5cd1fe 34 color=COLOR_CREATE((ledAnimationStep/2),ledAnimationStep,0,0);
the_sz 1:35e2ad5cd1fe 35 LED_SetColor(color);
the_sz 1:35e2ad5cd1fe 36 }
the_sz 1:35e2ad5cd1fe 37 else if (ledAnimationStep<(255+180))
the_sz 1:35e2ad5cd1fe 38 {
the_sz 1:35e2ad5cd1fe 39 ledAnimationStep++;
the_sz 1:35e2ad5cd1fe 40
the_sz 1:35e2ad5cd1fe 41 color=COLOR_CREATE(128,255,0,(ledAnimationStep-255));
the_sz 1:35e2ad5cd1fe 42 LED_SetColor(color);
the_sz 1:35e2ad5cd1fe 43 }
the_sz 1:35e2ad5cd1fe 44 }
the_sz 3:ecf7f1f8d749 45 else if (ledAnimation==LAE_OFF)
the_sz 3:ecf7f1f8d749 46 {
the_sz 13:811a5c5b3fd6 47 double red;
the_sz 13:811a5c5b3fd6 48 double green;
the_sz 13:811a5c5b3fd6 49 double blue;
the_sz 13:811a5c5b3fd6 50 double white;
the_sz 3:ecf7f1f8d749 51 uint32_t redInt;
the_sz 3:ecf7f1f8d749 52 uint32_t greenInt;
the_sz 3:ecf7f1f8d749 53 uint32_t blueInt;
the_sz 3:ecf7f1f8d749 54 uint32_t whiteInt;
the_sz 3:ecf7f1f8d749 55
the_sz 3:ecf7f1f8d749 56 red=ledRed.read();
the_sz 3:ecf7f1f8d749 57 if (red>0.0)
the_sz 3:ecf7f1f8d749 58 red-=0.001;
the_sz 3:ecf7f1f8d749 59 red=MAX(red,0.0);
the_sz 3:ecf7f1f8d749 60 redInt=(int32_t)(red*255.0);
the_sz 3:ecf7f1f8d749 61
the_sz 3:ecf7f1f8d749 62 green=ledGreen.read();
the_sz 3:ecf7f1f8d749 63 if (green>0.0)
the_sz 3:ecf7f1f8d749 64 green-=0.001;
the_sz 3:ecf7f1f8d749 65 green=MAX(green,0.0);
the_sz 3:ecf7f1f8d749 66 greenInt=(int32_t)(green*255.0);
the_sz 3:ecf7f1f8d749 67
the_sz 3:ecf7f1f8d749 68 blue=ledBlue.read();
the_sz 3:ecf7f1f8d749 69 if (blue>0)
the_sz 3:ecf7f1f8d749 70 blue-=0.001;
the_sz 3:ecf7f1f8d749 71 blue=MAX(blue,0.0);
the_sz 3:ecf7f1f8d749 72 blueInt=(int32_t)(blue*255.0);
the_sz 3:ecf7f1f8d749 73
the_sz 3:ecf7f1f8d749 74 white=ledWhite.read();
the_sz 3:ecf7f1f8d749 75 if (white>0)
the_sz 3:ecf7f1f8d749 76 white-=0.001;
the_sz 3:ecf7f1f8d749 77 white=MAX(white,0.0);
the_sz 3:ecf7f1f8d749 78 whiteInt=(int32_t)(white*255.0);
the_sz 3:ecf7f1f8d749 79
the_sz 3:ecf7f1f8d749 80 color=COLOR_CREATE(redInt,greenInt,blueInt,whiteInt);
the_sz 3:ecf7f1f8d749 81 LED_SetColor(color);
the_sz 3:ecf7f1f8d749 82 }
the_sz 1:35e2ad5cd1fe 83 }
the_sz 1:35e2ad5cd1fe 84
the_sz 1:35e2ad5cd1fe 85 void LED_StartAnimation(LED_ANIMATION_ENUM animation)
the_sz 1:35e2ad5cd1fe 86 {
the_sz 1:35e2ad5cd1fe 87 ledAnimationStep=0;
the_sz 1:35e2ad5cd1fe 88 ledAnimation=animation;
the_sz 1:35e2ad5cd1fe 89 }
the_sz 1:35e2ad5cd1fe 90
the_sz 1:35e2ad5cd1fe 91 void LED_Init(void)
the_sz 1:35e2ad5cd1fe 92 {
the_sz 1:35e2ad5cd1fe 93 ledRed.period_ms(LED_PERIOD);
the_sz 1:35e2ad5cd1fe 94 ledGreen.period_ms(LED_PERIOD);
the_sz 1:35e2ad5cd1fe 95 ledBlue.period_ms(LED_PERIOD);
the_sz 1:35e2ad5cd1fe 96 ledWhite.period_ms(LED_PERIOD);
the_sz 1:35e2ad5cd1fe 97
the_sz 1:35e2ad5cd1fe 98 LED_SetColor(COLOR_CREATE(0,0,0,0));
the_sz 1:35e2ad5cd1fe 99
the_sz 1:35e2ad5cd1fe 100 LED_StartAnimation(LAE_NONE);
the_sz 1:35e2ad5cd1fe 101
the_sz 1:35e2ad5cd1fe 102 ledTicker.attach(&LED_Callback,0.05);
the_sz 1:35e2ad5cd1fe 103 }