From 8eb06c8eab410b1967075c940b8c95b082ec03df Mon Sep 17 00:00:00 2001 From: Attila BODY Date: Sun, 16 Dec 2018 18:36:42 +0100 Subject: [PATCH] sparkling --- App/App.cpp | 40 +++++++++++++++++----------------------- App/Sparkle.cpp | 9 ++++++--- 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/App/App.cpp b/App/App.cpp index 570d90c..ca9cefb 100644 --- a/App/App.cpp +++ b/App/App.cpp @@ -12,8 +12,9 @@ #include "gpio.h" #include -#include "App/Pixel.h" -#include "App/LedBuffers.h" +#include "Pixel.h" +#include "LedBuffers.h" +#include "Sparkle.h" void convert(uint8_t *src, uint8_t *dst, uint16_t size) { @@ -31,38 +32,31 @@ void convert(uint8_t *src, uint8_t *dst, uint16_t size) extern "C" void App() { -#define BRIGHTNESS 4 -#define DELAY 10 - g_ledBits[sizeof(g_ledBits)-1] = 0; memset(g_pixels, 0, sizeof(g_pixels)); + while(1) { - for(uint16_t idx=0; idx < NUMPIXELS; idx++) - { - if(idx % 3 == 0) g_pixels[idx].r = BRIGHTNESS; - else if(idx % 3 == 1) g_pixels[idx].g = BRIGHTNESS; - else g_pixels[idx].b = BRIGHTNESS; - - convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels)); - - HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); - while(!g_done); - HAL_Delay(DELAY); - } + Sparkle s; + Pixel_t color = {0xff, 0xff, 0xff}; + Pixel_t fadeSpeed = {1,2,3}; for(uint16_t idx=0; idx < NUMPIXELS; idx++) { - if(idx % 3 == 0) g_pixels[idx].r = 0; - else if(idx % 3 == 1) g_pixels[idx].g = 0; - else g_pixels[idx].b = 0; - + s.Start(&g_pixels[idx], color, fadeSpeed); convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels)); - HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); while(!g_done); - HAL_Delay(DELAY); + HAL_Delay(1); + + do { + s.Step(); + convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels)); + HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); + while(!g_done); + HAL_Delay(1); + } while( static_cast( s )); } } } diff --git a/App/Sparkle.cpp b/App/Sparkle.cpp index b928f82..eec81a6 100644 --- a/App/Sparkle.cpp +++ b/App/Sparkle.cpp @@ -26,9 +26,9 @@ bool Sparkle::Step() Pixel_t current = *m_target; uint8_t remaining = 3; - if(current.b > m_fadeSpeed.r )current.r -= m_fadeSpeed.r; + if(current.r > m_fadeSpeed.r )current.r -= m_fadeSpeed.r; else { - current.b = 0; + current.r = 0; --remaining; } @@ -43,7 +43,10 @@ bool Sparkle::Step() current.b = 0; --remaining; } + *m_target = current; - return remaining != 0; + if(remaining) return true; + m_target = nullptr; + return false; }