You are correct. I am communicating with it via Serial and when I try to use an SPI driver it never gets to any Serial.write() statements after FastLED.show() . And I cannot communicate with it again until I reboot the board. Code is below. Note that SPI fails but WS2812 does work just fine.
#include “FastLED.h”
#include <EEPROM.h>
#include “global.h”
#include “SPI.h”
CRGB * _fastLEDs;
uint16_t numLEDs = 1;
CLEDController * pLed = NULL;
inline void setupFastLED()
{
_fastLEDs = (CRGB*)malloc(sizeof(CRGB)*numLEDs);
memset(_fastLEDs, 0, sizeof(CRGB)*numLEDs);
switch (config.type)
{
//SPI Based Chipsets
case LEDTYPE::LPD8806:
pLed = new LPD8806Controller < SPI_DATA, SPI_CLOCK, RGB>();
break;
case LEDTYPE::WS2801:
pLed = new WS2801Controller<SPI_DATA, SPI_CLOCK, RGB>();
break;
//One Wire Chipsets
case LEDTYPE::NEOPIXEL:
pLed = new WS2811Controller800Khz<ONEWIREPIN, RGB>();
break;
case LEDTYPE::WS2811_400:
pLed = new WS2811Controller400Khz<ONEWIREPIN, RGB>();
break;
default:
//TODO: Some error condition should go here
break;
}
if (pLed)
{
FastLED.addLeds(pLed, _fastLEDs, numLEDs);
}
FastLED.clear();
FastLED.show();
}
void setup()
{
digitalWrite(rebootPin, LOW);
pinMode(rebootPin, OUTPUT);
Serial.begin(115200); //USB Serial, not actually 115200
Serial.setTimeout(1000);
if (EEPROM.read(0) != CONFIGCHECK)
{
EEPROM.write(0, CONFIGCHECK);
writeDefaultConfig();
}
readConfig();
numLEDs = config.pixelCount;
setupFastLED();
}
inline void getData()
{
static char cmd = 0;
static uint16_t size = 0;
static uint16_t count = 0;
static size_t c = 0;
static uint16_t packSize = numLEDs * 3; //This will need to be dynamic for other bit depths
if (Serial.available())
{
cmd = Serial.read();
size = 0;
Serial.readBytes((char*)&size, 2);
if (cmd == CMDTYPE::PIXEL_DATA)
{
count = 0;
if (size == packSize)
{
while (count < packSize - 1)
{
//should limit the number of 0 responses allow so that it fails out eventually
c = Serial.readBytes(((char*)_fastLEDs) + count, packSize - count);
//if (c == 0) break;
count += c;
}
}
uint8_t resp = RETURN_CODES::SUCCESS;
if (count == packSize)
{
FastLED.show();
}
else
resp = RETURN_CODES::ERROR_SIZE;
Serial.write(resp);
}
Serial.flush();
}
}
void loop()
{
getData();
}