mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
JsonCpp to QTJson (Final Part) (#273)
* Update CMakeLists.txt * Update Hyperion.h * Update LedDevice.h * Update LedDeviceFactory.h * Update Hyperion.cpp * Update LedString.cpp * Update JsonClientConnection.cpp * Update LedDeviceAdalight.cpp * Update LedDeviceAdalight.h * Update LedDeviceAPA102.cpp * Update LedDeviceAdalightApa102.h * Update LedDeviceAdalightApa102.cpp * Update LedDeviceAPA102.h * Update LedDeviceAtmo.cpp * Update LedDeviceAtmo.h * Update LedDeviceAtmoOrb.cpp * Update LedDeviceAtmoOrb.h * Update LedDeviceDMX.cpp * Update LedDeviceDMX.h * Update LedDeviceFactory.cpp * Update LedDeviceFadeCandy.cpp * Update LedDeviceFadeCandy.h * Update LedDeviceFile.cpp * Update LedDeviceFile.h * Update LedDeviceHyperionUsbasp.cpp * Update LedDeviceHyperionUsbasp.h * Update LedDeviceLightpack.cpp * Update LedDeviceLightpack.h * Update LedDeviceLpd6803.cpp * Update LedDeviceLpd6803.h * Update LedDeviceLpd8806.cpp * Update LedDeviceLpd8806.h * Update LedDeviceMultiLightpack.cpp * Update LedDeviceMultiLightpack.h * Update LedDeviceP9813.cpp * Update LedDeviceP9813.h * Update LedDevicePaintpack.cpp * Update LedDevicePaintpack.h * Update LedDevicePhilipsHue.cpp * Update LedDevicePhilipsHue.h * Update LedDevicePiBlaster.cpp * Update LedDevicePiBlaster.h * Update LedDeviceRawHID.cpp * Update LedDeviceRawHID.h * Update LedDeviceSedu.cpp * Update LedDeviceSedu.h * Update LedDeviceSk6812SPI.cpp * Update LedDeviceSk6812SPI.h * Update LedDeviceTinkerforge.cpp * Update LedDeviceTinkerforge.h * Update LedDeviceTpm2.cpp * Update LedDeviceTpm2.h * Update LedDeviceTpm2net.cpp * Update LedDeviceTpm2net.h * Update LedDeviceUdpE131.cpp * Update LedDeviceUdpE131.h * Update LedDeviceUdpH801.cpp * Update LedDeviceUdpH801.h * Update LedDeviceUdpRaw.cpp * Update LedDeviceUdpRaw.h * Update LedDeviceWs2801.cpp * Update LedDeviceWs2801.h * Update LedDeviceWS2812b.cpp * Update LedDeviceWS2812b.h * Update LedDeviceWs2812SPI.cpp * Update LedDeviceWs2812SPI.h * Update LedDeviceWS281x.cpp * Update LedDeviceWS281x.h * Update ProviderHID.cpp * Update ProviderHID.h * Update ProviderRs232.cpp * Update ProviderRs232.h * Update ProviderSpi.cpp * Update ProviderSpi.h * Update ProviderUdp.cpp * Update ProviderUdp.h * Update LedDevice.cpp * Update CMakeLists.txt * Update hyperiond.cpp * Update hyperiond.h * Update TestSpi.cpp * Delete AUTHORS * Delete CMakeLists.txt * Delete LICENSE * Delete json_batchallocator.h * Delete json_internalarray.inl * Delete json_internalmap.inl * Delete json_reader.cpp * Delete json_tool.h * Delete json_value.cpp * Delete json_valueiterator.inl * Delete json_writer.cpp * Delete sconscript * Delete autolink.h * Delete config.h * Delete features.h * Delete forwards.h * Delete json.h * Delete reader.h * Delete value.h * Delete writer.h
This commit is contained in:
committed by
redPanther
parent
48d8781cdf
commit
464de381a0
@@ -5,8 +5,6 @@
|
||||
#include <QResource>
|
||||
#include <QStringList>
|
||||
#include <QDir>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonDocument>
|
||||
|
||||
LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry();
|
||||
std::string LedDevice::_activeDevice = "";
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "LedDeviceAPA102.h"
|
||||
|
||||
LedDeviceAPA102::LedDeviceAPA102(const Json::Value &deviceConfig)
|
||||
LedDeviceAPA102::LedDeviceAPA102(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceAPA102::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceAPA102::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceAPA102(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceAPA102::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceAPA102::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderSpi::init(deviceConfig);
|
||||
_latchTime_ns = 500000; // fixed latchtime
|
||||
|
@@ -13,12 +13,12 @@ public:
|
||||
///
|
||||
/// Constructs specific LedDevice
|
||||
///
|
||||
LedDeviceAPA102(const Json::Value &deviceConfig);
|
||||
LedDeviceAPA102(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
private:
|
||||
///
|
||||
/// Writes the led color values to the led-device
|
||||
|
@@ -1,18 +1,18 @@
|
||||
#include "LedDeviceAdalight.h"
|
||||
|
||||
LedDeviceAdalight::LedDeviceAdalight(const Json::Value &deviceConfig)
|
||||
LedDeviceAdalight::LedDeviceAdalight(const QJsonObject &deviceConfig)
|
||||
: ProviderRs232()
|
||||
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceAdalight::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceAdalight::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceAdalight(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceAdalight::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceAdalight::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
|
||||
|
@@ -15,12 +15,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceAdalight(const Json::Value &deviceConfig);
|
||||
LedDeviceAdalight(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "LedDeviceAdalightApa102.h"
|
||||
|
||||
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const Json::Value &deviceConfig)
|
||||
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const QJsonObject &deviceConfig)
|
||||
: ProviderRs232()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceAdalightApa102::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceAdalightApa102::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceAdalightApa102(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceAdalightApa102::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceAdalightApa102::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
|
||||
|
@@ -17,12 +17,12 @@ public:
|
||||
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
|
||||
/// @param baudrate The used baudrate for writing to the output device
|
||||
///
|
||||
LedDeviceAdalightApa102(const Json::Value &deviceConfig);
|
||||
LedDeviceAdalightApa102(const QJsonObject &deviceConfig);
|
||||
|
||||
/// create leddevice when type in config is set to this type
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,18 +1,18 @@
|
||||
// hyperion local includes
|
||||
#include "LedDeviceAtmo.h"
|
||||
|
||||
LedDeviceAtmo::LedDeviceAtmo(const Json::Value &deviceConfig)
|
||||
LedDeviceAtmo::LedDeviceAtmo(const QJsonObject &deviceConfig)
|
||||
: ProviderRs232()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceAtmo::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceAtmo::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceAtmo(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceAtmo::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceAtmo::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
|
||||
@@ -36,4 +36,3 @@ int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues)
|
||||
memcpy(4 + _ledBuffer.data(), ledValues.data(), _ledCount * sizeof(ColorRgb));
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
|
@@ -14,12 +14,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceAtmo(const Json::Value &deviceConfig);
|
||||
LedDeviceAtmo(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -16,7 +16,7 @@ AtmoOrbLight::AtmoOrbLight(unsigned int id) {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const Json::Value &deviceConfig)
|
||||
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
{
|
||||
init(deviceConfig);
|
||||
@@ -29,16 +29,16 @@ LedDeviceAtmoOrb::LedDeviceAtmoOrb(const Json::Value &deviceConfig)
|
||||
joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress);
|
||||
}
|
||||
|
||||
bool LedDeviceAtmoOrb::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceAtmoOrb::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_multicastGroup = deviceConfig["output"].asString().c_str();
|
||||
_useOrbSmoothing = deviceConfig.get("useOrbSmoothing", false).asBool();
|
||||
_transitiontime = deviceConfig.get("transitiontime", 0).asInt();
|
||||
_skipSmoothingDiff = deviceConfig.get("skipSmoothingDiff", 0).asInt();
|
||||
_multiCastGroupPort = deviceConfig.get("port", 49692).asInt();
|
||||
_numLeds = deviceConfig.get("numLeds", 24).asInt();
|
||||
_multicastGroup = deviceConfig["output"].toString().toStdString().c_str();
|
||||
_useOrbSmoothing = deviceConfig["useOrbSmoothing"].toBool(false);
|
||||
_transitiontime = deviceConfig["transitiontime"].toInt(0);
|
||||
_skipSmoothingDiff = deviceConfig["skipSmoothingDiff"].toInt(0);
|
||||
_multiCastGroupPort = deviceConfig["port"].toInt(49692);
|
||||
_numLeds = deviceConfig["numLeds"].toInt(24);
|
||||
|
||||
const std::string orbId = deviceConfig["orbIds"].asString();
|
||||
const std::string orbId = deviceConfig["orbIds"].toString().toStdString();
|
||||
_orbIds.clear();
|
||||
|
||||
// If we find multiple Orb ids separate them and add to list
|
||||
@@ -62,7 +62,7 @@ bool LedDeviceAtmoOrb::init(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceAtmoOrb::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceAtmoOrb::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceAtmoOrb(deviceConfig);
|
||||
}
|
||||
|
@@ -46,17 +46,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceAtmoOrb(const Json::Value &deviceConfig);
|
||||
LedDeviceAtmoOrb(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
///
|
||||
/// Destructor of this device
|
||||
///
|
||||
@@ -118,4 +118,4 @@ private:
|
||||
/// @param bytes the byte array containing command to send over multicast
|
||||
///
|
||||
void sendCommand(const QByteArray &bytes);
|
||||
};
|
||||
};
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include <QSerialPort>
|
||||
#include <time.h>
|
||||
|
||||
LedDeviceDMX::LedDeviceDMX(const Json::Value &deviceConfig)
|
||||
LedDeviceDMX::LedDeviceDMX(const QJsonObject &deviceConfig)
|
||||
: ProviderRs232()
|
||||
, _dmxDeviceType(0)
|
||||
, _dmxStart(1)
|
||||
@@ -11,7 +11,7 @@ LedDeviceDMX::LedDeviceDMX(const Json::Value &deviceConfig)
|
||||
, _dmxChannelCount(0)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
std::string _dmxString = deviceConfig.get("dmxdevice", "invalid").asString();
|
||||
std::string _dmxString = deviceConfig["dmxdevice"].toString("invalid").toStdString();
|
||||
if (_dmxString == "raw")
|
||||
{
|
||||
_dmxDeviceType = 0;
|
||||
@@ -42,7 +42,7 @@ LedDeviceDMX::LedDeviceDMX(const Json::Value &deviceConfig)
|
||||
_ledBuffer[0] = 0x00; // NULL START code
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceDMX::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceDMX::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceDMX(deviceConfig);
|
||||
}
|
||||
@@ -85,4 +85,3 @@ int LedDeviceDMX::write(const std::vector<ColorRgb> &ledValues)
|
||||
|
||||
return writeBytes(_dmxChannelCount, _ledBuffer.data());
|
||||
}
|
||||
|
||||
|
@@ -14,10 +14,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceDMX(const Json::Value &deviceConfig);
|
||||
LedDeviceDMX(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -57,14 +57,14 @@
|
||||
#include "LedDeviceWS281x.h"
|
||||
#endif
|
||||
|
||||
LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig, const int ledCount)
|
||||
LedDevice * LedDeviceFactory::construct(const QJsonObject & deviceConfig, const int ledCount)
|
||||
{
|
||||
Logger * log = Logger::getInstance("LedDevice");
|
||||
std::stringstream ss;
|
||||
ss << deviceConfig;
|
||||
Info(log, "configuration: %s ", ss.str().c_str());
|
||||
QJsonDocument config(deviceConfig);
|
||||
QString ss(config.toJson(QJsonDocument::Indented));
|
||||
Info(log, "configuration: %s ", ss.toUtf8().constData());
|
||||
|
||||
std::string type = deviceConfig.get("type", "UNSPECIFIED").asString();
|
||||
std::string type = deviceConfig["type"].toString("UNSPECIFIED").toStdString();
|
||||
std::transform(type.begin(), type.end(), type.begin(), ::tolower);
|
||||
|
||||
// set amount of led to leddevice
|
||||
@@ -148,8 +148,8 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig, const
|
||||
{
|
||||
|
||||
Error(log, "Dummy device used, because configured device '%s' throws error '%s'", type.c_str(), e.what());
|
||||
const Json::Value dummyDeviceConfig;
|
||||
device = LedDeviceFile::construct(Json::nullValue);
|
||||
const QJsonObject dummyDeviceConfig;
|
||||
device = LedDeviceFile::construct(QJsonObject());
|
||||
}
|
||||
|
||||
device->open();
|
||||
|
@@ -6,7 +6,7 @@ static const unsigned OPC_SYS_EX = 255; // OPC command codes
|
||||
static const unsigned OPC_HEADER_SIZE = 4; // OPC header size
|
||||
|
||||
|
||||
LedDeviceFadeCandy::LedDeviceFadeCandy(const Json::Value &deviceConfig)
|
||||
LedDeviceFadeCandy::LedDeviceFadeCandy(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
@@ -18,13 +18,13 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy()
|
||||
_client.close();
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceFadeCandy::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceFadeCandy::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceFadeCandy(deviceConfig);
|
||||
}
|
||||
|
||||
|
||||
bool LedDeviceFadeCandy::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceFadeCandy::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_client.close();
|
||||
|
||||
@@ -34,26 +34,26 @@ bool LedDeviceFadeCandy::init(const Json::Value &deviceConfig)
|
||||
return false;
|
||||
}
|
||||
|
||||
_host = deviceConfig.get("output", "127.0.0.1").asString();
|
||||
_port = deviceConfig.get("port", 7890).asInt();
|
||||
_channel = deviceConfig.get("channel", 0).asInt();
|
||||
_gamma = deviceConfig.get("gamma", 1.0).asDouble();
|
||||
_noDither = ! deviceConfig.get("dither", false).asBool();
|
||||
_noInterp = ! deviceConfig.get("interpolation", false).asBool();
|
||||
_manualLED = deviceConfig.get("manualLed", false).asBool();
|
||||
_ledOnOff = deviceConfig.get("ledOn", false).asBool();
|
||||
_setFcConfig = deviceConfig.get("setFcConfig", false).asBool();
|
||||
_host = deviceConfig["output"].toString("127.0.0.1").toStdString();
|
||||
_port = deviceConfig["port"].toInt(7890);
|
||||
_channel = deviceConfig["channel"].toInt(0);
|
||||
_gamma = deviceConfig["gamma"].toDouble(1.0);
|
||||
_noDither = ! deviceConfig["dither"].toBool(false);
|
||||
_noInterp = ! deviceConfig["interpolation"].toBool(false);
|
||||
_manualLED = deviceConfig["manualLed"].toBool(false);
|
||||
_ledOnOff = deviceConfig["ledOn"].toBool(false);
|
||||
_setFcConfig = deviceConfig["setFcConfig"].toBool(false);
|
||||
|
||||
_whitePoint_r = 1.0;
|
||||
_whitePoint_g = 1.0;
|
||||
_whitePoint_b = 1.0;
|
||||
|
||||
const Json::Value whitePointConfig = deviceConfig["whitePoint"];
|
||||
if ( whitePointConfig.isArray() && whitePointConfig.size() == 3 )
|
||||
const QJsonArray whitePointConfig = deviceConfig["whitePoint"].toArray();
|
||||
if ( !whitePointConfig.isEmpty() && whitePointConfig.size() == 3 )
|
||||
{
|
||||
_whitePoint_r = whitePointConfig[0].asDouble();
|
||||
_whitePoint_g = whitePointConfig[1].asDouble();
|
||||
_whitePoint_b = whitePointConfig[2].asDouble();
|
||||
_whitePoint_r = whitePointConfig[0].toDouble();
|
||||
_whitePoint_g = whitePointConfig[1].toDouble();
|
||||
_whitePoint_b = whitePointConfig[2].toDouble();
|
||||
}
|
||||
|
||||
_opc_data.resize( _ledRGBCount + OPC_HEADER_SIZE );
|
||||
|
@@ -38,7 +38,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json config for fadecandy
|
||||
///
|
||||
LedDeviceFadeCandy(const Json::Value &deviceConfig);
|
||||
LedDeviceFadeCandy(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the tcp client
|
||||
@@ -46,14 +46,14 @@ public:
|
||||
virtual ~LedDeviceFadeCandy();
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Writes the led color values to the led-device
|
||||
@@ -111,4 +111,3 @@ private:
|
||||
void sendFadeCandyConfiguration();
|
||||
|
||||
};
|
||||
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "LedDeviceFile.h"
|
||||
|
||||
LedDeviceFile::LedDeviceFile(const Json::Value &deviceConfig)
|
||||
LedDeviceFile::LedDeviceFile(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
{
|
||||
init(deviceConfig);
|
||||
@@ -10,19 +10,19 @@ LedDeviceFile::~LedDeviceFile()
|
||||
{
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceFile::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceFile::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceFile(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceFile::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceFile::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
if ( _ofs.is_open() )
|
||||
{
|
||||
_ofs.close();
|
||||
}
|
||||
|
||||
std::string fileName = deviceConfig.get("output","/dev/null").asString();
|
||||
std::string fileName = deviceConfig["output"].toString("/dev/null").toStdString();
|
||||
_ofs.open( fileName.c_str() );
|
||||
|
||||
return true;
|
||||
|
@@ -18,7 +18,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceFile(const Json::Value &deviceConfig);
|
||||
LedDeviceFile(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of this test-device
|
||||
@@ -26,14 +26,14 @@ public:
|
||||
virtual ~LedDeviceFile();
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
protected:
|
||||
///
|
||||
|
@@ -11,7 +11,7 @@ uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc;
|
||||
std::string LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller";
|
||||
|
||||
|
||||
LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const Json::Value &deviceConfig)
|
||||
LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
, _libusbContext(nullptr)
|
||||
, _deviceHandle(nullptr)
|
||||
@@ -37,9 +37,9 @@ LedDeviceHyperionUsbasp::~LedDeviceHyperionUsbasp()
|
||||
}
|
||||
}
|
||||
|
||||
bool LedDeviceHyperionUsbasp::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceHyperionUsbasp::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
std::string ledType = deviceConfig.get("output", "ws2801").asString();
|
||||
std::string ledType = deviceConfig["output"].toString("ws2801").toStdString();
|
||||
if (ledType != "ws2801" && ledType != "ws2812")
|
||||
{
|
||||
throw std::runtime_error("HyperionUsbasp: invalid output; must be 'ws2801' or 'ws2812'.");
|
||||
@@ -50,7 +50,7 @@ bool LedDeviceHyperionUsbasp::init(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceHyperionUsbasp::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceHyperionUsbasp::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceHyperionUsbasp(deviceConfig);
|
||||
}
|
||||
|
@@ -28,17 +28,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceHyperionUsbasp(const Json::Value &deviceConfig);
|
||||
LedDeviceHyperionUsbasp(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
|
@@ -45,7 +45,7 @@ LedDeviceLightpack::LedDeviceLightpack(const std::string & serialNumber)
|
||||
{
|
||||
}
|
||||
|
||||
LedDeviceLightpack::LedDeviceLightpack(const Json::Value &deviceConfig)
|
||||
LedDeviceLightpack::LedDeviceLightpack(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
{
|
||||
init(deviceConfig);
|
||||
@@ -69,14 +69,14 @@ LedDeviceLightpack::~LedDeviceLightpack()
|
||||
}
|
||||
}
|
||||
|
||||
bool LedDeviceLightpack::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceLightpack::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_serialNumber = deviceConfig.get("output", "").asString();
|
||||
_serialNumber = deviceConfig["output"].toString("").toStdString();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceLightpack::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceLightpack::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceLightpack(deviceConfig);
|
||||
}
|
||||
|
@@ -26,17 +26,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceLightpack(const Json::Value &deviceConfig);
|
||||
LedDeviceLightpack(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "LedDeviceLpd6803.h"
|
||||
|
||||
LedDeviceLpd6803::LedDeviceLpd6803(const Json::Value &deviceConfig)
|
||||
LedDeviceLpd6803::LedDeviceLpd6803(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceLpd6803::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceLpd6803::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceLpd6803(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceLpd6803::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceLpd6803::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderSpi::init(deviceConfig);
|
||||
|
||||
|
@@ -22,12 +22,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceLpd6803(const Json::Value &deviceConfig);
|
||||
LedDeviceLpd6803(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "LedDeviceLpd8806.h"
|
||||
|
||||
LedDeviceLpd8806::LedDeviceLpd8806(const Json::Value &deviceConfig)
|
||||
LedDeviceLpd8806::LedDeviceLpd8806(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceLpd8806::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceLpd8806::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceLpd8806(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceLpd8806::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceLpd8806::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderSpi::init(deviceConfig);
|
||||
|
||||
|
@@ -83,12 +83,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceLpd8806(const Json::Value &deviceConfig);
|
||||
LedDeviceLpd8806(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -17,7 +17,7 @@ bool compareLightpacks(LedDeviceLightpack * lhs, LedDeviceLightpack * rhs)
|
||||
return lhs->getSerialNumber() < rhs->getSerialNumber();
|
||||
}
|
||||
|
||||
LedDeviceMultiLightpack::LedDeviceMultiLightpack(const Json::Value &)
|
||||
LedDeviceMultiLightpack::LedDeviceMultiLightpack(const QJsonObject &)
|
||||
: LedDevice()
|
||||
, _lightpacks()
|
||||
{
|
||||
@@ -31,7 +31,7 @@ LedDeviceMultiLightpack::~LedDeviceMultiLightpack()
|
||||
}
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceMultiLightpack::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceMultiLightpack::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceMultiLightpack(deviceConfig);
|
||||
}
|
||||
|
@@ -22,9 +22,7 @@ public:
|
||||
///
|
||||
/// Constructs specific LedDevice
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceMultiLightpack(const Json::Value &);
|
||||
LedDeviceMultiLightpack(const QJsonObject &);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
@@ -32,7 +30,7 @@ public:
|
||||
virtual ~LedDeviceMultiLightpack();
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Opens and configures the output device7
|
||||
|
@@ -1,17 +1,17 @@
|
||||
#include "LedDeviceP9813.h"
|
||||
|
||||
LedDeviceP9813::LedDeviceP9813(const Json::Value &deviceConfig)
|
||||
LedDeviceP9813::LedDeviceP9813(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceP9813::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceP9813::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceP9813(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceP9813::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceP9813::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderSpi::init(deviceConfig);
|
||||
|
||||
|
@@ -14,12 +14,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceP9813(const Json::Value &deviceConfig);
|
||||
LedDeviceP9813(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "LedDevicePaintpack.h"
|
||||
|
||||
// Use out report HID device
|
||||
LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig)
|
||||
LedDevicePaintpack::LedDevicePaintpack(const QJsonObject &deviceConfig)
|
||||
: ProviderHID()
|
||||
{
|
||||
ProviderHID::init(deviceConfig);
|
||||
@@ -12,7 +12,7 @@ LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig)
|
||||
_ledBuffer[1] = 0;
|
||||
}
|
||||
|
||||
LedDevice* LedDevicePaintpack::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDevicePaintpack::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDevicePaintpack(deviceConfig);
|
||||
}
|
||||
|
@@ -14,10 +14,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDevicePaintpack(const Json::Value &deviceConfig);
|
||||
LedDevicePaintpack(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -161,7 +161,7 @@ CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue)
|
||||
return xy;
|
||||
}
|
||||
|
||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const Json::Value &deviceConfig)
|
||||
LedDevicePhilipsHue::LedDevicePhilipsHue(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
@@ -177,22 +177,23 @@ LedDevicePhilipsHue::~LedDevicePhilipsHue()
|
||||
delete manager;
|
||||
}
|
||||
|
||||
bool LedDevicePhilipsHue::init(const Json::Value &deviceConfig)
|
||||
bool LedDevicePhilipsHue::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
host = deviceConfig["output"].asString().c_str();
|
||||
username = deviceConfig.get("username", "newdeveloper").asString().c_str();
|
||||
switchOffOnBlack = deviceConfig.get("switchOffOnBlack", true).asBool();
|
||||
transitiontime = deviceConfig.get("transitiontime", 1).asInt();
|
||||
host = deviceConfig["output"].toString().toStdString().c_str();
|
||||
username = deviceConfig["username"].toString("newdeveloper").toStdString().c_str();
|
||||
switchOffOnBlack = deviceConfig["switchOffOnBlack"].toBool(true);
|
||||
transitiontime = deviceConfig["transitiontime"].toInt(1);
|
||||
lightIds.clear();
|
||||
for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++)
|
||||
QJsonArray lArray = deviceConfig["lightIds"].toArray();
|
||||
for(int i = 0; i < lArray.size(); i++)
|
||||
{
|
||||
lightIds.push_back(deviceConfig["lightIds"][i].asInt());
|
||||
lightIds.push_back(lArray[i].toInt());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDevicePhilipsHue::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDevicePhilipsHue::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDevicePhilipsHue(deviceConfig);
|
||||
}
|
||||
@@ -319,26 +320,34 @@ QString LedDevicePhilipsHue::getUrl(QString route)
|
||||
|
||||
void LedDevicePhilipsHue::saveStates(unsigned int nLights)
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument reader;
|
||||
QJsonObject json;
|
||||
QByteArray response;
|
||||
|
||||
// Clear saved lamps.
|
||||
lights.clear();
|
||||
// Use json parser to parse reponse.
|
||||
Json::Reader reader;
|
||||
Json::FastWriter writer;
|
||||
|
||||
// Read light ids if none have been supplied by the user.
|
||||
if (lightIds.size() != nLights)
|
||||
{
|
||||
lightIds.clear();
|
||||
//
|
||||
QByteArray response = get("lights");
|
||||
Json::Value json;
|
||||
if (!reader.parse(QString(response).toStdString(), json))
|
||||
response = get("lights");
|
||||
// Use QJsonDocument to parse reponse.
|
||||
reader = QJsonDocument::fromJson(response, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
throw std::runtime_error(("No lights found at " + getUrl("lights")).toStdString());
|
||||
}
|
||||
|
||||
json = reader.object();
|
||||
|
||||
// Loop over all children.
|
||||
for (Json::ValueIterator it = json.begin(); it != json.end() && lightIds.size() < nLights; it++)
|
||||
for (QJsonObject::iterator it = json.begin(); it != json.end() && lightIds.size() < nLights; it++)
|
||||
{
|
||||
int lightId = atoi(it.key().asCString());
|
||||
int lightId = atoi(it.key().toStdString().c_str());
|
||||
lightIds.push_back(lightId);
|
||||
Debug(_log, "nLights=%d: found light with id %d.", nLights, lightId);
|
||||
}
|
||||
@@ -352,36 +361,40 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights)
|
||||
for (unsigned int i = 0; i < nLights; i++)
|
||||
{
|
||||
// Read the response.
|
||||
QByteArray response = get(getRoute(lightIds.at(i)));
|
||||
response = get(getRoute(lightIds.at(i)));
|
||||
// Parse JSON.
|
||||
Json::Value json;
|
||||
if (!reader.parse(QString(response).toStdString(), json))
|
||||
reader = QJsonDocument::fromJson(response, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
// Error occured, break loop.
|
||||
Error(_log, "saveStates(nLights=%d): got invalid response from light %s.", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str());
|
||||
break;
|
||||
}
|
||||
|
||||
// Get state object values which are subject to change.
|
||||
Json::Value state(Json::objectValue);
|
||||
if (!json.isMember("state"))
|
||||
QJsonObject state;
|
||||
if (!json.contains("state"))
|
||||
{
|
||||
Error(_log, "saveStates(nLights=%d): got no state for light from %s", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str());
|
||||
break;
|
||||
}
|
||||
if (!json["state"].isMember("on"))
|
||||
if (!json["state"].toObject().contains("on"))
|
||||
{
|
||||
Error(_log, "saveStates(nLights=%d,): got no valid state from light %s", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str());
|
||||
break;
|
||||
}
|
||||
state["on"] = json["state"]["on"];
|
||||
if (json["state"]["on"] == true)
|
||||
state["on"] = json["state"].toObject()["on"];
|
||||
if (json["state"].toObject()["on"].toBool() == true)
|
||||
{
|
||||
state["xy"] = json["state"]["xy"];
|
||||
state["bri"] = json["state"]["bri"];
|
||||
state["xy"] = json["state"].toObject()["xy"];
|
||||
state["bri"] = json["state"].toObject()["bri"];
|
||||
}
|
||||
// Determine the model id.
|
||||
QString modelId = QString(writer.write(json["modelid"]).c_str()).trimmed().replace("\"", "");
|
||||
QString originalState = QString(writer.write(state).c_str()).trimmed();
|
||||
QJsonDocument mId(json["modelid"].toObject());
|
||||
QString modelId = mId.toJson().trimmed().replace("\"", "");
|
||||
QJsonDocument st(state);
|
||||
QString originalState = mId.toJson().trimmed();
|
||||
// Save state object.
|
||||
lights.push_back(PhilipsHueLight(lightIds.at(i), originalState, modelId));
|
||||
}
|
||||
|
@@ -115,7 +115,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDevicePhilipsHue(const Json::Value &deviceConfig);
|
||||
LedDevicePhilipsHue(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of this device
|
||||
@@ -127,10 +127,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
/// Restores the original state of the leds.
|
||||
virtual int switchOff();
|
||||
|
@@ -9,7 +9,7 @@
|
||||
// Local LedDevice includes
|
||||
#include "LedDevicePiBlaster.h"
|
||||
|
||||
LedDevicePiBlaster::LedDevicePiBlaster(const Json::Value &deviceConfig)
|
||||
LedDevicePiBlaster::LedDevicePiBlaster(const QJsonObject &deviceConfig)
|
||||
: _fid(nullptr)
|
||||
{
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
@@ -40,22 +40,23 @@ LedDevicePiBlaster::~LedDevicePiBlaster()
|
||||
}
|
||||
|
||||
|
||||
bool LedDevicePiBlaster::init(const Json::Value &deviceConfig)
|
||||
bool LedDevicePiBlaster::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_deviceName = deviceConfig.get("output", "").asString();
|
||||
Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue);
|
||||
_deviceName = deviceConfig["output"].toString("").toStdString();
|
||||
QJsonArray gpioMapping = deviceConfig["gpiomap"].toArray();
|
||||
|
||||
if (gpioMapping.isNull())
|
||||
if (gpioMapping.isEmpty())
|
||||
{
|
||||
throw std::runtime_error("Piblaster: no gpiomap defined.");
|
||||
}
|
||||
|
||||
// walk through the json config and populate the mapping tables
|
||||
for (const Json::Value& gpioMap : gpioMapping)
|
||||
for(QJsonArray::const_iterator gpioArray = gpioMapping.begin(); gpioArray != gpioMapping.end(); ++gpioArray)
|
||||
{
|
||||
const int gpio = gpioMap.get("gpio",-1).asInt();
|
||||
const int ledindex = gpioMap.get("ledindex",-1).asInt();
|
||||
const std::string ledcolor = gpioMap.get("ledcolor","z").asString();
|
||||
const QJsonObject value = (*gpioArray).toObject();
|
||||
const int gpio = value["gpio"].toInt(-1);
|
||||
const int ledindex = value["ledindex"].toInt(-1);
|
||||
const std::string ledcolor = value["ledcolor"].toString("z").toStdString();
|
||||
|
||||
// ignore missing/invalid settings
|
||||
if ( (gpio >= 0) && (gpio < signed(TABLE_SZ)) && (ledindex >= 0) ){
|
||||
@@ -69,7 +70,7 @@ bool LedDevicePiBlaster::init(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDevicePiBlaster::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDevicePiBlaster::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDevicePiBlaster(deviceConfig);
|
||||
}
|
||||
@@ -153,4 +154,3 @@ int LedDevicePiBlaster::write(const std::vector<ColorRgb> & ledValues)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@@ -15,7 +15,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDevicePiBlaster(const Json::Value &deviceConfig);
|
||||
LedDevicePiBlaster(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual ~LedDevicePiBlaster();
|
||||
|
||||
@@ -24,10 +24,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Attempts to open the piblaster-device. This will only succeed if the device is not yet open
|
||||
|
@@ -1,7 +1,7 @@
|
||||
#include "LedDeviceRawHID.h"
|
||||
|
||||
// Use feature report HID device
|
||||
LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig)
|
||||
LedDeviceRawHID::LedDeviceRawHID(const QJsonObject &deviceConfig)
|
||||
: ProviderHID()
|
||||
, _timer()
|
||||
{
|
||||
@@ -18,7 +18,7 @@ LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig)
|
||||
_timer.start();
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceRawHID::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceRawHID::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceRawHID(deviceConfig);
|
||||
}
|
||||
|
@@ -19,10 +19,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceRawHID(const Json::Value &deviceConfig);
|
||||
LedDeviceRawHID(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
private slots:
|
||||
/// Write the last data to the leds again
|
||||
|
@@ -6,18 +6,18 @@ struct FrameSpec
|
||||
size_t size;
|
||||
};
|
||||
|
||||
LedDeviceSedu::LedDeviceSedu(const Json::Value &deviceConfig)
|
||||
LedDeviceSedu::LedDeviceSedu(const QJsonObject &deviceConfig)
|
||||
: ProviderRs232()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceSedu::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceSedu::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceSedu(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceSedu::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceSedu::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
|
||||
|
@@ -14,12 +14,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceSedu(const Json::Value &deviceConfig);
|
||||
LedDeviceSedu(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "LedDeviceSk6812SPI.h"
|
||||
|
||||
LedDeviceSk6812SPI::LedDeviceSk6812SPI(const Json::Value &deviceConfig)
|
||||
LedDeviceSk6812SPI::LedDeviceSk6812SPI(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
, _whiteAlgorithm(RGBW::INVALID)
|
||||
, bitpair_to_byte {
|
||||
@@ -13,14 +13,14 @@ LedDeviceSk6812SPI::LedDeviceSk6812SPI(const Json::Value &deviceConfig)
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceSk6812SPI::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceSk6812SPI::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceSk6812SPI(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceSk6812SPI::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceSk6812SPI::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
std::string whiteAlgorithm = deviceConfig.get("white_algorithm","white_off").asString();
|
||||
std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString();
|
||||
_whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
|
||||
|
||||
if (_whiteAlgorithm == RGBW::INVALID)
|
||||
|
@@ -14,17 +14,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceSk6812SPI(const Json::Value &deviceConfig);
|
||||
LedDeviceSk6812SPI(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -9,7 +9,7 @@
|
||||
static const unsigned MAX_NUM_LEDS = 320;
|
||||
static const unsigned MAX_NUM_LEDS_SETTABLE = 16;
|
||||
|
||||
LedDeviceTinkerforge::LedDeviceTinkerforge(const Json::Value &deviceConfig)
|
||||
LedDeviceTinkerforge::LedDeviceTinkerforge(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
, _ipConnection(nullptr)
|
||||
, _ledStrip(nullptr)
|
||||
@@ -31,12 +31,12 @@ LedDeviceTinkerforge::~LedDeviceTinkerforge()
|
||||
delete _ledStrip;
|
||||
}
|
||||
|
||||
bool LedDeviceTinkerforge::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceTinkerforge::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_host = deviceConfig.get("output", "127.0.0.1").asString();
|
||||
_port = deviceConfig.get("port", 4223).asInt();
|
||||
_uid = deviceConfig["uid"].asString();
|
||||
_interval = deviceConfig["rate"].asInt();
|
||||
_host = deviceConfig["output"].toString("127.0.0.1").toStdString();
|
||||
_port = deviceConfig["port"].toInt(4223);
|
||||
_uid = deviceConfig["uid"].toString().toStdString();
|
||||
_interval = deviceConfig["rate"].toInt();
|
||||
|
||||
if ((unsigned)_ledCount > MAX_NUM_LEDS)
|
||||
{
|
||||
@@ -55,7 +55,7 @@ bool LedDeviceTinkerforge::init(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceTinkerforge::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceTinkerforge::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceTinkerforge(deviceConfig);
|
||||
}
|
||||
|
@@ -20,7 +20,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceTinkerforge(const Json::Value &deviceConfig);
|
||||
LedDeviceTinkerforge(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual ~LedDeviceTinkerforge();
|
||||
|
||||
@@ -29,10 +29,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Attempts to open a connection to the master bricklet and the led strip bricklet.
|
||||
|
@@ -1,18 +1,18 @@
|
||||
#include "LedDeviceTpm2.h"
|
||||
|
||||
|
||||
LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig)
|
||||
LedDeviceTpm2::LedDeviceTpm2(const QJsonObject &deviceConfig)
|
||||
: ProviderRs232()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceTpm2::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceTpm2::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceTpm2(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceTpm2::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceTpm2::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
|
||||
|
@@ -14,12 +14,12 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceTpm2(const Json::Value &deviceConfig);
|
||||
LedDeviceTpm2(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,24 +1,24 @@
|
||||
#include "LedDeviceTpm2net.h"
|
||||
|
||||
LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig)
|
||||
LedDeviceTpm2net::LedDeviceTpm2net(const QJsonObject &deviceConfig)
|
||||
: ProviderUdp()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceTpm2net::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceTpm2net::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_LatchTime_ns = 104000;
|
||||
_port = TPM2_DEFAULT_PORT;
|
||||
ProviderUdp::init(deviceConfig);
|
||||
_tpm2_max = deviceConfig.get("max-packet", 170).asInt();
|
||||
_tpm2_max = deviceConfig["max-packet"].toInt(170);
|
||||
_tpm2ByteCount = 3 * _ledCount;
|
||||
_tpm2TotalPackets = 1 + _tpm2ByteCount / _tpm2_max;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceTpm2net::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceTpm2net::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceTpm2net(deviceConfig);
|
||||
}
|
||||
|
@@ -16,17 +16,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceTpm2net(const Json::Value &deviceConfig);
|
||||
LedDeviceTpm2net(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -4,20 +4,20 @@
|
||||
// hyperion local includes
|
||||
#include "LedDeviceUdpE131.h"
|
||||
|
||||
LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig)
|
||||
LedDeviceUdpE131::LedDeviceUdpE131(const QJsonObject &deviceConfig)
|
||||
: ProviderUdp()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceUdpE131::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceUdpE131::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_LatchTime_ns = 104000;
|
||||
_port = 5568;
|
||||
ProviderUdp::init(deviceConfig);
|
||||
_e131_universe = deviceConfig.get("universe",1).asInt();
|
||||
_e131_source_name = deviceConfig.get("source-name","hyperion on "+QHostInfo::localHostName().toStdString()).asString();
|
||||
QString _json_cid = QString::fromStdString(deviceConfig.get("cid","").asString());
|
||||
_e131_universe = deviceConfig["universe"].toInt(1);
|
||||
_e131_source_name = deviceConfig["source-name"].toString("hyperion on "+QHostInfo::localHostName()).toStdString();
|
||||
QString _json_cid = deviceConfig["cid"].toString("");
|
||||
|
||||
if (_json_cid.isEmpty())
|
||||
{
|
||||
@@ -31,7 +31,7 @@ bool LedDeviceUdpE131::init(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceUdpE131::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceUdpE131::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceUdpE131(deviceConfig);
|
||||
}
|
||||
|
@@ -105,17 +105,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceUdpE131(const Json::Value &deviceConfig);
|
||||
LedDeviceUdpE131(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
|
||||
private:
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#include "LedDeviceUdpH801.h"
|
||||
|
||||
LedDeviceUdpH801::LedDeviceUdpH801(const Json::Value &deviceConfig)
|
||||
LedDeviceUdpH801::LedDeviceUdpH801(const QJsonObject &deviceConfig)
|
||||
: ProviderUdp()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceUdpH801::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceUdpH801::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
/* The H801 port is fixed */
|
||||
_LatchTime_ns = 10000000;
|
||||
@@ -14,9 +14,10 @@ bool LedDeviceUdpH801::init(const Json::Value &deviceConfig)
|
||||
ProviderUdp::init(deviceConfig, "255.255.255.255");
|
||||
|
||||
_ids.clear();
|
||||
for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++)
|
||||
QJsonArray lArray = deviceConfig["lightIds"].toArray();
|
||||
for (int i = 0; i < lArray.size(); i++)
|
||||
{
|
||||
QString id(deviceConfig["lightIds"][i].asCString());
|
||||
QString id = lArray[i].toString();
|
||||
_ids.push_back(id.toInt(nullptr, 16));
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ bool LedDeviceUdpH801::init(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceUdpH801::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceUdpH801::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceUdpH801(deviceConfig);
|
||||
}
|
||||
|
@@ -22,17 +22,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceUdpH801(const Json::Value &deviceConfig);
|
||||
LedDeviceUdpH801(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "LedDeviceUdpRaw.h"
|
||||
|
||||
LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig)
|
||||
LedDeviceUdpRaw::LedDeviceUdpRaw(const QJsonObject &deviceConfig)
|
||||
: ProviderUdp()
|
||||
{
|
||||
_LatchTime_ns = 500000;
|
||||
@@ -8,7 +8,7 @@ LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig)
|
||||
init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceUdpRaw::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceUdpRaw::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceUdpRaw(deviceConfig);
|
||||
}
|
||||
|
@@ -14,10 +14,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceUdpRaw(const Json::Value &deviceConfig);
|
||||
LedDeviceUdpRaw(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Writes the led color values to the led-device
|
||||
|
@@ -258,7 +258,7 @@ LedDeviceWS2812b::LedDeviceWS2812b()
|
||||
printf("WS2812b init finished \n");
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceWS2812b::construct(const Json::Value &)
|
||||
LedDevice* LedDeviceWS2812b::construct(const QJsonObject &)
|
||||
{
|
||||
return new LedDeviceWS2812b();
|
||||
}
|
||||
|
@@ -146,10 +146,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value&) {return true;};
|
||||
bool init(const QJsonObject&) {return true;};
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &);
|
||||
static LedDevice* construct(const QJsonObject &);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
#include "LedDeviceWS281x.h"
|
||||
|
||||
LedDeviceWS281x::LedDeviceWS281x(const Json::Value &deviceConfig)
|
||||
LedDeviceWS281x::LedDeviceWS281x(const QJsonObject &deviceConfig)
|
||||
: LedDevice()
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
@@ -16,9 +16,9 @@ LedDeviceWS281x::~LedDeviceWS281x()
|
||||
}
|
||||
}
|
||||
|
||||
bool LedDeviceWS281x::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceWS281x::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
std::string whiteAlgorithm = deviceConfig.get("white_algorithm","white_off").asString();
|
||||
std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString();
|
||||
_whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
|
||||
Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str());
|
||||
if (_whiteAlgorithm == RGBW::INVALID)
|
||||
@@ -27,18 +27,18 @@ bool LedDeviceWS281x::init(const Json::Value &deviceConfig)
|
||||
return false;
|
||||
}
|
||||
|
||||
_channel = deviceConfig.get("pwmchannel", 0).asInt();
|
||||
_channel = deviceConfig["pwmchannel"].toInt(0);
|
||||
if (_channel != 0 && _channel != 1)
|
||||
{
|
||||
throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1.");
|
||||
}
|
||||
|
||||
_led_string.freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt();
|
||||
_led_string.dmanum = deviceConfig.get("dmanum", 5).asInt();
|
||||
_led_string.channel[_channel].gpionum = deviceConfig.get("gpio", 18).asInt();
|
||||
_led_string.channel[_channel].count = deviceConfig.get("leds", 256).asInt();
|
||||
_led_string.channel[_channel].invert = deviceConfig.get("invert", 0).asInt();
|
||||
_led_string.channel[_channel].strip_type = ((deviceConfig.get("rgbw", 0).asInt() == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB);
|
||||
_led_string.freq = deviceConfig["freq"].toInt(800000ul);
|
||||
_led_string.dmanum = deviceConfig["dmanum"].toInt(5);
|
||||
_led_string.channel[_channel].gpionum = deviceConfig["gpio"].toInt(18);
|
||||
_led_string.channel[_channel].count = deviceConfig["leds"].toInt(256);
|
||||
_led_string.channel[_channel].invert = deviceConfig["invert"].toInt(0);
|
||||
_led_string.channel[_channel].strip_type = ((deviceConfig["rgbw"].toInt(0) == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB);
|
||||
_led_string.channel[_channel].brightness = 255;
|
||||
|
||||
_led_string.channel[!_channel].gpionum = 0;
|
||||
@@ -56,7 +56,7 @@ bool LedDeviceWS281x::init(const Json::Value &deviceConfig)
|
||||
return true;
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceWS281x::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceWS281x::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceWS281x(deviceConfig);
|
||||
}
|
||||
@@ -93,4 +93,3 @@ int LedDeviceWS281x::write(const std::vector<ColorRgb> &ledValues)
|
||||
|
||||
return ws2811_render(&_led_string) ? -1 : 0;
|
||||
}
|
||||
|
||||
|
@@ -14,7 +14,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceWS281x(const Json::Value &deviceConfig);
|
||||
LedDeviceWS281x(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice, waits for DMA to complete and then cleans up
|
||||
@@ -26,10 +26,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig);
|
||||
bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -1,12 +1,12 @@
|
||||
#include "LedDeviceWs2801.h"
|
||||
|
||||
LedDeviceWs2801::LedDeviceWs2801(const Json::Value &deviceConfig)
|
||||
LedDeviceWs2801::LedDeviceWs2801(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
{
|
||||
_deviceReady = ProviderSpi::init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceWs2801::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceWs2801::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceWs2801(deviceConfig);
|
||||
}
|
||||
@@ -18,4 +18,3 @@ int LedDeviceWs2801::write(const std::vector<ColorRgb> &ledValues)
|
||||
|
||||
return writeBytes(dataLen, dataPtr);
|
||||
}
|
||||
|
||||
|
@@ -13,10 +13,10 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceWs2801(const Json::Value &deviceConfig);
|
||||
LedDeviceWs2801(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
protected:
|
||||
///
|
||||
|
@@ -1,6 +1,6 @@
|
||||
#include "LedDeviceWs2812SPI.h"
|
||||
|
||||
LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig)
|
||||
LedDeviceWs2812SPI::LedDeviceWs2812SPI(const QJsonObject &deviceConfig)
|
||||
: ProviderSpi()
|
||||
, bitpair_to_byte {
|
||||
0b10001000,
|
||||
@@ -12,12 +12,12 @@ LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig)
|
||||
_deviceReady = init(deviceConfig);
|
||||
}
|
||||
|
||||
LedDevice* LedDeviceWs2812SPI::construct(const Json::Value &deviceConfig)
|
||||
LedDevice* LedDeviceWs2812SPI::construct(const QJsonObject &deviceConfig)
|
||||
{
|
||||
return new LedDeviceWs2812SPI(deviceConfig);
|
||||
}
|
||||
|
||||
bool LedDeviceWs2812SPI::init(const Json::Value &deviceConfig)
|
||||
bool LedDeviceWs2812SPI::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_baudRate_Hz = 3000000;
|
||||
ProviderSpi::init(deviceConfig);
|
||||
|
@@ -14,17 +14,17 @@ public:
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
LedDeviceWs2812SPI(const Json::Value &deviceConfig);
|
||||
LedDeviceWs2812SPI(const QJsonObject &deviceConfig);
|
||||
|
||||
/// constructs leddevice
|
||||
static LedDevice* construct(const Json::Value &deviceConfig);
|
||||
static LedDevice* construct(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Sets configuration
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
private:
|
||||
///
|
||||
|
@@ -27,11 +27,11 @@ ProviderHID::~ProviderHID()
|
||||
hid_exit();
|
||||
}
|
||||
|
||||
bool ProviderHID::init(const Json::Value &deviceConfig)
|
||||
bool ProviderHID::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_delayAfterConnect_ms = deviceConfig.get("delayAfterConnect", 0 ).asInt();
|
||||
auto VendorIdString = deviceConfig.get("VID", "0x2341").asString();
|
||||
auto ProductIdString = deviceConfig.get("PID", "0x8036").asString();
|
||||
_delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(0);
|
||||
auto VendorIdString = deviceConfig["VID"].toString("0x2341").toStdString();
|
||||
auto ProductIdString = deviceConfig["PID"].toString("0x8036").toStdString();
|
||||
|
||||
// Convert HEX values to integer
|
||||
_VendorId = std::stoul(VendorIdString, nullptr, 16);
|
||||
|
@@ -19,8 +19,6 @@ public:
|
||||
///
|
||||
/// Constructs specific LedDevice
|
||||
///
|
||||
/// @param deviceConfig json device config
|
||||
///
|
||||
ProviderHID();
|
||||
|
||||
///
|
||||
@@ -33,7 +31,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
||||
@@ -45,7 +43,7 @@ protected:
|
||||
/**
|
||||
* Writes the given bytes to the HID-device and
|
||||
*
|
||||
* @param[in[ size The length of the data
|
||||
* @param[in] size The length of the data
|
||||
* @param[in] data The data
|
||||
*
|
||||
* @return Zero on succes else negative
|
||||
|
@@ -32,13 +32,13 @@ ProviderRs232::ProviderRs232()
|
||||
connect(&_rs232Port, SIGNAL(readyRead()), this, SLOT(readyRead()));
|
||||
}
|
||||
|
||||
bool ProviderRs232::init(const Json::Value &deviceConfig)
|
||||
bool ProviderRs232::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
closeDevice();
|
||||
_deviceName = deviceConfig["output"].asString();
|
||||
_baudRate_Hz = deviceConfig["rate"].asInt();
|
||||
_delayAfterConnect_ms = deviceConfig.get("delayAfterConnect",250).asInt();
|
||||
_timer.setInterval ( deviceConfig.get("rewriteTime",5000).asInt() );
|
||||
_deviceName = deviceConfig["output"].toString().toStdString();
|
||||
_baudRate_Hz = deviceConfig["rate"].toInt();
|
||||
_delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(250);
|
||||
_timer.setInterval ( deviceConfig["rewriteTime"].toInt(5000) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -25,7 +25,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
|
@@ -31,13 +31,13 @@ ProviderSpi::~ProviderSpi()
|
||||
// close(_fid);
|
||||
}
|
||||
|
||||
bool ProviderSpi::init(const Json::Value &deviceConfig)
|
||||
bool ProviderSpi::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
_deviceName = deviceConfig.get("output",_deviceName).asString();
|
||||
_baudRate_Hz = deviceConfig.get("rate",_baudRate_Hz).asInt();
|
||||
_latchTime_ns = deviceConfig.get("latchtime",_latchTime_ns).asInt();
|
||||
_spiMode = deviceConfig.get("spimode",_spiMode).asInt();
|
||||
_spiDataInvert = deviceConfig.get("invert",_spiDataInvert).asBool();
|
||||
_deviceName = deviceConfig["output"].toString(QString::fromStdString(_deviceName)).toStdString();
|
||||
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
|
||||
_latchTime_ns = deviceConfig["latchtime"].toInt(_latchTime_ns);
|
||||
_spiMode = deviceConfig["spimode"].toInt(_spiMode);
|
||||
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -22,7 +22,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
virtual bool init(const Json::Value &deviceConfig);
|
||||
virtual bool init(const QJsonObject &deviceConfig);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice; closes the output device if it is open
|
||||
|
@@ -28,28 +28,28 @@ ProviderUdp::~ProviderUdp()
|
||||
_udpSocket->close();
|
||||
}
|
||||
|
||||
bool ProviderUdp::init(const Json::Value &deviceConfig, std::string defaultHost)
|
||||
bool ProviderUdp::init(const QJsonObject &deviceConfig, std::string defaultHost)
|
||||
{
|
||||
QString host = QString::fromStdString(deviceConfig.get("host",defaultHost).asString());
|
||||
QString host = deviceConfig["host"].toString(QString::fromStdString(defaultHost));
|
||||
|
||||
if (_address.setAddress(host) )
|
||||
{
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
Debug( _log, "Successfully parsed %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].asString().c_str());
|
||||
Debug( _log, "Failed to parse %s as an ip address.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
QHostInfo info = QHostInfo::fromName(host);
|
||||
if (info.addresses().isEmpty())
|
||||
{
|
||||
Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
Debug( _log, "Failed to parse %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
throw std::runtime_error("invalid target address");
|
||||
}
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].asString().c_str());
|
||||
Debug( _log, "Successfully parsed %s as a hostname.", deviceConfig["host"].toString().toStdString().c_str());
|
||||
_address = info.addresses().first();
|
||||
}
|
||||
|
||||
_port = deviceConfig.get("port", _port).asUInt();
|
||||
_port = deviceConfig["port"].toInt(_port);
|
||||
if ( _port<=0 || _port > 65535)
|
||||
{
|
||||
throw std::runtime_error("invalid target port");
|
||||
@@ -57,7 +57,7 @@ bool ProviderUdp::init(const Json::Value &deviceConfig, std::string defaultHost)
|
||||
|
||||
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
|
||||
|
||||
_LatchTime_ns = deviceConfig.get("latchtime", _LatchTime_ns).asInt();
|
||||
_LatchTime_ns = deviceConfig["latchtime"].toInt(_LatchTime_ns);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -94,4 +94,3 @@ int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
|
@@ -27,7 +27,7 @@ public:
|
||||
///
|
||||
/// @param deviceConfig the json device config
|
||||
/// @return true if success
|
||||
bool init(const Json::Value &deviceConfig, std::string defaultHost="127.0.0.1");
|
||||
bool init(const QJsonObject &deviceConfig, std::string defaultHost="127.0.0.1");
|
||||
|
||||
///
|
||||
/// Opens and configures the output device
|
||||
@@ -56,4 +56,3 @@ protected:
|
||||
QHostAddress _address;
|
||||
quint16 _port;
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user