Philiphs Hue Improvments (#472)

* patch and improve philiphshue

* cleanup

* cleanup

* cleanup

* LedDevice switchOn()

* add signal for on/off to ledDevice
This commit is contained in:
brindosch
2017-09-16 00:18:17 +02:00
committed by GitHub
parent 81f5f51257
commit 74ff5c7ada
5 changed files with 268 additions and 261 deletions

View File

@@ -44,12 +44,18 @@ int LedDevice::open()
void LedDevice::setEnable(bool enable)
{
// emit signal when state changed
if (_enabled != enable)
{
emit enableStateChanged(enable);
}
// set black to leds when they should go off
if ( _enabled && !enable)
{
switchOff();
}
_enabled = enable;
}
int LedDevice::addToDeviceMap(QString name, LedDeviceCreateFuncType funcPtr)
@@ -91,27 +97,27 @@ QJsonObject LedDevice::getLedDeviceSchemas()
QDir d(":/leddevices/");
QStringList l = d.entryList();
QJsonObject result, schemaJson;
for(QString &item : l)
{
QFile schemaData(QString(":/leddevices/")+item);
QString devName = item.remove("schema-");
if (!schemaData.open(QIODevice::ReadOnly))
{
Error(Logger::getInstance("LedDevice"), "Schema not found: %s", QSTRING_CSTR(item));
throw std::runtime_error("ERROR: Schema not found: " + item.toStdString());
}
QByteArray schema = schemaData.readAll();
QJsonDocument doc = QJsonDocument::fromJson(schema, &error);
schemaData.close();
if (error.error != QJsonParseError::NoError)
{
// report to the user the failure and their locations in the document.
int errorLine(0), errorColumn(0);
for( int i=0, count=qMin( error.offset,schema.size()); i<count; ++i )
{
++errorColumn;
@@ -121,18 +127,18 @@ QJsonObject LedDevice::getLedDeviceSchemas()
++errorLine;
}
}
QString errorMsg = error.errorString() + " at Line: " + QString::number(errorLine) + ", Column: " + QString::number(errorColumn);
Error(Logger::getInstance("LedDevice"), "LedDevice JSON schema error in %s (%s)", QSTRING_CSTR(item), QSTRING_CSTR(errorMsg));
throw std::runtime_error("ERROR: Json schema wrong: " + errorMsg.toStdString());
}
schemaJson = doc.object();
schemaJson["title"] = QString("edt_dev_spec_header_title");
result[devName] = schemaJson;
}
return result;
}
@@ -154,7 +160,7 @@ int LedDevice::setLedValues(const std::vector<ColorRgb>& ledValues)
_ledValues = ledValues;
retval = write(ledValues);
_last_write_time = QDateTime::currentMSecsSinceEpoch();
}
}
//else Debug(_log, "latch %d", QDateTime::currentMSecsSinceEpoch()-_last_write_time);
return retval;
@@ -165,6 +171,10 @@ int LedDevice::switchOff()
return _deviceReady ? write(std::vector<ColorRgb>(_ledCount, ColorRgb::BLACK )) : -1;
}
int LedDevice::switchOn()
{
return 0;
}
void LedDevice::setLedCount(int ledCount)
{