mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2023-10-10 13:36:59 +02:00
Make the Json server more flexible for set color commands. Commands can now contain multiple colors which are repeated over the entire string
Former-commit-id: e763f574a8d481a2d21e764d9b9ef2bfd6f1723a
This commit is contained in:
parent
83051543d2
commit
cf7f66bc40
@ -114,10 +114,33 @@ void JsonClientConnection::handleColorCommand(const Json::Value &message)
|
|||||||
// extract parameters
|
// extract parameters
|
||||||
int priority = message["priority"].asInt();
|
int priority = message["priority"].asInt();
|
||||||
int duration = message.get("duration", -1).asInt();
|
int duration = message.get("duration", -1).asInt();
|
||||||
ColorRgb color = {uint8_t(message["color"][0u].asInt()), uint8_t(message["color"][1u].asInt()), uint8_t(message["color"][2u].asInt())};
|
|
||||||
|
std::vector<ColorRgb> colorData(_hyperion->getLedCount());
|
||||||
|
const Json::Value & jsonColor = message["color"];
|
||||||
|
Json::UInt i = 0;
|
||||||
|
for (; i < jsonColor.size()/3 && i < _hyperion->getLedCount(); ++i)
|
||||||
|
{
|
||||||
|
colorData[i].red = uint8_t(message["color"][3u*i].asInt());
|
||||||
|
colorData[i].green = uint8_t(message["color"][3u*i+1u].asInt());
|
||||||
|
colorData[i].blue = uint8_t(message["color"][3u*i+2u].asInt());
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy full blocks of led colors
|
||||||
|
unsigned size = i;
|
||||||
|
while (i + size < _hyperion->getLedCount())
|
||||||
|
{
|
||||||
|
memcpy(&(colorData[i]), colorData.data(), size * sizeof(ColorRgb));
|
||||||
|
i += size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy remaining block of led colors
|
||||||
|
if (i < _hyperion->getLedCount())
|
||||||
|
{
|
||||||
|
memcpy(&(colorData[i]), colorData.data(), (_hyperion->getLedCount()-i) * sizeof(ColorRgb));
|
||||||
|
}
|
||||||
|
|
||||||
// set output
|
// set output
|
||||||
_hyperion->setColor(priority, color, duration);
|
_hyperion->setColors(priority, colorData, duration);
|
||||||
|
|
||||||
// send reply
|
// send reply
|
||||||
sendSuccessReply();
|
sendSuccessReply();
|
||||||
|
@ -21,8 +21,7 @@
|
|||||||
"items" :{
|
"items" :{
|
||||||
"type" : "integer"
|
"type" : "integer"
|
||||||
},
|
},
|
||||||
"minItems": 3,
|
"minItems": 3
|
||||||
"maxItems": 3
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"additionalProperties": false
|
"additionalProperties": false
|
||||||
|
Loading…
Reference in New Issue
Block a user