• R/O
  • HTTP
  • SSH
  • HTTPS

A01d: Commit

OPC(Olympus Air)用望遠鏡アプリ。


Commit MetaInfo

Révisione7048485db7efe70729f62898e18a1fe852c4491 (tree)
l'heure2018-07-03 00:31:08
AuteurMRSa <mrsa@myad...>
CommiterMRSa

Message de Log

オートフォーカスの動作を仮実装。

Change Summary

Modification

--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/RicohGr2CameraFocusControl.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/RicohGr2CameraFocusControl.java
@@ -1,20 +1,53 @@
11 package net.osdn.gokigen.a01d.camera.ricohgr2.operation;
22
3+import android.graphics.PointF;
4+import android.support.annotation.NonNull;
5+import android.util.Log;
36 import android.view.MotionEvent;
47
58 import net.osdn.gokigen.a01d.camera.IFocusingControl;
9+import net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture.RicohGr2AutoFocusControl;
10+import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
11+import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
612
713 public class RicohGr2CameraFocusControl implements IFocusingControl
814 {
15+ private final String TAG = toString();
16+ private final RicohGr2AutoFocusControl afControl;
17+ private final IAutoFocusFrameDisplay frameDisplay;
18+
19+ public RicohGr2CameraFocusControl(@NonNull final IAutoFocusFrameDisplay frameDisplayer, @NonNull final IIndicatorControl indicator)
20+ {
21+ this.frameDisplay = frameDisplayer;
22+ this.afControl = new RicohGr2AutoFocusControl(frameDisplayer, indicator);
23+ }
924
1025 @Override
11- public boolean driveAutoFocus(MotionEvent motionEvent) {
12- return false;
26+ public boolean driveAutoFocus(MotionEvent motionEvent)
27+ {
28+ Log.v(TAG, "driveAutoFocus()");
29+ if (motionEvent.getAction() != MotionEvent.ACTION_DOWN)
30+ {
31+ return (false);
32+ }
33+ try
34+ {
35+ PointF point = frameDisplay.getPointWithEvent(motionEvent);
36+ if (frameDisplay.isContainsPoint(point))
37+ {
38+ afControl.lockAutoFocus(point);
39+ }
40+ }
41+ catch (Exception e)
42+ {
43+ e.printStackTrace();
44+ }
45+ return (false);
1346 }
1447
1548 @Override
1649 public void unlockAutoFocus()
1750 {
18-
51+ afControl.unlockAutoFocus();
1952 }
2053 }
--- /dev/null
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/operation/takepicture/RicohGr2AutoFocusControl.java
@@ -0,0 +1,201 @@
1+package net.osdn.gokigen.a01d.camera.ricohgr2.operation.takepicture;
2+
3+import android.graphics.PointF;
4+import android.graphics.RectF;
5+import android.support.annotation.NonNull;
6+import android.util.Log;
7+
8+import net.osdn.gokigen.a01d.camera.sony.operation.takepicture.SonyAutoFocusControl;
9+import net.osdn.gokigen.a01d.camera.utils.SimpleHttpClient;
10+import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
11+import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
12+
13+import org.json.JSONObject;
14+
15+public class RicohGr2AutoFocusControl
16+{
17+ private static final String TAG = SonyAutoFocusControl.class.getSimpleName();
18+ private final IIndicatorControl indicator;
19+ private final IAutoFocusFrameDisplay frameDisplayer;
20+ private String lockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/lock";
21+ private String unlockAutoFocusUrl = "http://192.168.0.1/v1/lens/focus/unlock";
22+ private int timeoutMs = 6000;
23+
24+
25+ public RicohGr2AutoFocusControl(@NonNull final IAutoFocusFrameDisplay frameDisplayer, final IIndicatorControl indicator)
26+ {
27+ this.frameDisplayer = frameDisplayer;
28+ this.indicator = indicator;
29+ }
30+
31+ /**
32+ *
33+ *
34+ */
35+ public void lockAutoFocus(@NonNull final PointF point)
36+ {
37+ Log.v(TAG, "lockAutoFocus() : [" + point.x + ", " + point.y + "]");
38+ try
39+ {
40+ Thread thread = new Thread(new Runnable()
41+ {
42+ @Override
43+ public void run()
44+ {
45+ RectF preFocusFrameRect = getPreFocusFrameRect(point);
46+ try
47+ {
48+ showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Running, 0.0);
49+
50+ //int posX = (int) (Math.round(point.x * 100.0));
51+ //int posY = (int) (Math.round(point.y * 100.0));
52+ String postData = "pos=" + ( (int) (Math.round(point.x * 100.0))) + "," + ((int) (Math.round(point.y * 100.0)));
53+ Log.v(TAG, "AF (" + postData + ")");
54+ String result = SimpleHttpClient.httpPost(lockAutoFocusUrl, postData, timeoutMs);
55+ if ((result == null)||(result.length() < 1))
56+ {
57+ Log.v(TAG, "setTouchAFPosition() reply is null.");
58+ }
59+ else if (findTouchAFPositionResult(result))
60+ {
61+ // AF FOCUSED
62+ Log.v(TAG, "lockAutoFocus() : FOCUSED");
63+ showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Focused, 1.0); // いったん1秒だけ表示
64+ }
65+ else
66+ {
67+ // AF ERROR
68+ Log.v(TAG, "lockAutoFocus() : ERROR");
69+ showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Failed, 1.0);
70+ }
71+ }
72+ catch (Exception e)
73+ {
74+ e.printStackTrace();
75+ try
76+ {
77+ showFocusFrame(preFocusFrameRect, IAutoFocusFrameDisplay.FocusFrameStatus.Errored, 1.0);
78+ }
79+ catch (Exception ee)
80+ {
81+ ee.printStackTrace();
82+ }
83+ }
84+ }
85+ });
86+ thread.start();
87+ }
88+ catch (Exception e)
89+ {
90+ e.printStackTrace();
91+ }
92+ }
93+
94+ /**
95+ *
96+ *
97+ */
98+ public void unlockAutoFocus()
99+ {
100+ Log.v(TAG, "unlockAutoFocus()");
101+ try
102+ {
103+ Thread thread = new Thread(new Runnable()
104+ {
105+ @Override
106+ public void run()
107+ {
108+ try
109+ {
110+ String result = SimpleHttpClient.httpPost(unlockAutoFocusUrl, "", timeoutMs);
111+ if ((result == null)||(result.length() < 1))
112+ {
113+ Log.v(TAG, "cancelTouchAFPosition() reply is null.");
114+ }
115+ hideFocusFrame();
116+ }
117+ catch (Exception e)
118+ {
119+ e.printStackTrace();
120+ }
121+ }
122+ });
123+ thread.start();
124+ }
125+ catch (Exception e)
126+ {
127+ e.printStackTrace();
128+ }
129+ }
130+
131+ /**
132+ *
133+ *
134+ */
135+ private void showFocusFrame(RectF rect, IAutoFocusFrameDisplay.FocusFrameStatus status, double duration)
136+ {
137+ frameDisplayer.showFocusFrame(rect, status, duration);
138+ indicator.onAfLockUpdate(IAutoFocusFrameDisplay.FocusFrameStatus.Focused == status);
139+ }
140+
141+ /**
142+ *
143+ *
144+ */
145+ private void hideFocusFrame()
146+ {
147+ frameDisplayer.hideFocusFrame();
148+ indicator.onAfLockUpdate(false);
149+ }
150+
151+ /**
152+ *
153+ *
154+ */
155+ private RectF getPreFocusFrameRect(@NonNull PointF point)
156+ {
157+ float imageWidth = frameDisplayer.getContentSizeWidth();
158+ float imageHeight = frameDisplayer.getContentSizeHeight();
159+
160+ // Display a provisional focus frame at the touched point.
161+ float focusWidth = 0.125f; // 0.125 is rough estimate.
162+ float focusHeight = 0.125f;
163+ if (imageWidth > imageHeight)
164+ {
165+ focusHeight *= (imageWidth / imageHeight);
166+ }
167+ else
168+ {
169+ focusHeight *= (imageHeight / imageWidth);
170+ }
171+ return (new RectF(point.x - focusWidth / 2.0f, point.y - focusHeight / 2.0f,
172+ point.x + focusWidth / 2.0f, point.y + focusHeight / 2.0f));
173+ }
174+
175+ /**
176+ *
177+ *
178+ */
179+ private static boolean findTouchAFPositionResult(String replyString)
180+ {
181+ boolean afResult = false;
182+ try
183+ {
184+ int indexOfTouchAFPositionResult = 1;
185+ JSONObject resultObject = new JSONObject(replyString);
186+ String result = resultObject.getString("errMsg");
187+ boolean focused = resultObject.getBoolean("focused");
188+ if (result.contains("OK"))
189+ {
190+ afResult = focused;
191+ Log.v(TAG, "AF Result : " + afResult);
192+
193+ }
194+ }
195+ catch (Exception e)
196+ {
197+ e.printStackTrace();
198+ }
199+ return (afResult);
200+ }
201+}
--- a/app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/RicohGr2InterfaceProvider.java
+++ b/app/src/main/java/net/osdn/gokigen/a01d/camera/ricohgr2/wrapper/RicohGr2InterfaceProvider.java
@@ -49,7 +49,6 @@ public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, ID
4949 liveViewControl = new RicohGr2LiveViewControl();
5050 captureControl = new RicohGr2CameraCaptureControl();
5151 zoomControl = new RicohGr2CameraZoomLensControl();
52- focusControl = new RicohGr2CameraFocusControl();
5352
5453 }
5554
@@ -70,6 +69,7 @@ public class RicohGr2InterfaceProvider implements IRicohGr2InterfaceProvider, ID
7069 public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
7170 {
7271 Log.v(TAG, "injectDisplay()");
72+ focusControl = new RicohGr2CameraFocusControl(frameDisplayer, indicator);
7373
7474 }
7575
Afficher sur ancien navigateur de dépôt.