Ws2812spi and sk6812rgbw have wrong default rate (#221)

* Changed default baud rate in schema for ws2812spi and sk6812spi

* now sets the default baud_rate speed to 2800000 if omitted.
Previously it used the ProviderSPI default which was 1000000 and guaranteed not to work

* Added warnings if the SPI baud rate is likely out of range
Added some debug statements to ProviderSpi
This commit is contained in:
penfold42 2016-09-04 22:28:06 +10:00 committed by redPanther
parent 4968a11816
commit 49d3d35de1
6 changed files with 34 additions and 3 deletions

View File

@ -33,6 +33,13 @@ LedDevice* LedDeviceSk6812SPI::construct(const Json::Value &deviceConfig)
bool LedDeviceSk6812SPI::setConfig(const Json::Value &deviceConfig) bool LedDeviceSk6812SPI::setConfig(const Json::Value &deviceConfig)
{ {
ProviderSpi::setConfig(deviceConfig); ProviderSpi::setConfig(deviceConfig);
_baudRate_Hz = deviceConfig.get("rate",3000000).asInt();
if ( (_baudRate_Hz < 2050000) || (_baudRate_Hz > 4000000) )
{
Warning(_log, "SPI rate %d outside recommended range (2050000 -> 4000000)", _baudRate_Hz);
}
_whiteAlgorithm = deviceConfig.get("white_algorithm","").asString(); _whiteAlgorithm = deviceConfig.get("white_algorithm","").asString();
return true; return true;

View File

@ -19,7 +19,10 @@ LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig)
0b11001000, 0b11001000,
0b11001100, 0b11001100,
} }
{ {
setConfig(deviceConfig);
} }
LedDevice* LedDeviceWs2812SPI::construct(const Json::Value &deviceConfig) LedDevice* LedDeviceWs2812SPI::construct(const Json::Value &deviceConfig)
@ -27,6 +30,18 @@ LedDevice* LedDeviceWs2812SPI::construct(const Json::Value &deviceConfig)
return new LedDeviceWs2812SPI(deviceConfig); return new LedDeviceWs2812SPI(deviceConfig);
} }
bool LedDeviceWs2812SPI::setConfig(const Json::Value &deviceConfig)
{
ProviderSpi::setConfig(deviceConfig);
_baudRate_Hz = deviceConfig.get("rate",3000000).asInt();
if ( (_baudRate_Hz < 2050000) || (_baudRate_Hz > 4000000) )
{
Warning(_log, "SPI rate %d outside recommended range (2050000 -> 4000000)", _baudRate_Hz);
}
return true;
}
int LedDeviceWs2812SPI::write(const std::vector<ColorRgb> &ledValues) int LedDeviceWs2812SPI::write(const std::vector<ColorRgb> &ledValues)
{ {
_ledCount = ledValues.size(); _ledCount = ledValues.size();

View File

@ -22,6 +22,13 @@ public:
/// constructs leddevice /// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig); static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// ///
/// Writes the led color values to the led-device /// Writes the led color values to the led-device
/// ///

View File

@ -20,7 +20,6 @@ ProviderSpi::ProviderSpi(const Json::Value &deviceConfig)
{ {
setConfig(deviceConfig); setConfig(deviceConfig);
memset(&_spi, 0, sizeof(_spi)); memset(&_spi, 0, sizeof(_spi));
Debug(_log, "_spiDataInvert %d, _spiMode %d", _spiDataInvert, _spiMode);
} }
ProviderSpi::~ProviderSpi() ProviderSpi::~ProviderSpi()
@ -41,6 +40,9 @@ bool ProviderSpi::setConfig(const Json::Value &deviceConfig)
int ProviderSpi::open() int ProviderSpi::open()
{ {
Debug(_log, "_baudRate_Hz %d, _latchTime_ns %d", _baudRate_Hz, _latchTime_ns);
Debug(_log, "_spiDataInvert %d, _spiMode %d", _spiDataInvert, _spiMode);
const int bitsPerWord = 8; const int bitsPerWord = 8;
_fid = ::open(_deviceName.c_str(), O_RDWR); _fid = ::open(_deviceName.c_str(), O_RDWR);

View File

@ -10,7 +10,7 @@
"rate": { "rate": {
"type": "integer", "type": "integer",
"title":"Baudrate", "title":"Baudrate",
"default": 1000000 "default": 2666666
}, },
"invert": { "invert": {
"type": "boolean", "type": "boolean",

View File

@ -10,7 +10,7 @@
"rate": { "rate": {
"type": "integer", "type": "integer",
"title":"Baudrate", "title":"Baudrate",
"default": 1000000 "default": 2666666
}, },
"invert": { "invert": {
"type": "boolean", "type": "boolean",