Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
ViscaLib is an Arduino library that allows you to control Visca-compatible PTZ cameras.
[![GPLv3 License](https://img.shields.io/badge/License-GPL%20v3-yellow.svg)](https://opensource.org/licenses/)

This is a fork of the library, originally created by Unix5. I(Omnia et Nihil), created this fork to add additional functions. I have only used this library with a PTZOptics Move SE camera.

## How it work ?
This is not a complete VISCA library. It only covers some of the more commonly used functions.

## How does it work ?

This library generates [Visca](https://en.wikipedia.org/wiki/VISCA_Protocol) commands from predefined functions. For example, if you call PAN_TILT_UP(5);

Expand All @@ -16,6 +19,7 @@ It will send the following command to the chosen serial interface:
```

⚠️ **I only tested it on Sony Ipela SNC-RX550** ⚠️
Also tested with PTZOptics Move SE.

## Installation

Expand Down Expand Up @@ -66,14 +70,24 @@ void loop() {
| `PAN_TILT_SLOW_MODE(x)` | `x: True / False` |
| `PAN_TILT_ABSOLUTE_POSITION(s, x, y)` | `s = speed value 1 to 18 ; x = Pan value -8160 to 8160 ; y = Tilt value -2040 to 2040` |
| `PAN_TILT_RELATIVE_POSITION(s, x, y)` | `s = speed value 1 to 18 ; x = Pan value -8160 to 8160 ; y = Tilt value -2040 to 2040` |
| `ZOOM_TELE_STANDARD()` | `none`|
| `ZOOM_WIDE_STANDARD()` | `none` |
| `ZOOM_TELE_VARIABLE(s)` | `s = speed value 1 to 7` |
| `ZOOM_WIDE_VARIABLE(s)` | `s = speed value 1 to 7` |
| `ZOOM_STOP()` | `none` |
| `ZOOM_DIRECT(z)` | `z = zoom position 0 to 16384` |
| `QUERY_PAN_POSITION()` | `none` |
| `QUERY_TILT_POSITION()` | `none` |
| `QUERY_ZOOM()` | `none` |

## Authors

- [Unix5](https://unix5.net)
- [Omnia Et Nihil](https://www.youtube.com/@omnia8838)


## License

GNU General Public License v3.0 or later

See COPYING to see the full text.
See COPYING to see the full text.
2 changes: 1 addition & 1 deletion exemple/sweep/sweep.ino → example/sweep/sweep.ino
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ void loop() {

myVisca.PAN_TILT_RIGHT(5); // Send a PAN_TILT_RIGHT command with a speed of 5 (adjust speed as needed).
delay(1000); // Wait 1 second.
}
}
11 changes: 10 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,13 @@ PAN_TILT_RESET KEYWORD2
PAN_TILT_RAMP_CURVE KEYWORD2
PAN_TILT_SLOW_MODE KEYWORD2
PAN_TILT_ABSOLUTE_POSITION KEYWORD2
PAN_TILT_RELATIVE_POSITION KEYWORD2
PAN_TILT_RELATIVE_POSITION KEYWORD2
ZOOM_TELE_STANDARD KEYWORD2
ZOOM_WIDE_STANDARD KEYWORD2
ZOOM_TELE_VARIABLE KEYWORD2
ZOOM_WIDE_VARIABLE KEYWORD2
ZOOM_STOP KEYWORD2
ZOOM_DIRECT KEYWORD2
QUERY_PAN_POSITION KEYWORD2
QUERY_TILT_POSITION KEYWORD2
QUERY_ZOOM KEYWORD2
169 changes: 168 additions & 1 deletion viscalib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,171 @@ void ViscaLib::PAN_TILT_RELATIVE_POSITION(byte speed, int panPosition, int tiltP
list[12] = signedtiltPosition_byte2 & 0x0F;

sendList(list, sizeof(list) / sizeof(list[0]));
}
}

void ViscaLib::ZOOM_TELE_STANDARD(){
byte list[4] = {0x01, 0x04, 0x07, 0x02};
sendList(list, sizeof(list) / sizeof(list[0]));
}

void ViscaLib::ZOOM_WIDE_STANDARD(){
byte list[4] = {0x01, 0x04, 0x07, 0x03};
sendList(list, sizeof(list) / sizeof(list[0]));
}

void ViscaLib::ZOOM_TELE_VARIABLE(byte speed){
speed = constrain(speed, 0, 7);
byte list[4] = {0x01, 0x04, 0x07, 0x00};
list[3] = 0x20 + speed;
sendList(list, sizeof(list) / sizeof(list[0]));
}

void ViscaLib::ZOOM_WIDE_VARIABLE(byte speed){
speed = constrain(speed, 0, 7);
byte list[4] = {0x01, 0x04, 0x07, 0x00};
list[3] = 0x30 + speed;
sendList(list, sizeof(list) / sizeof(list[0]));
}

void ViscaLib::ZOOM_STOP(){
byte list[4] = {0x01, 0x04, 0x07, 0x00};
sendList(list, sizeof(list) / sizeof(list[0]));
}

void ViscaLib::ZOOM_DIRECT(unsigned int zoomPosition){
zoomPosition = constrain(zoomPosition, 0, 0x4000);
byte list[7] = {0x01, 0x04, 0x47, 0x00, 0x00, 0x00, 0x00};
list[3] = (zoomPosition & 0xF000) >> 12;
list[4] = (zoomPosition & 0x0F00) >> 8;
list[5] = (zoomPosition & 0x00F0) >> 4;
list[6] = (zoomPosition & 0x000F);

sendList(list, sizeof(list) / sizeof(list[0]));
}

int ViscaLib::QUERY_PAN_POSITION(){
while(_serial.available()){
_serial.read();
}
byte list[3] = {0x09, 0x06, 0x12};
unsigned long startTime = millis();
byte currentByte;
byte dataStream[10];
int val;
sendList(list, sizeof(list) / sizeof(list[0]));
while(!_serial.available()){
if(millis() - startTime > 1000){
return 0xffff;
}
}
while(currentByte != 0xff){
if(_serial.available()){
currentByte = _serial.read();
if(currentByte == 0xff){
val = dataStream[5] | (dataStream[4] << 4) | (dataStream[3] << 8) | (dataStream[2] << 12);
return val;
}else{
for(int i = 0; i < 9; i++){
dataStream[i] = dataStream[i + 1];
}
dataStream[9] = currentByte;
}
}else if(millis() - startTime > 2000){
return 0xffff;
}
}
}

int ViscaLib::QUERY_TILT_POSITION(){
while(_serial.available()){
_serial.read();
}
byte list[3] = {0x09, 0x06, 0x12};
unsigned long startTime = millis();
byte currentByte;
byte dataStream[10];
int val;
sendList(list, sizeof(list) / sizeof(list[0]));
while(!_serial.available()){
if(millis() - startTime > 1000){
return 0xffff;
}
}
while(currentByte != 0xff){
if(_serial.available()){
currentByte = _serial.read();
if(currentByte == 0xff){
val = dataStream[9] | (dataStream[8] << 4) | (dataStream[7] << 8) | (dataStream[6] << 12);
return val;
}else{
for(int i = 0; i < 9; i++){
dataStream[i] = dataStream[i + 1];
}
dataStream[9] = currentByte;
}
}else if(millis() - startTime > 2000){
return 0xffff;
}
}
}

unsigned int ViscaLib::QUERY_ZOOM(){
while(_serial.available()){
_serial.read();
}
byte list[3] = {0x09, 0x04, 0x47};
unsigned long startTime = millis();
byte currentByte;
byte dataStream[4];
unsigned int val;
sendList(list, sizeof(list) / sizeof(list[0]));
while(!_serial.available()){
if(millis() - startTime > 1000){
return 0xffff;
}
}
while(currentByte != 0xff){
if(_serial.available()){
currentByte = _serial.read();
if(currentByte == 0xff){
val = dataStream[3] + 0x10 * dataStream[2] + 0x100 * dataStream[1] + 0x1000 * dataStream[0];
return val;
}else if (currentByte < 0x10){
for(int i = 0; i < 3; i++){
dataStream[i] = dataStream[i + 1];
}
dataStream[3] = currentByte;
}
}else if(millis() - startTime > 2000){
return 0xffff;
}
}
}




























13 changes: 11 additions & 2 deletions viscalib.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,19 @@ class ViscaLib {
void PAN_TILT_SLOW_MODE(bool enable);
void PAN_TILT_ABSOLUTE_POSITION(byte speed, int panPosition, int tiltPosition);
void PAN_TILT_RELATIVE_POSITION(byte speed, int panPosition, int tiltPosition);

void ZOOM_TELE_STANDARD();
void ZOOM_WIDE_STANDARD();
void ZOOM_TELE_VARIABLE(byte speed);
void ZOOM_WIDE_VARIABLE(byte speed);
void ZOOM_STOP();
void ZOOM_DIRECT(unsigned int zoomPosition);
int QUERY_PAN_POSITION();
int QUERY_TILT_POSITION();
unsigned int QUERY_ZOOM();

private:
Stream& _serial;
void sendList(byte list[], size_t listsize);
};

#endif // VISCALIB_H
#endif // VISCALIB_H