|
|
|
@ -5,12 +5,11 @@ SoftwareSerial viscaOutput(VISCARX, VISCATX); |
|
|
|
|
|
|
|
void setup() { |
|
|
|
Serial.begin(115200); |
|
|
|
while (!Serial) { |
|
|
|
; // wait for serial port to connect. Needed for native USB port only
|
|
|
|
while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only
|
|
|
|
} |
|
|
|
|
|
|
|
for (uint8_t i = 4; i <= 12; i++) { |
|
|
|
pinMode(i,INPUT); |
|
|
|
pinMode(i, INPUT); |
|
|
|
} |
|
|
|
viscaOutput.begin(9600); |
|
|
|
|
|
|
|
@ -32,6 +31,7 @@ bool zoomIdle = true; |
|
|
|
int analogLowThreshold = 441; |
|
|
|
int analogHighThreshold = 581; |
|
|
|
int ptMaxSpeed = 5; |
|
|
|
|
|
|
|
void handleHardwareControl() { |
|
|
|
processPan(analogRead(PAN)); |
|
|
|
|
|
|
|
@ -55,9 +55,8 @@ void receiveViscaData() { |
|
|
|
if (ndx >= maxViscaMessageSize) { |
|
|
|
ndx = maxViscaMessageSize - 1; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if(DEBUG_VISCA == 1) { |
|
|
|
} else { |
|
|
|
if (DEBUG_VISCA == 1) { |
|
|
|
for (uint8_t i = 0; i < ndx; i++) { |
|
|
|
Serial.print("0x"); |
|
|
|
Serial.print(viscaMessage[i], HEX); |
|
|
|
@ -66,7 +65,7 @@ void receiveViscaData() { |
|
|
|
Serial.println("0xFF"); |
|
|
|
} |
|
|
|
ndx = 0; |
|
|
|
byte packet[3] = { 0x10, 0x41, 0xFF }; |
|
|
|
byte packet[3] = {0x10, 0x41, 0xFF}; |
|
|
|
viscaOutput.write(packet, 3); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -74,11 +73,10 @@ void receiveViscaData() { |
|
|
|
|
|
|
|
|
|
|
|
void handleSerialControl() { |
|
|
|
if (Serial.available() > 0) |
|
|
|
{ |
|
|
|
if (Serial.available() > 0) { |
|
|
|
char inChar = Serial.read(); // read incoming serial data:
|
|
|
|
|
|
|
|
switch(inChar) { |
|
|
|
switch (inChar) { |
|
|
|
case '1': |
|
|
|
initCameras(); |
|
|
|
break; |
|
|
|
@ -101,41 +99,41 @@ void handleSerialControl() { |
|
|
|
void processButtons() { |
|
|
|
int globalSpeed = analogRead(AUX1); |
|
|
|
int buttonZoomSpeed = map(globalSpeed, 0, 1023, 0, 15); |
|
|
|
if(millis() > time_now + 100) { |
|
|
|
if (millis() > time_now + 100) { |
|
|
|
time_now = millis(); |
|
|
|
|
|
|
|
collectCurrentButtonStatus(); |
|
|
|
|
|
|
|
int btn1 = buttons[0]; |
|
|
|
if(buttonPressed(btn1) == true) { |
|
|
|
if (buttonPressed(btn1) == true) { |
|
|
|
setButtonStatus(btn1, true); |
|
|
|
sendZoomPacket(0x20, buttonZoomSpeed); |
|
|
|
} else if(buttonReleased(btn1) == true) { |
|
|
|
} else if (buttonReleased(btn1) == true) { |
|
|
|
setButtonStatus(btn1, false); |
|
|
|
sendViscaPacket(zoomStop, sizeof(zoomStop)); |
|
|
|
} |
|
|
|
|
|
|
|
int btn2 = buttons[1]; |
|
|
|
if(buttonPressed(btn2) == true) { |
|
|
|
if (buttonPressed(btn2) == true) { |
|
|
|
setButtonStatus(btn2, true); |
|
|
|
sendZoomPacket(0x30, buttonZoomSpeed); |
|
|
|
} else if(buttonReleased(btn2) == true) { |
|
|
|
} else if (buttonReleased(btn2) == true) { |
|
|
|
setButtonStatus(btn2, false); |
|
|
|
sendViscaPacket(zoomStop, sizeof(zoomStop)); |
|
|
|
} |
|
|
|
|
|
|
|
int btn5 = buttons[4]; |
|
|
|
if(buttonPressed(btn5) == true) { |
|
|
|
if (buttonPressed(btn5) == true) { |
|
|
|
setButtonStatus(btn5, true); |
|
|
|
initCameras(); |
|
|
|
} else if(buttonReleased(btn5) == true) { |
|
|
|
} else if (buttonReleased(btn5) == true) { |
|
|
|
setButtonStatus(btn5, false); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void collectCurrentButtonStatus() { |
|
|
|
for (int i = 0; i < (int) (sizeof(buttons) / sizeof (buttons [0])); i++) { |
|
|
|
for (int i = 0; i < (int) (sizeof(buttons) / sizeof(buttons[0])); i++) { |
|
|
|
bitWrite(buttonCurrentStatus, buttons[i], (int) digitalRead(buttons[i])); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -168,10 +166,10 @@ void setButtonStatus(uint8_t input, bool status) { |
|
|
|
|
|
|
|
void processZoom(int zoom) { |
|
|
|
int zoomMaxSpeed = 15; |
|
|
|
if(zoom < analogLowThreshold || analogHighThreshold < zoom) { |
|
|
|
if (zoom < analogLowThreshold || analogHighThreshold < zoom) { |
|
|
|
uint8_t zoomSpeed; |
|
|
|
byte zoomDir; |
|
|
|
if(zoom < analogLowThreshold) { |
|
|
|
if (zoom < analogLowThreshold) { |
|
|
|
// Zoom Out
|
|
|
|
zoomSpeed = map(zoom, analogLowThreshold, 0, 0, zoomMaxSpeed); |
|
|
|
zoomDir = 0x30; |
|
|
|
@ -182,14 +180,14 @@ void processZoom(int zoom) { |
|
|
|
} |
|
|
|
|
|
|
|
uint8_t zoomDirSpeed = (uint8_t) zoomDir + zoomSpeed; |
|
|
|
if(zoomCommand[4] != zoomDirSpeed) { |
|
|
|
if (zoomCommand[4] != zoomDirSpeed) { |
|
|
|
zoomCommand[4] = zoomDirSpeed; |
|
|
|
sendViscaPacket(zoomCommand, sizeof(zoomCommand)); |
|
|
|
} |
|
|
|
zoomIdle = false; |
|
|
|
} else { |
|
|
|
// Stop Zoom
|
|
|
|
if(zoomIdle == false) { |
|
|
|
if (zoomIdle == false) { |
|
|
|
sendViscaPacket(zoomStop, sizeof(zoomStop)); |
|
|
|
zoomIdle = true; |
|
|
|
} |
|
|
|
@ -197,9 +195,9 @@ void processZoom(int zoom) { |
|
|
|
} |
|
|
|
|
|
|
|
void processPan(int pan) { |
|
|
|
if(pan < analogLowThreshold || analogHighThreshold < pan) { |
|
|
|
if (pan < analogLowThreshold || analogHighThreshold < pan) { |
|
|
|
uint8_t panSpeed; |
|
|
|
if(pan < analogLowThreshold) { |
|
|
|
if (pan < analogLowThreshold) { |
|
|
|
// Left
|
|
|
|
panSpeed = map(pan, analogLowThreshold, 0, 0, ptMaxSpeed); |
|
|
|
panTilt[6] = 0x01; |
|
|
|
@ -209,7 +207,7 @@ void processPan(int pan) { |
|
|
|
panTilt[6] = 0x02; |
|
|
|
} |
|
|
|
|
|
|
|
if(panTilt[4] != panSpeed) { |
|
|
|
if (panTilt[4] != panSpeed) { |
|
|
|
panTilt[4] = panSpeed; |
|
|
|
sendViscaPacket(panTilt, sizeof(panTilt)); |
|
|
|
} |
|
|
|
@ -218,7 +216,7 @@ void processPan(int pan) { |
|
|
|
// Stop Pan
|
|
|
|
panTilt[4] = 0x00; |
|
|
|
panTilt[6] = 0x03; |
|
|
|
if(panIdle == false) { |
|
|
|
if (panIdle == false) { |
|
|
|
sendViscaPacket(panTilt, sizeof(panTilt)); |
|
|
|
panIdle = true; |
|
|
|
} |
|
|
|
@ -226,9 +224,9 @@ void processPan(int pan) { |
|
|
|
} |
|
|
|
|
|
|
|
void processTilt(int tilt) { |
|
|
|
if(tilt < analogLowThreshold || analogHighThreshold < tilt) { |
|
|
|
if (tilt < analogLowThreshold || analogHighThreshold < tilt) { |
|
|
|
uint8_t tiltSpeed; |
|
|
|
if(tilt < analogLowThreshold) { |
|
|
|
if (tilt < analogLowThreshold) { |
|
|
|
// Down
|
|
|
|
tiltSpeed = map(tilt, analogLowThreshold, 0, 0, ptMaxSpeed); |
|
|
|
panTilt[7] = 0x02; |
|
|
|
@ -238,7 +236,7 @@ void processTilt(int tilt) { |
|
|
|
panTilt[7] = 0x01; |
|
|
|
} |
|
|
|
|
|
|
|
if(panTilt[5] != tiltSpeed) { |
|
|
|
if (panTilt[5] != tiltSpeed) { |
|
|
|
panTilt[5] = tiltSpeed; |
|
|
|
sendViscaPacket(panTilt, sizeof(panTilt)); |
|
|
|
} |
|
|
|
@ -247,7 +245,7 @@ void processTilt(int tilt) { |
|
|
|
// Stop Tilt
|
|
|
|
panTilt[5] = 0x00; |
|
|
|
panTilt[7] = 0x03; |
|
|
|
if(tiltIdle == false) { |
|
|
|
if (tiltIdle == false) { |
|
|
|
sendViscaPacket(panTilt, sizeof(panTilt)); |
|
|
|
tiltIdle = true; |
|
|
|
} |
|
|
|
@ -259,7 +257,7 @@ void toggleFocusControl() { |
|
|
|
delay(100); |
|
|
|
receiveViscaData(); |
|
|
|
Serial.print("Current Focus Status: "); |
|
|
|
if(viscaMessage[2] == 2) { |
|
|
|
if (viscaMessage[2] == 2) { |
|
|
|
Serial.println("Auto, Toggling to manual"); |
|
|
|
sendViscaPacket(focusManual, sizeof(focusManual)); |
|
|
|
} else { |
|
|
|
@ -270,19 +268,18 @@ void toggleFocusControl() { |
|
|
|
|
|
|
|
|
|
|
|
void sendViscaPacket(byte *packet, int byteSize) { |
|
|
|
if(DEBUG_VISCA == 1) { |
|
|
|
if (DEBUG_VISCA == 1) { |
|
|
|
Serial.print("Sending:"); |
|
|
|
} |
|
|
|
for (int i = 0; i < byteSize; i++) |
|
|
|
{ |
|
|
|
if(DEBUG_VISCA == 1) { |
|
|
|
for (int i = 0; i < byteSize; i++) { |
|
|
|
if (DEBUG_VISCA == 1) { |
|
|
|
Serial.print(" 0x"); |
|
|
|
Serial.print(packet[i], HEX); |
|
|
|
} |
|
|
|
|
|
|
|
viscaOutput.write(packet[i]); |
|
|
|
} |
|
|
|
if(DEBUG_VISCA == 1) { |
|
|
|
if (DEBUG_VISCA == 1) { |
|
|
|
Serial.println(); |
|
|
|
} |
|
|
|
} |
|
|
|
|