@@ -61,6 +61,9 @@ JsonAPI::JsonAPI(QString peerAddress, Logger* log, bool localConnection, QObject
61
61
_streaming_logging_activated = false ;
62
62
_ledStreamTimer = new QTimer (this );
63
63
_lastSendImage = InternalClock::now ();
64
+ _colorsStreamingInterval = 50 ;
65
+
66
+ connect (_ledStreamTimer, &QTimer::timeout, this , &JsonAPI::handleLedColorsTimer, Qt::UniqueConnection);
64
67
65
68
Q_INIT_RESOURCE (JSONRPC_schemas);
66
69
}
@@ -1165,44 +1168,45 @@ void JsonAPI::handleComponentStateCommand(const QJsonObject& message, const QStr
1165
1168
sendSuccessReply (command, tan);
1166
1169
}
1167
1170
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
+
1168
1184
void JsonAPI::handleLedColorsCommand (const QJsonObject& message, const QString& command, int tan)
1169
1185
{
1170
1186
// create result
1171
1187
QString subcommand = message[" subcommand" ].toString (" " );
1172
1188
1173
1189
// 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 );
1175
1191
1176
1192
if (subcommand == " ledstream-start" )
1177
1193
{
1178
1194
_streaming_leds_reply[" success" ] = true ;
1179
1195
_streaming_leds_reply[" command" ] = command + " -ledstream-update" ;
1180
1196
_streaming_leds_reply[" tan" ] = tan;
1181
1197
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
+
1198
1203
// push once
1199
1204
QMetaObject::invokeMethod (_hyperhdr, " update" );
1200
1205
}
1201
1206
else if (subcommand == " ledstream-stop" )
1202
1207
{
1203
1208
disconnect (_hyperhdr, &HyperHdrInstance::rawLedColors, this , 0 );
1204
1209
_ledStreamTimer->stop ();
1205
- disconnect (_ledStreamConnection);
1206
1210
}
1207
1211
else if (subcommand == " imagestream-start" )
1208
1212
{
@@ -1877,7 +1881,6 @@ void JsonAPI::stopDataConnections()
1877
1881
// led stream colors
1878
1882
disconnect (_hyperhdr, &HyperHdrInstance::rawLedColors, this , 0 );
1879
1883
_ledStreamTimer->stop ();
1880
- disconnect (_ledStreamConnection);
1881
1884
}
1882
1885
1883
1886
void JsonAPI::handleTunnel (const QJsonObject& message, const QString& command, int tan)
0 commit comments