Leddevice rework2 (#193)

* commit debug code to save it due to merge

* migrate first devices to new device registry and configure on runtime

* fadecandy and rs232 resets device if config is set

* try to hunt crash on osx

* test commit if this works with osx

* refactor spi devices

* cleanup

* refactor leddevices file, tinkerforge and ws2812b

* refactor raw usb devices

* refactor udp devices

* - add tpm2net driver
- remove old udp driver from build (files left in place for reference for new udp driver)
- json serverinfo shows available leddevices

* finish rework part 2 of leddevices

* add schemas for leddevices.
currently only compiled in, but not usedx
This commit is contained in:
redPanther
2016-08-23 20:07:12 +02:00
committed by GitHub
parent c207828069
commit d679affeb4
103 changed files with 1244 additions and 596 deletions

View File

@@ -4,31 +4,13 @@
#include "LedDeviceWS281x.h"
// Constructor
LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum, const int pwmchannel, const int invert, const int rgbw, const std::string& whiteAlgorithm)
LedDeviceWS281x::LedDeviceWS281x(const Json::Value &deviceConfig)
: LedDevice()
, _channel(pwmchannel)
, _initialized(false)
, _whiteAlgorithm(whiteAlgorithm)
{
Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str());
setConfig(deviceConfig);
Debug( _log, "whiteAlgorithm : %s", _whiteAlgorithm.c_str());
_led_string.freq = freq;
_led_string.dmanum = dmanum;
if (pwmchannel != 0 && pwmchannel != 1)
{
throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1.");
}
_led_string.channel[_channel].gpionum = gpio;
_led_string.channel[_channel].invert = invert;
_led_string.channel[_channel].count = leds;
_led_string.channel[_channel].brightness = 255;
_led_string.channel[_channel].strip_type = ((rgbw == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB);
_led_string.channel[!_channel].gpionum = 0;
_led_string.channel[!_channel].invert = invert;
_led_string.channel[!_channel].count = 0;
_led_string.channel[!_channel].brightness = 0;
_led_string.channel[!_channel].strip_type = WS2811_STRIP_RGB;
if (ws2811_init(&_led_string) < 0)
{
throw std::runtime_error("Unable to initialize ws281x library.");
@@ -36,6 +18,38 @@ LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t
_initialized = true;
}
bool LedDeviceWS281x::setConfig(const Json::Value &deviceConfig)
{
_whiteAlgorithm = deviceConfig.get("white_algorithm","").asString();
_channel = deviceConfig.get("pwmchannel", 0).asInt();
if (_channel != 0 && _channel != 1)
{
throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1.");
}
_led_string.freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt();
_led_string.dmanum = deviceConfig.get("dmanum", 5).asInt();
_led_string.channel[_channel].gpionum = deviceConfig.get("gpio", 18).asInt();
_led_string.channel[_channel].count = deviceConfig.get("leds", 256).asInt();
_led_string.channel[_channel].invert = deviceConfig.get("invert", 0).asInt();
_led_string.channel[_channel].strip_type = ((deviceConfig.get("rgbw", 0).asInt() == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB);
_led_string.channel[_channel].brightness = 255;
_led_string.channel[!_channel].gpionum = 0;
_led_string.channel[!_channel].invert = _led_string.channel[_channel].invert;
_led_string.channel[!_channel].count = 0;
_led_string.channel[!_channel].brightness = 0;
_led_string.channel[!_channel].strip_type = WS2811_STRIP_RGB;
return true;
}
LedDevice* LedDeviceWS281x::construct(const Json::Value &deviceConfig)
{
return new LedDeviceWS281x(deviceConfig);
}
// Send new values down the LED chain
int LedDeviceWS281x::write(const std::vector<ColorRgb> &ledValues)
{