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>
|
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"
|
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;
|
2013-12-17 22:53:16 +01:00
|
|
|
if (false) {}
|
2014-01-04 11:35:11 +01:00
|
|
|
else if (type == "adalight")
|
2013-12-17 19:50:15 +01:00
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceAdalight(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
2016-07-24 15:18:34 +02:00
|
|
|
deviceConfig.get("delayAfterConnect",500).asInt()
|
2016-07-13 11:18:12 +02:00
|
|
|
);
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2015-10-13 19:11:01 +02:00
|
|
|
else if (type == "adalightapa102")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceAdalightApa102(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
2016-07-24 15:18:34 +02:00
|
|
|
deviceConfig.get("delayAfterConnect",500).asInt()
|
2016-07-13 11:18:12 +02:00
|
|
|
);
|
2015-10-13 19:11:01 +02:00
|
|
|
}
|
2014-01-04 11:35:11 +01:00
|
|
|
#ifdef ENABLE_SPIDEV
|
2013-12-17 19:50:15 +01:00
|
|
|
else if (type == "lpd6803" || type == "ldp6803")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceLpd6803(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
|
|
|
else if (type == "lpd8806" || type == "ldp8806")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceLpd8806(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2014-01-18 23:57:47 +01:00
|
|
|
else if (type == "p9813")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceP9813(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2014-12-03 18:41:44 +01:00
|
|
|
}
|
2014-12-03 09:34:48 +01:00
|
|
|
else if (type == "apa102")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceAPA102(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2014-01-18 23:57:47 +01:00
|
|
|
}
|
2014-01-04 11:35:11 +01:00
|
|
|
else if (type == "ws2801" || type == "lightberry")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceWs2801(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
|
|
|
deviceConfig.get("latchtime",500000).asInt()
|
|
|
|
);
|
2014-01-04 11:35:11 +01:00
|
|
|
}
|
2016-05-15 18:39:17 +02:00
|
|
|
else if (type == "ws2812spi")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceWs2812SPI(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig.get("rate",2857143).asInt()
|
|
|
|
);
|
2016-05-15 18:39:17 +02:00
|
|
|
}
|
2016-07-10 17:07:19 +02:00
|
|
|
else if (type == "sk6812rgbw-spi")
|
2016-06-27 22:43:35 +02:00
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceSk6812SPI(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig.get("rate",2857143).asInt(),
|
|
|
|
deviceConfig.get("white_algorithm","").asString()
|
|
|
|
);
|
2016-06-27 22:43:35 +02:00
|
|
|
}
|
2013-12-19 09:29:26 +01:00
|
|
|
#endif
|
2014-03-04 20:38:54 +01:00
|
|
|
#ifdef ENABLE_TINKERFORGE
|
2014-03-09 11:42:20 +01:00
|
|
|
else if (type=="tinkerforge")
|
2014-03-04 20:38:54 +01:00
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
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
|
|
|
|
|
|
|
}
|
2013-12-19 09:29:26 +01:00
|
|
|
#endif
|
2015-11-08 16:31:18 +01:00
|
|
|
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();
|
|
|
|
|
|
|
|
// Convert HEX values to integer
|
|
|
|
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
|
|
|
|
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
|
|
|
|
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceRawHID(VendorId, ProductId, delay_ms);
|
2015-11-08 16:31:18 +01:00
|
|
|
}
|
2013-12-17 19:50:15 +01:00
|
|
|
else if (type == "lightpack")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceLightpack(
|
|
|
|
deviceConfig.get("output", "").asString()
|
|
|
|
);
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2016-03-22 01:01:54 +01:00
|
|
|
else if (type == "multi-lightpack")
|
2014-01-04 11:35:11 +01:00
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceMultiLightpack();
|
2014-01-04 11:35:11 +01:00
|
|
|
}
|
2013-12-17 19:50:15 +01:00
|
|
|
else if (type == "paintpack")
|
|
|
|
{
|
2015-11-08 16:32:53 +01:00
|
|
|
const int delay_ms = deviceConfig["delayAfterConnect"].asInt();
|
|
|
|
auto VendorIdString = deviceConfig.get("VID", "0x0EBF").asString();
|
|
|
|
auto ProductIdString = deviceConfig.get("PID", "0x0025").asString();
|
|
|
|
|
|
|
|
// Convert HEX values to integer
|
|
|
|
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
|
|
|
|
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
|
|
|
|
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDevicePaintpack(VendorId, ProductId, delay_ms);
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2014-01-04 11:35:11 +01:00
|
|
|
else if (type == "piblaster")
|
2013-12-17 19:50:15 +01:00
|
|
|
{
|
2014-01-04 11:35:11 +01:00
|
|
|
const std::string output = deviceConfig.get("output", "").asString();
|
|
|
|
const std::string assignment = deviceConfig.get("assignment", "").asString();
|
2016-04-29 16:00:33 +02:00
|
|
|
const Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue);
|
|
|
|
|
2016-07-13 11:18:12 +02:00
|
|
|
if (! assignment.empty())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Piblaster: The piblaster configuration syntax has changed in this version.");
|
2016-04-29 16:00:33 +02:00
|
|
|
}
|
2016-07-13 11:18:12 +02:00
|
|
|
if (gpioMapping.isNull())
|
|
|
|
{
|
|
|
|
throw std::runtime_error("Piblaster: no gpiomap defined.");
|
2016-04-29 16:00:33 +02:00
|
|
|
}
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDevicePiBlaster(output, gpioMapping);
|
2014-01-04 11:35:11 +01:00
|
|
|
}
|
|
|
|
else if (type == "sedu")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceSedu(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2014-03-09 11:36:46 +01:00
|
|
|
else if (type == "hyperion-usbasp-ws2801")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2801);
|
2014-03-09 11:36:46 +01:00
|
|
|
}
|
|
|
|
else if (type == "hyperion-usbasp-ws2812")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2812);
|
2014-03-09 11:36:46 +01:00
|
|
|
}
|
2014-04-27 12:59:44 +02:00
|
|
|
else if (type == "philipshue")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
2015-02-01 15:29:40 +01:00
|
|
|
const std::string username = deviceConfig.get("username", "newdeveloper").asString();
|
2014-07-16 20:22:37 +02:00
|
|
|
const bool switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool();
|
2015-02-01 15:56:51 +01:00
|
|
|
const int transitiontime = deviceConfig.get("transitiontime", 1).asInt();
|
2015-03-03 15:45:09 +01:00
|
|
|
std::vector<unsigned int> lightIds;
|
2015-03-07 09:58:48 +01:00
|
|
|
for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++) {
|
2015-03-03 15:45:09 +01:00
|
|
|
lightIds.push_back(deviceConfig["lightIds"][i].asInt());
|
|
|
|
}
|
|
|
|
device = new LedDevicePhilipsHue(output, username, switchOffOnBlack, transitiontime, lightIds);
|
2014-04-27 12:59:44 +02:00
|
|
|
}
|
2016-04-02 00:07:28 +02:00
|
|
|
else if (type == "atmoorb")
|
|
|
|
{
|
2016-03-15 12:06:24 +01:00
|
|
|
const std::string output = deviceConfig["output"].asString();
|
2016-04-02 00:07:28 +02:00
|
|
|
const bool useOrbSmoothing = deviceConfig.get("useOrbSmoothing", false).asBool();
|
2016-03-15 12:06:24 +01:00
|
|
|
const int transitiontime = deviceConfig.get("transitiontime", 1).asInt();
|
2016-04-02 00:07:28 +02:00
|
|
|
const int skipSmoothingDiff = deviceConfig.get("skipSmoothingDiff", 0).asInt();
|
2016-03-15 12:06:24 +01:00
|
|
|
const int port = deviceConfig.get("port", 1).asInt();
|
|
|
|
const int numLeds = deviceConfig.get("numLeds", 1).asInt();
|
2016-04-02 00:07:28 +02:00
|
|
|
const std::string orbId = deviceConfig["orbIds"].asString();
|
2016-03-15 12:06:24 +01:00
|
|
|
std::vector<unsigned int> orbIds;
|
2016-03-14 20:19:19 +01:00
|
|
|
|
2016-03-15 18:37:55 +01:00
|
|
|
// If we find multiple Orb ids separate them and add to list
|
|
|
|
const std::string separator (",");
|
|
|
|
if (orbId.find(separator) != std::string::npos) {
|
2016-04-02 00:07:28 +02:00
|
|
|
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();
|
|
|
|
}
|
2016-03-15 18:37:55 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-04-02 00:07:28 +02:00
|
|
|
orbIds.push_back(atoi(orbId.c_str()));
|
2016-03-15 18:37:55 +01:00
|
|
|
}
|
|
|
|
|
2016-04-02 00:07:28 +02:00
|
|
|
device = new LedDeviceAtmoOrb(output, useOrbSmoothing, transitiontime, skipSmoothingDiff, port, numLeds, orbIds);
|
|
|
|
}
|
2016-01-04 12:16:44 +01:00
|
|
|
else if (type == "fadecandy")
|
|
|
|
{
|
2016-07-12 22:37:45 +02:00
|
|
|
device = new LedDeviceFadeCandy(deviceConfig);
|
2016-01-04 12:16:44 +01:00
|
|
|
}
|
2016-01-06 10:40:48 +01:00
|
|
|
else if (type == "udp")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceUdp(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
|
|
|
deviceConfig["protocol"].asInt(),
|
|
|
|
deviceConfig["maxpacket"].asInt()
|
|
|
|
);
|
2016-01-06 10:40:48 +01:00
|
|
|
}
|
2016-05-30 23:58:31 +02:00
|
|
|
else if (type == "udpraw")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceUdpRaw(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt(),
|
|
|
|
deviceConfig.get("latchtime",500000).asInt()
|
|
|
|
);
|
2016-05-30 23:58:31 +02:00
|
|
|
}
|
2014-06-15 02:19:09 +02:00
|
|
|
else if (type == "tpm2")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceTpm2(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
deviceConfig["rate"].asInt()
|
|
|
|
);
|
2014-09-19 16:37:58 +02:00
|
|
|
}
|
2015-02-04 21:49:33 +01:00
|
|
|
else if (type == "atmo")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceAtmo(
|
|
|
|
deviceConfig["output"].asString(),
|
|
|
|
38400
|
|
|
|
);
|
2015-02-04 21:49:33 +01:00
|
|
|
}
|
2014-09-19 16:37:58 +02:00
|
|
|
#ifdef ENABLE_WS2812BPWM
|
|
|
|
else if (type == "ws2812b")
|
2014-09-16 00:17:23 +02:00
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceWS2812b();
|
2014-06-15 02:19:09 +02:00
|
|
|
}
|
2016-03-04 09:07:02 +01:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_WS281XPWM
|
|
|
|
else if (type == "ws281x")
|
|
|
|
{
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceWS281x(
|
2016-07-13 16:19:19 +02:00
|
|
|
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()
|
2016-07-13 11:18:12 +02:00
|
|
|
);
|
2016-03-04 09:07:02 +01:00
|
|
|
}
|
2014-09-19 16:37:58 +02:00
|
|
|
#endif
|
2013-12-17 19:50:15 +01:00
|
|
|
else
|
|
|
|
{
|
2016-06-25 22:08:17 +02:00
|
|
|
if (type != "file")
|
|
|
|
{
|
|
|
|
Error(log, "Dummy device used, because unknown device %s set.", type.c_str());
|
|
|
|
}
|
2016-07-13 11:18:12 +02:00
|
|
|
device = new LedDeviceFile(
|
|
|
|
deviceConfig.get("output", "/dev/null").asString()
|
|
|
|
);
|
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;
|
|
|
|
}
|