-
Notifications
You must be signed in to change notification settings - Fork 0
/
viscalib.cpp
142 lines (110 loc) · 4.62 KB
/
viscalib.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#include "viscalib.h"
ViscaLib::ViscaLib(Stream& serialPort) : _serial(serialPort) {
}
void ViscaLib::sendList(byte list[], size_t listsize) {
_serial.write(0x81);
//_serial.print(0x81, HEX);
for (size_t i = 0; i < listsize; i++) {
_serial.write(list[i]);
//_serial.print(" ");
//_serial.print(list[i], HEX);
}
_serial.write(0xFF);
//_serial.println(0xFF, HEX);
}
void ViscaLib::IF_Clear() {
byte list[3] = {0x01, 0x00, 0x01};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_UP(byte speed) {
byte list[7] = {0x01, 0x06, 0x01, speed, speed, 0x03, 0x01};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_DOWN(byte speed) {
byte list[7] = {0x01, 0x06, 0x01, speed, speed, 0x03, 0x02};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_LEFT(byte speed) {
byte list[7] = {0x01, 0x06, 0x01, speed, speed, 0x01, 0x03};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_RIGHT(byte speed) {
byte list[7] = {0x01, 0x06, 0x01, speed, speed, 0x02, 0x03};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_UP_LEFT(byte panSpeed, byte tiltSpeed) {
byte list[7] = {0x01, 0x06, 0x01, panSpeed, tiltSpeed, 0x01, 0x01};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_UP_RIGHT(byte panSpeed, byte tiltSpeed) {
byte list[7] = {0x01, 0x06, 0x01, panSpeed, tiltSpeed, 0x02, 0x01};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_DOWN_LEFT(byte panSpeed, byte tiltSpeed) {
byte list[7] = {0x01, 0x06, 0x01, panSpeed, tiltSpeed, 0x01, 0x02};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_DOWN_RIGHT(byte panSpeed, byte tiltSpeed) {
byte list[7] = {0x01, 0x06, 0x01, panSpeed, tiltSpeed, 0x02, 0x02};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_STOP(byte panSpeed, byte tiltSpeed) {
// Commande pour arrêter le mouvement PAN/TILT
byte list[7] = {0x01, 0x06, 0x01, panSpeed, tiltSpeed, 0x03, 0x03};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_HOME() {
byte list[3] = {0x01, 0x06, 0x04};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_RESET() {
byte list[3] = {0x01, 0x06, 0x05};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_RAMP_CURVE(byte rampCurve) {
byte list[] = {0x01, 0x06, 0x31, rampCurve};
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_SLOW_MODE(bool enable) {
byte list[] = {0x01, 0x06, 0x44, 0x03};
if (enable) {
list[3] = 0x02;
}
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_ABSOLUTE_POSITION(byte speed, int panPosition, int tiltPosition) {
byte list[13] = {0x01, 0x06, 0x02, speed, speed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int16_t signedpanPosition = constrain(panPosition, -8160, 8160);
uint8_t signedpanPosition_byte1 = (signedpanPosition >> 8) & 0xFF;
uint8_t signedpanPosition_byte2 = signedpanPosition & 0xFF;
list[5] = signedpanPosition_byte1 >> 4;
list[6] = signedpanPosition_byte1 & 0x0F;
list[7] = signedpanPosition_byte2 >> 4;
list[8] = signedpanPosition_byte2 & 0x0F;
int16_t signedtiltPosition = constrain(tiltPosition, -2040, 2040);
uint8_t signedtiltPosition_byte1 = (signedtiltPosition >> 8) & 0xFF;
uint8_t signedtiltPosition_byte2 = signedtiltPosition & 0xFF;
list[9] = signedtiltPosition_byte1 >> 4;
list[10] = signedtiltPosition_byte1 & 0x0F;
list[11] = signedtiltPosition_byte2 >> 4;
list[12] = signedtiltPosition_byte2 & 0x0F;
sendList(list, sizeof(list) / sizeof(list[0]));
}
void ViscaLib::PAN_TILT_RELATIVE_POSITION(byte speed, int panPosition, int tiltPosition) {
byte list[13] = {0x01, 0x06, 0x03, speed, speed, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int16_t signedpanPosition = constrain(panPosition, -8160, 8160);
uint8_t signedpanPosition_byte1 = (signedpanPosition >> 8) & 0xFF;
uint8_t signedpanPosition_byte2 = signedpanPosition & 0xFF;
list[5] = signedpanPosition_byte1 >> 4;
list[6] = signedpanPosition_byte1 & 0x0F;
list[7] = signedpanPosition_byte2 >> 4;
list[8] = signedpanPosition_byte2 & 0x0F;
int16_t signedtiltPosition = constrain(tiltPosition, -2040, 2040);
uint8_t signedtiltPosition_byte1 = (signedtiltPosition >> 8) & 0xFF;
uint8_t signedtiltPosition_byte2 = signedtiltPosition & 0xFF;
list[9] = signedtiltPosition_byte1 >> 4;
list[10] = signedtiltPosition_byte1 & 0x0F;
list[11] = signedtiltPosition_byte2 >> 4;
list[12] = signedtiltPosition_byte2 & 0x0F;
sendList(list, sizeof(list) / sizeof(list[0]));
}