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
LED.cpp@3:ecf7f1f8d749, 2015-10-29 (annotated)
- Committer:
- the_sz
- Date:
- Thu Oct 29 18:09:31 2015 +0000
- Revision:
- 3:ecf7f1f8d749
- Parent:
- 1:35e2ad5cd1fe
- Child:
- 5:13c70bcde7f6
ui menu working, time() added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
the_sz | 1:35e2ad5cd1fe | 1 | #include "WakeupLight.h" |
the_sz | 1:35e2ad5cd1fe | 2 | |
the_sz | 1:35e2ad5cd1fe | 3 | #define COLOR_CREATE(_RED_,_GREEN_,_BLUE_,_WHITE_) (_RED_ | (_GREEN_ << 8) | (_BLUE_ << 16) | (_WHITE_ <<24)) |
the_sz | 1:35e2ad5cd1fe | 4 | #define COLOR_RED(_COLOR_) (_COLOR_ & 0xFF) |
the_sz | 1:35e2ad5cd1fe | 5 | #define COLOR_GREEN(_COLOR_) ((_COLOR_ >> 8) & 0xFF) |
the_sz | 1:35e2ad5cd1fe | 6 | #define COLOR_BLUE(_COLOR_) ((_COLOR_ >> 16) & 0xFF) |
the_sz | 1:35e2ad5cd1fe | 7 | #define COLOR_WHITE(_COLOR_) ((_COLOR_ >> 24) & 0xFF) |
the_sz | 1:35e2ad5cd1fe | 8 | |
the_sz | 1:35e2ad5cd1fe | 9 | #define LED_PERIOD 10 |
the_sz | 1:35e2ad5cd1fe | 10 | |
the_sz | 1:35e2ad5cd1fe | 11 | PwmOut ledBlue(PB_15); |
the_sz | 1:35e2ad5cd1fe | 12 | PwmOut ledRed(PH_6); |
the_sz | 1:35e2ad5cd1fe | 13 | PwmOut ledGreen(PB_4); |
the_sz | 1:35e2ad5cd1fe | 14 | PwmOut ledWhite(PA_15); |
the_sz | 1:35e2ad5cd1fe | 15 | Ticker ledTicker; |
the_sz | 1:35e2ad5cd1fe | 16 | int32_t ledAnimationStep; |
the_sz | 1:35e2ad5cd1fe | 17 | LED_ANIMATION_ENUM ledAnimation; |
the_sz | 1:35e2ad5cd1fe | 18 | |
the_sz | 1:35e2ad5cd1fe | 19 | void LED_SetColor(int32_t color) |
the_sz | 1:35e2ad5cd1fe | 20 | { |
the_sz | 1:35e2ad5cd1fe | 21 | DPrintfCore("LED_SetColor: 0x%08X.\r\n",color); |
the_sz | 1:35e2ad5cd1fe | 22 | |
the_sz | 1:35e2ad5cd1fe | 23 | ledRed.write(1.0 * COLOR_RED(color) / 255.0); |
the_sz | 1:35e2ad5cd1fe | 24 | ledGreen.write(1.0 * COLOR_GREEN(color) / 255.0); |
the_sz | 1:35e2ad5cd1fe | 25 | ledBlue.write(1.0 * COLOR_BLUE(color) / 255.0); |
the_sz | 1:35e2ad5cd1fe | 26 | ledWhite.write(1.0 * COLOR_WHITE(color) / 255.0); |
the_sz | 1:35e2ad5cd1fe | 27 | } |
the_sz | 1:35e2ad5cd1fe | 28 | |
the_sz | 1:35e2ad5cd1fe | 29 | void LED_Callback() |
the_sz | 1:35e2ad5cd1fe | 30 | { |
the_sz | 1:35e2ad5cd1fe | 31 | int32_t color; |
the_sz | 1:35e2ad5cd1fe | 32 | |
the_sz | 1:35e2ad5cd1fe | 33 | DPrintfCore("LED_Callback: Animation: %u, Step: %u.\r\n",ledAnimation,ledAnimationStep); |
the_sz | 1:35e2ad5cd1fe | 34 | |
the_sz | 1:35e2ad5cd1fe | 35 | if (ledAnimation==LAE_WAKEUP) |
the_sz | 1:35e2ad5cd1fe | 36 | { |
the_sz | 1:35e2ad5cd1fe | 37 | if (ledAnimationStep<255) |
the_sz | 1:35e2ad5cd1fe | 38 | { |
the_sz | 1:35e2ad5cd1fe | 39 | ledAnimationStep++; |
the_sz | 1:35e2ad5cd1fe | 40 | color=COLOR_CREATE((ledAnimationStep/2),ledAnimationStep,0,0); |
the_sz | 1:35e2ad5cd1fe | 41 | LED_SetColor(color); |
the_sz | 1:35e2ad5cd1fe | 42 | } |
the_sz | 1:35e2ad5cd1fe | 43 | else if (ledAnimationStep<(255+180)) |
the_sz | 1:35e2ad5cd1fe | 44 | { |
the_sz | 1:35e2ad5cd1fe | 45 | ledAnimationStep++; |
the_sz | 1:35e2ad5cd1fe | 46 | |
the_sz | 1:35e2ad5cd1fe | 47 | color=COLOR_CREATE(128,255,0,(ledAnimationStep-255)); |
the_sz | 1:35e2ad5cd1fe | 48 | LED_SetColor(color); |
the_sz | 1:35e2ad5cd1fe | 49 | } |
the_sz | 1:35e2ad5cd1fe | 50 | } |
the_sz | 3:ecf7f1f8d749 | 51 | else if (ledAnimation==LAE_OFF) |
the_sz | 3:ecf7f1f8d749 | 52 | { |
the_sz | 3:ecf7f1f8d749 | 53 | float red; |
the_sz | 3:ecf7f1f8d749 | 54 | float green; |
the_sz | 3:ecf7f1f8d749 | 55 | float blue; |
the_sz | 3:ecf7f1f8d749 | 56 | float white; |
the_sz | 3:ecf7f1f8d749 | 57 | uint32_t redInt; |
the_sz | 3:ecf7f1f8d749 | 58 | uint32_t greenInt; |
the_sz | 3:ecf7f1f8d749 | 59 | uint32_t blueInt; |
the_sz | 3:ecf7f1f8d749 | 60 | uint32_t whiteInt; |
the_sz | 3:ecf7f1f8d749 | 61 | |
the_sz | 3:ecf7f1f8d749 | 62 | red=ledRed.read(); |
the_sz | 3:ecf7f1f8d749 | 63 | if (red>0.0) |
the_sz | 3:ecf7f1f8d749 | 64 | red-=0.001; |
the_sz | 3:ecf7f1f8d749 | 65 | red=MAX(red,0.0); |
the_sz | 3:ecf7f1f8d749 | 66 | redInt=(int32_t)(red*255.0); |
the_sz | 3:ecf7f1f8d749 | 67 | |
the_sz | 3:ecf7f1f8d749 | 68 | green=ledGreen.read(); |
the_sz | 3:ecf7f1f8d749 | 69 | if (green>0.0) |
the_sz | 3:ecf7f1f8d749 | 70 | green-=0.001; |
the_sz | 3:ecf7f1f8d749 | 71 | green=MAX(green,0.0); |
the_sz | 3:ecf7f1f8d749 | 72 | greenInt=(int32_t)(green*255.0); |
the_sz | 3:ecf7f1f8d749 | 73 | |
the_sz | 3:ecf7f1f8d749 | 74 | blue=ledBlue.read(); |
the_sz | 3:ecf7f1f8d749 | 75 | if (blue>0) |
the_sz | 3:ecf7f1f8d749 | 76 | blue-=0.001; |
the_sz | 3:ecf7f1f8d749 | 77 | blue=MAX(blue,0.0); |
the_sz | 3:ecf7f1f8d749 | 78 | blueInt=(int32_t)(blue*255.0); |
the_sz | 3:ecf7f1f8d749 | 79 | |
the_sz | 3:ecf7f1f8d749 | 80 | white=ledWhite.read(); |
the_sz | 3:ecf7f1f8d749 | 81 | if (white>0) |
the_sz | 3:ecf7f1f8d749 | 82 | white-=0.001; |
the_sz | 3:ecf7f1f8d749 | 83 | white=MAX(white,0.0); |
the_sz | 3:ecf7f1f8d749 | 84 | whiteInt=(int32_t)(white*255.0); |
the_sz | 3:ecf7f1f8d749 | 85 | |
the_sz | 3:ecf7f1f8d749 | 86 | color=COLOR_CREATE(redInt,greenInt,blueInt,whiteInt); |
the_sz | 3:ecf7f1f8d749 | 87 | LED_SetColor(color); |
the_sz | 3:ecf7f1f8d749 | 88 | } |
the_sz | 1:35e2ad5cd1fe | 89 | } |
the_sz | 1:35e2ad5cd1fe | 90 | |
the_sz | 1:35e2ad5cd1fe | 91 | void LED_StartAnimation(LED_ANIMATION_ENUM animation) |
the_sz | 1:35e2ad5cd1fe | 92 | { |
the_sz | 1:35e2ad5cd1fe | 93 | ledAnimationStep=0; |
the_sz | 1:35e2ad5cd1fe | 94 | ledAnimation=animation; |
the_sz | 1:35e2ad5cd1fe | 95 | } |
the_sz | 1:35e2ad5cd1fe | 96 | |
the_sz | 1:35e2ad5cd1fe | 97 | void LED_Init(void) |
the_sz | 1:35e2ad5cd1fe | 98 | { |
the_sz | 1:35e2ad5cd1fe | 99 | ledRed.period_ms(LED_PERIOD); |
the_sz | 1:35e2ad5cd1fe | 100 | ledGreen.period_ms(LED_PERIOD); |
the_sz | 1:35e2ad5cd1fe | 101 | ledBlue.period_ms(LED_PERIOD); |
the_sz | 1:35e2ad5cd1fe | 102 | ledWhite.period_ms(LED_PERIOD); |
the_sz | 1:35e2ad5cd1fe | 103 | |
the_sz | 1:35e2ad5cd1fe | 104 | LED_SetColor(COLOR_CREATE(0,0,0,0)); |
the_sz | 1:35e2ad5cd1fe | 105 | |
the_sz | 1:35e2ad5cd1fe | 106 | LED_StartAnimation(LAE_NONE); |
the_sz | 1:35e2ad5cd1fe | 107 | |
the_sz | 1:35e2ad5cd1fe | 108 | ledTicker.attach(&LED_Callback,0.05); |
the_sz | 1:35e2ad5cd1fe | 109 | } |