Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
#include "eosconsole.h"
2
#include <eosvaluetitles.h>
3
#include <valuelist.h>
4
 
5
extern CanonEOS                Eos;
6
extern EEPROMByteList          vlAperture;
7
extern EEPROMByteList          vlShutterSpeed;
8
extern EEPROMByteList          vlWhiteBalance;
9
extern EEPROMByteList          vlPictureStyle;
10
extern EEPROMByteList          vlIso;
11
extern EEPROMByteList          vlExpCompensation;
12
 
13
extern uint8_t                 dpMode;
14
extern uint8_t                 dpAperture;
15
extern uint8_t                 dpShutterSpeed;
16
extern uint8_t                 dpWb;
17
extern uint8_t                 dpPStyle;
18
extern uint8_t                 dpIso;
19
extern uint8_t                 dpExpComp;
20
 
21
/* fixes avr-gcc incompatibility with virtual destructors */
22
void operator delete( void *p ) {}
23
 
24
const char* menuMain[] = {"Capture", "View Settings", "Change Settings"};
25
const char* menuChangeSettings[] = {"Aperture", "Shutter Speed", "WB", "Pict Style", "ISO", "Exp Comp"};
26
const char* menuUpDown[] = {"<<", ">>"};
27
 
28
void EOSConsole::ShowParams()
29
{
30
    Notify(PSTR("\r\nMode:"));
31
    Notify((char*)FindTitle<VT_MODE, VT_MODE_TEXT_LEN>(VT_MODE_COUNT, ModeTitles, dpMode));
32
    Notify(PSTR("\r\nF:"));
33
    Notify((char*)FindTitle<VT_APERTURE, VT_APT_TEXT_LEN>(VT_APT_COUNT, ApertureTitles, dpAperture));
34
    Notify(PSTR("\r\nT:"));
35
    Notify((char*)FindTitle<VT_SHSPEED, VT_SHSPEED_TEXT_LEN>(VT_SHSPEED_COUNT, ShutterSpeedTitles, dpShutterSpeed));
36
    Notify(PSTR("\r\nWB:"));
37
    Notify((char*)FindTitle<VT_WB, VT_WB_TEXT_LEN>(VT_WB_COUNT, WbTitles, dpWb));
38
    Notify(PSTR("\r\nPict Style:"));
39
    Notify((char*)FindTitle<VT_PSTYLE, VT_PSTYLE_TEXT_LEN>(VT_PSTYLE_COUNT, PStyleTitles, dpPStyle));
40
    Notify(PSTR("\r\nISO:"));
41
    Notify((char*)FindTitle<VT_ISO, VT_ISO_TEXT_LEN>(VT_ISO_COUNT, IsoTitles, dpIso));
42
    Notify(PSTR("\r\nExp Comp:"));
43
    Notify((char*)FindTitle<VT_EXPCOMP, VT_EXPCOMP_TEXT_LEN>(VT_EXPCOMP_COUNT, ExpCompTitles, dpExpComp));
44
    Notify(PSTR("\r\n"));
45
}
46
 
47
QState EOSConsole::Initial(EOSConsole *me, QEvent const *e)
48
{
49
    return Q_TRAN(&EOSConsole::Inactive);
50
}
51
 
52
QState EOSConsole::Inactive(EOSConsole *me, QEvent const *e)
53
{
54
    switch (e->sig)
55
    {
56
        case TICK_SIG:
57
            return Q_TRAN(&EOSConsole::Active);
58
    }
59
    return Q_SUPER(QHsm::top);
60
}
61
 
62
QState EOSConsole::Active(EOSConsole *me, QEvent const *e)
63
{
64
    switch (e->sig)
65
    {
66
        case Q_INIT_SIG:
67
            return Q_TRAN(&EOSConsole::MainMenu);
68
        case TICK_SIG:
69
            return Q_TRAN(&EOSConsole::Inactive);
70
    }
71
    return Q_SUPER(QHsm::top);
72
}
73
 
74
void EOSConsole::PrintMenuTitles(uint8_t count, const char **menu)
75
{
76
    Serial.println("");
77
    for (uint8_t i=0; i<=count; i++)
78
    {
79
        Serial.print(i, DEC);
80
        Serial.print(". ");
81
 
82
        if (i == 0)
83
            Serial.println("<..>");
84
        else
85
            Serial.println(menu[i-1]);
86
    }
87
    Serial.println("");
88
}
89
 
90
QState EOSConsole::MainMenu(EOSConsole *me, QEvent const *e)
91
{
92
    switch (e->sig)
93
    {
94
        case Q_ENTRY_SIG:
95
            PrintMenuTitles(3, menuMain);
96
            return Q_HANDLED();
97
        case MENU_SELECT_SIG:
98
        {
99
            switch (((MenuSelectEvt*)e)->item_index)
100
            {
101
                case 0:
102
                    PrintMenuTitles(3, menuMain);
103
                    return Q_HANDLED();
104
                case 1:
105
                    Eos.Capture();
106
                    return Q_HANDLED();
107
                case 2:
108
                    ShowParams();
109
                    PrintMenuTitles(3, menuMain);
110
                    return Q_HANDLED();
111
                case 3:
112
                    return Q_TRAN(&EOSConsole::ChangeSettingsMenu);
113
            }
114
        }
115
    }
116
    return Q_SUPER(&EOSConsole::Active);
117
}
118
 
119
QState EOSConsole::ChangeSettingsMenu(EOSConsole *me, QEvent const *e)
120
{
121
    switch (e->sig)
122
    {
123
        case Q_ENTRY_SIG:
124
            PrintMenuTitles(6, menuChangeSettings);
125
            return Q_HANDLED();
126
        case MENU_SELECT_SIG:
127
        {
128
            switch (((MenuSelectEvt*)e)->item_index)
129
            {
130
                case 0:
131
                    return Q_TRAN(&EOSConsole::MainMenu);
132
 
133
                case 1:  // Aperture
134
                      return Q_TRAN(&EOSConsole::ChangeApertureMenu);
135
                case 2:  // Shutter Speed
136
                      return Q_TRAN(&EOSConsole::ChangeShutterSpeedMenu);
137
                case 3:  // White Balance
138
                      return Q_TRAN(&EOSConsole::ChangeWBMenu);
139
                case 4:  // Picture Style
140
                      return Q_TRAN(&EOSConsole::ChangePStyleMenu);
141
                case 5:  // ISO
142
                      return Q_TRAN(&EOSConsole::ChangeIsoMenu);
143
                case 6:  // Exposure Compensation
144
                      return Q_TRAN(&EOSConsole::ChangeExpCompMenu);
145
            } // switch
146
        }
147
    }
148
    return Q_SUPER(&EOSConsole::Active);
149
}
150
 
151
QState EOSConsole::ChangeApertureMenu(EOSConsole *me, QEvent const *e)
152
{
153
    switch (e->sig)
154
    {
155
        case Q_ENTRY_SIG:
156
            PrintMenuTitles(2, menuUpDown);
157
            return Q_HANDLED();
158
        case MENU_SELECT_SIG:
159
        {
160
            uint8_t new_value;
161
 
162
            switch (((MenuSelectEvt*)e)->item_index)
163
            {
164
            case 0:
165
                return Q_TRAN(&EOSConsole::ChangeSettingsMenu);
166
 
167
            case 2:
168
                if (vlAperture.GetSize() > 0)
169
                {
170
                    new_value = vlAperture.GetNext(dpAperture, 1);
171
                    Eos.SetProperty(EOS_DPC_Aperture, new_value);
172
                }
173
                return Q_HANDLED();
174
            case 1:
175
                if (vlAperture.GetSize() > 0)
176
                {
177
                    new_value = vlAperture.GetPrev(dpAperture, 1);
178
                    Eos.SetProperty(EOS_DPC_Aperture, new_value);
179
                }
180
                return Q_HANDLED();
181
            } // switch (((MenuSelectEvt*)e)->item_index)
182
        } // case MENU_SELECT_SIG:
183
    }
184
    return Q_SUPER(&EOSConsole::Active);
185
}
186
 
187
QState EOSConsole::ChangeShutterSpeedMenu(EOSConsole *me, QEvent const *e)
188
{
189
    switch (e->sig)
190
    {
191
        case Q_ENTRY_SIG:
192
            PrintMenuTitles(2, menuUpDown);
193
            return Q_HANDLED();
194
        case MENU_SELECT_SIG:
195
        {
196
            uint8_t new_value;
197
 
198
            switch (((MenuSelectEvt*)e)->item_index)
199
            {
200
            case 0:
201
                return Q_TRAN(&EOSConsole::ChangeSettingsMenu);
202
 
203
            case 2:
204
                if (vlShutterSpeed.GetSize() > 0)
205
                {
206
                    new_value = vlShutterSpeed.GetNext(dpShutterSpeed, 1);
207
                    Eos.SetProperty(EOS_DPC_ShutterSpeed, new_value);
208
                }
209
                return Q_HANDLED();
210
            case 1:
211
                if (vlShutterSpeed.GetSize() > 0)
212
                {
213
                    new_value = vlShutterSpeed.GetPrev(dpShutterSpeed, 1);
214
                    Eos.SetProperty(EOS_DPC_ShutterSpeed, new_value);
215
                }
216
                return Q_HANDLED();
217
            } // switch (((MenuSelectEvt*)e)->item_index)
218
        } // case MENU_SELECT_SIG:
219
    }
220
    return Q_SUPER(&EOSConsole::Active);
221
}
222
 
223
QState EOSConsole::ChangeWBMenu(EOSConsole *me, QEvent const *e)
224
{
225
    switch (e->sig)
226
    {
227
        case Q_ENTRY_SIG:
228
            PrintMenuTitles(2, menuUpDown);
229
            return Q_HANDLED();
230
        case MENU_SELECT_SIG:
231
        {
232
            uint8_t new_value;
233
 
234
            switch (((MenuSelectEvt*)e)->item_index)
235
            {
236
            case 0:
237
                return Q_TRAN(&EOSConsole::ChangeSettingsMenu);
238
 
239
            case 2:
240
                if (vlWhiteBalance.GetSize() > 0)
241
                {
242
                    new_value = vlWhiteBalance.GetNext(dpWb, 1);
243
                    Eos.SetProperty(EOS_DPC_WhiteBalance, new_value);
244
                }
245
                return Q_HANDLED();
246
            case 1:
247
                if (vlAperture.GetSize() > 0)
248
                {
249
                    new_value = vlWhiteBalance.GetPrev(dpWb, 1);
250
                    Eos.SetProperty(EOS_DPC_WhiteBalance, new_value);
251
                }
252
                return Q_HANDLED();
253
            } // switch (((MenuSelectEvt*)e)->item_index)
254
        } // case MENU_SELECT_SIG:
255
    }
256
    return Q_SUPER(&EOSConsole::Active);
257
}
258
 
259
QState EOSConsole::ChangeIsoMenu(EOSConsole *me, QEvent const *e)
260
{
261
    switch (e->sig)
262
    {
263
        case Q_ENTRY_SIG:
264
            PrintMenuTitles(2, menuUpDown);
265
            return Q_HANDLED();
266
        case MENU_SELECT_SIG:
267
        {
268
            uint8_t new_value;
269
 
270
            switch (((MenuSelectEvt*)e)->item_index)
271
            {
272
            case 0:
273
                return Q_TRAN(&EOSConsole::ChangeSettingsMenu);
274
 
275
            case 2:
276
                if (vlIso.GetSize() > 0)
277
                {
278
                    new_value = vlIso.GetNext(dpIso, 1);
279
                    Eos.SetProperty(EOS_DPC_Iso, new_value);
280
                }
281
                return Q_HANDLED();
282
            case 1:
283
                if (vlAperture.GetSize() > 0)
284
                {
285
                    new_value = vlIso.GetPrev(dpIso, 1);
286
                    Eos.SetProperty(EOS_DPC_Iso, new_value);
287
                }
288
                return Q_HANDLED();
289
            } // switch (((MenuSelectEvt*)e)->item_index)
290
        } // case MENU_SELECT_SIG:
291
    }
292
    return Q_SUPER(&EOSConsole::Active);
293
}
294
 
295
QState EOSConsole::ChangePStyleMenu(EOSConsole *me, QEvent const *e)
296
{
297
    switch (e->sig)
298
    {
299
        case Q_ENTRY_SIG:
300
            PrintMenuTitles(2, menuUpDown);
301
            return Q_HANDLED();
302
        case MENU_SELECT_SIG:
303
        {
304
            uint8_t new_value;
305
 
306
            switch (((MenuSelectEvt*)e)->item_index)
307
            {
308
            case 0:
309
                return Q_TRAN(&EOSConsole::ChangeSettingsMenu);
310
 
311
            case 2:
312
                if (vlPictureStyle.GetSize() > 0)
313
                {
314
                    new_value = vlPictureStyle.GetNext(dpPStyle, 1);
315
                    Eos.SetProperty(EOS_DPC_PictureStyle, new_value);
316
                }
317
                return Q_HANDLED();
318
            case 1:
319
                if (vlPictureStyle.GetSize() > 0)
320
                {
321
                    new_value = vlPictureStyle.GetPrev(dpPStyle, 1);
322
                    Eos.SetProperty(EOS_DPC_PictureStyle, new_value);
323
                }
324
                return Q_HANDLED();
325
            } // switch (((MenuSelectEvt*)e)->item_index)
326
        } // case MENU_SELECT_SIG:
327
    }
328
    return Q_SUPER(&EOSConsole::Active);
329
}
330
 
331
QState EOSConsole::ChangeExpCompMenu(EOSConsole *me, QEvent const *e)
332
{
333
    switch (e->sig)
334
    {
335
        case Q_ENTRY_SIG:
336
            PrintMenuTitles(2, menuUpDown);
337
            return Q_HANDLED();
338
        case MENU_SELECT_SIG:
339
        {
340
            uint8_t new_value;
341
 
342
            switch (((MenuSelectEvt*)e)->item_index)
343
            {
344
            case 0:
345
                return Q_TRAN(&EOSConsole::ChangeSettingsMenu);
346
 
347
            case 2:
348
                if (vlExpCompensation.GetSize() > 0)
349
                {
350
                    new_value = vlExpCompensation.GetNext(dpExpComp, 1);
351
                    Eos.SetProperty(EOS_DPC_ExposureCompensation, new_value);
352
                }
353
                return Q_HANDLED();
354
            case 1:
355
                if (vlExpCompensation.GetSize() > 0)
356
                {
357
                    new_value = vlExpCompensation.GetPrev(dpExpComp, 1);
358
                    Eos.SetProperty(EOS_DPC_ExposureCompensation, new_value);
359
                }
360
                return Q_HANDLED();
361
            } // switch (((MenuSelectEvt*)e)->item_index)
362
        } // case MENU_SELECT_SIG:
363
    }
364
    return Q_SUPER(&EOSConsole::Active);
365
}
366
 
367
//static EOSConsole          menu;
368
static TickEvt           tick_evt;
369
//static MenuSelectEvt     menu_sel_evt;
370
 
371
//............................................................................
372
 
373
//void setup()
374
//{
375
//    Serial.begin( 115200 );
376
//
377
//    menu.init();                                // take the initial transition
378
//    
379
//    tick_evt.sig = TICK_SIG;
380
//    tick_evt.fine_time = 0;
381
//}
382
 
383
int8_t EOSConsole::MenuSelect()
384
{
385
    if( !Serial.available())
386
        return -1;
387
 
388
    uint8_t  char_count = 0;
389
    uint8_t  index = 0;
390
 
391
    while (Serial.available() > 0 && char_count < 2)
392
    {
393
        uint8_t key = Serial.read();
394
        key -= '0';
395
 
396
        if (index)
397
        {
398
            uint8_t tmp = index;
399
            // index *= 10;
400
            index <<= 3;
401
            index += tmp;
402
            index += tmp;
403
        }
404
        index += key;
405
        char_count ++;
406
    }
407
    return (char_count) ? (int8_t)index : (int8_t)-1;
408
}
409
 
410
//void loop()
411
//{
412
//    delay(100);                                            // 100 ms delay
413
//
414
//    if (++tick_evt.fine_time == 10) 
415
//        tick_evt.fine_time = 0;
416
//
417
//    menu.dispatch(&tick_evt);                       // dispatch TICK event
418
//
419
//    int8_t  index = MenuSelect();
420
//    
421
//    if (index >= 0)
422
//    {
423
//        menu_sel_evt.sig         = MENU_SELECT_SIG;
424
//        menu_sel_evt.item_index  = index;
425
//        menu.dispatch(&menu_sel_evt);      // dispatch the event
426
//    }
427
//}
428