From 7d3bde27e412ebb6783c2c94f52a08f0e8d8ba49 Mon Sep 17 00:00:00 2001 From: cbdev Date: Sat, 19 Sep 2020 01:09:43 +0200 Subject: Fix VISCA channel parser --- backends/visca.c | 15 ++++++++------- backends/visca.h | 12 +++++++----- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/backends/visca.c b/backends/visca.c index 32f11c9..8465c14 100644 --- a/backends/visca.c +++ b/backends/visca.c @@ -110,8 +110,7 @@ static int ptz_instance(instance* inst){ } static channel* ptz_channel(instance* inst, char* spec, uint8_t flags){ - uint64_t ident = pan; - size_t command = 0; + uint64_t command = 0; if(flags & mmchannel_input){ LOG("This backend currently only supports output channels"); @@ -120,21 +119,23 @@ static channel* ptz_channel(instance* inst, char* spec, uint8_t flags){ for(command = 0; command < sentinel; command++){ if(!strncmp(spec, ptz_channels[command].name, strlen(ptz_channels[command].name))){ - ident = command; + break; } } - if(ident == sentinel){ + DBGPF("Matched spec %s as %s", spec, ptz_channels[command].name ? ptz_channels[command].name : "sentinel"); + + if(command == sentinel){ LOGPF("Unknown channel spec %s", spec); return NULL; } //store the memory to be called above the command type - if(ident == call || ident == store){ - ident |= (strtoul(spec + strlen(ptz_channels[ident].name), NULL, 10) << 8); + if(command == call || command == store){ + command |= (strtoul(spec + strlen(ptz_channels[command].name), NULL, 10) << 8); } - return mm_channel(inst, ident, 1); + return mm_channel(inst, command, 1); } static size_t ptz_set_pantilt(instance* inst, channel* c, channel_value* v, uint8_t* msg){ diff --git a/backends/visca.h b/backends/visca.h index 481f5c7..160398d 100644 --- a/backends/visca.h +++ b/backends/visca.h @@ -22,10 +22,12 @@ typedef struct /*_ptz_instance_data*/ { } ptz_instance_data; enum /*ptz_channels*/ { - pan = 0, - tilt, - panspeed, + //channels with a name that includes another channels as prefix + //go first so the channel matching logic works + panspeed = 0, tiltspeed, + pan, + tilt, zoom, focus, focus_mode, @@ -62,10 +64,10 @@ static struct { size_t offset; //channel value = normalised * range - offset ptz_channel_set set; } ptz_channels[] = { - [pan] = {"pan", 15, {0x80, 0x01, 0x06, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF}, 0, 0x990 * 2, 0x990, ptz_set_pantilt}, - [tilt] = {"tilt", 15, {0x80, 0x01, 0x06, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF}, 0, 0x510 * 2, 0x510, ptz_set_pantilt}, [panspeed] = {"panspeed", 0, {0}, 0x01, 0x18, 0, ptz_set_ptspeed}, [tiltspeed] = {"tiltspeed", 0, {0}, 0x01, 0x14, 0, ptz_set_ptspeed}, + [pan] = {"pan", 15, {0x80, 0x01, 0x06, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF}, 0, 0x990 * 2, 0x990, ptz_set_pantilt}, + [tilt] = {"tilt", 15, {0x80, 0x01, 0x06, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF}, 0, 0x510 * 2, 0x510, ptz_set_pantilt}, [zoom] = {"zoom", 9, {0x80, 0x01, 0x04, 0x47, 0, 0, 0, 0, 0xFF}, 0, 0x4000, 0, ptz_set_zoom}, [focus] = {"focus", 9, {0x80, 0x01, 0x04, 0x48, 0, 0, 0, 0, 0xFF}, 0, 0x4000, 0, ptz_set_focus}, [focus_mode] = {"autofocus", 6, {0x80, 0x01, 0x04, 0x38, 0, 0xFF}, 0, 1, 0, ptz_set_focus_mode}, -- cgit v1.2.3