1 package net.osdn.gokigen.a01d.camera.nikon.wrapper;
3 import android.app.Activity;
4 import android.util.Log;
6 import androidx.annotation.NonNull;
7 import androidx.appcompat.app.AppCompatActivity;
9 import net.osdn.gokigen.a01d.IInformationReceiver;
10 import net.osdn.gokigen.a01d.camera.ICameraConnection;
11 import net.osdn.gokigen.a01d.camera.ICameraInformation;
12 import net.osdn.gokigen.a01d.camera.ICameraStatus;
13 import net.osdn.gokigen.a01d.camera.ICameraStatusReceiver;
14 import net.osdn.gokigen.a01d.camera.ICameraStatusWatcher;
15 import net.osdn.gokigen.a01d.camera.ICaptureControl;
16 import net.osdn.gokigen.a01d.camera.IDisplayInjector;
17 import net.osdn.gokigen.a01d.camera.IFocusingControl;
18 import net.osdn.gokigen.a01d.camera.IFocusingModeNotify;
19 import net.osdn.gokigen.a01d.camera.ILiveViewControl;
20 import net.osdn.gokigen.a01d.camera.IZoomLensControl;
21 import net.osdn.gokigen.a01d.camera.nikon.operation.NikonCaptureControl;
22 import net.osdn.gokigen.a01d.camera.nikon.operation.NikonFocusingControl;
23 import net.osdn.gokigen.a01d.camera.nikon.operation.NikonZoomLensControl;
24 import net.osdn.gokigen.a01d.camera.nikon.wrapper.connection.NikonConnection;
25 import net.osdn.gokigen.a01d.camera.nikon.wrapper.hardware.NikonCameraInformation;
26 import net.osdn.gokigen.a01d.camera.nikon.wrapper.liveview.NikonLiveViewControl;
27 import net.osdn.gokigen.a01d.camera.nikon.wrapper.status.NikonStatusChecker;
28 import net.osdn.gokigen.a01d.camera.ptpip.IPtpIpInterfaceProvider;
29 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandCallback;
30 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommandPublisher;
31 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.IPtpIpCommunication;
32 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpAsyncResponseReceiver;
33 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.command.PtpIpCommandPublisher;
34 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.IPtpIpRunModeHolder;
35 import net.osdn.gokigen.a01d.camera.ptpip.wrapper.status.PtpIpRunMode;
36 import net.osdn.gokigen.a01d.liveview.IAutoFocusFrameDisplay;
37 import net.osdn.gokigen.a01d.liveview.ICameraStatusUpdateNotify;
38 import net.osdn.gokigen.a01d.liveview.IIndicatorControl;
39 import net.osdn.gokigen.a01d.liveview.liveviewlistener.ILiveViewListener;
41 public class NikonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplayInjector
43 private final String TAG = toString();
45 private static final int ASYNC_RESPONSE_PORT = 15741;
46 private static final int CONTROL_PORT = 15740;
47 private static final int EVENT_PORT = 15740;
48 private static final String CAMERA_IP = "192.168.1.1";
50 private final Activity activity;
51 private final PtpIpRunMode runmode;
52 private final NikonCameraInformation cameraInformation;
53 private NikonCaptureControl captureControl;
54 private NikonFocusingControl focusingControl;
55 private NikonConnection canonConnection;
56 private PtpIpCommandPublisher commandPublisher;
57 private NikonLiveViewControl liveViewControl;
58 private PtpIpAsyncResponseReceiver asyncReceiver;
59 private NikonZoomLensControl zoomControl;
60 private NikonStatusChecker statusChecker;
61 private ICameraStatusUpdateNotify statusListener;
62 private IInformationReceiver informationReceiver;
64 public NikonInterfaceProvider(@NonNull AppCompatActivity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
66 this.activity = context;
67 commandPublisher = new PtpIpCommandPublisher(CAMERA_IP, CONTROL_PORT, true, false);
68 liveViewControl = new NikonLiveViewControl(context, this, 30);
69 asyncReceiver = new PtpIpAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
70 statusChecker = new NikonStatusChecker(activity, commandPublisher, CAMERA_IP, EVENT_PORT);
71 canonConnection = new NikonConnection(context, provider, this, statusChecker);
72 cameraInformation = new NikonCameraInformation();
73 zoomControl = new NikonZoomLensControl();
74 this.statusListener = statusListener;
75 this.runmode = new PtpIpRunMode();
76 this.informationReceiver = informationReceiver;
80 public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
82 Log.v(TAG, "injectDisplay()");
83 captureControl = new NikonCaptureControl(commandPublisher, frameDisplayer);
84 focusingControl = new NikonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
88 public ICameraConnection getCameraConnection()
90 return (canonConnection);
94 public ILiveViewControl getLiveViewControl()
96 return (liveViewControl);
100 public ILiveViewListener getLiveViewListener()
102 return (liveViewControl.getLiveViewListener());
106 public IFocusingControl getFocusingControl()
108 return (focusingControl);
112 public ICameraInformation getCameraInformation()
114 return (cameraInformation);
118 public IZoomLensControl getZoomLensControl()
120 return (zoomControl);
124 public ICaptureControl getCaptureControl()
126 return (captureControl);
130 public IDisplayInjector getDisplayInjector()
136 public IPtpIpRunModeHolder getRunModeHolder()
142 public IPtpIpCommandCallback getStatusHolder() {
143 return (statusChecker);
147 public IPtpIpCommandPublisher getCommandPublisher()
149 return (commandPublisher);
153 public IPtpIpCommunication getLiveviewCommunication()
155 return (liveViewControl);
159 public IPtpIpCommunication getAsyncEventCommunication()
161 return (asyncReceiver);
165 public IPtpIpCommunication getCommandCommunication()
167 return (commandPublisher);
171 public ICameraStatusWatcher getCameraStatusWatcher()
173 return (statusChecker);
177 public ICameraStatusUpdateNotify getStatusListener()
179 return (statusListener);
183 public ICameraStatus getCameraStatusListHolder()
185 return (statusChecker);
189 public IInformationReceiver getInformationReceiver()
191 // ちょっとこの引き回しは気持ちがよくない...
192 return (informationReceiver);
196 public ICameraStatusWatcher getStatusWatcher()
198 return (statusChecker);
202 public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
204 asyncReceiver.setEventSubscriber(receiver);