14
14
#include < QByteArray>
15
15
#include < QDateTime>
16
16
#include < QHostInfo>
17
+ #include < QMutexLocker>
17
18
18
19
// hyperion includes
19
20
#include < utils/jsonschema/QJsonFactory.h>
@@ -55,9 +56,6 @@ JsonAPI::JsonAPI(QString peerAddress, Logger* log, QObject* parent, bool noListe
55
56
56
57
// notify hyperion about a jsonMessageForward
57
58
connect (this , &JsonAPI::forwardJsonMessage, _hyperion, &Hyperion::forwardJsonMessage);
58
-
59
- _image_stream_mutex.unlock ();
60
- _led_stream_mutex.unlock ();
61
59
}
62
60
63
61
void JsonAPI::handleMessage (const QString& messageString)
@@ -475,10 +473,10 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject& message, const QString&
475
473
// BEGIN | The following entries are derecated but used to ensure backward compatibility with hyperion Classic remote control
476
474
// TODO Output the real transformation information instead of default
477
475
478
- // host name
476
+ // HOST NAME
479
477
info[" hostname" ] = QHostInfo::localHostName ();
480
478
481
- // transform information (default values )
479
+ // TRANSFORM INFORMATION (DEFAULT VALUES )
482
480
QJsonArray transformArray;
483
481
for (const QString& transformId : _hyperion->getAdjustmentIds ())
484
482
{
@@ -507,9 +505,66 @@ void JsonAPI::handleServerInfoCommand(const QJsonObject& message, const QString&
507
505
508
506
transformArray.append (transform);
509
507
}
510
-
511
508
info[" transform" ] = transformArray;
512
509
510
+ // ACTIVE EFFECT INFO
511
+ QJsonArray activeEffects;
512
+ const std::list<ActiveEffectDefinition> & activeEffectsDefinitions = _hyperion->getActiveEffects ();
513
+ for (const ActiveEffectDefinition & activeEffectDefinition : activeEffectsDefinitions)
514
+ {
515
+ if (activeEffectDefinition.priority != PriorityMuxer::LOWEST_PRIORITY -1 )
516
+ {
517
+ QJsonObject activeEffect;
518
+ activeEffect[" script" ] = activeEffectDefinition.script ;
519
+ activeEffect[" name" ] = activeEffectDefinition.name ;
520
+ activeEffect[" priority" ] = activeEffectDefinition.priority ;
521
+ activeEffect[" timeout" ] = activeEffectDefinition.timeout ;
522
+ activeEffect[" args" ] = activeEffectDefinition.args ;
523
+ activeEffects.append (activeEffect);
524
+ }
525
+ }
526
+ info[" activeEffects" ] = activeEffects;
527
+
528
+ // ACTIVE STATIC LED COLOR
529
+ QJsonArray activeLedColors;
530
+ const Hyperion::InputInfo & priorityInfo = _hyperion->getPriorityInfo (_hyperion->getCurrentPriority ());
531
+ if (priorityInfo.componentId == hyperion::COMP_COLOR && !priorityInfo.ledColors .empty ())
532
+ {
533
+ QJsonObject LEDcolor;
534
+ // check if LED Color not Black (0,0,0)
535
+ if ((priorityInfo.ledColors .begin ()->red +
536
+ priorityInfo.ledColors .begin ()->green +
537
+ priorityInfo.ledColors .begin ()->blue != 0 ))
538
+ {
539
+ QJsonObject LEDcolor;
540
+
541
+ // add RGB Value to Array
542
+ QJsonArray RGBValue;
543
+ RGBValue.append (priorityInfo.ledColors .begin ()->red );
544
+ RGBValue.append (priorityInfo.ledColors .begin ()->green );
545
+ RGBValue.append (priorityInfo.ledColors .begin ()->blue );
546
+ LEDcolor.insert (" RGB Value" , RGBValue);
547
+
548
+ uint16_t Hue;
549
+ float Saturation, Luminace;
550
+
551
+ // add HSL Value to Array
552
+ QJsonArray HSLValue;
553
+ ColorSys::rgb2hsl (priorityInfo.ledColors .begin ()->red ,
554
+ priorityInfo.ledColors .begin ()->green ,
555
+ priorityInfo.ledColors .begin ()->blue ,
556
+ Hue, Saturation, Luminace);
557
+
558
+ HSLValue.append (Hue);
559
+ HSLValue.append (Saturation);
560
+ HSLValue.append (Luminace);
561
+ LEDcolor.insert (" HSL Value" , HSLValue);
562
+
563
+ activeLedColors.append (LEDcolor);
564
+ }
565
+ }
566
+ info[" activeLedColor" ] = activeLedColors;
567
+
513
568
// END
514
569
515
570
sendSuccessDataReply (QJsonDocument (info), command, tan );
@@ -952,7 +1007,8 @@ void JsonAPI::sendErrorReply(const QString &error, const QString &command, const
952
1007
953
1008
void JsonAPI::streamLedcolorsUpdate (const std::vector<ColorRgb>& ledColors)
954
1009
{
955
- if ( (_led_stream_timeout+100 ) < QDateTime::currentMSecsSinceEpoch () && _led_stream_mutex.tryLock (0 ) )
1010
+ QMutexLocker lock (&_led_stream_mutex);
1011
+ if ( (_led_stream_timeout+100 ) < QDateTime::currentMSecsSinceEpoch () )
956
1012
{
957
1013
_led_stream_timeout = QDateTime::currentMSecsSinceEpoch ();
958
1014
QJsonObject result;
@@ -973,14 +1029,13 @@ void JsonAPI::streamLedcolorsUpdate(const std::vector<ColorRgb>& ledColors)
973
1029
974
1030
// send the result
975
1031
emit callbackMessage (_streaming_leds_reply);
976
-
977
- _led_stream_mutex.unlock ();
978
1032
}
979
1033
}
980
1034
981
1035
void JsonAPI::setImage (const Image<ColorRgb> & image)
982
1036
{
983
- if ( (_image_stream_timeout+100 ) < QDateTime::currentMSecsSinceEpoch () && _image_stream_mutex.tryLock (0 ) )
1037
+ QMutexLocker lock (&_image_stream_mutex);
1038
+ if ( (_image_stream_timeout+100 ) < QDateTime::currentMSecsSinceEpoch () )
984
1039
{
985
1040
_image_stream_timeout = QDateTime::currentMSecsSinceEpoch ();
986
1041
@@ -994,8 +1049,6 @@ void JsonAPI::setImage(const Image<ColorRgb> & image)
994
1049
result[" image" ] = " data:image/jpg;base64," +QString (ba.toBase64 ());
995
1050
_streaming_image_reply[" result" ] = result;
996
1051
emit callbackMessage (_streaming_image_reply);
997
-
998
- _image_stream_mutex.unlock ();
999
1052
}
1000
1053
}
1001
1054
0 commit comments