Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | /* Copyright (C) 2010-2011 Circuits At Home, LTD. All rights reserved. |
2 | |||
3 | This software may be distributed and modified under the terms of the GNU |
||
4 | General Public License version 2 (GPL2) as published by the Free Software |
||
5 | Foundation and appearing in the file GPL2.TXT included in the packaging of |
||
6 | this file. Please note that GPL2 Section 2[b] requires that all works based |
||
7 | on this software must also be made publicly available under the terms of |
||
8 | the GPL2 ("Copyleft"). |
||
9 | |||
10 | Contact information |
||
11 | ------------------- |
||
12 | |||
13 | Circuits At Home, LTD |
||
14 | Web : http://www.circuitsathome.com |
||
15 | e-mail : support@circuitsathome.com |
||
16 | */ |
||
17 | #include "canoneos.h" |
||
18 | |||
19 | |||
20 | void EOSStateHandlers::OnSessionOpenedState(PTP *ptp) |
||
21 | { |
||
22 | if (!FAILED(((CanonEOS*)ptp)->SetPCConnectMode(1)) && !FAILED(((CanonEOS*)ptp)->SetExtendedEventInfo(1))) |
||
23 | ptp->SetState(PTP_STATE_DEVICE_INITIALIZED); |
||
24 | } |
||
25 | |||
26 | uint32_t ImgQualitySupplier::GetDataSize() |
||
27 | { |
||
28 | return ((pictFormat & 0xFFFF0000) ? 0x0000002C : 0x0000001C); |
||
29 | } |
||
30 | |||
31 | void ImgQualitySupplier::GetData(const uint16_t len, uint8_t *pbuf) |
||
32 | { |
||
33 | uint8_t num_files = (pictFormat & 0xFFFF0000) ? 2 : 1; |
||
34 | |||
35 | ((uint32_t*)pbuf)[0] = (num_files == 2) ? 0x0000002C : 0x0000001C; |
||
36 | ((uint32_t*)pbuf)[1] = (uint32_t) EOS_DPC_ImageQuality; |
||
37 | ((uint32_t*)pbuf)[2] = (uint32_t) num_files; |
||
38 | |||
39 | uint32_t format = pictFormat; |
||
40 | |||
41 | for (uint8_t i=0, pos=3; i<num_files; i++) |
||
42 | { |
||
43 | ((uint32_t*)pbuf)[pos++] = 0x00000010; |
||
44 | |||
45 | for (uint8_t j=0; j<3; j++, format >>= 4) |
||
46 | ((uint32_t*)pbuf)[pos++] = (uint32_t)(format & 0xF); |
||
47 | } |
||
48 | } |
||
49 | |||
50 | CanonEOS::CanonEOS(uint8_t addr, uint8_t epin, uint8_t epout, uint8_t epint, uint8_t nconf, PTPStateHandlers *s) |
||
51 | : PTP(addr, epin, epout, epint, nconf, s) |
||
52 | { |
||
53 | } |
||
54 | |||
55 | uint16_t CanonEOS::SetImageQuality(uint32_t format) |
||
56 | { |
||
57 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
58 | OperFlags flags = { 0, 0, 1, 1, 1, 0 }; |
||
59 | |||
60 | ImgQualitySupplier sup; |
||
61 | sup.SetPictureFormat(format); |
||
62 | |||
63 | if ( (ptp_error = Transaction(EOS_OC_SetDevicePropValue, &flags, NULL, (void*)&sup)) != PTP_RC_OK) |
||
64 | PTPTRACE2("SetImageQuality error", ptp_error); |
||
65 | |||
66 | return ptp_error; |
||
67 | } |
||
68 | |||
69 | uint16_t CanonEOS::SetPCConnectMode(uint8_t mode) |
||
70 | { |
||
71 | uint32_t params[1]; |
||
72 | params[0] = (uint32_t) mode; |
||
73 | return Operation(EOS_OC_SetPCConnectMode, 1, params); |
||
74 | } |
||
75 | |||
76 | uint16_t CanonEOS::SetExtendedEventInfo(uint8_t mode) |
||
77 | { |
||
78 | uint32_t params[1]; |
||
79 | params[0] = (uint32_t) mode; |
||
80 | return Operation(EOS_OC_SetExtendedEventInfo, 1, params); |
||
81 | } |
||
82 | |||
83 | uint16_t CanonEOS::StartBulb() |
||
84 | { |
||
85 | uint32_t params[3]; |
||
86 | |||
87 | params[0] = 0xfffffff8; |
||
88 | params[1] = 0x00001000; |
||
89 | params[2] = 0x00000000; |
||
90 | |||
91 | Operation(0x911A, 3, params); |
||
92 | Operation(0x911B, 0, NULL); |
||
93 | Operation(0x9125, 0, NULL); |
||
94 | |||
95 | return PTP_RC_OK; |
||
96 | } |
||
97 | |||
98 | uint16_t CanonEOS::StopBulb() |
||
99 | { |
||
100 | uint32_t params[3]; |
||
101 | |||
102 | params[0] = 0xffffffff; |
||
103 | params[1] = 0x00001000; |
||
104 | params[2] = 0x00000000; |
||
105 | Operation(0x911A, 3, params); |
||
106 | |||
107 | params[0] = 0xfffffffc; |
||
108 | Operation(0x911A, 3, params); |
||
109 | Operation(0x9126, 0, NULL); |
||
110 | Operation(0x911C, 0, NULL); |
||
111 | |||
112 | return PTP_RC_OK; |
||
113 | } |
||
114 | |||
115 | uint16_t CanonEOS::CancelTransfer(uint32_t object_id) |
||
116 | { |
||
117 | uint32_t params[1]; |
||
118 | params[0] = object_id; |
||
119 | |||
120 | return Operation(EOS_OC_CancelTransfer, 1, params); |
||
121 | } |
||
122 | |||
123 | uint16_t CanonEOS::ResetTransfer(uint32_t object_id) |
||
124 | { |
||
125 | uint32_t params[1]; |
||
126 | params[0] = object_id; |
||
127 | |||
128 | return Operation(EOS_OC_ResetTransfer, 1, params); |
||
129 | } |
||
130 | |||
131 | uint16_t CanonEOS::SwitchLiveView(bool on) |
||
132 | { |
||
133 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
134 | |||
135 | if ((ptp_error = SetProperty(EOS_DPC_LiveView, (on) ? 2 : 0)) == PTP_RC_OK) |
||
136 | { |
||
137 | if (on) |
||
138 | { |
||
139 | if ((ptp_error = SetProperty(0xD1B3, 0)) != PTP_RC_OK) |
||
140 | { |
||
141 | PTPTRACE2("LiveView start failure:", ptp_error); |
||
142 | SetProperty(EOS_DPC_LiveView, 0); |
||
143 | return PTP_RC_GeneralError; |
||
144 | } |
||
145 | } |
||
146 | } |
||
147 | return ptp_error; |
||
148 | } |
||
149 | |||
150 | uint16_t CanonEOS::MoveFocus(uint16_t step) |
||
151 | { |
||
152 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
153 | OperFlags flags = { 1, 0, 0, 0, 0, 0 }; |
||
154 | uint32_t params[1]; |
||
155 | |||
156 | params[0] = (uint32_t) step; |
||
157 | |||
158 | if ( (ptp_error = Transaction(EOS_OC_MoveFocus, &flags, params, NULL)) != PTP_RC_OK) |
||
159 | PTPTRACE2("MoveFocus error: ", ptp_error); |
||
160 | |||
161 | return ptp_error; |
||
162 | } |
||
163 | |||
164 | uint16_t CanonEOS::EventCheck(PTPReadParser *parser) |
||
165 | { |
||
166 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
167 | OperFlags flags = { 0, 0, 0, 1, 1, 0 }; |
||
168 | |||
169 | if ( (ptp_error = Transaction(0x9116, &flags, NULL, parser)) != PTP_RC_OK) |
||
170 | PTPTRACE2("EOSEventCheck error:", ptp_error); |
||
171 | |||
172 | return ptp_error; |
||
173 | } |
||
174 | |||
175 | uint16_t CanonEOS::Capture() |
||
176 | { |
||
177 | return Operation(EOS_OC_Capture, 0, NULL); |
||
178 | } |
||
179 | |||
180 | |||
181 | uint16_t CanonEOS::SetProperty(uint16_t prop, uint32_t val) |
||
182 | { |
||
183 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
184 | OperFlags flags = { 0, 0, 1, 1, 3, 12 }; |
||
185 | uint32_t params[3]; |
||
186 | |||
187 | params[0] = 0x0000000C; |
||
188 | params[1] = (uint32_t)prop; |
||
189 | params[2] = val; |
||
190 | |||
191 | if ( (ptp_error = Transaction(EOS_OC_SetDevicePropValue, &flags, NULL, (void*)params)) != PTP_RC_OK) |
||
192 | PTPTRACE2("SetProperty error:", ptp_error); |
||
193 | |||
194 | return ptp_error; |
||
195 | } |
||
196 | |||
197 | uint16_t CanonEOS::GetProperty(uint16_t prop, PTPReadParser *parser) |
||
198 | { |
||
199 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
200 | OperFlags flags = { 1, 0, 0, 1, 1, 0 }; |
||
201 | uint32_t params[1]; |
||
202 | |||
203 | params[0] = (uint32_t)prop; |
||
204 | |||
205 | if ( (ptp_error = Transaction(EOS_OC_GetDevicePropValue, &flags, params, (void*)parser)) != PTP_RC_OK) |
||
206 | PTPTRACE2("GetProperty error:", ptp_error); |
||
207 | |||
208 | return ptp_error; |
||
209 | } |
||
210 | |||
211 | uint16_t CanonEOS::GetDeviceInfoEx(PTPReadParser *parser) |
||
212 | { |
||
213 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
214 | OperFlags flags = { 0, 0, 0, 1, 1, 0 }; |
||
215 | |||
216 | if ( (ptp_error = Transaction(EOS_OC_GetDeviceInfoEx, &flags, NULL, (void*)parser)) != PTP_RC_OK) |
||
217 | PTPTRACE2("GetDeviceInfo error:", ptp_error); |
||
218 | |||
219 | return ptp_error; |
||
220 | } |
||
221 | |||
222 | uint16_t CanonEOS::GetObject(uint32_t object_id, uint32_t parent_id, PTPReadParser *parser) |
||
223 | { |
||
224 | uint16_t ptp_error = PTP_RC_GeneralError; |
||
225 | OperFlags flags = { 2, 0, 0, 1, 1, 0 }; |
||
226 | uint32_t params[2]; |
||
227 | |||
228 | params[0] = object_id; |
||
229 | params[1] = parent_id; |
||
230 | |||
231 | if ( (ptp_error = Transaction(EOS_OC_GetObject, &flags, params, (void*)parser)) != PTP_RC_OK) |
||
232 | PTPTRACE2("GetObject error:", ptp_error); |
||
233 | |||
234 | return ptp_error; |
||
235 | } |