OSDN Git Service

AF駆動、AFlock解除のコマンドを追加。(調整中)
authorMRSa <mrsa@myad.jp>
Tue, 7 May 2019 15:19:30 +0000 (00:19 +0900)
committerMRSa <mrsa@myad.jp>
Tue, 7 May 2019 15:19:30 +0000 (00:19 +0900)
app/src/main/java/net/osdn/gokigen/cameratest/camtest/CamTest.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/Connection.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/FujiStreamReceiver.java
app/src/main/java/net/osdn/gokigen/cameratest/fuji/MessageSequence.java
app/src/main/java/net/osdn/gokigen/cameratest/pages/TestViewFragment.java
app/src/main/res/layout/fragment_main.xml
app/src/main/res/values/strings.xml

index 4f94ff9..50b1fbf 100644 (file)
@@ -3,8 +3,10 @@ package net.osdn.gokigen.cameratest.camtest;
 import android.app.Activity;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
+import android.graphics.PointF;
 import android.os.Environment;
 import android.util.Log;
+import android.view.MotionEvent;
 import android.view.View;
 import android.widget.ImageView;
 import android.widget.TextView;
@@ -22,7 +24,7 @@ import java.io.File;
 import java.io.FileInputStream;
 
 
-public class CamTest implements View.OnClickListener, ILiveViewImage
+public class CamTest implements View.OnClickListener, View.OnTouchListener, ILiveViewImage
 {
     private String TAG = toString();
     private final Activity activity;
@@ -151,8 +153,7 @@ public class CamTest implements View.OnClickListener, ILiveViewImage
                 doShutter();
                 break;
             case R.id.button2:
-                //readImageFile("sampledata1.bin");
-                //showMessageText("show 'sampledata1.bin'.");
+                unlockFocus();
                 break;
             case R.id.button3:
                 //readImageFile("sampledata2.bin");
@@ -193,6 +194,56 @@ public class CamTest implements View.OnClickListener, ILiveViewImage
         }
     }
 
+    private void driveAutoFocus(final PointF point)
+    {
+        if (point == null)
+        {
+            return;
+        }
+        try
+        {
+            Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.drive_af, Snackbar.LENGTH_SHORT).show();
+            showMessageText("AF : " + point.x + "," + point.y);
+            Thread thread = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    boolean ret = connection.execute_focus_point(point);
+                    if (!ret)
+                    {
+                        showMessageText("Auto Focus FAILURE...");
+                    }
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+    private void unlockFocus()
+    {
+        try
+        {
+            Snackbar.make(activity.findViewById(R.id.constraintLayout), R.string.unlock_focus, Snackbar.LENGTH_SHORT).show();
+            Thread thread = new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    boolean ret = connection.execute_unlock_focus();
+                    if (!ret)
+                    {
+                        showMessageText("Unlock Focus FAILURE...");
+                    }
+                }
+            });
+            thread.start();
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+    }
+
     @Override
     public void updateImage(ReceivedDataHolder receivedData)
     {
@@ -382,4 +433,42 @@ public class CamTest implements View.OnClickListener, ILiveViewImage
         }
         return (null);
     }
+
+    @Override
+    public boolean onTouch(View v, MotionEvent event)
+    {
+        try
+        {
+            int id = v.getId();
+            Log.v(TAG, "onTouch() : " + id);
+            if (event.getAction() == MotionEvent.ACTION_DOWN)
+            {
+                driveAutoFocus(getPointWithEvent(event));
+                return (true);
+            }
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+    private PointF getPointWithEvent(MotionEvent event)
+    {
+        if (event == null)
+        {
+            return (null);
+        }
+        try
+        {
+            ImageView imageView = activity.findViewById(R.id.imageView);
+            return (new PointF(((event.getX() / (float) imageView.getWidth()) * 100.0f), ((event.getY() / (float) imageView.getHeight()) * 100.0f)));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (null);
+    }
 }
index 51a4701..267e162 100644 (file)
@@ -1,5 +1,6 @@
 package net.osdn.gokigen.cameratest.fuji;
 
+import android.graphics.PointF;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
@@ -198,6 +199,42 @@ public class Connection
         System.gc();
     }
 
+    public boolean execute_focus_point(PointF point)
+    {
+        try
+        {
+            byte x = (byte) (0x000000ff & Math.round(point.x));
+            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);
+
+            ReceivedDataHolder rx_bytes = comm.receive_from_camera();
+            dump_bytes(16, rx_bytes);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
+    public boolean execute_unlock_focus()
+    {
+        try
+        {
+            comm.send_to_camera(sequence.execute_focus_unlock(), true);
+
+            ReceivedDataHolder rx_bytes = comm.receive_from_camera();
+            dump_bytes(17, rx_bytes);
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (false);
+    }
+
     public boolean execute_shutter()
     {
         try
index daa08e2..3bfd4b2 100644 (file)
@@ -11,7 +11,7 @@ class FujiStreamReceiver
     private final String ipAddress;
     private final int portNumber;
     private final ILiveViewImage imageViewer;
-    private static final int WAIT_MS = 75;
+    private static final int WAIT_MS = 80;
     private static final int BUFFER_SIZE = 1280 * 1024 + 8;
     private boolean isStart = false;
 
index 9ea8c4d..295ba78 100644 (file)
@@ -359,4 +359,41 @@ class MessageSequence
         });
     }
 
+
+
+    byte[] execute_focus_lock(byte pointX, byte pointY)
+    {
+        return (new byte[] {
+
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : focus_point (0x9026)
+                (byte)0x26, (byte)0x90,
+
+                // message_id (0~1づつ繰り上がる...
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+
+                // data ...
+                pointY, pointX, (byte)0x00, (byte)0x00,
+
+        });
+    }
+
+
+    byte[] execute_focus_unlock()
+    {
+        return (new byte[] {
+
+                // message_header.index : uint16 (0: terminate, 2: two_part_message, 1: other)
+                (byte)0x01, (byte)0x00,
+
+                // message_header.type : focus_unlock (0x9027)
+                (byte)0x27, (byte)0x90,
+
+                // message_id (0~1づつ繰り上がる...
+                (byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
+        });
+    }
+
 }
index 82dfb09..e992ec2 100644 (file)
@@ -5,6 +5,7 @@ import android.view.LayoutInflater;
 import android.view.View;
 import android.view.ViewGroup;
 import android.widget.Button;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import net.osdn.gokigen.cameratest.R;
@@ -55,6 +56,7 @@ public class TestViewFragment extends Fragment
         {
             if (testTarget != null)
             {
+                ImageView imageView = rootView.findViewById(R.id.imageView);
                 Button btn1 = rootView.findViewById(R.id.button1);
                 Button btn2 = rootView.findViewById(R.id.button2);
                 Button btn3 = rootView.findViewById(R.id.button3);
@@ -63,6 +65,7 @@ public class TestViewFragment extends Fragment
                 btn2.setOnClickListener(testTarget);
                 btn3.setOnClickListener(testTarget);
                 btn4.setOnClickListener(testTarget);
+                imageView.setOnTouchListener(testTarget);
             }
         }
         catch (Exception e)
index b87e50e..089483b 100644 (file)
@@ -80,8 +80,8 @@
 
     <ImageView
         android:id="@+id/imageView"
-        android:layout_width="wrap_content"
-        android:layout_height="320dp"
+        android:layout_width="fill_parent"
+        android:layout_height="0dip"
         android:layout_marginTop="2dp"
         android:contentDescription="@string/blank"
         android:scaleType="fitCenter"
index d4dd566..cc4b22f 100644 (file)
@@ -4,9 +4,11 @@
     <string name="action_exit_app">Exit</string>
     <string name="action_settings">Settings</string>
     <string name="action_wifi_settings">WiFi Settings</string>
-    <string name="section_format">Hello World from section: %1$d</string>
+    <string name="section_format">%1$d</string>
     <string name="connect">Try connect</string>
     <string name="shutter">Execute Shutter</string>
+    <string name="drive_af">Drive AF</string>
+    <string name="unlock_focus">Focus Unlock</string>
     <string name="label_button1">1</string>
     <string name="label_button2">2</string>
     <string name="label_button3">3</string>