add limit for write to leddevice (#432)

* add limit for write to leddevice

* add to default config

* add i18n

* extend xmas effect

* fix indention

* add check for minimum brightness

* adapt effects to fading and new minWriteTime

* remove old latchTime
rename minimumWriteTime to latchTime
make it as dev specific option

* set default for rewriteTime to 1s
pause smoothing on color too

* reenable smoothing for color - it looks nicer :-)

* fix timeout timer
This commit is contained in:
redPanther 2017-04-09 22:28:32 +02:00 committed by GitHub
parent d11dcf3640
commit b65d811640
62 changed files with 564 additions and 202 deletions

View File

@ -27,13 +27,15 @@
/// * [device type specific configuration]
/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.).
/// * 'rewriteTime': in ms. Data is resend to leds, if no new data is available in thistime. 0 means no refresh
/// * 'latchTime' : minimum time between led writes. 0 means no limit. default 10 means a rate of max 100Hz write time
"device" :
{
"type" : "file",
"output" : "/dev/null",
"rate" : 1000000,
"colorOrder" : "rgb",
"rewriteTime": 0
"rewriteTime": 0,
"latchTime" : 10
},
/// Color manipulation configuration used to tune the output colors to specific surroundings.

View File

@ -16,7 +16,8 @@
"output" : "/dev/null",
"rate" : 1000000,
"colorOrder" : "rgb",
"rewriteTime": 5000
"rewriteTime": 5000,
"latchTime" : 10
},
"color" :

View File

@ -5,7 +5,7 @@
{
"color-end": [ 255, 255, 255 ],
"color-start": [ 50, 50, 50 ],
"fade-in-time" : 4000,
"fade-in-time" : 3000,
"fade-out-time" : 1000,
"color-start-time" : 50,
"color-end-time" : 250,

View File

@ -9,31 +9,32 @@ colorStartTime = float(hyperion.args.get('color-start-time', 1000)) / 1000
colorEndTime = float(hyperion.args.get('color-end-time', 1000)) / 1000
repeat = hyperion.args.get('repeat-count', 0)
maintainEndCol = hyperion.args.get('maintain-end-color', True)
minStepTime = 0.03
minStepTime = float(hyperion.latchTime)/1000.0
currentR = currentG = currentB = 0
# create color table for fading from start to end color
steps = float(abs(max((colorEnd[0] - colorStart[0]),max((colorEnd[1] - colorStart[1]),(colorEnd[2] - colorStart[2])))))
color_step = (
(colorEnd[0] - colorStart[0]) / 256.0,
(colorEnd[1] - colorStart[1]) / 256.0,
(colorEnd[2] - colorStart[2]) / 256.0
(colorEnd[0] - colorStart[0]) / steps,
(colorEnd[1] - colorStart[1]) / steps,
(colorEnd[2] - colorStart[2]) / steps
)
calcChannel = lambda i: min(max(int(colorStart[i] + color_step[i]*step),0),255)
calcChannel = lambda i: min(max(int(round(colorStart[i] + color_step[i]*step)),0), colorEnd[i] if colorStart[i] < colorEnd[i] else colorStart[i])
colors = []
for step in range(256):
for step in range(int(steps)+1):
colors.append( (calcChannel(0),calcChannel(1),calcChannel(2)) )
# calculate timings
if fadeInTime>0:
incrementIn = max(1,int(round(256.0 / (fadeInTime / minStepTime) )))
sleepTimeIn = fadeInTime / (256.0 / incrementIn)
incrementIn = max(1,int(round(steps / (fadeInTime / minStepTime) )))
sleepTimeIn = fadeInTime / (steps / incrementIn)
else:
incrementIn = sleepTimeIn = 1
if fadeOutTime>0:
incrementOut = max(1,int(round(256.0 / (fadeOutTime / minStepTime) )))
sleepTimeOut = fadeOutTime / (256.0 / incrementOut)
incrementOut = max(1,int(round(steps / (fadeOutTime / minStepTime) )))
sleepTimeOut = fadeOutTime / (steps / incrementOut)
else:
incrementOut = sleepTimeOut = 1
@ -50,7 +51,8 @@ repeatCounter = 1
while not hyperion.abort():
# fade in
if fadeInTime > 0:
for step in range(0,256,incrementIn):
setColor( colors[0][0],colors[0][1],colors[0][2] )
for step in range(0,int(steps)+1,incrementIn):
if hyperion.abort(): break
setColor( colors[step][0],colors[step][1],colors[step][2] )
time.sleep(sleepTimeIn)
@ -58,29 +60,31 @@ while not hyperion.abort():
# end color
t = 0.0
while t<colorStartTime and not hyperion.abort():
setColor( colors[255][0],colors[255][1],colors[255][2] )
time.sleep(0.01)
t += 0.01
setColor( colors[int(steps)][0],colors[int(steps)][1],colors[int(steps)][2] )
time.sleep(minStepTime)
t += minStepTime
# fade out
if fadeOutTime > 0:
for step in range(255,-1,-incrementOut):
setColor( colors[int(steps)][0],colors[int(steps)][1],colors[int(steps)][2] )
for step in range(int(steps),-1,-incrementOut):
if hyperion.abort(): break
hyperion.setColor( colors[step][0],colors[step][1],colors[step][2] )
setColor( colors[step][0],colors[step][1],colors[step][2] )
time.sleep(sleepTimeOut)
# start color
t = 0.0
while t<colorEndTime and not hyperion.abort():
setColor( colors[0][0],colors[0][1],colors[0][2] )
time.sleep(0.01)
t += 0.01
time.sleep(minStepTime)
t += minStepTime
# repeat
if repeat > 0 and repeatCounter >= repeat : break
repeatCounter += 1
time.sleep(0.5)
# maintain end color until effect end
while not hyperion.abort() and maintainEndCol:
hyperion.setColor( currentR, currentG, currentB )

View File

@ -51,4 +51,4 @@ while not hyperion.abort():
hyperion.imageCanonicalGradient(centerX, centerY, angleS, colorsSecond)
hyperion.imageShow()
time.sleep(0.01 )
time.sleep(0.5 )

View File

@ -1,4 +1,4 @@
import hyperion, time
import hyperion, time, math
# Get the parameters
rotationTime = float(hyperion.args.get('rotation-time', 3.0))
@ -6,12 +6,18 @@ reverse = bool(hyperion.args.get('reverse', False))
centerX = float(hyperion.args.get('center_x', 0.5))
centerY = float(hyperion.args.get('center_y', 0.5))
minStepTime = float(hyperion.latchTime)/1000.0
sleepTime = max(0.1, rotationTime) / 360
angle = 0
centerX = int(round(float(hyperion.imageWidth)*centerX))
centerY = int(round(float(hyperion.imageHeight)*centerY))
increment = -1 if reverse else 1
# adapt sleeptime to hardware
if minStepTime > sleepTime:
increment *= int(math.ceil(minStepTime / sleepTime))
sleepTime = minStepTime
# table of stop colors for rainbow gradient, first is the position, next rgb, all values 0-255
rainbowColors = bytearray([
0 ,255,0 ,0, 255,

View File

@ -3,7 +3,7 @@
"script" : "random.py",
"args" :
{
"speed" : 1.0,
"speed" : 750,
"saturation" : 1.0
}
}

View File

@ -1,21 +1,46 @@
import hyperion, time, colorsys, random
import hyperion, time, colorsys, random, math
# get args
sleepTime = float(hyperion.args.get('speed', 1.0))
sleepTime = float(hyperion.args.get('speed', 1.0))/1000.0
saturation = float(hyperion.args.get('saturation', 1.0))
ledData = bytearray()
ledDataBuf = bytearray()
color_step = []
minStepTime= float(hyperion.latchTime)/1000.0
fadeSteps = min(256.0, math.floor(sleepTime/minStepTime))
# Initialize the led data
for i in range(hyperion.ledCount):
ledData += bytearray((0,0,0))
ledDataBuf += bytearray((0,0,0))
color_step.append((0.0,0.0,0.0))
# Start the write data loop
while not hyperion.abort():
hyperion.setColor(ledData)
for i in range(len(ledData)):
ledDataBuf[i] = ledData[i]
for i in range(hyperion.ledCount):
if random.randrange(10) == 1:
rgb = colorsys.hsv_to_rgb(random.random(), saturation, random.random())
ledData[i*3 ] = int(255*rgb[0])
ledData[i*3+1] = int(255*rgb[1])
ledData[i*3+2] = int(255*rgb[2])
time.sleep(sleepTime)
color_step[i] = (
(ledData[i*3 ]-ledDataBuf[i*3 ])/fadeSteps,
(ledData[i*3+1]-ledDataBuf[i*3+1])/fadeSteps,
(ledData[i*3+2]-ledDataBuf[i*3+2])/fadeSteps)
else:
color_step[i] = (0.0,0.0,0.0)
for step in range(int(fadeSteps)):
for i in range(hyperion.ledCount):
ledDataBuf[i*3 ] = min(max(int(ledDataBuf[i*3 ] + color_step[i][0]*float(step)),0),ledData[i*3 ])
ledDataBuf[i*3+1] = min(max(int(ledDataBuf[i*3+1] + color_step[i][1]*float(step)),0),ledData[i*3+1])
ledDataBuf[i*3+2] = min(max(int(ledDataBuf[i*3+2] + color_step[i][2]*float(step)),0),ledData[i*3+2])
hyperion.setColor(ledDataBuf)
time.sleep(sleepTime/fadeSteps)
hyperion.setColor(ledData)

View File

@ -7,8 +7,9 @@
"speed": {
"type": "number",
"title":"edt_eff_speed_title",
"default": 1.0,
"minimum" : 0.0,
"default": 1000,
"minimum" : 10,
"append" : "edt_append_ms",
"propertyOrder" : 1
},
"saturation": {

View File

@ -33,10 +33,11 @@
"propertyOrder" : 4
},
"speed": {
"type": "number",
"type": "integer",
"title":"edt_eff_speed_title",
"default": 1.0,
"minimum" : 0.1,
"default": 100,
"minimum" : 10,
"append" : "edt_append_ms",
"propertyOrder" : 5
},
"random": {

View File

@ -5,11 +5,47 @@
"required":true,
"properties":{
"sleepTime": {
"type": "number",
"type": "integer",
"title":"edt_eff_sleeptime_title",
"default": 1.0,
"minimum" : 0.1,
"default": 1000,
"minimum" : 100,
"append" : "edt_append_ms",
"propertyOrder" : 1
},
"length": {
"type": "integer",
"title":"edt_eff_length_title",
"default": 1,
"minimum" : 1,
"propertyOrder" : 2
},
"color1": {
"type": "array",
"title":"edt_eff_color_title",
"format":"colorpicker",
"default": [255,255,255],
"items" : {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"minItems": 3,
"maxItems": 3,
"propertyOrder" : 3
},
"color2": {
"type": "array",
"title":"edt_eff_color_title",
"format":"colorpicker",
"default": [255,0,0],
"items" : {
"type": "integer",
"minimum": 0,
"maximum": 255
},
"minItems": 3,
"maxItems": 3,
"propertyOrder" : 4
}
},
"additionalProperties": false

View File

@ -1,25 +1,25 @@
import hyperion
import time
import colorsys
import random
import hyperion, time, random, math
# Initialize the led data
ledData = bytearray()
for i in range(hyperion.ledCount):
ledData += bytearray((0,0,0))
sleepTime = float(hyperion.args.get('speed', 1.0)) * 0.004
sleepTime = float(hyperion.args.get('speed', 1.0)) * 0.004
minStepTime = float(hyperion.latchTime)/1000.0
factor = 1 if sleepTime > minStepTime else int(math.ceil(minStepTime/sleepTime))
runners = [
{ "i":0, "pos":0, "c":0, "step":9 , "lvl":255},
{ "i":1, "pos":0, "c":0, "step":8 , "lvl":255},
{ "i":2, "pos":0, "c":0, "step":7 , "lvl":255},
{ "i":0, "pos":0, "c":0, "step":6 , "lvl":100},
{ "i":1, "pos":0, "c":0, "step":5 , "lvl":100},
{ "i":2, "pos":0, "c":0, "step":4, "lvl":100},
{ "i":0, "pos":0, "c":0, "step":9, "lvl":255},
{ "i":1, "pos":0, "c":0, "step":8, "lvl":255},
{ "i":2, "pos":0, "c":0, "step":7, "lvl":255},
{ "i":0, "pos":0, "c":0, "step":6, "lvl":100},
{ "i":1, "pos":0, "c":0, "step":5, "lvl":100},
{ "i":2, "pos":0, "c":0, "step":4, "lvl":100},
]
# Start the write data loop
i = 0
while not hyperion.abort():
for r in runners:
if r["c"] == 0:
@ -30,5 +30,9 @@ while not hyperion.abort():
else:
r["c"] -= 1
hyperion.setColor(ledData)
i += 1
if i % factor == 0:
hyperion.setColor(ledData)
i = 0
time.sleep(sleepTime)

View File

@ -7,7 +7,7 @@
"max_len" : 7,
"height" : 8,
"trails": 3,
"speed" : 1.0,
"speed" : 30,
"random" : false,
"color" : [255, 255, 255]
}

View File

@ -7,93 +7,91 @@ min_len = int(hyperion.args.get('min_len', 3))
max_len = int(hyperion.args.get('max_len', 3))
height = int(hyperion.args.get('height', 8))
trails = int(hyperion.args.get('int', 8))
sleepTime = float(hyperion.args.get('speed', 1.0)) * 0.01
sleepTime = float(hyperion.args.get('speed', 1)) / 1000.0
color = list(hyperion.args.get('color', (255,255,255)))
randomise = bool(hyperion.args.get('random', False))
whidth = hyperion.ledCount / height
class trail:
def __init__(self):
return
def __init__(self):
return
def start(self, x, y, step, color, _len, _h):
self.pos = 0.0
self.step = step
self.h = _h
self.x = x
self.data = []
brigtness = color[2]
step_brigtness = color[2] / _len
for i in range(0, _len):
rgb = colorsys.hsv_to_rgb(color[0], color[1], brigtness)
self.data.insert(0, (int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
brigtness -= step_brigtness
def start(self, x, y, step, color, _len, _h):
self.pos = 0.0
self.step = step
self.h = _h
self.x = x
self.data = []
brigtness = color[2]
step_brigtness = color[2] / _len
for i in range(0, _len):
rgb = colorsys.hsv_to_rgb(color[0], color[1], brigtness)
self.data.insert(0, (int(255*rgb[0]), int(255*rgb[1]), int(255*rgb[2])))
brigtness -= step_brigtness
self.data.extend([(0,0,0)]*(_h-y))
if len(self.data) < _h:
for i in range (_h-len(self.data)):
self.data.insert(0, (0,0,0))
self.data.extend([(0,0,0)]*(_h-y))
if len(self.data) < _h:
for i in range (_h-len(self.data)):
self.data.insert(0, (0,0,0))
def getdata(self):
self.pos += self.step
if self.pos > 1.0:
self.pos = 0.0
self.data.pop()
self.data.insert(0, (0,0,0))
return self.x, self.data[-self.h:], all(x == self.data[0] for x in self.data)
def getdata(self):
self.pos += self.step
if self.pos > 1.0:
self.pos = 0.0
self.data.pop()
self.data.insert(0, (0,0,0))
return self.x, self.data[-self.h:], all(x == self.data[0] for x in self.data)
tr = []
for i in range(trails):
r = {
'exec': trail()
}
r = {'exec': trail()}
if randomise:
col = (random.uniform(0.1, 1.0), random.uniform(0.1, 1.0), random.uniform(0.1, 1.0))
else:
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
if randomise:
col = (random.uniform(0.1, 1.0), random.uniform(0.1, 1.0), random.uniform(0.1, 1.0))
else:
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
r['exec'].start(
random.randint(0, whidth),
random.randint(0, height),
random.uniform(0.2, 0.8),
col,
random.randint(min_len, max_len),
height
)
tr.append(r)
r['exec'].start(
random.randint(0, whidth),
random.randint(0, height),
random.uniform(0.2, 0.8),
col,
random.randint(min_len, max_len),
height
)
tr.append(r)
# Start the write data loop
while not hyperion.abort():
ledData = bytearray()
ledData = bytearray()
for r in tr:
r['x'], r['data'], c = r['exec'].getdata()
if c:
if randomise:
col = (random.uniform(0.1, 1.0), random.uniform(0.1, 1.0), random.uniform(0.1, 1.0))
else:
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
for r in tr:
r['x'], r['data'], c = r['exec'].getdata()
if c:
if randomise:
col = (random.uniform(0.1, 1.0), random.uniform(0.1, 1.0), random.uniform(0.1, 1.0))
else:
col = colorsys.rgb_to_hsv(color[0]/255.0, color[1]/255.0, color[2]/255.0)
r['exec'].start(
random.randint(0, whidth),
random.randint(0, height),
random.uniform(0.2, 0.8),
col,
random.randint(min_len, max_len),
height
)
r['exec'].start(
random.randint(0, whidth),
random.randint(0, height),
random.uniform(0.2, 0.8),
col,
random.randint(min_len, max_len),
height
)
for y in range(0, height):
for x in range(0, whidth):
for r in tr:
if x == r['x']:
led = bytearray(r['data'][y])
break
led = bytearray((0,0,0))
ledData += led
for y in range(0, height):
for x in range(0, whidth):
for r in tr:
if x == r['x']:
led = bytearray(r['data'][y])
break
led = bytearray((0,0,0))
ledData += led
hyperion.setImage(whidth,height,ledData)
time.sleep(sleepTime)
hyperion.setImage(whidth,height,ledData)
time.sleep(sleepTime)

View File

@ -7,7 +7,7 @@
"max_len" : 6,
"height" : 8,
"trails": 16,
"speed" : 8.0,
"speed" : 50,
"random" : true,
"color" : [255, 255, 255]
}

View File

@ -3,6 +3,9 @@
"script" : "x-mas.py",
"args" :
{
"sleepTime" : 0.75
"sleepTime" : 750,
"color1" : [255,255,255],
"color2" : [255,0,0],
"length" : 1
}
}

View File

@ -1,26 +1,30 @@
import hyperion, time, colorsys
# Get the parameters
sleepTime = float(hyperion.args.get('sleepTime', 1.0))
sleepTime = float(hyperion.args.get('sleepTime', 1000))/1000.0
length = hyperion.args.get('length', 1)
color1 = hyperion.args.get('color1', (255,255,255))
color2 = hyperion.args.get('color2', (255,0,0))
# Initialize the led data
i = 0
ledDataOdd = bytearray()
for i in range(hyperion.ledCount):
if i%2 == 0:
ledDataOdd += bytearray((int(255), int(0), int(0)))
else:
ledDataOdd += bytearray((int(255), int(255), int(255)))
ledDataEven = bytearray()
for i in range(hyperion.ledCount):
if i%2 == 0:
ledDataEven += bytearray((int(255), int(255), int(255)))
else:
ledDataEven += bytearray((int(255), int(0), int(0)))
while i < hyperion.ledCount:
for l in range(length):
if i<hyperion.ledCount:
ledDataOdd += bytearray((int(color1[0]), int(color1[1]), int(color1[2])))
i += 1
for l in range(length):
if i<hyperion.ledCount:
ledDataOdd += bytearray((int(color2[0]), int(color2[1]), int(color2[2])))
i += 1
ledDataEven = ledDataOdd[3*length:] + ledDataOdd[0:3*length]
# Start the write data loop
while not hyperion.abort():
hyperion.setColor(ledDataOdd)
time.sleep(sleepTime)
hyperion.setColor(ledDataEven)
time.sleep(sleepTime)
time.sleep(sleepTime)

View File

@ -179,6 +179,8 @@ public:
int getConfigVersionId() { return _configVersionId; };
int getLatchTime() const;
public slots:
///
/// Writes a single color to all the leds for the given time and priority

View File

@ -62,6 +62,7 @@ public:
void setEnable(bool enable);
bool enabled() { return _enabled; };
int getLatchTime() { return _latchTime_ms; };
inline bool componentState() { return enabled(); };
@ -93,15 +94,16 @@ protected:
/// Timer object which makes sure that led data is written at a minimum rate
/// e.g. Adalight device will switch off when it does not receive data at least every 15 seconds
QTimer _refresh_timer;
QTimer _refresh_timer;
unsigned int _refresh_timer_interval;
qint64 _last_write_time;
unsigned int _latchTime_ms;
protected slots:
/// Write the last data to the leds again
int rewriteLeds();
private:
std::vector<ColorRgb> _ledValues;
bool _componentRegistered;
bool _enabled;
bool _componentRegistered;
bool _enabled;
};

View File

@ -126,6 +126,9 @@ void Effect::run()
// add imageHeight variable to the interpreter
PyObject_SetAttrString(module, "imageHeight", Py_BuildValue("i", _imageSize.height()));
// add minimumWriteTime variable to the interpreter
PyObject_SetAttrString(module, "latchTime", Py_BuildValue("i", Hyperion::getInstance()->getLatchTime()));
// add a args variable to the interpreter
PyObject_SetAttrString(module, "args", json2python(_args));

View File

@ -436,7 +436,7 @@ Hyperion::Hyperion(const QJsonObject &qjsonConfig, const QString configFile)
_timerBonjourResolver.start();
// create the effect engine
_effectEngine = new EffectEngine(this,qjsonConfig["effects"].toObject());
_effectEngine = new EffectEngine(this,qjsonConfig["effects"].toObject() );
const QJsonObject& device = qjsonConfig["device"].toObject();
unsigned int hwLedCount = device["ledCount"].toInt(getLedCount());
@ -455,6 +455,10 @@ Hyperion::Hyperion(const QJsonObject &qjsonConfig, const QString configFile)
update();
}
int Hyperion::getLatchTime() const
{
return _device->getLatchTime();
}
void Hyperion::freeObjects(bool emitCloseSignal)
{
@ -857,7 +861,7 @@ void Hyperion::update()
}
// Start the timeout-timer
if (priorityInfo.timeoutTime_ms == -1)
if (priorityInfo.timeoutTime_ms <= 0)
{
_timer.stop();
}

View File

@ -61,7 +61,7 @@
"type" : "object",
"title" : "edt_dev_general_heading_title",
"required" : true,
"defaultProperties": ["ledCount","colorOrder","rewriteTime"],
"defaultProperties": ["ledCount","colorOrder","rewriteTime","minimumWriteTime"],
"properties" :
{
"type" :
@ -89,7 +89,7 @@
"rewriteTime": {
"type": "integer",
"title":"edt_dev_general_rewriteTime_title",
"default": 5000,
"default": 1000,
"append" : "edt_append_ms",
"minimum": 0,
"access" : "expert",

View File

@ -5,6 +5,8 @@
#include <QResource>
#include <QStringList>
#include <QDir>
#include <QDateTime>
#include "hyperion/Hyperion.h"
LedDeviceRegistry LedDevice::_ledDeviceMap = LedDeviceRegistry();
@ -20,6 +22,8 @@ LedDevice::LedDevice()
, _deviceReady(true)
, _refresh_timer()
, _refresh_timer_interval(0)
, _last_write_time(QDateTime::currentMSecsSinceEpoch())
, _latchTime_ms(0)
, _componentRegistered(false)
, _enabled(true)
{
@ -66,7 +70,14 @@ void LedDevice::setActiveDevice(QString dev)
bool LedDevice::init(const QJsonObject &deviceConfig)
{
_refresh_timer.setInterval( deviceConfig["rewriteTime"].toInt(_refresh_timer_interval) );
_latchTime_ms = deviceConfig["latchTime"].toInt(_latchTime_ms);
_refresh_timer.setInterval( deviceConfig["rewriteTime"].toInt( _refresh_timer_interval) );
if (_refresh_timer.interval() <= (signed)_latchTime_ms )
{
Warning(_log, "latchTime(%d) is bigger/equal rewriteTime(%d)", _refresh_timer.interval(), _latchTime_ms);
_refresh_timer.setInterval(_latchTime_ms+10);
}
return true;
}
@ -127,17 +138,26 @@ QJsonObject LedDevice::getLedDeviceSchemas()
int LedDevice::setLedValues(const std::vector<ColorRgb>& ledValues)
{
int retval = 0;
if (!_deviceReady || !_enabled)
return -1;
_ledValues = ledValues;
// restart the timer
if (_refresh_timer.interval() > 0)
{
_refresh_timer.start();
}
return write(ledValues);
if (_latchTime_ms == 0 || QDateTime::currentMSecsSinceEpoch()-_last_write_time >= _latchTime_ms)
{
_ledValues = ledValues;
retval = write(ledValues);
_last_write_time = QDateTime::currentMSecsSinceEpoch();
}
//else Debug(_log, "latch %d", QDateTime::currentMSecsSinceEpoch()-_last_write_time);
return retval;
}
int LedDevice::switchOff()

View File

@ -14,7 +14,6 @@ LedDevice* LedDeviceAPA102::construct(const QJsonObject &deviceConfig)
bool LedDeviceAPA102::init(const QJsonObject &deviceConfig)
{
ProviderSpi::init(deviceConfig);
_latchTime_ns = 500000; // fixed latchtime
const unsigned int startFrameSize = 4;
const unsigned int endFrameSize = std::max<unsigned int>(((_ledCount + 15) / 16), 4);

View File

@ -8,7 +8,6 @@ LedDeviceTpm2net::LedDeviceTpm2net(const QJsonObject &deviceConfig)
bool LedDeviceTpm2net::init(const QJsonObject &deviceConfig)
{
_LatchTime_ns = 104000;
_port = TPM2_DEFAULT_PORT;
ProviderUdp::init(deviceConfig);
_tpm2_max = deviceConfig["max-packet"].toInt(170);

View File

@ -12,7 +12,6 @@ LedDeviceUdpE131::LedDeviceUdpE131(const QJsonObject &deviceConfig)
bool LedDeviceUdpE131::init(const QJsonObject &deviceConfig)
{
_LatchTime_ns = 104000;
_port = 5568;
ProviderUdp::init(deviceConfig);
_e131_universe = deviceConfig["universe"].toInt(1);

View File

@ -9,7 +9,7 @@ LedDeviceUdpH801::LedDeviceUdpH801(const QJsonObject &deviceConfig)
bool LedDeviceUdpH801::init(const QJsonObject &deviceConfig)
{
/* The H801 port is fixed */
_LatchTime_ns = 10000000;
_latchTime_ms = 10;
_port = 30977;
_defaultHost = "255.255.255.255";
ProviderUdp::init(deviceConfig);

View File

@ -3,7 +3,6 @@
LedDeviceUdpRaw::LedDeviceUdpRaw(const QJsonObject &deviceConfig)
: ProviderUdp()
{
_LatchTime_ns = 500000;
_port = 5568;
init(deviceConfig);
}

View File

@ -3,7 +3,6 @@
LedDeviceWs2801::LedDeviceWs2801(const QJsonObject &deviceConfig)
: ProviderSpi()
{
_latchTime_ns = 500000;
_deviceReady = ProviderSpi::init(deviceConfig);
}

View File

@ -18,12 +18,12 @@ ProviderSpi::ProviderSpi()
: LedDevice()
, _deviceName("/dev/spidev0.0")
, _baudRate_Hz(1000000)
, _latchTime_ns(0)
, _fid(-1)
, _spiMode(SPI_MODE_0)
, _spiDataInvert(false)
{
memset(&_spi, 0, sizeof(_spi));
_latchTime_ms = 1;
}
ProviderSpi::~ProviderSpi()
@ -37,7 +37,6 @@ bool ProviderSpi::init(const QJsonObject &deviceConfig)
_deviceName = deviceConfig["output"].toString(_deviceName);
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
_latchTime_ns = deviceConfig["latchtime"].toInt(_latchTime_ns);
_spiMode = deviceConfig["spimode"].toInt(_spiMode);
_spiDataInvert = deviceConfig["invert"].toBool(_spiDataInvert);
@ -46,7 +45,7 @@ bool ProviderSpi::init(const QJsonObject &deviceConfig)
int ProviderSpi::open()
{
Debug(_log, "_baudRate_Hz %d, _latchTime_ns %d", _baudRate_Hz, _latchTime_ns);
Debug(_log, "_baudRate_Hz %d, _latchTime_ns %d", _baudRate_Hz, _latchTime_ms);
Debug(_log, "_spiDataInvert %d, _spiMode %d", _spiDataInvert, _spiMode);
const int bitsPerWord = 8;
@ -99,16 +98,5 @@ int ProviderSpi::writeBytes(const unsigned size, const uint8_t * data)
int retVal = ioctl(_fid, SPI_IOC_MESSAGE(1), &_spi);
ErrorIf((retVal < 0), _log, "SPI failed to write. errno: %d, %s", errno, strerror(errno) );
if (retVal >= 0 && _latchTime_ns > 0)
{
// The 'latch' time for latching the shifted-value into the leds
timespec latchTime;
latchTime.tv_sec = 0;
latchTime.tv_nsec = _latchTime_ns;
// Sleep to latch the leds (only if write succesfull)
nanosleep(&latchTime, NULL);
}
return retVal;
}

View File

@ -54,9 +54,6 @@ protected:
/// The used baudrate of the output device
int _baudRate_Hz;
/// The time which the device should be untouched after a write
int _latchTime_ns;
/// The File Identifier of the opened output device (or -1 if not opened)
int _fid;

View File

@ -17,10 +17,10 @@
ProviderUdp::ProviderUdp()
: LedDevice()
, _LatchTime_ns(-1)
, _port(1)
, _defaultHost("127.0.0.1")
{
_latchTime_ms = 1;
_udpSocket = new QUdpSocket();
}
@ -60,8 +60,6 @@ bool ProviderUdp::init(const QJsonObject &deviceConfig)
Debug( _log, "UDP using %s:%d", _address.toString().toStdString().c_str() , _port );
_LatchTime_ns = deviceConfig["latchtime"].toInt(_LatchTime_ns);
return true;
}
@ -79,21 +77,7 @@ int ProviderUdp::writeBytes(const unsigned size, const uint8_t * data)
{
qint64 retVal = _udpSocket->writeDatagram((const char *)data,size,_address,_port);
if (retVal >= 0 && _LatchTime_ns > 0)
{
// The 'latch' time for latching the shifted-value into the leds
timespec latchTime;
latchTime.tv_sec = 0;
latchTime.tv_nsec = _LatchTime_ns;
// Sleep to latch the leds (only if write succesfull)
nanosleep(&latchTime, NULL);
}
else
{
Warning( _log, "Error sending: %s", strerror(errno));
}
WarningIf((retVal<0), _log, "Error sending: %s", strerror(errno));
return retVal;
}

View File

@ -48,9 +48,6 @@ protected:
///
int writeBytes(const unsigned size, const uint8_t *data);
/// The time which the device should be untouched after a write
int _LatchTime_ns;
///
QUdpSocket * _udpSocket;
QHostAddress _address;

View File

@ -26,6 +26,16 @@
"title":"edt_dev_spec_LBap102Mode_title",
"default": false,
"propertyOrder" : 4
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 15,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 5
}
},
"additionalProperties": true

View File

@ -20,6 +20,16 @@
"title":"edt_dev_spec_invert_title",
"default": false,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -20,6 +20,16 @@
"default": 250,
"append" : "ms",
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 10,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -33,6 +33,16 @@
"title":"edt_dev_spec_useOrbSmoothing_title",
"default": true,
"propertyOrder" : 5
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 6
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_delayAfterConnect_title",
"default": 250,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 10,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -21,11 +21,14 @@
"default": 1,
"propertyOrder" : 3
},
"latchtime": {
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 104000,
"append" : "ns",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
},
"cid": {

View File

@ -14,47 +14,57 @@
"default": 7890,
"propertyOrder" : 2
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 3
},
"setFcConfig": {
"type": "boolean",
"title":"edt_dev_spec_FCsetConfig_title",
"default": false,
"propertyOrder" : 3
"propertyOrder" : 4
},
"manualLed": {
"type": "boolean",
"title":"edt_dev_spec_FCmanualControl_title",
"default": false,
"propertyOrder" : 4
"propertyOrder" : 5
},
"ledOn": {
"type": "boolean",
"title":"edt_dev_spec_FCledToOn_title",
"default": false,
"propertyOrder" : 5
"propertyOrder" : 6
},
"interpolation": {
"type": "boolean",
"title":"edt_dev_spec_interpolation_title",
"default": false,
"propertyOrder" : 6
"propertyOrder" : 7
},
"dither": {
"type": "boolean",
"title":"edt_dev_spec_dithering_title",
"default": false,
"propertyOrder" : 7
"propertyOrder" : 8
},
"gamma" : {
"type" : "number",
"title" : "edt_dev_spec_gamma_title",
"minimum" : 0.0,
"maximum": 100.0,
"propertyOrder" : 8
"minimum" : 0.1,
"maximum": 5.0,
"propertyOrder" : 9
},
"whitepoint" : {
"type" : "array",
"title" : "edt_dev_spec_whitepoint_title",
"propertyOrder" : 9,
"propertyOrder" : 10,
"default" : [255,255,255],
"maxItems" : 3,
"minItems" : 3,

View File

@ -5,7 +5,18 @@
"output": {
"type": "string",
"title":"edt_dev_spec_outputPath_title",
"default" : "/dev/null"
"default" : "/dev/null",
"propertyOrder" : 1
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 2
}
},
"additionalProperties": true

View File

@ -22,6 +22,16 @@
"title" : "edt_dev_spec_lightid_itemtitle"
},
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 10,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -2,6 +2,16 @@
"type":"object",
"required":true,
"properties":{
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 10,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 1
}
},
"additionalProperties": true
}

View File

@ -4,7 +4,18 @@
"properties":{
"output": {
"type": "string",
"title":"edt_dev_spec_serial_title"
"title":"edt_dev_spec_serial_title",
"propertyOrder" : 1
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 11,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 2
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_invert_title",
"default": false,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_invert_title",
"default": false,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -2,6 +2,16 @@
"type":"object",
"required":true,
"properties":{
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 11,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 1
}
},
"additionalProperties": true
}

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_invert_title",
"default": false,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_delayAfterConnect_title",
"default": 0,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -44,6 +44,16 @@
"title" : "edt_dev_spec_lightid_itemtitle"
},
"propertyOrder" : 6
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 200,
"append" : "edt_append_ms",
"minimum": 100,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 7
}
},
"additionalProperties": true

View File

@ -8,6 +8,16 @@
"default" : "/dev/pi-blaster",
"propertyOrder" : 1
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 5,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 2
},
"gpiomap": {
"type": "array",
"title":"edt_dev_spec_gpioMap_title",

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_delayAfterConnect_title",
"default": 0,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 10,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_delayAfterConnect_title",
"default": 250,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 10,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -29,6 +29,16 @@
"enum_titles" : ["edt_dev_enum_subtract_minimum", "edt_dev_enum_sub_min_warm_adjust", "edt_dev_enum_white_off"]
},
"propertyOrder" : 4
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 5
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_invert_title",
"default": false,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_general_latchTime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -26,6 +26,16 @@
"title":"edt_dev_spec_intervall_title",
"minimum" : 0,
"propertyOrder" : 4
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 5
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_delayAfterConnect_title",
"default": 250,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 10,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -28,6 +28,16 @@
"minimum" : 0,
"default" : 170,
"propertyOrder" : 4
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 5
}
},
"additionalProperties": true

View File

@ -14,6 +14,16 @@
"minimum" : 0,
"maximum" : 65535,
"propertyOrder" : 2
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 3
}
},
"additionalProperties": true

View File

@ -26,6 +26,16 @@
"title":"edt_dev_spec_invert_title",
"default": false,
"propertyOrder" : 4
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 5
}
},
"additionalProperties": true

View File

@ -19,6 +19,16 @@
"title":"edt_dev_spec_invert_title",
"default": false,
"propertyOrder" : 3
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 4
}
},
"additionalProperties": true

View File

@ -35,6 +35,16 @@
"enum_titles" : ["edt_dev_enum_subtract_minimum", "edt_dev_enum_sub_min_warm_adjust", "edt_dev_enum_white_off"]
},
"propertyOrder" : 4
},
"latchTime": {
"type": "integer",
"title":"edt_dev_spec_latchtime_title",
"default": 1,
"append" : "edt_append_ms",
"minimum": 1,
"maximum": 1000,
"access" : "expert",
"propertyOrder" : 5
}
},
"additionalProperties": true