refresh time for all devices + schema fixes (#305)

* refresh for all :-)
remove dups

* - integrate refresh leds for all devices
- fix schemas for led devices

* add minimum for rewrite time

* rewriteTime: add missing info in config examples
This commit is contained in:
redPanther 2016-12-02 12:07:24 +01:00 committed by brindosch
parent 9ddbf81810
commit 96e8c29582
28 changed files with 109 additions and 68 deletions

View File

@ -16,13 +16,15 @@
/// APA102, WS2801, P9813, LPD6803, LPD8806, ---------PWM---------, WS2812b (just RPi1), WS281X (RPi1, RPi2, RPi3), --------OTHER--------, PhilipsHUE, AtmoOrb, PiBlaster, Tinkerforge, FadeCandy, RawHID (USB), UDP, SEDU, TPM2, USBASP-WS2801, USBASP-WS2812, ------3rd PARTY------, Adalight, AdalightAPA102, Atmo, Lightpack, Multi-Lightpack, Paintpack, Test (file), None) /// APA102, WS2801, P9813, LPD6803, LPD8806, ---------PWM---------, WS2812b (just RPi1), WS281X (RPi1, RPi2, RPi3), --------OTHER--------, PhilipsHUE, AtmoOrb, PiBlaster, Tinkerforge, FadeCandy, RawHID (USB), UDP, SEDU, TPM2, USBASP-WS2801, USBASP-WS2812, ------3rd PARTY------, Adalight, AdalightAPA102, Atmo, Lightpack, Multi-Lightpack, Paintpack, Test (file), None)
/// * [device type specific configuration] /// * [device type specific configuration]
/// * 'colorOrder' : The order of the color bytes ('rgb', 'rbg', 'bgr', etc.). /// * '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
"device" : "device" :
{ {
"name" : "MyHyperionConfig", "name" : "MyHyperionConfig",
"type" : "file", "type" : "file",
"output" : "/dev/null", "output" : "/dev/null",
"rate" : 1000000, "rate" : 1000000,
"colorOrder" : "rgb" "colorOrder" : "rgb",
"rewriteTime": 0
}, },
/// Color manipulation configuration used to tune the output colors to specific surroundings. /// Color manipulation configuration used to tune the output colors to specific surroundings.

View File

@ -10,7 +10,8 @@
"type" : "file", "type" : "file",
"output" : "/dev/null", "output" : "/dev/null",
"rate" : 1000000, "rate" : 1000000,
"colorOrder" : "rgb" "colorOrder" : "rgb",
"rewriteTime": 0
}, },
"color" : "color" :

View File

@ -68,6 +68,7 @@ protected:
/// @return Zero on success else negative /// @return Zero on success else negative
/// ///
virtual int write(const std::vector<ColorRgb>& ledValues) = 0; virtual int write(const std::vector<ColorRgb>& ledValues) = 0;
virtual bool init(const QJsonObject &deviceConfig);
/// The common Logger instance for all LedDevices /// The common Logger instance for all LedDevices
Logger * _log; Logger * _log;
@ -86,7 +87,8 @@ protected:
/// Timer object which makes sure that led data is written at a minimum rate /// 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 /// 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;
protected slots: protected slots:
/// Write the last data to the leds again /// Write the last data to the leds again

View File

@ -24,7 +24,7 @@
"type" : "object", "type" : "object",
"title" : "LED Device General", "title" : "LED Device General",
"required" : true, "required" : true,
"defaultProperties": ["name","ledCount","colorOrder"], "defaultProperties": ["name","ledCount","colorOrder","rewriteTime"],
"properties" : "properties" :
{ {
"name" : "name" :
@ -52,6 +52,14 @@
"title" : "RGB byte order", "title" : "RGB byte order",
"enum" : ["rgb", "bgr", "rbg", "brg", "gbr", "grb"], "enum" : ["rgb", "bgr", "rbg", "brg", "gbr", "grb"],
"propertyOrder" : 3 "propertyOrder" : 3
},
"rewriteTime": {
"type": "integer",
"title":"Refresh time",
"default": 5000,
"append" : "ms",
"minimum": 0,
"propertOrder" : 4
} }
}, },
"additionalProperties" : true "additionalProperties" : true

View File

@ -18,6 +18,7 @@ LedDevice::LedDevice()
, _ledBuffer(0) , _ledBuffer(0)
, _deviceReady(true) , _deviceReady(true)
, _refresh_timer() , _refresh_timer()
, _refresh_timer_interval(0)
{ {
LedDevice::getLedDeviceSchemas(); LedDevice::getLedDeviceSchemas();
@ -49,6 +50,12 @@ void LedDevice::setActiveDevice(std::string dev)
_activeDevice = dev; _activeDevice = dev;
} }
bool LedDevice::init(const QJsonObject &deviceConfig)
{
_refresh_timer.setInterval( deviceConfig["rewriteTime"].toInt(_refresh_timer_interval) );
return true;
}
QJsonObject LedDevice::getLedDeviceSchemas() QJsonObject LedDevice::getLedDeviceSchemas()
{ {
// make sure the resources are loaded (they may be left out after static linking) // make sure the resources are loaded (they may be left out after static linking)

View File

@ -22,6 +22,9 @@ bool LedDeviceFile::init(const QJsonObject &deviceConfig)
_ofs.close(); _ofs.close();
} }
_refresh_timer_interval = 0;
LedDevice::init(deviceConfig);
std::string fileName = deviceConfig["output"].toString("/dev/null").toStdString(); std::string fileName = deviceConfig["output"].toString("/dev/null").toStdString();
_ofs.open( fileName.c_str() ); _ofs.open( fileName.c_str() );

View File

@ -39,6 +39,8 @@ LedDeviceHyperionUsbasp::~LedDeviceHyperionUsbasp()
bool LedDeviceHyperionUsbasp::init(const QJsonObject &deviceConfig) bool LedDeviceHyperionUsbasp::init(const QJsonObject &deviceConfig)
{ {
LedDevice::init(deviceConfig);
std::string ledType = deviceConfig["output"].toString("ws2801").toStdString(); std::string ledType = deviceConfig["output"].toString("ws2801").toStdString();
if (ledType != "ws2801" && ledType != "ws2812") if (ledType != "ws2801" && ledType != "ws2812")
{ {

View File

@ -71,6 +71,7 @@ LedDeviceLightpack::~LedDeviceLightpack()
bool LedDeviceLightpack::init(const QJsonObject &deviceConfig) bool LedDeviceLightpack::init(const QJsonObject &deviceConfig)
{ {
LedDevice::init(deviceConfig);
_serialNumber = deviceConfig["output"].toString("").toStdString(); _serialNumber = deviceConfig["output"].toString("").toStdString();
return true; return true;

View File

@ -17,10 +17,11 @@ bool compareLightpacks(LedDeviceLightpack * lhs, LedDeviceLightpack * rhs)
return lhs->getSerialNumber() < rhs->getSerialNumber(); return lhs->getSerialNumber() < rhs->getSerialNumber();
} }
LedDeviceMultiLightpack::LedDeviceMultiLightpack(const QJsonObject &) LedDeviceMultiLightpack::LedDeviceMultiLightpack(const QJsonObject &deviceConfig)
: LedDevice() : LedDevice()
, _lightpacks() , _lightpacks()
{ {
LedDevice::init(deviceConfig);
} }
LedDeviceMultiLightpack::~LedDeviceMultiLightpack() LedDeviceMultiLightpack::~LedDeviceMultiLightpack()

View File

@ -179,6 +179,8 @@ LedDevicePhilipsHue::~LedDevicePhilipsHue()
bool LedDevicePhilipsHue::init(const QJsonObject &deviceConfig) bool LedDevicePhilipsHue::init(const QJsonObject &deviceConfig)
{ {
LedDevice::init(deviceConfig);
host = deviceConfig["output"].toString().toStdString().c_str(); host = deviceConfig["output"].toString().toStdString().c_str();
username = deviceConfig["username"].toString("newdeveloper").toStdString().c_str(); username = deviceConfig["username"].toString("newdeveloper").toStdString().c_str();
switchOffOnBlack = deviceConfig["switchOffOnBlack"].toBool(true); switchOffOnBlack = deviceConfig["switchOffOnBlack"].toBool(true);

View File

@ -42,7 +42,9 @@ LedDevicePiBlaster::~LedDevicePiBlaster()
bool LedDevicePiBlaster::init(const QJsonObject &deviceConfig) bool LedDevicePiBlaster::init(const QJsonObject &deviceConfig)
{ {
_deviceName = deviceConfig["output"].toString("").toStdString(); LedDevice::init(deviceConfig);
_deviceName = deviceConfig["output"].toString("/dev/pi-blaster").toStdString();
QJsonArray gpioMapping = deviceConfig["gpiomap"].toArray(); QJsonArray gpioMapping = deviceConfig["gpiomap"].toArray();
if (gpioMapping.isEmpty()) if (gpioMapping.isEmpty())

View File

@ -3,19 +3,10 @@
// Use feature report HID device // Use feature report HID device
LedDeviceRawHID::LedDeviceRawHID(const QJsonObject &deviceConfig) LedDeviceRawHID::LedDeviceRawHID(const QJsonObject &deviceConfig)
: ProviderHID() : ProviderHID()
, _timer()
{ {
ProviderHID::init(deviceConfig); ProviderHID::init(deviceConfig);
_useFeature = true; _useFeature = true;
_ledBuffer.resize(_ledRGBCount); _ledBuffer.resize(_ledRGBCount);
// setup the timer
_timer.setSingleShot(false);
_timer.setInterval(5000);
connect(&_timer, SIGNAL(timeout()), this, SLOT(rewriteLeds()));
// start the timer
_timer.start();
} }
LedDevice* LedDeviceRawHID::construct(const QJsonObject &deviceConfig) LedDevice* LedDeviceRawHID::construct(const QJsonObject &deviceConfig)
@ -25,9 +16,6 @@ LedDevice* LedDeviceRawHID::construct(const QJsonObject &deviceConfig)
int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues) int LedDeviceRawHID::write(const std::vector<ColorRgb> & ledValues)
{ {
// restart the timer
_timer.start();
// write data // write data
memcpy(_ledBuffer.data(), ledValues.data(), _ledRGBCount); memcpy(_ledBuffer.data(), ledValues.data(), _ledRGBCount);
return writeBytes(_ledBuffer.size(), _ledBuffer.data()); return writeBytes(_ledBuffer.size(), _ledBuffer.data());

View File

@ -36,9 +36,4 @@ private:
/// @return Zero on succes else negative /// @return Zero on succes else negative
/// ///
virtual int write(const std::vector<ColorRgb> & ledValues); virtual int write(const std::vector<ColorRgb> & ledValues);
/// Timer object which makes sure that led data is written at a minimum rate
/// The RawHID device will switch off when it does not receive data at least
/// every 15 seconds
QTimer _timer;
}; };

View File

@ -2,31 +2,31 @@
<qresource prefix="/leddevices/"> <qresource prefix="/leddevices/">
<file alias="schema-adalight">schemas/schema-adalight.json</file> <file alias="schema-adalight">schemas/schema-adalight.json</file>
<file alias="schema-apa102">schemas/schema-apa102.json</file> <file alias="schema-apa102">schemas/schema-apa102.json</file>
<file alias="schema-atmo">schemas/schema-atmo.json</file>
<file alias="schema-atmoorb">schemas/schema-atmoorb.json</file> <file alias="schema-atmoorb">schemas/schema-atmoorb.json</file>
<file alias="schema-e131">schemas/schema-e131.json</file> <file alias="schema-atmo">schemas/schema-atmo.json</file>
<file alias="schema-dmx">schemas/schema-dmx.json</file>
<file alias="schema-fadecandy">schemas/schema-fadecandy.json</file> <file alias="schema-fadecandy">schemas/schema-fadecandy.json</file>
<file alias="schema-file">schemas/schema-file.json</file> <file alias="schema-file">schemas/schema-file.json</file>
<file alias="schema-hyperion-usbasp">schemas/schema-hyperion-usbasp.json</file> <file alias="schema-hyperionusbasp">schemas/schema-hyperionusbasp.json</file>
<file alias="schema-lightpack">schemas/schema-lightpack.json</file> <file alias="schema-lightpack">schemas/schema-lightpack.json</file>
<file alias="schema-lpd6803">schemas/schema-lpd6803.json</file> <file alias="schema-lpd6803">schemas/schema-lpd6803.json</file>
<file alias="schema-lpd8806">schemas/schema-lpd8806.json</file> <file alias="schema-lpd8806">schemas/schema-lpd8806.json</file>
<file alias="schema-multi-lightpack">schemas/schema-multi-lightpack.json</file> <file alias="schema-multilightpack">schemas/schema-multilightpack.json</file>
<file alias="schema-p9813">schemas/schema-p9813.json</file> <file alias="schema-p9813">schemas/schema-p9813.json</file>
<file alias="schema-paintpack">schemas/schema-paintpack.json</file> <file alias="schema-paintpack">schemas/schema-paintpack.json</file>
<file alias="schema-philipshue">schemas/schema-philipshue.json</file> <file alias="schema-philipshue">schemas/schema-philipshue.json</file>
<file alias="schema-piblaster">schemas/schema-piblaster.json</file> <file alias="schema-piblaster">schemas/schema-piblaster.json</file>
<file alias="schema-rawhid">schemas/schema-rawhid.json</file> <file alias="schema-rawhid">schemas/schema-rawhid.json</file>
<file alias="schema-sedu">schemas/schema-sedu.json</file> <file alias="schema-sedu">schemas/schema-sedu.json</file>
<file alias="schema-dmx">schemas/schema-dmx.json</file>
<file alias="schema-sk6812spi">schemas/schema-sk6812spi.json</file> <file alias="schema-sk6812spi">schemas/schema-sk6812spi.json</file>
<file alias="schema-tinkerforge">schemas/schema-tinkerforge.json</file> <file alias="schema-tinkerforge">schemas/schema-tinkerforge.json</file>
<file alias="schema-tpm2net">schemas/schema-tpm2net.json</file> <file alias="schema-tpm2net">schemas/schema-tpm2net.json</file>
<file alias="schema-tpm2.json">schemas/schema-tpm2.json</file> <file alias="schema-tpm2">schemas/schema-tpm2.json</file>
<file alias="schema-udpe131">schemas/schema-e131.json</file>
<file alias="schema-udph801">schemas/schema-h801.json</file>
<file alias="schema-udpraw">schemas/schema-udpraw.json</file> <file alias="schema-udpraw">schemas/schema-udpraw.json</file>
<file alias="schema-ws2801">schemas/schema-ws2801.json</file> <file alias="schema-ws2801">schemas/schema-ws2801.json</file>
<file alias="schema-ws2812spi">schemas/schema-ws2812spi.json</file> <file alias="schema-ws2812spi">schemas/schema-ws2812spi.json</file>
<file alias="schema-ws281x">schemas/schema-ws281x.json</file> <file alias="schema-ws281x">schemas/schema-ws281x.json</file>
<file alias="schema-h801">schemas/schema-h801.json</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -33,6 +33,8 @@ LedDeviceTinkerforge::~LedDeviceTinkerforge()
bool LedDeviceTinkerforge::init(const QJsonObject &deviceConfig) bool LedDeviceTinkerforge::init(const QJsonObject &deviceConfig)
{ {
LedDevice::init(deviceConfig);
_host = deviceConfig["output"].toString("127.0.0.1").toStdString(); _host = deviceConfig["output"].toString("127.0.0.1").toStdString();
_port = deviceConfig["port"].toInt(4223); _port = deviceConfig["port"].toInt(4223);
_uid = deviceConfig["uid"].toString().toStdString(); _uid = deviceConfig["uid"].toString().toStdString();

View File

@ -18,6 +18,8 @@ LedDeviceWS281x::~LedDeviceWS281x()
bool LedDeviceWS281x::init(const QJsonObject &deviceConfig) bool LedDeviceWS281x::init(const QJsonObject &deviceConfig)
{ {
LedDevice::init(deviceConfig);
std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString(); std::string whiteAlgorithm = deviceConfig["white_algorithm"].toString("white_off").toStdString();
_whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm); _whiteAlgorithm = RGBW::stringToWhiteAlgorithm(whiteAlgorithm);
Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str()); Debug( _log, "whiteAlgorithm : %s", whiteAlgorithm.c_str());

View File

@ -29,6 +29,8 @@ ProviderHID::~ProviderHID()
bool ProviderHID::init(const QJsonObject &deviceConfig) bool ProviderHID::init(const QJsonObject &deviceConfig)
{ {
LedDevice::init(deviceConfig);
_delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(0); _delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(0);
auto VendorIdString = deviceConfig["VID"].toString("0x2341").toStdString(); auto VendorIdString = deviceConfig["VID"].toString("0x2341").toStdString();
auto ProductIdString = deviceConfig["PID"].toString("0x8036").toStdString(); auto ProductIdString = deviceConfig["PID"].toString("0x8036").toStdString();

View File

@ -26,10 +26,12 @@ ProviderRs232::ProviderRs232()
bool ProviderRs232::init(const QJsonObject &deviceConfig) bool ProviderRs232::init(const QJsonObject &deviceConfig)
{ {
closeDevice(); closeDevice();
LedDevice::init(deviceConfig);
_deviceName = deviceConfig["output"].toString().toStdString(); _deviceName = deviceConfig["output"].toString().toStdString();
_baudRate_Hz = deviceConfig["rate"].toInt(); _baudRate_Hz = deviceConfig["rate"].toInt();
_delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(250); _delayAfterConnect_ms = deviceConfig["delayAfterConnect"].toInt(250);
_refresh_timer.setInterval( deviceConfig["rewriteTime"].toInt(5000) );
return true; return true;
} }

View File

@ -33,6 +33,8 @@ ProviderSpi::~ProviderSpi()
bool ProviderSpi::init(const QJsonObject &deviceConfig) bool ProviderSpi::init(const QJsonObject &deviceConfig)
{ {
LedDevice::init(deviceConfig);
_deviceName = deviceConfig["output"].toString(QString::fromStdString(_deviceName)).toStdString(); _deviceName = deviceConfig["output"].toString(QString::fromStdString(_deviceName)).toStdString();
_baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz); _baudRate_Hz = deviceConfig["rate"].toInt(_baudRate_Hz);
_latchTime_ns = deviceConfig["latchtime"].toInt(_latchTime_ns); _latchTime_ns = deviceConfig["latchtime"].toInt(_latchTime_ns);

View File

@ -30,6 +30,8 @@ ProviderUdp::~ProviderUdp()
bool ProviderUdp::init(const QJsonObject &deviceConfig, std::string defaultHost) bool ProviderUdp::init(const QJsonObject &deviceConfig, std::string defaultHost)
{ {
LedDevice::init(deviceConfig);
QString host = deviceConfig["host"].toString(QString::fromStdString(defaultHost)); QString host = deviceConfig["host"].toString(QString::fromStdString(defaultHost));
if (_address.setAddress(host) ) if (_address.setAddress(host) )

View File

@ -5,6 +5,7 @@
"output": { "output": {
"type": "string", "type": "string",
"title":"Output path", "title":"Output path",
"default":"/dev/ttyACM0",
"propertyOrder" : 1 "propertyOrder" : 1
}, },
"rate": { "rate": {
@ -20,19 +21,12 @@
"append" : "ms", "append" : "ms",
"propertyOrder" : 3 "propertyOrder" : 3
}, },
"rewriteTime": {
"type": "integer",
"title":"refresh time",
"default": 5000,
"append" : "ms",
"propertyOrder" : 4
},
"lightberry_apa102_mode": { "lightberry_apa102_mode": {
"type": "boolean", "type": "boolean",
"format": "checkbox", "format": "checkbox",
"title":"LightBerry APA102 Mode", "title":"LightBerry APA102 Mode",
"default": false, "default": false,
"propertyOrder" : 5 "propertyOrder" : 4
} }
}, },
"additionalProperties": true "additionalProperties": true

View File

@ -19,13 +19,6 @@
"default": 250, "default": 250,
"append" : "ms", "append" : "ms",
"propertyOrder" : 3 "propertyOrder" : 3
},
"rewriteTime": {
"type": "integer",
"title":"refresh time",
"default": 5000,
"append" : "ms",
"propertyOrder" : 4
} }
}, },
"additionalProperties": true "additionalProperties": true

View File

@ -2,10 +2,6 @@
"type":"object", "type":"object",
"required":true, "required":true,
"properties":{ "properties":{
"output": {
"type": "string",
"title":"Serial number"
}
}, },
"additionalProperties": true "additionalProperties": true
} }

View File

@ -2,6 +2,52 @@
"type":"object", "type":"object",
"required":true, "required":true,
"properties":{ "properties":{
"output": {
"type": "string",
"title":"Pi-Blaster FiFo",
"default" : "/dev/pi-blaster",
"propertyOrder" : 1
},
"gpiomap": {
"type": "array",
"title":"GPIO Map",
"propertyOrder" : 2,
"minimum" : 1,
"maximum" : 27,
"items" : {
"type" : "object",
"required" : true,
"properties" :
{
"gpio" :
{
"type" : "integer",
"title" : "GPIO BCMxx",
"minimum" : 0,
"maximum" : 27,
"required" : true,
"propertyOrder" : 1
},
"ledindex" :
{
"type" : "integer",
"title" : "LED index",
"minimum" : 0,
"required" : true,
"propertyOrder" : 2
},
"ledcolor" :
{
"type" : "string",
"title" : "Color component",
"enum" : ["r","g","b","w"],
"required" : true,
"propertyOrder" : 3
}
}
},
"propertyOrder" : 3
}
}, },
"additionalProperties": true "additionalProperties": true
} }

View File

@ -18,13 +18,6 @@
"title":"Delay after connect", "title":"Delay after connect",
"default": 250, "default": 250,
"propertyOrder" : 3 "propertyOrder" : 3
},
"rewriteTime": {
"type": "integer",
"title":"refresh time",
"default": 5000,
"append" : "ms",
"propertyOrder" : 4
} }
}, },
"additionalProperties": true "additionalProperties": true

View File

@ -18,13 +18,6 @@
"title":"Delay after connect", "title":"Delay after connect",
"default": 250, "default": 250,
"propertyOrder" : 3 "propertyOrder" : 3
},
"rewriteTime": {
"type": "integer",
"title":"refresh time",
"default": 5000,
"append" : "ms",
"propertyOrder" : 4
} }
}, },
"additionalProperties": true "additionalProperties": true

View File

@ -16,7 +16,7 @@
}, },
"latchtime": { "latchtime": {
"type": "integer", "type": "integer",
"title":"Latchtime", "title":"Latch time",
"default": 500000, "default": 500000,
"append" : "ns", "append" : "ns",
"propertyOrder" : 3 "propertyOrder" : 3