Subversion Repositories Projects

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1702 - 1
/* Canon Powershot Capture Demo */
2
#include <inttypes.h>
3
#include <avr/pgmspace.h>
4
 
5
//#include <Spi.h>
6
#include <Max3421e.h>
7
#include <Max3421e_constants.h>
8
#include <Max_LCD.h>
9
#include <Usb.h>
10
 
11
#include <ptp.h>
12
#include <ptpdebug.h>
13
#include <canonps.h>
14
#include <simpletimer.h>
15
#include "pseventparser.h"
16
#include "ptpobjinfoparser.h"
17
 
18
#define DEV_ADDR        1
19
 
20
// Canon PowerShot S3 IS
21
#define DATA_IN_EP      1
22
#define DATA_OUT_EP     2
23
#define INTERRUPT_EP    3
24
#define CONFIG_NUM      1
25
 
26
void setup();
27
void loop();
28
 
29
class CamStateHandlers : public PSStateHandlers
30
{
31
      bool stateConnected;
32
 
33
public:
34
      CamStateHandlers() : stateConnected(false) {};
35
 
36
      virtual void OnDeviceDisconnectedState(PTP *ptp);
37
      virtual void OnDeviceInitializedState(PTP *ptp);
38
} CamStates;
39
 
40
CanonPS  Ps(DEV_ADDR, DATA_IN_EP, DATA_OUT_EP, INTERRUPT_EP, CONFIG_NUM, &CamStates);
41
SimpleTimer  eventTimer, captureTimer;
42
 
43
void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)
44
{
45
    if (stateConnected)
46
    {
47
        eventTimer.Disable();
48
        captureTimer.Disable();
49
        stateConnected = false;
50
 
51
        Notify(PSTR("Camera disconnected\r\n"));
52
    }
53
}
54
 
55
void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)
56
{
57
    if (!stateConnected)
58
    {
59
        Notify(PSTR("stateConnected\r\n"));
60
 
61
        stateConnected = true;
62
        eventTimer.Enable();
63
        captureTimer.Enable();
64
    }
65
}
66
 
67
void setup()
68
{
69
  Serial.begin( 115200 );
70
  Serial.println("Start");
71
  Ps.Setup();
72
  eventTimer.Set(&OnEventTimer, 200);
73
  captureTimer.Set(&OnCaptureTimer, 5000);
74
  delay( 200 );
75
}
76
 
77
void loop()
78
{
79
    eventTimer.Run();
80
    captureTimer.Run();
81
    Ps.Task();
82
}
83
 
84
void OnCaptureTimer()
85
{
86
    Ps.SetDevicePropValue(PS_DPC_CaptureTransferMode, (uint16_t)0x0D);
87
 
88
    uint16_t rc = Ps.Capture();
89
 
90
    if (rc != PTP_RC_OK)
91
        Message(PSTR("Error: "), rc);
92
}
93
 
94
void OnEventTimer()
95
{
96
    PSEventParser  prs;
97
    Ps.EventCheck(&prs);
98
 
99
    if (uint32_t handle = prs.GetObjHandle())
100
    {
101
                PTPObjInfoParser     inf;
102
                Ps.GetObjectInfo(handle, &inf);
103
    }
104
}
105
 
106