CHDK_DE Vorschauversion  Trunk Rev. 5163
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
action_stack.c-Dateireferenz
#include "camera_info.h"
#include "stdlib.h"
#include "modes.h"
#include "clock.h"
#include "shooting.h"
#include "console.h"
#include "conf.h"
#include "keyboard.h"
#include "histogram.h"
#include "action_stack.h"
#include "script_api.h"
+ Include-Abhängigkeitsdiagramm für action_stack.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  _action_stack
 

Makrodefinitionen

#define AS_FUNC_ENTRY   0xa32f1c9e
 
#define ACTION_STACK_SIZE   48
 
#define MAX_ACTION_STACKS   5
 

Typdefinitionen

typedef struct _action_stack action_stack_t
 

Funktionen

int action_stack_is_finished (AS_ID comp_id)
 
AS_ID action_stack_create (action_func proc_func)
 
static void action_stack_finish (action_stack_t *p)
 
void action_stack_kill (AS_ID comp_id)
 
long action_top (int n)
 
long action_pop ()
 
long action_pop_func (int nParam)
 
void action_push (long p)
 
void action_push_func (action_func f)
 
static int action_process_delay (long delay)
 
void action_pop_delay ()
 
static int action_stack_AS_SLEEP ()
 
void action_push_delay (long msec)
 
static int action_stack_AS_PRESS ()
 
void action_push_press (long key)
 
static int action_stack_AS_RELEASE ()
 
void action_push_release (long key)
 
void action_push_click (long key)
 
static int action_stack_AS_WAIT_SHOOTING_DONE ()
 
static int action_stack_AS_WAIT_FLASH ()
 
static int action_stack_AS_WAIT_SHOOTING_IN_PROGRESS ()
 
void action_push_shoot (int retry)
 
int action_stack_AS_SHOOT ()
 
static void action_stack_process ()
 
void action_stack_process_all ()
 

Variablen

static action_stack_taction_stacks = NULL
 
static action_stack_tactive_stack = NULL
 
static action_stack_tfree_stacks = NULL
 
static int num_stacks = 0
 
static AS_ID task_comp_id = 1
 

Makro-Dokumentation

#define ACTION_STACK_SIZE   48

Definiert in Zeile 20 der Datei action_stack.c.

#define AS_FUNC_ENTRY   0xa32f1c9e

Definiert in Zeile 15 der Datei action_stack.c.

#define MAX_ACTION_STACKS   5

Definiert in Zeile 21 der Datei action_stack.c.

Dokumentation der benutzerdefinierten Typen

typedef struct _action_stack action_stack_t

Dokumentation der Funktionen

long action_pop ( )

Definiert in Zeile 173 der Datei action_stack.c.

174 {
175  if (active_stack)
177  return 0;
178 }
void action_pop_delay ( )

Definiert in Zeile 235 der Datei action_stack.c.

236 {
238  action_pop_func(1);
239 }
long action_pop_func ( int  nParam)

Definiert in Zeile 182 der Datei action_stack.c.

183 {
184  for (; nParam >= 0; nParam--)
185  action_pop();
186  return action_pop(); // Return function pointer / last parameter
187 }
static int action_process_delay ( long  delay)
static

Definiert in Zeile 210 der Datei action_stack.c.

211 {
212  unsigned t = get_tick_count();
213  // FIXME take care if overflow occurs
215  {
216  /* delay of -1 signals indefinite (actually 1 day) delay*/
217  if(delay == -1)
218  delay = 86400000;
219 
220  active_stack->delay_target_ticks = t+delay;
221  return 0;
222  }
224  {
225  return 1;
226  }
227  return 0;
228 }
void action_push ( long  p)

Definiert in Zeile 191 der Datei action_stack.c.

192 {
193  if (active_stack)
195 }
void action_push_click ( long  key)

Definiert in Zeile 301 der Datei action_stack.c.

302 {
303  // WARNING stack program flow is reversed
306 }
void action_push_delay ( long  msec)

Definiert in Zeile 257 der Datei action_stack.c.

258 {
259  action_push(msec);
261 }
void action_push_func ( action_func  f)

Definiert in Zeile 198 der Datei action_stack.c.

199 {
200  action_push((long)f);
202 }
void action_push_press ( long  key)

Definiert in Zeile 273 der Datei action_stack.c.

274 {
275  // WARNING stack program flow is reversed
277  action_push(key);
279 }
void action_push_release ( long  key)

Definiert in Zeile 291 der Datei action_stack.c.

292 {
293  // WARNING stack program flow is reversed
295  action_push(key);
297 }
void action_push_shoot ( int  retry)

Definiert in Zeile 407 der Datei action_stack.c.

408 {
409  // Init shooting state
411 
412  // Wait for camera ready to shoot or timeout
413  action_push(retry);
414  action_push(get_tick_count() + 5000);
416 
417  // Half press shutter
419 }
static int action_stack_AS_PRESS ( )
static

Definiert in Zeile 264 der Datei action_stack.c.

265 {
266  long skey = action_pop_func(1); // Key parameter returned
267  kbd_key_press(skey);
268  return 1;
269 }
static int action_stack_AS_RELEASE ( )
static

Definiert in Zeile 282 der Datei action_stack.c.

283 {
284  long skey = action_pop_func(1); // Key parameter returned
285  kbd_key_release(skey);
286  return 1;
287 }
int action_stack_AS_SHOOT ( void  )

Definiert in Zeile 421 der Datei action_stack.c.

422 {
423  // Remove this action from stack
424  action_pop_func(0);
425 
426  // Push the shoot actions (with retry on shoot failure)
428 
429  return 1;
430 }
static int action_stack_AS_SLEEP ( )
static

Definiert in Zeile 242 der Datei action_stack.c.

243 {
244  long delay = action_top(2);
245 
246  if (action_process_delay(delay))
247  {
249  return 1;
250  }
251 
252  return 0;
253 }
static int action_stack_AS_WAIT_FLASH ( )
static

Definiert in Zeile 355 der Datei action_stack.c.

356 {
358  {
359  action_pop_func(0);
360  return 1;
361  }
362  return 0;
363 }
static int action_stack_AS_WAIT_SHOOTING_DONE ( )
static

Definiert in Zeile 313 der Datei action_stack.c.

314 {
315  // Are we there yet?
316  if (!shooting_in_progress())
317  {
318  // Remove this action from stack
319  int retry = action_pop_func(1); // Retry parameter returned
320 
321  // Check if shoot succeeded or not
323  {
324  if (retry)
325  {
326  // Shoot failed, retry once, if it fails again give up
328 
329  // Short delay before retrying shoot
330  action_push_delay(250);
331  }
332  else
333  {
334  // Failed - already retried, or no retry requested
335  // Return 'shoot' status to script - 2 = shoot failed
337  }
338  }
339  else
340  {
341  // Return 'shoot' status to script - 0 = shoot succesful
343 
344  // Final script config delay (XXX FIXME find out how to wait to jpeg save finished)
345  if (conf.script_shoot_delay > 0)
347  }
348 
349  return 1;
350  }
351  return 0;
352 }
static int action_stack_AS_WAIT_SHOOTING_IN_PROGRESS ( )
static

Definiert in Zeile 367 der Datei action_stack.c.

368 {
369  // Get parameters
370  int timeout = action_top(2);
371  int retry = action_top(3);
372 
374  {
375  // Remove this action from the stack
376  action_pop_func(2);
377 
378  // Push the rest of the shoot actions onto the stack (reversed flow)
379 
380  // Push 'retry if failed' parameter for exit action
381  action_push(retry);
383 
384  // Full press shutter
386 
387  // Wait for flash recharged
389 
390  return 1;
391  }
392  if (get_tick_count() >= timeout)
393  {
394  // Remove this action from the stack
395  action_pop_func(2);
396 
397  // Return 'shoot' status to script - 1 = shutter half press timed out
399 
400  return 1;
401  }
402  return 0;
403 }
AS_ID action_stack_create ( action_func  proc_func)

Definiert in Zeile 63 der Datei action_stack.c.

64 {
65  // Cap the maximum number of action_stacks
67  return -1;
68 
69  // Initialize new action stack
70  action_stack_t* stack = 0;
71  if (free_stacks)
72  {
73  // Reuse previous memory block
74  stack = free_stacks;
76  }
77  else
78  {
79  // Get a new block
80  stack = (action_stack_t*)malloc(sizeof(action_stack_t));
81  }
82  memset(stack,0,sizeof(action_stack_t));
83 
84  // Insert at start of list - stacks execute in order of most recent creation
85  stack->next = action_stacks;
86  action_stacks = stack;
87 
88  // Initialize id & processing function
89  stack->comp_id = task_comp_id;
90  stack->stack[0] = (long)proc_func;
91  stack->stack[1] = AS_FUNC_ENTRY; // Can't use action_push_func as active_stack not set
92  stack->stack_ptr = 1;
93 
94  ++num_stacks;
95 
96  // Increment task_comp_id
97  // For this to clash with a running stack you would need to leave one running
98  // while 4 billion more were created - highly unlikely.
99  ++task_comp_id;
100  // Reset just in case it wraps around to 'finished' value
101  if (task_comp_id == 0) task_comp_id = 1;
102 
103  return stack->comp_id;
104 }
static void action_stack_finish ( action_stack_t p)
static

Definiert in Zeile 107 der Datei action_stack.c.

108 {
109  // Check in case already finalised
110  if (p->comp_id == 0) return;
111 
112  // Remove 'active_stack' from the list since it is done execuing
113  if (p == action_stacks)
114  {
116  }
117  else
118  {
120  while (prev && (prev->next != p))
121  {
122  prev = prev->next;
123  }
124  if (prev)
125  {
126  prev->next = prev->next->next;
127  }
128  }
129 
130  --num_stacks;
131 
132  // Mark as free in case this function gets called again
133  p->comp_id = 0;
134  p->stack_ptr = -1;
135 
136  // Instead of freeing memory, save it to the free list
137  // Next time this block will be reused
138  p->next = free_stacks;
139  free_stacks = p;
140 }
int action_stack_is_finished ( AS_ID  comp_id)

Definiert in Zeile 46 der Datei action_stack.c.

47 {
49  while (p)
50  {
51  if (p->comp_id == comp_id)
52  return 0;
53  p = p->next;
54  }
55 
56  return 1;
57 }
void action_stack_kill ( AS_ID  comp_id)

Definiert in Zeile 144 der Datei action_stack.c.

145 {
147  while (p)
148  {
149  if (p->comp_id == comp_id)
150  {
152  return;
153  }
154  p = p->next;
155  }
156 }
static void action_stack_process ( )
static

Definiert in Zeile 436 der Datei action_stack.c.

437 {
438  int process = 1;
439 
440  while (process && (active_stack->stack_ptr >= 0))
441  {
442  // Get function address and id from stack
443  long id = action_top(0);
445  if (id == AS_FUNC_ENTRY) // Safety check
446  {
447  process = f();
448  }
449  else
450  {
451  char buf[100];
452  sprintf(buf,"AS Error - Not a Function. Aborting. %d %08x %08x.",active_stack->stack_ptr,id,f);
453  script_console_add_error((long)buf);
455  return;
456  }
457  }
458 
459  if (active_stack->stack_ptr < 0)
460  {
462  }
463 }
void action_stack_process_all ( )

Definiert in Zeile 466 der Datei action_stack.c.

467 {
469 
470  while (active_stack)
471  {
472  // Save the next stack in case the current one ends and
473  // releases it's stack during execution
475 
476  // Process stack functions
478 
479  active_stack = next;
480  }
481 }
long action_top ( int  n)

Definiert in Zeile 164 der Datei action_stack.c.

165 {
166  if (active_stack)
168  return 0;
169 }

Variablen-Dokumentation

action_stack_t* action_stacks = NULL
static

Definiert in Zeile 35 der Datei action_stack.c.

action_stack_t* active_stack = NULL
static

Definiert in Zeile 36 der Datei action_stack.c.

action_stack_t* free_stacks = NULL
static

Definiert in Zeile 37 der Datei action_stack.c.

int num_stacks = 0
static

Definiert in Zeile 38 der Datei action_stack.c.

AS_ID task_comp_id = 1
static

Definiert in Zeile 39 der Datei action_stack.c.