Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | /* Canon Powershot control terminal */ |
2 | //#include <Spi.h> |
||
3 | #include <Max3421e.h> |
||
4 | #include <Usb.h> |
||
5 | #include <simpletimer.h> |
||
6 | #include <ptp.h> |
||
7 | #include <canonps.h> |
||
8 | #include <qep_port.h> |
||
9 | #include <valuelist.h> |
||
10 | #include <psvaluetitles.h> |
||
11 | |||
12 | #include "ptpdpparser.h" |
||
13 | #include "ptpobjinfoparser.h" |
||
14 | #include "pseventparser.h" |
||
15 | #include "psconsole.h" |
||
16 | |||
17 | #define DEV_ADDR 1 |
||
18 | |||
19 | // Canon PowerShot S3 IS |
||
20 | #define DATA_IN_EP 1 |
||
21 | #define DATA_OUT_EP 2 |
||
22 | #define INTERRUPT_EP 3 |
||
23 | #define CONFIG_NUM 1 |
||
24 | |||
25 | class CamStateHandlers : public PSStateHandlers |
||
26 | { |
||
27 | enum CamStates { stInitial, stDisconnected, stConnected }; |
||
28 | CamStates stateConnected; |
||
29 | |||
30 | public: |
||
31 | CamStateHandlers() : stateConnected(stInitial) |
||
32 | { |
||
33 | }; |
||
34 | |||
35 | virtual void OnDeviceDisconnectedState(PTP *ptp); |
||
36 | virtual void OnDeviceInitializedState(PTP *ptp); |
||
37 | }; |
||
38 | |||
39 | CamStateHandlers CamStates; |
||
40 | SimpleTimer ControlTimer, PTPPollTimer; |
||
41 | |||
42 | CanonPS Ps(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates); |
||
43 | QEvent evtTick, evtAbort; |
||
44 | PSConsole psConsole; |
||
45 | |||
46 | void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp) |
||
47 | { |
||
48 | if (stateConnected == stConnected || stateConnected == stInitial) |
||
49 | { |
||
50 | stateConnected = stDisconnected; |
||
51 | PTPPollTimer.Disable(); |
||
52 | Notify(PSTR("Camera disconnected.\r\n")); |
||
53 | |||
54 | if (stateConnected == stConnected) |
||
55 | psConsole.dispatch(&evtTick); |
||
56 | } |
||
57 | } |
||
58 | |||
59 | void CamStateHandlers::OnDeviceInitializedState(PTP *ptp) |
||
60 | { |
||
61 | if (stateConnected == stDisconnected || stateConnected == stInitial) |
||
62 | { |
||
63 | stateConnected = stConnected; |
||
64 | PTPPollTimer.Enable(); |
||
65 | psConsole.dispatch(&evtTick); |
||
66 | } |
||
67 | int8_t index = psConsole.MenuSelect(); |
||
68 | |||
69 | if (index >= 0) |
||
70 | { |
||
71 | MenuSelectEvt menu_sel_evt; |
||
72 | menu_sel_evt.sig = MENU_SELECT_SIG; |
||
73 | menu_sel_evt.item_index = index; |
||
74 | psConsole.dispatch(&menu_sel_evt); // dispatch the event |
||
75 | } |
||
76 | } |
||
77 | |||
78 | void OnPTPPollTimer() |
||
79 | { |
||
80 | PSEventParser prs; |
||
81 | Ps.EventCheck(&prs); |
||
82 | |||
83 | if (uint32_t handle = prs.GetObjHandle()) |
||
84 | { |
||
85 | PTPObjInfoParser inf; |
||
86 | Ps.GetObjectInfo(handle, &inf); |
||
87 | } |
||
88 | } |
||
89 | |||
90 | void setup() |
||
91 | { |
||
92 | Serial.begin(115200); |
||
93 | Ps.Setup(); |
||
94 | delay( 200 ); |
||
95 | |||
96 | PTPPollTimer.Set(OnPTPPollTimer, 300); |
||
97 | |||
98 | evtTick.sig = TICK_SIG; |
||
99 | // evtAbort.sig = ABORT_SIG; |
||
100 | psConsole.init(); |
||
101 | |||
102 | Serial.println("Start"); |
||
103 | } |
||
104 | |||
105 | void loop() |
||
106 | { |
||
107 | Ps.Task(); |
||
108 | PTPPollTimer.Run(); |
||
109 | } |
||
110 |