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:
redPanther 2016-08-23 20:07:12 +02:00 committed by GitHub
parent c207828069
commit d679affeb4
103 changed files with 1244 additions and 596 deletions

View File

@ -15,7 +15,7 @@ then
mkdir build || exit 1
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DENABLE_TESTS=ON -Wno-dev .. || exit 2
cmake -DCMAKE_BUILD_TYPE=Debug -DENABLE_TESTS=ON -Wno-dev .. || exit 2
make -j$procs || exit 3
# make -j$(nproc) package || exit 4 # currently osx(dmg) package creation not implemented
fi
@ -25,7 +25,7 @@ if [[ $TRAVIS_OS_NAME == 'linux' ]]
then
mkdir build || exit 1
cd build
cmake -DPLATFORM=x86-dev -DCMAKE_BUILD_TYPE=Release .. || exit 2
cmake -DPLATFORM=x86-dev -DCMAKE_BUILD_TYPE=Debug .. || exit 2
make -j$(nproc) || exit 3
make -j$(nproc) package || exit 4
fi

View File

@ -1,6 +1,8 @@
#!/bin/bash
# install osx deps for hyperion compile
if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
if [[ $TRAVIS_OS_NAME == 'osx' ]]
then
echo "Install OSX deps"
time brew update
time brew install qt5 || true
@ -10,7 +12,8 @@ if [[ $TRAVIS_OS_NAME == 'osx' ]]; then
fi
# install linux deps for hyperion compile
if [[ $TRAVIS_OS_NAME == 'linux' ]]; then
if [[ $TRAVIS_OS_NAME == 'linux' ]]
then
echo "Install linux deps"
sudo apt-get -qq update
sudo apt-get install -qq -y qtbase5-dev libqt5serialport5-dev libusb-1.0-0-dev python-dev libxrender-dev libavahi-core-dev libavahi-compat-libdnssd-dev doxygen

View File

@ -41,7 +41,7 @@ MyClass::MyClass() : myVarA(0),
good:
MyClass::MyClass()
: myVarA(0),
: myVarA(0)
, myVarB("eee")
, myVarC(true)
{

View File

@ -2,14 +2,21 @@
// STL incldues
#include <vector>
#include <QObject>
#include <map>
// Utility includes
#include <utils/ColorRgb.h>
#include <utils/ColorRgbw.h>
#include <utils/RgbToRgbw.h>
#include <utils/Logger.h>
#include <functional>
#include <json/json.h>
class LedDevice;
typedef LedDevice* ( *LedDeviceCreateFuncType ) ( const Json::Value& );
typedef std::map<std::string,LedDeviceCreateFuncType> LedDeviceRegistry;
///
/// Interface (pure virtual base class) for LedDevices.
@ -44,6 +51,10 @@ public:
///
virtual int open();
static int addToDeviceMap(std::string name, LedDeviceCreateFuncType funcPtr);
static const LedDeviceRegistry& getDeviceMap();
static void setActiveDevice(std::string dev);
static std::string activeDevice() { return _activeDevice; };
protected:
/// The common Logger instance for all LedDevices
Logger * _log;
@ -53,4 +64,6 @@ protected:
/// The buffer containing the packed RGB values
std::vector<uint8_t> _ledBuffer;
static std::string _activeDevice;
static LedDeviceRegistry _ledDeviceMap;
};

View File

@ -565,7 +565,6 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
, _raw2ledTransform(createLedColorsTransform(_ledString.leds().size(), jsonConfig["color"]))
, _raw2ledTemperature(createLedColorsTemperature(_ledString.leds().size(), jsonConfig["color"]))
, _raw2ledAdjustment(createLedColorsAdjustment(_ledString.leds().size(), jsonConfig["color"]))
, _device(LedDeviceFactory::construct(jsonConfig["device"]))
, _effectEngine(nullptr)
, _messageForwarder(createMessageForwarder(jsonConfig["forwarder"]))
, _jsonConfig(jsonConfig)
@ -575,6 +574,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
, _hwLedCount(_ledString.leds().size())
, _sourceAutoSelectEnabled(true)
{
_device = LedDeviceFactory::construct(jsonConfig["device"]);
registerPriority("Off", PriorityMuxer::LOWEST_PRIORITY);
if (!_raw2ledAdjustment->verifyAdjustments())

View File

@ -24,6 +24,7 @@
#include <hyperion/ColorCorrection.h>
#include <hyperion/ColorAdjustment.h>
#include <utils/ColorRgb.h>
#include <leddevice/LedDevice.h>
#include <HyperionConfig.h>
#include <utils/jsonschema/JsonFactory.h>
@ -630,15 +631,25 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st
}
}
// get available led devices
info["ledDevices"]["active"] = LedDevice::activeDevice();
info["ledDevices"]["available"] = Json::Value(Json::arrayValue);
for ( auto dev: LedDevice::getDeviceMap())
{
info["ledDevices"]["available"].append(dev.first);
}
// Add Hyperion Version, build time
Json::Value & version = info["hyperion"] = Json::Value(Json::arrayValue);
//Json::Value & version =
info["hyperion"] = Json::Value(Json::arrayValue);
Json::Value ver;
ver["jsonrpc_version"] = HYPERION_JSON_VERSION;
ver["version"] = HYPERION_VERSION;
ver["build"] = HYPERION_BUILD_ID;
ver["time"] = __DATE__ " " __TIME__;
version.append(ver);
info["hyperion"].append(ver);
// send the result
sendMessage(result);
@ -941,7 +952,7 @@ void JsonClientConnection::handleConfigSetCommand(const Json::Value &message, co
sendSuccessReply(command, tan);
}
} else
sendErrorReply("Error while parsing json: Message size " + message.size(), command, tan);
sendErrorReply("Error while parsing json: Message size " + std::to_string(message.size()), command, tan);
}
void JsonClientConnection::handleComponentStateCommand(const Json::Value& message, const std::string &command, const int tan)

View File

@ -34,13 +34,12 @@ SET(Leddevice_HEADERS
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
${CURRENT_SOURCE_DIR}/LedDeviceFile.h
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
${CURRENT_SOURCE_DIR}/LedDeviceUdp.h
${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.h
${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.h
${CURRENT_SOURCE_DIR}/LedUdpDevice.h
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
${CURRENT_SOURCE_DIR}/LedDeviceTpm2net.h
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h
)
@ -62,13 +61,13 @@ SET(Leddevice_SOURCES
${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp
${CURRENT_SOURCE_DIR}/LedDeviceFile.cpp
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp
${CURRENT_SOURCE_DIR}/LedDeviceUdp.cpp
${CURRENT_SOURCE_DIR}/LedDeviceUdpRaw.cpp
${CURRENT_SOURCE_DIR}/LedDeviceUdpE131.cpp
${CURRENT_SOURCE_DIR}/LedUdpDevice.cpp
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTpm2net.cpp
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.cpp
)
@ -131,7 +130,13 @@ if(ENABLE_TINKERFORGE)
)
endif()
set(LedDevice_RESOURCES
${CURRENT_SOURCE_DIR}/LedDeviceSchemas.qrc
)
QT5_WRAP_CPP(Leddevice_HEADERS_MOC ${Leddevice_QT_HEADERS})
qt5_add_resources(LedDevice_RESOURCES_RCC ${LedDevice_RESOURCES} OPTIONS "-no-compress")
add_library(leddevice
@ -139,13 +144,14 @@ add_library(leddevice
${Leddevice_QT_HEADERS}
${Leddevice_HEADERS_MOC}
${Leddevice_SOURCES}
${LedDevice_RESOURCES}
${LedDevice_RESOURCES_RCC}
)
qt5_use_modules(leddevice Network SerialPort)
target_link_libraries(leddevice
hyperion-utils
# serialport
${LIBUSB_1_LIBRARIES} #apt-get install libusb-1.0-0-dev
${CMAKE_THREAD_LIBS_INIT}
${QT_LIBRARIES}

View File

@ -1,5 +1,8 @@
#include <leddevice/LedDevice.h>
LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry();
std::string LedDevice::_activeDevice = "";
LedDevice::LedDevice()
: QObject()
, _log(Logger::getInstance("LedDevice"))
@ -9,8 +12,24 @@ LedDevice::LedDevice()
{
}
// dummy implemention
int LedDevice::open()
{
//dummy implemention
return 0;
}
int LedDevice::addToDeviceMap(std::string name, LedDeviceCreateFuncType funcPtr)
{
_ledDeviceMap.emplace(name,funcPtr);
return 0;
}
const LedDeviceRegistry& LedDevice::getDeviceMap()
{
return _ledDeviceMap;
}
void LedDevice::setActiveDevice(std::string dev)
{
_activeDevice = dev;
}

View File

@ -12,9 +12,15 @@
// hyperion local includes
#include "LedDeviceAPA102.h"
LedDeviceAPA102::LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate)
: LedSpiDevice(outputDevice, baudrate, 500000)
LedDeviceAPA102::LedDeviceAPA102(const Json::Value &deviceConfig)
: LedSpiDevice(deviceConfig)
{
_latchTime_ns = 500000;
}
LedDevice* LedDeviceAPA102::construct(const Json::Value &deviceConfig)
{
return new LedDeviceAPA102(deviceConfig);
}
int LedDeviceAPA102::write(const std::vector<ColorRgb> &ledValues)

View File

@ -5,22 +5,23 @@
// hyperion incluse
#include "LedSpiDevice.h"
#include <json/json.h>
///
/// Implementation of the LedDevice interface for writing to APA102 led device.
///
/// APA102 is
///
class LedDeviceAPA102 : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type APA102
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/dev/spidev.0.0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceAPA102(const std::string& outputDevice, const unsigned baudrate );
LedDeviceAPA102(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///

View File

@ -10,9 +10,10 @@
// hyperion local includes
#include "LedDeviceAdalight.h"
#include <leddevice/LedDevice.h>
LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms)
: LedRs232Device(outputDevice, baudrate, delayAfterConnect_ms)
LedDeviceAdalight::LedDeviceAdalight(const Json::Value &deviceConfig)
: LedRs232Device(deviceConfig)
, _timer()
{
// setup the timer
@ -24,6 +25,11 @@ LedDeviceAdalight::LedDeviceAdalight(const std::string& outputDevice, const unsi
_timer.start();
}
LedDevice* LedDeviceAdalight::construct(const Json::Value &deviceConfig)
{
return new LedDeviceAdalight(deviceConfig);
}
int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
{
if (_ledBuffer.size() == 0)

View File

@ -18,12 +18,14 @@ class LedDeviceAdalight : public LedRs232Device
public:
///
/// Constructs the LedDevice for attached Adalight device
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceAdalight(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms);
LedDeviceAdalight(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device
@ -46,3 +48,4 @@ protected:
/// every 15 seconds
QTimer _timer;
};

View File

@ -11,11 +11,17 @@
// hyperion local includes
#include "LedDeviceAdalightApa102.h"
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms)
: LedDeviceAdalight(outputDevice, baudrate, delayAfterConnect_ms)
LedDeviceAdalightApa102::LedDeviceAdalightApa102(const Json::Value &deviceConfig)
: LedDeviceAdalight(deviceConfig)
{
}
LedDevice* LedDeviceAdalightApa102::construct(const Json::Value &deviceConfig)
{
return new LedDeviceAdalightApa102(deviceConfig);
}
//comparing to ws2801 adalight, the following changes were needed:
// 1- differnt data frame (4 bytes instead of 3)
// 2 - in order to accomodate point 1 above, number of leds sent to adalight is increased by 1/3rd

View File

@ -20,7 +20,10 @@ 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 std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms);
LedDeviceAdalightApa102(const Json::Value &deviceConfig);
/// create leddevice when type in config is set to this type
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device
@ -33,3 +36,4 @@ public:
/// Switch the leds off
virtual int switchOff();
};

View File

@ -1,8 +1,8 @@
// hyperion local includes
#include "LedDeviceAtmo.h"
LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate)
: LedRs232Device(outputDevice, baudrate)
LedDeviceAtmo::LedDeviceAtmo(const Json::Value &deviceConfig)
: LedRs232Device(deviceConfig)
{
_ledBuffer.resize(4 + 5*3); // 4-byte header, 5 RGB values
_ledBuffer[0] = 0xFF; // Startbyte
@ -11,6 +11,12 @@ LedDeviceAtmo::LedDeviceAtmo(const std::string& outputDevice, const unsigned bau
_ledBuffer[3] = 0x0F; // Number of Databytes send (always! 15)
}
LedDevice* LedDeviceAtmo::construct(const Json::Value &deviceConfig)
{
return new LedDeviceAtmo(deviceConfig);
}
int LedDeviceAtmo::write(const std::vector<ColorRgb> &ledValues)
{
// The protocol is shomehow limited. we always need to send exactly 5 channels + header

View File

@ -13,13 +13,14 @@ class LedDeviceAtmo : public LedRs232Device
{
public:
///
/// Constructs the LedDevice for attached serial device using supporting tpm2 protocol
/// All LEDs in the stripe are handled as one frame
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/dev/ttyAMA0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceAtmo(const std::string& outputDevice, const unsigned baudrate);
LedDeviceAtmo(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -8,6 +8,7 @@
#include <QNetworkReply>
#include <stdexcept>
#include <sstream>
#include <string>
#include <set>
@ -15,23 +16,10 @@ AtmoOrbLight::AtmoOrbLight(unsigned int id) {
// Not implemented
}
LedDeviceAtmoOrb::LedDeviceAtmoOrb(
const std::string &output,
bool useOrbSmoothing,
int transitiontime,
int skipSmoothingDiff,
int port,
int numLeds,
std::vector<unsigned int> orbIds)
LedDeviceAtmoOrb::LedDeviceAtmoOrb(const Json::Value &deviceConfig)
: LedDevice()
, _multicastGroup(output.c_str())
, _useOrbSmoothing(useOrbSmoothing)
, _transitiontime(transitiontime)
, _skipSmoothingDiff(skipSmoothingDiff)
, _multiCastGroupPort(port)
, _numLeds(numLeds)
, _orbIds(orbIds)
{
setConfig(deviceConfig);
_manager = new QNetworkAccessManager();
_groupAddress = QHostAddress(_multicastGroup);
@ -41,6 +29,44 @@ LedDeviceAtmoOrb::LedDeviceAtmoOrb(
joinedMulticastgroup = _udpSocket->joinMulticastGroup(_groupAddress);
}
bool LedDeviceAtmoOrb::setConfig(const Json::Value &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();
const std::string orbId = deviceConfig["orbIds"].asString();
_orbIds.clear();
// 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()));
}
return true;
}
LedDevice* LedDeviceAtmoOrb::construct(const Json::Value &deviceConfig)
{
return new LedDeviceAtmoOrb(deviceConfig);
}
int LedDeviceAtmoOrb::write(const std::vector <ColorRgb> &ledValues)
{
// If not in multicast group return

View File

@ -45,20 +45,21 @@ public:
bool joinedMulticastgroup;
///
/// Constructs the device.
/// Constructs specific LedDevice
///
/// @param output is the multicast address of Orbs
/// @param transitiontime is optional and not used at the moment
/// @param useOrbSmoothing use Orbs own (external) smoothing algorithm (default: false)
/// @param skipSmoothingDiff minimal color (0-255) difference to override smoothing so that if current and previously received colors are higher than set dif we override smoothing
/// @param port is the multicast port.
/// @param numLeds is the total amount of leds per Orb
/// @param array containing orb ids
/// @param deviceConfig json device config
///
LedDeviceAtmoOrb(const std::string &output, bool useOrbSmoothing =
false, int transitiontime = 0, int skipSmoothingDiff = 0, int port = 49692, int numLeds = 24,
std::vector<unsigned int> orbIds = std::vector<unsigned int>());
LedDeviceAtmoOrb(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Destructor of this device
///

View File

@ -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")
if (dev.first == type)
{
device = new LedDeviceAdalightApa102(
deviceConfig["output"].asString(),
deviceConfig["rate"].asInt(),
deviceConfig.get("delayAfterConnect",500).asInt()
);
device = dev.second(deviceConfig);
LedDevice::setActiveDevice(dev.first);
Info(log,"LedDevice '%s' configured.", dev.first.c_str());
break;
}
#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())
{
throw std::runtime_error("Piblaster: The piblaster configuration syntax has changed in this version.");
}
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();

View File

@ -10,13 +10,6 @@ LedDeviceFadeCandy::LedDeviceFadeCandy(const Json::Value &deviceConfig)
: LedDevice()
{
setConfig(deviceConfig);
_opc_data.resize( OPC_HEADER_SIZE );
_opc_data[0] = _channel;
_opc_data[1] = OPC_SET_PIXELS;
_opc_data[2] = 0;
_opc_data[3] = 0;
}
@ -25,8 +18,16 @@ LedDeviceFadeCandy::~LedDeviceFadeCandy()
_client.close();
}
LedDevice* LedDeviceFadeCandy::construct(const Json::Value &deviceConfig)
{
return new LedDeviceFadeCandy(deviceConfig);
}
bool LedDeviceFadeCandy::setConfig(const Json::Value &deviceConfig)
{
_client.close();
_host = deviceConfig.get("output", "127.0.0.1").asString();
_port = deviceConfig.get("port", 7890).asInt();
_channel = deviceConfig.get("channel", 0).asInt();
@ -49,6 +50,12 @@ bool LedDeviceFadeCandy::setConfig(const Json::Value &deviceConfig)
_whitePoint_b = whitePointConfig[2].asDouble();
}
_opc_data.resize( OPC_HEADER_SIZE );
_opc_data[0] = _channel;
_opc_data[1] = OPC_SET_PIXELS;
_opc_data[2] = 0;
_opc_data[3] = 0;
return true;
}

View File

@ -7,7 +7,6 @@
// Leddevice includes
#include <leddevice/LedDevice.h>
#include <json/json.h>
///
/// Implementation of the LedDevice interface for sending to
@ -48,6 +47,9 @@ public:
///
virtual ~LedDeviceFadeCandy();
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Sets configuration
///
@ -66,7 +68,6 @@ public:
/// Switch the leds off
virtual int switchOff();
private:
QTcpSocket _client;
std::string _host;
@ -115,3 +116,4 @@ private:
void sendFadeCandyConfiguration();
};

View File

@ -2,16 +2,32 @@
// Local-Hyperion includes
#include "LedDeviceFile.h"
LedDeviceFile::LedDeviceFile(const std::string& output)
LedDeviceFile::LedDeviceFile(const Json::Value &deviceConfig)
: LedDevice()
, _ofs( output.empty() ? "/dev/null" : output.c_str())
{
// empty
setConfig(deviceConfig);
}
LedDeviceFile::~LedDeviceFile()
{
// empty
}
LedDevice* LedDeviceFile::construct(const Json::Value &deviceConfig)
{
return new LedDeviceFile(deviceConfig);
}
bool LedDeviceFile::setConfig(const Json::Value &deviceConfig)
{
if ( _ofs.is_open() )
{
_ofs.close();
}
std::string fileName = deviceConfig.get("output","/dev/null").asString();
_ofs.open( fileName.c_str() );
return true;
}
int LedDeviceFile::write(const std::vector<ColorRgb> & ledValues)

View File

@ -14,15 +14,27 @@ class LedDeviceFile : public LedDevice
{
public:
///
/// Constructs the test-device, which opens an output stream to the file
/// Constructs specific LedDevice
///
LedDeviceFile(const std::string& output);
/// @param deviceConfig json device config
///
LedDeviceFile(const Json::Value &deviceConfig);
///
/// Destructor of this test-device
///
virtual ~LedDeviceFile();
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool setConfig(const Json::Value &deviceConfig);
///
/// Writes the given led-color values to the output stream
///

View File

@ -11,12 +11,12 @@ uint16_t LedDeviceHyperionUsbasp::_usbProductId = 0x05dc;
std::string LedDeviceHyperionUsbasp::_usbProductDescription = "Hyperion led controller";
LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(uint8_t writeLedsCommand)
LedDeviceHyperionUsbasp::LedDeviceHyperionUsbasp(const Json::Value &deviceConfig)
: LedDevice()
, _writeLedsCommand(writeLedsCommand)
, _libusbContext(nullptr)
, _deviceHandle(nullptr)
{
setConfig(deviceConfig);
}
LedDeviceHyperionUsbasp::~LedDeviceHyperionUsbasp()
@ -37,6 +37,25 @@ LedDeviceHyperionUsbasp::~LedDeviceHyperionUsbasp()
}
}
bool LedDeviceHyperionUsbasp::setConfig(const Json::Value &deviceConfig)
{
std::string ledType = deviceConfig.get("output", "ws2801").asString();
if (ledType != "ws2801" && ledType != "ws2812")
{
throw std::runtime_error("HyperionUsbasp: invalid output; must be 'ws2801' or 'ws2812'.");
}
_writeLedsCommand = (ledType == "ws2801") ? CMD_WRITE_WS2801 : CMD_WRITE_WS2812;
return true;
}
LedDevice* LedDeviceHyperionUsbasp::construct(const Json::Value &deviceConfig)
{
return new LedDeviceHyperionUsbasp(deviceConfig);
}
int LedDeviceHyperionUsbasp::open()
{
int error;

View File

@ -24,9 +24,21 @@ public:
};
///
/// Constructs the LedDeviceLightpack
/// Constructs specific LedDevice
///
LedDeviceHyperionUsbasp(uint8_t writeLedsCommand);
/// @param deviceConfig json device config
///
LedDeviceHyperionUsbasp(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Destructor of the LedDevice; closes the output device if it is open
@ -70,7 +82,7 @@ private:
private:
/// command to write the leds
const uint8_t _writeLedsCommand;
uint8_t _writeLedsCommand;
/// libusb context
libusb_context * _libusbContext;

View File

@ -45,6 +45,12 @@ LedDeviceLightpack::LedDeviceLightpack(const std::string & serialNumber)
_ledCount = -1;
}
LedDeviceLightpack::LedDeviceLightpack(const Json::Value &deviceConfig)
: LedDeviceLightpack()
{
setConfig(deviceConfig);
}
LedDeviceLightpack::~LedDeviceLightpack()
{
if (_deviceHandle != nullptr)
@ -63,6 +69,18 @@ LedDeviceLightpack::~LedDeviceLightpack()
}
}
bool LedDeviceLightpack::setConfig(const Json::Value &deviceConfig)
{
_serialNumber = deviceConfig.get("output", "").asString();
return true;
}
LedDevice* LedDeviceLightpack::construct(const Json::Value &deviceConfig)
{
return new LedDeviceLightpack(deviceConfig);
}
int LedDeviceLightpack::open()
{
int error;

View File

@ -23,6 +23,22 @@ public:
/// @param serialNumber serial output device
///
LedDeviceLightpack(const std::string & serialNumber = "");
///
/// Constructs specific LedDevice
///
/// @param deviceConfig json device config
///
LedDeviceLightpack(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Destructor of the LedDevice; closes the output device if it is open

View File

@ -10,11 +10,16 @@
// hyperion local includes
#include "LedDeviceLpd6803.h"
LedDeviceLpd6803::LedDeviceLpd6803(const std::string& outputDevice, const unsigned baudrate)
: LedSpiDevice(outputDevice, baudrate)
LedDeviceLpd6803::LedDeviceLpd6803(const Json::Value &deviceConfig)
: LedSpiDevice(deviceConfig)
{
}
LedDevice* LedDeviceLpd6803::construct(const Json::Value &deviceConfig)
{
return new LedDeviceLpd6803(deviceConfig);
}
int LedDeviceLpd6803::write(const std::vector<ColorRgb> &ledValues)
{
unsigned messageLength = 4 + 2*ledValues.size() + ledValues.size()/8 + 1;

View File

@ -18,12 +18,14 @@ class LedDeviceLpd6803 : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type LDP6803
/// Constructs specific LedDevice
///
/// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0')
/// @param[in] baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceLpd6803(const std::string& outputDevice, const unsigned baudrate);
LedDeviceLpd6803(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -10,10 +10,14 @@
// hyperion local includes
#include "LedDeviceLpd8806.h"
LedDeviceLpd8806::LedDeviceLpd8806(const std::string& outputDevice, const unsigned baudrate)
: LedSpiDevice(outputDevice, baudrate)
LedDeviceLpd8806::LedDeviceLpd8806(const Json::Value &deviceConfig)
: LedSpiDevice(deviceConfig)
{
// empty
}
LedDevice* LedDeviceLpd8806::construct(const Json::Value &deviceConfig)
{
return new LedDeviceLpd8806(deviceConfig);
}
int LedDeviceLpd8806::write(const std::vector<ColorRgb> &ledValues)

View File

@ -79,12 +79,14 @@ class LedDeviceLpd8806 : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type LPD8806
/// Constructs specific LedDevice
///
/// @param[in] outputDevice The name of the output device (eg '/dev/spidev0.0')
/// @param[in] baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceLpd8806(const std::string& outputDevice, const unsigned baudrate);
LedDeviceLpd8806(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -17,7 +17,7 @@ bool compareLightpacks(LedDeviceLightpack * lhs, LedDeviceLightpack * rhs)
return lhs->getSerialNumber() < rhs->getSerialNumber();
}
LedDeviceMultiLightpack::LedDeviceMultiLightpack()
LedDeviceMultiLightpack::LedDeviceMultiLightpack(const Json::Value &)
: LedDevice()
, _lightpacks()
{
@ -31,6 +31,11 @@ LedDeviceMultiLightpack::~LedDeviceMultiLightpack()
}
}
LedDevice* LedDeviceMultiLightpack::construct(const Json::Value &deviceConfig)
{
return new LedDeviceMultiLightpack(deviceConfig);
}
int LedDeviceMultiLightpack::open()
{
// retrieve a list with Lightpack serials

View File

@ -20,15 +20,20 @@ class LedDeviceMultiLightpack : public LedDevice
{
public:
///
/// Constructs the LedDeviceMultiLightpack
/// Constructs specific LedDevice
///
LedDeviceMultiLightpack();
/// @param deviceConfig json device config
///
LedDeviceMultiLightpack(const Json::Value &);
///
/// Destructor of the LedDevice; closes the output device if it is open
///
virtual ~LedDeviceMultiLightpack();
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Opens and configures the output device7
///

View File

@ -11,10 +11,14 @@
// hyperion local includes
#include "LedDeviceP9813.h"
LedDeviceP9813::LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate)
: LedSpiDevice(outputDevice, baudrate, 0)
LedDeviceP9813::LedDeviceP9813(const Json::Value &deviceConfig)
: LedSpiDevice(deviceConfig)
{
// empty
}
LedDevice* LedDeviceP9813::construct(const Json::Value &deviceConfig)
{
return new LedDeviceP9813(deviceConfig);
}
int LedDeviceP9813::write(const std::vector<ColorRgb> &ledValues)

View File

@ -13,12 +13,14 @@ class LedDeviceP9813 : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type P9813
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceP9813(const std::string& outputDevice, const unsigned baudrate);
LedDeviceP9813(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -3,12 +3,16 @@
#include "LedDevicePaintpack.h"
// Use out report HID device
LedDevicePaintpack::LedDevicePaintpack(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms)
: LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, false)
LedDevicePaintpack::LedDevicePaintpack(const Json::Value &deviceConfig)
: LedHIDDevice(deviceConfig)
{
// empty
_useFeature = false;
}
LedDevice* LedDevicePaintpack::construct(const Json::Value &deviceConfig)
{
return new LedDevicePaintpack(deviceConfig);
}
int LedDevicePaintpack::write(const std::vector<ColorRgb> & ledValues)
{

View File

@ -12,10 +12,15 @@
class LedDevicePaintpack : public LedHIDDevice
{
public:
/**
* Constructs the paintpack device
*/
LedDevicePaintpack(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms);
///
/// Constructs specific LedDevice
///
/// @param deviceConfig json device config
///
LedDevicePaintpack(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the RGB-Color values to the leds.

View File

@ -164,14 +164,11 @@ CiColor PhilipsHueLight::rgbToCiColor(float red, float green, float blue)
return xy;
}
LedDevicePhilipsHue::LedDevicePhilipsHue(const std::string& output, const std::string& username, bool switchOffOnBlack, int transitiontime, std::vector<unsigned int> lightIds)
LedDevicePhilipsHue::LedDevicePhilipsHue(const Json::Value &deviceConfig)
: LedDevice()
, host(output.c_str())
, username(username.c_str())
, switchOffOnBlack(switchOffOnBlack)
, transitiontime(transitiontime)
, lightIds(lightIds)
{
setConfig(deviceConfig);
manager = new QNetworkAccessManager();
timer.setInterval(3000);
timer.setSingleShot(true);
@ -183,6 +180,26 @@ LedDevicePhilipsHue::~LedDevicePhilipsHue()
delete manager;
}
bool LedDevicePhilipsHue::setConfig(const Json::Value &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();
lightIds.clear();
for (Json::Value::ArrayIndex i = 0; i < deviceConfig["lightIds"].size(); i++)
{
lightIds.push_back(deviceConfig["lightIds"][i].asInt());
}
return true;
}
LedDevice* LedDevicePhilipsHue::construct(const Json::Value &deviceConfig)
{
return new LedDevicePhilipsHue(deviceConfig);
}
int LedDevicePhilipsHue::write(const std::vector<ColorRgb> & ledValues)
{
// Save light states if not done before.

View File

@ -115,22 +115,27 @@ class LedDevicePhilipsHue: public LedDevice {
public:
///
/// Constructs the device.
/// Constructs specific LedDevice
///
/// @param output the ip address of the bridge
/// @param username username of the hue bridge (default: newdeveloper)
/// @param switchOffOnBlack kill lights for black (default: false)
/// @param transitiontime the time duration a light change takes in multiples of 100 ms (default: 400 ms).
/// @param lightIds light ids of the lights to control if not starting at one in ascending order.
/// @param deviceConfig json device config
///
LedDevicePhilipsHue(const std::string& output, const std::string& username = "newdeveloper", bool switchOffOnBlack =
false, int transitiontime = 1, std::vector<unsigned int> lightIds = std::vector<unsigned int>());
LedDevicePhilipsHue(const Json::Value &deviceConfig);
///
/// Destructor of this device
///
virtual ~LedDevicePhilipsHue();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Sends the given led-color values via put request to the hue system
///

View File

@ -13,11 +13,9 @@
// Local LedDevice includes
#include "LedDevicePiBlaster.h"
LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping)
: _deviceName(deviceName)
, _fid(nullptr)
LedDevicePiBlaster::LedDevicePiBlaster(const Json::Value &deviceConfig)
: _fid(nullptr)
{
signal(SIGPIPE, SIG_IGN);
// initialise the mapping tables
@ -32,7 +30,31 @@ LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Jso
_gpio_to_color[i] = 'z';
}
// walk through the json config and populate the mapping tables
setConfig(deviceConfig);
}
LedDevicePiBlaster::~LedDevicePiBlaster()
{
// Close the device (if it is opened)
if (_fid != nullptr)
{
fclose(_fid);
_fid = nullptr;
}
}
bool LedDevicePiBlaster::setConfig(const Json::Value &deviceConfig)
{
_deviceName = deviceConfig.get("output", "").asString();
Json::Value gpioMapping = deviceConfig.get("gpiomap", Json::nullValue);
if (gpioMapping.isNull())
{
throw std::runtime_error("Piblaster: no gpiomap defined.");
}
// walk through the json config and populate the mapping tables
for (const Json::Value& gpioMap : gpioMapping)
{
const int gpio = gpioMap.get("gpio",-1).asInt();
@ -47,16 +69,12 @@ LedDevicePiBlaster::LedDevicePiBlaster(const std::string & deviceName, const Jso
Warning( _log, "IGNORING gpio %d ledindex %d color %c", gpio,ledindex, ledcolor[0]);
}
}
return true;
}
LedDevicePiBlaster::~LedDevicePiBlaster()
LedDevice* LedDevicePiBlaster::construct(const Json::Value &deviceConfig)
{
// Close the device (if it is opened)
if (_fid != nullptr)
{
fclose(_fid);
_fid = nullptr;
}
return new LedDevicePiBlaster(deviceConfig);
}
int LedDevicePiBlaster::open()

View File

@ -14,15 +14,24 @@ class LedDevicePiBlaster : public LedDevice
{
public:
///
/// Constructs the PiBlaster device which writes to the indicated device and for the assigned
/// channels
/// @param deviceName The name of the output device
/// @param gpioMapping The RGB-Channel assignment json object
/// Constructs specific LedDevice
///
LedDevicePiBlaster(const std::string & deviceName, const Json::Value & gpioMapping);
/// @param deviceConfig json device config
///
LedDevicePiBlaster(const Json::Value &deviceConfig);
virtual ~LedDevicePiBlaster();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Attempts to open the piblaster-device. This will only succeed if the device is not yet open
/// and the device is available.
@ -50,7 +59,7 @@ public:
private:
/// The name of the output device (very likely '/dev/pi-blaster')
const std::string _deviceName;
std::string _deviceName;
int _gpio_to_led[64];
char _gpio_to_color[64];

View File

@ -12,10 +12,12 @@
#include "LedDeviceRawHID.h"
// Use feature report HID device
LedDeviceRawHID::LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms)
: LedHIDDevice(VendorId, ProductId, delayAfterConnect_ms, true)
LedDeviceRawHID::LedDeviceRawHID(const Json::Value &deviceConfig)
: LedHIDDevice(deviceConfig)
, _timer()
{
_useFeature = true;
// setup the timer
_timer.setSingleShot(false);
_timer.setInterval(5000);
@ -25,6 +27,11 @@ LedDeviceRawHID::LedDeviceRawHID(const unsigned short VendorId, const unsigned s
_timer.start();
}
LedDevice* LedDeviceRawHID::construct(const Json::Value &deviceConfig)
{
return new LedDeviceRawHID(deviceConfig);
}
int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
{
// Resize buffer if required

View File

@ -18,9 +18,14 @@ class LedDeviceRawHID : public LedHIDDevice
public:
///
/// Constructs the LedDevice for attached RawHID device
/// Constructs specific LedDevice
///
LedDeviceRawHID(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms);
/// @param deviceConfig json device config
///
LedDeviceRawHID(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -0,0 +1,31 @@
<RCC>
<qresource prefix="/">
<file alias="schema-adalightapa102">schemas/schema-adalightapa102.json</file>
<file alias="schema-adalight">schemas/schema-adalight.json</file>
<file alias="schema-apa102">schemas/schema-apa102.json</file>
<file alias="schema-atmo">schemas/schema-atmo.json</file>
<file alias="schema-atmoorb">schemas/schema-atmoorb.json</file>
<file alias="schema-e131">schemas/schema-e131.json</file>
<file alias="schema-fadecandy">schemas/schema-fadecandy.json</file>
<file alias="schema-file">schemas/schema-file.json</file>
<file alias="schema-hyperion-usbasp">schemas/schema-hyperion-usbasp.json</file>
<file alias="schema-lightpack">schemas/schema-lightpack.json</file>
<file alias="schema-lpd6803">schemas/schema-lpd6803.json</file>
<file alias="schema-lpd8806">schemas/schema-lpd8806.json</file>
<file alias="schema-multi-lightpack">schemas/schema-multi-lightpack.json</file>
<file alias="schema-p9813">schemas/schema-p9813.json</file>
<file alias="schema-paintpack">schemas/schema-paintpack.json</file>
<file alias="schema-philipshue">schemas/schema-philipshue.json</file>
<file alias="schema-piblaster">schemas/schema-piblaster.json</file>
<file alias="schema-rawhid">schemas/schema-rawhid.json</file>
<file alias="schema-sedu">schemas/schema-sedu.json</file>
<file alias="schema-sk6812rgbw-spi">schemas/schema-sk6812rgbw-spi.json</file>
<file alias="schema-tinkerforge">schemas/schema-tinkerforge.json</file>
<file alias="schema-tmp2net">schemas/schema-tmp2net.json</file>
<file alias="schema-tpm2.json">schemas/schema-tpm2.json</file>
<file alias="schema-udpraw">schemas/schema-udpraw.json</file>
<file alias="schema-ws2801">schemas/schema-ws2801.json</file>
<file alias="schema-ws2812spi">schemas/schema-ws2812spi.json</file>
<file alias="schema-ws281x">schemas/schema-ws281x.json</file>
</qresource>
</RCC>

View File

@ -17,12 +17,17 @@ struct FrameSpec
size_t size;
};
LedDeviceSedu::LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate)
: LedRs232Device(outputDevice, baudrate)
LedDeviceSedu::LedDeviceSedu(const Json::Value &deviceConfig)
: LedRs232Device(deviceConfig)
{
// empty
}
LedDevice* LedDeviceSedu::construct(const Json::Value &deviceConfig)
{
return new LedDeviceSedu(deviceConfig);
}
int LedDeviceSedu::write(const std::vector<ColorRgb> &ledValues)
{
if (_ledBuffer.size() == 0)

View File

@ -13,12 +13,14 @@ class LedDeviceSedu : public LedRs232Device
{
public:
///
/// Constructs the LedDevice for attached via SEDU device
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/dev/ttyS0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceSedu(const std::string& outputDevice, const unsigned baudrate);
LedDeviceSedu(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -11,10 +11,8 @@
// hyperion local includes
#include "LedDeviceSk6812SPI.h"
LedDeviceSk6812SPI::LedDeviceSk6812SPI(const std::string& outputDevice, const unsigned baudrate, const std::string& whiteAlgorithm,
const int spiMode, const bool spiDataInvert)
: LedSpiDevice(outputDevice, baudrate, 0, spiMode, spiDataInvert)
, _whiteAlgorithm(whiteAlgorithm)
LedDeviceSk6812SPI::LedDeviceSk6812SPI(const Json::Value &deviceConfig)
: LedSpiDevice(deviceConfig)
, bitpair_to_byte {
0b10001000,
0b10001100,
@ -23,7 +21,21 @@ LedDeviceSk6812SPI::LedDeviceSk6812SPI(const std::string& outputDevice, const un
}
{
Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str());
setConfig(deviceConfig);
Debug( _log, "whiteAlgorithm : %s", _whiteAlgorithm.c_str());
}
LedDevice* LedDeviceSk6812SPI::construct(const Json::Value &deviceConfig)
{
return new LedDeviceSk6812SPI(deviceConfig);
}
bool LedDeviceSk6812SPI::setConfig(const Json::Value &deviceConfig)
{
LedSpiDevice::setConfig(deviceConfig);
_whiteAlgorithm = deviceConfig.get("white_algorithm","").asString();
return true;
}
int LedDeviceSk6812SPI::write(const std::vector<ColorRgb> &ledValues)

View File

@ -13,14 +13,21 @@ class LedDeviceSk6812SPI : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type Sk6812SPI
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceSk6812SPI(const Json::Value &deviceConfig);
LedDeviceSk6812SPI(const std::string& outputDevice, const unsigned baudrate,
const std::string& whiteAlgorithm, const int spiMode, const bool spiDataInvert);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -9,17 +9,13 @@
static const unsigned MAX_NUM_LEDS = 320;
static const unsigned MAX_NUM_LEDS_SETTABLE = 16;
LedDeviceTinkerforge::LedDeviceTinkerforge(const std::string & host, uint16_t port, const std::string & uid, const unsigned interval)
LedDeviceTinkerforge::LedDeviceTinkerforge(const Json::Value &deviceConfig)
: LedDevice()
, _host(host)
, _port(port)
, _uid(uid)
, _interval(interval)
, _ipConnection(nullptr)
, _ledStrip(nullptr)
, _colorChannelSize(0)
{
// empty
setConfig(deviceConfig);
}
LedDeviceTinkerforge::~LedDeviceTinkerforge()
@ -35,6 +31,21 @@ LedDeviceTinkerforge::~LedDeviceTinkerforge()
delete _ledStrip;
}
bool LedDeviceTinkerforge::setConfig(const Json::Value &deviceConfig)
{
_host = deviceConfig.get("output", "127.0.0.1").asString();
_port = deviceConfig.get("port", 4223).asInt();
_uid = deviceConfig["uid"].asString();
_interval = deviceConfig["rate"].asInt();
return true;
}
LedDevice* LedDeviceTinkerforge::construct(const Json::Value &deviceConfig)
{
return new LedDeviceTinkerforge(deviceConfig);
}
int LedDeviceTinkerforge::open()
{
// Check if connection is already createds

View File

@ -16,11 +16,25 @@ extern "C" {
class LedDeviceTinkerforge : public LedDevice
{
public:
LedDeviceTinkerforge(const std::string &host, uint16_t port, const std::string &uid, const unsigned interval);
///
/// Constructs specific LedDevice
///
/// @param deviceConfig json device config
///
LedDeviceTinkerforge(const Json::Value &deviceConfig);
virtual ~LedDeviceTinkerforge();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Attempts to open a connection to the master bricklet and the led strip bricklet.
///
@ -50,16 +64,16 @@ private:
int transferLedData(LEDStrip *ledstrip, unsigned int index, unsigned int length, uint8_t *redChannel, uint8_t *greenChannel, uint8_t *blueChannel);
/// The host of the master brick
const std::string _host;
std::string _host;
/// The port of the master brick
const uint16_t _port;
uint16_t _port;
/// The uid of the led strip bricklet
const std::string _uid;
std::string _uid;
/// The interval/rate
const unsigned _interval;
unsigned _interval;
/// ip connection handle
IPConnection *_ipConnection;

View File

@ -6,11 +6,16 @@
// hyperion local includes
#include "LedDeviceTpm2.h"
#include <json/json.h>
LedDeviceTpm2::LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate)
: LedRs232Device(outputDevice, baudrate)
LedDeviceTpm2::LedDeviceTpm2(const Json::Value &deviceConfig)
: LedRs232Device(deviceConfig)
{
// empty
}
LedDevice* LedDeviceTpm2::construct(const Json::Value &deviceConfig)
{
return new LedDeviceTpm2(deviceConfig);
}
int LedDeviceTpm2::write(const std::vector<ColorRgb> &ledValues)

View File

@ -13,13 +13,14 @@ class LedDeviceTpm2 : public LedRs232Device
{
public:
///
/// Constructs the LedDevice for attached serial device using supporting tpm2 protocol
/// All LEDs in the stripe are handled as one frame
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/dev/ttyAMA0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate);
LedDeviceTpm2(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -0,0 +1,63 @@
// STL includes
#include <cstring>
#include <cstdio>
#include <iostream>
#include <sstream>
// Local-Hyperion includes
#include "LedDeviceTpm2net.h"
LedDeviceTpm2net::LedDeviceTpm2net(const Json::Value &deviceConfig)
: LedDevice()
, _socket(this)
{
setConfig(deviceConfig);
}
LedDeviceTpm2net::~LedDeviceTpm2net()
{
}
bool LedDeviceTpm2net::setConfig(const Json::Value &deviceConfig)
{
_host = QHostAddress(QString::fromStdString(deviceConfig.get("output", "127.0.0.1").asString()));
_port = deviceConfig.get("port", 65506).asInt();
return true;
}
LedDevice* LedDeviceTpm2net::construct(const Json::Value &deviceConfig)
{
return new LedDeviceTpm2net(deviceConfig);
}
int LedDeviceTpm2net::write(const std::vector<ColorRgb> & ledValues)
{
if (_ledBuffer.size() == 0)
{
_ledBuffer.resize(7 + 3*ledValues.size());
_ledBuffer[0] = 0x9c; // block-start byte TPM.NET
_ledBuffer[1] = 0xDA;
_ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // frame size high byte
_ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // frame size low byte
_ledBuffer[4] = 1; // packets number
_ledBuffer[5] = 1; // Number of packets
_ledBuffer[(int)(7 + 3*ledValues.size()-1)] = 0x36; // block-end byte
}
// write data
memcpy(6 + _ledBuffer.data(), ledValues.data() /*Max 1,490 bytes*/, ledValues.size() * 3);
_socket.connectToHost(_host, _port);
_socket.write((const char *)_ledBuffer.data());
_socket.close();
return 0;
}
int LedDeviceTpm2net::switchOff()
{
memset(6 + _ledBuffer.data(), 0, _ledBuffer.size() - 5);
return 0;
}

View File

@ -0,0 +1,53 @@
#pragma once
// STL includes
#include <fstream>
#include <string>
#include <QUdpSocket>
#include <QStringList>
// Leddevice includes
#include <leddevice/LedDevice.h>
///
class LedDeviceTpm2net : public LedDevice
{
public:
///
/// Constructs specific LedDevice
///
/// @param deviceConfig json device config
///
LedDeviceTpm2net(const Json::Value &deviceConfig);
virtual ~LedDeviceTpm2net();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the given led-color values to the output stream
///
/// @param ledValues The color-value per led
///
/// @return Zero on success else negative
///
virtual int write(const std::vector<ColorRgb> & ledValues);
/// Switch the leds off
virtual int switchOff();
private:
/// The host of the master brick
QHostAddress _host;
/// The port of the master brick
uint16_t _port;
QUdpSocket _socket;
};

View File

@ -12,12 +12,25 @@
// hyperion local includes
#include "LedDeviceUdpE131.h"
LedDeviceUdpE131::LedDeviceUdpE131(const std::string& outputDevice, const unsigned latchTime, const unsigned universe)
: LedUdpDevice(outputDevice, latchTime)
, _e131_universe(universe)
LedDeviceUdpE131::LedDeviceUdpE131(const Json::Value &deviceConfig)
: LedUdpDevice(deviceConfig)
{
// empty
setConfig(deviceConfig);
}
bool LedDeviceUdpE131::setConfig(const Json::Value &deviceConfig)
{
LedUdpDevice::setConfig(deviceConfig);
_LatchTime_ns = deviceConfig.get("latchtime",104000).asInt();
_e131_universe = deviceConfig.get("universe",1).asInt();
return true;
}
LedDevice* LedDeviceUdpE131::construct(const Json::Value &deviceConfig)
{
return new LedDeviceUdpE131(deviceConfig);
}
#define CID "hyperion!\0"

View File

@ -100,13 +100,21 @@ class LedDeviceUdpE131 : public LedUdpDevice
{
public:
///
/// Constructs the LedDevice for sending led colors via udp
/// Constructs specific LedDevice
///
/// @param outputDevice hostname:port
/// @param latchTime
/// @param deviceConfig json device config
///
LedDeviceUdpE131(const Json::Value &deviceConfig);
LedDeviceUdpE131(const std::string& outputDevice, const unsigned latchTime, const unsigned universe);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///

View File

@ -11,10 +11,23 @@
// hyperion local includes
#include "LedDeviceUdpRaw.h"
LedDeviceUdpRaw::LedDeviceUdpRaw(const std::string& outputDevice, const unsigned latchTime)
: LedUdpDevice(outputDevice, latchTime)
LedDeviceUdpRaw::LedDeviceUdpRaw(const Json::Value &deviceConfig)
: LedUdpDevice(deviceConfig)
{
// empty
setConfig(deviceConfig);
}
bool LedDeviceUdpRaw::setConfig(const Json::Value &deviceConfig)
{
LedUdpDevice::setConfig(deviceConfig);
_LatchTime_ns = deviceConfig.get("latchtime",500000).asInt();
return true;
}
LedDevice* LedDeviceUdpRaw::construct(const Json::Value &deviceConfig)
{
return new LedDeviceUdpRaw(deviceConfig);
}
int LedDeviceUdpRaw::write(const std::vector<ColorRgb> &ledValues)

View File

@ -13,13 +13,21 @@ class LedDeviceUdpRaw : public LedUdpDevice
{
public:
///
/// Constructs the LedDevice for sending led colors via udp
/// Constructs specific LedDevice
///
/// @param outputDevice hostname:port
/// @param latchTime
/// @param deviceConfig json device config
///
LedDeviceUdpRaw(const Json::Value &deviceConfig);
LedDeviceUdpRaw(const std::string& outputDevice, const unsigned latchTime);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -258,6 +258,11 @@ LedDeviceWS2812b::LedDeviceWS2812b()
printf("WS2812b init finished \n");
}
LedDevice* LedDeviceWS2812b::construct(const Json::Value &)
{
return new LedDeviceWS2812b();
}
#ifdef WS2812_ASM_OPTI
// rotate register, used to move the 1 around :-)

View File

@ -133,10 +133,24 @@ class LedDeviceWS2812b : public LedDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type WS2812
/// Constructs specific LedDevice
///
/// @param deviceConfig json device config
///
LedDeviceWS2812b();
~LedDeviceWS2812b();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value&) {};
/// constructs leddevice
static LedDevice* construct(const Json::Value &);
///
/// Writes the led color values to the led-device
///

View File

@ -4,31 +4,13 @@
#include "LedDeviceWS281x.h"
// Constructor
LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum, const int pwmchannel, const int invert, const int rgbw, const std::string& whiteAlgorithm)
LedDeviceWS281x::LedDeviceWS281x(const Json::Value &deviceConfig)
: LedDevice()
, _channel(pwmchannel)
, _initialized(false)
, _whiteAlgorithm(whiteAlgorithm)
{
Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str());
setConfig(deviceConfig);
Debug( _log, "whiteAlgorithm : %s", _whiteAlgorithm.c_str());
_led_string.freq = freq;
_led_string.dmanum = dmanum;
if (pwmchannel != 0 && pwmchannel != 1)
{
throw std::runtime_error("WS281x: invalid PWM channel; must be 0 or 1.");
}
_led_string.channel[_channel].gpionum = gpio;
_led_string.channel[_channel].invert = invert;
_led_string.channel[_channel].count = leds;
_led_string.channel[_channel].brightness = 255;
_led_string.channel[_channel].strip_type = ((rgbw == 1) ? SK6812_STRIP_GRBW : WS2811_STRIP_RGB);
_led_string.channel[!_channel].gpionum = 0;
_led_string.channel[!_channel].invert = invert;
_led_string.channel[!_channel].count = 0;
_led_string.channel[!_channel].brightness = 0;
_led_string.channel[!_channel].strip_type = WS2811_STRIP_RGB;
if (ws2811_init(&_led_string) < 0)
{
throw std::runtime_error("Unable to initialize ws281x library.");
@ -36,6 +18,38 @@ LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t
_initialized = true;
}
bool LedDeviceWS281x::setConfig(const Json::Value &deviceConfig)
{
_whiteAlgorithm = deviceConfig.get("white_algorithm","").asString();
_channel = deviceConfig.get("pwmchannel", 0).asInt();
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.channel[_channel].brightness = 255;
_led_string.channel[!_channel].gpionum = 0;
_led_string.channel[!_channel].invert = _led_string.channel[_channel].invert;
_led_string.channel[!_channel].count = 0;
_led_string.channel[!_channel].brightness = 0;
_led_string.channel[!_channel].strip_type = WS2811_STRIP_RGB;
return true;
}
LedDevice* LedDeviceWS281x::construct(const Json::Value &deviceConfig)
{
return new LedDeviceWS281x(deviceConfig);
}
// Send new values down the LED chain
int LedDeviceWS281x::write(const std::vector<ColorRgb> &ledValues)
{

View File

@ -7,25 +7,27 @@ class LedDeviceWS281x : public LedDevice
{
public:
///
/// Constructs the LedDevice for WS281x (one wire 800kHz)
/// Constructs specific LedDevice
///
/// @param gpio The gpio pin to use (BCM chip counting, default is 18)
/// @param leds The number of leds attached to the gpio pin
/// @param freq The target frequency for the data line, default is 800000
/// @param dmanum The DMA channel to use, default is 5
/// @param pwmchannel The pwm channel to use
/// @param invert Invert the output line to support an inverting level shifter
/// @param rgbw Send 32 bit rgbw colour data for sk6812
/// @param deviceConfig json device config
///
LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, int dmanum, int pwmchannel, int invert,
int rgbw, const std::string& whiteAlgorithm);
LedDeviceWS281x(const Json::Value &deviceConfig);
///
/// Destructor of the LedDevice, waits for DMA to complete and then cleans up
///
~LedDeviceWS281x();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device
///

View File

@ -11,11 +11,14 @@
// hyperion local includes
#include "LedDeviceWs2801.h"
LedDeviceWs2801::LedDeviceWs2801(const std::string& outputDevice, const unsigned baudrate, const unsigned latchTime,
const int spiMode, const bool spiDataInvert)
: LedSpiDevice(outputDevice, baudrate, latchTime, spiMode, spiDataInvert)
LedDeviceWs2801::LedDeviceWs2801(const Json::Value &deviceConfig)
: LedSpiDevice(deviceConfig)
{
// empty
}
LedDevice* LedDeviceWs2801::construct(const Json::Value &deviceConfig)
{
return new LedDeviceWs2801(deviceConfig);
}
int LedDeviceWs2801::write(const std::vector<ColorRgb> &ledValues)

View File

@ -13,17 +13,14 @@ class LedDeviceWs2801 : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type Ws2801
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceWs2801(const Json::Value &deviceConfig);
LedDeviceWs2801(const std::string& outputDevice,
const unsigned baudrate,
const unsigned latchTime,
const int spiMode,
const bool spiDataInvert);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -11,8 +11,8 @@
// hyperion local includes
#include "LedDeviceWs2812SPI.h"
LedDeviceWs2812SPI::LedDeviceWs2812SPI(const std::string& outputDevice, const unsigned baudrate, const int spiMode, const bool spiDataInvert)
: LedSpiDevice(outputDevice, baudrate, 0, spiMode, spiDataInvert)
LedDeviceWs2812SPI::LedDeviceWs2812SPI(const Json::Value &deviceConfig)
: LedSpiDevice(deviceConfig)
, bitpair_to_byte {
0b10001000,
0b10001100,
@ -20,7 +20,11 @@ LedDeviceWs2812SPI::LedDeviceWs2812SPI(const std::string& outputDevice, const un
0b11001100,
}
{
// empty
}
LedDevice* LedDeviceWs2812SPI::construct(const Json::Value &deviceConfig)
{
return new LedDeviceWs2812SPI(deviceConfig);
}
int LedDeviceWs2812SPI::write(const std::vector<ColorRgb> &ledValues)

View File

@ -13,13 +13,14 @@ class LedDeviceWs2812SPI : public LedSpiDevice
{
public:
///
/// Constructs the LedDevice for a string containing leds of the type Ws2812SPI
/// Constructs specific LedDevice
///
/// @param outputDevice The name of the output device (eg '/etc/SpiDev.0.0')
/// @param baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedDeviceWs2812SPI(const std::string& outputDevice, const unsigned baudrate,
const int spiMode, const bool spiDataInvert);
LedDeviceWs2812SPI(const Json::Value &deviceConfig);
/// constructs leddevice
static LedDevice* construct(const Json::Value &deviceConfig);
///
/// Writes the led color values to the led-device

View File

@ -9,15 +9,12 @@
// Local Hyperion includes
#include "LedHIDDevice.h"
LedHIDDevice::LedHIDDevice(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms, const bool useFeature)
: _VendorId(VendorId)
, _ProductId(ProductId)
, _useFeature(useFeature)
LedHIDDevice::LedHIDDevice(const Json::Value &deviceConfig)
: _useFeature(false)
, _deviceHandle(nullptr)
, _delayAfterConnect_ms(delayAfterConnect_ms)
, _blockedForDelay(false)
{
// empty
setConfig(deviceConfig);
}
LedHIDDevice::~LedHIDDevice()
@ -31,6 +28,19 @@ LedHIDDevice::~LedHIDDevice()
hid_exit();
}
bool LedHIDDevice::setConfig(const Json::Value &deviceConfig)
{
_delayAfterConnect_ms = deviceConfig.get("delayAfterConnect", 0 ).asInt();
auto VendorIdString = deviceConfig.get("VID", "0x2341").asString();
auto ProductIdString = deviceConfig.get("PID", "0x8036").asString();
// Convert HEX values to integer
_VendorId = std::stoul(VendorIdString, nullptr, 16);
_ProductId = std::stoul(ProductIdString, nullptr, 16);
return true;
}
int LedHIDDevice::open()
{
// Initialize the usb context

View File

@ -17,18 +17,24 @@ class LedHIDDevice : public LedDevice
public:
///
/// Constructs the LedDevice attached to an HID-device
/// Constructs specific LedDevice
///
/// @param[in] VendorId The USB VID of the output device
/// @param[in] ProductId The USB PID of the output device
/// @param deviceConfig json device config
///
LedHIDDevice(const unsigned short VendorId, const unsigned short ProductId, int delayAfterConnect_ms = 0, const bool useFeature = false);
LedHIDDevice(const Json::Value &deviceConfig);
///
/// Destructor of the LedDevice; closes the output device if it is open
///
virtual ~LedHIDDevice();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool setConfig(const Json::Value &deviceConfig);
///
/// Opens and configures the output device
///
@ -46,21 +52,20 @@ protected:
*/
int writeBytes(const unsigned size, const uint8_t *data);
private slots:
/// Unblock the device after a connection delay
void unblockAfterDelay();
private:
// HID VID and PID
const unsigned short _VendorId;
const unsigned short _ProductId;
const bool _useFeature;
unsigned short _VendorId;
unsigned short _ProductId;
bool _useFeature;
/// libusb device handle
hid_device * _deviceHandle;
/// Sleep after the connect before continuing
const int _delayAfterConnect_ms;
int _delayAfterConnect_ms;
bool _blockedForDelay;
private slots:
/// Unblock the device after a connection delay
void unblockAfterDelay();
};

View File

@ -9,17 +9,25 @@
// Local Hyperion includes
#include "LedRs232Device.h"
LedRs232Device::LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms)
: _deviceName(outputDevice)
, _baudRate_Hz(baudrate)
, _delayAfterConnect_ms(delayAfterConnect_ms)
, _rs232Port(this)
LedRs232Device::LedRs232Device(const Json::Value &deviceConfig)
: _rs232Port(this)
, _blockedForDelay(false)
, _stateChanged(true)
{
setConfig(deviceConfig);
connect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError)));
}
bool LedRs232Device::setConfig(const Json::Value &deviceConfig)
{
closeDevice();
_deviceName = deviceConfig["output"].asString();
_baudRate_Hz = deviceConfig["rate"].asInt();
_delayAfterConnect_ms = deviceConfig.get("delayAfterConnect",250).asInt();
return true;
}
void LedRs232Device::error(QSerialPort::SerialPortError error)
{
if ( error != QSerialPort::NoError )
@ -59,6 +67,11 @@ void LedRs232Device::error(QSerialPort::SerialPortError error)
LedRs232Device::~LedRs232Device()
{
disconnect(&_rs232Port, SIGNAL(error(QSerialPort::SerialPortError)), this, SLOT(error(QSerialPort::SerialPortError)));
closeDevice();
}
void LedRs232Device::closeDevice()
{
if (_rs232Port.isOpen())
{
_rs232Port.close();
@ -66,7 +79,6 @@ LedRs232Device::~LedRs232Device()
}
}
int LedRs232Device::open()
{
Info(_log, "Opening UART: %s", _deviceName.c_str());

View File

@ -15,12 +15,18 @@ class LedRs232Device : public LedDevice
public:
///
/// Constructs the LedDevice attached to a RS232-device
/// Constructs specific LedDevice
///
/// @param[in] outputDevice The name of the output device (eg '/etc/ttyS0')
/// @param[in] baudrate The used baudrate for writing to the output device
/// @param deviceConfig json device config
///
LedRs232Device(const std::string& outputDevice, const unsigned baudrate, int delayAfterConnect_ms = 0);
LedRs232Device(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool setConfig(const Json::Value &deviceConfig);
///
/// Destructor of the LedDevice; closes the output device if it is open
@ -45,6 +51,8 @@ protected:
*/
int writeBytes(const unsigned size, const uint8_t *data);
void closeDevice();
private slots:
/// Unblock the device after a connection delay
void unblockAfterDelay();
@ -55,10 +63,10 @@ private:
bool tryOpen();
/// The name of the output device
const std::string _deviceName;
std::string _deviceName;
/// The used baudrate of the output device
const qint32 _baudRate_Hz;
qint32 _baudRate_Hz;
/// Sleep after the connect before continuing
int _delayAfterConnect_ms;

View File

@ -14,14 +14,11 @@
#include <utils/Logger.h>
LedSpiDevice::LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns, const int spiMode, const bool spiDataInvert)
: _deviceName(outputDevice)
, _baudRate_Hz(baudrate)
, _latchTime_ns(latchTime_ns)
LedSpiDevice::LedSpiDevice(const Json::Value &deviceConfig)
: LedDevice()
, _fid(-1)
, _spiMode(spiMode)
, _spiDataInvert(spiDataInvert)
{
setConfig(deviceConfig);
memset(&_spi, 0, sizeof(_spi));
Debug(_log, "_spiDataInvert %d, _spiMode %d", _spiDataInvert, _spiMode);
}
@ -31,6 +28,17 @@ LedSpiDevice::~LedSpiDevice()
// close(_fid);
}
bool LedSpiDevice::setConfig(const Json::Value &deviceConfig)
{
_deviceName = deviceConfig.get("output","/dev/spidev.0.0").asString();
_baudRate_Hz = deviceConfig.get("rate",1000000).asInt();
_latchTime_ns = deviceConfig.get("latchtime",0).asInt();
_spiMode = deviceConfig.get("spimode",SPI_MODE_0).asInt();
_spiDataInvert = deviceConfig.get("invert",false).asBool();
return true;
}
int LedSpiDevice::open()
{
const int bitsPerWord = 8;

View File

@ -13,16 +13,18 @@ class LedSpiDevice : public LedDevice
{
public:
///
/// Constructs the LedDevice attached to a SPI-device
/// Constructs specific LedDevice
///
/// @param[in] outputDevice The name of the output device (eg '/dev/spidev.0.0')
/// @param[in] baudrate The used baudrate for writing to the output device
/// @param[in] latchTime_ns The latch-time to latch in the values across the SPI-device (negative
/// means no latch required) [ns]
/// @param deviceConfig json device config
///
LedSpiDevice(const std::string& outputDevice, const unsigned baudrate, const int latchTime_ns = -1,
const int spiMode = SPI_MODE_0, const bool spiDataInvert = false);
LedSpiDevice(const Json::Value &deviceConfig);
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
virtual bool setConfig(const Json::Value &deviceConfig);
///
/// Destructor of the LedDevice; closes the output device if it is open
@ -48,15 +50,14 @@ protected:
///
int writeBytes(const unsigned size, const uint8_t *data);
private:
/// The name of the output device
const std::string _deviceName;
std::string _deviceName;
/// The used baudrate of the output device
const int _baudRate_Hz;
int _baudRate_Hz;
/// The time which the device should be untouched after a write
const int _latchTime_ns;
int _latchTime_ns;
/// The File Identifier of the opened output device (or -1 if not opened)
int _fid;

View File

@ -15,24 +15,12 @@
// Local Hyperion includes
#include "LedUdpDevice.h"
LedUdpDevice::LedUdpDevice(const std::string& output, const int latchTime_ns)
: _target(output)
, _LatchTime_ns(latchTime_ns)
LedUdpDevice::LedUdpDevice(const Json::Value &deviceConfig)
: LedDevice()
, _LatchTime_ns(-1)
{
setConfig(deviceConfig);
_udpSocket = new QUdpSocket();
QString str = QString::fromStdString(_target);
QStringList str_splitted = str.split(":");
if (str_splitted.size() != 2)
{
throw("Error parsing hostname:port");
}
QHostInfo info = QHostInfo::fromName(str_splitted.at(0));
if (!info.addresses().isEmpty())
{
// use the first IP address
_address = info.addresses().first();
}
_port = str_splitted.at(1).toInt();
}
LedUdpDevice::~LedUdpDevice()
@ -40,6 +28,19 @@ LedUdpDevice::~LedUdpDevice()
_udpSocket->close();
}
bool LedUdpDevice::setConfig(const Json::Value &deviceConfig)
{
QHostInfo info = QHostInfo::fromName( QString::fromStdString(deviceConfig["output"].asString()) );
if (info.addresses().isEmpty())
{
throw("invalid target address");
}
_address = info.addresses().first();
_port = deviceConfig["port"].asUInt();
return true;
}
int LedUdpDevice::open()
{
QHostAddress localAddress = QHostAddress::Any;

View File

@ -13,19 +13,24 @@ class LedUdpDevice : public LedDevice
{
public:
///
/// Constructs the LedDevice sendig data via udp
/// Constructs specific LedDevice
///
/// @param[in] outputDevice string hostname:port
/// @param[in] latchTime_ns The latch-time to latch in the values across the SPI-device (negative
/// means no latch required) [ns]
/// @param deviceConfig json device config
///
LedUdpDevice(const std::string& outputDevice, const int latchTime_ns = -1);
LedUdpDevice(const Json::Value &deviceConfig);
///
/// Destructor of the LedDevice; closes the output device if it is open
///
virtual ~LedUdpDevice();
///
/// Sets configuration
///
/// @param deviceConfig the json device config
/// @return true if success
bool setConfig(const Json::Value &deviceConfig);
///
/// Opens and configures the output device
///
@ -45,12 +50,8 @@ protected:
///
int writeBytes(const unsigned size, const uint8_t *data);
private:
/// The UDP destination as "host:port"
const std::string _target;
/// The time which the device should be untouched after a write
const int _LatchTime_ns;
int _LatchTime_ns;
///
QUdpSocket * _udpSocket;

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

View File

@ -0,0 +1,7 @@
{
"type":"object",
"required":true,
"properties":{
},
"additionalProperties": true
}

Some files were not shown because too many files have changed in this diff Show More