|
@@ -16,6 +16,11 @@ var currentInquiry = '';
|
|
|
var ZoomAuto = false ;
|
|
|
var ZoomPos_target ;
|
|
|
var ZoomTime_target ;
|
|
|
+var ZoomCurrentSpeed;
|
|
|
+var ZoomAuto_Remain = script.addFloatParameter("Zoom remain", "", 0.);
|
|
|
+var ZoomAuto_Speed = script.addFloatParameter("Zoom speed", "", 0., -7, 7);
|
|
|
+
|
|
|
+var autoZoomPos = false;
|
|
|
|
|
|
//////////////////////// HELPERS FUNCTIONS ////////////////////////////
|
|
|
|
|
@@ -30,6 +35,7 @@ function printArray(name, array){
|
|
|
//////////////////////// VISCA FUNCTIONS ////////////////////////////////
|
|
|
|
|
|
function setZoomPos(ID, position){
|
|
|
+ ZoomAuto = false ;
|
|
|
var header = [1, 4, 71];
|
|
|
var posCmd = [];
|
|
|
var pos = Math.round(Math.floor(16384 * position));
|
|
@@ -46,6 +52,7 @@ function setZoomPos(ID, position){
|
|
|
}
|
|
|
|
|
|
function setZoomSpeed(ID, speed){
|
|
|
+ ZoomAuto = false ;
|
|
|
var header = [1, 4, 7];
|
|
|
|
|
|
var speedCmd = speed < 0 ? 48 : 32;
|
|
@@ -82,12 +89,25 @@ function sendHeaderCommand(id, header, command){
|
|
|
// printArray('header', header);
|
|
|
// printArray('command', command);
|
|
|
local.sendBytes(idHex, header, command, 255);
|
|
|
- waitTaskComplete = 1;
|
|
|
+ waitTaskComplete = 0;
|
|
|
}
|
|
|
else { script.log('task not complete');}
|
|
|
|
|
|
}
|
|
|
|
|
|
+function continuousZoomPos(state){
|
|
|
+ if (autoZoomPos != state ){
|
|
|
+ autoZoomPos = state;
|
|
|
+
|
|
|
+ var header = [1, 4, 105];
|
|
|
+
|
|
|
+ var stateCmd = state ? 2 : 3;
|
|
|
+
|
|
|
+ // stateCmd = speed == 0 ? 0 : speedCmd ;
|
|
|
+ sendHeaderCommand(camID, header, stateCmd);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
@@ -102,7 +122,7 @@ function setZoomPositionInTime(ID, position, time){
|
|
|
|
|
|
//activate callback
|
|
|
ZoomAuto = true ;
|
|
|
-
|
|
|
+ continuousZoomPos(true);
|
|
|
//deduce appropriate speed
|
|
|
// var speedCmd = speed < 0 ? 48 : 32;
|
|
|
// speedCmd = speed == 0 ? 0 : speedCmd ;
|
|
@@ -131,16 +151,21 @@ function setZoomPositionInTime_TL(ID, position, time){
|
|
|
function updateZoomPosition() {
|
|
|
|
|
|
if (ZoomAuto){
|
|
|
- //update position
|
|
|
- sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
-
|
|
|
+ var lastUpdated = util.getTime()-ZoomPosLastUpdate.get();
|
|
|
+ //update position if was updated long ago
|
|
|
+ // sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
+ if (lastUpdated>0.5){
|
|
|
+ // sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
+ continuousZoomPos(true);
|
|
|
+ }
|
|
|
//update speed if needed
|
|
|
var lastUpdated = util.getTime()-ZoomPosLastUpdate.get();
|
|
|
// script.log(lastUpdated);
|
|
|
if(lastUpdated<0.5){
|
|
|
//compute remaining time
|
|
|
var remainTime = ZoomTime_target - util.getTime();
|
|
|
- if(remainTime > 0){
|
|
|
+ if(remainTime > 0.5){
|
|
|
+
|
|
|
var remainLength = (ZoomPos_target - ZoomPos.get()) * 100;
|
|
|
var rawSpeed = remainLength / remainTime ;
|
|
|
|
|
@@ -149,15 +174,25 @@ function updateZoomPosition() {
|
|
|
var direction = rawSpeed > 0 ? 1 : -1;
|
|
|
realSpeed *= direction ;
|
|
|
realSpeed = Math.floor(realSpeed);
|
|
|
- script.log(remainLength + '% in ' + remainTime + ' s : ' + realSpeed + ' / ' +rawSpeed );
|
|
|
- setZoomSpeed(1, realSpeed);
|
|
|
+ ZoomAuto_Remain.set(remainTime);
|
|
|
+ ZoomAuto_Speed.set(realSpeed);
|
|
|
+ // script.log(remainLength + '% in ' + remainTime + ' s : ' + realSpeed + ' / ' +rawSpeed );
|
|
|
+ if (realSpeed != ZoomCurrentSpeed){
|
|
|
+ script.log("change speed");
|
|
|
+ ZoomCurrentSpeed = realSpeed ;
|
|
|
+ setZoomSpeed(1, ZoomCurrentSpeed);
|
|
|
+ }
|
|
|
+
|
|
|
+ ZoomAuto=true;
|
|
|
+ break;
|
|
|
}
|
|
|
else {
|
|
|
ZoomAuto = false;
|
|
|
script.log('automation timeout');
|
|
|
//go to position
|
|
|
setZoomPos(1, ZoomPos_target);
|
|
|
- sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
+ continuousZoomPos(false);
|
|
|
+ // sendInquiry(1, 'CAM_ZoomPosInq');
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -179,12 +214,12 @@ function updateZoomPosition() {
|
|
|
function init() {
|
|
|
//loadFixtures();
|
|
|
script.log("VISCA module loaded");
|
|
|
- script.setUpdateRate(2);
|
|
|
+ script.setUpdateRate(10);
|
|
|
+ continuousZoomPos(false);
|
|
|
}
|
|
|
|
|
|
function update(deltaTime){
|
|
|
updateZoomPosition();
|
|
|
- computeSpeed();
|
|
|
// script.log('update');
|
|
|
|
|
|
}
|