Skip to content

Commit

Permalink
added identify to led layout right click
Browse files Browse the repository at this point in the history
  • Loading branch information
gibahjoe committed Jan 24, 2023
1 parent e9cbced commit a3da48e
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 20 deletions.
1 change: 1 addition & 0 deletions assets/webconfig/content/light_source.html
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ <h4 class="card-title"><i class="fa fa-search fa-fw"></i><span data-i18n="conf_l
<div class="dropdown-menu dropdown-menu-sm" style="display: none;" id="creator-context-menu">
<a class="dropdown-item" href="#" id="CMD_MOVE"><i class="fa fa-arrows fa-fw"></i><span data-i18n="led_editor_context_move">Move</span></a>
<a class="dropdown-item" href="#" id="CMD_PROPERTIES"><i class="fa fa-edit fa-fw"></i><span data-i18n="led_editor_context_properties">Properties</span></a>
<a class="dropdown-item" href="#" id="CMD_IDENTIFY"><i class="fa fa-eye-slash fa-fw"></i><span data-i18n="led_editor_context_identify">Identify</span></a>
<a class="dropdown-item" href="#" id="CMD_ENABLE"><i class="fa fa-lightbulb-o fa-fw"></i><span id="cmd_dis_enable_text" data-i18n="led_editor_context_enable">Enable</span></a>
<a class="dropdown-item" href="#" id="CMD_DELETE"><i class="fa fa-remove fa-fw"></i><span data-i18n="led_editor_context_delete">Delete</span></a>
</div>
Expand Down
1 change: 1 addition & 0 deletions assets/webconfig/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,7 @@
"led_editor_context_move": "Move",
"led_editor_context_properties": "Properties",
"led_editor_context_delete": "Delete",
"led_editor_context_identify": "Identify",
"led_editor_context_enable": "Enable",
"led_editor_context_disable": "Disable",
"led_editor_context_moving": "Left click the mouse to accept the position",
Expand Down
6 changes: 3 additions & 3 deletions assets/webconfig/js/hyperhdr.js
Original file line number Diff line number Diff line change
Expand Up @@ -447,10 +447,10 @@ function requestPlayEffect(effectName, duration)
{
sendToHyperhdr("effect", "", '"effect":{"name":"' + effectName + '"},"priority":' + window.webPrio + ',"duration":' + validateDuration(duration) + ',"origin":"' + window.webOrigin + '"');
}

function requestSetColor(r, g, b, duration)
function requestSetColor(r, g, b, duration,indexOfLed=-1)
{
sendToHyperhdr("color", "", '"color":[' + r + ',' + g + ',' + b + '], "priority":' + window.webPrio + ',"duration":' + validateDuration(duration) + ',"origin":"' + window.webOrigin + '"');
let msg=`"color":[${r},${g},${b}],"indexofled":${indexOfLed},"priority":${window.webPrio},"duration":${validateDuration(duration)},"origin":"${window.webOrigin}"`;
sendToHyperhdr("color", "", msg);
}

function requestSetImage(data, duration, name)
Expand Down
24 changes: 24 additions & 0 deletions assets/webconfig/js/light_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -1169,6 +1169,12 @@ $(document).ready(function()

selectedObject = null;
}
if (this.id == "CMD_IDENTIFY")
{
identify(parsedIndex);

selectedObject = null;
}
else if (this.id == "CMD_DELETE")
{
finalLedArray[parsedIndex] = undefined;
Expand Down Expand Up @@ -1362,3 +1368,21 @@ $(document).ready(function()
$("#leddevices").trigger("change");

});

function identify(index) {
// // clear current effect, should be called also on exit
requestPriorityClear();
// set color
setTimeout(function(){
// rgb and duration: 0 = inf.
requestSetColor(255, 0, 0,1,index);
setTimeout(function () {
requestSetColor(0, 255, 0,1,index);
},1000);
setTimeout(function () {
requestSetColor(0, 0, 255,1,index);
requestSetComponentState('LEDDEVICE',true);
},2000);
// turn on led device if disabled
}, 100);
}
3 changes: 2 additions & 1 deletion include/api/API.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,11 @@ class API : public QObject
/// @brief Set a single color
/// @param[in] priority The priority of the written color
/// @param[in] ledColor The color to write to the leds
/// @param[in] indexOfLed The index of the led or -1 to write to all
/// @param[in] timeout_ms The time the leds are set to the given color [ms]
/// @param[in] origin The setter
///
void setColor(int priority, const std::vector<uint8_t>& ledColors, int timeout_ms = -1, const QString& origin = "API", hyperhdr::Components callerComp = hyperhdr::COMP_INVALID);
void setColor(int priority, const std::vector<uint8_t>& ledColors,int indexOfLed=-1, int timeout_ms = -1, const QString& origin = "API", hyperhdr::Components callerComp = hyperhdr::COMP_INVALID);

///
/// @brief Set a image
Expand Down
3 changes: 2 additions & 1 deletion include/base/HyperHdrInstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,12 @@ public slots:
///
/// @param[in] priority The priority of the written color
/// @param[in] ledColors The color to write to the leds
/// @param[in] indexOfLed The index of the led or -1 to write to all
/// @param[in] timeout_ms The time the leds are set to the given color [ms]
/// @param[in] origin The setter
/// @param clearEffect Should be true when NOT called from an effect
///
void setColor(int priority, const std::vector<ColorRgb>& ledColors, int timeout_ms = -1, const QString& origin = "System", bool clearEffects = true);
void setColor(int priority, const std::vector<ColorRgb>& ledColors,int indexOfLed=-1, int timeout_ms = -1, const QString& origin = "System", bool clearEffects = true);

///
/// @brief Set the given priority to inactive
Expand Down
2 changes: 1 addition & 1 deletion include/proto-nano-server/ProtoNanoClientConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ProtoNanoClientConnection : public QObject
///
/// @brief Forward requested color
///
void setGlobalInputColor(int priority, const std::vector<ColorRgb> &ledColor, int timeout_ms, const QString& origin = "ProtoBuffer" ,bool clearEffects = true);
void setGlobalInputColor(int priority, const std::vector<ColorRgb> &ledColor,int indexOfLed = -1, int timeout_ms = -1, const QString& origin = "ProtoBuffer" ,bool clearEffects = true);

///
/// @brief Emits whenever the client disconnected
Expand Down
2 changes: 1 addition & 1 deletion include/utils/GlobalSignals.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class GlobalSignals : public QObject
/// @param[in] origin The setter
/// @param clearEffect Should be true when NOT called from an effect
///
void setGlobalColor(int priority, const std::vector<ColorRgb>& ledColor, int timeout_ms, const QString& origin = "External", bool clearEffects = true);
void setGlobalColor(int priority, const std::vector<ColorRgb>& ledColor,int indexOfLed = -1, int timeout_ms = -1, const QString& origin = "External", bool clearEffects = true);

///////////////////////////////////////
///////////////// FROM ////////////////
Expand Down
4 changes: 2 additions & 2 deletions sources/api/API.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void API::init()
}
}

void API::setColor(int priority, const std::vector<uint8_t>& ledColors, int timeout_ms, const QString& origin, hyperhdr::Components callerComp)
void API::setColor(int priority, const std::vector<uint8_t>& ledColors,int indexOfLed, int timeout_ms, const QString& origin, hyperhdr::Components callerComp)
{
std::vector<ColorRgb> fledColors;
if (ledColors.size() % 3 == 0)
Expand All @@ -105,7 +105,7 @@ void API::setColor(int priority, const std::vector<uint8_t>& ledColors, int time
{
fledColors.emplace_back(ColorRgb{ ledColors[i], ledColors[i + 1], ledColors[i + 2] });
}
QMetaObject::invokeMethod(_hyperhdr, "setColor", Qt::QueuedConnection, Q_ARG(int, priority), Q_ARG(std::vector<ColorRgb>, fledColors), Q_ARG(int, timeout_ms), Q_ARG(QString, origin));
QMetaObject::invokeMethod(_hyperhdr, "setColor", Qt::QueuedConnection, Q_ARG(int, priority), Q_ARG(std::vector<ColorRgb>, fledColors),Q_ARG(int,indexOfLed), Q_ARG(int, timeout_ms), Q_ARG(QString, origin));
}
}

Expand Down
4 changes: 4 additions & 0 deletions sources/api/JSONRPC_schema/schema-color.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
"maximum" : 253,
"required": true
},
"indexofled": {
"type": "integer",
"required": false
},
"duration": {
"type": "integer",
"required": false
Expand Down
3 changes: 2 additions & 1 deletion sources/api/JsonAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void JsonAPI::handleColorCommand(const QJsonObject& message, const QString& comm
emit forwardJsonMessage(message);
int priority = message["priority"].toInt();
int duration = message["duration"].toInt(-1);
int indexofled = message["indexofled"].toInt(-1);
const QString origin = message["origin"].toString("JsonRpc") + "@" + _peerAddress;

const QJsonArray& jsonColor = message["color"].toArray();
Expand All @@ -249,7 +250,7 @@ void JsonAPI::handleColorCommand(const QJsonObject& message, const QString& comm
colors.emplace_back(uint8_t(entry.toInt()));
}

API::setColor(priority, colors, duration, origin);
API::setColor(priority, colors,indexofled, duration, origin);
sendSuccessReply(command, tan);
}

Expand Down
18 changes: 10 additions & 8 deletions sources/base/HyperHdrInstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ bool HyperHdrInstance::setInputInactive(quint8 priority)
return _muxer.setInputInactive(priority);
}

void HyperHdrInstance::setColor(int priority, const std::vector<ColorRgb>& ledColors, int timeout_ms, const QString& origin, bool clearEffects)
void HyperHdrInstance::setColor(int priority, const std::vector<ColorRgb>& ledColors,int indexOfLed, int timeout_ms, const QString& origin, bool clearEffects)
{
if (ledColors.size() == 0)
return;
Expand All @@ -457,14 +457,16 @@ void HyperHdrInstance::setColor(int priority, const std::vector<ColorRgb>& ledCo
// create full led vector from single/multiple colors
std::vector<ColorRgb> newLedColors;
auto currentCol = ledColors.begin();
int itr=0;
for (const auto &item: _ledString.leds()){
if(itr==indexOfLed){
newLedColors.emplace_back(*currentCol);
} else{
newLedColors.emplace_back(ColorRgb::BLACK);
}
itr++;
}

while (newLedColors.size() < _ledString.leds().size())
{
newLedColors.emplace_back(*currentCol);

if (++currentCol == ledColors.end())
currentCol = ledColors.begin();
}

if (getPriorityInfo(priority).componentId != hyperhdr::COMP_COLOR)
{
Expand Down
2 changes: 1 addition & 1 deletion sources/flatbufserver/FlatBufferClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void FlatBufferClient::handleColorCommand(const hyperhdrnet::Color* colorReq)
std::vector<ColorRgb> color{ ColorRgb{ uint8_t(qRed(rgbData)), uint8_t(qGreen(rgbData)), uint8_t(qBlue(rgbData)) } };

// set output
emit setGlobalInputColor(_priority, color, colorReq->duration());
emit setGlobalInputColor(_priority, color,-1, colorReq->duration());

// send reply
sendSuccessReply();
Expand Down
2 changes: 1 addition & 1 deletion sources/flatbufserver/FlatBufferClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FlatBufferClient : public QObject
///
/// @brief Forward requested color
///
void setGlobalInputColor(int priority, const std::vector<ColorRgb>& ledColor, int timeout_ms, const QString& origin = "FlatBuffer", bool clearEffects = true);
void setGlobalInputColor(int priority, const std::vector<ColorRgb>& ledColor,int indexOfLed = -1, int timeout_ms = -1, const QString& origin = "FlatBuffer", bool clearEffects = true);

///
/// @brief Emits whenever the client disconnected
Expand Down

0 comments on commit a3da48e

Please sign in to comment.