Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
/* EOS control terminal */
2
//#include <Spi.h>
3
#include <Max3421e.h>
4
#include <Usb.h>
5
#include <simpletimer.h>
6
#include <ptp.h>
7
#include <canoneos.h>
8
#include <qep_port.h>
9
#include <valuelist.h>
10
#include <eosvaluetitles.h>
11
 
12
#include "eoseventparser.h"
13
#include "eosconsole.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
#define EEP_APERTURE_LIST_OFFSET    0
24
#define EEP_APERTURE_LIST_SIZE      32
25
 
26
#define EEP_SHTSPEED_LIST_OFFSET    (EEP_APERTURE_LIST_OFFSET + EEP_APERTURE_LIST_SIZE)
27
#define EEP_SHTSPEED_LIST_SIZE      64
28
 
29
#define EEP_WBALANCE_LIST_OFFSET    (EEP_SHTSPEED_LIST_OFFSET + EEP_SHTSPEED_LIST_SIZE)
30
#define EEP_WBALANCE_LIST_SIZE      12
31
 
32
#define EEP_PICSTYLE_LIST_OFFSET    (EEP_WBALANCE_LIST_OFFSET + EEP_WBALANCE_LIST_SIZE)
33
#define EEP_PICSTYLE_LIST_SIZE      12
34
 
35
#define EEP_EXPOCOR_LIST_OFFSET     (EEP_PICSTYLE_LIST_OFFSET + EEP_PICSTYLE_LIST_SIZE)
36
#define EEP_EXPOCOR_LIST_SIZE       48
37
 
38
#define EEP_ISO_LIST_OFFSET         (EEP_EXPOCOR_LIST_OFFSET + EEP_EXPOCOR_LIST_SIZE)
39
#define EEP_ISO_LIST_SIZE           8
40
 
41
EEPROMByteList          vlAperture(EEP_APERTURE_LIST_OFFSET, EEP_APERTURE_LIST_SIZE);
42
EEPROMByteList          vlShutterSpeed(EEP_SHTSPEED_LIST_OFFSET, EEP_SHTSPEED_LIST_SIZE);
43
EEPROMByteList          vlWhiteBalance(EEP_WBALANCE_LIST_OFFSET, EEP_WBALANCE_LIST_SIZE);
44
EEPROMByteList          vlPictureStyle(EEP_PICSTYLE_LIST_OFFSET, EEP_PICSTYLE_LIST_SIZE);
45
EEPROMByteList          vlIso(EEP_EXPOCOR_LIST_OFFSET, EEP_EXPOCOR_LIST_SIZE);
46
EEPROMByteList          vlExpCompensation(EEP_EXPOCOR_LIST_OFFSET, EEP_EXPOCOR_LIST_SIZE);
47
 
48
class CamStateHandlers : public EOSStateHandlers
49
{
50
      enum CamStates { stInitial, stDisconnected, stConnected };
51
      CamStates stateConnected;
52
 
53
public:
54
      CamStateHandlers() : stateConnected(stInitial)
55
      {
56
      };
57
 
58
      virtual void OnDeviceDisconnectedState(PTP *ptp);
59
      virtual void OnDeviceInitializedState(PTP *ptp);
60
};
61
 
62
CamStateHandlers  CamStates;
63
SimpleTimer       ControlTimer, PTPPollTimer;
64
 
65
CanonEOS          Eos(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates);
66
QEvent            evtTick, evtAbort;
67
EOSConsole        eosConsole;
68
 
69
uint8_t  dpMode         = 0;
70
uint8_t  dpAperture     = 0;
71
uint8_t  dpShutterSpeed = 0;
72
uint8_t  dpWb           = 0;
73
uint8_t  dpPStyle       = 0;
74
uint8_t  dpIso          = 0;
75
uint8_t  dpExpComp      = 0;
76
 
77
void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)
78
{
79
    if (stateConnected == stConnected || stateConnected == stInitial)
80
    {
81
        stateConnected = stDisconnected;
82
        PTPPollTimer.Disable();
83
        Notify(PSTR("Camera disconnected.\r\n"));
84
 
85
        if (stateConnected == stConnected)
86
            eosConsole.dispatch(&evtTick);
87
    }
88
}
89
 
90
void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)
91
{
92
    if (stateConnected == stDisconnected)
93
    {
94
        stateConnected = stConnected;
95
        PTPPollTimer.Enable();
96
        eosConsole.dispatch(&evtTick);
97
    }
98
    int8_t  index = eosConsole.MenuSelect();
99
 
100
    if (index >= 0)
101
    {
102
        MenuSelectEvt     menu_sel_evt;
103
        menu_sel_evt.sig         = MENU_SELECT_SIG;
104
        menu_sel_evt.item_index  = index;
105
        eosConsole.dispatch(&menu_sel_evt);      // dispatch the event
106
    }
107
}
108
 
109
void OnControlTimer()
110
{
111
//    ExtControls.CheckControls();
112
//    hdrCapture.PostEvent(&evtTick);
113
//    Screen::Run(&LCD);
114
}
115
 
116
void OnPTPPollTimer()
117
{
118
    EOSEventParser    prs;
119
    Eos.EventCheck(&prs);
120
}
121
 
122
void setup()
123
{
124
    Serial.begin(115200);
125
    Eos.Setup();
126
    delay( 200 );
127
 
128
    PTPPollTimer.Set(OnPTPPollTimer, 300);
129
 
130
    // 1ms is the perfect interval for encoder polling
131
    ControlTimer.Set(OnControlTimer, 1);
132
    ControlTimer.Enable();
133
 
134
    evtTick.sig = TICK_SIG;
135
//    evtAbort.sig = ABORT_SIG;
136
    eosConsole.init();
137
 
138
    Serial.println("Start");
139
}
140
 
141
void loop()
142
{
143
    Eos.Task();
144
    PTPPollTimer.Run();
145
    ControlTimer.Run();
146
}
147