OSDN Git Service

g06だと安定していた。g06+での安定模索中。
authorMRSa <mrsa@myad.jp>
Sun, 8 Mar 2020 12:07:07 +0000 (21:07 +0900)
committerMRSa <mrsa@myad.jp>
Sun, 8 Mar 2020 12:07:07 +0000 (21:07 +0900)
app/src/main/java/net/osdn/gokigen/a01d/camera/canon/wrapper/CanonInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/operation/NikonFocusingControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/NikonInterfaceProvider.java
app/src/main/java/net/osdn/gokigen/a01d/camera/nikon/wrapper/liveview/NikonLiveViewControl.java
app/src/main/java/net/osdn/gokigen/a01d/camera/ptpip/wrapper/command/PtpIpCommandPublisher.java
app/src/main/java/net/osdn/gokigen/a01d/preference/IPreferencePropertyAccessor.java
app/src/main/java/net/osdn/gokigen/a01d/preference/nikon/NikonPreferenceFragment.java
app/src/main/res/values-ja/strings.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/preferences_nikon.xml
build.gradle

index 5100eb7..d5f0820 100644 (file)
@@ -63,7 +63,7 @@ public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
     public CanonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
     {
         this.activity = context;
-        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, false);
+        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, false, false);
         liveViewControl = new CanonLiveViewControl(context, this, 10);  //
         asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
         statusChecker = new CanonStatusChecker(context, commandPublisher, CAMERA_IP, EVENT_PORT);
index b6b3808..e1b323a 100644 (file)
@@ -34,7 +34,8 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
     private float maxPointLimitWidth;
     private float maxPointLimitHeight;
     private RectF preFocusFrameRect = null;
-    private boolean isDumpLog = false;
+    private boolean not_support_focus_lock = false;
+    private boolean isDumpLog = true;
 
     public NikonFocusingControl(@NonNull Activity context, @NonNull PtpIpCommandPublisher commandPublisher, IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator)
     {
@@ -57,7 +58,8 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
                 maxPointLimitWidth = 6000.0f;
                 maxPointLimitHeight = 4000.0f;
             }
-            Log.v(TAG, "FOCUS RESOLUTION : " + maxPointLimitWidth + "," + maxPointLimitHeight);
+            not_support_focus_lock = preferences.getBoolean(IPreferencePropertyAccessor.NIKON_NOT_SUPPORT_FOCUS_LOCK, false);
+            Log.v(TAG, "FOCUS RESOLUTION : " + maxPointLimitWidth + "," + maxPointLimitHeight + " FOCUS LOCK : " + not_support_focus_lock);
         }
         catch (Exception e)
         {
@@ -137,8 +139,11 @@ public class NikonFocusingControl implements IFocusingControl, IPtpIpCommandCall
             int x = (0x0000ffff & (Math.round(point.x * maxPointLimitWidth) + 1));
             int y = (0x0000ffff & (Math.round(point.y * maxPointLimitHeight) + 1));
             Log.v(TAG, "Lock AF: [" + x + ","+ y + "]");
-            commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_LOCK, isDumpLog, 0, 0x9205, 8, x, y));
-            //commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
+            if (!not_support_focus_lock) {
+                commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_LOCK, isDumpLog, 0, 0x9205, 8, x, y));
+            } else {
+                commandPublisher.enqueueCommand(new PtpIpCommandGeneric(this, FOCUS_MOVE, isDumpLog, 0, 0x90c1));
+            }
         }
         catch (Exception e)
         {
index 3494c7d..8f98e3a 100644 (file)
@@ -63,7 +63,7 @@ public class NikonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplay
     public NikonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
     {
         this.activity = context;
-        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, false);
+        commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, true, false);
         liveViewControl = new NikonLiveViewControl(context, this, 20);
         asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
         statusChecker = new NikonStatusChecker(activity, commandPublisher, CAMERA_IP, EVENT_PORT);
index cfb3eda..dc93d73 100644 (file)
@@ -199,11 +199,26 @@ public class NikonLiveViewControl  implements ILiveViewControl, ILiveViewListene
         {
             e.printStackTrace();
         }
-        //commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP1, 30, isDumpLog, 0, 0x1015, 4, 0x5007, 0x00, 0x00, 0x00));
-        commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHECK_EVENT, 30, isDumpLog, 0, 0x90c7, 0, 0x00, 0x00, 0x00, 0x00));
         commandIssued = false;
+        sendNextMessage();
     }
 
+    private void sendNextMessage()
+    {
+        try
+        {
+            Thread.sleep(delayMs);
+            //commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_GET_DEVICE_PROP1, 30, isDumpLog, 0, 0x1015, 4, 0x5007, 0x00, 0x00, 0x00));
+            //commandIssuer.enqueueCommand(new PtpIpCommandGeneric(this, SEQ_CHECK_EVENT, 30, isDumpLog, 0, 0x90c7, 0, 0x00, 0x00, 0x00, 0x00));
+            commandIssuer.enqueueCommand(new NikonLiveViewRequestMessage(imageReceiver, 35, isDumpLog));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
+
     private int searchJpegHeader(byte[] data)
     {
         try
index e0468d8..c4dd0af 100644 (file)
@@ -10,6 +10,7 @@ import java.io.BufferedReader;
 import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.InputStream;
+import java.net.InetSocketAddress;
 import java.net.Socket;
 import java.util.ArrayDeque;
 import java.util.Arrays;
@@ -33,6 +34,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
     private boolean isStart = false;
     private boolean isHold = false;
     private boolean tcpNoDelay;
+    private boolean waitForever;
     private int holdId = 0;
     private Socket socket = null;
     private DataOutputStream dos = null;
@@ -41,11 +43,12 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
     private Queue<IPtpIpCommand> commandQueue;
     private Queue<IPtpIpCommand> holdCommandQueue;
 
-    public PtpIpCommandPublisher(@NonNull String ip, int portNumber, boolean tcpNoDelay)
+    public PtpIpCommandPublisher(@NonNull String ip, int portNumber, boolean tcpNoDelay, boolean waitForever)
     {
         this.ipAddress = ip;
         this.portNumber = portNumber;
         this.tcpNoDelay = tcpNoDelay;
+        this.waitForever = waitForever;
         this.commandQueue = new ArrayDeque<>();
         this.holdCommandQueue = new ArrayDeque<>();
         commandQueue.clear();
@@ -64,11 +67,21 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
         try
         {
             Log.v(TAG, " connect()");
-            socket = new Socket(ipAddress, portNumber);
+            //socket = new Socket(ipAddress, portNumber);
+            socket = new Socket();
             socket.setTcpNoDelay(tcpNoDelay);
-            socket.setKeepAlive(true);
-            //socket.setReceiveBufferSize(32768);
-            //socket.setTrafficClass(0x10);
+            if (tcpNoDelay)
+            {
+                socket.setKeepAlive(false);
+                socket.setPerformancePreferences(0, 1, 0);
+                //socket.setSoLinger(true, 3000);
+                socket.setOOBInline(true);
+                socket.setReuseAddress(false);
+                //socket.setReceiveBufferSize(2097152);
+                //socket.setSendBufferSize(524288);
+                socket.setTrafficClass(0x80);
+            }
+            socket.connect(new InetSocketAddress(ipAddress, portNumber), 0);
             return (true);
         }
         catch (Exception e)
@@ -280,7 +293,11 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                 {
                     if (!command.isRetrySend())
                     {
-                        //  コマンドを再送信しない場合はここで抜ける
+                        while (retry_over)
+                        {
+                            //  コマンドを再送信しない場合はここで応答を待つ...
+                            retry_over = receive_from_camera(command);
+                        }
                         break;
                     }
                     if (!command.isIncrementSequenceNumberToRetry())
@@ -376,6 +393,19 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
         {
             delayMs = COMMAND_SEND_RECEIVE_DURATION_MS;
         }
+
+        try
+        {
+            if (socket != null)
+            {
+                Log.v(TAG, " SOCKET : send " + socket.getSendBufferSize() + "  recv " + socket.getReceiveBufferSize() + " " + socket.getTcpNoDelay() + " " + socket.getOOBInline() + " " + socket.getKeepAlive() + " " + socket.getReuseAddress() + " " + socket.getSoLinger() + " " + socket.getSoTimeout() + " " + socket.getTrafficClass());
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+
         if ((callback != null)&&(callback.isReceiveMulti()))
         {
             // 受信したら逐次「受信したよ」と応答するパターン
@@ -685,7 +715,7 @@ public class PtpIpCommandPublisher implements IPtpIpCommandPublisher, IPtpIpComm
                         isLogOutput = false;
                     }
                     retry_count--;
-                    if (retry_count < 0)
+                    if ((!waitForever)&&(retry_count < 0))
                     {
                         return (-1);
                     }
index 9b80768..eb60e36 100644 (file)
@@ -79,6 +79,8 @@ public interface IPreferencePropertyAccessor
     String NIKON_FOCUS_XY = "nikon_focus_xy";
     String NIKON_FOCUS_XY_DEFAULT_VALUE = "6000,4000";
 
+    String NIKON_NOT_SUPPORT_FOCUS_LOCK = "nikon_not_support_focus_lock";
+
  /*
     int CHOICE_SPLASH_SCREEN = 10;
 
index bdb6fab..9f1eb17 100644 (file)
@@ -127,6 +127,12 @@ public class NikonPreferenceFragment extends PreferenceFragmentCompat implements
             if (!items.containsKey(IPreferencePropertyAccessor.CONNECTION_METHOD)) {
                 editor.putString(IPreferencePropertyAccessor.CONNECTION_METHOD, IPreferencePropertyAccessor.CONNECTION_METHOD_DEFAULT_VALUE);
             }
+            if (!items.containsKey(IPreferencePropertyAccessor.NIKON_FOCUS_XY)) {
+                editor.putString(IPreferencePropertyAccessor.NIKON_FOCUS_XY, IPreferencePropertyAccessor.NIKON_FOCUS_XY_DEFAULT_VALUE);
+            }
+            if (!items.containsKey(IPreferencePropertyAccessor.NIKON_NOT_SUPPORT_FOCUS_LOCK)) {
+                editor.putBoolean(IPreferencePropertyAccessor.NIKON_NOT_SUPPORT_FOCUS_LOCK, false);
+            }
             editor.apply();
         }
         catch (Exception e)
@@ -158,6 +164,11 @@ public class NikonPreferenceFragment extends PreferenceFragmentCompat implements
                     Log.v(TAG, " " + key + " , " + value);
                     break;
 
+                case IPreferencePropertyAccessor.NIKON_NOT_SUPPORT_FOCUS_LOCK:
+                    value = preferences.getBoolean(key, false);
+                    Log.v(TAG, " " + key + " , " + value);
+                    break;
+
                 default:
                     String strValue = preferences.getString(key, "");
                     setListPreference(key, key, strValue);
@@ -177,7 +188,7 @@ public class NikonPreferenceFragment extends PreferenceFragmentCompat implements
         try
         {
             //super.onCreate(savedInstanceState);
-            addPreferencesFromResource(R.xml.preferences_olympuspen);
+            addPreferencesFromResource(R.xml.preferences_nikon);
 
             ListPreference connectionMethod = findPreference(IPreferencePropertyAccessor.CONNECTION_METHOD);
             connectionMethod.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@@ -313,6 +324,7 @@ public class NikonPreferenceFragment extends PreferenceFragmentCompat implements
                         // Preferenceの画面に反映させる
                         setBooleanPreference(IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, IPreferencePropertyAccessor.AUTO_CONNECT_TO_CAMERA, defaultValue);
                         setBooleanPreference(IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, IPreferencePropertyAccessor.CAPTURE_BOTH_CAMERA_AND_LIVE_VIEW, defaultValue);
+                        setBooleanPreference(IPreferencePropertyAccessor.NIKON_NOT_SUPPORT_FOCUS_LOCK, IPreferencePropertyAccessor.NIKON_NOT_SUPPORT_FOCUS_LOCK, false);
                     }
                     catch (Exception e)
                     {
index e879522..0f22435 100644 (file)
     <string name="pref_canon_zoom_resolution">ズームステップ</string>
     <string name="pref_summary_canon_zoom_resolution">ズームを何段階にするか指定します (標準: 25)</string>
 
+    <string name="pref_nikon_not_support_focus_lock">フォーカスロック未対応機</string>
+    <string name="pref_summary_nikon_not_support_focus_lock">フォーカスロックでライブビューが止まる場合にチェックを入れてください。</string>
 
 </resources>
index 0bbb7f8..ebeff1d 100644 (file)
     <string name="pref_canon_zoom_resolution">Zoom Step</string>
     <string name="pref_summary_canon_zoom_resolution"> </string>
 
+    <string name="pref_nikon_not_support_focus_lock">Not support Focus-Lock</string>
+    <string name="pref_summary_nikon_not_support_focus_lock"> </string>
+
 </resources>
index 41eee8a..735aebf 100644 (file)
             android:summary="@string/pref_summary_nikon_focus_xy" />
 
         <CheckBoxPreference
+            android:key="nikon_not_support_focus_lock"
+            android:title="@string/pref_nikon_not_support_focus_lock"
+            android:summary="@string/pref_summary_nikon_not_support_focus_lock" />
+
+        <CheckBoxPreference
             android:key="capture_both_camera_and_live_view"
             android:title="@string/pref_capture_both_camera_and_live_view" />
 
index 265988f..ff5816a 100644 (file)
@@ -6,7 +6,7 @@ buildscript {
         google()
     }
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.6.0'
+        classpath 'com.android.tools.build:gradle:3.6.1'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files