-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraController.cs
269 lines (216 loc) · 12.2 KB
/
CameraController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
/******************************************************************************
* *
* PROJECT : Eos Digital camera Software Development Kit EDSDK *
* *
* Description: This is the Sample code to show the usage of EDSDK. *
* *
* *
*******************************************************************************
* *
* Written and developed by Canon Inc. *
* Copyright Canon Inc. 2018 All Rights Reserved *
* *
*******************************************************************************/
using System;
namespace CameraControl
{
public class CameraController : ActionListener
{
private CameraModel _model;
CommandProcessor _processor = new CommandProcessor();
public CameraController(ref CameraModel model)
{
_model = model;
}
public void Run()
{
_processor.Start();
//The communication with the camera begins
_processor.PostCommand(new OpenSessionCommand(ref _model));
_processor.PostCommand(new GetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_ProductName));
//It is necessary to acquire the property information that cannot acquire in sending OpenSessionCommand automatically by manual operation.
}
public CameraModel GetModel()
{
return _model;
}
public override void ActionPerformed(ActionEvent e)
{
ActionEvent.Command command = e.GetActionCommand();
uint inPropertyID;
uint data;
EDSDKLib.EDSDK.EdsPoint point;
switch (command)
{
case ActionEvent.Command.GET_PROPERTY:
inPropertyID = (uint)e.GetArg();
_processor.PostCommand(new GetPropertyCommand(ref _model, inPropertyID));
break;
case ActionEvent.Command.GET_PROPERTYDESC:
inPropertyID = (uint)e.GetArg();
_processor.PostCommand(new GetPropertyDescCommand(ref _model, inPropertyID));
break;
case ActionEvent.Command.TAKE_PICTURE:
_processor.PostCommand(new TakePictureCommand(ref _model));
break;
case ActionEvent.Command.PRESS_COMPLETELY:
_processor.PostCommand(new PressShutterCommand(ref _model, (uint)EDSDKLib.EDSDK.EdsShutterButton.CameraCommand_ShutterButton_Completely));
break;
case ActionEvent.Command.PRESS_HALFWAY:
_processor.PostCommand(new PressShutterCommand(ref _model, (uint)EDSDKLib.EDSDK.EdsShutterButton.CameraCommand_ShutterButton_Halfway));
break;
case ActionEvent.Command.PRESS_OFF:
_processor.PostCommand(new PressShutterCommand(ref _model, (uint)EDSDKLib.EDSDK.EdsShutterButton.CameraCommand_ShutterButton_OFF));
break;
case ActionEvent.Command.START_EVF:
_model.isEvfEnable = true;
_processor.PostCommand(new StartEvfCommand(ref _model));
break;
case ActionEvent.Command.END_EVF:
_model.isEvfEnable = false;
// When exit LiveView, cancel EVF AF ON
_processor.PostCommand(new DoEvfAFCommand(ref _model, (uint)EDSDKLib.EDSDK.EdsEvfAf.CameraCommand_EvfAf_OFF));
_processor.PostCommand(new EndEvfCommand(ref _model));
break;
case ActionEvent.Command.DOWNLOAD_EVF:
_processor.PostCommand(new DownloadEvfCommand(ref _model));
break;
case ActionEvent.Command.SET_AF_MODE:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_AFMode, data));
break;
case ActionEvent.Command.SET_AV:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_Av, data));
break;
case ActionEvent.Command.SET_TV:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_Tv, data));
break;
case ActionEvent.Command.SET_ISO_SPEED:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_ISOSpeed, data));
break;
case ActionEvent.Command.SET_METERING_MODE:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_MeteringMode, data));
break;
case ActionEvent.Command.SET_DRIVE_MODE:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_DriveMode, data));
break;
case ActionEvent.Command.SET_WHITE_BALANCE:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_WhiteBalance, data));
break;
case ActionEvent.Command.SET_EXPOSURE_COMPENSATION:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_ExposureCompensation, data));
break;
case ActionEvent.Command.SET_IMAGEQUALITY:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_ImageQuality, data));
break;
case ActionEvent.Command.SET_EVF_AFMODE:
// When switching a EVF AF MODE, cancel EVF AF ON
_processor.PostCommand(new DoEvfAFCommand(ref _model, (uint)EDSDKLib.EDSDK.EdsEvfAf.CameraCommand_EvfAf_OFF));
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_Evf_AFMode, data));
break;
case ActionEvent.Command.SET_ZOOM:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_DC_Zoom, data));
break;
case ActionEvent.Command.SET_FLASH_MODE:
data = (uint)e.GetArg();
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_DC_Strobe, data));
break;
case ActionEvent.Command.FOCUS_NEAR1:
_processor.PostCommand(new DriveLensCommand(ref _model, EDSDKLib.EDSDK.EvfDriveLens_Near1));
break;
case ActionEvent.Command.FOCUS_NEAR2:
_processor.PostCommand(new DriveLensCommand(ref _model, EDSDKLib.EDSDK.EvfDriveLens_Near2));
break;
case ActionEvent.Command.FOCUS_NEAR3:
_processor.PostCommand(new DriveLensCommand(ref _model, EDSDKLib.EDSDK.EvfDriveLens_Near3));
break;
case ActionEvent.Command.FOCUS_FAR1:
_processor.PostCommand(new DriveLensCommand(ref _model, EDSDKLib.EDSDK.EvfDriveLens_Far1));
break;
case ActionEvent.Command.FOCUS_FAR2:
_processor.PostCommand(new DriveLensCommand(ref _model, EDSDKLib.EDSDK.EvfDriveLens_Far2));
break;
case ActionEvent.Command.FOCUS_FAR3:
_processor.PostCommand(new DriveLensCommand(ref _model, EDSDKLib.EDSDK.EvfDriveLens_Far3));
break;
case ActionEvent.Command.DOWNLOAD:
IntPtr inRef = (IntPtr)e.GetArg();
_processor.PostCommand(new DownloadCommand(ref _model, ref inRef));
break;
case ActionEvent.Command.CLOSING:
_processor.PostCommand(new CloseSessionCommand(ref _model));
_processor.Stop();
break;
case ActionEvent.Command.SHUT_DOWN:
_processor.Stop();
CameraEvent shotDownEvent = new CameraEvent(CameraEvent.Type.SHUT_DOWN, IntPtr.Zero);
_model.NotifyObservers(shotDownEvent);
break;
case ActionEvent.Command.EVF_AF_ON:
_processor.PostCommand(new DoEvfAFCommand(ref _model, (uint)EDSDKLib.EDSDK.EdsEvfAf.CameraCommand_EvfAf_ON));
break;
case ActionEvent.Command.EVF_AF_OFF:
_processor.PostCommand(new DoEvfAFCommand(ref _model, (uint)EDSDKLib.EDSDK.EdsEvfAf.CameraCommand_EvfAf_OFF));
break;
case ActionEvent.Command.ZOOM_FIT:
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_Evf_Zoom, EDSDKLib.EDSDK.EvfZoom_Fit));
break;
case ActionEvent.Command.ZOOM_ZOOM:
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_Evf_Zoom, EDSDKLib.EDSDK.EvfZoom_x5));
break;
case ActionEvent.Command.POSITION_UP:
case ActionEvent.Command.POSITION_DOWN:
const int stepY = 128;
point = _model.GetZoomPosition();
if (command == ActionEvent.Command.POSITION_UP)
{
point.y -= stepY;
if (point.y < 0) point.y = 0;
}
if (command == ActionEvent.Command.POSITION_DOWN) point.y += stepY;
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_Evf_ZoomPosition, point));
break;
case ActionEvent.Command.POSITION_LEFT:
case ActionEvent.Command.POSITION_RIGHT:
const int stepX = 128;
point = _model.GetZoomPosition();
if (command == ActionEvent.Command.POSITION_LEFT)
{
point.x -= stepX;
if (point.x < 0) point.x = 0;
}
if (command == ActionEvent.Command.POSITION_RIGHT) point.x += stepX;
_processor.PostCommand(new SetPropertyCommand(ref _model, EDSDKLib.EDSDK.PropID_Evf_ZoomPosition, point));
break;
case ActionEvent.Command.REMOTESHOOTING_START:
_processor.PostCommand(new SetRemoteShootingCommand(ref _model, (uint)EDSDKLib.EDSDK.DcRemoteShootingMode.DcRemoteShootingModeStart));
break;
case ActionEvent.Command.REMOTESHOOTING_STOP:
_processor.PostCommand(new SetRemoteShootingCommand(ref _model, (uint)EDSDKLib.EDSDK.DcRemoteShootingMode.DcRemoteShootingModeStop));
break;
}
}
public void DownloadFile()
{
_processor.PostCommand(new DownloadAllFilesCommand(ref _model));
}
public void DeleteFile()
{
_processor.PostCommand(new DeleteAllFilesCommand(ref _model));
}
public void FormatVolumeCommand()
{
_processor.PostCommand(new FormatVolumeCommand(ref _model));
}
}
}