mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Merge branch 'master' into support_for_philips_hue
Conflicts: libsrc/leddevice/LedDevicePhilipsHue.cpp libsrc/leddevice/LedDevicePhilipsHue.h Former-commit-id: 5f0b05cce12ca5c42ac2cdd94b9418d6eaef0f57
This commit is contained in:
@@ -16,12 +16,12 @@
|
||||
"required" : false
|
||||
},
|
||||
"saturationGain" : {
|
||||
"type" : "double",
|
||||
"type" : "number",
|
||||
"required" : false,
|
||||
"minimum" : 0.0
|
||||
},
|
||||
"valueGain" : {
|
||||
"type" : "double",
|
||||
"type" : "number",
|
||||
"required" : false,
|
||||
"minimum" : 0.0
|
||||
},
|
||||
@@ -29,7 +29,7 @@
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double",
|
||||
"type": "number",
|
||||
"minimum": 0.0,
|
||||
"maximum": 1.0
|
||||
},
|
||||
@@ -40,7 +40,7 @@
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double",
|
||||
"type": "number",
|
||||
"minimum": 0.0
|
||||
},
|
||||
"minItems": 3,
|
||||
@@ -50,7 +50,7 @@
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double"
|
||||
"type": "number"
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
@@ -59,7 +59,7 @@
|
||||
"type": "array",
|
||||
"required": false,
|
||||
"items" : {
|
||||
"type": "double"
|
||||
"type": "number"
|
||||
},
|
||||
"minItems": 3,
|
||||
"maxItems": 3
|
||||
|
@@ -29,6 +29,7 @@ SET(Leddevice_HEADERS
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
|
||||
)
|
||||
|
||||
SET(Leddevice_SOURCES
|
||||
@@ -45,6 +46,7 @@ SET(Leddevice_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
|
||||
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
|
||||
)
|
||||
|
||||
if(ENABLE_SPIDEV)
|
||||
|
@@ -29,6 +29,7 @@
|
||||
#include "LedDeviceTest.h"
|
||||
#include "LedDeviceHyperionUsbasp.h"
|
||||
#include "LedDevicePhilipsHue.h"
|
||||
#include "LedDeviceTpm2.h"
|
||||
|
||||
LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
{
|
||||
@@ -172,6 +173,15 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
|
||||
const std::string output = deviceConfig["output"].asString();
|
||||
device = new LedDeviceTest(output);
|
||||
}
|
||||
else if (type == "tpm2")
|
||||
{
|
||||
const std::string output = deviceConfig["output"].asString();
|
||||
const unsigned rate = deviceConfig["rate"].asInt();
|
||||
|
||||
LedDeviceTpm2* deviceTpm2 = new LedDeviceTpm2(output, rate);
|
||||
deviceTpm2->open();
|
||||
device = deviceTpm2;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Unable to create device " << type << std::endl;
|
||||
|
42
libsrc/leddevice/LedDeviceTpm2.cpp
Normal file
42
libsrc/leddevice/LedDeviceTpm2.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
|
||||
// STL includes
|
||||
#include <cstring>
|
||||
#include <cstdio>
|
||||
#include <iostream>
|
||||
|
||||
// Linux includes
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
// hyperion local includes
|
||||
#include "LedDeviceTpm2.h"
|
||||
|
||||
LedDeviceTpm2::LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate) :
|
||||
LedRs232Device(outputDevice, baudrate),
|
||||
_ledBuffer(0)
|
||||
{
|
||||
// empty
|
||||
}
|
||||
|
||||
int LedDeviceTpm2::write(const std::vector<ColorRgb> &ledValues)
|
||||
{
|
||||
if (_ledBuffer.size() == 0)
|
||||
{
|
||||
_ledBuffer.resize(5 + 3*ledValues.size());
|
||||
_ledBuffer[0] = 0xC9; // block-start byte
|
||||
_ledBuffer[1] = 0xDA; // DATA frame
|
||||
_ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // frame size high byte
|
||||
_ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // frame size low byte
|
||||
_ledBuffer.back() = 0x36; // block-end byte
|
||||
}
|
||||
|
||||
// write data
|
||||
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
||||
|
||||
int LedDeviceTpm2::switchOff()
|
||||
{
|
||||
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 5);
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
}
|
38
libsrc/leddevice/LedDeviceTpm2.h
Normal file
38
libsrc/leddevice/LedDeviceTpm2.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#pragma once
|
||||
|
||||
// STL includes
|
||||
#include <string>
|
||||
|
||||
// hyperion incluse
|
||||
#include "LedRs232Device.h"
|
||||
|
||||
///
|
||||
/// Implementation of the LedDevice interface for writing to serial device using tpm2 protocol.
|
||||
///
|
||||
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
|
||||
///
|
||||
/// @param outputDevice The name of the output device (eg '/dev/ttyAMA0')
|
||||
/// @param baudrate The used baudrate for writing to the output device
|
||||
///
|
||||
LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate);
|
||||
|
||||
///
|
||||
/// 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:
|
||||
/// The buffer containing the packed RGB values
|
||||
std::vector<uint8_t> _ledBuffer;
|
||||
};
|
Reference in New Issue
Block a user