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 <string.h>
#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<Pixel_t*>( s ));
}
}
}

View file

@ -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;
}