mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
detect config is readonly, adalight and other stuff (#333)
* update lightberry sketches update compilehowwto (windows disclaimer) some refactoring in main cmakelists + preparation for windows compile tune ada driver, set delayAfterConnect default to 1.5s because some arduino (e.g. mega r3) needs this set priority min/max for grabber/network services - prevent colliding prios between webui/background stuff and grabbers/net services * add check if config is writable. TODO do something usefull in webui * fix indention error * fix typo * fix webui can't write led config * typo * fix cmakelists * change methode of detecting linux
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <QStringList>
|
||||
#include <QCryptographicHash>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
|
||||
// hyperion include
|
||||
#include <hyperion/Hyperion.h>
|
||||
@@ -32,7 +33,7 @@
|
||||
|
||||
Hyperion* Hyperion::_hyperion = nullptr;
|
||||
|
||||
Hyperion* Hyperion::initInstance(const QJsonObject& qjsonConfig, const std::string configFile) // REMOVE jsonConfig variable when the conversion from jsonCPP to QtJSON is finished
|
||||
Hyperion* Hyperion::initInstance(const QJsonObject& qjsonConfig, const QString configFile) // REMOVE jsonConfig variable when the conversion from jsonCPP to QtJSON is finished
|
||||
{
|
||||
if ( Hyperion::_hyperion != nullptr )
|
||||
throw std::runtime_error("Hyperion::initInstance can be called only one time");
|
||||
@@ -514,7 +515,7 @@ MessageForwarder * Hyperion::getForwarder()
|
||||
return _messageForwarder;
|
||||
}
|
||||
|
||||
Hyperion::Hyperion(const QJsonObject &qjsonConfig, const std::string configFile)
|
||||
Hyperion::Hyperion(const QJsonObject &qjsonConfig, const QString configFile)
|
||||
: _ledString(createLedString(qjsonConfig["leds"], createColorOrder(qjsonConfig["device"].toObject())))
|
||||
, _ledStringClone(createLedStringClone(qjsonConfig["leds"], createColorOrder(qjsonConfig["device"].toObject())))
|
||||
, _muxer(_ledString.leds().size())
|
||||
@@ -582,6 +583,7 @@ Hyperion::Hyperion(const QJsonObject &qjsonConfig, const std::string configFile)
|
||||
Debug(_log,"configured leds: %d hw leds: %d", getLedCount(), _hwLedCount);
|
||||
WarningIf(hwLedCount < getLedCount(), _log, "more leds configured than available. check 'ledCount' in 'device' section");
|
||||
|
||||
WarningIf(!configWriteable(), _log, "Your config is not writeable - you won't be able to use the web ui for configuration.");
|
||||
// initialize hash of current config
|
||||
configModified();
|
||||
|
||||
@@ -618,7 +620,7 @@ unsigned Hyperion::getLedCount() const
|
||||
bool Hyperion::configModified()
|
||||
{
|
||||
bool isModified = false;
|
||||
QFile f(_configFile.c_str());
|
||||
QFile f(_configFile);
|
||||
if (f.open(QFile::ReadOnly))
|
||||
{
|
||||
QCryptographicHash hash(QCryptographicHash::Sha1);
|
||||
@@ -639,6 +641,14 @@ bool Hyperion::configModified()
|
||||
return isModified;
|
||||
}
|
||||
|
||||
bool Hyperion::configWriteable()
|
||||
{
|
||||
QFile file(_configFile);
|
||||
QFileInfo fileInfo(file);
|
||||
return fileInfo.isWritable() && fileInfo.isReadable();
|
||||
}
|
||||
|
||||
|
||||
void Hyperion::registerPriority(const std::string name, const int priority)
|
||||
{
|
||||
Info(_log, "Register new input source named '%s' for priority channel '%d'", name.c_str(), priority );
|
||||
|
@@ -476,7 +476,8 @@
|
||||
"priority" :
|
||||
{
|
||||
"type" : "integer",
|
||||
"minimum" : 0,
|
||||
"minimum" : 2,
|
||||
"maximum" : 2000000000,
|
||||
"title" : "edt_conf_general_priority_title",
|
||||
"default" : 900,
|
||||
"propertyOrder" : 9
|
||||
@@ -617,7 +618,8 @@
|
||||
{
|
||||
"type" : "integer",
|
||||
"title" : "edt_conf_general_priority_title",
|
||||
"minimum" : 0,
|
||||
"minimum" : 2,
|
||||
"maximum" : 2000000000,
|
||||
"default" : 890
|
||||
},
|
||||
"cropLeft" :
|
||||
@@ -974,7 +976,8 @@
|
||||
{
|
||||
"type" : "integer",
|
||||
"title" : "edt_conf_general_priority_title",
|
||||
"minimum" : 0,
|
||||
"minimum" : 2,
|
||||
"maximum" : 2000000000,
|
||||
"default" : 800,
|
||||
"propertyOrder" : 3
|
||||
}
|
||||
@@ -1014,7 +1017,8 @@
|
||||
{
|
||||
"type" : "integer",
|
||||
"title" : "edt_conf_general_priority_title",
|
||||
"minimum" : 0,
|
||||
"minimum" : 2,
|
||||
"maximum" : 2000000000,
|
||||
"default" : 800,
|
||||
"propertyOrder" : 4
|
||||
},
|
||||
|
@@ -841,6 +841,7 @@ void JsonClientConnection::handleServerInfoCommand(const QJsonObject&, const QSt
|
||||
ver["build"] = QString(HYPERION_BUILD_ID);
|
||||
ver["time"] = QString(__DATE__ " " __TIME__);
|
||||
ver["config_modified"] = _hyperion->configModified();
|
||||
ver["config_writeable"] = _hyperion->configWriteable();
|
||||
|
||||
hyperion.append(ver);
|
||||
info["hyperion"] = hyperion;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
|
||||
LedDeviceAdalight::LedDeviceAdalight(const QJsonObject &deviceConfig)
|
||||
: ProviderRs232()
|
||||
, _headerSize(6)
|
||||
, _ligthBerryAPA102Mode(false)
|
||||
{
|
||||
_deviceReady = init(deviceConfig);
|
||||
@@ -18,7 +19,6 @@ bool LedDeviceAdalight::init(const QJsonObject &deviceConfig)
|
||||
_ligthBerryAPA102Mode = deviceConfig["lightberry_apa102_mode"].toBool(false);
|
||||
|
||||
// create ledBuffer
|
||||
unsigned int bufferSize = 6; // 6 bytes header
|
||||
unsigned int totalLedCount = _ledCount;
|
||||
|
||||
if (_ligthBerryAPA102Mode)
|
||||
@@ -26,25 +26,30 @@ bool LedDeviceAdalight::init(const QJsonObject &deviceConfig)
|
||||
const unsigned int startFrameSize = 4;
|
||||
const unsigned int bytesPerRGBLed = 4;
|
||||
const unsigned int endFrameSize = std::max<unsigned int>(((_ledCount + 15) / 16), bytesPerRGBLed);
|
||||
bufferSize += (_ledCount * bytesPerRGBLed) + startFrameSize + endFrameSize ;
|
||||
_ledBuffer.resize(_headerSize + (_ledCount * bytesPerRGBLed) + startFrameSize + endFrameSize, 0x00);
|
||||
|
||||
// init constant data values
|
||||
for (signed iLed=1; iLed<=_ledCount; iLed++)
|
||||
{
|
||||
_ledBuffer[iLed*4+_headerSize] = 0xFF;
|
||||
}
|
||||
Debug( _log, "Adalight driver with activated LightBerry APA102 mode");
|
||||
}
|
||||
else
|
||||
{
|
||||
totalLedCount -= 1;
|
||||
bufferSize += _ledRGBCount;
|
||||
_ledBuffer.resize(_headerSize + _ledRGBCount, 0x00);
|
||||
}
|
||||
|
||||
_ledBuffer.resize(bufferSize, 0x00);
|
||||
_ledBuffer[0] = 'A';
|
||||
_ledBuffer[1] = 'd';
|
||||
_ledBuffer[2] = 'a';
|
||||
_ledBuffer[3] = (((unsigned int)(totalLedCount)) >> 8) & 0xFF; // LED count high byte
|
||||
_ledBuffer[4] = ((unsigned int)(totalLedCount)) & 0xFF; // LED count low byte
|
||||
_ledBuffer[3] = (totalLedCount >> 8) & 0xFF; // LED count high byte
|
||||
_ledBuffer[4] = totalLedCount & 0xFF; // LED count low byte
|
||||
_ledBuffer[5] = _ledBuffer[3] ^ _ledBuffer[4] ^ 0x55; // Checksum
|
||||
|
||||
Debug( _log, "Adalight header for %d leds: %c%c%c 0x%02x 0x%02x 0x%02x", _ledCount,
|
||||
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5]
|
||||
);
|
||||
_ledBuffer[0], _ledBuffer[1], _ledBuffer[2], _ledBuffer[3], _ledBuffer[4], _ledBuffer[5] );
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -56,15 +61,14 @@ int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
||||
for (signed iLed=1; iLed<=_ledCount; iLed++)
|
||||
{
|
||||
const ColorRgb& rgb = ledValues[iLed-1];
|
||||
_ledBuffer[iLed*4+6] = 0xFF;
|
||||
_ledBuffer[iLed*4+1+6] = rgb.red;
|
||||
_ledBuffer[iLed*4+2+6] = rgb.green;
|
||||
_ledBuffer[iLed*4+3+6] = rgb.blue;
|
||||
_ledBuffer[iLed*4+7] = rgb.red;
|
||||
_ledBuffer[iLed*4+8] = rgb.green;
|
||||
_ledBuffer[iLed*4+9] = rgb.blue;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
memcpy(6 + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
||||
memcpy(_headerSize + _ledBuffer.data(), ledValues.data(), ledValues.size() * 3);
|
||||
}
|
||||
|
||||
return writeBytes(_ledBuffer.size(), _ledBuffer.data());
|
||||
|
@@ -31,6 +31,7 @@ private:
|
||||
///
|
||||
virtual int write(const std::vector<ColorRgb> & ledValues);
|
||||
|
||||
const short _headerSize;
|
||||
bool _ligthBerryAPA102Mode;
|
||||
};
|
||||
|
||||
|
@@ -369,7 +369,9 @@ void LedDevicePhilipsHue::saveStates(unsigned int nLights)
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
// Error occured, break loop.
|
||||
Error(_log, "saveStates(nLights=%d): got invalid response from light %s.", nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str());
|
||||
Error(_log, "saveStates(nLights=%d): got invalid response from light %s. (error:%s, offset:%d)",
|
||||
nLights, getUrl(getRoute(lightIds.at(i))).toStdString().c_str(), error.errorString().toLocal8Bit().constData(), error.offset );
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -16,11 +16,11 @@ bool LedDeviceTpm2::init(const QJsonObject &deviceConfig)
|
||||
{
|
||||
ProviderRs232::init(deviceConfig);
|
||||
|
||||
_ledBuffer.resize(5 + 3*_ledCount);
|
||||
_ledBuffer.resize(5 + _ledRGBCount);
|
||||
_ledBuffer[0] = 0xC9; // block-start byte
|
||||
_ledBuffer[1] = 0xDA; // DATA frame
|
||||
_ledBuffer[2] = ((3 * _ledCount) >> 8) & 0xFF; // frame size high byte
|
||||
_ledBuffer[3] = (3 * _ledCount) & 0xFF; // frame size low byte
|
||||
_ledBuffer[2] = (_ledRGBCount >> 8) & 0xFF; // frame size high byte
|
||||
_ledBuffer[3] = _ledRGBCount & 0xFF; // frame size low byte
|
||||
_ledBuffer.back() = 0x36; // block-end byte
|
||||
|
||||
return true;
|
||||
|
@@ -17,7 +17,7 @@
|
||||
"delayAfterConnect": {
|
||||
"type": "integer",
|
||||
"title":"edt_dev_spec_delayAfterConnect_title",
|
||||
"default": 250,
|
||||
"default": 1500,
|
||||
"append" : "ms",
|
||||
"propertyOrder" : 3
|
||||
},
|
||||
|
Reference in New Issue
Block a user