OSDN Git Service

wits update
[vem/WITs.git] / JS / realtimeCamera.js
old mode 100644 (file)
new mode 100755 (executable)
index 9e2a82f..e633aba
@@ -1,6 +1,6 @@
-
 var ws ;
 var i = 0;
+var toggleSwitch =0;
 var params = {
   size : 0,
   binninb : 1,
@@ -12,29 +12,89 @@ var UrlElement = userSetting.GetUrlElementInstance();
 var hello = userSetting.sayHello;
 console.log(UrlElement['sendIpAddress']);
 
-function conectionStart(){
+/*function
+wsConnectionSwitch();
+apiConnectionSwitch();
+setParams();
+settings()
+connection()
+image()
+simplePhotoCamera()
+
+*/
+
+
+
+function wsConnectionSwitch(){
+  setParams();
+  var data;
+  toggleSwitch ^= 1 ;
+  switch(toggleSwitch){
+    case 1:
  ws = new WebSocket("ws://"+UrlElement['sendIpAddress']+":3001");
   ws.onopen = function(){
+    console.log('websocket connected')
   //  ws.send('req');
   };
-/*  ws.onerror = function(error){
-    console.log('websocket error' + error);
-  };*/
+  document.getElementById("wsConnectBtn").value = "websocket close";
   ws.onmessage = function(ture){
     data = JSON.parse(ture.data)
     console.log('server:' +data["type"]);
-    switch(data["type"]){
-      case "connection":
-      connection(data);
-      break;
-
-      case "img":
-      image(data);
-      break;
-    }
+  switch(data["type"]){
+    case "connection":
+    connection(data);
+    break;
+
+    case "img":
+    image(data);
+    break;
+  }
+};
+  break;
+
+  case 0:
+    ws.close();
+    console.log('closed');
+    document.getElementById("wsConnectBtn").value = "websocket start";
+    break;
   }
 }
 
+function apiConnectionSwitch(){
+toggleSwitch ^= 1;
+switch(toggleSwitch){
+  case 1:
+  //start
+  $.ajax({
+    type:"GET",
+    url:"http://" +UrlElement['sendIpAddress']+
+    ":"+UrlElement['sendPortNumber']+"/"+UrlElement['sendManufacturer']+
+    "/set/",
+    success: function(data){
+      console.log(data);//string型
+    }
+  });
+  document.getElementById("apiConnectBtn").value = "API close";
+  break;
+
+  case 0:
+//stop
+  $.ajax({
+    type:"GET",
+    url:"http://" +UrlElement['sendIpAddress']+
+    ":"+UrlElement['sendPortNumber']+"/"+UrlElement['sendManufacturer']+
+    "/set/",
+    success: function(data){
+      console.log(data);//string型
+    }
+  });
+  document.getElementById("apiConnectBtn").value = "API start";
+  break;
+};
+}
+
+
+
 function setParams(){
   settings();
 }
@@ -48,7 +108,7 @@ function settings(){
   }
   $.ajax({
     type:"GET",
-    url:"http://"+$ipAddress+":"+$port+"/fei/set/acq_init?bng="+params["binning"]+"&&exp="+params["exptime"]+"&&size="+params["size"],
+    url:"http://"+UrlElement["sendipAddress"]+":"+UrlElement["sendPortNumber"]+"/"+UrlElement["sendManufacturer"]+"/set/acq_init?bng="+params["binning"]+"&&exp="+params["exptime"]+"&&size="+params["size"],
     success: function(data){
     }
   });
@@ -59,21 +119,94 @@ ws.send('{"type":"req", "data":"img"}');
 }
 
 function image(data){
-console.log(data);
   ws.send('{"type":"req", "data":"img"}');
   drawMycrograph(data.data);
 }
 
-function connectionClose(){
-  ws.close();
+
+function simplePhotoCamera(){
+  var simplePhotoImage = $("canvasOne").val();
 
 }
 
+window.onload=canvasMap;
+function canvasMap(){
+  var canvas = document.getElementById("canvasMap");
+  var ctx = canvas.getContext("2d");
+  var x = $("#movex").val();
+  var y = $("#movey").val();
+  var z = $("#movez").val();
+  var a = $("#movea").val();
 
+  ctx.beginPath();
+  ctx.fillStyle = "#808080";
+  ctx.arc(100,100,100,0,Math.PI*2,true);
+  ctx.fill();
+  ctx.closePath();
 
-function simplePhotoCamera(){
-  var simplePhotoImage = $("canvasOne").val();
 
+  canvas.addEventListener("mousedown",function(e){
+    $.ajax({
+      type:"GET",
+      url:"http://"+UrlElement['sendIpAddress']+
+      ":"+UrlElement['sendPortNumber']+
+      "/"+UrlElement['sendManufacturer']+
+      "/set/stagea?x="+encodeURIComponent(movexr)+
+      "&y="+encodeURIComponent(moveyr)+
+      "&z="+encodeURIComponent(movezr)+
+      "&a="+encodeURIComponent(movezr),
+      success: function(data){
+        console.log(data);
+      }
+    });
+  });
+}
 
+/*
+function canvasMapDraw(){
+  var step = (1/2000);//倍率変化はここの通知を変化
+  var canvas = document.getElementById("canvasMap");
+  var ctx = canvas.getContext("2d");
+  var x = $("#movex").val();
+  var y = $("#movey").val();
+  if(x == 0 || y==0){
+  ctx.beginPath();
+  ctx.fillStyle = "#000000";
+  ctx.moveTo(100,100);
+  ctx.lineTo((parseInt(x)*step+100,-(parseInt(y)*step)+100);
+  //ctx.lineTo(150,100)
+  ctx.closePath();
+  ctx.stroke();
+  moveX = (parseInt(x)*step)+100;
+  moveY = -(parseInt(y)*step)+100;
+}
+  else if(x !=0 || y!= 0){
+  ctx.beginPath();
+  ctx.fillStyle = "#000000";
+  ctx.moveTo(moveX,moveY);
+  ctx.lineTo((parseInt(x)*step+100,-(parseInt(y)*step)+100);
+  //ctx.lineTo(150,100)
+  ctx.closePath();
+  ctx.stroke();
+  moveX = (parseInt(x)*step)+100;
+  moveY = -(parseInt(y)*step)+100;
+}
+}
+*/
 
+/*window.onload = drawCanvasMap;
+function drawCanvasMap(){
+  var drawCanvas = document.getElementById("canvasMap");
+  var ctx = drawCanvas.getContext("2D");
+//  if(canvas.getContext){
+  var x = $("#movex").val();
+  var y = $("#movey").val();
+  ctx.fillStyle = "#000000";
+  ctx.beginPath();
+  ctx.moveTo(parseInt(x)+100,parseInt(y)+100);
+  ctx.lineTo(150,100);
+  ctx.closePath();
+  ctx.stroke();
+//}
 }
+*/