mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Leddevice rework2 (#193)
* commit debug code to save it due to merge * migrate first devices to new device registry and configure on runtime * fadecandy and rs232 resets device if config is set * try to hunt crash on osx * test commit if this works with osx * refactor spi devices * cleanup * refactor leddevices file, tinkerforge and ws2812b * refactor raw usb devices * refactor udp devices * - add tpm2net driver - remove old udp driver from build (files left in place for reference for new udp driver) - json serverinfo shows available leddevices * finish rework part 2 of leddevices * add schemas for leddevices. currently only compiled in, but not usedx
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
#include <map>
|
||||
|
||||
// Build configuration
|
||||
#include <HyperionConfig.h>
|
||||
@@ -10,6 +11,7 @@
|
||||
// Leddevice includes
|
||||
#include <leddevice/LedDeviceFactory.h>
|
||||
#include <utils/Logger.h>
|
||||
#include <leddevice/LedDevice.h>
|
||||
|
||||
// Local Leddevice includes
|
||||
#ifdef ENABLE_SPIDEV
|
||||
@@ -35,7 +37,7 @@
|
||||
#include "LedDeviceSedu.h"
|
||||
#include "LedDeviceFile.h"
|
||||
#include "LedDeviceFadeCandy.h"
|
||||
#include "LedDeviceUdp.h"
|
||||
#include "LedDeviceTpm2net.h"
|
||||
#include "LedDeviceUdpRaw.h"
|
||||
#include "LedDeviceUdpE131.h"
|
||||
#include "LedDeviceHyperionUsbasp.h"
|
||||
@@ -63,281 +65,81 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
std::string type = deviceConfig.get("type", "UNSPECIFIED").asString();
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
|
||||
// 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);
|
||||
|
||||
// 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);
|
||||
#endif
|
||||
|
||||
// pwm devices
|
||||
#ifdef ENABLE_WS2812BPWM
|
||||
LedDevice::addToDeviceMap("ws2812b", LedDeviceWS2812b::construct);
|
||||
#endif
|
||||
#ifdef ENABLE_WS281XPWM
|
||||
LedDevice::addToDeviceMap("ws281x", LedDeviceWS281x::construct);
|
||||
#endif
|
||||
|
||||
// network lights
|
||||
LedDevice::addToDeviceMap("tmp2net", LedDeviceTpm2net::construct);
|
||||
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
|
||||
{
|
||||
if (false) {}
|
||||
else if (type == "adalight")
|
||||
for ( auto dev: devList)
|
||||
{
|
||||
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(),
|
||||
deviceConfig.get("latchtime",500000).asInt(),
|
||||
deviceConfig.get("spimode",0).asInt(),
|
||||
deviceConfig.get("invert",false).asBool()
|
||||
);
|
||||
}
|
||||
else if (type == "ws2812spi")
|
||||
{
|
||||
device = new LedDeviceWs2812SPI(
|
||||
deviceConfig["output"].asString(),
|
||||
deviceConfig.get("rate",2857143).asInt(),
|
||||
deviceConfig.get("spimode",0).asInt(),
|
||||
deviceConfig.get("invert",false).asBool()
|
||||
);
|
||||
}
|
||||
else if (type == "sk6812rgbw-spi")
|
||||
{
|
||||
device = new LedDeviceSk6812SPI(
|
||||
deviceConfig["output"].asString(),
|
||||
deviceConfig.get("rate",2857143).asInt(),
|
||||
deviceConfig.get("white_algorithm","").asString(),
|
||||
deviceConfig.get("spimode",0).asInt(),
|
||||
deviceConfig.get("invert",false).asBool()
|
||||
);
|
||||
}
|
||||
#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()
|
||||
);
|
||||
|
||||
}
|
||||
#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();
|
||||
|
||||
// Convert HEX values to integer
|
||||
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
|
||||
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
|
||||
|
||||
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();
|
||||
|
||||
// Convert HEX values to integer
|
||||
auto VendorId = std::stoul(VendorIdString, nullptr, 16);
|
||||
auto ProductId = std::stoul(ProductIdString, nullptr, 16);
|
||||
|
||||
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);
|
||||
|
||||
if (! assignment.empty())
|
||||
if (dev.first == type)
|
||||
{
|
||||
throw std::runtime_error("Piblaster: The piblaster configuration syntax has changed in this version.");
|
||||
device = dev.second(deviceConfig);
|
||||
LedDevice::setActiveDevice(dev.first);
|
||||
Info(log,"LedDevice '%s' configured.", dev.first.c_str());
|
||||
break;
|
||||
}
|
||||
if (gpioMapping.isNull())
|
||||
{
|
||||
throw std::runtime_error("Piblaster: no gpiomap defined.");
|
||||
}
|
||||
device = new LedDevicePiBlaster(output, gpioMapping);
|
||||
}
|
||||
else if (type == "sedu")
|
||||
{
|
||||
device = new LedDeviceSedu(
|
||||
deviceConfig["output"].asString(),
|
||||
deviceConfig["rate"].asInt()
|
||||
);
|
||||
}
|
||||
else if (type == "hyperion-usbasp-ws2801")
|
||||
{
|
||||
device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2801);
|
||||
}
|
||||
else if (type == "hyperion-usbasp-ws2812")
|
||||
{
|
||||
device = new LedDeviceHyperionUsbasp(LedDeviceHyperionUsbasp::CMD_WRITE_WS2812);
|
||||
}
|
||||
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;
|
||||
|
||||
// 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()
|
||||
);
|
||||
}
|
||||
else if (type == "e131")
|
||||
{
|
||||
device = new LedDeviceUdpE131(
|
||||
deviceConfig["output"].asString(),
|
||||
deviceConfig.get("latchtime",104000).asInt(),
|
||||
deviceConfig.get("universe",1).asInt()
|
||||
);
|
||||
}
|
||||
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() );
|
||||
}
|
||||
else
|
||||
|
||||
if (device == nullptr)
|
||||
{
|
||||
Error(log, "Dummy device used, because configured device '%s' is unknown", type.c_str() );
|
||||
throw std::runtime_error("unknown device");
|
||||
}
|
||||
}
|
||||
catch(std::exception e)
|
||||
catch(std::exception& e)
|
||||
{
|
||||
|
||||
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what());
|
||||
device = new LedDeviceFile( "/dev/null" );
|
||||
const Json::Value dummyDeviceConfig;
|
||||
device = LedDeviceFile::construct(Json::nullValue);
|
||||
}
|
||||
|
||||
device->open();
|
||||
|
Reference in New Issue
Block a user