CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
action_stack.c-Dateireferenz
#include "camera_info.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 19 der Datei action_stack.c.

#define AS_FUNC_ENTRY   0xa32f1c9e

Definiert in Zeile 14 der Datei action_stack.c.

#define MAX_ACTION_STACKS   5

Definiert in Zeile 20 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 172 der Datei action_stack.c.

173 {
174  if (active_stack)
176  return 0;
177 }
void action_pop_delay ( )

Definiert in Zeile 234 der Datei action_stack.c.

235 {
237  action_pop_func(1);
238 }
long action_pop_func ( int  nParam)

Definiert in Zeile 181 der Datei action_stack.c.

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

Definiert in Zeile 209 der Datei action_stack.c.

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

Definiert in Zeile 190 der Datei action_stack.c.

191 {
192  if (active_stack)
194 }
void action_push_click ( long  key)

Definiert in Zeile 300 der Datei action_stack.c.

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

Definiert in Zeile 256 der Datei action_stack.c.

257 {
258  action_push(msec);
260 }
void action_push_func ( action_func  f)

Definiert in Zeile 197 der Datei action_stack.c.

198 {
199  action_push((long)f);
201 }
void action_push_press ( long  key)

Definiert in Zeile 272 der Datei action_stack.c.

273 {
274  // WARNING stack program flow is reversed
276  action_push(key);
278 }
void action_push_release ( long  key)

Definiert in Zeile 290 der Datei action_stack.c.

291 {
292  // WARNING stack program flow is reversed
294  action_push(key);
296 }
void action_push_shoot ( int  retry)

Definiert in Zeile 406 der Datei action_stack.c.

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

Definiert in Zeile 263 der Datei action_stack.c.

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

Definiert in Zeile 281 der Datei action_stack.c.

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

Definiert in Zeile 420 der Datei action_stack.c.

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

Definiert in Zeile 241 der Datei action_stack.c.

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

Definiert in Zeile 354 der Datei action_stack.c.

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

Definiert in Zeile 312 der Datei action_stack.c.

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

Definiert in Zeile 366 der Datei action_stack.c.

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

Definiert in Zeile 62 der Datei action_stack.c.

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

Definiert in Zeile 106 der Datei action_stack.c.

107 {
108  // Check in case already finalised
109  if (p->comp_id == 0) return;
110 
111  // Remove 'active_stack' from the list since it is done execuing
112  if (p == action_stacks)
113  {
115  }
116  else
117  {
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  // Mark as free in case this function gets called again
132  p->comp_id = 0;
133  p->stack_ptr = -1;
134 
135  // Instead of freeing memory, save it to the free list
136  // Next time this block will be reused
137  p->next = free_stacks;
138  free_stacks = p;
139 }
int action_stack_is_finished ( AS_ID  comp_id)

Definiert in Zeile 45 der Datei action_stack.c.

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

Definiert in Zeile 143 der Datei action_stack.c.

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

Definiert in Zeile 435 der Datei action_stack.c.

436 {
437  int process = 1;
438 
439  while (process && (active_stack->stack_ptr >= 0))
440  {
441  // Get function address and id from stack
442  long id = action_top(0);
444  if (id == (long)AS_FUNC_ENTRY) // Safety check
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);
454  return;
455  }
456  }
457 
458  if (active_stack->stack_ptr < 0)
459  {
461  }
462 }
void action_stack_process_all ( )

Definiert in Zeile 465 der Datei action_stack.c.

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

Definiert in Zeile 163 der Datei action_stack.c.

164 {
165  if (active_stack)
167  return 0;
168 }

Variablen-Dokumentation

action_stack_t* action_stacks = NULL
static

Definiert in Zeile 34 der Datei action_stack.c.

action_stack_t* active_stack = NULL
static

Definiert in Zeile 35 der Datei action_stack.c.

action_stack_t* free_stacks = NULL
static

Definiert in Zeile 36 der Datei action_stack.c.

int num_stacks = 0
static

Definiert in Zeile 37 der Datei action_stack.c.

AS_ID task_comp_id = 1
static

Definiert in Zeile 38 der Datei action_stack.c.