CHDK_DE Vorschauversion  Trunk Rev. 6014
 Alle Datenstrukturen Dateien Funktionen Variablen Typdefinitionen Aufzählungen Aufzählungswerte Makrodefinitionen
scrdump.c-Dateireferenz
#include "camera_info.h"
#include "lang.h"
#include "conf.h"
#include "shooting.h"
#include "time.h"
#include "clock.h"
#include "task.h"
#include "gui.h"
#include "gui_menu.h"
#include "gui_lang.h"
#include "semaphore.h"
#include "simple_module.h"
+ Include-Abhängigkeitsdiagramm für scrdump.c:

gehe zum Quellcode dieser Datei

Datenstrukturen

struct  dummy_ptp_data
 
struct  scrdump_settings_t
 

Makrodefinitionen

#define CMD_SEM_TIMEOUT   1000
 

Aufzählungen

enum  SCRDUMP_CMD { SCRDUMP_CMD_NONE = 0, SCRDUMP_CMD_SCHEDULE, SCRDUMP_CMD_EXIT }
 
enum  SCRDUMP_STATE { SCRDUMP_STATE_IDLE = 0, SCRDUMP_STATE_PENDING, SCRDUMP_STATE_RUN }
 

Funktionen

int live_view_get_data (dummy_ptp_data *data, int flags)
 
int send_data_to_file (int handle, const char *buf, int part_size, int total_size, __attribute__((unused)) int u1, __attribute__((unused)) int u2, __attribute__((unused)) int u3)
 
static int scrdump_start (void)
 
static void scrdump_frame (int what)
 
static void scrdump_finish (void)
 
void scrdump_task (void)
 
void scrdump_schedule (void)
 
void scrdump_menu_schedule (void)
 
void scrdump_menu_exit (void)
 
int _run ()
 
int _module_unloader ()
 
int _module_can_unload ()
 

Variablen

static int running = 0
 
static dummy_ptp_data ptp_data
 
static char fn [32]
 
static int cmd_sem
 
static int cmd_next
 
scrdump_settings_t settings_next
 
static int scrdump_task_running
 
static int scrdump_frames = 1
 
static int scrdump_frame_delay = 10
 
static int scrdump_buffers = 2
 
static int scrdump_skip = 0
 
static int scrdump_delay = 5
 
static const char * scrdump_buffer_names [] = { "Viewprt", "Bitmap", "Both"}
 
static CMenuItem scrdump_submenu_items []
 
static CMenu scrdump_submenu = {0x2a,(int)"Screen Dump Settings", scrdump_submenu_items }
 
libsimple_sym _libscrdump
 
ModuleInfo _module_info
 

Makro-Dokumentation

#define CMD_SEM_TIMEOUT   1000

Definiert in Zeile 99 der Datei scrdump.c.

Dokumentation der Aufzählungstypen

Aufzählungswerte
SCRDUMP_CMD_NONE 
SCRDUMP_CMD_SCHEDULE 
SCRDUMP_CMD_EXIT 

Definiert in Zeile 92 der Datei scrdump.c.

93 {
94  SCRDUMP_CMD_NONE = 0, // no command
95  SCRDUMP_CMD_SCHEDULE, // schedule a dump
96  SCRDUMP_CMD_EXIT, // end task, ending any current dump
97 };
Aufzählungswerte
SCRDUMP_STATE_IDLE 
SCRDUMP_STATE_PENDING 
SCRDUMP_STATE_RUN 

Definiert in Zeile 113 der Datei scrdump.c.

114 {
115  SCRDUMP_STATE_IDLE = 0, // nothing scheduled, just poll for commands
116  SCRDUMP_STATE_PENDING, // dump requested, not started
117  SCRDUMP_STATE_RUN, // dump frames
118 };

Dokumentation der Funktionen

int _module_can_unload ( )

Definiert in Zeile 312 der Datei scrdump.c.

313 {
314  return (running == 0);
315 }
int _module_unloader ( )

Definiert in Zeile 304 der Datei scrdump.c.

305 {
306  if(cmd_sem) {
308  }
309  return 0;
310 }
int _run ( )

Definiert in Zeile 276 der Datei scrdump.c.

277 {
278  running = 1;
279  if(!cmd_sem) {
280  cmd_sem = CreateBinarySemaphore("ScrDumpCmd", 1);
281  }
282  if(!scrdump_task_running) {
283  // lower priority (higher number) than spytask, like dng reverser
284  CreateTask("ScrDump",0x1A,0x800,scrdump_task);
286  }
287 
289  return 0;
290 }
int live_view_get_data ( dummy_ptp_data data,
int  flags 
)
static void scrdump_finish ( void  )
static

Definiert in Zeile 80 der Datei scrdump.c.

81 {
82  if(ptp_data.handle >= 0) {
84  ptp_data.handle = -1;
85  struct utimbuf t;
86  t.actime = t.modtime = time(NULL);
87  utime(fn, &t);
88  }
89 }
static void scrdump_frame ( int  what)
static

Definiert in Zeile 73 der Datei scrdump.c.

74 {
75  // TODO could limit frames, time, roll over files at specific size
76  if(ptp_data.handle >= 0) {
78  }
79 }
void scrdump_menu_exit ( void  )

Definiert in Zeile 242 der Datei scrdump.c.

243 {
244  // if it times out, cmd is ignored
248  while(scrdump_task_running) {
249  msleep(10);
250  }
252  running = 0;
253  }
254 }
void scrdump_menu_schedule ( void  )

Definiert in Zeile 236 der Datei scrdump.c.

237 {
240 }
void scrdump_schedule ( void  )

Definiert in Zeile 208 der Datei scrdump.c.

208  {
209  // if it times out, cmd is ignored
212  // 1 = bitmap 2 = both
213  if(scrdump_buffers > 0) {
215  // skip only applies if bitmap selected
216  // TODO could theoretically want alpha only on d6?
217  if(!scrdump_skip) {
218 #ifdef THUMB_FW
220 #else
222 #endif
223  }
224  }
225  // viewport setting
226  // 0 = viewport 2 = both
227  if(scrdump_buffers == 0 || scrdump_buffers == 2) {
229  }
234  }
235 }
static int scrdump_start ( void  )
static

Definiert in Zeile 39 der Datei scrdump.c.

40 {
41  running = 1;
42  int fd;
43  static int lvdump_header[] = {
44  0x766c6863, // magic chlv
45  8, // size of version record
46  1, // major ver
47  0, // minor ver
48  };
49  // could be desirable but unlikely to work well. Better to use PTP
50  if ( is_video_recording() ) {
51  return -1;
52  }
53  // TODO might want to allow specifying name
54  mkdir("A/DCIM");
55  mkdir("A/DCIM/100CANON");
56  fd = -1;
57  int cnt = 0;
58  do {
59  sprintf(fn, "A/DCIM/100CANON/CRW_%04d.JPG", cnt++);
60  if (stat(fn,0) != 0) {
61  fd = open(fn, O_WRONLY|O_CREAT, 0777);
62  break;
63  }
64  } while(cnt<9999);
65  if (fd>=0) {
66  ptp_data.handle = fd;
67  // TODO write on some cams may require uncached
68  write(fd, lvdump_header,sizeof(lvdump_header));
69  return 0;
70  }
71  return -1;
72 }
void scrdump_task ( void  )

Definiert in Zeile 122 der Datei scrdump.c.

123 {
124  static scrdump_settings_t settings;
125 
126  int state = SCRDUMP_STATE_IDLE;
127  int frames_left = 0;
128 
129  unsigned next_action_tick = get_tick_count();
130 
131  while(1) {
133  int cmd = cmd_next;
135  if(cmd == SCRDUMP_CMD_SCHEDULE) {
136  if(state == SCRDUMP_STATE_RUN) {
137  scrdump_finish();
138  }
139  memcpy(&settings,&settings_next,sizeof(settings));
140  next_action_tick = (unsigned)get_tick_count() + settings.start_delay;
141  frames_left = settings.frame_count;
142  state = SCRDUMP_STATE_PENDING;
143  } else if(cmd == SCRDUMP_CMD_EXIT) {
145  if(state == SCRDUMP_STATE_RUN) {
146  scrdump_finish();
147  }
148  break;
149  }
151  }
152  if(state == SCRDUMP_STATE_PENDING) {
153  if(next_action_tick <= (unsigned)get_tick_count()) {
154  // if starting dump now, schedule first frame immediately, next_action_tick unchanged
155  if(scrdump_start() == 0) {
156  state = SCRDUMP_STATE_RUN;
157  } else { // failed
158  state = SCRDUMP_STATE_IDLE;
159  }
160  }
161  }
162  if(state == SCRDUMP_STATE_RUN) {
163  unsigned t = (unsigned)get_tick_count();
164  if(next_action_tick <= t) {
165  if(frames_left > 0) {
166  scrdump_frame(settings.frame_buffers);
167  frames_left--;
168 
169  // next frame from the start of this frame
170  next_action_tick = t + settings.frame_time;
171  }
172  if(frames_left == 0) {
173  scrdump_finish();
174  state = SCRDUMP_STATE_IDLE;
175  }
176  }
177  }
178  if(state == SCRDUMP_STATE_IDLE) {
179  next_action_tick = (unsigned)get_tick_count() + 100;
180  }
181 
182  unsigned now = (unsigned)get_tick_count();
183  if(next_action_tick >= now) {
184  unsigned sleep_time = next_action_tick - now;
185  // sleep a maximum of 100ms to receive commands
186  // minimum of 10 to avoid hogging cpu
187  if(sleep_time > 100) {
188  sleep_time = 100;
189  } else if(sleep_time < 10) {
190  sleep_time = 10;
191  }
192  msleep((long)sleep_time);
193  } else {
194  msleep(10);
195  }
196  }
198  ExitTask();
199 }
int send_data_to_file ( int  handle,
const char *  buf,
int  part_size,
int  total_size,
__attribute__((unused)) int  u1,
__attribute__((unused)) int  u2,
__attribute__((unused)) int  u3 
)

Definiert in Zeile 23 der Datei scrdump.c.

24 {
25  // TODO write on some cams may require uncached, buffers are but structs + palette may not be
26  // only the first call has total size set, write length of following record
27  if(total_size) {
28  write(handle, &total_size, sizeof(total_size));
29  }
30  write(handle, buf, part_size);
31  return 0;
32 }

Variablen-Dokumentation

libsimple_sym _libscrdump
Initialisierung:

Definiert in Zeile 319 der Datei scrdump.c.

ModuleInfo _module_info
Initialisierung:

Definiert in Zeile 326 der Datei scrdump.c.

int cmd_next
static

Definiert in Zeile 101 der Datei scrdump.c.

int cmd_sem
static

Definiert in Zeile 100 der Datei scrdump.c.

char fn[32]
static

Definiert in Zeile 37 der Datei scrdump.c.

Initialisierung:
= {
-1,
}

Definiert in Zeile 33 der Datei scrdump.c.

int running = 0
static

Definiert in Zeile 14 der Datei scrdump.c.

const char* scrdump_buffer_names[] = { "Viewprt", "Bitmap", "Both"}
static

Definiert in Zeile 257 der Datei scrdump.c.

int scrdump_buffers = 2
static

Definiert in Zeile 204 der Datei scrdump.c.

int scrdump_delay = 5
static

Definiert in Zeile 206 der Datei scrdump.c.

int scrdump_frame_delay = 10
static

Definiert in Zeile 203 der Datei scrdump.c.

int scrdump_frames = 1
static

Definiert in Zeile 202 der Datei scrdump.c.

int scrdump_skip = 0
static

Definiert in Zeile 205 der Datei scrdump.c.

CMenu scrdump_submenu = {0x2a,(int)"Screen Dump Settings", scrdump_submenu_items }
static

Definiert in Zeile 274 der Datei scrdump.c.

CMenuItem scrdump_submenu_items[]
static
Initialisierung:
= {
MENU_ITEM (0x5c,(int)"Schedule dump", MENUITEM_PROC, scrdump_menu_schedule, 0 ),
MENU_ENUM2 (0x5c,(int)"Framebuffers", &scrdump_buffers, scrdump_buffer_names ),
MENU_ITEM (0x5c,(int)"Skip Palette", MENUITEM_BOOL, &scrdump_skip, 0 ),
MENU_ITEM (0x5c,(int)"Exit module", MENUITEM_PROC, scrdump_menu_exit, 0 ),
{0}
}

Definiert in Zeile 258 der Datei scrdump.c.

int scrdump_task_running
static

Definiert in Zeile 121 der Datei scrdump.c.

scrdump_settings_t settings_next

Definiert in Zeile 110 der Datei scrdump.c.