Fix logger and led colors (#906)

This commit is contained in:
Murat Seker 2020-07-27 20:00:36 +02:00 committed by GitHub
parent 773b47bf53
commit d4b4158cb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 69 additions and 41 deletions

View File

@ -1,7 +1,8 @@
var conf_editor = null; var conf_editor = null;
var createdCont = false; var createdCont = false;
performTranslation();
requestLoggingStart(); performTranslation();
requestLoggingStart();
$(document).ready(function() { $(document).ready(function() {
var messages; var messages;
@ -160,7 +161,8 @@ $(document).ready(function() {
toggleClass('#btn_autoscroll', "btn-success", "btn-danger"); toggleClass('#btn_autoscroll', "btn-success", "btn-danger");
}); });
} }
for(var idx=0; idx<messages.length; idx++)
for(var idx = 0; idx < messages.length; idx++)
{ {
var app_name = messages[idx].appName; var app_name = messages[idx].appName;
var logger_name = messages[idx].loggerName; var logger_name = messages[idx].loggerName;
@ -169,17 +171,21 @@ $(document).ready(function() {
var file_name = messages[idx].fileName; var file_name = messages[idx].fileName;
var msg = messages[idx].message; var msg = messages[idx].message;
var level_string = messages[idx].levelString; var level_string = messages[idx].levelString;
var utime = messages[idx].utime;
var debug = ""; var debug = "";
if(level_string == "DEBUG") { if(level_string == "DEBUG") {
debug = "("+file_name+":"+line+":"+function_+"()) "; debug = "("+file_name+":"+line+":"+function_+"()) ";
} }
$("#logmessages").append("\n <code>"+"["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"</code>"); var date = new Date(parseInt(utime));
$("#logmessages").append("\n <code>"+date.toISOString()+" ["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"</code>");
loguplmess += "["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"\n"; loguplmess += "["+app_name+" "+logger_name+"] ("+level_string+") "+debug+msg+"\n";
} }
if($("#btn_autoscroll").hasClass('btn-success')){
if($("#btn_autoscroll").hasClass('btn-success'))
{
$('#logmessages').stop().animate({ $('#logmessages').stop().animate({
scrollTop: $('#logmessages')[0].scrollHeight scrollTop: $('#logmessages')[0].scrollHeight
}, 800); }, 800);

View File

@ -165,9 +165,9 @@ public:
/// ///
/// @param[out] image The image that buffers the output /// @param[out] image The image that buffers the output
/// ///
void toRgb(Image<ColorRgb>& image) void toRgb(Image<ColorRgb>& image) const
{ {
_d_ptr->toRgb(*(image.imageData())); _d_ptr->toRgb(*image._d_ptr);
} }
/// ///
@ -186,12 +186,10 @@ public:
_d_ptr->clear(); _d_ptr->clear();
} }
QSharedDataPointer<ImageData<Pixel_T>> imageData() const
{
return _d_ptr;
}
private: private:
template<class T>
friend class Image;
/// ///
/// Translate x and y coordinate to index of the underlying vector /// Translate x and y coordinate to index of the underlying vector
/// ///

View File

@ -134,7 +134,7 @@ public:
return _pixels; return _pixels;
} }
void toRgb(ImageData<ColorRgb>& image) void toRgb(ImageData<ColorRgb>& image) const
{ {
if (image.width() != _width || image.height() != _height) if (image.width() != _width || image.height() != _height)
image.resize(_width, _height); image.resize(_width, _height);

View File

@ -79,7 +79,7 @@ protected:
~Logger(); ~Logger();
private: private:
void write(const Logger::T_LOG_MESSAGE & message) const; void write(const Logger::T_LOG_MESSAGE & message);
static QMutex MapLock; static QMutex MapLock;
static QMap<QString,Logger*> LoggerMap; static QMap<QString,Logger*> LoggerMap;
@ -106,7 +106,7 @@ public slots:
void handleNewLogMessage(const Logger::T_LOG_MESSAGE&); void handleNewLogMessage(const Logger::T_LOG_MESSAGE&);
signals: signals:
void newLogMessage(Logger::T_LOG_MESSAGE); void newLogMessage(const Logger::T_LOG_MESSAGE&);
protected: protected:
LoggerManager(); LoggerManager();

View File

@ -1053,7 +1053,7 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co
if (!_streaming_logging_activated) if (!_streaming_logging_activated)
{ {
_streaming_logging_reply["command"] = command + "-update"; _streaming_logging_reply["command"] = command + "-update";
connect(LoggerManager::getInstance(), SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, SLOT(incommingLogMessage(Logger::T_LOG_MESSAGE))); connect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage);
Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); // needed to trigger log sending Debug(_log, "log streaming activated for client %s", _peerAddress.toStdString().c_str()); // needed to trigger log sending
} }
} }
@ -1061,7 +1061,7 @@ void JsonAPI::handleLoggingCommand(const QJsonObject &message, const QString &co
{ {
if (_streaming_logging_activated) if (_streaming_logging_activated)
{ {
disconnect(LoggerManager::getInstance(), SIGNAL(newLogMessage(Logger::T_LOG_MESSAGE)), this, 0); disconnect(LoggerManager::getInstance(), &LoggerManager::newLogMessage, this, &JsonAPI::incommingLogMessage);
_streaming_logging_activated = false; _streaming_logging_activated = false;
Debug(_log, "log streaming deactivated for client %s", _peerAddress.toStdString().c_str()); Debug(_log, "log streaming deactivated for client %s", _peerAddress.toStdString().c_str());
} }
@ -1561,6 +1561,7 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg)
message["fileName"] = logBuffer->at(i).fileName; message["fileName"] = logBuffer->at(i).fileName;
message["message"] = logBuffer->at(i).message; message["message"] = logBuffer->at(i).message;
message["levelString"] = logBuffer->at(i).levelString; message["levelString"] = logBuffer->at(i).levelString;
message["utime"] = QString::number(logBuffer->at(i).utime);
messageArray.append(message); messageArray.append(message);
} }
@ -1574,6 +1575,7 @@ void JsonAPI::incommingLogMessage(const Logger::T_LOG_MESSAGE &msg)
message["fileName"] = msg.fileName; message["fileName"] = msg.fileName;
message["message"] = msg.message; message["message"] = msg.message;
message["levelString"] = msg.levelString; message["levelString"] = msg.levelString;
message["utime"] = QString::number(msg.utime);
messageArray.append(message); messageArray.append(message);
} }

View File

@ -379,8 +379,18 @@ void Hyperion::setColor(const int priority, const std::vector<ColorRgb> &ledColo
_effectEngine->channelCleared(priority); _effectEngine->channelCleared(priority);
// create full led vector from single/multiple colors // create full led vector from single/multiple colors
size_t size = _ledString.leds().size();
std::vector<ColorRgb> newLedColors; std::vector<ColorRgb> newLedColors;
std::copy_n(ledColors.begin(), _ledString.leds().size(), std::back_inserter(newLedColors)); while (true)
{
for (const auto &entry : ledColors)
{
newLedColors.emplace_back(entry);
if (newLedColors.size() == size)
goto end;
}
}
end:
if (getPriorityInfo(priority).componentId != hyperion::COMP_COLOR) if (getPriorityInfo(priority).componentId != hyperion::COMP_COLOR)
clear(priority); clear(priority);

View File

@ -243,9 +243,10 @@ QJsonObject LedDeviceWled::getProperties(const QJsonObject& params)
return properties; return properties;
} }
void LedDeviceWled::identify(const QJsonObject& params) void LedDeviceWled::identify(const QJsonObject& /*params*/)
{ {
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData() ); #if 0
Debug(_log, "params: [%s]", QString(QJsonDocument(params).toJson(QJsonDocument::Compact)).toUtf8().constData());
QJsonObject properties; QJsonObject properties;
// Get Nanoleaf device properties // Get Nanoleaf device properties
@ -281,6 +282,7 @@ void LedDeviceWled::identify(const QJsonObject& params)
// Warning (_log, "%s identification failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason())); // Warning (_log, "%s identification failed with error: '%s'", QSTRING_CSTR(_activeDeviceType), QSTRING_CSTR(response.getErrorReason()));
// } // }
} }
#endif
} }
int LedDeviceWled::write(const std::vector<ColorRgb> &ledValues) int LedDeviceWled::write(const std::vector<ColorRgb> &ledValues)

View File

@ -9,6 +9,10 @@
#include <QNetworkInterface> #include <QNetworkInterface>
#include <QNetworkConfigurationManager> #include <QNetworkConfigurationManager>
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#include <QRandomGenerator>
#endif
static const QString SSDP_HYPERION_ST("urn:hyperion-project.org:device:basic:1"); static const QString SSDP_HYPERION_ST("urn:hyperion-project.org:device:basic:1");
SSDPHandler::SSDPHandler(WebServer* webserver, const quint16& flatBufPort, const quint16& jsonServerPort, const QString& name, QObject * parent) SSDPHandler::SSDPHandler(WebServer* webserver, const quint16& flatBufPort, const quint16& jsonServerPort, const QString& name, QObject * parent)
@ -162,7 +166,11 @@ void SSDPHandler::handleMSearchRequest(const QString& target, const QString& mx,
if (ok) if (ok)
{ {
/* Pick a random delay between 0 and MX seconds */ /* Pick a random delay between 0 and MX seconds */
#if (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
int randomDelay = QRandomGenerator::global()->generate() % (maxDelay * 1000);
#else
int randomDelay = qrand() % (maxDelay * 1000); int randomDelay = qrand() % (maxDelay * 1000);
#endif
QTimer::singleShot(randomDelay, respond); QTimer::singleShot(randomDelay, respond);
} }
else else

View File

@ -155,7 +155,7 @@ Logger::~Logger()
} }
} }
void Logger::write(const Logger::T_LOG_MESSAGE & message) const void Logger::write(const Logger::T_LOG_MESSAGE & message)
{ {
QString location; QString location;
if (message.level == Logger::DEBUG) if (message.level == Logger::DEBUG)
@ -179,6 +179,8 @@ void Logger::write(const Logger::T_LOG_MESSAGE & message) const
.arg(message.message) .arg(message.message)
.toStdString() .toStdString()
<< std::endl; << std::endl;
newLogMessage(message);
} }
void Logger::Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...) void Logger::Message(LogLevel level, const char* sourceFile, const char* func, unsigned int line, const char* fmt, ...)