multi fix commit (#112)

* multi fix commit

- refactoring leddevicefactory
- adalight: default for "delayAfterConnect" is 1s now - needed for most arduino's because of there special behaviour on open
- fadecandy: new option for disabling configuration send - if you want to keep your fadecandy defaults
- Hyperion.cpp: simplify createSmoothing discussed in #105
- smoothing:
-- add option for continuous output
-- when updatedelay>0 and continousOutput is disabled, buffer is flushed correctly after no input is detected

* add doxygen to travis
This commit is contained in:
redPanther 2016-07-13 11:18:12 +02:00 committed by brindosch
parent 1cf7fd545e
commit 5a2ef6c4a3
14 changed files with 212 additions and 255 deletions

View File

@ -11,6 +11,6 @@ fi
# install linux deps for hyperion compile # install linux deps for hyperion compile
if [[ $TRAVIS_OS_NAME == 'linux' ]]; then if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
echo "Install linux deps" echo "Install linux deps"
sudo apt-get -qq update ; sudo apt-get install -qq -y qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev sudo apt-get -qq update ; sudo apt-get install -qq -y qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev doxygen
fi fi

View File

@ -58,10 +58,11 @@
/// Next to the list with color transforms there is also a smoothing option. /// Next to the list with color transforms there is also a smoothing option.
/// * 'smoothing' : Smoothing of the colors in the time-domain with the following tuning /// * 'smoothing' : Smoothing of the colors in the time-domain with the following tuning
/// parameters: /// parameters:
/// - 'type' The type of smoothing algorithm ('linear' or 'none') /// - 'type' The type of smoothing algorithm ('linear' or 'none')
/// - 'time_ms' The time constant for smoothing algorithm in milliseconds /// - 'time_ms' The time constant for smoothing algorithm in milliseconds
/// - 'updateFrequency' The update frequency of the leds in Hz /// - 'updateFrequency' The update frequency of the leds in Hz
/// - 'updateDelay' The delay of the output to leds (in periods of smoothing) /// - 'updateDelay' The delay of the output to leds (in periods of smoothing)
/// - 'continuousOutput' Flag for enabling continuous output to Leds regardless of new input or not
"color" : "color" :
{ {
"channelAdjustment" : "channelAdjustment" :
@ -133,11 +134,12 @@
"smoothing" : "smoothing" :
{ {
"enable" : true, "enable" : true,
"type" : "linear", "type" : "linear",
"time_ms" : 200, "time_ms" : 200,
"updateFrequency" : 20.0000, "updateFrequency" : 20.0000,
"updateDelay" : 0 "updateDelay" : 0,
"continuousOutput" : true
} }
}, },

View File

@ -83,11 +83,12 @@
], ],
"smoothing" : "smoothing" :
{ {
"enable" : true, "enable" : true,
"type" : "linear", "type" : "linear",
"time_ms" : 200, "time_ms" : 200,
"updateFrequency" : 20.0000, "updateFrequency" : 20.0000,
"updateDelay" : 0 "updateDelay" : 0,
"continuousOutput" : false
} }
}, },

View File

@ -33,6 +33,13 @@ public:
/// Switch the leds off /// Switch the leds off
virtual int switchOff() = 0; virtual int switchOff() = 0;
///
/// Opens and configures the output device
///
/// @return Zero on succes else negative
///
int open();
protected: protected:
Logger * _log; Logger * _log;
}; };

View File

@ -481,47 +481,31 @@ LedString Hyperion::createLedString(const Json::Value& ledsConfig, const ColorOr
} }
LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice) LedDevice * Hyperion::createColorSmoothing(const Json::Value & smoothingConfig, LedDevice * ledDevice)
{ {
Logger * log = Logger::getInstance("Core"); Logger * log = Logger::getInstance("Core");
std::string type = smoothingConfig.get("type", "none").asString(); std::string type = smoothingConfig.get("type", "linear").asString();
std::transform(type.begin(), type.end(), type.begin(), ::tolower); std::transform(type.begin(), type.end(), type.begin(), ::tolower);
type = "linear"; // TODO currently hardcoded type, delete it if we have more types
if ( ! smoothingConfig.get("enable", true).asBool() ) if ( ! smoothingConfig.get("enable", true).asBool() )
{ {
Info(log,"Smoothing disabled in config"); Info(log,"Smoothing disabled");
return ledDevice; return ledDevice;
} }
if (type == "none")
{
Info(log, "Smoothing set to none");
return ledDevice;
}
else if (type == "linear")
{
if (!smoothingConfig.isMember("time_ms"))
{
Error(log, "Unable to create smoothing of type linear because of missing parameter 'time_ms'");
}
else if (!smoothingConfig.isMember("updateFrequency"))
{
Error(log, "Unable to create smoothing of type linear because of missing parameter 'updateFrequency'");
}
else
{
const unsigned updateDelay = smoothingConfig.get("updateDelay", Json::Value(0u)).asUInt();
Info(log, "Creating linear smoothing");
return new LinearColorSmoothing(
ledDevice,
smoothingConfig["updateFrequency"].asDouble(),
smoothingConfig["time_ms"].asInt(),
updateDelay);
}
}
else
{
Error(log, "Unknown smoothing type %s.", type.c_str());
}
if (type == "linear")
{
Info(log, "Creating linear smoothing");
return new LinearColorSmoothing(
ledDevice,
smoothingConfig.get("updateFrequency", 25.0).asDouble(),
smoothingConfig.get("time_ms", 200).asInt(),
smoothingConfig.get("updateDelay", 0).asUInt(),
smoothingConfig.get("continuousOutput", false).asBool()
);
}
Error(log, "Smoothing disabled, because of unknown type '%s'.", type.c_str());
return ledDevice; return ledDevice;
} }

View File

@ -3,26 +3,24 @@
#include "LinearColorSmoothing.h" #include "LinearColorSmoothing.h"
LinearColorSmoothing::LinearColorSmoothing( LinearColorSmoothing::LinearColorSmoothing( LedDevice * ledDevice, double ledUpdateFrequency_hz, int settlingTime_ms, unsigned updateDelay, bool continuousOutput)
LedDevice * ledDevice, : QObject()
double ledUpdateFrequency_hz, , LedDevice()
int settlingTime_ms, , _ledDevice(ledDevice)
unsigned updateDelay) : , _updateInterval(1000 / ledUpdateFrequency_hz)
QObject(), , _settlingTime(settlingTime_ms)
LedDevice(), , _timer()
_ledDevice(ledDevice), , _outputDelay(updateDelay)
_updateInterval(1000 / ledUpdateFrequency_hz), , _writeToLedsEnable(true)
_settlingTime(settlingTime_ms), , _continuousOutput(continuousOutput)
_timer(),
_outputDelay(updateDelay),
_writeToLedsEnable(true)
{ {
_timer.setSingleShot(false); _timer.setSingleShot(false);
_timer.setInterval(_updateInterval); _timer.setInterval(_updateInterval);
connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds())); connect(&_timer, SIGNAL(timeout()), this, SLOT(updateLeds()));
Info(Logger::getInstance("Smoothing"), "Created linear-smoothing with interval_ms: %d, settlingTime_ms: %d, updateDelay: %d", Info(Logger::getInstance("Smoothing"),
"Created linear-smoothing with interval: %d ms, settlingTime: %d ms, updateDelay: %d frames",
_updateInterval, settlingTime_ms, _outputDelay ); _updateInterval, settlingTime_ms, _outputDelay );
} }
@ -84,7 +82,7 @@ void LinearColorSmoothing::updateLeds()
_previousTime = now; _previousTime = now;
queueColors(_previousValues); queueColors(_previousValues);
_writeToLedsEnable = false; _writeToLedsEnable = _continuousOutput;
} }
else else
{ {
@ -116,14 +114,18 @@ void LinearColorSmoothing::queueColors(const std::vector<ColorRgb> & ledColors)
} }
else else
{ {
// Push the new colors in the delay-buffer // Push new colors in the delay-buffer
_outputQueue.push_back(ledColors); if ( _writeToLedsEnable )
_outputQueue.push_back(ledColors);
// If the delay-buffer is filled pop the front and write to device // If the delay-buffer is filled pop the front and write to device
if (_outputQueue.size() > _outputDelay) if (_outputQueue.size() > 0 )
{ {
if ( _writeToLedsEnable ) if ( _outputQueue.size() > _outputDelay || !_writeToLedsEnable )
{
_ledDevice->write(_outputQueue.front()); _ledDevice->write(_outputQueue.front());
_outputQueue.pop_front(); _outputQueue.pop_front();
}
} }
} }
} }

View File

@ -24,7 +24,7 @@ public:
/// @param LedUpdatFrequency The frequency at which the leds will be updated (Hz) /// @param LedUpdatFrequency The frequency at which the leds will be updated (Hz)
/// @param settingTime The time after which the updated led values have been fully applied (sec) /// @param settingTime The time after which the updated led values have been fully applied (sec)
/// @param updateDelay The number of frames to delay outgoing led updates /// @param updateDelay The number of frames to delay outgoing led updates
LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime, unsigned updateDelay); LinearColorSmoothing(LedDevice *ledDevice, double ledUpdateFrequency, int settlingTime, unsigned updateDelay, bool continuousOutput);
/// Destructor /// Destructor
virtual ~LinearColorSmoothing(); virtual ~LinearColorSmoothing();
@ -75,11 +75,14 @@ private:
/// The previously written led data /// The previously written led data
std::vector<ColorRgb> _previousValues; std::vector<ColorRgb> _previousValues;
/** The number of updates to keep in the output queue (delayed) before being output */ /// The number of updates to keep in the output queue (delayed) before being output
const unsigned _outputDelay; const unsigned _outputDelay;
/** The output queue */ /// The output queue
std::list<std::vector<ColorRgb> > _outputQueue; std::list<std::vector<ColorRgb> > _outputQueue;
// prevent sending data to device when no intput data is sent /// Prevent sending data to device when no intput data is sent
bool _writeToLedsEnable; bool _writeToLedsEnable;
/// Flag for dis/enable continuous output to led device regardless there is new data or not
bool _continuousOutput;
}; };

View File

@ -4,3 +4,9 @@ LedDevice::LedDevice()
: _log(Logger::getInstance("LedDevice")) : _log(Logger::getInstance("LedDevice"))
{ {
} }
int LedDevice::open()
{
//dummy implemention
return 0;
}

View File

@ -65,112 +65,83 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
if (false) {} if (false) {}
else if (type == "adalight") else if (type == "adalight")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceAdalight(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
const int delay_ms = deviceConfig["delayAfterConnect"].asInt(); deviceConfig["rate"].asInt(),
deviceConfig.get("delayAfterConnect",1000).asInt()
LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate, delay_ms); );
deviceAdalight->open();
device = deviceAdalight;
} }
else if (type == "adalightapa102") else if (type == "adalightapa102")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceAdalightApa102(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
const int delay_ms = deviceConfig["delayAfterConnect"].asInt(); deviceConfig["rate"].asInt(),
deviceConfig.get("delayAfterConnect",1000).asInt()
LedDeviceAdalightApa102* deviceAdalightApa102 = new LedDeviceAdalightApa102(output, rate, delay_ms); );
deviceAdalightApa102->open();
device = deviceAdalightApa102;
} }
#ifdef ENABLE_SPIDEV #ifdef ENABLE_SPIDEV
else if (type == "lpd6803" || type == "ldp6803") else if (type == "lpd6803" || type == "ldp6803")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceLpd6803(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
deviceConfig["rate"].asInt()
LedDeviceLpd6803* deviceLdp6803 = new LedDeviceLpd6803(output, rate); );
deviceLdp6803->open();
device = deviceLdp6803;
} }
else if (type == "lpd8806" || type == "ldp8806") else if (type == "lpd8806" || type == "ldp8806")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceLpd8806(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
deviceConfig["rate"].asInt()
LedDeviceLpd8806* deviceLpd8806 = new LedDeviceLpd8806(output, rate); );
deviceLpd8806->open();
device = deviceLpd8806;
} }
else if (type == "p9813") else if (type == "p9813")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceP9813(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
deviceConfig["rate"].asInt()
LedDeviceP9813* deviceP9813 = new LedDeviceP9813(output, rate); );
deviceP9813->open();
device = deviceP9813;
} }
else if (type == "apa102") else if (type == "apa102")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceAPA102(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
deviceConfig["rate"].asInt()
LedDeviceAPA102* deviceAPA102 = new LedDeviceAPA102(output, rate); );
deviceAPA102->open();
device = deviceAPA102;
} }
else if (type == "ws2801" || type == "lightberry") else if (type == "ws2801" || type == "lightberry")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceWs2801(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
const unsigned latchtime = deviceConfig.get("latchtime",500000).asInt(); deviceConfig["rate"].asInt(),
deviceConfig.get("latchtime",500000).asInt()
LedDeviceWs2801* deviceWs2801 = new LedDeviceWs2801(output, rate, latchtime); );
deviceWs2801->open();
device = deviceWs2801;
} }
else if (type == "ws2812spi") else if (type == "ws2812spi")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceWs2812SPI(
const unsigned rate = deviceConfig.get("rate",2857143).asInt(); deviceConfig["output"].asString(),
deviceConfig.get("rate",2857143).asInt()
LedDeviceWs2812SPI* deviceWs2812SPI = new LedDeviceWs2812SPI(output, rate); );
deviceWs2812SPI->open();
device = deviceWs2812SPI;
} }
else if (type == "sk6812rgbw-spi") else if (type == "sk6812rgbw-spi")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceSk6812SPI(
const unsigned rate = deviceConfig.get("rate",2857143).asInt(); deviceConfig["output"].asString(),
const std::string& whiteAlgorithm = deviceConfig.get("white_algorithm","").asString(); deviceConfig.get("rate",2857143).asInt(),
deviceConfig.get("white_algorithm","").asString()
LedDeviceSk6812SPI* deviceSk6812SPI = new LedDeviceSk6812SPI(output, rate, whiteAlgorithm); );
deviceSk6812SPI->open();
device = deviceSk6812SPI;
} }
#endif #endif
#ifdef ENABLE_TINKERFORGE #ifdef ENABLE_TINKERFORGE
else if (type=="tinkerforge") else if (type=="tinkerforge")
{ {
const std::string host = deviceConfig.get("output", "127.0.0.1").asString(); device = new LedDeviceTinkerforge(
const uint16_t port = deviceConfig.get("port", 4223).asInt(); deviceConfig.get("output", "127.0.0.1").asString(),
const std::string uid = deviceConfig["uid"].asString(); deviceConfig.get("port", 4223).asInt(),
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["uid"].asString(),
deviceConfig["rate"].asInt()
);
LedDeviceTinkerforge* deviceTinkerforge = new LedDeviceTinkerforge(host, port, uid, rate);
deviceTinkerforge->open();
device = deviceTinkerforge;
} }
#endif #endif
else if (type == "rawhid") else if (type == "rawhid")
@ -183,26 +154,17 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
auto VendorId = std::stoul(VendorIdString, nullptr, 16); auto VendorId = std::stoul(VendorIdString, nullptr, 16);
auto ProductId = std::stoul(ProductIdString, nullptr, 16); auto ProductId = std::stoul(ProductIdString, nullptr, 16);
LedDeviceRawHID* deviceHID = new LedDeviceRawHID(VendorId, ProductId, delay_ms); device = new LedDeviceRawHID(VendorId, ProductId, delay_ms);
deviceHID->open();
device = deviceHID;
} }
else if (type == "lightpack") else if (type == "lightpack")
{ {
const std::string output = deviceConfig.get("output", "").asString(); device = new LedDeviceLightpack(
deviceConfig.get("output", "").asString()
LedDeviceLightpack* deviceLightpack = new LedDeviceLightpack(); );
deviceLightpack->open(output);
device = deviceLightpack;
} }
else if (type == "multi-lightpack") else if (type == "multi-lightpack")
{ {
LedDeviceMultiLightpack* deviceLightpack = new LedDeviceMultiLightpack(); device = new LedDeviceMultiLightpack();
deviceLightpack->open();
device = deviceLightpack;
} }
else if (type == "paintpack") else if (type == "paintpack")
{ {
@ -214,10 +176,7 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
auto VendorId = std::stoul(VendorIdString, nullptr, 16); auto VendorId = std::stoul(VendorIdString, nullptr, 16);
auto ProductId = std::stoul(ProductIdString, nullptr, 16); auto ProductId = std::stoul(ProductIdString, nullptr, 16);
LedDevicePaintpack * devicePainLightpack = new LedDevicePaintpack(VendorId, ProductId, delay_ms); device = new LedDevicePaintpack(VendorId, ProductId, delay_ms);
devicePainLightpack->open();
device = devicePainLightpack;
} }
else if (type == "piblaster") else if (type == "piblaster")
{ {
@ -225,41 +184,30 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
const std::string assignment = deviceConfig.get("assignment", "").asString(); const std::string assignment = deviceConfig.get("assignment", "").asString();
const Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue); const Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue);
if (assignment.length() > 0) { if (! assignment.empty())
Error(log, "Piblaster: The piblaster configuration syntax has changed in this version."); {
exit(EXIT_FAILURE); throw std::runtime_error("Piblaster: The piblaster configuration syntax has changed in this version.");
} }
if (! gpioMapping.isNull() ) { if (gpioMapping.isNull())
LedDevicePiBlaster * devicePiBlaster = new LedDevicePiBlaster(output, gpioMapping); {
devicePiBlaster->open(); throw std::runtime_error("Piblaster: no gpiomap defined.");
device = devicePiBlaster;
} else {
Error(log, "Piblaster: no gpiomap defined.");
exit(EXIT_FAILURE);
} }
device = new LedDevicePiBlaster(output, gpioMapping);
} }
else if (type == "sedu") else if (type == "sedu")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceSedu(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
deviceConfig["rate"].asInt()
LedDeviceSedu* deviceSedu = new LedDeviceSedu(output, rate); );
deviceSedu->open();
device = deviceSedu;
} }
else if (type == "hyperion-usbasp-ws2801") else if (type == "hyperion-usbasp-ws2801")
{ {
LedDeviceHyperionUsbasp * deviceHyperionUsbasp = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2801); device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2801);
deviceHyperionUsbasp->open();
device = deviceHyperionUsbasp;
} }
else if (type == "hyperion-usbasp-ws2812") else if (type == "hyperion-usbasp-ws2812")
{ {
LedDeviceHyperionUsbasp * deviceHyperionUsbasp = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2812); device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2812);
deviceHyperionUsbasp->open();
device = deviceHyperionUsbasp;
} }
else if (type == "philipshue") else if (type == "philipshue")
{ {
@ -309,62 +257,54 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
} }
else if (type == "udp") else if (type == "udp")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceUdp(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
const unsigned protocol = deviceConfig["protocol"].asInt(); deviceConfig["rate"].asInt(),
const unsigned maxPacket = deviceConfig["maxpacket"].asInt(); deviceConfig["protocol"].asInt(),
device = new LedDeviceUdp(output, rate, protocol, maxPacket); deviceConfig["maxpacket"].asInt()
);
} }
else if (type == "udpraw") else if (type == "udpraw")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceUdpRaw(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
const unsigned latchtime = deviceConfig.get("latchtime",500000).asInt(); deviceConfig["rate"].asInt(),
deviceConfig.get("latchtime",500000).asInt()
LedDeviceUdpRaw* deviceUdpRaw = new LedDeviceUdpRaw(output, rate, latchtime); );
deviceUdpRaw->open();
device = deviceUdpRaw;
} }
else if (type == "tpm2") else if (type == "tpm2")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceTpm2(
const unsigned rate = deviceConfig["rate"].asInt(); deviceConfig["output"].asString(),
deviceConfig["rate"].asInt()
LedDeviceTpm2 * deviceTpm2 = new LedDeviceTpm2(output, rate); );
deviceTpm2->open();
device = deviceTpm2;
} }
else if (type == "atmo") else if (type == "atmo")
{ {
const std::string output = deviceConfig["output"].asString(); device = new LedDeviceAtmo(
const unsigned rate = 38400; deviceConfig["output"].asString(),
38400
LedDeviceAtmo * deviceAtmo = new LedDeviceAtmo(output, rate); );
deviceAtmo->open();
device = deviceAtmo;
} }
#ifdef ENABLE_WS2812BPWM #ifdef ENABLE_WS2812BPWM
else if (type == "ws2812b") else if (type == "ws2812b")
{ {
LedDeviceWS2812b * ledDeviceWS2812b = new LedDeviceWS2812b(); device = new LedDeviceWS2812b();
device = ledDeviceWS2812b;
} }
#endif #endif
#ifdef ENABLE_WS281XPWM #ifdef ENABLE_WS281XPWM
else if (type == "ws281x") else if (type == "ws281x")
{ {
const int gpio = deviceConfig.get("gpio", 18).asInt(); device = new LedDeviceWS281x(
const int leds = deviceConfig.get("leds", 256).asInt(); deviceConfig.get("gpio", 18).asInt();
const uint32_t freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt(); leds = deviceConfig.get("leds", 256).asInt();
const int dmanum = deviceConfig.get("dmanum", 5).asInt(); freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt();
const int pwmchannel = deviceConfig.get("pwmchannel", 0).asInt(); dmanum = deviceConfig.get("dmanum", 5).asInt();
const int invert = deviceConfig.get("invert", 0).asInt(); deviceConfig.get("pwmchannel", 0).asInt();
const int rgbw = deviceConfig.get("rgbw", 0).asInt(); deviceConfig.get("invert", 0).asInt();
const std::string& whiteAlgorithm = deviceConfig.get("white_algorithm","").asString(); deviceConfig.get("rgbw", 0).asInt();
whiteAlgorithm = deviceConfig.get("white_algorithm","").asString();
LedDeviceWS281x * ledDeviceWS281x = new LedDeviceWS281x(gpio, leds, freq, dmanum, pwmchannel, invert, );
rgbw, whiteAlgorithm);
device = ledDeviceWS281x;
} }
#endif #endif
else else
@ -373,9 +313,12 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
{ {
Error(log, "Dummy device used, because unknown device %s set.", type.c_str()); Error(log, "Dummy device used, because unknown device %s set.", type.c_str());
} }
const std::string output = deviceConfig.get("output", "/dev/null").asString(); device = new LedDeviceFile(
device = new LedDeviceFile(output); deviceConfig.get("output", "/dev/null").asString()
);
} }
device->open();
return device; return device;
} }

View File

@ -26,14 +26,15 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy()
bool LedDeviceFadeCandy::setConfig(const Json::Value &deviceConfig) bool LedDeviceFadeCandy::setConfig(const Json::Value &deviceConfig)
{ {
_host = deviceConfig.get("output", "127.0.0.1").asString(); _host = deviceConfig.get("output", "127.0.0.1").asString();
_port = deviceConfig.get("port", 7890).asInt(); _port = deviceConfig.get("port", 7890).asInt();
_channel = deviceConfig.get("channel", 0).asInt(); _channel = deviceConfig.get("channel", 0).asInt();
_gamma = deviceConfig.get("gamma", 1.0).asDouble(); _gamma = deviceConfig.get("gamma", 1.0).asDouble();
_noDither = ! deviceConfig.get("dither", false).asBool(); _noDither = ! deviceConfig.get("dither", false).asBool();
_noInterp = ! deviceConfig.get("interpolation", false).asBool(); _noInterp = ! deviceConfig.get("interpolation", false).asBool();
_manualLED = deviceConfig.get("manualLed", false).asBool(); _manualLED = deviceConfig.get("manualLed", false).asBool();
_ledOnOff = deviceConfig.get("ledOn", false).asBool(); _ledOnOff = deviceConfig.get("ledOn", false).asBool();
_setFcConfig = deviceConfig.get("setFcConfig", false).asBool();
_whitePoint_r = 1.0; _whitePoint_r = 1.0;
_whitePoint_g = 1.0; _whitePoint_g = 1.0;
@ -62,8 +63,11 @@ bool LedDeviceFadeCandy::tryConnect()
_client.connectToHost( _host.c_str(), _port); _client.connectToHost( _host.c_str(), _port);
if ( _client.waitForConnected(1000) ) if ( _client.waitForConnected(1000) )
{ {
sendFadeCandyConfiguration();
Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", _host.c_str(), _port, _channel); Info(_log,"fadecandy/opc: connected to %s:%i on channel %i", _host.c_str(), _port, _channel);
if (_setFcConfig)
{
sendFadeCandyConfiguration();
}
} }
} }
@ -145,6 +149,7 @@ int LedDeviceFadeCandy::sendSysEx(uint8_t systemId, uint8_t commandId, QByteArra
void LedDeviceFadeCandy::sendFadeCandyConfiguration() void LedDeviceFadeCandy::sendFadeCandyConfiguration()
{ {
Debug(_log, "send configuration to fadecandy");
QString data = "{\"gamma\": "+QString::number(_gamma,'g',4)+", \"whitepoint\": ["+QString::number(_whitePoint_r,'g',4)+", "+QString::number(_whitePoint_g,'g',4)+", "+QString::number(_whitePoint_b,'g',4)+"]}"; QString data = "{\"gamma\": "+QString::number(_gamma,'g',4)+", \"whitepoint\": ["+QString::number(_whitePoint_r,'g',4)+", "+QString::number(_whitePoint_g,'g',4)+", "+QString::number(_whitePoint_b,'g',4)+"]}";
sendSysEx(1, 1, data.toLocal8Bit() ); sendSysEx(1, 1, data.toLocal8Bit() );

View File

@ -29,6 +29,7 @@ public:
/// "type" : "fadecandy", /// "type" : "fadecandy",
/// "output" : "localhost", /// "output" : "localhost",
/// "colorOrder" : "rgb", /// "colorOrder" : "rgb",
/// "setFcConfig" : false,
/// "gamma" : 1.0, /// "gamma" : 1.0,
/// "whitepoint" : [1.0, 1.0, 1.0], /// "whitepoint" : [1.0, 1.0, 1.0],
/// "dither" : false, /// "dither" : false,
@ -74,6 +75,7 @@ private:
QByteArray _opc_data; QByteArray _opc_data;
// fadecandy sysEx // fadecandy sysEx
bool _setFcConfig;
double _gamma; double _gamma;
double _whitePoint_r; double _whitePoint_r;
double _whitePoint_g; double _whitePoint_g;

View File

@ -32,17 +32,17 @@ enum DATA_VERSION_INDEXES{
INDEX_FW_VER_MINOR INDEX_FW_VER_MINOR
}; };
LedDeviceLightpack::LedDeviceLightpack() : LedDeviceLightpack::LedDeviceLightpack(const std::string & serialNumber)
LedDevice(), : LedDevice()
_libusbContext(nullptr), , _libusbContext(nullptr)
_deviceHandle(nullptr), , _deviceHandle(nullptr)
_busNumber(-1), , _busNumber(-1)
_addressNumber(-1), , _addressNumber(-1)
_serialNumber(""), , _serialNumber(serialNumber)
_firmwareVersion({-1,-1}), , _firmwareVersion({-1,-1})
_ledCount(-1), , _ledCount(-1)
_bitsPerChannel(-1), , _bitsPerChannel(-1)
_ledBuffer() , _ledBuffer()
{ {
} }
@ -64,7 +64,7 @@ LedDeviceLightpack::~LedDeviceLightpack()
} }
} }
int LedDeviceLightpack::open(const std::string & serialNumber) int LedDeviceLightpack::open()
{ {
int error; int error;
@ -86,7 +86,7 @@ int LedDeviceLightpack::open(const std::string & serialNumber)
for (ssize_t i = 0 ; i < deviceCount; ++i) for (ssize_t i = 0 ; i < deviceCount; ++i)
{ {
// try to open and initialize the device // try to open and initialize the device
error = testAndOpen(deviceList[i], serialNumber); error = testAndOpen(deviceList[i], _serialNumber);
if (error == 0) if (error == 0)
{ {

View File

@ -20,7 +20,9 @@ public:
/// ///
/// Constructs the LedDeviceLightpack /// Constructs the LedDeviceLightpack
/// ///
LedDeviceLightpack(); /// @param serialNumber serial output device
///
LedDeviceLightpack(const std::string & serialNumber = "");
/// ///
/// Destructor of the LedDevice; closes the output device if it is open /// Destructor of the LedDevice; closes the output device if it is open
@ -32,7 +34,7 @@ public:
/// ///
/// @return Zero on succes else negative /// @return Zero on succes else negative
/// ///
int open(const std::string & serialNumber = ""); int open();
/// ///
/// Writes the RGB-Color values to the leds. /// Writes the RGB-Color values to the leds.

View File

@ -42,8 +42,8 @@ int LedDeviceMultiLightpack::open()
// open each lightpack device // open each lightpack device
for (const std::string & serial : serialList) for (const std::string & serial : serialList)
{ {
LedDeviceLightpack * device = new LedDeviceLightpack(); LedDeviceLightpack * device = new LedDeviceLightpack(serial);
int error = device->open(serial); int error = device->open();
if (error == 0) if (error == 0)
{ {