This source file includes following definitions.
- action_stack_is_finished
- action_stack_create
- action_stack_finish
- action_stack_kill
- action_top
- action_pop
- action_pop_func
- action_push
- action_push_func
- action_process_delay
- action_pop_delay
- action_stack_AS_SLEEP
- action_push_delay
- action_stack_AS_PRESS
- action_push_press
- action_stack_AS_RELEASE
- action_push_release
- action_push_click
- action_stack_AS_WAIT_SHOOTING_DONE
- action_stack_AS_WAIT_FLASH
- action_stack_AS_WAIT_SHOOTING_IN_PROGRESS
- action_push_shoot
- action_stack_AS_SHOOT
- action_stack_process
- action_stack_process_all
1 #include "camera_info.h"
2 #include "modes.h"
3 #include "clock.h"
4 #include "shooting.h"
5 #include "console.h"
6 #include "conf.h"
7 #include "keyboard.h"
8 #include "histogram.h"
9 #include "action_stack.h"
10 #include "script_api.h"
11
12
13
14 #define AS_FUNC_ENTRY 0xa32f1c9e
15
16
17
18
19 #define ACTION_STACK_SIZE 48
20 #define MAX_ACTION_STACKS 5
21
22 typedef struct _action_stack
23 {
24 long stack[ACTION_STACK_SIZE];
25 int stack_ptr;
26 AS_ID comp_id;
27 unsigned long delay_target_ticks;
28 struct _action_stack* next;
29 } action_stack_t;
30
31
32
33
34 static action_stack_t* action_stacks = NULL;
35 static action_stack_t* active_stack = NULL;
36 static action_stack_t* free_stacks = NULL;
37 static int num_stacks = 0;
38 static AS_ID task_comp_id = 1;
39
40
41
42
43
44
45 int action_stack_is_finished(AS_ID comp_id)
46 {
47 action_stack_t *p = action_stacks;
48 while (p)
49 {
50 if (p->comp_id == comp_id)
51 return 0;
52 p = p->next;
53 }
54
55 return 1;
56 }
57
58
59
60
61
62 AS_ID action_stack_create(action_func proc_func)
63 {
64
65 if (num_stacks == MAX_ACTION_STACKS)
66 return -1;
67
68
69 action_stack_t* stack = 0;
70 if (free_stacks)
71 {
72
73 stack = free_stacks;
74 free_stacks = free_stacks->next;
75 }
76 else
77 {
78
79 stack = (action_stack_t*)malloc(sizeof(action_stack_t));
80 }
81 memset(stack,0,sizeof(action_stack_t));
82
83
84 stack->next = action_stacks;
85 action_stacks = stack;
86
87
88 stack->comp_id = task_comp_id;
89 stack->stack[0] = (long)proc_func;
90 stack->stack[1] = AS_FUNC_ENTRY;
91 stack->stack_ptr = 1;
92
93 ++num_stacks;
94
95
96
97
98 ++task_comp_id;
99
100 if (task_comp_id == 0) task_comp_id = 1;
101
102 return stack->comp_id;
103 }
104
105
106 static void action_stack_finish(action_stack_t *p)
107 {
108
109 if (p->comp_id == 0) return;
110
111
112 if (p == action_stacks)
113 {
114 action_stacks = action_stacks->next;
115 }
116 else
117 {
118 action_stack_t* prev = action_stacks;
119 while (prev && (prev->next != p))
120 {
121 prev = prev->next;
122 }
123 if (prev)
124 {
125 prev->next = prev->next->next;
126 }
127 }
128
129 --num_stacks;
130
131
132 p->comp_id = 0;
133 p->stack_ptr = -1;
134
135
136
137 p->next = free_stacks;
138 free_stacks = p;
139 }
140
141
142
143 void action_stack_kill(AS_ID comp_id)
144 {
145 action_stack_t *p = action_stacks;
146 while (p)
147 {
148 if (p->comp_id == comp_id)
149 {
150 action_stack_finish(p);
151 return;
152 }
153 p = p->next;
154 }
155 }
156
157
158
159
160
161
162
163 long action_top(int n)
164 {
165 if (active_stack)
166 return active_stack->stack[active_stack->stack_ptr-n];
167 return 0;
168 }
169
170
171
172 long action_pop()
173 {
174 if (active_stack)
175 return active_stack->stack[active_stack->stack_ptr--];
176 return 0;
177 }
178
179
180
181 long action_pop_func(int nParam)
182 {
183 for (; nParam >= 0; nParam--)
184 action_pop();
185 return action_pop();
186 }
187
188
189
190 void action_push(long p)
191 {
192 if (active_stack)
193 active_stack->stack[++active_stack->stack_ptr] = p;
194 }
195
196
197 void action_push_func(action_func f)
198 {
199 action_push((long)f);
200 action_push(AS_FUNC_ENTRY);
201 }
202
203
204
205
206
207
208
209 static int action_process_delay(long delay)
210 {
211 unsigned t = get_tick_count();
212
213 if (active_stack->delay_target_ticks == 0)
214 {
215
216 if(delay == -1)
217 delay = 86400000;
218
219 active_stack->delay_target_ticks = t+delay;
220 return 0;
221 }
222 if (active_stack->delay_target_ticks <= t)
223 {
224 return 1;
225 }
226 return 0;
227 }
228
229
230
231
232
233
234 void action_pop_delay()
235 {
236 active_stack->delay_target_ticks = 0;
237 action_pop_func(1);
238 }
239
240
241 static int action_stack_AS_SLEEP()
242 {
243 long delay = action_top(2);
244
245 if (action_process_delay(delay))
246 {
247 action_pop_delay();
248 return 1;
249 }
250
251 return 0;
252 }
253
254
255
256 void action_push_delay(long msec)
257 {
258 action_push(msec);
259 action_push_func(action_stack_AS_SLEEP);
260 }
261
262
263 static int action_stack_AS_PRESS()
264 {
265 long skey = action_pop_func(1);
266 kbd_key_press(skey);
267 return 1;
268 }
269
270
271
272 void action_push_press(long key)
273 {
274
275 action_push_delay(camera_info.cam_key_press_delay);
276 action_push(key);
277 action_push_func(action_stack_AS_PRESS);
278 }
279
280
281 static int action_stack_AS_RELEASE()
282 {
283 long skey = action_pop_func(1);
284 kbd_key_release(skey);
285 return 1;
286 }
287
288
289
290 void action_push_release(long key)
291 {
292
293 action_push_delay(camera_info.cam_key_release_delay);
294 action_push(key);
295 action_push_func(action_stack_AS_RELEASE);
296 }
297
298
299
300 void action_push_click(long key)
301 {
302
303 action_push_release(key);
304 action_push_press(key);
305 }
306
307
308
309
310
311
312 static int action_stack_AS_WAIT_SHOOTING_DONE()
313 {
314
315 if (!shooting_in_progress())
316 {
317
318 int retry = action_pop_func(1);
319
320
321 if (camera_info.state.state_shooting_progress == SHOOTING_PROGRESS_NONE)
322 {
323 if (retry)
324 {
325
326 action_push_shoot(0);
327
328
329 action_push_delay(250);
330 }
331 else
332 {
333
334
335 libscriptapi->set_as_ret(2);
336 }
337 }
338 else
339 {
340
341 libscriptapi->set_as_ret(0);
342
343
344 if (conf.script_shoot_delay > 0)
345 action_push_delay(conf.script_shoot_delay*100);
346 }
347
348 return 1;
349 }
350 return 0;
351 }
352
353
354 static int action_stack_AS_WAIT_FLASH()
355 {
356 if (shooting_is_flash_ready())
357 {
358 action_pop_func(0);
359 return 1;
360 }
361 return 0;
362 }
363
364
365
366 static int action_stack_AS_WAIT_SHOOTING_IN_PROGRESS()
367 {
368
369 int timeout = action_top(2);
370 int retry = action_top(3);
371
372 if (shooting_in_progress() || camera_info.state.mode_video)
373 {
374
375 action_pop_func(2);
376
377
378
379
380 action_push(retry);
381 action_push_func(action_stack_AS_WAIT_SHOOTING_DONE);
382
383
384 action_push_click(KEY_SHOOT_FULL);
385
386
387 action_push_func(action_stack_AS_WAIT_FLASH);
388
389 return 1;
390 }
391 if (get_tick_count() >= timeout)
392 {
393
394 action_pop_func(2);
395
396
397 libscriptapi->set_as_ret(1);
398
399 return 1;
400 }
401 return 0;
402 }
403
404
405
406 void action_push_shoot(int retry)
407 {
408
409 camera_info.state.state_shooting_progress = SHOOTING_PROGRESS_NONE;
410
411
412 action_push(retry);
413 action_push(get_tick_count() + 5000);
414 action_push_func(action_stack_AS_WAIT_SHOOTING_IN_PROGRESS);
415
416
417 action_push_press(KEY_SHOOT_HALF);
418 }
419
420 int action_stack_AS_SHOOT()
421 {
422
423 action_pop_func(0);
424
425
426 action_push_shoot(1);
427
428 return 1;
429 }
430
431
432
433
434
435 static void action_stack_process()
436 {
437 int process = 1;
438
439 while (process && (active_stack->stack_ptr >= 0))
440 {
441
442 long id = action_top(0);
443 action_func f = (action_func)action_top(1);
444 if (id == (long)AS_FUNC_ENTRY)
445 {
446 process = f();
447 }
448 else
449 {
450 char buf[100];
451 sprintf(buf,"AS Error - Not a Function. Aborting. %d %08x %08x.",active_stack->stack_ptr,id,f);
452 script_console_add_error((long)buf);
453 action_stack_finish(active_stack);
454 return;
455 }
456 }
457
458 if (active_stack->stack_ptr < 0)
459 {
460 action_stack_finish(active_stack);
461 }
462 }
463
464
465 void action_stack_process_all()
466 {
467 active_stack = action_stacks;
468
469 while (active_stack)
470 {
471
472
473 action_stack_t *next = active_stack->next;
474
475
476 action_stack_process();
477
478 active_stack = next;
479 }
480 }
481
482