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:
ntim 2014-08-18 17:08:21 +02:00
commit 507a237f47
11 changed files with 221 additions and 28 deletions

View File

@ -1 +1 @@
e3e4ea5204c555e64aa909d5bbbd6ac95ebec0dc 5e8d795d2aa82337e42924c1a5292203d7d4271a

View File

@ -0,0 +1,16 @@
{
"name" : "Cold mood blobs",
"script" : "mood-blobs.py",
"args" :
{
"rotationTime" : 60.0,
"color" : [0,0,255],
"hueChange" : 30.0,
"blobs" : 5,
"reverse" : false,
"baseChange" : true,
"baseColorRangeLeft" : 160,
"baseColorRangeRight" : 320,
"baseColorChangeRate" : 2.0
}
}

View File

@ -0,0 +1,16 @@
{
"name" : "Full color mood blobs",
"script" : "mood-blobs.py",
"args" :
{
"rotationTime" : 60.0,
"color" : [0,0,255],
"hueChange" : 30.0,
"blobs" : 5,
"reverse" : false,
"baseChange" : true,
"baseColorRangeLeft" : 0,
"baseColorRangeRight" : 360,
"baseColorChangeRate" : 0.2
}
}

View File

@ -0,0 +1,16 @@
{
"name" : "Warm mood blobs",
"script" : "mood-blobs.py",
"args" :
{
"rotationTime" : 60.0,
"color" : [255,0,0],
"hueChange" : 30.0,
"blobs" : 5,
"reverse" : false,
"baseChange" : true,
"baseColorRangeLeft" : 333,
"baseColorRangeRight" : 151,
"baseColorChangeRate" : 2.0
}
}

View File

@ -6,14 +6,31 @@ import math
# Get the parameters # Get the parameters
rotationTime = float(hyperion.args.get('rotationTime', 20.0)) rotationTime = float(hyperion.args.get('rotationTime', 20.0))
color = hyperion.args.get('color', (0,0,255)) color = hyperion.args.get('color', (0,0,255))
hueChange = float(hyperion.args.get('hueChange', 60.0)) / 360.0 hueChange = float(hyperion.args.get('hueChange', 60.0))
blobs = int(hyperion.args.get('blobs', 5)) blobs = int(hyperion.args.get('blobs', 5))
reverse = bool(hyperion.args.get('reverse', False)) reverse = bool(hyperion.args.get('reverse', False))
baseColorChange = bool(hyperion.args.get('baseChange', False))
baseColorRangeLeft = float(hyperion.args.get('baseColorRangeLeft',0.0)) # Degree
baseColorRangeRight = float(hyperion.args.get('baseColorRangeRight',360.0)) # Degree
baseColorChangeRate = float(hyperion.args.get('baseColorChangeRate',10.0)) # Seconds for one Degree
# switch baseColor change off if left and right are too close together to see a difference in color
if (baseColorRangeRight > baseColorRangeLeft and (baseColorRangeRight - baseColorRangeLeft) < 10) or \
(baseColorRangeLeft > baseColorRangeRight and ((baseColorRangeRight + 360) - baseColorRangeLeft) < 10):
baseColorChange = False
# 360 -> 1
fullColorWheelAvailable = (baseColorRangeRight % 360) == (baseColorRangeLeft % 360)
baseColorChangeIncreaseValue = 1.0 / 360.0 # 1 degree
hueChange /= 360.0
baseColorRangeLeft = (baseColorRangeLeft / 360.0)
baseColorRangeRight = (baseColorRangeRight / 360.0)
# Check parameters # Check parameters
rotationTime = max(0.1, rotationTime) rotationTime = max(0.1, rotationTime)
hueChange = max(0.0, min(abs(hueChange), .5)) hueChange = max(0.0, min(abs(hueChange), .5))
blobs = max(1, blobs) blobs = max(1, blobs)
baseColorChangeRate = max(0, baseColorChangeRate) # > 0
# Calculate the color data # Calculate the color data
baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0) baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
@ -27,6 +44,7 @@ for i in range(hyperion.ledCount):
sleepTime = 0.1 sleepTime = 0.1
amplitudePhaseIncrement = blobs * math.pi * sleepTime / rotationTime amplitudePhaseIncrement = blobs * math.pi * sleepTime / rotationTime
colorDataIncrement = 3 colorDataIncrement = 3
baseColorChangeRate /= sleepTime
# Switch direction if needed # Switch direction if needed
if reverse: if reverse:
@ -39,23 +57,58 @@ colors = bytearray(hyperion.ledCount * (0,0,0))
# Start the write data loop # Start the write data loop
amplitudePhase = 0.0 amplitudePhase = 0.0
rotateColors = False rotateColors = False
baseColorChangeStepCount = 0
baseHSVValue = baseHsv[0]
numberOfRotates = 0
while not hyperion.abort(): while not hyperion.abort():
# Calculate new colors
for i in range(hyperion.ledCount):
amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount))
colors[3*i+0] = int(colorData[3*i+0] * amplitude)
colors[3*i+1] = int(colorData[3*i+1] * amplitude)
colors[3*i+2] = int(colorData[3*i+2] * amplitude)
# set colors # move the basecolor
hyperion.setColor(colors) if baseColorChange:
# every baseColorChangeRate seconds
if baseColorChangeStepCount >= baseColorChangeRate:
baseColorChangeStepCount = 0
# cyclic increment when the full colorwheel is available, move up and down otherwise
if fullColorWheelAvailable:
baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % baseColorRangeRight
else:
# switch increment direction if baseHSV <= left or baseHSV >= right
if baseColorChangeIncreaseValue < 0 and baseHSVValue > baseColorRangeLeft and (baseHSVValue + baseColorChangeIncreaseValue) <= baseColorRangeLeft:
baseColorChangeIncreaseValue = abs(baseColorChangeIncreaseValue)
elif baseColorChangeIncreaseValue > 0 and baseHSVValue < baseColorRangeRight and (baseHSVValue + baseColorChangeIncreaseValue) >= baseColorRangeRight :
baseColorChangeIncreaseValue = -abs(baseColorChangeIncreaseValue)
# increment the phase baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % 1.0
amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi)
if rotateColors: # update color values
colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement] colorData = bytearray()
rotateColors = not rotateColors for i in range(hyperion.ledCount):
hue = (baseHSVValue + hueChange * math.sin(2*math.pi * i / hyperion.ledCount)) % 1.0
rgb = colorsys.hsv_to_rgb(hue, baseHsv[1], baseHsv[2])
colorData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
# sleep for a while # set correct rotation after reinitialisation of the array
time.sleep(sleepTime) colorData = colorData[-colorDataIncrement*numberOfRotates:] + colorData[:-colorDataIncrement*numberOfRotates]
baseColorChangeStepCount += 1
# Calculate new colors
for i in range(hyperion.ledCount):
amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount))
colors[3*i+0] = int(colorData[3*i+0] * amplitude)
colors[3*i+1] = int(colorData[3*i+1] * amplitude)
colors[3*i+2] = int(colorData[3*i+2] * amplitude)
# set colors
hyperion.setColor(colors)
# increment the phase
amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi)
if rotateColors:
colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement]
numberOfRotates = (numberOfRotates + 1) % hyperion.ledCount
rotateColors = not rotateColors
# sleep for a while
time.sleep(sleepTime)

View File

@ -18,7 +18,7 @@ inline VideoMode parse3DMode(std::string videoMode)
// convert to lower case // convert to lower case
std::transform(videoMode.begin(), videoMode.end(), videoMode.begin(), ::tolower); std::transform(videoMode.begin(), videoMode.end(), videoMode.begin(), ::tolower);
if (videoMode == "23DTAB") if (videoMode == "3DTAB")
{ {
return VIDEO_3DTAB; return VIDEO_3DTAB;
} }

View File

@ -16,12 +16,12 @@
"required" : false "required" : false
}, },
"saturationGain" : { "saturationGain" : {
"type" : "double", "type" : "number",
"required" : false, "required" : false,
"minimum" : 0.0 "minimum" : 0.0
}, },
"valueGain" : { "valueGain" : {
"type" : "double", "type" : "number",
"required" : false, "required" : false,
"minimum" : 0.0 "minimum" : 0.0
}, },
@ -29,7 +29,7 @@
"type": "array", "type": "array",
"required": false, "required": false,
"items" : { "items" : {
"type": "double", "type": "number",
"minimum": 0.0, "minimum": 0.0,
"maximum": 1.0 "maximum": 1.0
}, },
@ -40,7 +40,7 @@
"type": "array", "type": "array",
"required": false, "required": false,
"items" : { "items" : {
"type": "double", "type": "number",
"minimum": 0.0 "minimum": 0.0
}, },
"minItems": 3, "minItems": 3,
@ -50,7 +50,7 @@
"type": "array", "type": "array",
"required": false, "required": false,
"items" : { "items" : {
"type": "double" "type": "number"
}, },
"minItems": 3, "minItems": 3,
"maxItems": 3 "maxItems": 3
@ -59,7 +59,7 @@
"type": "array", "type": "array",
"required": false, "required": false,
"items" : { "items" : {
"type": "double" "type": "number"
}, },
"minItems": 3, "minItems": 3,
"maxItems": 3 "maxItems": 3

View File

@ -29,6 +29,7 @@ SET(Leddevice_HEADERS
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h ${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
${CURRENT_SOURCE_DIR}/LedDeviceTest.h ${CURRENT_SOURCE_DIR}/LedDeviceTest.h
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
) )
SET(Leddevice_SOURCES SET(Leddevice_SOURCES
@ -45,6 +46,7 @@ SET(Leddevice_SOURCES
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp ${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp ${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp ${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
) )
if(ENABLE_SPIDEV) if(ENABLE_SPIDEV)

View File

@ -29,6 +29,7 @@
#include "LedDeviceTest.h" #include "LedDeviceTest.h"
#include "LedDeviceHyperionUsbasp.h" #include "LedDeviceHyperionUsbasp.h"
#include "LedDevicePhilipsHue.h" #include "LedDevicePhilipsHue.h"
#include "LedDeviceTpm2.h"
LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig) 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(); const std::string output = deviceConfig["output"].asString();
device = new LedDeviceTest(output); 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 else
{ {
std::cout << "Unable to create device " << type << std::endl; std::cout << "Unable to create device " << type << std::endl;

View 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());
}

View 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;
};