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

gehe zum Quellcode dieser Datei

Makrodefinitionen

#define USB_BUFFER_SIZE   16
 
#define CALIBRATE_SYNCH_DELAY   1
 
#define KBD_CALIBRATE_TIME   100
 

Funktionen

void debug_error (int err_num)
 
void kbd_synch_delay (int delay_value)
 
void kbd_calibrate_synch_delay ()
 
void usb_remote_status_led (int state)
 
void usb_buffer_insert (int value)
 
void usb_remote_key (void)
 
int usb_HPtimer_good (int time, int interval)
 
int usb_HPtimer_bad (int time, int interval)
 
void clear_usb_power ()
 
int get_usb_power (int mode)
 
void set_usb_remote_state ()
 
int handle_usb_remote ()
 

Variablen

int usb_sync_wait_flag =0
 
int usb_remote_active =0
 
int bracketing_timeout = 0
 
int usb_power =0
 
static int usb_count =0
 
static int logic_module_usb_count = 0
 
int remote_mark_count
 
int remote_space_count
 
static int usb_buffer [USB_BUFFER_SIZE]
 
static int * usb_buffer_in = usb_buffer
 
static int * usb_buffer_out = usb_buffer
 
enum SWITCH_TYPE switch_type = SW_NONE
 
enum CONTROL_MODULE control_module = RMT_NONE
 
enum VIRTUAL_REMOTE_STATE virtual_remote_state = REMOTE_RESET
 
enum DRIVER_STATE driver_state = SW_RESET
 
enum LOGIC_MODULE_STATE logic_module_state = LM_RESET
 
enum USB_POWER_STATE usb_state = USB_POWER_OFF
 
enum CAMERA_MODE camera_mode = CAMERA_MODE_PLAYBACK
 
static int synch_delay_tick = 2800
 
static int synch_delay_calib = 0
 
int usb_HPtimer_error_count
 
void(* usb_driver [])()
 
void(* usb_module_play [])()
 
void(* usb_module_shoot [])()
 
void(* usb_module_video [])()
 
static int rmt_state = RMT_DISABLED
 

Makro-Dokumentation

#define CALIBRATE_SYNCH_DELAY   1

Definiert in Zeile 178 der Datei usb_remote.c.

#define KBD_CALIBRATE_TIME   100

Definiert in Zeile 183 der Datei usb_remote.c.

#define USB_BUFFER_SIZE   16

Definiert in Zeile 40 der Datei usb_remote.c.

Dokumentation der Funktionen

void clear_usb_power ( )

Definiert in Zeile 312 der Datei usb_remote.c.

313 {
314  usb_power = 0 ;
315  usb_count = 0 ;
318 }
void debug_error ( int  err_num)

Definiert in Zeile 76 der Datei usb_remote.c.

77 {
78 }
int get_usb_power ( int  mode)

Definiert in Zeile 327 der Datei usb_remote.c.

328 {
329  int x = 0;
330 
331  switch( mode)
332  {
333  case SINGLE_PULSE :
334  x = usb_power;
335  usb_power = 0;
336  break ;
337  case USB_STATE :
338  x=usb_state;
339  break ;
340  case BUFFERED_PULSE :
341  if ( usb_buffer_out != usb_buffer_in )
342  {
344  x = *usb_buffer_out ;
345  }
346  break ;
347  case PULSE_COUNT :
348  x = usb_count;
349  usb_count = 0;
350  break ;
351  case LM_PULSE_COUNT :
354  break ;
355  case HPTIMER_ERROR_COUNT :
358  break ;
359  }
360  return x;
361 }
int handle_usb_remote ( )

Definiert in Zeile 393 der Datei usb_remote.c.

394 {
395  if (conf.remote_enable)
396  {
399  else
401 
402  (*usb_driver[switch_type])(get_usb_power(USB_STATE)); // jump to driver state machine
403 
404  switch( camera_mode )
405  {
406  case CAMERA_MODE_PLAYBACK :
407  (*usb_module_play[switch_type])(); // jump to control module state machine
408  break ;
409  case CAMERA_MODE_SHOOTING :
410  (*usb_module_shoot[control_module])(); // jump to control module state machine
411  break ;
412  case CAMERA_MODE_VIDEO :
413  (*usb_module_video[control_module])(); // jump to control module state machine
414  break ;
415  default :
416  conf.remote_enable = 0 ;
417  break ;
418  }
419 
420  usb_remote_active = ((logic_module_state > 1) || (driver_state > 1) || (virtual_remote_state > 1) ) ? 1 : 0 ;
421 
422  #ifdef USB_REMOTE_RECORD
423  debug_add_rec();
424  #endif
425 
426  #ifdef USB_REMOTE_DEBUGGING
427  extern int sync_counter ;
428  extern long physw_status[3] ;
429  extern int usb_buffer[] ;
430  extern int * usb_buffer_in ;
431  extern int * usb_buffer_out ;
432  extern const char* gui_USB_switch_types[] ;
433  extern const char* gui_USB_control_modes[];
435  char buf[64] ;
436  static int debug_print = 0 ;
437  static int startup_delay = 0 ;
438  int i, buff_pos, *buff_ptr ;
439 
440  if ( startup_delay < 100 ) startup_delay++ ; // need to give things time to settle before using draw_string()
441  else
442  {
443  if ( debug_print++ > 10000 ) debug_print = 0 ;
444 
445  if ((debug_print%2) == 0)
446  {
447  switch( virtual_remote_state )
448  {
449  case REMOTE_RESET :
450  sprintf(buf,"RESET ") ;
451  break;
452  case REMOTE_RELEASE :
453  sprintf(buf,"RELEASED ") ;
454  break;
455  case REMOTE_HALF_PRESS :
456  sprintf(buf,"HALF PRESS ") ;
457  break;
458  case REMOTE_FULL_PRESS :
459  sprintf(buf,"FULL PRESS ") ;
460  break;
461  default :
462  sprintf(buf,"ERROR ") ;
463  break;
464  }
466  }
467  else
468  {
471  }
472 
473  if (((debug_print+25)%100) ==0 )
474  {
475  sprintf(buf,"switch=%d logic=%d sync=%s mode=%d ", switch_type, control_module, conf.synch_enable?"yes":"no", camera_mode) ;
477  sprintf(buf,"sync count=%d, pulse count=%d width=%d b=%d ", sync_counter, usb_count, usb_power, bracketing.shoot_counter);
479  sprintf(buf,"physw=%d err=%d %d %d ", physw_status[0]&0x03, debug_errors[0], debug_errors[1], debug_errors[2] );
481  }
482 
483  if (((debug_print+75)%100) == 0 )
484  {
485  buff_ptr = usb_buffer_in ;
486  buff_pos = 0 ;
487 
488  for ( i=0 ; i<16 ; i++ )
489  {
490  sprintf(&buf[buff_pos],"%d ", *buff_ptr) ;
491  buff_pos = strlen(buf) ;
492  if ( buff_pos > 45 )
493  {
494  buf[45] = 0 ;
495  i=17 ;
496  }
497  if ( buff_ptr-- == usb_buffer ) buff_ptr = &usb_buffer[15] ;
498  }
500  }
501  }
502  #endif
503  }
504 
505  return usb_remote_active ;
506 }
void kbd_calibrate_synch_delay ( )

Definiert in Zeile 187 der Datei usb_remote.c.

188 {
189  if (synch_delay_calib) return;
190  int t0 = get_tick_count();
192  int t = get_tick_count() - t0;
193 
195 
196  if (synch_delay_tick < 100) synch_delay_tick = 2800; /*something went wrong */
197  if (synch_delay_tick > 100000) synch_delay_tick = 2800;
198 
199  int fd;
200  char buf[64];
201  sprintf(buf, "%d %d ", synch_delay_tick, t);
202  fd = open("A/CALIB.TXT", O_WRONLY|O_CREAT, 0777);
203  if (fd>=0) {
204  write(fd, buf, strlen(buf));
205  close(fd);
206  }
207  synch_delay_calib = 1;
208 }
void kbd_synch_delay ( int  delay_value)

Definiert in Zeile 158 der Datei usb_remote.c.

159 {
160  int count1;
161 
162  for (count1=0;count1<delay_value;count1++) //wait delay_value * 0.1ms
163  {
164  asm volatile (
165  "mov r1, #0\n"
166  ".loop: \n\t"
167  "add r1, r1, #1\n\t"
168  "cmp r1, %0\n\t"
169  "blt .loop"
170  :
171  : "r" (synch_delay_tick)
172  : "r1" );
173 
174  }
175 }
void set_usb_remote_state ( )

Definiert in Zeile 377 der Datei usb_remote.c.

378 {
379  if (conf.remote_enable)
380  {
384  }
385  else
386  {
388  usb_remote_active = 0 ;
389  }
391 }
void usb_buffer_insert ( int  value)

Definiert in Zeile 235 der Datei usb_remote.c.

236 {
238  if ( usb_buffer_in == usb_buffer_out )
239  {
241  }
242  *usb_buffer_in = value ;
243 }
int usb_HPtimer_bad ( int  time,
int  interval 
)

Definiert in Zeile 300 der Datei usb_remote.c.

301 {
303  return (usb_HPtimer_good(time, interval));
304 }
int usb_HPtimer_good ( int  time,
int  interval 
)

Definiert in Zeile 292 der Datei usb_remote.c.

293 {
296  usb_remote_key() ;
297  return 0;
298 }
void usb_remote_key ( void  )

Definiert in Zeile 245 der Datei usb_remote.c.

246 {
247  static int pulse_count=0 ;
248 
250 
251  if(conf.remote_enable)
252  {
253  if (usb_state)
254  { // USB power is ON
255  if (remote_mark_count<30000) remote_mark_count++ ; // track how long the USB power is ON
256  if (remote_space_count != 0) // is this the 0 -> 1 transistion?
257  { //
258  usb_buffer_insert(remote_space_count); // insert space length into buffer
259  remote_space_count = 0 ; // reset the counter
260  }
261  }
262  else
263  { // USB power if OFF
264  if(remote_space_count>-30000) remote_space_count-- ; // track how long the USB power is OFF (note space counts are negative)
265  if (remote_mark_count != 0) // is this the 1 -> 0 transistion?
266  { //
267  pulse_count++ ; // count pulses transistions
268  usb_power = remote_mark_count; // transfer most recent pulse length to variable read by scripts
269  usb_buffer_insert(remote_mark_count); // insert pulse length into buffer
270  remote_mark_count = 0; // reset the counter
271  camera_info.state.kbd_last_clicked = 0xFF; // flag the remote key as the last one pressed (for scripts)
272  camera_info.state.kbd_last_clicked_time = get_tick_count(); // store key release time too
273  } //
274  if ((remote_space_count < -50) && (pulse_count > 0)) // pulse counting done if no activity for 50 timer periods
275  {
276  usb_count = pulse_count ;
277  logic_module_usb_count = pulse_count ;
278  pulse_count = 0 ;
279  }
280  }
281  }
282 }
void usb_remote_status_led ( int  state)

Definiert in Zeile 218 der Datei usb_remote.c.

219 {
221  *(int*)camera_info.cam_remote_sync_status_led=state ? 0x46 : 0x44;
222 }

Variablen-Dokumentation

int bracketing_timeout = 0

Definiert in Zeile 34 der Datei usb_remote.c.

enum CAMERA_MODE camera_mode = CAMERA_MODE_PLAYBACK

Definiert in Zeile 52 der Datei usb_remote.c.

enum CONTROL_MODULE control_module = RMT_NONE

Definiert in Zeile 47 der Datei usb_remote.c.

enum DRIVER_STATE driver_state = SW_RESET

Definiert in Zeile 49 der Datei usb_remote.c.

enum LOGIC_MODULE_STATE logic_module_state = LM_RESET

Definiert in Zeile 50 der Datei usb_remote.c.

int logic_module_usb_count = 0
static

Definiert in Zeile 37 der Datei usb_remote.c.

int remote_mark_count

Definiert in Zeile 38 der Datei usb_remote.c.

int remote_space_count

Definiert in Zeile 38 der Datei usb_remote.c.

int rmt_state = RMT_DISABLED
static

Definiert in Zeile 375 der Datei usb_remote.c.

enum SWITCH_TYPE switch_type = SW_NONE

Definiert in Zeile 46 der Datei usb_remote.c.

int synch_delay_calib = 0
static

Definiert in Zeile 185 der Datei usb_remote.c.

int synch_delay_tick = 2800
static

Definiert in Zeile 155 der Datei usb_remote.c.

int usb_buffer[USB_BUFFER_SIZE]
static

Definiert in Zeile 41 der Datei usb_remote.c.

int* usb_buffer_in = usb_buffer
static

Definiert in Zeile 42 der Datei usb_remote.c.

int* usb_buffer_out = usb_buffer
static

Definiert in Zeile 43 der Datei usb_remote.c.

int usb_count =0
static

Definiert in Zeile 36 der Datei usb_remote.c.

void(* usb_driver[])()

Definiert in Zeile 282 der Datei usb_input.c.

int usb_HPtimer_error_count

Definiert in Zeile 290 der Datei usb_remote.c.

void(* usb_module_play[])()

Definiert in Zeile 675 der Datei usb_module.c.

void(* usb_module_shoot[])()

Definiert in Zeile 692 der Datei usb_module.c.

void(* usb_module_video[])()

Definiert in Zeile 709 der Datei usb_module.c.

int usb_power =0

Definiert in Zeile 35 der Datei usb_remote.c.

int usb_remote_active =0

Definiert in Zeile 33 der Datei usb_remote.c.

enum USB_POWER_STATE usb_state = USB_POWER_OFF

Definiert in Zeile 51 der Datei usb_remote.c.

int usb_sync_wait_flag =0

Definiert in Zeile 32 der Datei usb_remote.c.

enum VIRTUAL_REMOTE_STATE virtual_remote_state = REMOTE_RESET

Definiert in Zeile 48 der Datei usb_remote.c.