diff --git a/README.md b/README.md index bb35102..fe07a6b 100644 --- a/README.md +++ b/README.md @@ -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); @@ -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 @@ -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. \ No newline at end of file +See COPYING to see the full text. diff --git a/exemple/sweep/sweep.ino b/example/sweep/sweep.ino similarity index 99% rename from exemple/sweep/sweep.ino rename to example/sweep/sweep.ino index f17dc65..a0934e9 100644 --- a/exemple/sweep/sweep.ino +++ b/example/sweep/sweep.ino @@ -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. -} \ No newline at end of file +} diff --git a/keywords.txt b/keywords.txt index a8e6276..265004c 100644 --- a/keywords.txt +++ b/keywords.txt @@ -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 \ No newline at end of file +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 diff --git a/viscalib.cpp b/viscalib.cpp index 5ccfd35..1a4a35c 100644 --- a/viscalib.cpp +++ b/viscalib.cpp @@ -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])); -} \ No newline at end of file +} + +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; + } + } +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/viscalib.h b/viscalib.h index f9ed1f8..2b3c4ed 100644 --- a/viscalib.h +++ b/viscalib.h @@ -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 \ No newline at end of file +#endif // VISCALIB_H