OSDN Git Service

フィルムシミュレーションを変えられるようにした。(これで機能は一通り。)
[gokigen/FujiCam.git] / app / src / main / java / net / osdn / gokigen / cameratest / fuji / Connection.java
index 2efc02d..c48c972 100644 (file)
@@ -23,6 +23,7 @@ public class Connection implements IFujiStatusRequest
     private final MessageSequence sequence;
     private final Communication comm;
     private final FujiStatusChecker statusChecker;
+    private boolean pauseRequestStatus = false;
 
     public Connection(@NonNull Activity activity, @NonNull ILiveViewImage imageViewer, @NonNull IFujiStatusNotify notify)
     {
@@ -54,7 +55,7 @@ public class Connection implements IFujiStatusRequest
             ReceivedDataHolder rx_bytes;
             comm.connect_socket();
 
-            comm.send_to_camera(sequence.registration_message(), false);
+            comm.send_to_camera(sequence.registration_message(), false, false);
             rx_bytes = comm.receive_from_camera();
             dump_bytes(0, rx_bytes);
             Thread.sleep(50);
@@ -73,19 +74,19 @@ public class Connection implements IFujiStatusRequest
             }
 
             // start_messageを送信
-            comm.send_to_camera(sequence.start_message(), true);
+            comm.send_to_camera(sequence.start_message(), true, true);
             rx_bytes = comm.receive_from_camera();
             dump_bytes(1, rx_bytes);
             Thread.sleep(50);
 
             //  なんだろう?? (送信が必要なようだが)
-            comm.send_to_camera(sequence.start_message2(), true);
+            comm.send_to_camera(sequence.start_message2(), true, true);
             rx_bytes = comm.receive_from_camera();
             dump_bytes(2, rx_bytes);
             Thread.sleep(50);
 
             // two_part messageを発行 (その1)
-            comm.send_to_camera(sequence.start_message3_1(), true);
+            comm.send_to_camera(sequence.start_message3_1(), true, true);
             rx_bytes = comm.receive_from_camera();
             dump_bytes(3, rx_bytes);
             Thread.sleep(50);
@@ -93,14 +94,14 @@ public class Connection implements IFujiStatusRequest
             if (rx_bytes.getData().length <= 50)
             {
                 // two_part messageを発行 (その2)
-                comm.send_to_camera(sequence.start_message3_2(), false);
+                comm.send_to_camera(sequence.start_message3_2(), false, false);
                 rx_bytes = comm.receive_from_camera();
                 dump_bytes(4, rx_bytes);
                 Thread.sleep(50);
             }
 
             // remote mode
-            comm.send_to_camera(sequence.start_message4(), true);
+            comm.send_to_camera(sequence.start_message4(), true, true);
             rx_bytes = comm.receive_from_camera();
             dump_bytes(5, rx_bytes);
             Thread.sleep(50);
@@ -108,38 +109,38 @@ public class Connection implements IFujiStatusRequest
             if (!isBothLiveView)
             {
                 // two_part messageを発行 (その1)
-                comm.send_to_camera(sequence.start_message5_1(), true);
+                comm.send_to_camera(sequence.start_message5_1(), true, false);
                 rx_bytes = comm.receive_from_camera();
                 dump_bytes(6, rx_bytes);
                 Thread.sleep(50);
 
                 // two_part messageを発行 (その2)
-                comm.send_to_camera(sequence.start_message5_2(), false);
+                comm.send_to_camera(sequence.start_message5_2(), true, true);
                 rx_bytes = comm.receive_from_camera();
                 dump_bytes(7, rx_bytes);
                 Thread.sleep(50);
 
                 // ????
-                comm.send_to_camera(sequence.start_message6(), true);
+                comm.send_to_camera(sequence.start_message6(), true, true);
                 rx_bytes = comm.receive_from_camera();
                 dump_bytes(8, rx_bytes);
                 Thread.sleep(50);
 
                 // ????
-                comm.send_to_camera(sequence.start_message7(), true);
+                comm.send_to_camera(sequence.query_camera_capabilities(), true, true);
                 rx_bytes = comm.receive_from_camera();
                 dump_bytes(9, rx_bytes);
                 Thread.sleep(50);
 
                 // ????
-                comm.send_to_camera(sequence.start_message8(), true);
+                comm.send_to_camera(sequence.start_message8(), true, true);
                 rx_bytes = comm.receive_from_camera();
                 dump_bytes(10, rx_bytes);
                 Thread.sleep(50);
             }
 
             // リモート制御の開始!
-            comm.send_to_camera(sequence.camera_remote_message(), true);
+            comm.send_to_camera(sequence.camera_remote_message(), true, true);
 
             // 応答OKの場合は、8バイト ({0x03, 0x00, 0x01, 0x20} + {0x10, 0x02, 0x00, 0x00} )が応答されるはず
             rx_bytes = comm.receive_from_camera();
@@ -166,7 +167,7 @@ public class Connection implements IFujiStatusRequest
     {
         try
         {
-            comm.send_to_camera(sequence.reset_message(), true);
+            comm.send_to_camera(sequence.reset_message(), true, true);
             ReceivedDataHolder rx_bytes = comm.receive_from_camera();
             dump_bytes(0, rx_bytes);
             statusChecker.stop();
@@ -217,9 +218,14 @@ public class Connection implements IFujiStatusRequest
     @Override
     public boolean requestStatus()
     {
+        if (pauseRequestStatus)
+        {
+            // ステータス更新を一時停止する。
+            return (false);
+        }
         try
         {
-            comm.send_to_camera(sequence.status_request_message(), true);
+            comm.send_to_camera(sequence.status_request_message(), true, true);
             ReceivedDataHolder rx_bytes = comm.receive_from_camera();
             if (rx_bytes.getData().length > 0)
             {
@@ -268,7 +274,7 @@ public class Connection implements IFujiStatusRequest
             byte y = (byte) (0x000000ff & Math.round(point.y));
             Log.v(TAG, "DRIVE AF (" + x + "," + y + ")");
 
-            comm.send_to_camera(sequence.execute_focus_lock(x, y), true);
+            comm.send_to_camera(sequence.execute_focus_lock(x, y), true, true);
 
             ReceivedDataHolder rx_bytes = comm.receive_from_camera();
             dump_bytes(16, rx_bytes);
@@ -291,7 +297,7 @@ public class Connection implements IFujiStatusRequest
             {
                 currentValue = FILM_SIMULATION_MIN;
             }
-            return (updateProperty(FILM_SIMULATION, currentValue));
+            return (updateProperty(FILM_SIMULATION, currentValue, true));
         }
         catch (Exception e)
         {
@@ -311,12 +317,30 @@ public class Connection implements IFujiStatusRequest
             {
                 currentValue = IMAGE_ASPECT_MIN;
             }
-            return (updateProperty(IMAGE_ASPECT, currentValue));
+            return (updateProperty(IMAGE_ASPECT, currentValue, true));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+    public boolean execute_query_camera_capability()
+    {
+        pauseRequestStatus = true;
+        try
+        {
+            comm.send_to_camera(sequence.query_camera_capabilities(), true, true);
+            Thread.sleep(50);
+            ReceivedDataHolder rx_bytes = comm.receive_from_camera();
+            dump_bytes(21, rx_bytes);
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
+        pauseRequestStatus = false;
         return (false);
     }
 
@@ -325,7 +349,7 @@ public class Connection implements IFujiStatusRequest
     {
         try
         {
-            comm.send_to_camera(sequence.execute_focus_unlock(), true);
+            comm.send_to_camera(sequence.execute_focus_unlock(), true, true);
 
             ReceivedDataHolder rx_bytes = comm.receive_from_camera();
             dump_bytes(17, rx_bytes);
@@ -341,7 +365,7 @@ public class Connection implements IFujiStatusRequest
     {
         try
         {
-            comm.send_to_camera(sequence.execute_shutter_message(), true);
+            comm.send_to_camera(sequence.execute_shutter_message(), true, true);
 
             ReceivedDataHolder rx_bytes = comm.receive_from_camera();
             dump_bytes(14, rx_bytes);
@@ -353,8 +377,9 @@ public class Connection implements IFujiStatusRequest
         return (false);
     }
 
-    public boolean updateProperty(int commandCode, int setValue)
+    private boolean updateProperty(int commandCode, int setValue, boolean isShort)
     {
+        pauseRequestStatus = true;
         ReceivedDataHolder rx_bytes;
         try {
             byte high = (byte) ((0x0000ff00 & commandCode) >> 8);
@@ -366,20 +391,28 @@ public class Connection implements IFujiStatusRequest
             byte data3 = (byte)((0x000000ff & setValue));
 
             // two_part messageを発行 (その1)
-            comm.send_to_camera(sequence.update_property_1(high, low), true);
+            comm.send_to_camera(sequence.update_property_1(high, low), true, false);
+            Thread.sleep(50);
             rx_bytes = comm.receive_from_camera();
-            dump_bytes(15, rx_bytes);
+            dump_bytes(19, rx_bytes);
+/*
+            // two_part messageを発行 (その1)  :  ダミーでもう一発...!
+            comm.send_to_camera(sequence.update_property_1(high, low), true, false);
             Thread.sleep(50);
-
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(15, rx_bytes);
+*/
             // two_part messageを発行 (その2)
-            comm.send_to_camera(sequence.update_property_2(data0, data1, data2, data3), false);
+            comm.send_to_camera((isShort) ? sequence.update_property_2(data2, data3) : sequence.update_property_2(data0, data1, data2, data3), true, true);
+            Thread.sleep(50);
             rx_bytes = comm.receive_from_camera();
-            dump_bytes(16, rx_bytes);
+            dump_bytes(20, rx_bytes);
         }
         catch (Exception e)
         {
             e.printStackTrace();
         }
+        pauseRequestStatus = false;
         return (false);
     }
 }