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>
|
2016-08-23 20:07:12 +02:00
|
|
|
#include <map>
|
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>
|
2016-08-23 20:07:12 +02:00
|
|
|
#include <leddevice/LedDevice.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-08-23 20:07:12 +02:00
|
|
|
#include "LedDeviceTpm2net.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);
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
// rs232 devices
|
|
|
|
LedDevice::addToDeviceMap("adalight" , LedDeviceAdalight::construct);
|
|
|
|
LedDevice::addToDeviceMap("adalightapa102", LedDeviceAdalightApa102::construct);
|
|
|
|
LedDevice::addToDeviceMap("sedu" , LedDeviceSedu::construct);
|
|
|
|
LedDevice::addToDeviceMap("tpm2" , LedDeviceTpm2::construct);
|
|
|
|
LedDevice::addToDeviceMap("atmo" , LedDeviceAtmo::construct);
|
|
|
|
LedDevice::addToDeviceMap("fadecandy" , LedDeviceFadeCandy::construct);
|
2014-03-04 20:38:54 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
// spi devices
|
|
|
|
#ifdef ENABLE_SPIDEV
|
|
|
|
LedDevice::addToDeviceMap("apa102" , LedDeviceAPA102::construct);
|
|
|
|
LedDevice::addToDeviceMap("lpd6803" , LedDeviceLpd6803::construct);
|
|
|
|
LedDevice::addToDeviceMap("lpd8806" , LedDeviceLpd8806::construct);
|
|
|
|
LedDevice::addToDeviceMap("p9813" , LedDeviceP9813::construct);
|
|
|
|
LedDevice::addToDeviceMap("ws2801" , LedDeviceWs2801::construct);
|
|
|
|
LedDevice::addToDeviceMap("ws2812spi" , LedDeviceWs2812SPI::construct);
|
|
|
|
LedDevice::addToDeviceMap("sk6812rgbw-spi", LedDeviceSk6812SPI::construct);
|
2016-08-08 00:17:00 +02:00
|
|
|
#endif
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
// pwm devices
|
2016-08-08 00:17:00 +02:00
|
|
|
#ifdef ENABLE_WS2812BPWM
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice::addToDeviceMap("ws2812b", LedDeviceWS2812b::construct);
|
2016-08-08 00:17:00 +02:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_WS281XPWM
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice::addToDeviceMap("ws281x", LedDeviceWS281x::construct);
|
2016-08-08 00:17:00 +02:00
|
|
|
#endif
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
// network lights
|
2016-09-04 09:07:10 +02:00
|
|
|
LedDevice::addToDeviceMap("tpm2net", LedDeviceTpm2net::construct);
|
2016-08-23 20:07:12 +02:00
|
|
|
LedDevice::addToDeviceMap("udpraw", LedDeviceUdpRaw::construct);
|
|
|
|
LedDevice::addToDeviceMap("e131", LedDeviceUdpE131::construct);
|
|
|
|
#ifdef ENABLE_TINKERFORGE
|
|
|
|
LedDevice::addToDeviceMap("tinkerforge", LedDeviceTinkerforge::construct);
|
|
|
|
#endif
|
|
|
|
LedDevice::addToDeviceMap("philipshue", LedDevicePhilipsHue::construct);
|
|
|
|
LedDevice::addToDeviceMap("atmoorb", LedDeviceAtmoOrb::construct);
|
|
|
|
|
|
|
|
// direct usb
|
|
|
|
LedDevice::addToDeviceMap("hyperion-usbasp", LedDeviceHyperionUsbasp::construct);
|
|
|
|
LedDevice::addToDeviceMap("rawhid", LedDeviceRawHID::construct);
|
|
|
|
LedDevice::addToDeviceMap("paintpack", LedDevicePaintpack::construct);
|
|
|
|
LedDevice::addToDeviceMap("lightpack", LedDeviceLightpack::construct);
|
|
|
|
LedDevice::addToDeviceMap("multi-lightpack", LedDeviceMultiLightpack::construct);
|
|
|
|
|
|
|
|
// other
|
|
|
|
LedDevice::addToDeviceMap("file", LedDeviceFile::construct);
|
|
|
|
LedDevice::addToDeviceMap("piblaster", LedDevicePiBlaster::construct);
|
|
|
|
|
|
|
|
const LedDeviceRegistry& devList = LedDevice::getDeviceMap();
|
|
|
|
LedDevice* device = nullptr;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for ( auto dev: devList)
|
2016-08-08 00:17:00 +02:00
|
|
|
{
|
2016-08-23 20:07:12 +02:00
|
|
|
if (dev.first == type)
|
|
|
|
{
|
|
|
|
device = dev.second(deviceConfig);
|
|
|
|
LedDevice::setActiveDevice(dev.first);
|
|
|
|
Info(log,"LedDevice '%s' configured.", dev.first.c_str());
|
|
|
|
break;
|
|
|
|
}
|
2016-03-15 18:37:55 +01:00
|
|
|
}
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
if (device == nullptr)
|
2016-03-15 18:37:55 +01:00
|
|
|
{
|
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-23 20:07:12 +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());
|
2016-08-23 20:07:12 +02:00
|
|
|
const Json::Value dummyDeviceConfig;
|
|
|
|
device = LedDeviceFile::construct(Json::nullValue);
|
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;
|
|
|
|
}
|