aboutsummaryrefslogtreecommitdiffhomepage
path: root/backends/visca.h
blob: 09c9057e5c264543a0ef366ac770caeb0f9e9b3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "midimonster.h"

MM_PLUGIN_API int init();
static int ptz_configure(char* option, char* value);
static int ptz_configure_instance(instance* inst, char* option, char* value);
static int ptz_instance(instance* inst);
static channel* ptz_channel(instance* inst, char* spec, uint8_t flags);
static int ptz_set(instance* inst, size_t num, channel** c, channel_value* v);
static int ptz_handle(size_t num, managed_fd* fds);
static int ptz_start(size_t n, instance** inst);
static int ptz_shutdown(size_t n, instance** inst);

#define VISCA_BUFFER_LENGTH 50

typedef struct /*_ptz_instance_data*/ {
	int fd;
	uint8_t cam_address;
	uint16_t x;
	uint16_t y;
	uint8_t panspeed;
	uint8_t tiltspeed;
} ptz_instance_data;

enum /*ptz_channels*/ {
	pan = 0,
	tilt,
	panspeed,
	tiltspeed,
	zoom,
	focus,
	call,
	store,
	sentinel
};

typedef size_t (*ptz_channel_set)(instance*, channel*, channel_value*, uint8_t* msg);
static size_t ptz_set_pantilt(instance* inst, channel* c, channel_value* v, uint8_t* msg);
static size_t ptz_set_ptspeed(instance* inst, channel* c, channel_value* v, uint8_t* msg);
static size_t ptz_set_zoom(instance* inst, channel* c, channel_value* v, uint8_t* msg);
static size_t ptz_set_focus(instance* inst, channel* c, channel_value* v, uint8_t* msg);
static size_t ptz_set_memory(instance* inst, channel* c, channel_value* v, uint8_t* msg);
static size_t ptz_set_memory_store(instance* inst, channel* c, channel_value* v, uint8_t* msg);

static struct {
	char* name;
	size_t bytes;
	uint8_t pattern[VISCA_BUFFER_LENGTH];
	size_t min; //channel range = max - min
	size_t max;
	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},
	[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},
	[call] = {"memory", 7, {0x80, 0x01, 0x04, 0x3F, 0x02, 0, 0xFF}, 0, 254, 0, ptz_set_memory},
	[store] = {"store", 7, {0x80, 0x01, 0x04, 0x3F, 0x01, 0, 0xFF}, 0, 254, 0, ptz_set_memory_store}
};