sparkling

This commit is contained in:
Attila BODY 2018-12-16 18:36:42 +01:00
parent 087af69592
commit 8eb06c8eab
2 changed files with 23 additions and 26 deletions

View file

@ -12,8 +12,9 @@
#include "gpio.h" #include "gpio.h"
#include <string.h> #include <string.h>
#include "App/Pixel.h" #include "Pixel.h"
#include "App/LedBuffers.h" #include "LedBuffers.h"
#include "Sparkle.h"
void convert(uint8_t *src, uint8_t *dst, uint16_t size) 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() extern "C" void App()
{ {
#define BRIGHTNESS 4
#define DELAY 10
g_ledBits[sizeof(g_ledBits)-1] = 0; g_ledBits[sizeof(g_ledBits)-1] = 0;
memset(g_pixels, 0, sizeof(g_pixels)); memset(g_pixels, 0, sizeof(g_pixels));
while(1) while(1)
{ {
for(uint16_t idx=0; idx < NUMPIXELS; idx++) Sparkle s;
{ Pixel_t color = {0xff, 0xff, 0xff};
if(idx % 3 == 0) g_pixels[idx].r = BRIGHTNESS; Pixel_t fadeSpeed = {1,2,3};
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);
}
for(uint16_t idx=0; idx < NUMPIXELS; idx++) for(uint16_t idx=0; idx < NUMPIXELS; idx++)
{ {
if(idx % 3 == 0) g_pixels[idx].r = 0; s.Start(&g_pixels[idx], color, fadeSpeed);
else if(idx % 3 == 1) g_pixels[idx].g = 0;
else g_pixels[idx].b = 0;
convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels)); convert((uint8_t*)g_pixels, g_ledBits, sizeof(g_pixels));
HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits)); HAL_SPI_Transmit_DMA(&hspi1, g_ledBits, sizeof(g_ledBits));
while(!g_done); 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<Pixel_t*>( s ));
} }
} }
} }

View file

@ -26,9 +26,9 @@ bool Sparkle::Step()
Pixel_t current = *m_target; Pixel_t current = *m_target;
uint8_t remaining = 3; 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 { else {
current.b = 0; current.r = 0;
--remaining; --remaining;
} }
@ -43,7 +43,10 @@ bool Sparkle::Step()
current.b = 0; current.b = 0;
--remaining; --remaining;
} }
*m_target = current;
return remaining != 0; if(remaining) return true;
m_target = nullptr;
return false;
} }