Browse Source

Some cleanup.

extract-visca-communication-to-class
Ed Walker 5 years ago
parent
commit
3d62d79573
2 changed files with 87 additions and 103 deletions
  1. +1
    -1
      visca-controller/visca-controller.h
  2. +86
    -102
      visca-controller/visca-controller.ino

+ 1
- 1
visca-controller/visca-controller.h View File

@ -86,7 +86,7 @@ byte wbTableDirect[9] = { 0x81, 0x01, 0x04, 0x75, 0x00, 0x00, 0x0, 0x00, 0xff };
// Config
byte address_command[4] = { 0x88, 0x30, 0x01, 0xFF }; // Sets camera address (Needed for Daisy Chaining)
byte if_clear[5] = { 0x88, 0x01, 0x00, 0x01, 0xFF }; // Checks to see if communication line is clear
byte ir_off[6] = { 0x81, 0x01, 0x06, 0x09, 0x03, 0xff }; // Turn off IR control (required for speed control of Pan/Tilt)
byte ir_off[6] = { 0x81, 0x01, 0x06, 0x09, 0x03, 0xff }; // Turn off IR control (required for speed control of Pan/Tilt on TelePresence cameras)
byte callLedOn[6] = { 0x81, 0x01, 0x33, 0x01, 0x01, 0xff};
byte callLedOff[6] = { 0x81, 0x01, 0x33, 0x01, 0x00, 0xff};
byte callLedBlink[6] = { 0x81, 0x01, 0x33, 0x01, 0x02, 0xff};


+ 86
- 102
visca-controller/visca-controller.ino View File

@ -20,13 +20,28 @@ void setup() {
}
void loop() {
readSerial();
receiveData();
readButtons();
// int talentDimmer = map(analogRead(TALENT_DIMMER_PIN), 0, 1023, 0, 255);
handleSerialControl();
receiveViscaData();
handleHardwareControl();
}
void receiveData() {
unsigned long time_now = 0;
bool panIdle = true;
bool tiltIdle = true;
int ptLow = 441;
int ptHight = 581;
int ptMaxSpeed = 5;
void handleHardwareControl() {
processPan(analogRead(PAN));
processTilt(analogRead(TILT));
processButtons();
}
void receiveViscaData() {
static byte ndx = 0;
byte rc;
while (visca.available() > 0) {
@ -54,7 +69,7 @@ void receiveData() {
}
void readSerial() {
void handleSerialControl() {
if (Serial.available() > 0)
{
char inChar = Serial.read(); // read incoming serial data:
@ -132,114 +147,84 @@ 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() {
void processButtons() {
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();
// 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);
sendViscaPacket(zoomStop, sizeof(zoomStop));
}
if((bool) digitalRead(BTN3) == true) {
if((bool) digitalRead(BTN2) == true) {
uint8_t zoomDirSpeed = (uint8_t) 0x20 + zoomSpeed;
zoom[4] = zoomDirSpeed;
sendViscaPacket(zoom, sizeof(zoom));
}
if((bool) digitalRead(BTN5) == true) {
if((bool) digitalRead(BTN3) == 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 processPan(int pan) {
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;
}
}
}
void processTilt(int tilt) {
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;
}
}
}
@ -258,7 +243,7 @@ void handleButton(uint8_t input, uint8_t bitPosition) {
void toggleFocusControl() {
sendViscaPacket(focusModeInq, sizeof(focusModeInq));
delay(100);
receiveData();
receiveViscaData();
Serial.print("Current Focus Status: ");
if(viscaMessage[2] == 2) {
Serial.println("Auto, Toggling to manual");
@ -274,7 +259,6 @@ void sendViscaPacket(byte* packet, int byteSize, bool echoCommand, bool sendPack
if(echoCommand == true) {
Serial.print("Sending:");
}
// visca.write(byte 0x81);
for (int i = 0; i < byteSize; i++)
{
if(echoCommand == true) {
@ -296,17 +280,17 @@ void initCameras() {
Serial.println("Setting addresses...");
sendViscaPacket(address_command, sizeof(address_command));
delay(delayTime); //delay to allow camera time for next command
receiveData();
receiveViscaData();
// Turn off IR control
Serial.println("Disabling IR control...");
sendViscaPacket(ir_off, sizeof(ir_off));
delay(delayTime); //delay to allow camera time for next command
receiveData();
receiveViscaData();
//Send IF_clear command
Serial.println("Sending IF_Clear...");
sendViscaPacket(if_clear, sizeof(if_clear));
delay(delayTime); //delay to allow camera time for next command
receiveData();
receiveViscaData();
}

Loading…
Cancel
Save