From 454e757f740b74d714e9fa47bfa4954cb30e67ba Mon Sep 17 00:00:00 2001 From: cbdev Date: Fri, 28 Feb 2020 21:10:45 +0100 Subject: Implement openpixelcontrol 16bit server mode --- backends/openpixelcontrol.c | 35 ++++++++++++++++++++++++++++++++--- backends/openpixelcontrol.md | 2 -- 2 files changed, 32 insertions(+), 5 deletions(-) (limited to 'backends') diff --git a/backends/openpixelcontrol.c b/backends/openpixelcontrol.c index 0f590c6..62cdb68 100644 --- a/backends/openpixelcontrol.c +++ b/backends/openpixelcontrol.c @@ -385,9 +385,38 @@ static ssize_t openpixel_client_pixeldata(instance* inst, openpixel_client* clie return u; } else{ - //TODO byte-order conversion may be on recv boundary - //if over buffer length, ignore - //skip non-multiple-of 6 trailing data + for(u = 0; u < bytes_left; u++){ + //if over buffer length, ignore + if(u + client->offset >= data->buffer[client->buffer].bytes){ + client->buffer = -2; + break; + } + + //if at start of trailing non-multiple of 6, ignore + if((client->offset + u) >= (client->offset + client->left) - ((client->offset + client->left) % 6)){ + client->buffer = -2; + break; + } + + //byte-order conversion may be on message boundary, do it via a buffer + client->boundary.u8[(client->offset + u) % 2] = buffer[u]; + + //detect and update changed channels + if((client->offset + u) % 2 + && data->buffer[client->buffer].data.u16[(u + client->offset) / 2] != be16toh(client->boundary.u16)){ + data->buffer[client->buffer].data.u16[(u + client->offset) / 2] = be16toh(client->boundary.u16); + chan = mm_channel(inst, ((uint64_t) client->hdr.strip << 32) | ((u + client->offset) / 2 + 1), 0); + if(chan){ + //push event + val.raw.u64 = be16toh(client->boundary.u16);; + val.normalised = (double) val.raw.u64 / 65535.0; + if(mm_channel_event(chan, val)){ + LOG("Failed to push channel event to core"); + } + } + + } + } } } return -1; diff --git a/backends/openpixelcontrol.md b/backends/openpixelcontrol.md index 6dd38bc..5a8686f 100644 --- a/backends/openpixelcontrol.md +++ b/backends/openpixelcontrol.md @@ -50,5 +50,3 @@ This behaviour may be changed in future releases. While acting as an OpenPixelControl server, the backend allows multiple clients to connect. This may lead to confusing data output when multiple clients are trying to control the same strip. - -16 bit server mode is not implemented yet. This will be fixed in a future release. -- cgit v1.2.3