1 package net.osdn.gokigen.pkremote.camera.vendor.fujix.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.fujix.IFujiXInterfaceProvider;
31 import net.osdn.gokigen.pkremote.camera.vendor.fujix.operation.FujiXCaptureControl;
32 import net.osdn.gokigen.pkremote.camera.vendor.fujix.operation.FujiXFocusingControl;
33 import net.osdn.gokigen.pkremote.camera.vendor.fujix.operation.FujiXZoomControl;
34 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.FujiXAsyncResponseReceiver;
35 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.FujiXCommandPublisher;
36 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandCallback;
37 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommandPublisher;
38 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.command.IFujiXCommunication;
39 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.connection.FujiXConnection;
40 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.liveview.FujiXLiveViewControl;
41 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.status.FujiXStatusChecker;
42 import net.osdn.gokigen.pkremote.camera.vendor.fujix.wrapper.status.IFujiXRunModeHolder;
44 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.FUJIX_COMMAND_POLLING_WAIT;
45 import static net.osdn.gokigen.pkremote.preference.IPreferencePropertyAccessor.FUJIX_COMMAND_POLLING_WAIT_DEFAULT_VALUE;
47 public class FujiXInterfaceProvider implements IFujiXInterfaceProvider, IDisplayInjector
49 private final String TAG = toString();
51 private static final int STREAM_PORT = 55742;
52 private static final int ASYNC_RESPONSE_PORT = 55741;
53 private static final int CONTROL_PORT = 55740;
54 private static final String CAMERA_IP = "192.168.0.1";
56 private static final int COMMAND_POLL_QUEUE_DEFAULT_MS = 50;
57 private static final int COMMAND_POLL_QUEUE_MAX_MS = 499;
58 private static final int COMMAND_POLL_QUEUE_MIN_MS = 10;
60 private final Activity activity;
61 private final FujiXRunMode runmode;
62 private final FujiXHardwareStatus hardwareStatus;
63 private FujiXButtonControl fujiXButtonControl;
64 private FujiXConnection fujiXConnection;
65 private FujiXCommandPublisher commandPublisher;
66 private FujiXLiveViewControl liveViewControl;
67 private FujiXAsyncResponseReceiver asyncReceiver;
68 private FujiXZoomControl zoomControl;
69 private FujiXCaptureControl captureControl;
70 private FujiXFocusingControl focusingControl;
71 private FujiXStatusChecker statusChecker;
72 private ICameraStatusUpdateNotify statusListener;
73 private FujiXPlaybackControl playbackControl;
74 private IInformationReceiver informationReceiver;
76 public FujiXInterfaceProvider(@NonNull Activity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
78 this.activity = context;
79 int duration = COMMAND_POLL_QUEUE_DEFAULT_MS;
83 SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
84 duration = Integer.parseInt(preferences.getString(FUJIX_COMMAND_POLLING_WAIT, FUJIX_COMMAND_POLLING_WAIT_DEFAULT_VALUE));
90 if ((duration < COMMAND_POLL_QUEUE_MIN_MS)|| (duration > COMMAND_POLL_QUEUE_MAX_MS))
92 // 設定の上下限値を超えたらデフォルト値(の半分程度の値)に変更する。
93 duration = COMMAND_POLL_QUEUE_DEFAULT_MS;
95 commandPublisher = new FujiXCommandPublisher(CAMERA_IP, CONTROL_PORT, duration);
96 liveViewControl = new FujiXLiveViewControl(context, CAMERA_IP, STREAM_PORT);
97 asyncReceiver = new FujiXAsyncResponseReceiver(CAMERA_IP, ASYNC_RESPONSE_PORT);
98 fujiXConnection = new FujiXConnection(context, provider, this);
99 zoomControl = new FujiXZoomControl();
100 statusChecker = new FujiXStatusChecker(activity, commandPublisher);
101 this.statusListener = statusListener;
102 this.runmode = new FujiXRunMode();
103 this.hardwareStatus = new FujiXHardwareStatus();
104 this.fujiXButtonControl = new FujiXButtonControl();
105 this.playbackControl = new FujiXPlaybackControl(activity, this);
106 this.informationReceiver = informationReceiver;
110 public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
112 Log.v(TAG, "injectDisplay()");
113 captureControl = new FujiXCaptureControl(commandPublisher, frameDisplayer);
114 focusingControl = new FujiXFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
118 public ICameraConnection getFujiXCameraConnection()
120 return (fujiXConnection);
124 public ILiveViewControl getLiveViewControl()
126 return (liveViewControl);
130 public ILiveViewListener getLiveViewListener()
132 return (liveViewControl.getLiveViewListener());
136 public IFocusingControl getFocusingControl()
138 return (focusingControl);
142 public ICameraInformation getCameraInformation()
148 public IZoomLensControl getZoomLensControl()
150 return (zoomControl);
154 public ICaptureControl getCaptureControl()
156 return (captureControl);
160 public IDisplayInjector getDisplayInjector()
166 public IFujiXRunModeHolder getRunModeHolder()
172 public IFujiXCommandCallback getStatusHolder() {
173 return (statusChecker);
177 public IFujiXCommandPublisher getCommandPublisher()
179 return (commandPublisher);
183 public IFujiXCommunication getLiveviewCommunication()
185 return (liveViewControl);
189 public IFujiXCommunication getAsyncEventCommunication()
191 return (asyncReceiver);
195 public IFujiXCommunication getCommandCommunication()
197 return (commandPublisher);
201 public ICameraStatusWatcher getCameraStatusWatcher()
203 return (statusChecker);
207 public ICameraStatusUpdateNotify getStatusListener()
209 return (statusListener);
213 public ICameraStatus getCameraStatusListHolder()
215 return (statusChecker);
219 public ICameraButtonControl getButtonControl()
221 return (fujiXButtonControl);
225 public IPlaybackControl getPlaybackControl()
227 return (playbackControl);
231 public ICameraHardwareStatus getHardwareStatus()
233 return (hardwareStatus);
237 public ICameraRunMode getCameraRunMode()
243 public IInformationReceiver getInformationReceiver()
245 // ちょっとこの引き回しは気持ちがよくない...
246 return (informationReceiver);
250 public void setAsyncEventReceiver(@NonNull IFujiXCommandCallback receiver)
252 asyncReceiver.setEventSubscriber(receiver);