Skip to content
This repository was archived by the owner on May 6, 2021. It is now read-only.

Commit 5f0b05c

Browse files
committed
Merge branch 'master' into support_for_philips_hue
Conflicts: libsrc/leddevice/LedDevicePhilipsHue.cpp libsrc/leddevice/LedDevicePhilipsHue.h
2 parents fdc93ea + 664fc81 commit 5f0b05c

File tree

11 files changed

+220
-27
lines changed

11 files changed

+220
-27
lines changed

deploy/hyperion.tar.gz

10.5 KB
Binary file not shown.

effects/mood-blobs-cold.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name" : "Cold mood blobs",
3+
"script" : "mood-blobs.py",
4+
"args" :
5+
{
6+
"rotationTime" : 60.0,
7+
"color" : [0,0,255],
8+
"hueChange" : 30.0,
9+
"blobs" : 5,
10+
"reverse" : false,
11+
"baseChange" : true,
12+
"baseColorRangeLeft" : 160,
13+
"baseColorRangeRight" : 320,
14+
"baseColorChangeRate" : 2.0
15+
}
16+
}

effects/mood-blobs-full.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name" : "Full color mood blobs",
3+
"script" : "mood-blobs.py",
4+
"args" :
5+
{
6+
"rotationTime" : 60.0,
7+
"color" : [0,0,255],
8+
"hueChange" : 30.0,
9+
"blobs" : 5,
10+
"reverse" : false,
11+
"baseChange" : true,
12+
"baseColorRangeLeft" : 0,
13+
"baseColorRangeRight" : 360,
14+
"baseColorChangeRate" : 0.2
15+
}
16+
}

effects/mood-blobs-warm.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name" : "Warm mood blobs",
3+
"script" : "mood-blobs.py",
4+
"args" :
5+
{
6+
"rotationTime" : 60.0,
7+
"color" : [255,0,0],
8+
"hueChange" : 30.0,
9+
"blobs" : 5,
10+
"reverse" : false,
11+
"baseChange" : true,
12+
"baseColorRangeLeft" : 333,
13+
"baseColorRangeRight" : 151,
14+
"baseColorChangeRate" : 2.0
15+
}
16+
}

effects/mood-blobs.py

Lines changed: 73 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,31 @@
66
# Get the parameters
77
rotationTime = float(hyperion.args.get('rotationTime', 20.0))
88
color = hyperion.args.get('color', (0,0,255))
9-
hueChange = float(hyperion.args.get('hueChange', 60.0)) / 360.0
9+
hueChange = float(hyperion.args.get('hueChange', 60.0))
1010
blobs = int(hyperion.args.get('blobs', 5))
1111
reverse = bool(hyperion.args.get('reverse', False))
12+
baseColorChange = bool(hyperion.args.get('baseChange', False))
13+
baseColorRangeLeft = float(hyperion.args.get('baseColorRangeLeft',0.0)) # Degree
14+
baseColorRangeRight = float(hyperion.args.get('baseColorRangeRight',360.0)) # Degree
15+
baseColorChangeRate = float(hyperion.args.get('baseColorChangeRate',10.0)) # Seconds for one Degree
16+
17+
# switch baseColor change off if left and right are too close together to see a difference in color
18+
if (baseColorRangeRight > baseColorRangeLeft and (baseColorRangeRight - baseColorRangeLeft) < 10) or \
19+
(baseColorRangeLeft > baseColorRangeRight and ((baseColorRangeRight + 360) - baseColorRangeLeft) < 10):
20+
baseColorChange = False
21+
22+
# 360 -> 1
23+
fullColorWheelAvailable = (baseColorRangeRight % 360) == (baseColorRangeLeft % 360)
24+
baseColorChangeIncreaseValue = 1.0 / 360.0 # 1 degree
25+
hueChange /= 360.0
26+
baseColorRangeLeft = (baseColorRangeLeft / 360.0)
27+
baseColorRangeRight = (baseColorRangeRight / 360.0)
1228

1329
# Check parameters
1430
rotationTime = max(0.1, rotationTime)
1531
hueChange = max(0.0, min(abs(hueChange), .5))
1632
blobs = max(1, blobs)
33+
baseColorChangeRate = max(0, baseColorChangeRate) # > 0
1734

1835
# Calculate the color data
1936
baseHsv = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
@@ -27,6 +44,7 @@
2744
sleepTime = 0.1
2845
amplitudePhaseIncrement = blobs * math.pi * sleepTime / rotationTime
2946
colorDataIncrement = 3
47+
baseColorChangeRate /= sleepTime
3048

3149
# Switch direction if needed
3250
if reverse:
@@ -39,23 +57,58 @@
3957
# Start the write data loop
4058
amplitudePhase = 0.0
4159
rotateColors = False
60+
baseColorChangeStepCount = 0
61+
baseHSVValue = baseHsv[0]
62+
numberOfRotates = 0
63+
4264
while not hyperion.abort():
43-
# Calculate new colors
44-
for i in range(hyperion.ledCount):
45-
amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount))
46-
colors[3*i+0] = int(colorData[3*i+0] * amplitude)
47-
colors[3*i+1] = int(colorData[3*i+1] * amplitude)
48-
colors[3*i+2] = int(colorData[3*i+2] * amplitude)
49-
50-
# set colors
51-
hyperion.setColor(colors)
52-
53-
# increment the phase
54-
amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi)
55-
56-
if rotateColors:
57-
colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement]
58-
rotateColors = not rotateColors
59-
60-
# sleep for a while
61-
time.sleep(sleepTime)
65+
66+
# move the basecolor
67+
if baseColorChange:
68+
# every baseColorChangeRate seconds
69+
if baseColorChangeStepCount >= baseColorChangeRate:
70+
baseColorChangeStepCount = 0
71+
# cyclic increment when the full colorwheel is available, move up and down otherwise
72+
if fullColorWheelAvailable:
73+
baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % baseColorRangeRight
74+
else:
75+
# switch increment direction if baseHSV <= left or baseHSV >= right
76+
if baseColorChangeIncreaseValue < 0 and baseHSVValue > baseColorRangeLeft and (baseHSVValue + baseColorChangeIncreaseValue) <= baseColorRangeLeft:
77+
baseColorChangeIncreaseValue = abs(baseColorChangeIncreaseValue)
78+
elif baseColorChangeIncreaseValue > 0 and baseHSVValue < baseColorRangeRight and (baseHSVValue + baseColorChangeIncreaseValue) >= baseColorRangeRight :
79+
baseColorChangeIncreaseValue = -abs(baseColorChangeIncreaseValue)
80+
81+
baseHSVValue = (baseHSVValue + baseColorChangeIncreaseValue) % 1.0
82+
83+
# update color values
84+
colorData = bytearray()
85+
for i in range(hyperion.ledCount):
86+
hue = (baseHSVValue + hueChange * math.sin(2*math.pi * i / hyperion.ledCount)) % 1.0
87+
rgb = colorsys.hsv_to_rgb(hue, baseHsv[1], baseHsv[2])
88+
colorData += bytearray((int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
89+
90+
# set correct rotation after reinitialisation of the array
91+
colorData = colorData[-colorDataIncrement*numberOfRotates:] + colorData[:-colorDataIncrement*numberOfRotates]
92+
93+
baseColorChangeStepCount += 1
94+
95+
# Calculate new colors
96+
for i in range(hyperion.ledCount):
97+
amplitude = max(0.0, math.sin(-amplitudePhase + 2*math.pi * blobs * i / hyperion.ledCount))
98+
colors[3*i+0] = int(colorData[3*i+0] * amplitude)
99+
colors[3*i+1] = int(colorData[3*i+1] * amplitude)
100+
colors[3*i+2] = int(colorData[3*i+2] * amplitude)
101+
102+
# set colors
103+
hyperion.setColor(colors)
104+
105+
# increment the phase
106+
amplitudePhase = (amplitudePhase + amplitudePhaseIncrement) % (2*math.pi)
107+
108+
if rotateColors:
109+
colorData = colorData[-colorDataIncrement:] + colorData[:-colorDataIncrement]
110+
numberOfRotates = (numberOfRotates + 1) % hyperion.ledCount
111+
rotateColors = not rotateColors
112+
113+
# sleep for a while
114+
time.sleep(sleepTime)

include/utils/VideoMode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ inline VideoMode parse3DMode(std::string videoMode)
1818
// convert to lower case
1919
std::transform(videoMode.begin(), videoMode.end(), videoMode.begin(), ::tolower);
2020

21-
if (videoMode == "23DTAB")
21+
if (videoMode == "3DTAB")
2222
{
2323
return VIDEO_3DTAB;
2424
}

libsrc/jsonserver/schema/schema-transform.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
"required" : false
1717
},
1818
"saturationGain" : {
19-
"type" : "double",
19+
"type" : "number",
2020
"required" : false,
2121
"minimum" : 0.0
2222
},
2323
"valueGain" : {
24-
"type" : "double",
24+
"type" : "number",
2525
"required" : false,
2626
"minimum" : 0.0
2727
},
2828
"threshold": {
2929
"type": "array",
3030
"required": false,
3131
"items" : {
32-
"type": "double",
32+
"type": "number",
3333
"minimum": 0.0,
3434
"maximum": 1.0
3535
},
@@ -40,7 +40,7 @@
4040
"type": "array",
4141
"required": false,
4242
"items" : {
43-
"type": "double",
43+
"type": "number",
4444
"minimum": 0.0
4545
},
4646
"minItems": 3,
@@ -50,7 +50,7 @@
5050
"type": "array",
5151
"required": false,
5252
"items" : {
53-
"type": "double"
53+
"type": "number"
5454
},
5555
"minItems": 3,
5656
"maxItems": 3
@@ -59,7 +59,7 @@
5959
"type": "array",
6060
"required": false,
6161
"items" : {
62-
"type": "double"
62+
"type": "number"
6363
},
6464
"minItems": 3,
6565
"maxItems": 3

libsrc/leddevice/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ SET(Leddevice_HEADERS
2929
${CURRENT_SOURCE_DIR}/LedDeviceSedu.h
3030
${CURRENT_SOURCE_DIR}/LedDeviceTest.h
3131
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.h
32+
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.h
3233
)
3334

3435
SET(Leddevice_SOURCES
@@ -45,6 +46,7 @@ SET(Leddevice_SOURCES
4546
${CURRENT_SOURCE_DIR}/LedDeviceTest.cpp
4647
${CURRENT_SOURCE_DIR}/LedDeviceHyperionUsbasp.cpp
4748
${CURRENT_SOURCE_DIR}/LedDevicePhilipsHue.cpp
49+
${CURRENT_SOURCE_DIR}/LedDeviceTpm2.cpp
4850
)
4951

5052
if(ENABLE_SPIDEV)

libsrc/leddevice/LedDeviceFactory.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "LedDeviceTest.h"
3030
#include "LedDeviceHyperionUsbasp.h"
3131
#include "LedDevicePhilipsHue.h"
32+
#include "LedDeviceTpm2.h"
3233

3334
LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
3435
{
@@ -172,6 +173,15 @@ LedDevice * LedDeviceFactory::construct(const Json::Value & deviceConfig)
172173
const std::string output = deviceConfig["output"].asString();
173174
device = new LedDeviceTest(output);
174175
}
176+
else if (type == "tpm2")
177+
{
178+
const std::string output = deviceConfig["output"].asString();
179+
const unsigned rate = deviceConfig["rate"].asInt();
180+
181+
LedDeviceTpm2* deviceTpm2 = new LedDeviceTpm2(output, rate);
182+
deviceTpm2->open();
183+
device = deviceTpm2;
184+
}
175185
else
176186
{
177187
std::cout << "Unable to create device " << type << std::endl;

libsrc/leddevice/LedDeviceTpm2.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
// STL includes
3+
#include <cstring>
4+
#include <cstdio>
5+
#include <iostream>
6+
7+
// Linux includes
8+
#include <fcntl.h>
9+
#include <sys/ioctl.h>
10+
11+
// hyperion local includes
12+
#include "LedDeviceTpm2.h"
13+
14+
LedDeviceTpm2::LedDeviceTpm2(const std::string& outputDevice, const unsigned baudrate) :
15+
LedRs232Device(outputDevice, baudrate),
16+
_ledBuffer(0)
17+
{
18+
// empty
19+
}
20+
21+
int LedDeviceTpm2::write(const std::vector<ColorRgb> &ledValues)
22+
{
23+
if (_ledBuffer.size() == 0)
24+
{
25+
_ledBuffer.resize(5 + 3*ledValues.size());
26+
_ledBuffer[0] = 0xC9; // block-start byte
27+
_ledBuffer[1] = 0xDA; // DATA frame
28+
_ledBuffer[2] = ((3 * ledValues.size()) >> 8) & 0xFF; // frame size high byte
29+
_ledBuffer[3] = (3 * ledValues.size()) & 0xFF; // frame size low byte
30+
_ledBuffer.back() = 0x36; // block-end byte
31+
}
32+
33+
// write data
34+
memcpy(4 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
35+
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
36+
}
37+
38+
int LedDeviceTpm2::switchOff()
39+
{
40+
memset(4 + _ledBuffer.data(), 0, _ledBuffer.size() - 5);
41+
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
42+
}

0 commit comments

Comments
 (0)