OSDN Git Service

カメラサーバーとviewを変更
authorayaka <gyzdisk@gmail.com>
Wed, 11 Nov 2015 22:05:31 +0000 (07:05 +0900)
committerayaka <gyzdisk@gmail.com>
Wed, 11 Nov 2015 22:05:31 +0000 (07:05 +0900)
test/server/cameraServer.rb
test/view/img.html
test/view/img.js
test/view/mock/img.html
test/view/mock/img.js

index 0e0b87e..edad5d5 100644 (file)
@@ -13,11 +13,13 @@ EM::WebSocket.start(host: "localhost", port:3000) do |ws|
   # 接続確立時の処理
   ws.onopen do
     puts "WebSocket connection open"
-    ws.send("init")
   end
 
   # メッセージ受信時の処理
-  ws.onmessage do |message|
+  ws.onmessage do |recBuf|
+    puts recBuf
+    puts recBuf.type
+
     if(message=="acq")
       # 画像配列の取得
       result = @@vem.acquisition
index 06f42bb..994be0b 100644 (file)
@@ -6,5 +6,6 @@
         <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
         <script src="img.js"></script>
         <canvas id="test" width="256" height="256"></canvas>
+        <button>start</button>
     </body>
 </html>
index 5fca9e4..341d285 100644 (file)
@@ -1,5 +1,42 @@
-var ws = new  WebSocket("ws://192.168.4.145:3000");
-var i = 0;
+var ws     // WebSocket
+var i = 0; // 画像取得回数カウント用
+
+
+$( function(){
+  $( "button" ).toggle( startAcq, stopAcq );
+} );
+
+
+function startAcq(){
+  $( "button" ).text( "stop" );
+
+  // サーバーとWebSocket接続
+  ws = new WebSocket( "ws://192.168.4.145:3000" );
+
+  // メッセージ受信時の処理
+  ws.onmessage = function( event ){
+    if( event.data = "init" ){
+      ws.send( "acq" );
+    }else{
+      ws.send( "acq" );
+      draw( JSON.parse(event.data) );
+      console.log(i);
+      i = i + 1;
+    }
+  }
+
+}
+
+
+function stopAcq(){
+  $( "button" ).text( "start" );
+
+  // サーバーとの通信を切断
+  ws.close( 1000, "close");
+
+  console.log("stop");
+}
+
 
 function draw(data){
   var ctx;
@@ -30,16 +67,3 @@ function draw(data){
   // CanvasのコンテキストにImageDataを設定
   ctx.putImageData(imgData, 0, 0);
 }
-
-// メッセージ受信時の処理
-ws.onmessage = function(event){
-  if(event.data=="init"){
-    ws.send("acq")
-  }else{
-    ws.send("acq");
-    draw(event.data);
-    console.log(i);
-    i = i + 1;
-  }
-};
-
index 90c1a47..4274019 100644 (file)
@@ -5,7 +5,21 @@
         <script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
         <script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
         <script src="img.js"></script>
+        
         <canvas id="test" width="512" height="512"></canvas>
-        <button>start</button>
+
+        <select id="size" name="size">
+          <option value="0">full</option>
+          <option value="1">half</option>
+          <option value="2">quarter</option>
+        </select>
+
+        <select id="binning" name="binning">
+          <option value="1">1</option>
+          <option value="2">2</option>
+          <option value="4">4</option>
+        </select>
+
+        <button id="acqButton">start</button>
       </body>
 </html>
index 32094d5..37ca410 100644 (file)
@@ -1,37 +1,80 @@
-var ws      // WebSocket
-var i = 0;  // 画像取得回数カウント用
+var ws           // WebSocket
+var i = 0;       // 画像取得回数カウント用
+var settings = {
+  size : 0,      // 画像サイズ
+  binning : 1    // ビニング
+};
+var sendBuf = {
+  "type" : 0,
+  "msg"  : 0
+};
 
 
 $(function(){
-  $("button").toggle(startAcq, stopAcq);
+
+  $( "#acqButton" ).toggle( startAcq, stopAcq) ;
+
+  $( "#size" ).change( changeSize ) ;
+
+  $( "#binning" ).change( changeBinning );
+
 });
 
 
 function startAcq(){
-  $("button").text("stop");
+  $( "#acqButton" ).text( "stop" );
+
   // サーバーとWebSocket接続
-  ws = new WebSocket("ws://localhost:3000");
-  // メッセージ受信時の処理
-  ws.onmessage = function(event){
-    if(event.data=="init"){
-      ws.send("acq");
-    }else{
-      ws.send("acq");
-      draw(JSON.parse(event.data));
-      console.log(i);
-      i = i + 1;
-    }
-  };
+  ws = new WebSocket( "ws://localhost:3000" );
+
+  sendSettings();
+
+ // serialAcq;
 }
 
 
 function stopAcq(){
-  $("button").text("start");
+  $( "#acqButton" ).text( "start" );
   console.log("stop");
   ws.close(1000, "close");
 }
 
 
+function changeSize(){
+  settings[size] = $( "#size option:selected" ).val();
+  console.log(settings[size]);
+}
+
+
+function changeBinning(){
+  settings[binning] = $( "#binning option:selected" ).val();
+  console.log(settings[binning]);
+}
+
+
+function sendSettings(){
+  sendBuf["type"] = "settings";
+  sendBuf["msg"]  = settings;
+  ws.send("aaa");
+  console.log( "send " + JSON.stringify(sendBuf) ); }
+
+
+function serialAcq(){
+  // メッセージ受信時の処理
+  ws.onmessage = function( event ){
+    if( event.data == "init" ){
+      ws.send( "acq" );
+    }else{
+      ws.send( "acq" );
+      draw( JSON.parse(event.data ));
+      console.log(i);
+      i = i + 1;
+    }
+  }
+}
+
+
+
 // 描画
 function draw(data){
   var ctx;