Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | /* EOS Focus control demo */ |
2 | /* Tested with 7D */ |
||
3 | #include <inttypes.h> |
||
4 | #include <avr/pgmspace.h> |
||
5 | |||
6 | //#include <Spi.h> |
||
7 | #include <Max3421e.h> |
||
8 | #include <Max3421e_constants.h> |
||
9 | #include <Max_LCD.h> |
||
10 | #include <Usb.h> |
||
11 | |||
12 | #include <ptp.h> |
||
13 | #include <canoneos.h> |
||
14 | |||
15 | #define DEV_ADDR 1 |
||
16 | |||
17 | // Canon EOS 400D |
||
18 | #define DATA_IN_EP 1 |
||
19 | #define DATA_OUT_EP 2 |
||
20 | #define INTERRUPT_EP 3 |
||
21 | #define CONFIG_NUM 1 |
||
22 | |||
23 | class CamStateHandlers : public EOSStateHandlers |
||
24 | { |
||
25 | enum CamStates { stInitial, stDisconnected, stConnected }; |
||
26 | CamStates stateConnected; |
||
27 | |||
28 | public: |
||
29 | CamStateHandlers() : stateConnected(stInitial) |
||
30 | { |
||
31 | }; |
||
32 | |||
33 | virtual void OnDeviceDisconnectedState(PTP *ptp); |
||
34 | virtual void OnDeviceInitializedState(PTP *ptp); |
||
35 | }; |
||
36 | |||
37 | CamStateHandlers CamStates; |
||
38 | CanonEOS Eos(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates); |
||
39 | |||
40 | void setup() { |
||
41 | Serial.begin( 115200 ); |
||
42 | Serial.println("Start"); |
||
43 | Eos.Setup(); |
||
44 | delay( 200 ); |
||
45 | } |
||
46 | |||
47 | void loop() |
||
48 | { |
||
49 | Eos.Task(); |
||
50 | } |
||
51 | |||
52 | void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp) |
||
53 | { |
||
54 | if (stateConnected == stConnected || stateConnected == stInitial) |
||
55 | { |
||
56 | stateConnected = stDisconnected; |
||
57 | Notify(PSTR("Camera disconnected.\r\n")); |
||
58 | } |
||
59 | } |
||
60 | |||
61 | void CamStateHandlers::OnDeviceInitializedState(PTP *ptp) |
||
62 | { |
||
63 | if (stateConnected == stDisconnected) |
||
64 | { |
||
65 | stateConnected = stConnected; |
||
66 | |||
67 | // Switch LiveView on |
||
68 | Eos.SwitchLiveView(true); |
||
69 | delay(50); |
||
70 | |||
71 | for (uint8_t i=0; i<10; i++) |
||
72 | { |
||
73 | if (i > 4) |
||
74 | Eos.MoveFocus(3); |
||
75 | else |
||
76 | Eos.MoveFocus(0x8003); |
||
77 | |||
78 | delay(100); |
||
79 | Eos.Capture(); |
||
80 | delay(1500); |
||
81 | } |
||
82 | |||
83 | // Switch LiveView off |
||
84 | Eos.SwitchLiveView(false); |
||
85 | } |
||
86 | } |
||
87 |