1 package net.osdn.gokigen.pkremote.camera.vendor.nikon.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.pkremote.IInformationReceiver;
11 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraButtonControl;
12 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraConnection;
13 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICameraRunMode;
14 import net.osdn.gokigen.pkremote.camera.interfaces.control.ICaptureControl;
15 import net.osdn.gokigen.pkremote.camera.interfaces.control.IFocusingControl;
16 import net.osdn.gokigen.pkremote.camera.interfaces.control.IFocusingModeNotify;
17 import net.osdn.gokigen.pkremote.camera.interfaces.control.IZoomLensControl;
18 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.IAutoFocusFrameDisplay;
19 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ICameraStatusUpdateNotify;
20 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.IDisplayInjector;
21 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.IIndicatorControl;
22 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewControl;
23 import net.osdn.gokigen.pkremote.camera.interfaces.liveview.ILiveViewListener;
24 import net.osdn.gokigen.pkremote.camera.interfaces.playback.IPlaybackControl;
25 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraHardwareStatus;
26 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraInformation;
27 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatus;
28 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusReceiver;
29 import net.osdn.gokigen.pkremote.camera.interfaces.status.ICameraStatusWatcher;
30 import net.osdn.gokigen.pkremote.camera.vendor.nikon.INikonInterfaceProvider;
31 import net.osdn.gokigen.pkremote.camera.vendor.nikon.wrapper.playback.NikonPlaybackControl;
32 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.IPtpIpInterfaceProvider;
33 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.operation.PtpIpZoomControl;
34 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpButtonControl;
35 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpHardwareStatus;
36 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.PtpIpRunMode;
37 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandCallback;
38 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommandPublisher;
39 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.IPtpIpCommunication;
40 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.PtpIpAsyncResponseReceiver;
41 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.command.PtpIpCommandPublisher;
42 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.connection.NikonConnection;
43 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.liveview.PtpIpLiveViewControl;
44 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.status.IPtpIpRunModeHolder;
45 import net.osdn.gokigen.pkremote.camera.vendor.ptpip.wrapper.status.PtpIpStatusChecker;
47 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.NIKON_CAMERA_IP_ADDRESS;
48 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.NIKON_CAMERA_IP_ADDRESS_DEFAULT_VALUE;
50 public class NikonInterfaceProvider implements INikonInterfaceProvider, IDisplayInjector
52 private final String TAG = toString();
54 private static final int STREAM_PORT = 15742; // ??
55 private static final int ASYNC_RESPONSE_PORT = 15741; // ??
56 private static final int CONTROL_PORT = 15740;
57 private static final int EVENT_PORT = 15740;
58 private static final String DEFAULT_CAMERA_IP_ADDR = "192.168.1.1";
60 private final Activity activity;
61 private final PtpIpRunMode runmode;
62 private final PtpIpHardwareStatus hardwareStatus;
63 private PtpIpButtonControl ptpIpButtonControl;
64 private NikonConnection nikonConnection;
65 private PtpIpCommandPublisher commandPublisher;
66 private PtpIpLiveViewControl liveViewControl;
67 private PtpIpAsyncResponseReceiver asyncReceiver;
68 private PtpIpZoomControl zoomControl;
69 //private PtpIpCaptureControl captureControl;
70 //private PtpIpFocusingControl focusingControl;
71 private PtpIpStatusChecker statusChecker;
72 private ICameraStatusUpdateNotify statusListener;
73 private NikonPlaybackControl playbackControl;
74 private IInformationReceiver informationReceiver;
76 public NikonInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
78 this.activity = context;
79 String ipAddress = DEFAULT_CAMERA_IP_ADDR;
82 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
83 ipAddress = preferences.getString(NIKON_CAMERA_IP_ADDRESS, NIKON_CAMERA_IP_ADDRESS_DEFAULT_VALUE);
89 commandPublisher = new PtpIpCommandPublisher(ipAddress, CONTROL_PORT);
90 liveViewControl = new PtpIpLiveViewControl(context, ipAddress, STREAM_PORT);
91 asyncReceiver = new PtpIpAsyncResponseReceiver(ipAddress, ASYNC_RESPONSE_PORT);
92 statusChecker = new PtpIpStatusChecker(activity, commandPublisher, ipAddress, EVENT_PORT);
93 nikonConnection = new NikonConnection(context, provider, this, statusChecker);
94 zoomControl = new PtpIpZoomControl();
95 this.statusListener = statusListener;
96 this.runmode = new PtpIpRunMode();
97 this.hardwareStatus = new PtpIpHardwareStatus();
98 this.ptpIpButtonControl = new PtpIpButtonControl();
99 this.playbackControl = new NikonPlaybackControl(activity, this);
100 this.informationReceiver = informationReceiver;
104 public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
106 Log.v(TAG, "injectDisplay()");
107 //captureControl = new FujiXCaptureControl(commandPublisher, frameDisplayer);
108 //focusingControl = new FujiXFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
112 public ICameraConnection getPtpIpCameraConnection()
114 return (nikonConnection);
118 public ILiveViewControl getLiveViewControl()
120 return (liveViewControl);
124 public ILiveViewListener getLiveViewListener()
126 return (liveViewControl.getLiveViewListener());
130 public IFocusingControl getFocusingControl()
136 public ICameraInformation getCameraInformation()
142 public IZoomLensControl getZoomLensControl()
144 return (zoomControl);
148 public ICaptureControl getCaptureControl()
154 public IDisplayInjector getDisplayInjector()
160 public IPtpIpRunModeHolder getRunModeHolder()
166 public IPtpIpCommandCallback getStatusHolder() {
167 return (statusChecker);
171 public IPtpIpCommandPublisher getCommandPublisher()
173 return (commandPublisher);
177 public IPtpIpCommunication getLiveviewCommunication()
179 return (liveViewControl);
183 public IPtpIpCommunication getAsyncEventCommunication()
185 return (asyncReceiver);
189 public IPtpIpCommunication getCommandCommunication()
191 return (commandPublisher);
195 public ICameraStatusWatcher getCameraStatusWatcher()
197 return (statusChecker);
201 public ICameraStatusUpdateNotify getStatusListener()
203 return (statusListener);
207 public ICameraStatus getCameraStatusListHolder()
209 return (statusChecker);
213 public ICameraButtonControl getButtonControl()
215 return (ptpIpButtonControl);
219 public IPlaybackControl getPlaybackControl()
221 return (playbackControl);
225 public ICameraHardwareStatus getHardwareStatus()
227 return (hardwareStatus);
231 public ICameraRunMode getCameraRunMode()
237 public IInformationReceiver getInformationReceiver()
239 // ちょっとこの引き回しは気持ちがよくない...
240 return (informationReceiver);
244 public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
246 asyncReceiver.setEventSubscriber(receiver);