OSDN Git Service

NikonのLV、すこし改善。
[gokigen/A01d.git] / app / src / main / java / net / osdn / gokigen / a01d / camera / nikon / wrapper / NikonInterfaceProvider.java
1 package net.osdn.gokigen.a01d.camera.nikon.wrapper;
2
3 import android.app.Activity;
4 import android.util.Log;
5
6 import androidx.annotation.NonNull;
7 import androidx.appcompat.app.AppCompatActivity;
8
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;
40
41 public class NikonInterfaceProvider implements IPtpIpInterfaceProvider, IDisplayInjector
42 {
43     private final String TAG = toString();
44
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";
49
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;
63
64     public NikonInterfaceProvider(@NonNull AppCompatActivity context, @NonNull ICameraStatusReceiver provider, @NonNull ICameraStatusUpdateNotify statusListener, @NonNull IInformationReceiver informationReceiver)
65     {
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;
77     }
78
79     @Override
80     public void injectDisplay(IAutoFocusFrameDisplay frameDisplayer, IIndicatorControl indicator, IFocusingModeNotify focusingModeNotify)
81     {
82         Log.v(TAG, "injectDisplay()");
83         captureControl = new NikonCaptureControl(commandPublisher, frameDisplayer);
84         focusingControl = new NikonFocusingControl(activity, commandPublisher, frameDisplayer, indicator);
85     }
86
87     @Override
88     public ICameraConnection getCameraConnection()
89     {
90         return (canonConnection);
91     }
92
93     @Override
94     public ILiveViewControl getLiveViewControl()
95     {
96         return (liveViewControl);
97     }
98
99     @Override
100     public ILiveViewListener getLiveViewListener()
101     {
102         return (liveViewControl.getLiveViewListener());
103     }
104
105     @Override
106     public IFocusingControl getFocusingControl()
107     {
108         return (focusingControl);
109     }
110
111     @Override
112     public ICameraInformation getCameraInformation()
113     {
114         return (cameraInformation);
115     }
116
117     @Override
118     public IZoomLensControl getZoomLensControl()
119     {
120         return (zoomControl);
121     }
122
123     @Override
124     public ICaptureControl getCaptureControl()
125     {
126         return (captureControl);
127     }
128
129     @Override
130     public IDisplayInjector getDisplayInjector()
131     {
132         return (this);
133     }
134
135     @Override
136     public IPtpIpRunModeHolder getRunModeHolder()
137     {
138         return (runmode);
139     }
140
141     @Override
142     public IPtpIpCommandCallback getStatusHolder() {
143         return (statusChecker);
144     }
145
146     @Override
147     public IPtpIpCommandPublisher getCommandPublisher()
148     {
149         return (commandPublisher);
150     }
151
152     @Override
153     public IPtpIpCommunication getLiveviewCommunication()
154     {
155         return (liveViewControl);
156     }
157
158     @Override
159     public IPtpIpCommunication getAsyncEventCommunication()
160     {
161         return (asyncReceiver);
162     }
163
164     @Override
165     public IPtpIpCommunication getCommandCommunication()
166     {
167         return (commandPublisher);
168     }
169
170     @Override
171     public ICameraStatusWatcher getCameraStatusWatcher()
172     {
173         return (statusChecker);
174     }
175
176     @Override
177     public ICameraStatusUpdateNotify getStatusListener()
178     {
179         return (statusListener);
180     }
181
182     @Override
183     public ICameraStatus getCameraStatusListHolder()
184     {
185         return (statusChecker);
186     }
187
188     @Override
189     public IInformationReceiver getInformationReceiver()
190     {
191         // ちょっとこの引き回しは気持ちがよくない...
192         return (informationReceiver);
193     }
194
195     @Override
196     public ICameraStatusWatcher getStatusWatcher()
197     {
198         return (statusChecker);
199     }
200
201     @Override
202     public void setAsyncEventReceiver(@NonNull IPtpIpCommandCallback receiver)
203     {
204         asyncReceiver.setEventSubscriber(receiver);
205     }
206
207 }