|
@@ -4,8 +4,13 @@
|
|
|
// var parameterPath = local.parameters;
|
|
|
// var valuesPath = local.values;
|
|
|
|
|
|
+var ZoomPos = script.addFloatParameter("Zoom Position", "", 0., 0., 1.);
|
|
|
+
|
|
|
// var state =
|
|
|
var inquiry = ['CAM_ZoomPosInq', 'CAM_FocusModeInq', 'CAM_FocusPosInq'];
|
|
|
+var camID = 1;
|
|
|
+var waitTaskComplete = 0 ;
|
|
|
+var currentInquiry = '';
|
|
|
|
|
|
/////////// HELPERS FUNCTIONS ////////////////
|
|
|
|
|
@@ -17,27 +22,59 @@ function printArray(name, array){
|
|
|
|
|
|
/////////// VISCA FUNCTIONS ////////////////
|
|
|
|
|
|
-function setZoom(ID, position){
|
|
|
+function setZoomPos(ID, position){
|
|
|
var header = [1, 4, 71];
|
|
|
- var posCommand = [];
|
|
|
+ var posCmd = [];
|
|
|
var pos = Math.round(Math.floor(16384 * position));
|
|
|
// script.log(pos);
|
|
|
- posCommand[3]=pos%16;
|
|
|
+ posCmd[3]=pos%16;
|
|
|
pos = Math.round(Math.floor(pos/16));
|
|
|
- posCommand[2]=pos%16;
|
|
|
+ posCmd[2]=pos%16;
|
|
|
pos=Math.round(Math.floor(pos/16));
|
|
|
- posCommand[1]=pos%16;
|
|
|
- posCommand[0]=Math.round(Math.floor(pos/16));
|
|
|
+ posCmd[1]=pos%16;
|
|
|
+ posCmd[0]=Math.round(Math.floor(pos/16));
|
|
|
// local.sendBytes(idHex, 1, 4, 71, posCommand, 255);
|
|
|
|
|
|
- sendCommand(1, header, posCommand);
|
|
|
+ sendHeaderCommand(camID, header, posCmd);
|
|
|
+}
|
|
|
+function setZoomSpeed(ID, speed){
|
|
|
+ var header = [1, 4, 7];
|
|
|
+
|
|
|
+ var speedCmd = speed < 0 ? 48 : 32;
|
|
|
+ speedCmd = speed == 0 ? 0 : speedCmd ;
|
|
|
+ speedCmd += Math.abs(speed);
|
|
|
+ sendHeaderCommand(camID, header, speedCmd);
|
|
|
+}
|
|
|
+
|
|
|
+function sendInquiry(id, inquiryName){
|
|
|
+ var command ;
|
|
|
+ if (currentInquiry == ''){ //no inquiry running;
|
|
|
+ currentInquiry = inquiryName ;
|
|
|
+ if(inquiryName == 'CAM_ZoomPosInq'){ command = [9, 4, 71];}
|
|
|
+
|
|
|
+ sendCommand(camID, command);
|
|
|
+ }
|
|
|
+ else{script.log("inquiry running");}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
-function sendCommand(id, header, command){
|
|
|
- var idHex = (parseInt("0x80") + ID);
|
|
|
- printArray('header', header);
|
|
|
+function sendCommand(id, command){
|
|
|
+ var idHex = (parseInt("0x80") + id);
|
|
|
+
|
|
|
printArray('command', command);
|
|
|
- local.sendBytes(idHex, header, command, 255);
|
|
|
+ local.sendBytes(idHex, command, 255);
|
|
|
+}
|
|
|
+
|
|
|
+function sendHeaderCommand(id, header, command){
|
|
|
+ if (!waitTaskComplete){
|
|
|
+ var idHex = (parseInt("0x80") + id);
|
|
|
+ printArray('header', header);
|
|
|
+ printArray('command', command);
|
|
|
+ local.sendBytes(idHex, header, command, 255);
|
|
|
+ waitTaskComplete = 1;
|
|
|
+ }
|
|
|
+ else { script.log('task not complete');}
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/////////// SCRIPT FUNCTIONS ////////////////
|
|
@@ -45,6 +82,15 @@ function sendCommand(id, header, command){
|
|
|
function init() {
|
|
|
//loadFixtures();
|
|
|
script.log("VISCA module loaded");
|
|
|
+ script.setUpdateRate(100);
|
|
|
+}
|
|
|
+
|
|
|
+function update(deltatTime){
|
|
|
+ if(!waitTaskComplete && (currentInquiry!=''))
|
|
|
+ {
|
|
|
+ sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
var buffer=[];
|
|
@@ -72,15 +118,16 @@ function dataReceived(data)
|
|
|
else{
|
|
|
if(buffer[0]==144){ //0x90, you've got a message
|
|
|
if (buffer[1]==65){script.log("received command");} //0x41
|
|
|
- if (buffer[1]==81){script.log("complete command");} //0x51
|
|
|
- if (buffer[1]==97){//0x61
|
|
|
+ else if (buffer[1]==81){script.log("complete command");waitTaskComplete=0;} //0x51
|
|
|
+ else if (buffer[1]==96){script.log("syntax error");} //0x60
|
|
|
+ else if (buffer[1]==97){//0x61
|
|
|
var msg = "error :";
|
|
|
if(buffer[2]==1){msg=msg+"message length";}
|
|
|
- if(buffer[2]==2){msg=msg+"syntax";}
|
|
|
- if(buffer[2]==3){msg=msg+"command buffer full";}
|
|
|
- if(buffer[2]==4){msg=msg+"command cancelled";}
|
|
|
- if(buffer[2]==5){msg=msg+"no socket";}
|
|
|
- if(buffer[2]==65){msg=msg+"command not executable";}
|
|
|
+ else if(buffer[2]==2){msg=msg+"syntax";}
|
|
|
+ else if(buffer[2]==3){msg=msg+"command buffer full";}
|
|
|
+ else if(buffer[2]==4){msg=msg+"command cancelled";}
|
|
|
+ else if(buffer[2]==5){msg=msg+"no socket";}
|
|
|
+ else if(buffer[2]==65){msg=msg+"command not executable";}
|
|
|
else{
|
|
|
msg=msg+"unknow error";
|
|
|
for(var j=2; j < buffer.length; j++)
|
|
@@ -92,13 +139,17 @@ function dataReceived(data)
|
|
|
}
|
|
|
|
|
|
//inquiry answers
|
|
|
- // if (buffer[1]==80){//0x50){
|
|
|
- // switch(inquiry){
|
|
|
- // case 'CAM_ZoomPosInq':
|
|
|
-
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
+ else if (buffer[1]==80){//0x50
|
|
|
+ if(currentInquiry == 'CAM_ZoomPosInq'){
|
|
|
+ var position = buffer[2]*4096 + buffer[3]*256 + buffer[4]*16 + buffer[5];
|
|
|
+ printArray("zoom position :", buffer);
|
|
|
+ script.log(position);
|
|
|
+ ZoomPos.set(position/16384.);
|
|
|
+ }
|
|
|
+ //free inquiry slot
|
|
|
+ currentInquiry = '';
|
|
|
+ }
|
|
|
+ else{printArray("unknown answer :", buffer);}
|
|
|
}
|
|
|
bufferIndex = 0;
|
|
|
buffer=[];
|