2014-02-07 14:55:54 +01:00
|
|
|
// Stl includes
|
|
|
|
#include <string>
|
2016-06-23 00:11:09 +02:00
|
|
|
#include <sstream>
|
2014-02-07 14:55:54 +01:00
|
|
|
#include <algorithm>
|
2016-08-08 00:17:00 +02:00
|
|
|
#include <exception>
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2014-01-04 11:35:11 +01:00
|
|
|
// Build configuration
|
2013-12-29 20:43:01 +01:00
|
|
|
#include <HyperionConfig.h>
|
|
|
|
|
2013-12-17 19:50:15 +01:00
|
|
|
// Leddevice includes
|
|
|
|
#include <leddevice/LedDeviceFactory.h>
|
2016-06-25 22:08:17 +02:00
|
|
|
#include <utils/Logger.h>
|
2013-12-17 19:50:15 +01:00
|
|
|
|
|
|
|
// Local Leddevice includes
|
2013-12-17 22:53:16 +01:00
|
|
|
#ifdef ENABLE_SPIDEV
|
|
|
|
#include "LedDeviceLpd6803.h"
|
|
|
|
#include "LedDeviceLpd8806.h"
|
2014-01-18 13:43:39 +01:00
|
|
|
#include "LedDeviceP9813.h"
|
2014-01-18 23:49:32 +01:00
|
|
|
#include "LedDeviceWs2801.h"
|
2016-05-15 18:39:17 +02:00
|
|
|
#include "LedDeviceWs2812SPI.h"
|
2016-06-27 22:43:35 +02:00
|
|
|
#include "LedDeviceSk6812SPI.h"
|
2014-12-03 09:34:48 +01:00
|
|
|
#include "LedDeviceAPA102.h"
|
2013-12-17 22:53:16 +01:00
|
|
|
#endif
|
|
|
|
|
2014-03-04 20:38:54 +01:00
|
|
|
#ifdef ENABLE_TINKERFORGE
|
|
|
|
#include "LedDeviceTinkerforge.h"
|
|
|
|
#endif
|
|
|
|
|
2014-01-04 11:35:11 +01:00
|
|
|
#include "LedDeviceAdalight.h"
|
2015-11-08 16:31:18 +01:00
|
|
|
#include "LedDeviceRawHID.h"
|
2014-01-04 11:35:11 +01:00
|
|
|
#include "LedDeviceLightpack.h"
|
|
|
|
#include "LedDeviceMultiLightpack.h"
|
|
|
|
#include "LedDevicePaintpack.h"
|
|
|
|
#include "LedDevicePiBlaster.h"
|
2013-12-17 19:50:15 +01:00
|
|
|
#include "LedDeviceSedu.h"
|
2016-03-23 11:12:34 +01:00
|
|
|
#include "LedDeviceFile.h"
|
2016-01-04 12:16:44 +01:00
|
|
|
#include "LedDeviceFadeCandy.h"
|
2016-01-06 10:40:48 +01:00
|
|
|
#include "LedDeviceUdp.h"
|
2016-05-30 23:58:31 +02:00
|
|
|
#include "LedDeviceUdpRaw.h"
|
2016-08-19 17:14:52 +02:00
|
|
|
#include "LedDeviceUdpE131.h"
|
2014-03-09 11:36:46 +01:00
|
|
|
#include "LedDeviceHyperionUsbasp.h"
|
2014-04-27 12:59:44 +02:00
|
|
|
#include "LedDevicePhilipsHue.h"
|
2014-06-15 02:19:09 +02:00
|
|
|
#include "LedDeviceTpm2.h"
|
2015-02-04 21:49:33 +01:00
|
|
|
#include "LedDeviceAtmo.h"
|
2015-10-13 19:11:01 +02:00
|
|
|
#include "LedDeviceAdalightApa102.h"
|
2016-03-14 20:19:19 +01:00
|
|
|
#include "LedDeviceAtmoOrb.h"
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2014-09-19 16:37:58 +02:00
|
|
|
#ifdef ENABLE_WS2812BPWM
|
|
|
|
#include "LedDeviceWS2812b.h"
|
|
|
|
#endif
|
2014-09-16 00:17:23 +02:00
|
|
|
|
2016-03-04 09:07:02 +01:00
|
|
|
#ifdef ENABLE_WS281XPWM
|
|
|
|
#include "LedDeviceWS281x.h"
|
|
|
|
#endif
|
|
|
|
|
2013-12-17 19:50:15 +01:00
|
|
|
LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
|
|
|
{
|
2016-06-25 22:08:17 +02:00
|
|
|
Logger * log = Logger::getInstance("LedDevice");
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << deviceConfig;
|
|
|
|
Info(log, "configuration: %s ", ss.str().c_str());
|
2013-12-17 19:50:15 +01:00
|
|
|
|
|
|
|
std::string type = deviceConfig.get("type", "UNSPECIFIED").asString();
|
|
|
|
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
|
|
|
|
|
|
|
LedDevice* device = nullptr;
|
2016-08-08 00:17:00 +02:00
|
|
|
try
|
2013-12-17 19:50:15 +01:00
|
|
|
{
|
2016-08-08 00:17:00 +02:00
|
|
|
if (false) {}
|
|
|
|
else if (type == "adalight")
|
|
|
|
{
|
|
|
|
device = new LedDeviceAdalight(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
|
|
|
deviceConfig.get("delayAfterConnect",500).asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "adalightapa102")
|
|
|
|
{
|
|
|
|
device = new LedDeviceAdalightApa102(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
|
|
|
deviceConfig.get("delayAfterConnect",500).asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#ifdef ENABLE_SPIDEV
|
|
|
|
else if (type == "lpd6803" || type == "ldp6803")
|
|
|
|
{
|
|
|
|
device = new LedDeviceLpd6803(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "lpd8806" || type == "ldp8806")
|
|
|
|
{
|
|
|
|
device = new LedDeviceLpd8806(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "p9813")
|
|
|
|
{
|
|
|
|
device = new LedDeviceP9813(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "apa102")
|
|
|
|
{
|
|
|
|
device = new LedDeviceAPA102(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "ws2801" || type == "lightberry")
|
|
|
|
{
|
|
|
|
device = new LedDeviceWs2801(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
2016-08-13 19:54:08 +02:00
|
|
|
deviceConfig.get("latchtime",500000).asInt(),
|
|
|
|
deviceConfig.get("spimode",0).asInt(),
|
|
|
|
deviceConfig.get("invert",false).asBool()
|
2016-08-08 00:17:00 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "ws2812spi")
|
|
|
|
{
|
|
|
|
device = new LedDeviceWs2812SPI(
|
|
|
|
deviceConfig["output"].asString(),
|
2016-08-13 19:54:08 +02:00
|
|
|
deviceConfig.get("rate",2857143).asInt(),
|
|
|
|
deviceConfig.get("spimode",0).asInt(),
|
|
|
|
deviceConfig.get("invert",false).asBool()
|
2016-08-08 00:17:00 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "sk6812rgbw-spi")
|
|
|
|
{
|
|
|
|
device = new LedDeviceSk6812SPI(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig.get("rate",2857143).asInt(),
|
2016-08-13 19:54:08 +02:00
|
|
|
deviceConfig.get("white_algorithm","").asString(),
|
|
|
|
deviceConfig.get("spimode",0).asInt(),
|
|
|
|
deviceConfig.get("invert",false).asBool()
|
2016-08-08 00:17:00 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_TINKERFORGE
|
|
|
|
else if (type=="tinkerforge")
|
|
|
|
{
|
|
|
|
device = new LedDeviceTinkerforge(
|
|
|
|
deviceConfig.get("output", "127.0.0.1").asString(),
|
|
|
|
deviceConfig.get("port", 4223).asInt(),
|
|
|
|
deviceConfig["uid"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2014-03-04 20:38:54 +01:00
|
|
|
|
2016-08-08 00:17:00 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (type == "rawhid")
|
|
|
|
{
|
|
|
|
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
|
|
|
|
auto VendorIdString = deviceConfig.get("VID", "0x2341").asString();
|
|
|
|
auto ProductIdString = deviceConfig.get("PID", "0x8036").asString();
|
2015-11-08 16:31:18 +01:00
|
|
|
|
2016-08-08 00:17:00 +02:00
|
|
|
// Convert HEX values to integer
|
|
|
|
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
|
|
|
|
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
|
2015-11-08 16:31:18 +01:00
|
|
|
|
2016-08-08 00:17:00 +02:00
|
|
|
device = new LedDeviceRawHID(VendorId, ProductId, delay_ms);
|
|
|
|
}
|
|
|
|
else if (type == "lightpack")
|
|
|
|
{
|
|
|
|
device = new LedDeviceLightpack(
|
|
|
|
deviceConfig.get("output", "").asString()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "multi-lightpack")
|
|
|
|
{
|
|
|
|
device = new LedDeviceMultiLightpack();
|
|
|
|
}
|
|
|
|
else if (type == "paintpack")
|
|
|
|
{
|
|
|
|
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
|
|
|
|
auto VendorIdString = deviceConfig.get("VID", "0x0EBF").asString();
|
|
|
|
auto ProductIdString = deviceConfig.get("PID", "0x0025").asString();
|
2015-11-08 16:32:53 +01:00
|
|
|
|
2016-08-08 00:17:00 +02:00
|
|
|
// Convert HEX values to integer
|
|
|
|
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
|
|
|
|
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
|
2015-11-08 16:32:53 +01:00
|
|
|
|
2016-08-08 00:17:00 +02:00
|
|
|
device = new LedDevicePaintpack(VendorId, ProductId, delay_ms);
|
|
|
|
}
|
|
|
|
else if (type == "piblaster")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig.get("output", "").asString();
|
|
|
|
const std::string assignment = deviceConfig.get("assignment", "").asString();
|
|
|
|
const Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue);
|
2016-04-29 16:00:33 +02:00
|
|
|
|
2016-08-08 00:17:00 +02:00
|
|
|
if (! assignment.empty())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Piblaster: The piblaster configuration syntax has changed in this version.");
|
|
|
|
}
|
|
|
|
if (gpioMapping.isNull())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Piblaster: no gpiomap defined.");
|
|
|
|
}
|
|
|
|
device = new LedDevicePiBlaster(output, gpioMapping);
|
|
|
|
}
|
|
|
|
else if (type == "sedu")
|
2016-07-13 11:18:12 +02:00
|
|
|
{
|
2016-08-08 00:17:00 +02:00
|
|
|
device = new LedDeviceSedu(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2016-04-29 16:00:33 +02:00
|
|
|
}
|
2016-08-08 00:17:00 +02:00
|
|
|
else if (type == "hyperion-usbasp-ws2801")
|
2016-07-13 11:18:12 +02:00
|
|
|
{
|
2016-08-08 00:17:00 +02:00
|
|
|
device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2801);
|
2016-04-29 16:00:33 +02:00
|
|
|
}
|
2016-08-08 00:17:00 +02:00
|
|
|
else if (type == "hyperion-usbasp-ws2812")
|
|
|
|
{
|
|
|
|
device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2812);
|
2015-03-03 15:45:09 +01:00
|
|
|
}
|
2016-08-08 00:17:00 +02:00
|
|
|
else if (type == "philipshue")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const std::string username = deviceConfig.get("username", "newdeveloper").asString();
|
|
|
|
const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool();
|
|
|
|
const int transitiontime = deviceConfig.get("transitiontime", 1).asInt();
|
|
|
|
std::vector<unsigned int> lightIds;
|
|
|
|
for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++) {
|
|
|
|
lightIds.push_back(deviceConfig["lightIds"][i].asInt());
|
|
|
|
}
|
|
|
|
device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime, lightIds);
|
|
|
|
}
|
|
|
|
else if (type == "atmoorb")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const bool useOrbSmoothing = deviceConfig.get("useOrbSmoothing", false).asBool();
|
|
|
|
const int transitiontime = deviceConfig.get("transitiontime", 1).asInt();
|
|
|
|
const int skipSmoothingDiff = deviceConfig.get("skipSmoothingDiff", 0).asInt();
|
|
|
|
const int port = deviceConfig.get("port", 1).asInt();
|
|
|
|
const int numLeds = deviceConfig.get("numLeds", 1).asInt();
|
|
|
|
const std::string orbId = deviceConfig["orbIds"].asString();
|
|
|
|
std::vector<unsigned int> orbIds;
|
2016-03-14 20:19:19 +01:00
|
|
|
|
2016-08-08 00:17:00 +02:00
|
|
|
// If we find multiple Orb ids separate them and add to list
|
|
|
|
const std::string separator (",");
|
|
|
|
if (orbId.find(separator) != std::string::npos) {
|
|
|
|
std::stringstream ss(orbId);
|
|
|
|
std::vector<int> output;
|
|
|
|
unsigned int i;
|
|
|
|
while (ss >> i) {
|
|
|
|
orbIds.push_back(i);
|
|
|
|
if (ss.peek() == ',' || ss.peek() == ' ')
|
|
|
|
ss.ignore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
orbIds.push_back(atoi(orbId.c_str()));
|
|
|
|
}
|
|
|
|
|
|
|
|
device = new LedDeviceAtmoOrb(output, useOrbSmoothing, transitiontime, skipSmoothingDiff, port, numLeds, orbIds);
|
|
|
|
}
|
|
|
|
else if (type == "fadecandy")
|
|
|
|
{
|
|
|
|
device = new LedDeviceFadeCandy(deviceConfig);
|
|
|
|
}
|
|
|
|
else if (type == "udp")
|
|
|
|
{
|
|
|
|
device = new LedDeviceUdp(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["protocol"].asInt(),
|
|
|
|
deviceConfig["maxpacket"].asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "udpraw")
|
|
|
|
{
|
|
|
|
device = new LedDeviceUdpRaw(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig.get("latchtime",500000).asInt()
|
|
|
|
);
|
|
|
|
}
|
2016-08-19 17:14:52 +02:00
|
|
|
else if (type == "e131")
|
|
|
|
{
|
|
|
|
device = new LedDeviceUdpE131(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig.get("latchtime",500000).asInt(),
|
|
|
|
deviceConfig.get("universe",1).asInt()
|
|
|
|
);
|
|
|
|
}
|
2016-08-08 00:17:00 +02:00
|
|
|
else if (type == "tpm2")
|
|
|
|
{
|
|
|
|
device = new LedDeviceTpm2(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else if (type == "atmo")
|
|
|
|
{
|
|
|
|
device = new LedDeviceAtmo(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
38400
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#ifdef ENABLE_WS2812BPWM
|
|
|
|
else if (type == "ws2812b")
|
|
|
|
{
|
|
|
|
device = new LedDeviceWS2812b();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_WS281XPWM
|
|
|
|
else if (type == "ws281x")
|
|
|
|
{
|
|
|
|
device = new LedDeviceWS281x(
|
|
|
|
deviceConfig.get("gpio", 18).asInt(),
|
|
|
|
deviceConfig.get("leds", 256).asInt(),
|
|
|
|
deviceConfig.get("freq", (Json::UInt)800000ul).asInt(),
|
|
|
|
deviceConfig.get("dmanum", 5).asInt(),
|
|
|
|
deviceConfig.get("pwmchannel", 0).asInt(),
|
|
|
|
deviceConfig.get("invert", 0).asInt(),
|
|
|
|
deviceConfig.get("rgbw", 0).asInt(),
|
|
|
|
deviceConfig.get("white_algorithm","").asString()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else if (type == "file")
|
|
|
|
{
|
|
|
|
device = new LedDeviceFile( deviceConfig.get("output", "/dev/null").asString() );
|
2016-03-15 18:37:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-19 17:14:52 +02:00
|
|
|
Error(log, "Dummy device used, because configured device '%s' is unknown", type.c_str() );
|
2016-08-08 00:17:00 +02:00
|
|
|
throw std::runtime_error("unknown device");
|
2016-03-15 18:37:55 +01:00
|
|
|
}
|
2016-05-30 23:58:31 +02:00
|
|
|
}
|
2016-08-08 00:17:00 +02:00
|
|
|
catch(std::exception e)
|
2014-06-15 02:19:09 +02:00
|
|
|
{
|
2016-08-08 00:17:00 +02:00
|
|
|
|
|
|
|
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what());
|
|
|
|
device = new LedDeviceFile( "/dev/null" );
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2016-06-25 22:08:17 +02:00
|
|
|
|
2016-07-13 11:18:12 +02:00
|
|
|
device->open();
|
|
|
|
|
2013-12-17 19:50:15 +01:00
|
|
|
return device;
|
|
|
|
}
|