OSDN Git Service

設定変える準備を搭載。
[gokigen/FujiCam.git] / app / src / main / java / net / osdn / gokigen / cameratest / fuji / Connection.java
index b0122f7..2efc02d 100644 (file)
@@ -1,5 +1,6 @@
 package net.osdn.gokigen.cameratest.fuji;
 
+import android.app.Activity;
 import android.graphics.PointF;
 import android.util.Log;
 
@@ -9,6 +10,13 @@ import net.osdn.gokigen.cameratest.fuji.statuses.FujiStatusChecker;
 import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusNotify;
 import net.osdn.gokigen.cameratest.fuji.statuses.IFujiStatusRequest;
 
+import static net.osdn.gokigen.cameratest.fuji.statuses.IFujiCameraProperties.FILM_SIMULATION;
+import static net.osdn.gokigen.cameratest.fuji.statuses.IFujiCameraProperties.IMAGE_ASPECT;
+import static net.osdn.gokigen.cameratest.fuji.statuses.IFujiCameraPropertyValues.FILM_SIMULATION_MAX;
+import static net.osdn.gokigen.cameratest.fuji.statuses.IFujiCameraPropertyValues.FILM_SIMULATION_MIN;
+import static net.osdn.gokigen.cameratest.fuji.statuses.IFujiCameraPropertyValues.IMAGE_ASPECT_MAX;
+import static net.osdn.gokigen.cameratest.fuji.statuses.IFujiCameraPropertyValues.IMAGE_ASPECT_MIN;
+
 public class Connection implements IFujiStatusRequest
 {
     private final String TAG = toString();
@@ -16,9 +24,9 @@ public class Connection implements IFujiStatusRequest
     private final Communication comm;
     private final FujiStatusChecker statusChecker;
 
-    public Connection(@NonNull ILiveViewImage imageViewer, @NonNull IFujiStatusNotify notify)
+    public Connection(@NonNull Activity activity, @NonNull ILiveViewImage imageViewer, @NonNull IFujiStatusNotify notify)
     {
-        this.comm = new Communication(imageViewer);
+        this.comm = new Communication(activity, imageViewer);
         this.sequence = new MessageSequence();
         this.statusChecker = new FujiStatusChecker(this, notify);
     }
@@ -272,6 +280,47 @@ public class Connection implements IFujiStatusRequest
         return (false);
     }
 
+    public boolean execute_change_film_simulation()
+    {
+        try
+        {
+            // 現在の値を入手
+            int currentValue = statusChecker.getValue(FILM_SIMULATION);
+            currentValue++;
+            if (currentValue > FILM_SIMULATION_MAX)
+            {
+                currentValue = FILM_SIMULATION_MIN;
+            }
+            return (updateProperty(FILM_SIMULATION, currentValue));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+    public boolean execute_change_image_aspect()
+    {
+        try
+        {
+            // 現在の値を入手
+            int currentValue = statusChecker.getValue(IMAGE_ASPECT);
+            currentValue++;
+            if (currentValue > IMAGE_ASPECT_MAX)
+            {
+                currentValue = IMAGE_ASPECT_MIN;
+            }
+            return (updateProperty(IMAGE_ASPECT, currentValue));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+
     public boolean execute_unlock_focus()
     {
         try
@@ -303,4 +352,34 @@ public class Connection implements IFujiStatusRequest
         }
         return (false);
     }
+
+    public boolean updateProperty(int commandCode, int setValue)
+    {
+        ReceivedDataHolder rx_bytes;
+        try {
+            byte high = (byte) ((0x0000ff00 & commandCode) >> 8);
+            byte low = (byte) (0x000000ff & commandCode);
+
+            byte data0 = (byte)((0xff000000 & setValue) >> 24);
+            byte data1 = (byte)((0x00ff0000 & setValue) >> 16);
+            byte data2 = (byte)((0x0000ff00 & setValue) >> 8);
+            byte data3 = (byte)((0x000000ff & setValue));
+
+            // two_part messageを発行 (その1)
+            comm.send_to_camera(sequence.update_property_1(high, low), true);
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(15, rx_bytes);
+            Thread.sleep(50);
+
+            // two_part messageを発行 (その2)
+            comm.send_to_camera(sequence.update_property_2(data0, data1, data2, data3), false);
+            rx_bytes = comm.receive_from_camera();
+            dump_bytes(16, rx_bytes);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
 }