⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controls_seq.js

📁 linux平台上的开放源代码的网络摄像机程序.实现视频捕捉,传输以及云台控制等.非常具有参考价值.
💻 JS
字号:
// ===================================================================================function to10ns(s) {//	var d= Math.round(parseFloat(s)*100);	var d= parseFloat(s);	if (d.isNaN) d=0;	if (s.toLowerCase().indexOf("ns") == -1) { //default "ns"		if      (s.toLowerCase().indexOf("us") != -1) d=1000*d;		else if (s.toLowerCase().indexOf("ms") != -1) d=1000000*d;		else if (s.toLowerCase().indexOf("s" ) != -1) d=1000000000*d;	}	return Math.round(d/10)*10;}// ===================================================================================function nsToStr(v) {	if      (v<1000)		return v.toString()+"ns";	else if (v<1000000)		return (v/1000).toString()+"us";	else 					return (v/1000000).toString()+"ms";}// ===================================================================================function setSeqTabCellInput(i,j,l,v,enbl,shw) {	//i,j should be within table range	var tab=document.tabP;	while (tab.rows[i].cells[j].firstChild) tab.rows[i].cells[j].removeChild(tab.rows[i].cells[j].firstChild);	if (l) {	  var fe= document.createElement('input');	  fe.type="text";	  fe.size=l;      tab.rows[i].cells[j].appendChild(fe);	  tab.rows[i].cells[j].firstChild.value=v;	  if (enbl) tab.rows[i].cells[j].firstChild.className="inputEnabled";	  else {		tab.rows[i].cells[j].firstChild.readOnly= true;		tab.rows[i].cells[j].firstChild.className="inputDisabled";	  }      tab.rows[i].cells[j].style.display=(shw)? "" : "none";	}}// ===================================================================================function setSeqTabCellText(i,j,v,a) {	//i,j should be within table range	var tab=document.tabP;	while (tab.rows[i].cells[j].firstChild) tab.rows[i].cells[j].removeChild(tab.rows[i].cells[j].firstChild);	if (v) {	  var fe= document.createTextNode(v);      tab.rows[i].cells[j].appendChild(fe);      tab.rows[i].cells[j].align=a;	}}// ===================================================================================function showSeqTabCell (i,j,s) {	//i,j should be within table range	var tab=document.tabP;     tab.rows[i].cells[j].style.display=(s)? "" : "none";}// ===================================================================================function seqAddRow() {//add row to Array	var last=(document.SeqTabLen>0)? (document.SeqTab[document.SeqTabLen-1][1]):0;	document.SeqTabLen++;	if (document.SeqTab.length < document.SeqTabLen) document.SeqTab[document.SeqTabLen-1]= new Array(2);	document.SeqTab[document.SeqTabLen-1][0]=last+10;	document.SeqTab[document.SeqTabLen-1][1]=last+20;  rebuildSeqTab();}// ===================================================================================function seqDelRow() {//delete last row from the Array	if (document.SeqTabLen >0) 	document.SeqTabLen--;	rebuildSeqTab();}// ===================================================================================function seqUpdate() {	var  tab=document.tabP;	var i, j, t;	var showDelay=   (document.getElementById("delayShow").checked)? 1:0;	var showStart=   (document.getElementById("startShow").checked)? 1:0;	var showDuration=(document.getElementById("durationShow").checked)? 1:0;	var showEnd=     (document.getElementById("endShow").checked)? 1:0;	var specifyDelay=   document.getElementById("delaySpecify").checked;	var specifyStart=   !specifyDelay;	var specifyDuration=document.getElementById("durationSpecify").checked;	var specifyEnd=     !specifyDuration;	var len;// 1-st pass - build tabele "as is"	t=0;	for (i=1;i<tab.rows.length;i++) {//		start?		t=specifyStart?			(to10ns(tab.rows[i].cells[2].firstChild.value)):			(t+to10ns(tab.rows[i].cells[1].firstChild.value));		document.SeqTab[i-1][0]=t;//		end?		t=specifyEnd?			to10ns(tab.rows[i].cells[4].firstChild.value):			(t+to10ns(tab.rows[i].cells[3].firstChild.value));		document.SeqTab[i-1][1]=t;	}	len=tab.rows.length-1;	i=0;// remove 0 or negative duration pulses	while (i<len)		if (document.SeqTab[i][1] <= document.SeqTab[i][0]) {			len--;			for (j=i;j<len;j++) {				document.SeqTab[j][0]=document.SeqTab[j+1][0];	//cannot reassign arrays - 2 will point to 1				document.SeqTab[j][1]=document.SeqTab[j+1][1];			}		} else i++;	// sort by "start"//	alert (document.SeqTab.toString());	i=0;	while (i<(len-1))		if (document.SeqTab[i][0] > document.SeqTab[i+1][0]) {			t=document.SeqTab[i+1];// swapping of arrays is fine			document.SeqTab[i+1]=document.SeqTab[i];			document.SeqTab[i]=t;//	alert ("i="+i+" array="+document.SeqTab.toString());			if (i>0) i--;		} else i++;//	alert ("After sorting: i="+i+" array="+document.SeqTab.toString());// find overlapping	i=1;	while (i<len)		if (document.SeqTab[i][0] <= document.SeqTab[i-1][1]) { // combine and remove second...			if (document.SeqTab[i][1] > document.SeqTab[i-1][1]) document.SeqTab[i-1][1] = document.SeqTab[i][1];			len--;			for (j=i;j<len;j++) {				document.SeqTab[j][0]=document.SeqTab[j+1][0];	//cannot reassign arrays - 2 will point to 1				document.SeqTab[j][1]=document.SeqTab[j+1][1];			}		} else i++;	document.SeqTabLen=len;  rebuildSeqTab();  	if (seqCompile()) {		seqSendCompiled();	}}// ===================================================================================function seqCompile() {	var wi=0;	// sequencer word index (0..127)	var ci=0;	// sequencer command index (in the same word - 0..3)	var	tim=0;	var	i,j;	var	dly;	seqPgmW=new Array();	seqPgmD=new Array();	i=0;	j=0;	// 0 - "on", 1 - "off"	while ((i<document.SeqTabLen) && (wi<128)) {		if (ci ==0) {seqPgmW[wi]=new Array(0,0,0,0);seqPgmD[wi]=0;}// can add "on"(or "off") to the same word?		if ((document.SeqTab[i][j]-tim) <= ((3-ci)*10)) {			ci=ci+(document.SeqTab[i][j]-tim)/10;			seqPgmW[wi][ci]=j+1;	// 1 - "on", 2 - "off"			tim=document.SeqTab[i][j]+10;			ci++; if (ci>3) {ci=0;wi++;}			j++;	if (j>1) {j=0;i++;}		} else { // no			tim+= (4-ci)*10;			dly=Math.floor((document.SeqTab[i][j]-tim)/40);			if (dly > 32767) dly=32767;			seqPgmD[wi]=dly;			tim+=40*dly;			wi++;			ci=0;		}	}// add "sequence end"	if (ci ==0) {seqPgmW[wi]=new Array(0,0,0,0);seqPgmD[wi]=0;}	seqPgmW[wi][ci]=3;	if (wi>=128) {		alert ("Can not program sequencer - sequence too long");		return -1;	}	document.camSeqData=new Array(2 *seqPgmW.length);		for (i=0;i<seqPgmW.length;i++) {	  document.camSeqData[2*i  ]=seqPgmW[i][0] + 4*seqPgmW[i][1] + 16*seqPgmW[i][2] + 64*seqPgmW[i][3];	  document.camSeqData[2*i+1]=seqPgmD[i];	}	return 1;}// ===================================================================================function seqSendCompiled() {  var t=new Date();    var str= parent.document.cameraMCP+"?";	var i,d;	str+="w=0200"; // start of	for (i=0;i<document.camSeqData.length;i++) {		d=document.camSeqData[i].toString(16);		while (d.length<4) d="0"+d;		str+=d;	}	str+='&l="'+escape("parent.frames[1].setUpdateStatus()")+'"';	str+="&_time="+t.getTime();//	alert (str);   parent.frames[0].location=str;}	 // ===================================================================================function seqDeCompile () {	// after reading from camera	var seqShift=512;	// address of first sequencer data in camera shadow memory	var tim=0;	var np=0;	var pOn=0;	//pulse "on"	var wi=0;	var	ci=0;	var d,d1,i;	var cmds=new Array (0,0,0,0);	while (wi < 128) {		if (ci==0) {//			d=document.camSeqData[2*wi];			d=document.camShadowData[2*wi+seqShift];			for (i=0;i<4;i++) {				d1=Math.floor(d/4);				cmds[i] = d-4*d1;				d=d1;			}		}		if      ((pOn==0) && (cmds[ci]==1)) {			if (document.SeqTab.length<=np) document.SeqTab[np]=new Array (0,0);			document.SeqTab[np][pOn]=tim;			pOn=1;		} else if ((pOn==1) && (cmds[ci]==2)) {			if (document.SeqTab.length<=np) document.SeqTab[np]=new Array (0,0);			document.SeqTab[np][pOn]=tim;			pOn=0;			np++;		} else if (cmds[ci]==3) {	// end of sequence			if (pOn) {				if (document.SeqTab.length<=np) document.SeqTab[np]=new Array (0,0);				document.SeqTab[np][pOn]=tim;				pOn=0;				np++;			}			document.SeqTabLen=np;			break; //while (wi<(document.camSeqData.length/2))		}		ci++;		tim+=10;		if (ci>3) {//			tim+= 40*document.camSeqData[2*wi+1];			tim+= 40*document.camShadowData[2*wi+seqShift+1];			ci=0;			wi++;		}	}	rebuildSeqTab();//	alert ("before setUpdateStatus()");}// ===================================================================================function rebuildSeqTab(){	var  tab=document.tabP;	var	 nr,nc0,nc1,nc2,nc3,nc4, tim, fe;	var showDelay=   (document.getElementById("delayShow").checked)? 1:0;	var showStart=   (document.getElementById("startShow").checked)? 1:0;	var showDuration=(document.getElementById("durationShow").checked)? 1:0;	var showEnd=     (document.getElementById("endShow").checked)? 1:0;	var specifyDelay=   document.getElementById("delaySpecify").checked;	var specifyStart=   !specifyDelay;	var specifyDuration=document.getElementById("durationSpecify").checked;	var specifyEnd=     !specifyDuration;//	alert("document.SeqTab.length="+document.SeqTab.length);// delete all rows in a table	while (tab.rows.length)  tab.deleteRow(tab.rows.length-1);	tim = 0;	  nr=tab.insertRow(0);	  nr.insertCell(0);	// pulse #  	  nr.insertCell(1); // delay  	  nr.insertCell(2); // satart  	  nr.insertCell(3); // duration  	  nr.insertCell(4); // end	  setSeqTabCellText (0,0,"pulse#","center");	  setSeqTabCellText (0,1,"Delay","center");	  showSeqTabCell	 (0,1,showDelay);      setSeqTabCellText (0,2,"Start","center");	  showSeqTabCell	 (0,2,showStart);	  setSeqTabCellText (0,3,"Duration","center");	  showSeqTabCell	 (0,3,showDuration);      setSeqTabCellText (0,4,"End","center");	  showSeqTabCell	 (0,4,showEnd);	tim=0;	for (i=0;i<document.SeqTabLen;i++) {//	  nr=tab.insertRow(tab.rows.length);	  nr=tab.insertRow(i+1);	  nr.insertCell(0);	// pulse #  	  nr.insertCell(1); // delay  	  nr.insertCell(2); // satart  	  nr.insertCell(3); // duration  	  nr.insertCell(4); // end	                    setSeqTabCellText  (i+1,0,i+1,"center");	  setSeqTabCellInput (i+1,1,8,nsToStr(document.SeqTab[i][0] - tim),specifyDelay,showDelay);	  setSeqTabCellInput (i+1,2,8,nsToStr(document.SeqTab[i][0]),specifyStart,showStart);	  tim=document.SeqTab[i][0];	  setSeqTabCellInput (i+1,3,8,nsToStr(document.SeqTab[i][1] - tim),specifyDuration,showDuration);	  setSeqTabCellInput (i+1,4,8,nsToStr(document.SeqTab[i][1]),specifyEnd,showEnd);	  tim=document.SeqTab[i][1];	}}// ===================================================================================function initSeqTab() {	document.SeqTab=new Array(new Array(0,10)); //format start(ns), endns)	document.SeqTabLen=document.SeqTab.length;	document.tabP=document.getElementById('tableSeq');	rebuildSeqTab();}// ===================================================================================

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -