Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
/* Digital camera controller board test sketch */
2
//#include <Spi.h>
3
#include <Max3421e.h>
4
#include <Usb.h>
5
#include <Max_LCD.h>
6
#include <simpletimer.h>
7
#include <valuelist.h>
8
#include <canoneos.h>
9
#include <qep_port.h>
10
 
11
#include "camcontroller.h"
12
#include "controls.h"
13
#include "eoseventparser.h"
14
#include "dataitem.h"
15
#include "screenitem.h"
16
#include "screen.h"
17
#include "menu.h"
18
#include "hdrcapture.h"
19
 
20
#define DEV_ADDR        1
21
 
22
// Canon EOS 400D
23
#define DATA_IN_EP      1
24
#define DATA_OUT_EP     2
25
#define INTERRUPT_EP    3
26
#define CONFIG_NUM      1
27
 
28
#define EEP_APERTURE_LIST_OFFSET    0
29
#define EEP_APERTURE_LIST_SIZE      32
30
 
31
#define EEP_SHTSPEED_LIST_OFFSET    (EEP_APERTURE_LIST_OFFSET + EEP_APERTURE_LIST_SIZE)
32
#define EEP_SHTSPEED_LIST_SIZE      64
33
 
34
#define EEP_WBALANCE_LIST_OFFSET    (EEP_SHTSPEED_LIST_OFFSET + EEP_SHTSPEED_LIST_SIZE)
35
#define EEP_WBALANCE_LIST_SIZE      12
36
 
37
#define EEP_PICSTYLE_LIST_OFFSET    (EEP_WBALANCE_LIST_OFFSET + EEP_WBALANCE_LIST_SIZE)
38
#define EEP_PICSTYLE_LIST_SIZE      12
39
 
40
#define EEP_EXPOCOR_LIST_OFFSET     (EEP_PICSTYLE_LIST_OFFSET + EEP_PICSTYLE_LIST_SIZE)
41
#define EEP_EXPOCOR_LIST_SIZE       48
42
 
43
#define EEP_ISO_LIST_OFFSET         (EEP_EXPOCOR_LIST_OFFSET + EEP_EXPOCOR_LIST_SIZE)
44
#define EEP_ISO_LIST_SIZE           8
45
 
46
EEPROMByteList          vlAperture(EEP_APERTURE_LIST_OFFSET, EEP_APERTURE_LIST_SIZE);
47
EEPROMByteList          vlShutterSpeed(EEP_SHTSPEED_LIST_OFFSET, EEP_SHTSPEED_LIST_SIZE);
48
EEPROMByteList          vlWhiteBalance(EEP_WBALANCE_LIST_OFFSET, EEP_WBALANCE_LIST_SIZE);
49
EEPROMByteList          vlPictureStyle(EEP_PICSTYLE_LIST_OFFSET, EEP_PICSTYLE_LIST_SIZE);
50
EEPROMByteList          vlIso(EEP_ISO_LIST_OFFSET, EEP_ISO_LIST_SIZE);
51
EEPROMByteList          vlExpCompensation(EEP_EXPOCOR_LIST_OFFSET, EEP_EXPOCOR_LIST_SIZE);
52
 
53
class CamStateHandlers : public EOSStateHandlers
54
{
55
      bool stateConnected;
56
 
57
public:
58
      CamStateHandlers() : stateConnected(false) {};
59
 
60
      virtual void OnDeviceDisconnectedState(PTP *ptp);
61
      virtual void OnDeviceInitializedState(PTP *ptp);
62
};
63
 
64
class CamHDRCapture : public HDRCapture
65
{
66
public:
67
    CamHDRCapture(CanonEOS &eos) : HDRCapture(eos) {};
68
protected:
69
    virtual void OnFrameCaptured(uint16_t left);
70
    virtual void OnSelfTimerProgress(uint32_t left);
71
    virtual void OnIntrTimerProgress(uint32_t left);
72
};
73
 
74
CamStateHandlers  CamStates;
75
Max_LCD               LCD;
76
SimpleTimer           ControlTimer, PTPPollTimer;
77
 
78
CanonEOS              Eos(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates);
79
CamHDRCapture         hdrCapture(Eos);
80
GPInRegister          ExtControls(Eos.GetMax());
81
QEvent                evtTick, evtAbort;
82
 
83
//--- (0) Message Screen ----------------------------------------------------------------------
84
PgmStringDataItem     diFirst(msgCamera);
85
PgmStringDataItem     diSecond(msgDisconnected);
86
 
87
ScreenItem            siFirst     (5, 0, 16, false, &diFirst);
88
ScreenItem            siSecond    (2, 1, 16, false, &diSecond);
89
 
90
ScreenItem            *messageScreenItems[]  PROGMEM = { &siFirst, &siSecond };
91
Screen                messageScreen(2, (ScreenItem*)messageScreenItems);
92
 
93
//--- (1) Main Menu Screen --------------------------------------------------------------------
94
ScreenItem            siIntervalometer (1,  0, 8, true,  (const char*)&msgIntervalometer);
95
ScreenItem            siSettings       (1,  1, 8, false, (const char*)&msgSettings);
96
 
97
ScreenItem            *mainMenuScreenItems[]  PROGMEM = { &siIntervalometer, &siSettings };
98
Screen                scrMainMenu(2, (ScreenItem*)mainMenuScreenItems);
99
 
100
//--- (2) Timer Menu Screen -------------------------------------------------------------------
101
ScreenItem            siSelf     (1,  0, 4, true,  (const char*)&msgSetSelf);
102
ScreenItem            siFrames   (1,  1, 4, false, (const char*)&msgSetFrames);
103
ScreenItem            siBkt      (6,  0, 3, false, (const char*)&msgSetBkt);
104
ScreenItem            siInterval (6,  1, 3, false, (const char*)&msgSetInterval);
105
ScreenItem            siRun      (10, 0, 4, false, (const char*)&msgSetRun);
106
ScreenItem            siExit     (10, 1, 4, false, (const char*)&msgExit);
107
 
108
ScreenItem            *timerSettingsScreenItems[]  PROGMEM = { &siSelf, &siFrames, &siBkt, &siInterval, &siRun, &siExit };
109
Screen                timerSettingsScreen(6, (ScreenItem*)timerSettingsScreenItems);
110
 
111
//--- (3) Self Timer Screen -------------------------------------------------------------------
112
DIT_TIMER_DIGIT_PAIR  diHourSelf(0),  diHourInt(0),
113
                      diMinSelf(0),   diMinInt(0),
114
                      diSecSelf(0),   diSecInt(0);
115
 
116
ScreenItem            siSelfTimer(0, 0, 16, false,  (const char*)&msgSelfTimer);
117
ScreenItem            siHourSelf(3, 1, 2, false, &diHourSelf);
118
ScreenItem            siMinSelf (6, 1, 2, false, &diMinSelf);
119
ScreenItem            siSecSelf (9, 1, 2, false, &diSecSelf);
120
 
121
ScreenItem            *scitmSelfTimerSet[]  PROGMEM = { &siSelfTimer, &siHourSelf, &siMinSelf, &siSecSelf };
122
Screen                scrSelfTimerSet(4, (ScreenItem*)scitmSelfTimerSet);
123
 
124
//--- (4) Number of Frames Screen -------------------------------------------------------------
125
IntDataItem<uint16_t, 5>         diFramesCount(0);
126
IntDataItem<uint16_t, 5>         diFramesLeft(0);
127
 
128
ScreenItem            siFramesText  (5, 0,  6, false, (const char*)&msgCntFrames);
129
ScreenItem            siFramesCount (6, 1,  4, false, &diFramesCount);
130
 
131
ScreenItem            *scitmFramesSet[]  PROGMEM = { &siFramesText, &siFramesCount };
132
Screen                scrFramesSet(2, (ScreenItem*)scitmFramesSet);
133
 
134
//--- (5) Bracketing Screen -------------------------------------------------------------------
135
KeyValuePairDataItem<uint8_t, 37, 7>      diBktEV(0, ExpCompTitles);
136
KeyValuePairDataItem<uint8_t, 37, 7>      diBktStep(0, ExpCompTitles);
137
uint8_t                                   nBktStep;
138
uint8_t                                   nBktNegativeIndex;
139
uint8_t                                   nBktPositiveIndex;
140
 
141
ScreenItem            siBracketing(0, 0, 15, false,  (const char*)&msgBracketing);
142
ScreenItem            siBktEV     (1, 1,  6, false,  &diBktEV);
143
ScreenItem            siBktStep   (9, 1,  6, false,  &diBktStep);
144
 
145
ScreenItem            *scitmBkt[]  PROGMEM = { &siBracketing, &siBktEV, &siBktStep };
146
Screen                scrBktSet(3, (ScreenItem*)scitmBkt);
147
 
148
//--- (6) Interval Timer Screen ---------------------------------------------------------------
149
ScreenItem            siIntTimer(0, 0, 16, false,  (const char*)&msgIntTimer);
150
ScreenItem            siHourInt(3, 1, 2, false, &diHourInt);
151
ScreenItem            siMinInt (6, 1, 2, false, &diMinInt);
152
ScreenItem            siSecInt (9, 1, 2, false, &diSecInt);
153
 
154
ScreenItem            *scitmIntTimerSet[]  PROGMEM = { &siIntTimer, &siHourInt, &siMinInt, &siSecInt };
155
Screen                scrIntTimerSet(4, (ScreenItem*)scitmIntTimerSet);
156
 
157
//--- (7) Run Screen ---------------------------------------------------------------------------
158
TimeSpanDataItem         diLeftTimer(0);
159
TimeSpanDataItem         diIntTimer(0);
160
 
161
ScreenItem            siRunLeftTime( 0, 0, 8, false,  &diLeftTimer);
162
ScreenItem            siRunIntTime( 0, 1, 8, false,  &diIntTimer);
163
ScreenItem            siRunFramesLeft ( 10, 0, 4, false,  &diFramesLeft);
164
ScreenItem            siAbort(10, 1, 5, false,  (const char*)&msgAbort);
165
 
166
ScreenItem            *scitmRun[]  PROGMEM = { &siRunLeftTime, &siRunIntTime, &siRunFramesLeft, &siAbort };
167
Screen                scrRun(4, (ScreenItem*)scitmRun);
168
 
169
//--- (8) Camera Settings Screen ---------------------------------------------------------------
170
DIT_MODE              diMode(0, ModeTitles);
171
DIT_APERTURE          diAperture(0, ApertureTitles);
172
DIT_WB                diWb(0, WbTitles);
173
DIT_SHUTTER_SPEED     diShutterSpeed(0, ShutterSpeedTitles);
174
DIT_PSTYLE            diPStyle(0, PStyleTitles);
175
DIT_ISO               diIso(0, IsoTitles);
176
DIT_EXPCOMP           diExpComp(0, ExpCompTitles);
177
 
178
ScreenItem            siMode        ( 0, 0, 3, false,  &diMode);
179
ScreenItem            siAperture    ( 0, 1, 3, false,  &diAperture);
180
ScreenItem            siWb          ( 4, 0, 3, false,  &diWb);
181
ScreenItem            siShutterSpeed( 4, 1, 4, false,  &diShutterSpeed);
182
ScreenItem            siPStyle      ( 8, 0, 3, false,  &diPStyle);
183
ScreenItem            siIso         (12, 0, 4, false,  &diIso);
184
ScreenItem            siExpComp     ( 9, 1, 6, false,  &diExpComp);
185
 
186
ScreenItem            *scitmSettings[]  PROGMEM = { &siMode, &siAperture, &siWb, &siShutterSpeed, &siPStyle, &siIso, &siExpComp };
187
Screen                scrSettings(7, (ScreenItem*)scitmSettings);
188
 
189
IntSpin<DIT_TIMER_DIGIT_PAIR, uint8_t>    hourSpinSelf(0, 99, 1, &diHourSelf, NULL);
190
IntSpin<DIT_TIMER_DIGIT_PAIR, uint8_t>    minSpinSelf(0, 99, 1, &diMinSelf, NULL);
191
IntSpin<DIT_TIMER_DIGIT_PAIR, uint8_t>    secSpinSelf(0, 99, 1, &diSecSelf, NULL);
192
 
193
IntSpin<DIT_TIMER_DIGIT_PAIR, uint8_t>    hourSpinInt(0, 99, 1, &diHourInt, NULL);
194
IntSpin<DIT_TIMER_DIGIT_PAIR, uint8_t>    minSpinInt(0, 99, 1, &diMinInt, NULL);
195
IntSpin<DIT_TIMER_DIGIT_PAIR, uint8_t>    secSpinInt(0, 99, 1, &diSecInt, NULL);
196
 
197
 
198
void SpinSetAperture(DataItemBase *data_item)
199
{
200
    Eos.SetProperty(EOS_DPC_Aperture, ((DIT_APERTURE*)data_item)->Get());
201
};
202
 
203
void SpinSetShutterSpeed(DataItemBase *data_item)
204
{
205
    Eos.SetProperty(EOS_DPC_ShutterSpeed, ((DIT_SHUTTER_SPEED*)data_item)->Get());
206
};
207
 
208
void SpinSetWb(DataItemBase *data_item)
209
{
210
    Eos.SetProperty(EOS_DPC_WhiteBalance, ((DIT_WB*)data_item)->Get());
211
};
212
 
213
void SpinSetPStyle(DataItemBase *data_item)
214
{
215
    Eos.SetProperty(EOS_DPC_PictureStyle, ((DIT_PSTYLE*)data_item)->Get());
216
};
217
 
218
void SpinSetIso(DataItemBase *data_item)
219
{
220
    Eos.SetProperty(EOS_DPC_Iso, ((DIT_ISO*)data_item)->Get());
221
};
222
 
223
void SpinSetExpComp(DataItemBase *data_item)
224
{
225
    Eos.SetProperty(EOS_DPC_ExposureCompensation, ((DIT_EXPCOMP*)data_item)->Get());
226
};
227
 
228
void SpinUpdateBktStepValues(DataItemBase *data_item);
229
void SpinUpdateBktStep(DataItemBase *data_item);
230
 
231
EEPROMListIntSpin<DIT_APERTURE, VT_APERTURE>         spinAperture(&vlAperture, &diAperture, &SpinSetAperture);
232
EEPROMListIntSpin<DIT_SHUTTER_SPEED, VT_SHSPEED>     spinShutterSpeed(&vlShutterSpeed, &diShutterSpeed, &SpinSetShutterSpeed);
233
EEPROMListIntSpin<DIT_WB, VT_WB>                     spinWb(&vlWhiteBalance, &diWb, &SpinSetWb);
234
EEPROMListIntSpin<DIT_PSTYLE, VT_PSTYLE>             spinPStyle(&vlPictureStyle, &diPStyle, &SpinSetPStyle);
235
EEPROMListIntSpin<DIT_ISO, VT_ISO>                   spinIso(&vlIso, &diIso, &SpinSetIso);
236
 
237
EEPROMListIntSpin<EXP_COMP_DATA_ITEM, VT_EXPCOMP>    spinExpComp(&vlExpCompensation, &diExpComp, &SpinSetExpComp);
238
EEPROMListIntSpin<EXP_COMP_DATA_ITEM, VT_EXPCOMP>    spinBktEV  (&vlExpCompensation, &diBktEV, &SpinUpdateBktStepValues);
239
 
240
BKT_STEP_VALUE_LIST  vlExpCompStep;
241
 
242
SRAMListIntSpin<EXP_COMP_DATA_ITEM, VT_EXPCOMP, BKT_STEP_VALUE_LIST>      spinBktStep(&vlExpCompStep, &diBktStep, &SpinUpdateBktStep);
243
 
244
 
245
void SpinUpdateBktStepValues(DataItemBase *data_item)
246
{
247
    uint8_t cur_value = ((EXP_COMP_DATA_ITEM*)data_item)->Get();
248
 
249
    vlExpCompStep.SetSize(0);
250
 
251
    // Check value for zerro. Exit on zerro.
252
    if (cur_value == 0)
253
        return;
254
 
255
    // Calculate negative and positive values of expo compensation
256
    uint8_t negative_value = (cur_value & 0x80) ? cur_value : ~(cur_value - 1);
257
    uint8_t positive_value = (cur_value & 0x80) ? ~(cur_value - 1) : cur_value;
258
 
259
    // Get indices of negative and positive expo compensation values
260
    uint16_t negative_index = vlExpCompensation.GetValueIndex(negative_value);
261
    uint16_t positive_index = vlExpCompensation.GetValueIndex(positive_value);
262
 
263
    nBktNegativeIndex = negative_index;
264
    nBktPositiveIndex = positive_index;
265
 
266
    // Calculate interval length
267
    uint16_t len = positive_index - negative_index;
268
 
269
    // Calculate zerro value index
270
    uint16_t zerro_index = vlExpCompensation.GetValueIndex(0);
271
 
272
    // Calculate positive index offset
273
    uint16_t zerro_based_offset = positive_index - zerro_index;
274
 
275
   // Calculate all possible interval indices
276
    for (uint16_t i = zerro_based_offset, j = positive_index; i>0; i--, j--)
277
    {
278
        // Insert values into the list
279
        if (len % i == 0)
280
            vlExpCompStep.Append(vlExpCompensation.Get(j));
281
    }
282
    diBktStep.Set(cur_value);
283
    diBktStep.SetUpdated(true);
284
};
285
 
286
void SpinUpdateBktStep(DataItemBase *data_item)
287
{
288
    uint8_t cur_value = ((EXP_COMP_DATA_ITEM*)data_item)->Get();
289
 
290
    nBktStep = vlExpCompensation.GetValueIndex(cur_value) - vlExpCompensation.GetValueIndex(0);
291
};
292
 
293
void MenuExit();
294
void MenuSetAperture();
295
void MenuSetShutterSpeed();
296
void MenuSetWb();
297
void MenuSetPStyle();
298
void MenuSetIso();
299
void MenuSetExpComp();
300
 
301
extern Menu mainMenu;
302
 
303
//--- Camera Settings Menu -----------------------------------------------------------------
304
MenuItem              settingsMenuItems[] = { {&siMode, &MenuExit}, {&siAperture, &MenuSetAperture}, {&siWb, &MenuSetWb}, {&siShutterSpeed, &MenuSetShutterSpeed}, {&siPStyle, &MenuSetPStyle}, {&siIso, &MenuSetIso}, {&siExpComp, &MenuSetExpComp} };
305
Menu                  settingsMenu(8, 7, settingsMenuItems, 0, &mainMenu);
306
 
307
void MenuSetAperture() { spinAperture.SetReturnState(&settingsMenu); StateMachine::SetState(&spinAperture); };
308
void MenuSetShutterSpeed() { spinShutterSpeed.SetReturnState(&settingsMenu); StateMachine::SetState(&spinShutterSpeed); };
309
void MenuSetWb(){ spinWb.SetReturnState(&settingsMenu); StateMachine::SetState(&spinWb); };
310
void MenuSetPStyle(){ spinPStyle.SetReturnState(&settingsMenu); StateMachine::SetState(&spinPStyle); };
311
void MenuSetIso(){ spinIso.SetReturnState(&settingsMenu); StateMachine::SetState(&spinIso); };
312
void MenuSetExpComp(){ spinExpComp.SetReturnState(&mainMenu); StateMachine::SetState(&spinExpComp); };
313
 
314
//--- Self Timer Menu ----------------------------------------------------------------------
315
void MenuSelfSetH();
316
void MenuSelfSetM();
317
void MenuSelfSetS();
318
 
319
extern Menu timerSettingsMenu;
320
 
321
MenuItem              selfSetMenuItems[] = { {&siHourSelf, &MenuSelfSetH}, {&siMinSelf, &MenuSelfSetM}, {&siSecSelf, &MenuSelfSetS} };
322
Menu                  selfSetMenu(3, 3, selfSetMenuItems, 0, &timerSettingsMenu);
323
 
324
void MenuSelfSetH() { hourSpinSelf.SetReturnState(&selfSetMenu); StateMachine::SetState(&hourSpinSelf); };
325
void MenuSelfSetM() { minSpinSelf.SetReturnState(&selfSetMenu); StateMachine::SetState(&minSpinSelf); };
326
 
327
//--- Timer Settings Menu ------------------------------------------------------------------
328
void MenuSelf();
329
void MenuBkt();
330
void MenuFrames();
331
void MenuInterval();
332
void MenuExit();
333
void MenuRun();
334
 
335
MenuItem              timerSettingsMenuItems[] = { {&siSelf, &MenuSelf}, {&siFrames, &MenuFrames}, {&siBkt, &MenuBkt}, {&siInterval, &MenuInterval}, {&siRun, &MenuRun}, {&siExit, &MenuExit} };
336
Menu                  timerSettingsMenu(2, 6, timerSettingsMenuItems, 0, &mainMenu);
337
 
338
void MenuSelfSetS() { secSpinSelf.SetReturnState(&timerSettingsMenu); StateMachine::SetState(&secSpinSelf); };
339
 
340
void MenuSelf()     { StateMachine::SetState(&selfSetMenu); };
341
 
342
void MenuBktSetStep();
343
void MenuBktStepExit();
344
 
345
MenuItem              bktSetMenuItems[] = { {&siBktEV, &MenuBktSetStep}, {&siBktStep, &MenuBktStepExit} };
346
Menu                  bktSetMenu(5, 2, bktSetMenuItems, 0, &timerSettingsMenu);
347
 
348
void MenuBktSetStep()
349
{
350
    spinBktEV.SetReturnState(&bktSetMenu);
351
 
352
    if (vlExpCompensation.GetSize())
353
        StateMachine::SetState(&spinBktEV);
354
};
355
 
356
void MenuBktStepExit()
357
{
358
    spinBktStep.SetReturnState(&timerSettingsMenu);
359
 
360
    if (vlExpCompensation.GetSize())
361
        StateMachine::SetState(&spinBktStep);
362
};
363
 
364
void MenuBkt()
365
{
366
    if (vlExpCompensation.GetSize())
367
        StateMachine::SetState(&bktSetMenu);
368
};
369
 
370
 
371
IntSpin<IntDataItem<uint16_t, 5>, int16_t>  framesSpin(0, 9999, 1, &diFramesCount, NULL);
372
 
373
void MenuFrames()   { framesSpin.SetReturnState(&timerSettingsMenu); Screen::Set(4); StateMachine::SetState(&framesSpin); };
374
 
375
void MenuIntSetH();
376
void MenuIntSetM();
377
void MenuIntSetS();
378
 
379
MenuItem              intSetMenuItems[] = { {&siHourInt, &MenuIntSetH}, {&siMinInt, &MenuIntSetM}, {&siSecInt, &MenuIntSetS} };
380
Menu                  intSetMenu(6, 3, intSetMenuItems, 0, &timerSettingsMenu);
381
 
382
void MenuIntSetH() { hourSpinInt.SetReturnState(&intSetMenu); StateMachine::SetState(&hourSpinInt); };
383
void MenuIntSetM() { minSpinInt.SetReturnState(&intSetMenu); StateMachine::SetState(&minSpinInt); };
384
void MenuIntSetS() { secSpinInt.SetReturnState(&timerSettingsMenu); StateMachine::SetState(&secSpinInt); };
385
 
386
void MenuInterval() { StateMachine::SetState(&intSetMenu); };
387
 
388
void MenuRunAbort()
389
{
390
    hdrCapture.PostEvent(&evtAbort);
391
    diFramesLeft.Set(0);
392
    StateMachine::SetState(&timerSettingsMenu);
393
};
394
 
395
MenuItem              runMenuItems[] = { {&siAbort, &MenuRunAbort} };
396
Menu                  runMenu(7, 1, runMenuItems, 0);
397
 
398
void MenuRun()
399
{
400
    if (!diFramesCount.Get())
401
        return;
402
 
403
    uint32_t  intr_timeout = ((uint32_t)diHourInt.Get() * 3600 + (uint32_t)diMinInt.Get() * 60 + (uint32_t)diSecInt.Get());
404
    uint32_t  self_timeout = ((uint32_t)diHourSelf.Get() * 3600 + (uint32_t)diMinSelf.Get() * 60 + (uint32_t)diSecSelf.Get());
405
 
406
    diFramesLeft.Set(diFramesCount.Get());
407
    diLeftTimer.Set(self_timeout);
408
    diIntTimer.Set(intr_timeout);
409
 
410
    SetEvt  setEvt;
411
 
412
    setEvt.sig     = SET_FRAMES_SIG;
413
    setEvt.value   = diFramesCount.Get();
414
 
415
    hdrCapture.dispatch(&setEvt);
416
 
417
    setEvt.sig     = SET_FRAME_TIMEOUT_SIG;
418
    setEvt.value   = intr_timeout;
419
 
420
    hdrCapture.dispatch(&setEvt);
421
 
422
    setEvt.sig     = SET_SELF_TIMEOUT_SIG;
423
    setEvt.value   = self_timeout;
424
 
425
    hdrCapture.dispatch(&setEvt);
426
 
427
    SetBktEvt          setBktEvt;
428
    setBktEvt.sig       = SET_BRACKETING_SIG;
429
    setBktEvt.step      = nBktStep;
430
    setBktEvt.negative  = nBktNegativeIndex;
431
    setBktEvt.positive  = nBktPositiveIndex;
432
 
433
    hdrCapture.dispatch(&setBktEvt);
434
 
435
    StateMachine::SetState(&runMenu);
436
 
437
    setEvt.sig     = RUN_SIG;
438
    hdrCapture.dispatch(&setEvt);
439
};
440
 
441
//--- Main Menu ----------------------------------------------------------------------------
442
void MenuIntervalometer() { StateMachine::SetState(&timerSettingsMenu); };
443
 
444
void MenuSettings()
445
{
446
    StateMachine::SetState(&settingsMenu);
447
};
448
 
449
MenuItem              mainMenuItems[] = { {&siIntervalometer, &MenuIntervalometer}, {&siSettings, &MenuSettings} };
450
Menu                  mainMenu(1, 2, mainMenuItems, 0);
451
 
452
void MenuExit()     { StateMachine::SetState(&mainMenu); };
453
 
454
class DummyMenu : public StateMachine
455
{
456
public:
457
    virtual bool OnInitialState()
458
    {
459
        Screen::Set(0);
460
        return true;
461
    };
462
} DisconnectedState;
463
 
464
void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)
465
{
466
    if (stateConnected)
467
    {
468
        stateConnected = false;
469
        PTPPollTimer.Disable();
470
        StateMachine::SetState(&DisconnectedState);
471
    }
472
}
473
 
474
void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)
475
{
476
    if (!stateConnected)
477
    {
478
        stateConnected = true;
479
        PTPPollTimer.Enable();
480
        StateMachine::SetState(&mainMenu);
481
    }
482
    hdrCapture.Run();
483
}
484
 
485
void CamHDRCapture::OnFrameCaptured(uint16_t left)
486
{
487
    diFramesLeft.Set(left);
488
 
489
    if (!left)
490
        StateMachine::SetState(&timerSettingsMenu);
491
}
492
 
493
void CamHDRCapture::OnSelfTimerProgress(uint32_t left)
494
{
495
    diLeftTimer.Set(left);
496
}
497
 
498
void CamHDRCapture::OnIntrTimerProgress(uint32_t left)
499
{
500
    diIntTimer.Set(left);
501
}
502
 
503
void OnControlTimer()
504
{
505
    ExtControls.CheckControls();
506
    hdrCapture.PostEvent(&evtTick);
507
    Screen::Run(&LCD);
508
}
509
 
510
void OnPTPPollTimer()
511
{
512
    EOSEventParser    prs;
513
    Eos.EventCheck(&prs);
514
    diLeftTimer.SetUpdated(true);
515
    diIntTimer.SetUpdated(true);
516
}
517
 
518
void setup()
519
{
520
    StateMachine::SetState(&DisconnectedState);
521
 
522
#ifdef PTPDEBUG
523
    Serial.begin(115200);
524
#endif
525
 
526
    Eos.Setup();
527
    delay( 200 );
528
 
529
    // set up the LCD's number of rows and columns:
530
    LCD.begin(16, 2);
531
    LCD.clear();
532
    LCD.home();
533
    LCD.setCursor(0,0);
534
 
535
    PTPPollTimer.Set(OnPTPPollTimer, 300);
536
 
537
    // 1ms is the perfect interval for encoder polling
538
    ControlTimer.Set(OnControlTimer, 1);
539
    ControlTimer.Enable();
540
 
541
    evtTick.sig = TICK_MILLIS_SIG;
542
    evtAbort.sig = ABORT_SIG;
543
    hdrCapture.init();
544
 
545
#ifdef PTPDEBUG
546
    Serial.println("Start");
547
#endif
548
}
549
 
550
void loop()
551
{
552
    Eos.Task();
553
    PTPPollTimer.Run();
554
    ControlTimer.Run();
555
}
556