2014-02-07 14:55:54 +01:00
|
|
|
// Stl includes
|
|
|
|
#include <string>
|
|
|
|
#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>
|
|
|
|
|
|
|
|
// 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"
|
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"
|
|
|
|
#include "LedDeviceLightpack.h"
|
|
|
|
#include "LedDeviceMultiLightpack.h"
|
|
|
|
#include "LedDevicePaintpack.h"
|
|
|
|
#include "LedDevicePiBlaster.h"
|
2013-12-17 19:50:15 +01:00
|
|
|
#include "LedDeviceSedu.h"
|
|
|
|
#include "LedDeviceTest.h"
|
2014-03-09 11:36:46 +01:00
|
|
|
#include "LedDeviceHyperionUsbasp.h"
|
2013-12-17 19:50:15 +01:00
|
|
|
|
|
|
|
LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
|
|
|
{
|
|
|
|
std::cout << "Device configuration: " << deviceConfig << std::endl;
|
|
|
|
|
|
|
|
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
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
2014-01-04 11:35:11 +01:00
|
|
|
LedDeviceAdalight* deviceAdalight = new LedDeviceAdalight(output, rate);
|
|
|
|
deviceAdalight->open();
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2014-01-04 11:35:11 +01:00
|
|
|
device = deviceAdalight;
|
2013-12-17 19:50:15 +01: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")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceLpd6803* deviceLdp6803 = new LedDeviceLpd6803(output, rate);
|
|
|
|
deviceLdp6803->open();
|
|
|
|
|
|
|
|
device = deviceLdp6803;
|
|
|
|
}
|
|
|
|
else if (type == "lpd8806" || type == "ldp8806")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceLpd8806* deviceLpd8806 = new LedDeviceLpd8806(output, rate);
|
|
|
|
deviceLpd8806->open();
|
|
|
|
|
|
|
|
device = deviceLpd8806;
|
|
|
|
}
|
2014-01-18 23:57:47 +01:00
|
|
|
else if (type == "p9813")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceP9813* deviceP9813 = new LedDeviceP9813(output, rate);
|
|
|
|
deviceP9813->open();
|
|
|
|
|
|
|
|
device = deviceP9813;
|
|
|
|
}
|
2014-01-04 11:35:11 +01:00
|
|
|
else if (type == "ws2801" || type == "lightberry")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceWs2801* deviceWs2801 = new LedDeviceWs2801(output, rate);
|
|
|
|
deviceWs2801->open();
|
|
|
|
|
|
|
|
device = deviceWs2801;
|
|
|
|
}
|
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
|
|
|
{
|
|
|
|
const std::string host = deviceConfig.get("output", "127.0.0.1").asString();
|
|
|
|
const uint16_t port = deviceConfig.get("port", 4223).asInt();
|
|
|
|
const std::string uid = deviceConfig["uid"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceTinkerforge* deviceTinkerforge = new LedDeviceTinkerforge(host, port, uid, rate);
|
|
|
|
deviceTinkerforge->open();
|
|
|
|
|
|
|
|
device = deviceTinkerforge;
|
|
|
|
}
|
2013-12-19 09:29:26 +01:00
|
|
|
#endif
|
2013-12-17 19:50:15 +01:00
|
|
|
else if (type == "lightpack")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig.get("output", "").asString();
|
|
|
|
|
|
|
|
LedDeviceLightpack* deviceLightpack = new LedDeviceLightpack();
|
|
|
|
deviceLightpack->open(output);
|
|
|
|
|
|
|
|
device = deviceLightpack;
|
|
|
|
}
|
2014-01-04 11:35:11 +01:00
|
|
|
else if (type == "multi-lightpack")
|
|
|
|
{
|
|
|
|
LedDeviceMultiLightpack* deviceLightpack = new LedDeviceMultiLightpack();
|
|
|
|
deviceLightpack->open();
|
|
|
|
|
|
|
|
device = deviceLightpack;
|
|
|
|
}
|
2013-12-17 19:50:15 +01:00
|
|
|
else if (type == "paintpack")
|
|
|
|
{
|
|
|
|
LedDevicePaintpack * devicePainLightpack = new LedDevicePaintpack();
|
|
|
|
devicePainLightpack->open();
|
|
|
|
|
|
|
|
device = devicePainLightpack;
|
|
|
|
}
|
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();
|
2013-12-17 19:50:15 +01:00
|
|
|
|
2014-01-04 11:35:11 +01:00
|
|
|
LedDevicePiBlaster * devicePiBlaster = new LedDevicePiBlaster(output, assignment);
|
|
|
|
devicePiBlaster->open();
|
|
|
|
|
|
|
|
device = devicePiBlaster;
|
|
|
|
}
|
|
|
|
else if (type == "sedu")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
const unsigned rate = deviceConfig["rate"].asInt();
|
|
|
|
|
|
|
|
LedDeviceSedu* deviceSedu = new LedDeviceSedu(output, rate);
|
|
|
|
deviceSedu->open();
|
|
|
|
|
|
|
|
device = deviceSedu;
|
2013-12-17 19:50:15 +01:00
|
|
|
}
|
2014-03-09 11:36:46 +01:00
|
|
|
else if (type == "hyperion-usbasp-ws2801")
|
|
|
|
{
|
|
|
|
LedDeviceHyperionUsbasp * deviceHyperionUsbasp = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2801);
|
|
|
|
deviceHyperionUsbasp->open();
|
|
|
|
device = deviceHyperionUsbasp;
|
|
|
|
}
|
|
|
|
else if (type == "hyperion-usbasp-ws2812")
|
|
|
|
{
|
|
|
|
LedDeviceHyperionUsbasp * deviceHyperionUsbasp = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2812);
|
|
|
|
deviceHyperionUsbasp->open();
|
|
|
|
device = deviceHyperionUsbasp;
|
|
|
|
}
|
2013-12-17 19:50:15 +01:00
|
|
|
else if (type == "test")
|
|
|
|
{
|
|
|
|
const std::string output = deviceConfig["output"].asString();
|
|
|
|
device = new LedDeviceTest(output);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
std::cout << "Unable to create device " << type << std::endl;
|
|
|
|
// Unknown / Unimplemented device
|
|
|
|
}
|
|
|
|
return device;
|
|
|
|
}
|