OSDN Git Service

GR2専用コマンドを、GR2と接続したときにだけ有効にするように仕様を変更した。
[gokigen/Gr2Control.git] / app / src / main / java / net / osdn / gokigen / gr2control / camera / ricohgr2 / wrapper / RicohGr2StatusChecker.java
index 3f19eff..75d6eb7 100644 (file)
@@ -1,6 +1,5 @@
 package net.osdn.gokigen.gr2control.camera.ricohgr2.wrapper;
 
-import android.support.annotation.NonNull;
 import android.util.Log;
 
 import net.osdn.gokigen.gr2control.camera.ICameraStatus;
@@ -11,6 +10,8 @@ import net.osdn.gokigen.gr2control.liveview.ICameraStatusUpdateNotify;
 import java.util.ArrayList;
 import java.util.List;
 
+import androidx.annotation.NonNull;
+
 /**
  *
  *
@@ -26,6 +27,7 @@ public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatu
     private int timeoutMs = 5000;
     private boolean whileFetching = false;
     private RicohGr2StatusHolder statusHolder;
+    private boolean useGR2command = false;
 
     /**
      *
@@ -36,6 +38,11 @@ public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatu
         this.sleepMs = sleepMs;
     }
 
+    public void setUseGR2Command(boolean useGR2command)
+    {
+        this.useGR2command = useGR2command;
+    }
+
     /**
      *
      *
@@ -75,7 +82,7 @@ public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatu
      *
      */
     @Override
-    public void stoptStatusWatch()
+    public void stopStatusWatch()
     {
         Log.v(TAG, "stoptStatusWatch()");
         whileFetching = false;
@@ -170,13 +177,25 @@ public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatu
             public void run() {
                 try
                 {
+                    String response;
                     String postData = key + "=" + value;
-                    String response = SimpleHttpClient.httpPut(statusSetUrl, postData, timeoutMs);
-                    Log.v(TAG, "SET PROPERTY : " + postData + " resp. (" + response.length() + "bytes.)");
-
-                    //  GR専用コマンドで、画面表示をリフレッシュ
-                    response = SimpleHttpClient.httpPost(grCommandUrl, "cmd=mode refresh", timeoutMs);
-                    Log.v(TAG, "refresh resp. (" + response.length() + "bytes.)");
+                    if ((useGR2command)&&(key.equals("exposureMode")))
+                    {
+                        //  撮影モードを変更するときは、GR専用コマンドを送ることにする。
+                        postData = "cmd=" + decideButtonCode(value);
+                        response = SimpleHttpClient.httpPost(grCommandUrl, postData, timeoutMs);
+                        Log.v(TAG, "CHANGE MODE : " + postData + " resp. (" + response.length() + "bytes.)");
+                    } else {
+                        // 通常の変更コマンド
+                        response = SimpleHttpClient.httpPut(statusSetUrl, postData, timeoutMs);
+                        Log.v(TAG, "SET PROPERTY : " + postData + " resp. (" + response.length() + "bytes.)");
+                    }
+                    if (useGR2command)
+                    {
+                        //  GR専用コマンドで、画面表示をリフレッシュ
+                        response = SimpleHttpClient.httpPost(grCommandUrl, "cmd=mode refresh", timeoutMs);
+                        Log.v(TAG, "refresh resp. (" + response.length() + "bytes.)");
+                    }
                 }
                 catch (Exception e)
                 {
@@ -193,4 +212,42 @@ public class RicohGr2StatusChecker implements ICameraStatusWatcher, ICameraStatu
             e.printStackTrace();
         }
     }
+
+    /**
+     *   撮影モードをGRのダイアルコマンドに変更する
+     *
+     */
+    private String decideButtonCode(String exposureMode)
+    {
+        String buttonCode = "bdial AUTO";
+        if (exposureMode == null)
+        {
+            return (buttonCode);
+        }
+        switch (exposureMode)
+        {
+            case "movie":
+                buttonCode = "bdial MOVIE";
+                break;
+            case "M":
+                buttonCode = "bdial M";
+                break;
+            case "TAV":
+                buttonCode = "bdial TAV";
+                break;
+            case "AV":
+                buttonCode = "bdial AV";
+                break;
+            case "TV":
+                buttonCode = "bdial TV";
+                break;
+            case "P":
+                buttonCode = "bdial P";
+                break;
+            case "auto":
+                buttonCode = "bdial AUTO";
+                break;
+        }
+        return (buttonCode);
+    }
 }