OSDN Git Service

wits update
[vem/WITs.git] / JS / realtimeCamera.js
1 var ws ;
2 var i = 0;
3 var toggleSwitch =0;
4 var params = {
5   size : 0,
6   binninb : 1,
7   exptime : 1
8 };
9 // インスタンス化
10 var userSetting = new GetUrlElement();
11 var UrlElement = userSetting.GetUrlElementInstance();
12 var hello = userSetting.sayHello;
13 console.log(UrlElement['sendIpAddress']);
14
15 /*function
16 wsConnectionSwitch();
17 apiConnectionSwitch();
18 setParams();
19 settings()
20 connection()
21 image()
22 simplePhotoCamera()
23
24 */
25
26
27
28 function wsConnectionSwitch(){
29   setParams();
30   var data;
31   toggleSwitch ^= 1 ;
32   switch(toggleSwitch){
33     case 1:
34  ws = new WebSocket("ws://"+UrlElement['sendIpAddress']+":3001");
35   ws.onopen = function(){
36     console.log('websocket connected')
37   //  ws.send('req');
38   };
39   document.getElementById("wsConnectBtn").value = "websocket close";
40   ws.onmessage = function(ture){
41     data = JSON.parse(ture.data)
42     console.log('server:' +data["type"]);
43   switch(data["type"]){
44     case "connection":
45     connection(data);
46     break;
47
48     case "img":
49     image(data);
50     break;
51   }
52 };
53   break;
54
55   case 0:
56     ws.close();
57     console.log('closed');
58     document.getElementById("wsConnectBtn").value = "websocket start";
59     break;
60   }
61 }
62
63 function apiConnectionSwitch(){
64 toggleSwitch ^= 1;
65 switch(toggleSwitch){
66   case 1:
67   //start
68   $.ajax({
69     type:"GET",
70     url:"http://" +UrlElement['sendIpAddress']+
71     ":"+UrlElement['sendPortNumber']+"/"+UrlElement['sendManufacturer']+
72     "/set/",
73     success: function(data){
74       console.log(data);//string型
75     }
76   });
77   document.getElementById("apiConnectBtn").value = "API close";
78   break;
79
80   case 0:
81 //stop
82   $.ajax({
83     type:"GET",
84     url:"http://" +UrlElement['sendIpAddress']+
85     ":"+UrlElement['sendPortNumber']+"/"+UrlElement['sendManufacturer']+
86     "/set/",
87     success: function(data){
88       console.log(data);//string型
89     }
90   });
91   document.getElementById("apiConnectBtn").value = "API start";
92   break;
93 };
94 }
95
96
97
98 function setParams(){
99   settings();
100 }
101
102 function settings(){
103   params["size"] = $( "#size option:selected" ).val();
104   var exptime = $( "#exptime" ).val();
105   if( 1 >= exptime && exptime >= 0.01){
106     params["exptime"] = exptime;
107     params["binning"] = $( "#binning option:selected" ).val();
108   }
109   $.ajax({
110     type:"GET",
111     url:"http://"+UrlElement["sendipAddress"]+":"+UrlElement["sendPortNumber"]+"/"+UrlElement["sendManufacturer"]+"/set/acq_init?bng="+params["binning"]+"&&exp="+params["exptime"]+"&&size="+params["size"],
112     success: function(data){
113     }
114   });
115 }
116
117 function connection(data){
118 ws.send('{"type":"req", "data":"img"}');
119 }
120
121 function image(data){
122   ws.send('{"type":"req", "data":"img"}');
123   drawMycrograph(data.data);
124 }
125
126
127 function simplePhotoCamera(){
128   var simplePhotoImage = $("canvasOne").val();
129
130 }
131
132 window.onload=canvasMap;
133 function canvasMap(){
134   var canvas = document.getElementById("canvasMap");
135   var ctx = canvas.getContext("2d");
136   var x = $("#movex").val();
137   var y = $("#movey").val();
138   var z = $("#movez").val();
139   var a = $("#movea").val();
140
141   ctx.beginPath();
142   ctx.fillStyle = "#808080";
143   ctx.arc(100,100,100,0,Math.PI*2,true);
144   ctx.fill();
145   ctx.closePath();
146
147
148   canvas.addEventListener("mousedown",function(e){
149     $.ajax({
150       type:"GET",
151       url:"http://"+UrlElement['sendIpAddress']+
152       ":"+UrlElement['sendPortNumber']+
153       "/"+UrlElement['sendManufacturer']+
154       "/set/stagea?x="+encodeURIComponent(movexr)+
155       "&y="+encodeURIComponent(moveyr)+
156       "&z="+encodeURIComponent(movezr)+
157       "&a="+encodeURIComponent(movezr),
158       success: function(data){
159         console.log(data);
160       }
161     });
162   });
163 }
164
165 /*
166 function canvasMapDraw(){
167   var step = (1/2000);//倍率変化はここの通知を変化
168   var canvas = document.getElementById("canvasMap");
169   var ctx = canvas.getContext("2d");
170   var x = $("#movex").val();
171   var y = $("#movey").val();
172   if(x == 0 || y==0){
173   ctx.beginPath();
174   ctx.fillStyle = "#000000";
175   ctx.moveTo(100,100);
176   ctx.lineTo((parseInt(x)*step+100,-(parseInt(y)*step)+100);
177   //ctx.lineTo(150,100)
178   ctx.closePath();
179   ctx.stroke();
180   moveX = (parseInt(x)*step)+100;
181   moveY = -(parseInt(y)*step)+100;
182 }
183   else if(x !=0 || y!= 0){
184   ctx.beginPath();
185   ctx.fillStyle = "#000000";
186   ctx.moveTo(moveX,moveY);
187   ctx.lineTo((parseInt(x)*step+100,-(parseInt(y)*step)+100);
188   //ctx.lineTo(150,100)
189   ctx.closePath();
190   ctx.stroke();
191   moveX = (parseInt(x)*step)+100;
192   moveY = -(parseInt(y)*step)+100;
193 }
194 }
195 */
196
197 /*window.onload = drawCanvasMap;
198 function drawCanvasMap(){
199   var drawCanvas = document.getElementById("canvasMap");
200   var ctx = drawCanvas.getContext("2D");
201 //  if(canvas.getContext){
202   var x = $("#movex").val();
203   var y = $("#movey").val();
204   ctx.fillStyle = "#000000";
205   ctx.beginPath();
206   ctx.moveTo(parseInt(x)+100,parseInt(y)+100);
207   ctx.lineTo(150,100);
208   ctx.closePath();
209   ctx.stroke();
210 //}
211 }
212 */