mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Fix WLED & Smoothing (#1567)
* WLED - Fix empty segment element in DB * WLED - Fix to not overwrite on state when not isStayOnAfterStreaming * Refactor ProviderRestApi, increase default timeout * Fix Smoothing - Fix empty updates, consider smoothing configs for effects * UI - Fix not removed priority * Add missing header and code updates * setRedirectPolicy was only introduced in Qt 5.9 * Adalight - Align to HyperSerial v9.0.0 * HyperSerial Hyperion with awa protocol v8.0.0 * Correct line-endings
This commit is contained in:
@@ -523,7 +523,10 @@ bool LedDeviceWled::restoreState()
|
||||
|
||||
_originalStateProperties[STATE_LIVE] = false;
|
||||
_originalStateProperties[STATE_TRANSITIONTIME_CURRENTCALL] = 0;
|
||||
_originalStateProperties[STATE_ON] = _isStayOnAfterStreaming;
|
||||
if (_isStayOnAfterStreaming)
|
||||
{
|
||||
_originalStateProperties[STATE_ON] = true;
|
||||
}
|
||||
|
||||
httpResponse response = _restApi->put(_originalStateProperties);
|
||||
if ( response.error() )
|
||||
|
@@ -20,25 +20,34 @@ enum HttpStatusCode {
|
||||
NoContent = 204,
|
||||
BadRequest = 400,
|
||||
UnAuthorized = 401,
|
||||
Forbidden = 403,
|
||||
NotFound = 404
|
||||
};
|
||||
|
||||
constexpr std::chrono::milliseconds DEFAULT_REST_TIMEOUT{ 400 };
|
||||
|
||||
} //End of constants
|
||||
|
||||
ProviderRestApi::ProviderRestApi(const QString& host, int port, const QString& basePath)
|
||||
:_log(Logger::getInstance("LEDDEVICE"))
|
||||
, _networkManager(nullptr)
|
||||
ProviderRestApi::ProviderRestApi(const QString& scheme, const QString& host, int port, const QString& basePath)
|
||||
: _log(Logger::getInstance("LEDDEVICE"))
|
||||
, _networkManager(nullptr)
|
||||
, _requestTimeout(DEFAULT_REST_TIMEOUT)
|
||||
{
|
||||
_networkManager = new QNetworkAccessManager();
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 9, 0))
|
||||
_networkManager->setRedirectPolicy(QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
#endif
|
||||
|
||||
_apiUrl.setScheme("http");
|
||||
_apiUrl.setScheme(scheme);
|
||||
_apiUrl.setHost(host);
|
||||
_apiUrl.setPort(port);
|
||||
_basePath = basePath;
|
||||
}
|
||||
|
||||
ProviderRestApi::ProviderRestApi(const QString& scheme, const QString& host, int port)
|
||||
: ProviderRestApi(scheme, host, port, "") {}
|
||||
|
||||
ProviderRestApi::ProviderRestApi(const QString& host, int port, const QString& basePath)
|
||||
: ProviderRestApi("http", host, port, basePath) {}
|
||||
|
||||
ProviderRestApi::ProviderRestApi(const QString& host, int port)
|
||||
: ProviderRestApi(host, port, "") {}
|
||||
|
||||
@@ -62,6 +71,12 @@ void ProviderRestApi::setBasePath(const QString& basePath)
|
||||
appendPath(_basePath, basePath);
|
||||
}
|
||||
|
||||
void ProviderRestApi::setPath(const QStringList& pathElements)
|
||||
{
|
||||
_path.clear();
|
||||
appendPath(_path, pathElements.join(ONE_SLASH));
|
||||
}
|
||||
|
||||
void ProviderRestApi::setPath(const QString& path)
|
||||
{
|
||||
_path.clear();
|
||||
@@ -73,6 +88,11 @@ void ProviderRestApi::appendPath(const QString& path)
|
||||
appendPath(_path, path);
|
||||
}
|
||||
|
||||
void ProviderRestApi::appendPath(const QStringList& pathElements)
|
||||
{
|
||||
appendPath(_path, pathElements.join(ONE_SLASH));
|
||||
}
|
||||
|
||||
void ProviderRestApi::appendPath ( QString& path, const QString &appendPath)
|
||||
{
|
||||
if (!appendPath.isEmpty() && appendPath != ONE_SLASH)
|
||||
@@ -132,40 +152,7 @@ httpResponse ProviderRestApi::get()
|
||||
|
||||
httpResponse ProviderRestApi::get(const QUrl& url)
|
||||
{
|
||||
// Perform request
|
||||
QNetworkRequest request(_networkRequestHeaders);
|
||||
request.setUrl(url);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||
_networkManager->setTransferTimeout(DEFAULT_REST_TIMEOUT.count());
|
||||
#endif
|
||||
|
||||
QNetworkReply* reply = _networkManager->get(request);
|
||||
|
||||
// Connect requestFinished signal to quit slot of the loop.
|
||||
QEventLoop loop;
|
||||
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
ReplyTimeout::set(reply, DEFAULT_REST_TIMEOUT.count());
|
||||
#endif
|
||||
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
|
||||
httpResponse response;
|
||||
if (reply->operation() == QNetworkAccessManager::GetOperation)
|
||||
{
|
||||
if(reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
Debug(_log, "GET: [%s]", QSTRING_CSTR( url.toString() ));
|
||||
}
|
||||
response = getResponse(reply );
|
||||
}
|
||||
// Free space.
|
||||
reply->deleteLater();
|
||||
// Return response
|
||||
return response;
|
||||
return executeOperation(QNetworkAccessManager::GetOperation, url);
|
||||
}
|
||||
|
||||
httpResponse ProviderRestApi::put(const QJsonObject &body)
|
||||
@@ -180,40 +167,7 @@ httpResponse ProviderRestApi::put(const QString &body)
|
||||
|
||||
httpResponse ProviderRestApi::put(const QUrl &url, const QByteArray &body)
|
||||
{
|
||||
// Perform request
|
||||
QNetworkRequest request(_networkRequestHeaders);
|
||||
request.setUrl(url);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||
_networkManager->setTransferTimeout(DEFAULT_REST_TIMEOUT.count());
|
||||
#endif
|
||||
|
||||
QNetworkReply* reply = _networkManager->put(request, body);
|
||||
// Connect requestFinished signal to quit slot of the loop.
|
||||
QEventLoop loop;
|
||||
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
ReplyTimeout::set(reply, DEFAULT_REST_TIMEOUT.count());
|
||||
#endif
|
||||
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
|
||||
httpResponse response;
|
||||
if (reply->operation() == QNetworkAccessManager::PutOperation)
|
||||
{
|
||||
if(reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
Debug(_log, "PUT: [%s] [%s]", QSTRING_CSTR( url.toString() ),body.constData() );
|
||||
}
|
||||
response = getResponse(reply);
|
||||
}
|
||||
// Free space.
|
||||
reply->deleteLater();
|
||||
|
||||
// Return response
|
||||
return response;
|
||||
return executeOperation(QNetworkAccessManager::PutOperation, url, body);
|
||||
}
|
||||
|
||||
httpResponse ProviderRestApi::post(const QJsonObject& body)
|
||||
@@ -228,76 +182,69 @@ httpResponse ProviderRestApi::post(const QString& body)
|
||||
|
||||
httpResponse ProviderRestApi::post(const QUrl& url, const QByteArray& body)
|
||||
{
|
||||
// Perform request
|
||||
QNetworkRequest request(_networkRequestHeaders);
|
||||
request.setUrl(url);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||
_networkManager->setTransferTimeout(DEFAULT_REST_TIMEOUT.count());
|
||||
#endif
|
||||
|
||||
QNetworkReply* reply = _networkManager->post(request, body);
|
||||
// Connect requestFinished signal to quit slot of the loop.
|
||||
QEventLoop loop;
|
||||
QEventLoop::connect(reply,&QNetworkReply::finished,&loop,&QEventLoop::quit);
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
ReplyTimeout::set(reply, DEFAULT_REST_TIMEOUT.count());
|
||||
#endif
|
||||
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
|
||||
httpResponse response;
|
||||
if (reply->operation() == QNetworkAccessManager::PostOperation)
|
||||
{
|
||||
if(reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
Debug(_log, "POST: [%s] [%s]", QSTRING_CSTR( url.toString() ),body.constData() );
|
||||
}
|
||||
response = getResponse(reply);
|
||||
}
|
||||
// Free space.
|
||||
reply->deleteLater();
|
||||
|
||||
// Return response
|
||||
return response;
|
||||
return executeOperation(QNetworkAccessManager::PostOperation, url, body);
|
||||
}
|
||||
|
||||
httpResponse ProviderRestApi::deleteResource(const QUrl& url)
|
||||
{
|
||||
return executeOperation(QNetworkAccessManager::DeleteOperation, url);
|
||||
}
|
||||
|
||||
httpResponse ProviderRestApi::executeOperation(QNetworkAccessManager::Operation operation, const QUrl& url, const QByteArray& body)
|
||||
{
|
||||
// Perform request
|
||||
QNetworkRequest request(_networkRequestHeaders);
|
||||
request.setUrl(url);
|
||||
request.setOriginatingObject(this);
|
||||
|
||||
#if (QT_VERSION >= QT_VERSION_CHECK(5, 15, 0))
|
||||
_networkManager->setTransferTimeout(DEFAULT_REST_TIMEOUT.count());
|
||||
_networkManager->setTransferTimeout(_requestTimeout.count());
|
||||
#endif
|
||||
|
||||
QNetworkReply* reply = _networkManager->deleteResource(request);
|
||||
QDateTime start = QDateTime::currentDateTime();
|
||||
QString opCode;
|
||||
QNetworkReply* reply;
|
||||
switch (operation) {
|
||||
case QNetworkAccessManager::GetOperation:
|
||||
opCode = "GET";
|
||||
reply = _networkManager->get(request);
|
||||
break;
|
||||
case QNetworkAccessManager::PutOperation:
|
||||
opCode = "PUT";
|
||||
reply = _networkManager->put(request, body);
|
||||
break;
|
||||
case QNetworkAccessManager::PostOperation:
|
||||
opCode = "POST";
|
||||
reply = _networkManager->post(request, body);
|
||||
break;
|
||||
case QNetworkAccessManager::DeleteOperation:
|
||||
opCode = "DELETE";
|
||||
reply = _networkManager->deleteResource(request);
|
||||
break;
|
||||
default:
|
||||
Error(_log, "Unsupported operation");
|
||||
return httpResponse();
|
||||
}
|
||||
|
||||
// Connect requestFinished signal to quit slot of the loop.
|
||||
QEventLoop loop;
|
||||
QEventLoop::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit);
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
|
||||
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
|
||||
ReplyTimeout::set(reply, DEFAULT_REST_TIMEOUT.count());
|
||||
ReplyTimeout* timeout = ReplyTimeout::set(reply, _requestTimeout.count());
|
||||
#endif
|
||||
|
||||
httpResponse response;
|
||||
if (reply->operation() == QNetworkAccessManager::DeleteOperation)
|
||||
{
|
||||
if(reply->error() != QNetworkReply::NoError)
|
||||
{
|
||||
Debug(_log, "DELETE: [%s]", QSTRING_CSTR(url.toString()));
|
||||
}
|
||||
response = getResponse(reply);
|
||||
}
|
||||
// Go into the loop until the request is finished.
|
||||
loop.exec();
|
||||
QDateTime end = QDateTime::currentDateTime();
|
||||
|
||||
httpResponse response = (reply->operation() == operation) ? getResponse(reply) : httpResponse();
|
||||
|
||||
Debug(_log, "%s took %lldms, HTTP %d: [%s] [%s]", QSTRING_CSTR(opCode), start.msecsTo(end), response.getHttpStatusCode(), QSTRING_CSTR(url.toString()), body.constData());
|
||||
|
||||
// Free space.
|
||||
reply->deleteLater();
|
||||
|
||||
// Return response
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -311,34 +258,31 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
|
||||
|
||||
if (reply->error() == QNetworkReply::NoError)
|
||||
{
|
||||
if ( httpStatusCode != HttpStatusCode::NoContent ){
|
||||
QByteArray replyData = reply->readAll();
|
||||
QByteArray replyData = reply->readAll();
|
||||
|
||||
if (!replyData.isEmpty())
|
||||
if (!replyData.isEmpty())
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(replyData, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
QJsonParseError error;
|
||||
QJsonDocument jsonDoc = QJsonDocument::fromJson(replyData, &error);
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
//Received not valid JSON response
|
||||
response.setError(true);
|
||||
response.setErrorReason(error.errorString());
|
||||
}
|
||||
else
|
||||
{
|
||||
response.setBody(jsonDoc);
|
||||
}
|
||||
//Received not valid JSON response
|
||||
response.setError(true);
|
||||
response.setErrorReason(error.errorString());
|
||||
}
|
||||
else
|
||||
{ // Create valid body which is empty
|
||||
response.setBody(QJsonDocument());
|
||||
{
|
||||
response.setBody(jsonDoc);
|
||||
}
|
||||
}
|
||||
else
|
||||
{ // Create valid body which is empty
|
||||
response.setBody(QJsonDocument());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log, "Reply.httpStatusCode [%d]", httpStatusCode );
|
||||
QString errorReason;
|
||||
if (httpStatusCode > 0) {
|
||||
QString httpReason = reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute).toString();
|
||||
@@ -350,25 +294,32 @@ httpResponse ProviderRestApi::getResponse(QNetworkReply* const& reply)
|
||||
case HttpStatusCode::UnAuthorized:
|
||||
advise = "Check Authentication Token (API Key)";
|
||||
break;
|
||||
case HttpStatusCode::Forbidden:
|
||||
advise = "No permission to access the given resource";
|
||||
break;
|
||||
case HttpStatusCode::NotFound:
|
||||
advise = "Check Resource given";
|
||||
break;
|
||||
default:
|
||||
advise = httpReason;
|
||||
break;
|
||||
}
|
||||
errorReason = QString ("[%3 %4] - %5").arg(httpStatusCode).arg(httpReason, advise);
|
||||
}
|
||||
else
|
||||
{
|
||||
errorReason = reply->errorString();
|
||||
if (reply->error() == QNetworkReply::OperationCanceledError)
|
||||
{
|
||||
response.setError(true);
|
||||
response.setErrorReason(errorReason);
|
||||
errorReason = "Network request timeout error";
|
||||
}
|
||||
else
|
||||
{
|
||||
errorReason = reply->errorString();
|
||||
}
|
||||
}
|
||||
|
||||
// Create valid body which is empty
|
||||
response.setBody(QJsonDocument());
|
||||
}
|
||||
response.setError(true);
|
||||
response.setErrorReason(errorReason);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
@@ -388,3 +339,8 @@ void ProviderRestApi::setHeader(QNetworkRequest::KnownHeaders header, const QVar
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ProviderRestApi::setHeader(const QByteArray &headerName, const QByteArray &headerValue)
|
||||
{
|
||||
_networkRequestHeaders.setRawHeader(headerName, headerValue);
|
||||
}
|
||||
|
@@ -13,15 +13,22 @@
|
||||
#include <QBasicTimer>
|
||||
#include <QTimerEvent>
|
||||
|
||||
#include <chrono>
|
||||
|
||||
constexpr std::chrono::milliseconds DEFAULT_REST_TIMEOUT{ 1000 };
|
||||
|
||||
//Set QNetworkReply timeout without external timer
|
||||
//https://stackoverflow.com/questions/37444539/how-to-set-qnetworkreply-timeout-without-external-timer
|
||||
|
||||
class ReplyTimeout : public QObject {
|
||||
class ReplyTimeout : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum HandleMethod { Abort, Close };
|
||||
|
||||
ReplyTimeout(QNetworkReply* reply, const int timeout, HandleMethod method = Abort) :
|
||||
QObject(reply), m_method(method)
|
||||
QObject(reply), m_method(method), m_timedout(false)
|
||||
{
|
||||
Q_ASSERT(reply);
|
||||
if (reply && reply->isRunning()) {
|
||||
@@ -29,20 +36,30 @@ public:
|
||||
connect(reply, &QNetworkReply::finished, this, &QObject::deleteLater);
|
||||
}
|
||||
}
|
||||
static void set(QNetworkReply* reply, const int timeout, HandleMethod method = Abort)
|
||||
|
||||
bool isTimedout() const
|
||||
{
|
||||
new ReplyTimeout(reply, timeout, method);
|
||||
return m_timedout;
|
||||
}
|
||||
|
||||
static ReplyTimeout * set(QNetworkReply* reply, const int timeout, HandleMethod method = Abort)
|
||||
{
|
||||
return new ReplyTimeout(reply, timeout, method);
|
||||
}
|
||||
|
||||
signals:
|
||||
void timedout();
|
||||
|
||||
protected:
|
||||
QBasicTimer m_timer;
|
||||
HandleMethod m_method;
|
||||
|
||||
void timerEvent(QTimerEvent * ev) override {
|
||||
if (!m_timer.isActive() || ev->timerId() != m_timer.timerId())
|
||||
return;
|
||||
auto reply = static_cast<QNetworkReply*>(parent());
|
||||
if (reply->isRunning())
|
||||
{
|
||||
m_timedout = true;
|
||||
emit timedout();
|
||||
if (m_method == Close)
|
||||
reply->close();
|
||||
else if (m_method == Abort)
|
||||
@@ -50,6 +67,10 @@ protected:
|
||||
m_timer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
QBasicTimer m_timer;
|
||||
HandleMethod m_method;
|
||||
bool m_timedout;
|
||||
};
|
||||
|
||||
///
|
||||
@@ -104,11 +125,12 @@ private:
|
||||
///
|
||||
///@endcode
|
||||
///
|
||||
class ProviderRestApi
|
||||
class ProviderRestApi : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
///
|
||||
/// @brief Constructor of the REST-API wrapper
|
||||
///
|
||||
ProviderRestApi();
|
||||
@@ -121,6 +143,15 @@ public:
|
||||
///
|
||||
explicit ProviderRestApi(const QString& host, int port);
|
||||
|
||||
///
|
||||
/// @brief Constructor of the REST-API wrapper
|
||||
///
|
||||
/// @param[in] scheme
|
||||
/// @param[in] host
|
||||
/// @param[in] port
|
||||
///
|
||||
explicit ProviderRestApi(const QString& scheme, const QString& host, int port);
|
||||
|
||||
///
|
||||
/// @brief Constructor of the REST-API wrapper
|
||||
///
|
||||
@@ -130,10 +161,20 @@ public:
|
||||
///
|
||||
explicit ProviderRestApi(const QString& host, int port, const QString& basePath);
|
||||
|
||||
///
|
||||
/// @brief Constructor of the REST-API wrapper
|
||||
///
|
||||
/// @param[in] scheme
|
||||
/// @param[in] host
|
||||
/// @param[in] port
|
||||
/// @param[in] API base-path
|
||||
///
|
||||
explicit ProviderRestApi(const QString& scheme, const QString& host, int port, const QString& basePath);
|
||||
|
||||
///
|
||||
/// @brief Destructor of the REST-API wrapper
|
||||
///
|
||||
virtual ~ProviderRestApi();
|
||||
virtual ~ProviderRestApi() override;
|
||||
|
||||
///
|
||||
/// @brief Set an API's host
|
||||
@@ -177,6 +218,12 @@ public:
|
||||
///
|
||||
void setPath(const QString& path);
|
||||
|
||||
/// @brief Set an API's path to address resources
|
||||
///
|
||||
/// @param[in] pathElements to form a path, e.g. (lights,1,state) results in "/lights/1/state/"
|
||||
///
|
||||
void setPath(const QStringList& pathElements);
|
||||
|
||||
///
|
||||
/// @brief Append an API's path element to path set before
|
||||
///
|
||||
@@ -184,6 +231,13 @@ public:
|
||||
///
|
||||
void appendPath(const QString& appendPath);
|
||||
|
||||
///
|
||||
/// @brief Append API's path elements to path set before
|
||||
///
|
||||
/// @param[in] pathElements
|
||||
///
|
||||
void appendPath(const QStringList& pathElements);
|
||||
|
||||
///
|
||||
/// @brief Set an API's fragment
|
||||
///
|
||||
@@ -283,14 +337,28 @@ public:
|
||||
/// @param[in] The type of the header field.
|
||||
/// @param[in] The value of the header field.
|
||||
/// If the header field exists, the value will be combined as comma separated string.
|
||||
|
||||
void setHeader(QNetworkRequest::KnownHeaders header, const QVariant& value);
|
||||
|
||||
///
|
||||
/// Set a header field.
|
||||
///
|
||||
/// @param[in] The type of the header field.
|
||||
/// @param[in] The value of the header field.
|
||||
/// If the header field exists, the value will override the previous setting.
|
||||
void setHeader(const QByteArray &headerName, const QByteArray &headerValue);
|
||||
|
||||
///
|
||||
/// Remove all header fields.
|
||||
///
|
||||
void removeAllHeaders() { _networkRequestHeaders = QNetworkRequest(); }
|
||||
|
||||
///
|
||||
/// Sets the timeout time frame after a request is aborted
|
||||
/// Zero means no timer is set.
|
||||
///
|
||||
/// @param[in] timeout in milliseconds.
|
||||
void setTransferTimeout(std::chrono::milliseconds timeout = DEFAULT_REST_TIMEOUT) { _requestTimeout = timeout; }
|
||||
|
||||
///
|
||||
/// @brief Set the common logger for LED-devices.
|
||||
///
|
||||
@@ -308,10 +376,14 @@ private:
|
||||
///
|
||||
static void appendPath (QString &path, const QString &appendPath) ;
|
||||
|
||||
|
||||
httpResponse executeOperation(QNetworkAccessManager::Operation op, const QUrl& url, const QByteArray& body = {});
|
||||
|
||||
Logger* _log;
|
||||
|
||||
// QNetworkAccessManager object for sending REST-requests.
|
||||
QNetworkAccessManager* _networkManager;
|
||||
std::chrono::milliseconds _requestTimeout;
|
||||
|
||||
QUrl _apiUrl;
|
||||
|
||||
|
@@ -94,7 +94,7 @@ void LedDeviceAdalight::prepareHeader()
|
||||
break;
|
||||
|
||||
case Adalight::AWA:
|
||||
_bufferLength += 7;
|
||||
_bufferLength += 8;
|
||||
[[fallthrough]];
|
||||
case Adalight::ADA:
|
||||
[[fallthrough]];
|
||||
@@ -162,14 +162,20 @@ int LedDeviceAdalight::write(const std::vector<ColorRgb> & ledValues)
|
||||
{
|
||||
whiteChannelExtension(writer);
|
||||
|
||||
uint16_t fletcher1 = 0, fletcher2 = 0;
|
||||
uint16_t fletcher1 = 0;
|
||||
uint16_t fletcher2 = 0;
|
||||
uint16_t fletcherExt = 0;
|
||||
uint8_t position = 0;
|
||||
|
||||
while (hasher < writer)
|
||||
{
|
||||
fletcherExt = (fletcherExt + (*(hasher) ^ (position++))) % 255;
|
||||
fletcher1 = (fletcher1 + *(hasher++)) % 255;
|
||||
fletcher2 = (fletcher2 + fletcher1) % 255;
|
||||
}
|
||||
*(writer++) = static_cast<uint8_t>(fletcher1);
|
||||
*(writer++) = static_cast<uint8_t>(fletcher2);
|
||||
*(writer++) = static_cast<uint8_t>((fletcherExt != 0x41) ? fletcherExt : 0xaa);
|
||||
}
|
||||
_bufferLength = writer - _ledBuffer.data();
|
||||
}
|
||||
|
Reference in New Issue
Block a user