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 = false;
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);
110 if (sequenceType == 1)
112 Log.v(TAG, " --- search JPEG header : true ");
113 isSearchJpegHeader = true;
119 ipAddress = "192.168.0.1";
121 Log.v(TAG, " Canon IP : " + ipAddress);
122 commandPublisher = new PtpIpCommandPublisher(ipAddress, CONTROL_PORT, false, false);
123 liveViewControl = new CanonLiveViewControl(context, this, delayMs, isSearchJpegHeader); //
124 asyncReceiver = new PtpIpAsyncResponseReceiver(ipAddress, ASYNC_RESPONSE_PORT);
125 statusChecker = new CanonStatusChecker(commandPublisher, ipAddress, EVENT_PORT);
126 canonConnection = new CanonConnection(context, provider, this, statusChecker);
127 cameraInformation = new CanonCameraInformation();
128 zoomControl = new CanonZoomLensControl(context, commandPublisher);
129 this.statusListener = statusListener;
130 this.runMode = new PtpIpRunMode();
131 this.informationReceiver = informationReceiver;
135 public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
137 Log.v(TAG, " injectDisplay()");
138 captureControl = new CanonCaptureControl(commandPublisher, frameDisplayer);
139 focusingControl = new CanonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
143 public ICameraConnection getCameraConnection()
145 return (canonConnection);
149 public ILiveViewControl getLiveViewControl()
151 return (liveViewControl);
155 public ILiveViewListener getLiveViewListener()
157 return (liveViewControl.getLiveViewListener());
161 public IFocusingControl getFocusingControl()
163 return (focusingControl);
167 public ICameraInformation getCameraInformation()
169 return (cameraInformation);
173 public IZoomLensControl getZoomLensControl()
175 return (zoomControl);
179 public ICaptureControl getCaptureControl()
181 return (captureControl);
185 public IDisplayInjector getDisplayInjector()
191 public IPtpIpRunModeHolder getRunModeHolder()
197 public IPtpIpCommandCallback getStatusHolder() {
198 return (statusChecker);
202 public IPtpIpCommandPublisher getCommandPublisher()
204 return (commandPublisher);
208 public IPtpIpCommunication getLiveviewCommunication()
210 return (liveViewControl);
214 public IPtpIpCommunication getAsyncEventCommunication()
216 return (asyncReceiver);
220 public IPtpIpCommunication getCommandCommunication()
222 return (commandPublisher);
226 public ICameraStatusWatcher getCameraStatusWatcher()
228 return (statusChecker);
232 public ICameraStatusUpdateNotify getStatusListener()
234 return (statusListener);
238 public ICameraStatus getCameraStatusListHolder()
240 return (statusChecker);
244 public IInformationReceiver getInformationReceiver()
246 // ちょっとこの引き回しは気持ちがよくない...
247 return (informationReceiver);
251 public ICameraStatusWatcher getStatusWatcher()
253 return (statusChecker);
257 public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
259 asyncReceiver.setEventSubscriber(receiver);