mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Merge remote-tracking branch 'refs/remotes/tvdzwan/master'
Former-commit-id: 59c1c363863c950e91ac57cc2ff39a722359634b
This commit is contained in:
@@ -33,9 +33,9 @@ SET(Leddevice_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePaintpack.h
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceAtmo.h
|
||||
@@ -56,9 +56,9 @@ SET(Leddevice_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePaintpack.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePiBlaster.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdp.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceFadeCandy.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceUdp.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
|
||||
@@ -97,6 +97,18 @@ SET(Leddevice_SOURCES
|
||||
)
|
||||
endif(ENABLE_WS2812BPWM)
|
||||
|
||||
if(ENABLE_WS281XPWM)
|
||||
include_directories(../../dependencies/external/rpi_ws281x)
|
||||
SET(Leddevice_HEADERS
|
||||
${Leddevice_HEADERS}
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceWS281x.h
|
||||
)
|
||||
SET(Leddevice_SOURCES
|
||||
${Leddevice_SOURCES}
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceWS281x.cpp
|
||||
)
|
||||
endif(ENABLE_WS281XPWM)
|
||||
|
||||
if(ENABLE_TINKERFORGE)
|
||||
SET(Leddevice_HEADERS
|
||||
${Leddevice_HEADERS}
|
||||
@@ -138,6 +150,10 @@ if(ENABLE_TINKERFORGE)
|
||||
target_link_libraries(leddevice tinkerforge)
|
||||
endif()
|
||||
|
||||
if(ENABLE_WS281XPWM)
|
||||
target_link_libraries(leddevice ws281x)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
target_link_libraries(leddevice hidapi-mac)
|
||||
else()
|
||||
|
@@ -42,6 +42,10 @@
|
||||
#include "LedDeviceWS2812b.h"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_WS281XPWM
|
||||
#include "LedDeviceWS281x.h"
|
||||
#endif
|
||||
|
||||
LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
{
|
||||
std::cout << "Device configuration: " << deviceConfig << std::endl;
|
||||
@@ -175,7 +179,7 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
|
||||
device = deviceLightpack;
|
||||
}
|
||||
else if (type == "multi-lightpack")
|
||||
else if (type == "multi-lightpack" || type == "multi_lightpack")
|
||||
{
|
||||
LedDeviceMultiLightpack* deviceLightpack = new LedDeviceMultiLightpack();
|
||||
deviceLightpack->open();
|
||||
@@ -285,10 +289,22 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
LedDeviceWS2812b * ledDeviceWS2812b = new LedDeviceWS2812b();
|
||||
device = ledDeviceWS2812b;
|
||||
}
|
||||
#endif
|
||||
#ifdef ENABLE_WS281XPWM
|
||||
else if (type == "ws281x")
|
||||
{
|
||||
const int gpio = deviceConfig.get("gpio", 18).asInt();
|
||||
const int leds = deviceConfig.get("leds", 12).asInt();
|
||||
const uint32_t freq = deviceConfig.get("freq", (Json::UInt)800000ul).asInt();
|
||||
const int dmanum = deviceConfig.get("dmanum", 5).asInt();
|
||||
|
||||
LedDeviceWS281x * ledDeviceWS281x = new LedDeviceWS281x(gpio, leds, freq, dmanum);
|
||||
device = ledDeviceWS281x;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
std::cout << "Unable to create device " << type << std::endl;
|
||||
std::cout << "Error: Unknown/Unimplemented device " << type << std::endl;
|
||||
// Unknown / Unimplemented device
|
||||
}
|
||||
return device;
|
||||
|
@@ -5,10 +5,11 @@
|
||||
#include <json/json.h>
|
||||
|
||||
// qt includes
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QtCore/qmath.h>
|
||||
#include <QEventLoop>
|
||||
#include <QNetworkReply>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <set>
|
||||
|
||||
bool operator ==(CiColor p1, CiColor p2) {
|
||||
@@ -20,33 +21,33 @@ bool operator !=(CiColor p1, CiColor p2) {
|
||||
}
|
||||
|
||||
PhilipsHueLight::PhilipsHueLight(unsigned int id, QString originalState, QString modelId) :
|
||||
id(id), originalState(originalState) {
|
||||
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
|
||||
// Light strips, color iris, ...
|
||||
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
|
||||
"LLC013", "LLC014", "LST001" };
|
||||
// Hue bulbs, spots, ...
|
||||
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
|
||||
// Hue Lightstrip plus, go ...
|
||||
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
|
||||
// Find id in the sets and set the appropiate color space.
|
||||
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
|
||||
colorSpace.red = {0.703f, 0.296f};
|
||||
colorSpace.green = {0.2151f, 0.7106f};
|
||||
colorSpace.blue = {0.138f, 0.08f};
|
||||
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||
colorSpace.red = {0.675f, 0.322f};
|
||||
colorSpace.green = {0.4091f, 0.518f};
|
||||
colorSpace.blue = {0.167f, 0.04f};
|
||||
} else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||
colorSpace.red = {0.675f, 0.322f};
|
||||
colorSpace.green = {0.2151f, 0.7106f};
|
||||
colorSpace.blue = {0.167f, 0.04f};
|
||||
} else {
|
||||
colorSpace.red = {1.0f, 0.0f};
|
||||
colorSpace.green = {0.0f, 1.0f};
|
||||
colorSpace.blue = {0.0f, 0.0f};
|
||||
}
|
||||
id(id), originalState(originalState) {
|
||||
// Hue system model ids (http://www.developers.meethue.com/documentation/supported-lights).
|
||||
// Light strips, color iris, ...
|
||||
const std::set<QString> GAMUT_A_MODEL_IDS = { "LLC001", "LLC005", "LLC006", "LLC007", "LLC010", "LLC011", "LLC012",
|
||||
"LLC013", "LLC014", "LST001" };
|
||||
// Hue bulbs, spots, ...
|
||||
const std::set<QString> GAMUT_B_MODEL_IDS = { "LCT001", "LCT002", "LCT003", "LCT007", "LLM001" };
|
||||
// Hue Lightstrip plus, go ...
|
||||
const std::set<QString> GAMUT_C_MODEL_IDS = { "LLC020", "LST002" };
|
||||
// Find id in the sets and set the appropiate color space.
|
||||
if (GAMUT_A_MODEL_IDS.find(modelId) != GAMUT_A_MODEL_IDS.end()) {
|
||||
colorSpace.red = {0.703f, 0.296f};
|
||||
colorSpace.green = {0.2151f, 0.7106f};
|
||||
colorSpace.blue = {0.138f, 0.08f};
|
||||
} else if (GAMUT_B_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||
colorSpace.red = {0.675f, 0.322f};
|
||||
colorSpace.green = {0.4091f, 0.518f};
|
||||
colorSpace.blue = {0.167f, 0.04f};
|
||||
} else if (GAMUT_C_MODEL_IDS.find(modelId) != GAMUT_B_MODEL_IDS.end()) {
|
||||
colorSpace.red = {0.675f, 0.322f};
|
||||
colorSpace.green = {0.2151f, 0.7106f};
|
||||
colorSpace.blue = {0.167f, 0.04f};
|
||||
} else {
|
||||
colorSpace.red = {1.0f, 0.0f};
|
||||
colorSpace.green = {0.0f, 1.0f};
|
||||
colorSpace.blue = {0.0f, 0.0f};
|
||||
}
|
||||
// Initialize black color.
|
||||
black = rgbToCiColor(0.0f, 0.0f, 0.0f);
|
||||
// Initialize color with black
|
||||
@@ -214,8 +215,8 @@ int LedDevicePhilipsHue::switchOff() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
// Perfrom request
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply* reply = manager->put(request, content.toLatin1());
|
||||
@@ -226,8 +227,8 @@ void LedDevicePhilipsHue::put(QString route, QString content) {
|
||||
loop.exec();
|
||||
}
|
||||
|
||||
QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||
QString url = QString("http://%1/api/%2/%3").arg(host).arg(username).arg(route);
|
||||
// Perfrom request
|
||||
QNetworkRequest request(url);
|
||||
QNetworkReply* reply = manager->get(request);
|
||||
@@ -236,8 +237,8 @@ QByteArray LedDevicePhilipsHue::get(QString route) {
|
||||
loop.connect(reply, SIGNAL(finished()), SLOT(quit()));
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
// Read all data of the response.
|
||||
return reply->readAll();
|
||||
// Read all data of the response.
|
||||
return reply->readAll();
|
||||
}
|
||||
|
||||
QString LedDevicePhilipsHue::getStateRoute(unsigned int lightId) {
|
||||
@@ -254,11 +255,19 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
||||
// Use json parser to parse reponse.
|
||||
Json::Reader reader;
|
||||
Json::FastWriter writer;
|
||||
// Create light ids if none supplied by the user.
|
||||
// Read light ids if none have been supplied by the user.
|
||||
if (lightIds.size() != nLights) {
|
||||
lightIds.clear();
|
||||
for (unsigned int i = 0; i < nLights; i++) {
|
||||
lightIds.push_back(i + 1);
|
||||
QByteArray response = get("lights");
|
||||
Json::Value json;
|
||||
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||
throw std::runtime_error("No lights found");
|
||||
}
|
||||
// Loop over all children.
|
||||
for (Json::ValueIterator it = json.begin(); it != json.end() && lightIds.size() <= nLights; it++) {
|
||||
int lightId = atoi(it.key().asCString());
|
||||
lightIds.push_back(lightId);
|
||||
std::cout << "LedDevicePhilipsHue::saveStates(nLights=" << nLights << "): found light with id " << lightId
|
||||
<< "." << std::endl;
|
||||
}
|
||||
}
|
||||
// Iterate lights.
|
||||
@@ -269,6 +278,8 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights) {
|
||||
Json::Value json;
|
||||
if (!reader.parse(QString(response).toStdString(), json)) {
|
||||
// Error occured, break loop.
|
||||
std::cerr << "LedDevicePhilipsHue::saveStates(nLights=" << nLights
|
||||
<< "): got invalid response from light with id " << lightIds.at(i) << "." << std::endl;
|
||||
break;
|
||||
}
|
||||
// Get state object values which are subject to change.
|
||||
|
78
libsrc/leddevice/LedDeviceWS281x.cpp
Normal file
78
libsrc/leddevice/LedDeviceWS281x.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "LedDeviceWS281x.h"
|
||||
|
||||
// Constructor
|
||||
LedDeviceWS281x::LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, const int dmanum)
|
||||
{
|
||||
initialized = false;
|
||||
led_string.freq = freq;
|
||||
led_string.dmanum = dmanum;
|
||||
led_string.channel[0].gpionum = gpio;
|
||||
led_string.channel[0].invert = 0;
|
||||
led_string.channel[0].count = leds;
|
||||
led_string.channel[0].brightness = 255;
|
||||
led_string.channel[0].strip_type = WS2811_STRIP_RGB;
|
||||
|
||||
led_string.channel[1].gpionum = 0;
|
||||
led_string.channel[1].invert = 0;
|
||||
led_string.channel[1].count = 0;
|
||||
led_string.channel[1].brightness = 0;
|
||||
led_string.channel[0].strip_type = WS2811_STRIP_RGB;
|
||||
if (ws2811_init(&led_string) < 0) {
|
||||
std::cout << "Unable to initialize ws281x library." << std::endl;
|
||||
throw -1;
|
||||
}
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
// Send new values down the LED chain
|
||||
int LedDeviceWS281x::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
if (!initialized)
|
||||
return -1;
|
||||
|
||||
int idx = 0;
|
||||
for (const ColorRgb& color : ledValues)
|
||||
{
|
||||
if (idx >= led_string.channel[0].count)
|
||||
break;
|
||||
led_string.channel[0].leds[idx++] = ((uint32_t)color.red << 16) + ((uint32_t)color.green << 8) + color.blue;
|
||||
}
|
||||
while (idx < led_string.channel[0].count)
|
||||
led_string.channel[0].leds[idx++] = 0;
|
||||
|
||||
if (ws2811_render(&led_string))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Turn off the LEDs by sending 000000's
|
||||
// TODO Allow optional power switch out another gpio, if this code handles it can
|
||||
// make it more likely we don't accidentally drive data into an off strip
|
||||
int LedDeviceWS281x::switchOff()
|
||||
{
|
||||
if (!initialized)
|
||||
return -1;
|
||||
|
||||
int idx = 0;
|
||||
while (idx < led_string.channel[0].count)
|
||||
led_string.channel[0].leds[idx++] = 0;
|
||||
|
||||
if (ws2811_render(&led_string))
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Destructor
|
||||
LedDeviceWS281x::~LedDeviceWS281x()
|
||||
{
|
||||
if (initialized)
|
||||
{
|
||||
std::cout << "Shutdown WS281x PWM and DMA channel" << std::endl;
|
||||
ws2811_fini(&led_string);
|
||||
}
|
||||
initialized = false;
|
||||
}
|
43
libsrc/leddevice/LedDeviceWS281x.h
Normal file
43
libsrc/leddevice/LedDeviceWS281x.h
Normal file
@@ -0,0 +1,43 @@
|
||||
#ifndef LEDDEVICEWS281X_H_
|
||||
#define LEDDEVICEWS281X_H_
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <leddevice/LedDevice.h>
|
||||
#include <ws2811.h>
|
||||
|
||||
class LedDeviceWS281x : public LedDevice
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs the LedDevice for WS281x (one wire 800kHz)
|
||||
///
|
||||
/// @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
|
||||
///
|
||||
LedDeviceWS281x(const int gpio, const int leds, const uint32_t freq, int dmanum);
|
||||
|
||||
///
|
||||
/// Destructor of the LedDevice, waits for DMA to complete and then cleans up
|
||||
///
|
||||
~LedDeviceWS281x();
|
||||
|
||||
///
|
||||
/// Writes the led color values to the led-device
|
||||
///
|
||||
/// @param ledValues The color-value per led
|
||||
/// @return Zero on succes else negative
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb> &ledValues);
|
||||
|
||||
/// Switch the leds off
|
||||
virtual int switchOff();
|
||||
|
||||
private:
|
||||
ws2811_t led_string;
|
||||
bool initialized;
|
||||
};
|
||||
|
||||
#endif /* LEDDEVICEWS281X_H_ */
|
Reference in New Issue
Block a user