Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | #include "psconsole.h" |
2 | #include <psvaluetitles.h> |
||
3 | #include <valuelist.h> |
||
4 | |||
5 | extern CanonPS Ps; |
||
6 | |||
7 | /* fixes avr-gcc incompatibility with virtual destructors */ |
||
8 | void operator delete( void *p ) {} |
||
9 | |||
10 | const char* menuMain[] = {"Capture", "View Settings", "Change Settings", "Viewfinder On", "Viewfinder Off"}; |
||
11 | const char* menuChangeSettings[] = {"Mode", "Aperture", "Shutter Speed", "WB", "ISO", "Exp Comp", "CamOutput", "Zoom"}; |
||
12 | const char* menuUpDown[] = {"<<", ">>"}; |
||
13 | |||
14 | #define MAIN_MENU_COUNT sizeof(menuMain) / sizeof(const char*) |
||
15 | #define CHSET_MENU_COUNT sizeof(menuChangeSettings) / sizeof(const char*) |
||
16 | #define UPDWN_MENU_COUNT sizeof(menuUpDown) / sizeof(const char*) |
||
17 | |||
18 | void PrintMode() |
||
19 | { |
||
20 | Notify(PSTR("Mode:")); |
||
21 | PrintValueTitle<uint8_t, VT_MODE, VT_MODE_COUNT, VT_MODE_TEXT_LEN>((PTP*)&Ps, PS_DPC_ShootingMode, ModeTitles); |
||
22 | Notify(PSTR("\r\n")); |
||
23 | } |
||
24 | |||
25 | void PrintAperture() |
||
26 | { |
||
27 | Notify(PSTR("F:")); |
||
28 | PrintValueTitle<uint16_t, VT_APERTURE, VT_APT_COUNT, VT_APT_TEXT_LEN>((PTP*)&Ps, PS_DPC_Aperture, ApertureTitles); |
||
29 | Notify(PSTR("\r\n")); |
||
30 | } |
||
31 | |||
32 | void PrintShutterSpeed() |
||
33 | { |
||
34 | Notify(PSTR("T:")); |
||
35 | PrintValueTitle<uint16_t, VT_SHSPEED, VT_SHSPEED_COUNT, VT_SHSPEED_TEXT_LEN>((PTP*)&Ps, PS_DPC_ShutterSpeed, ShutterSpeedTitles); |
||
36 | Notify(PSTR("\r\n")); |
||
37 | } |
||
38 | |||
39 | void PrintWB() |
||
40 | { |
||
41 | Notify(PSTR("WB:")); |
||
42 | PrintValueTitle<uint8_t, VT_WB, VT_WB_COUNT, VT_WB_TEXT_LEN>((PTP*)&Ps, PS_DPC_WhiteBalance, WbTitles); |
||
43 | Notify(PSTR("\r\n")); |
||
44 | } |
||
45 | |||
46 | void PrintIso() |
||
47 | { |
||
48 | Notify(PSTR("ISO:")); |
||
49 | PrintValueTitle<uint16_t, VT_ISO, VT_ISO_COUNT, VT_ISO_TEXT_LEN>((PTP*)&Ps, PS_DPC_ISOSpeed, IsoTitles); |
||
50 | Notify(PSTR("\r\n")); |
||
51 | } |
||
52 | |||
53 | void PrintExpCompensation() |
||
54 | { |
||
55 | Notify(PSTR("ExpComp:")); |
||
56 | PrintValueTitle<uint8_t, VT_EXPCOMP, VT_EXPCOMP_COUNT, VT_EXPCOMP_TEXT_LEN>((PTP*)&Ps, PS_DPC_ExpCompensation, ExpCompTitles); |
||
57 | Notify(PSTR("\r\n")); |
||
58 | } |
||
59 | |||
60 | void PrintCamOutput() |
||
61 | { |
||
62 | Notify(PSTR("CamOutput:")); |
||
63 | PrintValueTitle<uint8_t, VT_CAMOUTPUT, VT_CAMOUTPUT_COUNT, VT_CAMOUTPUT_TEXT_LEN>((PTP*)&Ps, PS_DPC_CameraOutput, CamOutputTitles); |
||
64 | Notify(PSTR("\r\n")); |
||
65 | } |
||
66 | |||
67 | void PrintZoom() |
||
68 | { |
||
69 | uint16_t val = 0; |
||
70 | Notify(PSTR("Zoom:")); |
||
71 | |||
72 | if (Ps.GetDevicePropValue(PS_DPC_Zoom, (uint16_t&)val) == PTP_RC_OK) |
||
73 | PrintHex<uint16_t>(val); |
||
74 | |||
75 | Notify(PSTR("\r\n")); |
||
76 | } |
||
77 | |||
78 | void PSConsole::ShowParams() |
||
79 | { |
||
80 | PrintMode(); |
||
81 | PrintAperture(); |
||
82 | PrintShutterSpeed(); |
||
83 | PrintWB(); |
||
84 | PrintIso(); |
||
85 | PrintExpCompensation(); |
||
86 | PrintCamOutput(); |
||
87 | PrintZoom(); |
||
88 | } |
||
89 | |||
90 | QState PSConsole::Initial(PSConsole *me, QEvent const *e) |
||
91 | { |
||
92 | return Q_TRAN(&PSConsole::Inactive); |
||
93 | } |
||
94 | |||
95 | QState PSConsole::Inactive(PSConsole *me, QEvent const *e) |
||
96 | { |
||
97 | switch (e->sig) |
||
98 | { |
||
99 | case Q_ENTRY_SIG: |
||
100 | Notify(PSTR("Inactive\r\n")); |
||
101 | return Q_HANDLED(); |
||
102 | case TICK_SIG: |
||
103 | return Q_TRAN(&PSConsole::Active); |
||
104 | } |
||
105 | return Q_SUPER(QHsm::top); |
||
106 | } |
||
107 | |||
108 | QState PSConsole::Active(PSConsole *me, QEvent const *e) |
||
109 | { |
||
110 | switch (e->sig) |
||
111 | { |
||
112 | case Q_ENTRY_SIG: |
||
113 | Notify(PSTR("Active\r\n")); |
||
114 | return Q_HANDLED(); |
||
115 | case Q_INIT_SIG: |
||
116 | return Q_TRAN(&PSConsole::MainMenu); |
||
117 | case TICK_SIG: |
||
118 | return Q_TRAN(&PSConsole::Inactive); |
||
119 | } |
||
120 | return Q_SUPER(QHsm::top); |
||
121 | } |
||
122 | |||
123 | void PSConsole::PrintMenuTitles(uint8_t count, const char **menu) |
||
124 | { |
||
125 | Serial.println(""); |
||
126 | for (uint8_t i=0; i<=count; i++) |
||
127 | { |
||
128 | Serial.print(i, DEC); |
||
129 | Serial.print(". "); |
||
130 | |||
131 | if (i == 0) |
||
132 | Serial.println("<..>"); |
||
133 | else |
||
134 | Serial.println(menu[i-1]); |
||
135 | } |
||
136 | Serial.println(""); |
||
137 | } |
||
138 | |||
139 | QState PSConsole::MainMenu(PSConsole *me, QEvent const *e) |
||
140 | { |
||
141 | switch (e->sig) |
||
142 | { |
||
143 | case Q_ENTRY_SIG: |
||
144 | PrintMenuTitles(MAIN_MENU_COUNT, menuMain); |
||
145 | return Q_HANDLED(); |
||
146 | case MENU_SELECT_SIG: |
||
147 | { |
||
148 | switch (((MenuSelectEvt*)e)->item_index) |
||
149 | { |
||
150 | case 0: |
||
151 | PrintMenuTitles(MAIN_MENU_COUNT, menuMain); |
||
152 | return Q_HANDLED(); |
||
153 | case 1: |
||
154 | Ps.SetDevicePropValue(PS_DPC_CaptureTransferMode, (uint16_t)0x0D); |
||
155 | Ps.Capture(); |
||
156 | return Q_HANDLED(); |
||
157 | case 2: |
||
158 | ShowParams(); |
||
159 | PrintMenuTitles(MAIN_MENU_COUNT, menuMain); |
||
160 | return Q_HANDLED(); |
||
161 | case 3: |
||
162 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
163 | case 4: |
||
164 | Ps.Operation(PS_OC_ViewfinderOn); |
||
165 | return Q_HANDLED(); |
||
166 | case 5: |
||
167 | Ps.Operation(PS_OC_ViewfinderOff); |
||
168 | return Q_HANDLED(); |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | return Q_SUPER(&PSConsole::Active); |
||
173 | } |
||
174 | |||
175 | QState PSConsole::ChangeSettingsMenu(PSConsole *me, QEvent const *e) |
||
176 | { |
||
177 | switch (e->sig) |
||
178 | { |
||
179 | case Q_ENTRY_SIG: |
||
180 | PrintMenuTitles(CHSET_MENU_COUNT, menuChangeSettings); |
||
181 | return Q_HANDLED(); |
||
182 | case MENU_SELECT_SIG: |
||
183 | { |
||
184 | switch (((MenuSelectEvt*)e)->item_index) |
||
185 | { |
||
186 | case 0: |
||
187 | return Q_TRAN(&PSConsole::MainMenu); |
||
188 | case 1: // Aperture |
||
189 | return Q_TRAN(&PSConsole::ChangeModeMenu); |
||
190 | case 2: // Aperture |
||
191 | return Q_TRAN(&PSConsole::ChangeApertureMenu); |
||
192 | case 3: // Shutter Speed |
||
193 | return Q_TRAN(&PSConsole::ChangeShutterSpeedMenu); |
||
194 | case 4: // White Balance |
||
195 | return Q_TRAN(&PSConsole::ChangeWBMenu); |
||
196 | case 5: // ISO |
||
197 | return Q_TRAN(&PSConsole::ChangeIsoMenu); |
||
198 | case 6: // Exposure Compensation |
||
199 | return Q_TRAN(&PSConsole::ChangeExpCompMenu); |
||
200 | case 7: // Camera Output |
||
201 | return Q_TRAN(&PSConsole::ChangeCamOutputMenu); |
||
202 | case 8: // Zoom |
||
203 | return Q_TRAN(&PSConsole::ChangeZoomMenu); |
||
204 | } // switch |
||
205 | } |
||
206 | } |
||
207 | return Q_SUPER(&PSConsole::Active); |
||
208 | } |
||
209 | |||
210 | QState PSConsole::ChangeModeMenu(PSConsole *me, QEvent const *e) |
||
211 | { |
||
212 | switch (e->sig) |
||
213 | { |
||
214 | case Q_ENTRY_SIG: |
||
215 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
216 | PrintMode(); |
||
217 | return Q_HANDLED(); |
||
218 | case MENU_SELECT_SIG: |
||
219 | { |
||
220 | uint8_t new_value; |
||
221 | |||
222 | switch (((MenuSelectEvt*)e)->item_index) |
||
223 | { |
||
224 | case 0: |
||
225 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
226 | case 2: |
||
227 | StepUp<uint8_t>((PTP*)&Ps, PS_DPC_ShootingMode); |
||
228 | PrintMode(); |
||
229 | return Q_HANDLED(); |
||
230 | case 1: |
||
231 | StepDown<uint8_t>((PTP*)&Ps, PS_DPC_ShootingMode); |
||
232 | PrintMode(); |
||
233 | return Q_HANDLED(); |
||
234 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
235 | } // case MENU_SELECT_SIG: |
||
236 | } |
||
237 | return Q_SUPER(&PSConsole::Active); |
||
238 | } |
||
239 | |||
240 | QState PSConsole::ChangeApertureMenu(PSConsole *me, QEvent const *e) |
||
241 | { |
||
242 | switch (e->sig) |
||
243 | { |
||
244 | case Q_ENTRY_SIG: |
||
245 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
246 | PrintAperture(); |
||
247 | return Q_HANDLED(); |
||
248 | case MENU_SELECT_SIG: |
||
249 | { |
||
250 | uint8_t new_value; |
||
251 | |||
252 | switch (((MenuSelectEvt*)e)->item_index) |
||
253 | { |
||
254 | case 0: |
||
255 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
256 | case 2: |
||
257 | StepUp<uint16_t>((PTP*)&Ps, PS_DPC_Aperture); |
||
258 | PrintAperture(); |
||
259 | return Q_HANDLED(); |
||
260 | case 1: |
||
261 | StepDown<uint16_t>((PTP*)&Ps, PS_DPC_Aperture); |
||
262 | PrintAperture(); |
||
263 | return Q_HANDLED(); |
||
264 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
265 | } // case MENU_SELECT_SIG: |
||
266 | } |
||
267 | return Q_SUPER(&PSConsole::Active); |
||
268 | } |
||
269 | |||
270 | QState PSConsole::ChangeShutterSpeedMenu(PSConsole *me, QEvent const *e) |
||
271 | { |
||
272 | switch (e->sig) |
||
273 | { |
||
274 | case Q_ENTRY_SIG: |
||
275 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
276 | PrintShutterSpeed(); |
||
277 | return Q_HANDLED(); |
||
278 | case MENU_SELECT_SIG: |
||
279 | { |
||
280 | uint8_t new_value; |
||
281 | |||
282 | switch (((MenuSelectEvt*)e)->item_index) |
||
283 | { |
||
284 | case 0: |
||
285 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
286 | case 2: |
||
287 | StepUp<uint16_t>((PTP*)&Ps, PS_DPC_ShutterSpeed); |
||
288 | PrintShutterSpeed(); |
||
289 | return Q_HANDLED(); |
||
290 | case 1: |
||
291 | StepDown<uint16_t>((PTP*)&Ps, PS_DPC_ShutterSpeed); |
||
292 | PrintShutterSpeed(); |
||
293 | return Q_HANDLED(); |
||
294 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
295 | } // case MENU_SELECT_SIG: |
||
296 | } |
||
297 | return Q_SUPER(&PSConsole::Active); |
||
298 | } |
||
299 | |||
300 | QState PSConsole::ChangeWBMenu(PSConsole *me, QEvent const *e) |
||
301 | { |
||
302 | switch (e->sig) |
||
303 | { |
||
304 | case Q_ENTRY_SIG: |
||
305 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
306 | PrintWB(); |
||
307 | return Q_HANDLED(); |
||
308 | case MENU_SELECT_SIG: |
||
309 | { |
||
310 | uint8_t new_value; |
||
311 | |||
312 | switch (((MenuSelectEvt*)e)->item_index) |
||
313 | { |
||
314 | case 0: |
||
315 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
316 | |||
317 | case 2: |
||
318 | StepUp<uint8_t>((PTP*)&Ps, PS_DPC_WhiteBalance); |
||
319 | PrintWB(); |
||
320 | return Q_HANDLED(); |
||
321 | case 1: |
||
322 | StepDown<uint8_t>((PTP*)&Ps, PS_DPC_WhiteBalance); |
||
323 | PrintWB(); |
||
324 | return Q_HANDLED(); |
||
325 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
326 | } // case MENU_SELECT_SIG: |
||
327 | } |
||
328 | return Q_SUPER(&PSConsole::Active); |
||
329 | } |
||
330 | |||
331 | QState PSConsole::ChangeIsoMenu(PSConsole *me, QEvent const *e) |
||
332 | { |
||
333 | switch (e->sig) |
||
334 | { |
||
335 | case Q_ENTRY_SIG: |
||
336 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
337 | PrintIso(); |
||
338 | return Q_HANDLED(); |
||
339 | case MENU_SELECT_SIG: |
||
340 | { |
||
341 | uint8_t new_value; |
||
342 | |||
343 | switch (((MenuSelectEvt*)e)->item_index) |
||
344 | { |
||
345 | case 0: |
||
346 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
347 | case 2: |
||
348 | StepUp<uint16_t>((PTP*)&Ps, PS_DPC_ISOSpeed); |
||
349 | PrintIso(); |
||
350 | return Q_HANDLED(); |
||
351 | case 1: |
||
352 | StepDown<uint16_t>((PTP*)&Ps, PS_DPC_ISOSpeed); |
||
353 | PrintIso(); |
||
354 | return Q_HANDLED(); |
||
355 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
356 | } // case MENU_SELECT_SIG: |
||
357 | } |
||
358 | return Q_SUPER(&PSConsole::Active); |
||
359 | } |
||
360 | |||
361 | QState PSConsole::ChangeExpCompMenu(PSConsole *me, QEvent const *e) |
||
362 | { |
||
363 | switch (e->sig) |
||
364 | { |
||
365 | case Q_ENTRY_SIG: |
||
366 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
367 | PrintExpCompensation(); |
||
368 | return Q_HANDLED(); |
||
369 | case MENU_SELECT_SIG: |
||
370 | { |
||
371 | uint8_t new_value; |
||
372 | |||
373 | switch (((MenuSelectEvt*)e)->item_index) |
||
374 | { |
||
375 | case 0: |
||
376 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
377 | case 1: |
||
378 | StepUp<uint8_t>((PTP*)&Ps, PS_DPC_ExpCompensation); |
||
379 | PrintExpCompensation(); |
||
380 | return Q_HANDLED(); |
||
381 | case 2: |
||
382 | StepDown<uint8_t>((PTP*)&Ps, PS_DPC_ExpCompensation); |
||
383 | PrintExpCompensation(); |
||
384 | return Q_HANDLED(); |
||
385 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
386 | } // case MENU_SELECT_SIG: |
||
387 | } |
||
388 | return Q_SUPER(&PSConsole::Active); |
||
389 | } |
||
390 | |||
391 | QState PSConsole::ChangeCamOutputMenu(PSConsole *me, QEvent const *e) |
||
392 | { |
||
393 | switch (e->sig) |
||
394 | { |
||
395 | case Q_ENTRY_SIG: |
||
396 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
397 | PrintCamOutput(); |
||
398 | return Q_HANDLED(); |
||
399 | case MENU_SELECT_SIG: |
||
400 | { |
||
401 | switch (((MenuSelectEvt*)e)->item_index) |
||
402 | { |
||
403 | case 0: |
||
404 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
405 | case 2: |
||
406 | StepUp<uint8_t>((PTP*)&Ps, PS_DPC_CameraOutput); |
||
407 | PrintCamOutput(); |
||
408 | return Q_HANDLED(); |
||
409 | case 1: |
||
410 | StepDown<uint8_t>((PTP*)&Ps, PS_DPC_CameraOutput); |
||
411 | PrintCamOutput(); |
||
412 | return Q_HANDLED(); |
||
413 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
414 | } // case MENU_SELECT_SIG: |
||
415 | } |
||
416 | return Q_SUPER(&PSConsole::Active); |
||
417 | } |
||
418 | |||
419 | QState PSConsole::ChangeZoomMenu(PSConsole *me, QEvent const *e) |
||
420 | { |
||
421 | switch (e->sig) |
||
422 | { |
||
423 | case Q_ENTRY_SIG: |
||
424 | PrintMenuTitles(UPDWN_MENU_COUNT, menuUpDown); |
||
425 | PrintZoom(); |
||
426 | return Q_HANDLED(); |
||
427 | case MENU_SELECT_SIG: |
||
428 | { |
||
429 | switch (((MenuSelectEvt*)e)->item_index) |
||
430 | { |
||
431 | case 0: |
||
432 | return Q_TRAN(&PSConsole::ChangeSettingsMenu); |
||
433 | case 2: |
||
434 | StepUp<uint16_t>((PTP*)&Ps, PS_DPC_Zoom); |
||
435 | PrintZoom(); |
||
436 | return Q_HANDLED(); |
||
437 | case 1: |
||
438 | StepDown<uint16_t>((PTP*)&Ps, PS_DPC_Zoom); |
||
439 | PrintZoom(); |
||
440 | return Q_HANDLED(); |
||
441 | } // switch (((MenuSelectEvt*)e)->item_index) |
||
442 | } // case MENU_SELECT_SIG: |
||
443 | } |
||
444 | return Q_SUPER(&PSConsole::Active); |
||
445 | } |
||
446 | |||
447 | static TickEvt tick_evt; |
||
448 | |||
449 | int8_t PSConsole::MenuSelect() |
||
450 | { |
||
451 | if( !Serial.available()) |
||
452 | return -1; |
||
453 | |||
454 | uint8_t char_count = 0; |
||
455 | uint8_t index = 0; |
||
456 | |||
457 | while (Serial.available() > 0 && char_count < 2) |
||
458 | { |
||
459 | uint8_t key = Serial.read(); |
||
460 | key -= '0'; |
||
461 | |||
462 | if (index) |
||
463 | { |
||
464 | uint8_t tmp = index; |
||
465 | // index *= 10; |
||
466 | index <<= 3; |
||
467 | index += tmp; |
||
468 | index += tmp; |
||
469 | } |
||
470 | index += key; |
||
471 | char_count ++; |
||
472 | } |
||
473 | return (char_count) ? (int8_t)index : (int8_t)-1; |
||
474 | } |
||
475 |