1 package net.osdn.gokigen.a01d.camera.canon.wrapper;
3 import android.app.Activity;
4 import android.content.SharedPreferences;
5 import android.util.Log;
7 import androidx.annotation.NonNull;
8 import androidx.preference.PreferenceManager;
10 import net.osdn.gokigen.a01d.IInformationReceiver;
11 import net.osdn.gokigen.a01d.camera.ICameraConnection;
12 import net.osdn.gokigen.a01d.camera.ICameraInformation;
13 import net.osdn.gokigen.a01d.camera.ICameraStatus;
14 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
15 import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
16 import net.osdn.gokigen.a01d.camera.ICaptureControl;
17 import net.osdn.gokigen.a01d.camera.IDisplayInjector;
18 import net.osdn.gokigen.a01d.camera.IFocusingControl;
19 import net.osdn.gokigen.a01d.camera.IFocusingModeNotify;
20 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
21 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
22 import net.osdn.gokigen.a01d.camera.canon.operation.CanonCaptureControl;
23 import net.osdn.gokigen.a01d.camera.canon.operation.CanonFocusingControl;
24 import net.osdn.gokigen.a01d.camera.canon.wrapper.connection.CanonConnection;
25 import net.osdn.gokigen.a01d.camera.canon.operation.CanonZoomLensControl;
26 import net.osdn.gokigen.a01d.camera.canon.wrapper.hardware.CanonCameraInformation;
27 import net.osdn.gokigen.a01d.camera.canon.wrapper.liveview.CanonLiveViewControl;
28 import net.osdn.gokigen.a01d.camera.canon.wrapper.status.CanonStatusChecker;
29 import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
30 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
31 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
32 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
33 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpAsyncResponseReceiver;
34 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
35 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.IPtpIpRunModeHolder;
36 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.PtpIpRunMode;
37 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
38 import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
39 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
40 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
41 import net.osdn.gokigen.a01d.preference.IPreferencePropertyAccessor;
43 public class CanonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplayInjector
45 private final String TAG = toString();
47 private static final int ASYNC_RESPONSE_PORT = 15741; // ??
48 private static final int CONTROL_PORT = 15740;
49 private static final int EVENT_PORT = 15740;
50 //private static final String CAMERA_IP = "192.168.0.1";
52 private final Activity activity;
53 private final PtpIpRunMode runMode;
54 private final CanonCameraInformation cameraInformation;
55 private CanonCaptureControl captureControl;
56 private CanonFocusingControl focusingControl;
57 private final CanonConnection canonConnection;
58 private final PtpIpCommandPublisher commandPublisher;
59 private final CanonLiveViewControl liveViewControl;
60 private final PtpIpAsyncResponseReceiver asyncReceiver;
61 private final CanonZoomLensControl zoomControl;
62 private final CanonStatusChecker statusChecker;
63 private final ICameraStatusUpdateNotify statusListener;
64 private final IInformationReceiver informationReceiver;
66 public CanonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
68 this.activity = context;
73 boolean isSearchJpegHeader = true;
76 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
77 ipAddress = preferences.getString(IPreferencePropertyAccessor.CANON_HOST_IP, IPreferencePropertyAccessor.CANON_HOST_IP_DEFAULT_VALUE);
78 if (ipAddress == null)
80 ipAddress = "192.168.0.1";
84 String delayMsStr = preferences.getString(IPreferencePropertyAccessor.CANON_LIVEVIEW_WAIT, IPreferencePropertyAccessor.CANON_LIVEVIEW_WAIT_DEFAULT_VALUE);
85 if (delayMsStr != null)
87 delayMs = Integer.parseInt(delayMsStr);
100 String sequenceTypeStr = preferences.getString(IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE, IPreferencePropertyAccessor.CANON_CONNECTION_SEQUENCE_DEFAULT_VALUE);
101 if (sequenceTypeStr != null)
103 sequenceType = Integer.parseInt(sequenceTypeStr);
111 isSearchJpegHeader = !(sequenceType == 2);
112 Log.v(TAG, " --- search JPEG header : " + isSearchJpegHeader);
117 ipAddress = "192.168.0.1";
119 Log.v(TAG, " Canon IP : " + ipAddress);
120 commandPublisher = new PtpIpCommandPublisher(ipAddress, CONTROL_PORT, false, false);
121 liveViewControl = new CanonLiveViewControl(context, this, delayMs, isSearchJpegHeader); //
122 asyncReceiver = new PtpIpAsyncResponseReceiver(ipAddress, ASYNC_RESPONSE_PORT);
123 statusChecker = new CanonStatusChecker(commandPublisher, ipAddress, EVENT_PORT);
124 canonConnection = new CanonConnection(context, provider, this, statusChecker);
125 cameraInformation = new CanonCameraInformation();
126 zoomControl = new CanonZoomLensControl(context, commandPublisher);
127 this.statusListener = statusListener;
128 this.runMode = new PtpIpRunMode();
129 this.informationReceiver = informationReceiver;
133 public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
135 Log.v(TAG, " injectDisplay()");
136 captureControl = new CanonCaptureControl(commandPublisher, frameDisplayer);
137 focusingControl = new CanonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
141 public ICameraConnection getCameraConnection()
143 return (canonConnection);
147 public ILiveViewControl getLiveViewControl()
149 return (liveViewControl);
153 public ILiveViewListener getLiveViewListener()
155 return (liveViewControl.getLiveViewListener());
159 public IFocusingControl getFocusingControl()
161 return (focusingControl);
165 public ICameraInformation getCameraInformation()
167 return (cameraInformation);
171 public IZoomLensControl getZoomLensControl()
173 return (zoomControl);
177 public ICaptureControl getCaptureControl()
179 return (captureControl);
183 public IDisplayInjector getDisplayInjector()
189 public IPtpIpRunModeHolder getRunModeHolder()
195 public IPtpIpCommandCallback getStatusHolder() {
196 return (statusChecker);
200 public IPtpIpCommandPublisher getCommandPublisher()
202 return (commandPublisher);
206 public IPtpIpCommunication getLiveviewCommunication()
208 return (liveViewControl);
212 public IPtpIpCommunication getAsyncEventCommunication()
214 return (asyncReceiver);
218 public IPtpIpCommunication getCommandCommunication()
220 return (commandPublisher);
224 public ICameraStatusWatcher getCameraStatusWatcher()
226 return (statusChecker);
230 public ICameraStatusUpdateNotify getStatusListener()
232 return (statusListener);
236 public ICameraStatus getCameraStatusListHolder()
238 return (statusChecker);
242 public IInformationReceiver getInformationReceiver()
244 // ちょっとこの引き回しは気持ちがよくない...
245 return (informationReceiver);
249 public ICameraStatusWatcher getStatusWatcher()
251 return (statusChecker);
255 public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
257 asyncReceiver.setEventSubscriber(receiver);