Skip to content

Commit da294c0

Browse files
awawa-devchbartsch
authored andcommitted
Fix: web LED live simulator doesn't update (awawa-dev#337)
1 parent f36e430 commit da294c0

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

include/api/JsonAPI.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ private slots:
9090
///
9191
void handleInstanceStateChange(InstanceState state, quint8 instance, const QString& name = QString());
9292

93+
void handleLedColorsIncoming(const std::vector<ColorRgb>& ledValues);
94+
95+
void handleLedColorsTimer();
96+
9397
signals:
9498
///
9599
/// Signal emits with the reply message provided with handleMessage()
@@ -122,8 +126,8 @@ private slots:
122126
/// timer for led color refresh
123127
QTimer* _ledStreamTimer;
124128

125-
/// led stream connection handle
126-
QMetaObject::Connection _ledStreamConnection;
129+
/// led stream refresh interval
130+
qint64 _colorsStreamingInterval;
127131

128132
/// the current streaming led values
129133
std::vector<ColorRgb> _currentLedValues;

sources/api/JsonAPI.cpp

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ JsonAPI::JsonAPI(QString peerAddress, Logger* log, bool localConnection, QObject
6161
_streaming_logging_activated = false;
6262
_ledStreamTimer = new QTimer(this);
6363
_lastSendImage = InternalClock::now();
64+
_colorsStreamingInterval = 50;
65+
66+
connect(_ledStreamTimer, &QTimer::timeout, this, &JsonAPI::handleLedColorsTimer, Qt::UniqueConnection);
6467

6568
Q_INIT_RESOURCE(JSONRPC_schemas);
6669
}
@@ -1165,44 +1168,45 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject& message, const QStr
11651168
sendSuccessReply(command, tan);
11661169
}
11671170

1171+
void JsonAPI::handleLedColorsIncoming(const std::vector<ColorRgb>& ledValues)
1172+
{
1173+
_currentLedValues = ledValues;
1174+
1175+
if (_ledStreamTimer->interval() != _colorsStreamingInterval)
1176+
_ledStreamTimer->start(_colorsStreamingInterval);
1177+
}
1178+
1179+
void JsonAPI::handleLedColorsTimer()
1180+
{
1181+
emit streamLedcolorsUpdate(_currentLedValues);
1182+
}
1183+
11681184
void JsonAPI::handleLedColorsCommand(const QJsonObject& message, const QString& command, int tan)
11691185
{
11701186
// create result
11711187
QString subcommand = message["subcommand"].toString("");
11721188

11731189
// max 20 Hz (50ms) interval for streaming (default: 10 Hz (100ms))
1174-
qint64 streaming_interval = qMax(message["interval"].toInt(100), 50);
1190+
_colorsStreamingInterval = qMax(message["interval"].toInt(100), 50);
11751191

11761192
if (subcommand == "ledstream-start")
11771193
{
11781194
_streaming_leds_reply["success"] = true;
11791195
_streaming_leds_reply["command"] = command + "-ledstream-update";
11801196
_streaming_leds_reply["tan"] = tan;
11811197

1182-
connect(_hyperhdr, &HyperHdrInstance::rawLedColors, this, [=](const std::vector<ColorRgb>& ledValues) {
1183-
_currentLedValues = ledValues;
1184-
1185-
// necessary because Qt::UniqueConnection for lambdas does not work until 5.9
1186-
// see: https://bugreports.qt.io/browse/QTBUG-52438
1187-
if (!_ledStreamConnection)
1188-
_ledStreamConnection = connect(_ledStreamTimer, &QTimer::timeout, this, [=]() {
1189-
emit streamLedcolorsUpdate(_currentLedValues);
1190-
},
1191-
Qt::UniqueConnection);
1192-
1193-
// start the timer
1194-
if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != streaming_interval)
1195-
_ledStreamTimer->start(streaming_interval);
1196-
},
1197-
Qt::UniqueConnection);
1198+
connect(_hyperhdr, &HyperHdrInstance::rawLedColors, this, &JsonAPI::handleLedColorsIncoming, Qt::UniqueConnection);
1199+
1200+
if (!_ledStreamTimer->isActive() || _ledStreamTimer->interval() != _colorsStreamingInterval)
1201+
_ledStreamTimer->start(_colorsStreamingInterval);
1202+
11981203
// push once
11991204
QMetaObject::invokeMethod(_hyperhdr, "update");
12001205
}
12011206
else if (subcommand == "ledstream-stop")
12021207
{
12031208
disconnect(_hyperhdr, &HyperHdrInstance::rawLedColors, this, 0);
12041209
_ledStreamTimer->stop();
1205-
disconnect(_ledStreamConnection);
12061210
}
12071211
else if (subcommand == "imagestream-start")
12081212
{
@@ -1877,7 +1881,6 @@ void JsonAPI::stopDataConnections()
18771881
// led stream colors
18781882
disconnect(_hyperhdr, &HyperHdrInstance::rawLedColors, this, 0);
18791883
_ledStreamTimer->stop();
1880-
disconnect(_ledStreamConnection);
18811884
}
18821885

18831886
void JsonAPI::handleTunnel(const QJsonObject& message, const QString& command, int tan)

0 commit comments

Comments
 (0)