diff --git a/.cproject b/.cproject
index 309b751..1925130 100644
--- a/.cproject
+++ b/.cproject
@@ -68,7 +68,7 @@
-
+
@@ -111,8 +111,8 @@
-
-
+
+
@@ -124,25 +124,25 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
diff --git a/App/App.cpp b/App/App.cpp
index ca9cefb..fa4a738 100644
--- a/App/App.cpp
+++ b/App/App.cpp
@@ -12,10 +12,14 @@
#include "gpio.h"
#include
+#include
#include "Pixel.h"
#include "LedBuffers.h"
#include "Sparkle.h"
+#define NUMSPARKLES 10
+Sparkle g_s[NUMSPARKLES];
+
void convert(uint8_t *src, uint8_t *dst, uint16_t size)
{
static uint8_t const bits[4] = { 0b10001000, 0b10001110, 0b11101000, 0b11101110 };
@@ -30,6 +34,31 @@ void convert(uint8_t *src, uint8_t *dst, uint16_t size)
}
}
+inline uint16_t rr(uint16_t top)
+{
+ return rand() % top;
+}
+
+uint16_t ChoosePixel()
+{
+ volatile uint16_t chosen;
+ uint16_t spi;
+
+ do {
+ chosen = rr(NUMPIXELS);
+ for(spi=0; spi(g_s[spi]) && static_cast(g_s[spi]) == &g_pixels[chosen])
+ break;
+ }
+ } while(spi < NUMSPARKLES);
+ return chosen;
+}
+
+void StartSparkle( Sparkle &s )
+{
+ s.Start(g_pixels+ChoosePixel(), Pixel(255,255,255), Pixel(rr(5)+1,rr(5)+1,rr(5)+1));
+}
+
extern "C" void App()
{
g_ledBits[sizeof(g_ledBits)-1] = 0;
@@ -38,25 +67,16 @@ extern "C" void App()
while(1)
{
- Sparkle s;
- Pixel_t color = {0xff, 0xff, 0xff};
- Pixel_t fadeSpeed = {1,2,3};
-
- for(uint16_t idx=0; idx < NUMPIXELS; idx++)
- {
- 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(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 ));
+ for(int16_t spi = 0; spi < NUMSPARKLES; ++spi) {
+ if(static_cast(g_s[spi]))
+ g_s[spi].Step();
+ else
+ StartSparkle(g_s[spi]);
}
+
+ 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(5);
}
}
diff --git a/App/Pixel.h b/App/Pixel.h
index ac6cc26..cf9ce5e 100644
--- a/App/Pixel.h
+++ b/App/Pixel.h
@@ -24,4 +24,14 @@ typedef struct {
}
#endif
+#ifdef __cplusplus
+struct Pixel : public Pixel_t {
+ Pixel(uint8_t _r, uint8_t _g, uint8_t _b) {
+ g =_g;
+ r = _r;
+ b = _b;
+ }
+};
+#endif
+
#endif /* PIXEL_H_ */