Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1702 | - | 1 | #include "hdrcapture.h" |
2 | #include "expcomp_macro.h" |
||
3 | |||
4 | /* fixes avr-gcc incompatibility with virtual destructors */ |
||
5 | void operator delete( void *p ) {} |
||
6 | |||
7 | QState HDRCapture::Initial(HDRCapture *me, QEvent const *e) |
||
8 | { |
||
9 | return Q_TRAN(&HDRCapture::Inactive); |
||
10 | } |
||
11 | |||
12 | QState HDRCapture::Inactive(HDRCapture *me, QEvent const *e) |
||
13 | { |
||
14 | switch(e->sig) |
||
15 | { |
||
16 | case Q_ENTRY_SIG: |
||
17 | PTPTRACE("Inactive\r\n"); |
||
18 | return Q_HANDLED(); |
||
19 | case SET_FRAMES_SIG: |
||
20 | me->frmCount = (uint16_t)((SetEvt*)e)->value; |
||
21 | return Q_HANDLED(); |
||
22 | case SET_SELF_TIMEOUT_SIG: |
||
23 | me->selfTimeout = ((SetEvt*)e)->value; |
||
24 | return Q_HANDLED(); |
||
25 | case SET_FRAME_TIMEOUT_SIG: |
||
26 | me->frameTimeout = ((SetEvt*)e)->value; |
||
27 | return Q_HANDLED(); |
||
28 | case SET_BRACKETING_SIG: |
||
29 | me->bktStep = ((SetBktEvt*)e)->step; |
||
30 | me->bktNegative = ((SetBktEvt*)e)->negative; |
||
31 | me->bktPositive = ((SetBktEvt*)e)->positive; |
||
32 | return Q_HANDLED(); |
||
33 | case RUN_SIG: |
||
34 | me->frmCntdn = me->frmCount; |
||
35 | me->bktCntdn = (me->bktStep) ? (me->bktPositive - me->bktNegative) / me->bktStep + 1 : 1; |
||
36 | me->bktPos = me->bktNegative; |
||
37 | return Q_TRAN(&HDRCapture::Active); |
||
38 | } |
||
39 | return Q_SUPER(&QHsm::top); |
||
40 | } |
||
41 | |||
42 | QState HDRCapture::Active(HDRCapture *me, QEvent const *e) |
||
43 | { |
||
44 | switch (e->sig) |
||
45 | { |
||
46 | case Q_ENTRY_SIG: |
||
47 | PTPTRACE("Active\r\n"); |
||
48 | return Q_HANDLED(); |
||
49 | case Q_EXIT_SIG: |
||
50 | PTPTRACE("::Q_EXIT_SIG\r\n"); |
||
51 | return Q_HANDLED(); |
||
52 | case Q_INIT_SIG: |
||
53 | PTPTRACE("Q_INIT_SIG\r\n"); |
||
54 | return Q_TRAN(&HDRCapture::SaveSettings); |
||
55 | case RUN_SIG: |
||
56 | PTPTRACE("::RUN_SIG\r\n"); |
||
57 | return Q_TRAN(&HDRCapture::SaveSettings); |
||
58 | case ABORT_SIG: |
||
59 | PTPTRACE("ABORT_SIG\r\n"); |
||
60 | return Q_TRAN(&HDRCapture::RestoreSettings); |
||
61 | case PTP_RC_SIG: |
||
62 | PTPTRACE("::PTP_RC_SIG\r\n"); |
||
63 | switch (((PTP_RC_Evt*)e)->rc) |
||
64 | { |
||
65 | case PTP_RC_OK: |
||
66 | me->qpEvt.sig = PTP_RC_OK_SIG; |
||
67 | me->theQueue.Push(&me->qpEvt); |
||
68 | return Q_HANDLED(); |
||
69 | case PTP_RC_DeviceBusy: |
||
70 | me->toEvt.timeout = PTP_TIMEOUT; |
||
71 | me->toEvt.attribs = TA_PTP_TIMEOUT; |
||
72 | me->theQueue.Push(&me->toEvt); |
||
73 | return Q_TRAN(&HDRCapture::Timeout); |
||
74 | default: |
||
75 | return Q_TRAN(&HDRCapture::Inactive); |
||
76 | } |
||
77 | case SET_TIMEOUT_SIG: |
||
78 | PTPTRACE("::SET_TIMEOUT_SIG\r\n"); |
||
79 | return Q_HANDLED(); |
||
80 | case TIMEOUT_SIG: |
||
81 | PTPTRACE("::TIMEOUT_SIG\r\n"); |
||
82 | return Q_TRAN(me->activeHistory); |
||
83 | case PTP_RC_OK_SIG: |
||
84 | PTPTRACE("::PTP_RC_OK_SIG\r\n"); |
||
85 | return Q_TRAN(me->activeHistory); |
||
86 | case TICK_MILLIS_SIG: |
||
87 | PTPTRACE("::TICK_MILLIS_SIG\r\n"); |
||
88 | return Q_HANDLED(); |
||
89 | } |
||
90 | return Q_SUPER(&QHsm::top); |
||
91 | } |
||
92 | |||
93 | QState HDRCapture::SaveSettings(HDRCapture *me, QEvent const *e) |
||
94 | { |
||
95 | static bool bSaved = false; |
||
96 | switch (e->sig) |
||
97 | { |
||
98 | case Q_ENTRY_SIG: |
||
99 | PTPTRACE("SaveSettings\r\n"); |
||
100 | me->activeHistory = (QStateHandler)&SaveSettings; |
||
101 | // me->rcEvt.rc = me->Eos.GetProperty(EOS_DPC_ExposureCompensation, me->bktOldVal); |
||
102 | me->rcEvt.rc = PTP_RC_OK; |
||
103 | me->theQueue.Push(&me->rcEvt); |
||
104 | me->bktOldVal = (uint8_t)0; |
||
105 | return Q_HANDLED(); |
||
106 | case PTP_RC_OK_SIG: |
||
107 | PTPTRACE("PTP_RC_OK_SIG\r\n"); |
||
108 | if (me->selfTimeout) |
||
109 | { |
||
110 | me->theQueue.Push((QEvent*)e); |
||
111 | return Q_TRAN(&HDRCapture::SelfTimer); |
||
112 | } |
||
113 | return Q_TRAN(&HDRCapture::PreCapture); |
||
114 | } // switch |
||
115 | return Q_SUPER(&HDRCapture::Active); |
||
116 | } |
||
117 | |||
118 | QState HDRCapture::SelfTimer(HDRCapture *me, QEvent const *e) |
||
119 | { |
||
120 | switch (e->sig) |
||
121 | { |
||
122 | case Q_ENTRY_SIG: |
||
123 | PTPTRACE("SelfTimer\r\n"); |
||
124 | me->activeHistory = (QStateHandler)&SelfTimer; |
||
125 | return Q_HANDLED(); |
||
126 | case TICK_MILLIS_SIG: |
||
127 | PTPTRACE("TICK_MILLIS_SIG\r\n"); |
||
128 | return Q_TRAN(&HDRCapture::PreCapture); |
||
129 | case PTP_RC_OK_SIG: |
||
130 | PTPTRACE("PTP_RC_OK_SIG\r\n"); |
||
131 | me->toEvt.timeout = me->selfTimeout; |
||
132 | me->toEvt.attribs = TA_SELF_TIMER; |
||
133 | me->theQueue.Push(&me->toEvt); |
||
134 | return Q_TRAN(&HDRCapture::Timeout); |
||
135 | case TIMEOUT_SIG: |
||
136 | PTPTRACE("TIMEOUT_SIG\r\n"); |
||
137 | return Q_TRAN(&HDRCapture::PreCapture); |
||
138 | } // switch |
||
139 | return Q_SUPER(&HDRCapture::Active); |
||
140 | } |
||
141 | |||
142 | QState HDRCapture::RestoreSettings(HDRCapture *me, QEvent const *e) |
||
143 | { |
||
144 | switch (e->sig) |
||
145 | { |
||
146 | case Q_ENTRY_SIG: |
||
147 | PTPTRACE("RestoreSettings\r\n"); |
||
148 | me->activeHistory = (QStateHandler)&RestoreSettings; |
||
149 | me->rcEvt.rc = me->Eos.SetProperty(EOS_DPC_ExposureCompensation, me->bktOldVal); |
||
150 | me->theQueue.Push(&me->rcEvt); |
||
151 | return Q_HANDLED(); |
||
152 | case PTP_RC_OK_SIG: |
||
153 | return Q_TRAN(&HDRCapture::Inactive); |
||
154 | } // switch |
||
155 | return Q_SUPER(&HDRCapture::Active); |
||
156 | } |
||
157 | |||
158 | QState HDRCapture::PreCapture(HDRCapture *me, QEvent const *e) |
||
159 | { |
||
160 | switch (e->sig) |
||
161 | { |
||
162 | case Q_ENTRY_SIG: |
||
163 | PTPTRACE("PreCapture\r\n"); |
||
164 | me->activeHistory = (QStateHandler)&PreCapture; |
||
165 | return Q_HANDLED(); |
||
166 | case TICK_MILLIS_SIG: |
||
167 | PTPTRACE("TICK_MILLIS_SIG\r\n"); |
||
168 | |||
169 | if (!me->bktCntdn) |
||
170 | { |
||
171 | me->bktCntdn = (me->bktStep) ? (me->bktPositive - me->bktNegative) / me->bktStep + 1 : 1; |
||
172 | me->bktPos = me->bktNegative; |
||
173 | } |
||
174 | if (me->bktStep) |
||
175 | return Q_TRAN(&HDRCapture::ExpCompSet); |
||
176 | |||
177 | return Q_TRAN(&HDRCapture::Capture); |
||
178 | } // switch |
||
179 | return Q_SUPER(&HDRCapture::Active); |
||
180 | } |
||
181 | |||
182 | QState HDRCapture::Capture(HDRCapture *me, QEvent const *e) |
||
183 | { |
||
184 | switch (e->sig) |
||
185 | { |
||
186 | case Q_ENTRY_SIG: |
||
187 | PTPTRACE("Capture\r\n"); |
||
188 | me->activeHistory = (QStateHandler)&Capture; |
||
189 | me->rcEvt.rc = me->Eos.Capture(); |
||
190 | // me->rcEvt.rc = PTP_RC_OK; |
||
191 | me->theQueue.Push(&me->rcEvt); |
||
192 | return Q_HANDLED(); |
||
193 | case PTP_RC_OK_SIG: |
||
194 | PTPTRACE("PTP_RC_OK_SIG\r\n"); |
||
195 | return Q_TRAN(&HDRCapture::PostCapture); |
||
196 | } // switch |
||
197 | return Q_SUPER(&HDRCapture::Active); |
||
198 | } |
||
199 | |||
200 | QState HDRCapture::PostCapture(HDRCapture *me, QEvent const *e) |
||
201 | { |
||
202 | switch (e->sig) |
||
203 | { |
||
204 | case Q_ENTRY_SIG: |
||
205 | PTPTRACE("PostCapture\r\n"); |
||
206 | me->activeHistory = (QStateHandler)&PostCapture; |
||
207 | return Q_HANDLED(); |
||
208 | case TICK_MILLIS_SIG: |
||
209 | PTPTRACE("TICK_MILLIS_SIG\r\n"); |
||
210 | |||
211 | if (!me->bktCntdn) |
||
212 | return Q_TRAN(&HDRCapture::PreCapture); |
||
213 | |||
214 | me->bktPos += me->bktStep; |
||
215 | |||
216 | if (--me->bktCntdn == 0) |
||
217 | { |
||
218 | --me->frmCntdn; |
||
219 | me->OnFrameCaptured(me->frmCntdn); |
||
220 | } |
||
221 | me->OnBktFrameCaptured(me->bktCntdn); |
||
222 | |||
223 | // if it was the last frame in total |
||
224 | if (!me->frmCntdn) |
||
225 | { |
||
226 | me->qpEvt.sig = ABORT_SIG; |
||
227 | me->theQueue.Push(&me->qpEvt); |
||
228 | return Q_HANDLED(); |
||
229 | } |
||
230 | if (me->bktCntdn) |
||
231 | return Q_TRAN(&HDRCapture::PreCapture); |
||
232 | |||
233 | // if it was the last frame in bracketing |
||
234 | me->toEvt.timeout = me->frameTimeout; |
||
235 | me->toEvt.attribs = TA_INTR_TIMER; |
||
236 | me->theQueue.Push(&me->toEvt); |
||
237 | return Q_TRAN(&HDRCapture::Timeout); |
||
238 | case TIMEOUT_SIG: |
||
239 | PTPTRACE("TIMEOUT_SIG\r\n"); |
||
240 | return Q_TRAN(&HDRCapture::PreCapture); |
||
241 | } |
||
242 | return Q_SUPER(&HDRCapture::Active); |
||
243 | } |
||
244 | |||
245 | QState HDRCapture::ExpCompSet(HDRCapture *me, QEvent const *e) |
||
246 | { |
||
247 | switch (e->sig) |
||
248 | { |
||
249 | case Q_ENTRY_SIG: |
||
250 | PTPTRACE("ExpCompSet\r\n"); |
||
251 | me->activeHistory = (QStateHandler)&ExpCompSet; |
||
252 | me->rcEvt.rc = me->Eos.SetProperty(EOS_DPC_ExposureCompensation, EXP_COMP_VALUE(me->bktPos)); |
||
253 | // me->rcEvt.rc = PTP_RC_OK; |
||
254 | me->theQueue.Push(&me->rcEvt); |
||
255 | return Q_HANDLED(); |
||
256 | case PTP_RC_OK_SIG: |
||
257 | PTPTRACE("PTP_RC_OK_SIG\r\n"); |
||
258 | return Q_TRAN(&HDRCapture::Capture); |
||
259 | } // switch |
||
260 | return Q_SUPER(&HDRCapture::Active); |
||
261 | } |
||
262 | |||
263 | QState HDRCapture::Timeout(HDRCapture *me, QEvent const *e) |
||
264 | { |
||
265 | static uint32_t timeout = 0; |
||
266 | static uint32_t local_time = 0; |
||
267 | static uint32_t seconds_left = 0; |
||
268 | static uint8_t attribs = 0; |
||
269 | static uint16_t sec_cntdn = 1000; |
||
270 | |||
271 | switch (e->sig) |
||
272 | { |
||
273 | case Q_ENTRY_SIG: |
||
274 | PTPTRACE("Timeout\r\n"); |
||
275 | return Q_HANDLED(); |
||
276 | case SET_TIMEOUT_SIG: |
||
277 | attribs = ((SetTimeoutEvt*)e)->attribs; |
||
278 | timeout = (attribs & 0x01) ? ((SetTimeoutEvt*)e)->timeout * 1000 : ((SetTimeoutEvt*)e)->timeout; |
||
279 | |||
280 | if (attribs & 0x01) |
||
281 | { |
||
282 | seconds_left = ((SetTimeoutEvt*)e)->timeout; |
||
283 | sec_cntdn = 1000; |
||
284 | |||
285 | switch (attribs) |
||
286 | { |
||
287 | case TA_SELF_TIMER: |
||
288 | me->OnSelfTimerProgress(seconds_left); |
||
289 | break; |
||
290 | case TA_INTR_TIMER: |
||
291 | me->OnIntrTimerProgress(seconds_left); |
||
292 | break; |
||
293 | // case TA_BULB_TIMER: |
||
294 | // me->OnBulbTimerProgress(seconds_left); |
||
295 | // break; |
||
296 | } // switch |
||
297 | } |
||
298 | local_time = millis(); |
||
299 | return Q_HANDLED(); |
||
300 | case TICK_MILLIS_SIG: |
||
301 | uint32_t dt = local_time; |
||
302 | local_time = millis(); |
||
303 | dt = local_time - dt; |
||
304 | timeout = (timeout < dt) ? 0 : timeout - dt; |
||
305 | |||
306 | if (attribs & 1) |
||
307 | { |
||
308 | bool bTick = (sec_cntdn <= dt); |
||
309 | sec_cntdn = (sec_cntdn > dt) ? sec_cntdn - dt : 1000 - dt; |
||
310 | |||
311 | if (bTick) |
||
312 | { |
||
313 | seconds_left --; |
||
314 | |||
315 | switch (attribs) |
||
316 | { |
||
317 | case TA_SELF_TIMER: |
||
318 | me->OnSelfTimerProgress(seconds_left); |
||
319 | break; |
||
320 | case TA_INTR_TIMER: |
||
321 | me->OnIntrTimerProgress(seconds_left); |
||
322 | break; |
||
323 | } // switch |
||
324 | } // if (--sec_cntdn == 0) |
||
325 | } // if (attribs & 1) |
||
326 | |||
327 | if (!timeout) |
||
328 | { |
||
329 | me->qpEvt.sig = TIMEOUT_SIG; |
||
330 | me->theQueue.Push(&me->qpEvt); |
||
331 | } |
||
332 | return Q_HANDLED(); |
||
333 | } // switch |
||
334 | return Q_SUPER(&HDRCapture::Active); |
||
335 | } |
||
336 |