2014-02-07 14:55:54 +01:00
|
|
|
// Stl includes
|
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"
|
2017-02-14 09:33:28 +01:00
|
|
|
#include "LedDeviceSk6822SPI.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-09-26 17:50:11 +02:00
|
|
|
#include "LedDeviceDMX.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"
|
2017-05-26 22:17:12 +02:00
|
|
|
#include "LedDeviceUdpArtNet.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"
|
2016-03-14 20:19:19 +01:00
|
|
|
#include "LedDeviceAtmoOrb.h"
|
2016-09-21 23:03:01 +02:00
|
|
|
#include "LedDeviceUdpH801.h"
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2016-03-04 09:07:02 +01:00
|
|
|
#ifdef ENABLE_WS281XPWM
|
|
|
|
#include "LedDeviceWS281x.h"
|
|
|
|
#endif
|
|
|
|
|
2016-10-13 21:59:58 +02:00
|
|
|
LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const int ledCount)
|
2013-12-17 19:50:15 +01:00
|
|
|
{
|
2016-06-25 22:08:17 +02:00
|
|
|
Logger * log = Logger::getInstance("LedDevice");
|
2016-10-13 21:59:58 +02:00
|
|
|
QJsonDocument config(deviceConfig);
|
|
|
|
QString ss(config.toJson(QJsonDocument::Indented));
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
QString type = deviceConfig["type"].toString("UNSPECIFIED").toLower();
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
// set amount of led to leddevice
|
|
|
|
LedDevice::setLedCount(ledCount);
|
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
#define REGISTER(className) LedDevice::addToDeviceMap(QString(#className).toLower(), LedDevice##className::construct);
|
2016-08-23 20:07:12 +02:00
|
|
|
// rs232 devices
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(Adalight);
|
|
|
|
REGISTER(Sedu);
|
|
|
|
REGISTER(DMX);
|
|
|
|
REGISTER(Tpm2);
|
|
|
|
REGISTER(Atmo);
|
2014-03-04 20:38:54 +01:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
// spi devices
|
|
|
|
#ifdef ENABLE_SPIDEV
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(APA102);
|
|
|
|
REGISTER(Lpd6803);
|
|
|
|
REGISTER(Lpd8806);
|
|
|
|
REGISTER(P9813);
|
|
|
|
REGISTER(Ws2801);
|
|
|
|
REGISTER(Ws2812SPI);
|
|
|
|
REGISTER(Sk6812SPI);
|
2017-02-14 09:33:28 +01:00
|
|
|
REGISTER(Sk6822SPI);
|
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_WS281XPWM
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(WS281x);
|
2016-08-08 00:17:00 +02:00
|
|
|
#endif
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
// network lights
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(FadeCandy);
|
|
|
|
REGISTER(Tpm2net);
|
|
|
|
REGISTER(UdpRaw);
|
|
|
|
REGISTER(UdpE131);
|
2017-05-26 22:17:12 +02:00
|
|
|
REGISTER(UdpArtNet);
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(UdpH801);
|
|
|
|
REGISTER(PhilipsHue);
|
|
|
|
REGISTER(AtmoOrb);
|
2016-08-23 20:07:12 +02:00
|
|
|
#ifdef ENABLE_TINKERFORGE
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(Tinkerforge);
|
2016-08-23 20:07:12 +02:00
|
|
|
#endif
|
2016-09-21 23:03:01 +02:00
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
// direct usb
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(HyperionUsbasp);
|
|
|
|
REGISTER(RawHID);
|
|
|
|
REGISTER(Paintpack);
|
|
|
|
REGISTER(Lightpack);
|
|
|
|
REGISTER(MultiLightpack);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
|
|
|
// other
|
2016-10-08 08:14:36 +02:00
|
|
|
REGISTER(File);
|
|
|
|
REGISTER(PiBlaster);
|
2016-08-23 20:07:12 +02:00
|
|
|
|
2016-10-08 08:14:36 +02:00
|
|
|
#undef REGISTER
|
|
|
|
|
2016-08-23 20:07:12 +02:00
|
|
|
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);
|
2017-03-04 22:17:42 +01:00
|
|
|
Info(log,"LedDevice '%s' configured.", QSTRING_CSTR(dev.first));
|
2016-08-23 20:07:12 +02:00
|
|
|
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
|
|
|
{
|
2017-03-04 22:17:42 +01:00
|
|
|
Error(log, "Dummy device used, because configured device '%s' is unknown", QSTRING_CSTR(type) );
|
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
|
|
|
|
2017-03-04 22:17:42 +01:00
|
|
|
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", QSTRING_CSTR(type), e.what());
|
2016-10-13 21:59:58 +02:00
|
|
|
const QJsonObject dummyDeviceConfig;
|
|
|
|
device = LedDeviceFile::construct(QJsonObject());
|
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;
|
|
|
|
}
|