Browse Source

Successful build of Visca shield & more testing of control code.

extract-visca-communication-to-class
Ed Walker 5 years ago
parent
commit
dcd83544f9
4 changed files with 180 additions and 129 deletions
  1. +38
    -51
      EAGLE/VISCAShield.brd
  2. +0
    -66
      EAGLE/VISCAShield.sch
  3. +11
    -3
      visca-controller/visca-controller.h
  4. +131
    -9
      visca-controller/visca-controller.ino

+ 38
- 51
EAGLE/VISCAShield.brd View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE eagle SYSTEM "eagle.dtd">
<eagle version="9.4.2">
<eagle version="9.6.2">
<drawing>
<settings>
<setting alwaysvectorfont="no"/>
@ -158,8 +158,6 @@ for Cisco
TelePresence
PrecisionHD</text>
<text x="52.07" y="16.51" size="1.016" layer="25" rot="R270" align="top-left">Rev 1.1</text>
<text x="41.91" y="49.53" size="1.778" layer="25" align="bottom-center">- ~ +</text>
<text x="41.91" y="38.1" size="1.778" layer="25" align="bottom-center">- ~ +</text>
<text x="41.91" y="26.67" size="1.778" layer="25" align="bottom-center">- ~ +</text>
<text x="45.72" y="1.27" size="1.778" layer="25" align="bottom-center">- ~ +</text>
<text x="38.1" y="1.27" size="1.778" layer="25" align="bottom-center">- ~ +</text>
@ -1025,24 +1023,6 @@ Note, that not all DRC settings must be set by the manufacturer. Several can be
<attribute name="POPULARITY" value="35" x="41.91" y="31.75" size="1.778" layer="27" display="off"/>
<attribute name="VALUE" x="38.1" y="26.67" size="1.016" layer="27" ratio="10" display="off"/>
</element>
<element name="AUX2" library="con-molex" library_urn="urn:adsk.eagle:library:165" package="22-23-2031" package3d_urn="urn:adsk.eagle:package:8078634/1" value="22-23-2031" x="41.91" y="43.18" smashed="yes">
<attribute name="MF" value="MOLEX" x="41.91" y="43.18" size="1.778" layer="27" display="off"/>
<attribute name="MPN" value="22-23-2031" x="41.91" y="43.18" size="1.778" layer="27" display="off"/>
<attribute name="NAME" x="38.1" y="46.99" size="1.016" layer="25" ratio="10"/>
<attribute name="OC_FARNELL" value="1462950" x="41.91" y="43.18" size="1.778" layer="27" display="off"/>
<attribute name="OC_NEWARK" value="30C0862" x="41.91" y="43.18" size="1.778" layer="27" display="off"/>
<attribute name="POPULARITY" value="35" x="41.91" y="43.18" size="1.778" layer="27" display="off"/>
<attribute name="VALUE" x="38.1" y="38.1" size="1.016" layer="27" ratio="10" display="off"/>
</element>
<element name="AUX3" library="con-molex" library_urn="urn:adsk.eagle:library:165" package="22-23-2031" package3d_urn="urn:adsk.eagle:package:8078634/1" value="22-23-2031" x="41.91" y="54.61" smashed="yes">
<attribute name="MF" value="MOLEX" x="41.91" y="54.61" size="1.778" layer="27" display="off"/>
<attribute name="MPN" value="22-23-2031" x="41.91" y="54.61" size="1.778" layer="27" display="off"/>
<attribute name="NAME" x="38.1" y="58.42" size="1.016" layer="25" ratio="10"/>
<attribute name="OC_FARNELL" value="1462950" x="41.91" y="54.61" size="1.778" layer="27" display="off"/>
<attribute name="OC_NEWARK" value="30C0862" x="41.91" y="54.61" size="1.778" layer="27" display="off"/>
<attribute name="POPULARITY" value="35" x="41.91" y="54.61" size="1.778" layer="27" display="off"/>
<attribute name="VALUE" x="38.1" y="49.53" size="1.016" layer="27" ratio="10" display="off"/>
</element>
<element name="I2C" library="con-molex" library_urn="urn:adsk.eagle:library:165" package="22-23-2041" package3d_urn="urn:adsk.eagle:package:8078635/1" value="22-23-2041" x="20.32" y="10.16" smashed="yes">
<attribute name="MF" value="MOLEX" x="20.32" y="10.16" size="1.778" layer="27" display="off"/>
<attribute name="MPN" value="22-23-2041" x="20.32" y="10.16" size="1.778" layer="27" display="off"/>
@ -1130,8 +1110,6 @@ Note, that not all DRC settings must be set by the manufacturer. Several can be
<contactref element="TILT" pad="1"/>
<contactref element="ZOOM" pad="1"/>
<contactref element="AUX1" pad="1"/>
<contactref element="AUX2" pad="1"/>
<contactref element="AUX3" pad="1"/>
<contactref element="EXT5V" pad="1"/>
<contactref element="I2C" pad="1"/>
<contactref element="U1" pad="15"/>
@ -1155,6 +1133,33 @@ Note, that not all DRC settings must be set by the manufacturer. Several can be
</polygon>
<contactref element="U1" pad="10"/>
<contactref element="U1" pad="8"/>
<wire x1="25.41" y1="56.64" x2="30.48" y2="58.42" width="0" layer="19" extent="1-1"/>
<wire x1="16.51" y1="58.79" x2="25.41" y2="56.64" width="0" layer="19" extent="1-1"/>
<wire x1="14.23" y1="59.055" x2="16.51" y2="58.79" width="0" layer="19" extent="1-1"/>
<wire x1="8.63" y1="57.785" x2="14.23" y2="59.055" width="0" layer="19" extent="1-1"/>
<wire x1="8.63" y1="51.435" x2="8.63" y2="57.785" width="0" layer="19" extent="1-1"/>
<wire x1="6.72" y1="48.26" x2="8.63" y2="51.435" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="44.45" x2="6.72" y2="48.26" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="41.91" x2="10.16" y2="44.45" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="39.37" x2="10.16" y2="41.91" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="36.83" x2="10.16" y2="39.37" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="33.02" x2="10.16" y2="36.83" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="30.48" x2="10.16" y2="33.02" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="27.94" x2="10.16" y2="30.48" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="25.4" x2="10.16" y2="27.94" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="22.86" x2="10.16" y2="25.4" width="0" layer="19" extent="1-1"/>
<wire x1="10.16" y1="20.32" x2="10.16" y2="22.86" width="0" layer="19" extent="1-1"/>
<wire x1="2.54" y1="17.78" x2="10.16" y2="20.32" width="0" layer="19" extent="1-1"/>
<wire x1="17.41" y1="48.26" x2="10.16" y2="44.45" width="0" layer="19" extent="1-1"/>
<wire x1="25.4" y1="45.72" x2="17.41" y2="48.26" width="0" layer="19" extent="1-1"/>
<wire x1="16.51" y1="10.16" x2="10.16" y2="20.32" width="0" layer="19" extent="1-1"/>
<wire x1="27.94" y1="6.35" x2="16.51" y2="10.16" width="0" layer="19" extent="1-1"/>
<wire x1="35.56" y1="6.35" x2="27.94" y2="6.35" width="0" layer="19" extent="1-1"/>
<wire x1="43.18" y1="6.35" x2="35.56" y2="6.35" width="0" layer="19" extent="1-1"/>
<wire x1="31.75" y1="19.05" x2="27.94" y2="6.35" width="0" layer="19" extent="1-1"/>
<wire x1="39.37" y1="31.75" x2="31.75" y2="19.05" width="0" layer="19" extent="1-1"/>
<wire x1="50.8" y1="31.75" x2="39.37" y2="31.75" width="0" layer="19" extent="1-1"/>
<wire x1="50.8" y1="34.29" x2="50.8" y2="31.75" width="0" layer="19" extent="1-1"/>
</signal>
<signal name="5V">
<contactref element="BTN1" pad="2"/>
@ -1186,10 +1191,6 @@ Note, that not all DRC settings must be set by the manufacturer. Several can be
<wire x1="29.21" y1="39.37" x2="29.21" y2="36.83" width="0.3048" layer="16"/>
<wire x1="34.29" y1="31.75" x2="34.29" y2="29.21" width="0.3048" layer="16"/>
<contactref element="AUX1" pad="3"/>
<contactref element="AUX2" pad="3"/>
<contactref element="AUX3" pad="3"/>
<wire x1="44.45" y1="54.61" x2="44.45" y2="43.18" width="0.3048" layer="16"/>
<wire x1="44.45" y1="43.18" x2="44.45" y2="31.75" width="0.3048" layer="16"/>
<contactref element="I2C" pad="2"/>
<contactref element="INT" pad="1"/>
<contactref element="EXT" pad="1"/>
@ -1202,13 +1203,13 @@ Note, that not all DRC settings must be set by the manufacturer. Several can be
<wire x1="48.26" y1="7.62" x2="40.64" y2="15.24" width="0.3048" layer="1"/>
<wire x1="33.02" y1="6.35" x2="33.02" y2="7.62" width="0.3048" layer="1"/>
<wire x1="33.02" y1="7.62" x2="40.64" y2="15.24" width="0.3048" layer="1"/>
<wire x1="19.05" y1="10.16" x2="19.05" y2="11.43" width="0.3048" layer="16"/>
<wire x1="19.05" y1="11.43" x2="21.59" y2="13.97" width="0.3048" layer="16"/>
<wire x1="21.59" y1="13.97" x2="25.4" y2="13.97" width="0.3048" layer="16"/>
<wire x1="25.4" y1="13.97" x2="27.94" y2="16.51" width="0.3048" layer="16"/>
<wire x1="27.94" y1="16.51" x2="27.94" y2="20.32" width="0.3048" layer="16"/>
<wire x1="27.94" y1="20.32" x2="31.75" y2="24.13" width="0.3048" layer="16"/>
<wire x1="31.75" y1="24.13" x2="40.64" y2="24.13" width="0.3048" layer="16"/>
<wire x1="19.05" y1="10.16" x2="19.05" y2="11.43" width="0.508" layer="16"/>
<wire x1="19.05" y1="11.43" x2="21.59" y2="13.97" width="0.508" layer="16"/>
<wire x1="21.59" y1="13.97" x2="25.4" y2="13.97" width="0.508" layer="16"/>
<wire x1="25.4" y1="13.97" x2="27.94" y2="16.51" width="0.508" layer="16"/>
<wire x1="27.94" y1="16.51" x2="27.94" y2="20.32" width="0.508" layer="16"/>
<wire x1="27.94" y1="20.32" x2="31.75" y2="24.13" width="0.508" layer="16"/>
<wire x1="31.75" y1="24.13" x2="40.64" y2="24.13" width="0.508" layer="16"/>
<contactref element="VIN" pad="1"/>
<wire x1="40.64" y1="21.59" x2="40.64" y2="24.13" width="0.508" layer="1"/>
<wire x1="36.83" y1="34.29" x2="36.83" y2="27.94" width="0.508" layer="1"/>
@ -1334,8 +1335,9 @@ Note, that not all DRC settings must be set by the manufacturer. Several can be
<wire x1="11.43" y1="38.1" x2="8.89" y2="38.1" width="0.3048" layer="1"/>
<wire x1="8.89" y1="38.1" x2="7.62" y2="36.83" width="0.3048" layer="1"/>
<wire x1="7.62" y1="36.83" x2="2.54" y2="36.83" width="0.3048" layer="1"/>
<wire x1="12.7" y1="36.83" x2="30.48" y2="36.83" width="0.3048" layer="1"/>
<wire x1="30.48" y1="36.83" x2="31.75" y2="38.1" width="0.3048" layer="1"/>
<wire x1="12.7" y1="36.83" x2="13.335" y2="36.195" width="0.3048" layer="1"/>
<wire x1="29.845" y1="36.195" x2="13.335" y2="36.195" width="0.3048" layer="1"/>
<wire x1="29.845" y1="36.195" x2="31.75" y2="38.1" width="0.3048" layer="1"/>
<wire x1="31.75" y1="38.1" x2="31.75" y2="39.37" width="0.3048" layer="1"/>
</signal>
<signal name="B5">
@ -1422,21 +1424,6 @@ Note, that not all DRC settings must be set by the manufacturer. Several can be
<wire x1="45.72" y1="46.99" x2="48.26" y2="49.53" width="0.3048" layer="1"/>
<wire x1="48.26" y1="49.53" x2="50.8" y2="49.53" width="0.3048" layer="1"/>
</signal>
<signal name="AUX2">
<contactref element="B1" pad="A4"/>
<contactref element="AUX2" pad="2"/>
<wire x1="41.91" y1="43.18" x2="41.91" y2="46.99" width="0.3048" layer="1"/>
<wire x1="41.91" y1="46.99" x2="46.99" y2="52.07" width="0.3048" layer="1"/>
<wire x1="46.99" y1="52.07" x2="50.8" y2="52.07" width="0.3048" layer="1"/>
</signal>
<signal name="AUX3">
<contactref element="B1" pad="A5"/>
<contactref element="AUX3" pad="2"/>
<wire x1="41.91" y1="54.61" x2="41.91" y2="55.88" width="0.3048" layer="1"/>
<wire x1="41.91" y1="55.88" x2="43.18" y2="57.15" width="0.3048" layer="1"/>
<wire x1="48.26" y1="57.15" x2="50.8" y2="54.61" width="0.3048" layer="1"/>
<wire x1="43.18" y1="57.15" x2="48.26" y2="57.15" width="0.3048" layer="1"/>
</signal>
<signal name="EXT5V">
<contactref element="EXT5V" pad="2"/>
<contactref element="EXT" pad="2"/>


+ 0
- 66
EAGLE/VISCAShield.sch View File

@ -4660,8 +4660,6 @@ You are welcome to use this library for commercial purposes. For attribution, we
<part name="R9" library="BeagleBone_Black_Wireless" library_urn="urn:adsk.eagle:library:6644236" deviceset="R-US_" device="0204/2V" package3d_urn="urn:adsk.eagle:package:8118463/1" value="10kohm"/>
<part name="R10" library="BeagleBone_Black_Wireless" library_urn="urn:adsk.eagle:library:6644236" deviceset="R-US_" device="0204/2V" package3d_urn="urn:adsk.eagle:package:8118463/1" value="10kohm"/>
<part name="AUX1" library="con-molex" library_urn="urn:adsk.eagle:library:165" deviceset="22-23-2031" device="" package3d_urn="urn:adsk.eagle:package:8078634/1"/>
<part name="AUX2" library="con-molex" library_urn="urn:adsk.eagle:library:165" deviceset="22-23-2031" device="" package3d_urn="urn:adsk.eagle:package:8078634/1"/>
<part name="AUX3" library="con-molex" library_urn="urn:adsk.eagle:library:165" deviceset="22-23-2031" device="" package3d_urn="urn:adsk.eagle:package:8078634/1"/>
<part name="I2C" library="con-molex" library_urn="urn:adsk.eagle:library:165" deviceset="22-23-2041" device="" package3d_urn="urn:adsk.eagle:package:8078635/1"/>
<part name="EXT5V" library="con-molex" library_urn="urn:adsk.eagle:library:165" deviceset="22-23-2021" device="" package3d_urn="urn:adsk.eagle:package:8078633/1"/>
<part name="EXT" library="BeagleBone_Black_Wireless" library_urn="urn:adsk.eagle:library:6644236" deviceset="R-US_" device="0204/2V" package3d_urn="urn:adsk.eagle:package:8118463/1" value="0ohm"/>
@ -4851,26 +4849,6 @@ You are welcome to use this library for commercial purposes. For attribution, we
<instance part="AUX1" gate="-3" x="33.02" y="88.9" smashed="yes">
<attribute name="NAME" x="35.56" y="88.138" size="1.524" layer="95"/>
</instance>
<instance part="AUX2" gate="-1" x="33.02" y="83.82" smashed="yes">
<attribute name="NAME" x="35.56" y="83.058" size="1.524" layer="95"/>
<attribute name="VALUE" x="32.258" y="85.217" size="1.778" layer="96"/>
</instance>
<instance part="AUX2" gate="-2" x="33.02" y="81.28" smashed="yes">
<attribute name="NAME" x="35.56" y="80.518" size="1.524" layer="95"/>
</instance>
<instance part="AUX2" gate="-3" x="33.02" y="78.74" smashed="yes">
<attribute name="NAME" x="35.56" y="77.978" size="1.524" layer="95"/>
</instance>
<instance part="AUX3" gate="-1" x="33.02" y="73.66" smashed="yes">
<attribute name="NAME" x="35.56" y="72.898" size="1.524" layer="95"/>
<attribute name="VALUE" x="32.258" y="75.057" size="1.778" layer="96"/>
</instance>
<instance part="AUX3" gate="-2" x="33.02" y="71.12" smashed="yes">
<attribute name="NAME" x="35.56" y="70.358" size="1.524" layer="95"/>
</instance>
<instance part="AUX3" gate="-3" x="33.02" y="68.58" smashed="yes">
<attribute name="NAME" x="35.56" y="67.818" size="1.524" layer="95"/>
</instance>
<instance part="I2C" gate="-1" x="71.12" y="124.46" smashed="yes">
<attribute name="NAME" x="73.66" y="123.698" size="1.524" layer="95"/>
<attribute name="VALUE" x="70.358" y="125.857" size="1.778" layer="96"/>
@ -5036,16 +5014,6 @@ You are welcome to use this library for commercial purposes. For attribution, we
<label x="22.86" y="93.98" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="AUX2" gate="-1" pin="S"/>
<wire x1="30.48" y1="83.82" x2="22.86" y2="83.82" width="0.1524" layer="91"/>
<label x="22.86" y="83.82" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="AUX3" gate="-1" pin="S"/>
<wire x1="30.48" y1="73.66" x2="22.86" y2="73.66" width="0.1524" layer="91"/>
<label x="22.86" y="73.66" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="EXT5V" gate="-1" pin="S"/>
<wire x1="68.58" y1="99.06" x2="58.42" y2="99.06" width="0.1524" layer="91"/>
<label x="58.42" y="99.06" size="1.778" layer="95"/>
@ -5158,16 +5126,6 @@ You are welcome to use this library for commercial purposes. For attribution, we
<label x="22.86" y="88.9" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="AUX2" gate="-3" pin="S"/>
<wire x1="30.48" y1="78.74" x2="22.86" y2="78.74" width="0.1524" layer="91"/>
<label x="22.86" y="78.74" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="AUX3" gate="-3" pin="S"/>
<wire x1="30.48" y1="68.58" x2="22.86" y2="68.58" width="0.1524" layer="91"/>
<label x="22.86" y="68.58" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="I2C" gate="-2" pin="S"/>
<wire x1="68.58" y1="121.92" x2="58.42" y2="121.92" width="0.1524" layer="91"/>
<label x="58.42" y="121.92" size="1.778" layer="95"/>
@ -5424,30 +5382,6 @@ You are welcome to use this library for commercial purposes. For attribution, we
<label x="22.86" y="91.44" size="1.778" layer="95"/>
</segment>
</net>
<net name="AUX2" class="0">
<segment>
<pinref part="B1" gate="G$1" pin="A4"/>
<wire x1="27.94" y1="10.16" x2="12.7" y2="10.16" width="0.1524" layer="91"/>
<label x="12.7" y="10.16" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="AUX2" gate="-2" pin="S"/>
<wire x1="30.48" y1="81.28" x2="22.86" y2="81.28" width="0.1524" layer="91"/>
<label x="22.86" y="81.28" size="1.778" layer="95"/>
</segment>
</net>
<net name="AUX3" class="0">
<segment>
<pinref part="B1" gate="G$1" pin="A5"/>
<wire x1="27.94" y1="7.62" x2="12.7" y2="7.62" width="0.1524" layer="91"/>
<label x="12.7" y="7.62" size="1.778" layer="95"/>
</segment>
<segment>
<pinref part="AUX3" gate="-2" pin="S"/>
<wire x1="30.48" y1="71.12" x2="22.86" y2="71.12" width="0.1524" layer="91"/>
<label x="22.86" y="71.12" size="1.778" layer="95"/>
</segment>
</net>
<net name="EXT5V" class="0">
<segment>
<pinref part="EXT5V" gate="-2" pin="S"/>


+ 11
- 3
visca-controller/visca-controller.h View File

@ -35,6 +35,8 @@
const byte numChars = 16;
byte viscaMessage[numChars];
byte buttonStatus = 0x00;
// Pan/Tilt
byte panTilt[9] = { 0x81, 0x01, 0x06, 0x01, 0x00, 0x00, 0x03, 0x03, 0xFF };
byte panUp[9] = { 0x81, 0x01, 0x06, 0x01, 0x00, 0x00, 0x03, 0x01, 0xFF }; // 8x 01 06 01 0p 0t 03 01 ff
@ -50,12 +52,16 @@ byte panStop[9] = { 0x81, 0x01, 0x06, 0x01, 0x09, 0x09, 0x03, 0x03, 0xFF }
byte panTiltPosReq[5] = { 0x81, 0x09, 0x06, 0x12, 0xff }; // Resp: y0 50 0p 0q 0r 0s 0t 0u 0v 0w ff ; pqrs: pan position ; tuvw: tilt position
// Zoom
byte zoomTele[6] = { 0x81, 0x01, 0x04, 0x07, 0x2E, 0xff }; // 8x 01 04 07 2p ff
byte zoomWide[6] = { 0x81, 0x01, 0x04, 0x07, 0x3E, 0xff }; // 8x 01 04 07 3p ff
// Tele: 8x 01 04 07 2p ff
// Wide: 8x 01 04 07 2p ff
byte zoom[6] = { 0x81, 0x01, 0x04, 0x07, 0x2F, 0xff }; // 8x 01 04 07 2p ff
byte zoomTele[6] = { 0x81, 0x01, 0x04, 0x07, 0x2F, 0xff }; // 8x 01 04 07 2p ff
byte zoomWide[6] = { 0x81, 0x01, 0x04, 0x07, 0x3F, 0xff }; // 8x 01 04 07 3p ff
byte zoomStop[6] = { 0x81, 0x01, 0x04, 0x07, 0x00, 0xff };
byte zoomDirect[9] = { 0x81, 0x01, 0x04, 0x47, 0x00, 0x00, 0x00, 0x00, 0xff }; // 8x 01 04 47 0p 0q 0r 0s ff
byte zoomDirect[9] = { 0x81, 0x01, 0x04, 0x47, 0x00, 0x00, 0x00, 0x00, 0xff }; // 8x 01 04 47 0p 0q 0r 0s ff pqrs: zoom position
byte zoomPosReq[5] = { 0x81, 0x09, 0x04, 0x47, 0xff }; // Resp: y0 50 0p 0q 0r 0s ff
// Focus
byte focusAuto[6] = { 0x81, 0x01, 0x04, 0x38, 0x02, 0xff };
byte focusManual[6] = { 0x81, 0x01, 0x04, 0x38, 0x03, 0xff };
@ -87,4 +93,6 @@ byte callLedBlink[6] = { 0x81, 0x01, 0x33, 0x01, 0x02, 0xff};
int delayTime = 500; //Time between commands
void sendViscaPacket(byte* packet, int byteSize, bool echoCommand = true, bool sendPacket = true);
#endif

+ 131
- 9
visca-controller/visca-controller.ino View File

@ -133,13 +133,124 @@ void readSerial() {
}
unsigned long time_now = 0;
unsigned long pt_now = 0;
int lastZoomPos;
int lastZoom;
bool panIdle = true;
bool tiltIdle = true;
int ptLow = 441;
int ptHight = 581;
void readButtons() {
int globalSpeed = analogRead(ZOOM);
int zoomSpeed = map(globalSpeed, 0, 1023, 0, 15);
// int ptMaxSpeed = map(globalSpeed, 0, 1023, 0, 7);
int ptMaxSpeed = 5;
int pan = analogRead(PAN);
int tilt = analogRead(TILT);
if(pan < ptLow || ptHight < pan) {
uint8_t panSpeed;
if(pan < ptLow) {
// Left
panSpeed = map(pan, ptLow, 0, 0, ptMaxSpeed);
panTilt[6] = 0x01;
} else {
panSpeed = map(pan, ptHight, 1018, 0, ptMaxSpeed);
// Right
panTilt[6] = 0x02;
}
if(panTilt[4] != panSpeed) {
panTilt[4] = panSpeed;
sendViscaPacket(panTilt, sizeof(panTilt), true);
}
panIdle = false;
} else {
// Stop Pan
panTilt[4] = 0x00;
panTilt[6] = 0x03;
if(panIdle == false) {
sendViscaPacket(panTilt, sizeof(panTilt), true);
panIdle = true;
}
}
if(tilt < ptLow || ptHight < tilt) {
uint8_t tiltSpeed;
if(tilt < ptLow) {
// Down
tiltSpeed = map(tilt, ptLow, 0, 0, ptMaxSpeed);
panTilt[7] = 0x02;
} else {
// Up
tiltSpeed = map(tilt, ptHight, 1018, 0, ptMaxSpeed);
panTilt[7] = 0x01;
}
if(panTilt[5] != tiltSpeed) {
panTilt[5] = tiltSpeed;
sendViscaPacket(panTilt, sizeof(panTilt), true);
}
tiltIdle = false;
} else {
// Stop Tilt
panTilt[5] = 0x00;
panTilt[7] = 0x03;
if(tiltIdle == false) {
sendViscaPacket(panTilt, sizeof(panTilt), true);
tiltIdle = true;
}
}
if(millis() > time_now + 100) {
time_now = millis();
bool button1 = digitalRead(8);
if(button1 == true) {
sendViscaPacket(panTiltPosReq, sizeof(panTiltPosReq));
// if(
// if(zoomPos < lastZoomPos - 2 || lastZoomPos + 2 < zoomPos) {
// lastZoomPos = zoomPos;
// zoomPos = map(zoomPos, 0, 1023, 0, 2883);
// byte mask = 0xF;
// Serial.println(zoomPos);
// zoomDirect[7] = zoomPos & mask;
// zoomDirect[6] = zoomPos >> 4 & mask;
// zoomDirect[5] = zoomPos >> 8 & mask;
// zoomDirect[4] = zoomPos >> 12 & mask;
// sendViscaPacket(zoomDirect, sizeof(zoomDirect), true);
// }
if((bool) digitalRead(BTN1) == true) {
sendViscaPacket(zoomPosReq, sizeof(zoomPosReq), false);
}
if((bool) digitalRead(BTN3) == true) {
uint8_t zoomDirSpeed = (uint8_t) 0x20 + zoomSpeed;
zoom[4] = zoomDirSpeed;
sendViscaPacket(zoom, sizeof(zoom));
}
if((bool) digitalRead(BTN5) == true) {
uint8_t zoomDirSpeed = (uint8_t) 0x30 + zoomSpeed;
zoom[4] = zoomDirSpeed;
sendViscaPacket(zoom, sizeof(zoom));
}
// Serial.println((bool) digitalRead(BTN7));
// if((bool) digitalRead(BTN7) == false) {
// sendViscaPacket(zoomStop, sizeof(zoomStop));
// }
}
}
void handleButton(uint8_t input, uint8_t bitPosition) {
bool previousStatus = (bool) bitRead(buttonStatus, bitPosition);
bool currentStatus = (bool) digitalRead(input);
if(previousStatus != currentStatus) {
if(currentStatus == true) {
bitWrite(buttonStatus, bitPosition, (int) currentStatus);
} else {
}
}
}
@ -158,15 +269,26 @@ void toggleFocusControl() {
}
}
void sendViscaPacket(byte* packet, int byteSize) {
Serial.print("Sending:");
void sendViscaPacket(byte* packet, int byteSize, bool echoCommand, bool sendPacket) {
if(echoCommand == true) {
Serial.print("Sending:");
}
// visca.write(byte 0x81);
for (int i = 0; i < byteSize; i++)
{
Serial.print(" 0x");
Serial.print(packet[i], HEX);
visca.write(packet[i]);
if(echoCommand == true) {
Serial.print(" 0x");
Serial.print(packet[i], HEX);
}
if(sendPacket == true) {
visca.write(packet[i]);
}
}
// visca.write(byte 0xFF);
if(echoCommand == true) {
Serial.println();
}
Serial.println();
}
void initCameras() {


Loading…
Cancel
Save