forked from felis/FSA-EOS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcamera.cpp
More file actions
281 lines (252 loc) · 8.17 KB
/
camera.cpp
File metadata and controls
281 lines (252 loc) · 8.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//////////////////////////////////////////////////////////////////////////////
// Model: fsa_eos.qm
// File: ./camera.cpp
//
// This file has been generated automatically by QP Modeler (QM).
// DO NOT EDIT THIS FILE MANUALLY.
//
// Please visit www.state-machine.com/qm for more information.
//////////////////////////////////////////////////////////////////////////////
/*
#include <avrpins.h>
#include <max3421e.h>
#include <usbhost.h>
#include <usb_ch9.h>
#include <Usb.h>
#include <address.h>
#include <parsetools.h>
#include <ptp.h>
#include <canoneos.h>
#include <qp_port.h>
#include <valuelist.h>
#include <eosvaluetitles.h>
#include <eoseventparser.h>
*/
#include "qp_port.h"
#include "bsp.h"
#include "fsa.h"
Q_DEFINE_THIS_FILE
/*
#define STEP_N1 0x01
#define STEP_N2 0x02
#define STEP_N3 0x03
#define STEP_F1 0x8001
#define STEP_F2 0x8002
#define STEP_F3 0x8003
#define COMMAND_DELAY BSP_TICKS_PER_SEC/10
class CamStateHandlers : public EOSStateHandlers
{
enum CamStates { stInitial, stDisconnected, stConnected };
CamStates stateConnected;
public:
CamStateHandlers() : stateConnected(stInitial)
{
};
virtual void OnDeviceDisconnectedState(PTP *ptp);
virtual void OnDeviceInitializedState(PTP *ptp);
};
CamStateHandlers CamStates;
USB Usb;
USB* const O_usb = &Usb;
CanonEOS Eos(&Usb, &CamStates);
void CamStateHandlers::OnDeviceDisconnectedState(PTP *ptp)
{
if (stateConnected == stConnected || stateConnected == stInitial)
{
stateConnected = stDisconnected;
AO_Camera->postFIFO(Q_NEW(QEvent, CAM_DISC_SIG));
}
}
void CamStateHandlers::OnDeviceInitializedState(PTP *ptp)
{
if (stateConnected == stDisconnected || stateConnected == stInitial) {
stateConnected = stConnected;
AO_Camera->postFIFO(Q_NEW(QEvent, CAM_READY_SIG));
}
}
*/
//Camera Class
// $(AOs::Camera) ............................................................
/// Camera control
class Camera : public QActive {
private:
/// near focus point
uint16_t n_point;
/// far focus point
uint16_t f_point;
uint16_t focus_position;
public:
Camera() : QActive((QStateHandler)&Camera::initial), n_point(0x7fff), f_point(0x7fff), focus_position(0x7fff) {
}
protected:
static QState initial(Camera *me, QEvent const *e);
static QState operation(Camera *me, QEvent const *e);
static QState disconnected(Camera *me, QEvent const *e);
static QState control(Camera *me, QEvent const *e);
static QState run(Camera *me, QEvent const *e);
static QState shoot(Camera *me, QEvent const *e);
};
//Local objects
static Camera l_Camera;
//Global objects
QActive * const AO_Camera = &l_Camera;
//Camera Class definition
// $(AOs::Camera) ............................................................
// $(AOs::Camera::Statechart) ................................................
// @(/2/1/4/0)
QState Camera::initial(Camera *me, QEvent const *e) {
return Q_TRAN(&Camera::operation);
}
// $(AOs::Camera::Statechart::operation) .....................................
QState Camera::operation(Camera *me, QEvent const *e) {
switch (e->sig) {
// @(/2/1/4/1/0)
case CAM_DISC_SIG: {
return Q_TRAN(&Camera::disconnected);
}
// @(/2/1/4/1/1)
case CAM_READY_SIG: {
AO_Lights->postFIFO(Q_NEW(QEvent, LED_IDLE_SIG));
return Q_TRAN(&Camera::control);
}
}
return Q_SUPER(&QHsm::top);
}
// $(AOs::Camera::Statechart::operation::disconnected) .......................
QState Camera::disconnected(Camera *me, QEvent const *e) {
switch (e->sig) {
// @(/2/1/4/1/2)
case Q_ENTRY_SIG: {
Notify(PSTR("Camera offline\r\n"));
AO_Lights->postFIFO(Q_NEW(QEvent, LED_ERROR_SIG));
return Q_HANDLED();
}
}
return Q_SUPER(&Camera::operation);
}
// $(AOs::Camera::Statechart::operation::control) ............................
QState Camera::control(Camera *me, QEvent const *e) {
switch (e->sig) {
// @(/2/1/4/1/3)
case Q_ENTRY_SIG: {
//Notify(PSTR("AO Camera: Control Entry\r\n"));
return Q_HANDLED();
}
// @(/2/1/4/1/3)
case Q_EXIT_SIG: {
//Notify(PSTR("AO Camera: Control Exit\r\n"));
return Q_HANDLED();
}
// @(/2/1/4/1/3/0)
case NEAR_SET_SIG: {
//Serial.println("Near Set");
me->n_point = me->focus_position;
AO_Lights->postFIFO(Q_NEW(QEvent, LED_WORKING_SIG));
return Q_HANDLED();
}
// @(/2/1/4/1/3/1)
case FAR_SET_SIG: {
//Serial.println("Far Set");
me->f_point = me->focus_position;
AO_Lights->postFIFO(Q_NEW(QEvent, LED_WORKING_SIG));
return Q_HANDLED();
}
// @(/2/1/4/1/3/2)
case RUN_SIG: {
//Notify(PSTR("AO_Cam: Run Signal\r\n"));
return Q_TRAN(&Camera::run);
}
// @(/2/1/4/1/3/3)
case FREERUN_SIG: {
//Notify(PSTR("AO_Cam: FreeRun Signal\r\n"));
me->f_point = 0xffff; //set far point as far as possible
me->n_point = me->focus_position;
return Q_TRAN(&Camera::run);
}
// @(/2/1/4/1/3/4)
case NEAR_STEP_SIG: {
AO_Commands->postFIFO(Q_NEW(QEvent, NEAR_STEP_SIG));
return Q_HANDLED();
}
// @(/2/1/4/1/3/5)
case FAR_STEP_SIG: {
AO_Commands->postFIFO(Q_NEW(QEvent, FAR_STEP_SIG));
return Q_HANDLED();
}
// @(/2/1/4/1/3/6)
case FOCUS_MOVED_SIG: {
me->focus_position = ((FocusMovedEvt *)e)->focus_position;
return Q_HANDLED();
}
}
return Q_SUPER(&Camera::operation);
}
// $(AOs::Camera::Statechart::operation::control::run) .......................
QState Camera::run(Camera *me, QEvent const *e) {
switch (e->sig) {
// @(/2/1/4/1/3/7)
case Q_ENTRY_SIG: {
//Notify(PSTR("AO_Camera: Run Entry\r\n"));
if( me->focus_position == me->n_point ) { //lens at near point
me->postFIFO(Q_NEW(QEvent, SHOOT_SIG));
}
else {
if( me->focus_position > me->n_point ) { //step back to N-point
AO_Commands->postFIFO(Q_NEW(QEvent, NEAR_STEP_SIG));
}
else { //step forward to N-point
AO_Commands->postFIFO(Q_NEW(QEvent, FAR_STEP_SIG));
}
}
return Q_HANDLED();
}
// @(/2/1/4/1/3/7)
case Q_EXIT_SIG: {
//Notify(PSTR("AO_Camera: Run Exit\r\n"));
return Q_HANDLED();
}
// @(/2/1/4/1/3/7/0)
case SHOOT_SIG: {
//Notify(PSTR("Time to Shoot\r\n"));
return Q_TRAN(&Camera::shoot);
}
// @(/2/1/4/1/3/7/1)
case FOCUS_MOVED_SIG: {
me->focus_position = ((FocusMovedEvt *)e)->focus_position;
return Q_TRAN(&Camera::run);
}
// @(/2/1/4/1/3/7/2)
case NEAR_STEP_SIG: {
return Q_TRAN(&Camera::control);
}
// @(/2/1/4/1/3/7/3)
case FAR_STEP_SIG: {
return Q_TRAN(&Camera::control);
}
}
return Q_SUPER(&Camera::control);
}
// $(AOs::Camera::Statechart::operation::control::run::shoot) ................
QState Camera::shoot(Camera *me, QEvent const *e) {
switch (e->sig) {
// @(/2/1/4/1/3/7/4)
case Q_ENTRY_SIG: {
//Notify(PSTR("AO_Camera: Shoot Entry\r\n"));
if( me->focus_position <= me->f_point ) {
AO_Commands->postFIFO(Q_NEW(QEvent, CAPTURE_SIG));
}
return Q_HANDLED();
}
// @(/2/1/4/1/3/7/4/0)
case CAP_COMPLETE_SIG: {
AO_Commands->postFIFO(Q_NEW(QEvent, FAR_STEP_SIG));
return Q_HANDLED();
}
// @(/2/1/4/1/3/7/4/1)
case FOCUS_MOVED_SIG: {
me->focus_position = ((FocusMovedEvt *)e)->focus_position;
return Q_TRAN(&Camera::shoot);
}
}
return Q_SUPER(&Camera::run);
}