All pastes #290465 Raw Edit

alesan

public text v1 · immutable
#290465 ·published 2006-12-24 01:06 UTC
rendered paste body
$ svn diff
Index: gphoto2/main.c
===================================================================
--- gphoto2/main.c      (revision 9721)
+++ gphoto2/main.c      (working copy)
@@ -86,7 +86,10 @@

 GPParams gp_params;

+/* flag for SIGUSR1 handler */
+int capture_now = 0;

+
 /*! \brief Copy string almost like strncpy, converting to lower case.
  *
  * This function behaves like strncpy, but
@@ -567,6 +570,12 @@
        return (GP_OK);
 }

+void
+sig_handler_capture_now(int sig_num)
+{
+       signal(SIGUSR1, sig_handler_capture_now);
+       capture_now = 1;
+}

 int
 capture_generic (CameraCaptureType type, const char __unused__ *name)
@@ -584,6 +593,8 @@
                        printf (_("Time-lapse mode enabled (interval: %ds).\n"),
                                glob_interval);
        }
+       capture_now = 0;
+       signal(SIGUSR1, sig_handler_capture_now);

        while(++frames) {
                if (!(gp_params.flags & FLAGS_QUIET) && glob_interval) {
@@ -700,14 +711,20 @@
                if (waittime > 0) {
                        if (!(gp_params.flags & FLAGS_QUIET) && glob_interval)
                                printf (_("Sleeping for %d second(s)...\n"), glob_interval);
-                       sleep (waittime);
+                       int i;
+                       for (i=0; (!capture_now) && (i<waittime); i++)
+                               sleep(1);
+                       if(capture_now && !(gp_params.flags & FLAGS_QUIET) && glob_interval)
+                               printf (_("Awakened by SIGUSR1...\n"));
                } else {
                        if (!(gp_params.flags & FLAGS_QUIET) && glob_interval)
                                printf (_("not sleeping (%d seconds behind schedule)\n"), - waittime);
                }
-               next_pic_time += glob_interval;
+               if(!(gp_params.flags & FLAGS_RESET_CAPTURE_INTERVAL))
+                       next_pic_time += glob_interval;
        }

+       signal(SIGUSR1, SIG_DFL);
        return (GP_OK);
 }

Index: gphoto2/main.h
===================================================================
--- gphoto2/main.h      (revision 9721)
+++ gphoto2/main.h      (working copy)
@@ -41,6 +41,7 @@
                           const char *folder, const char *filename,
                           CameraFileType type);
 int    save_camera_file_to_file (const char *folder, CameraFile *file, const char *tmpname);
+void   sig_handler_capture_now (int sig_num);
 int    capture_generic (CameraCaptureType type, const char *name);

 #endif /* __MAIN_H__ */
Index: doc/gphoto2.1
===================================================================
--- doc/gphoto2.1       (revision 9721)
+++ doc/gphoto2.1       (working copy)
@@ -259,7 +259,7 @@
 Number of frames to capture in one run. Default is infinite number of frames.
 .TP
 \fB\-I \fR\fB\fISECONDS\fR\fR, \fB\-\-interval \fR\fB\fISECONDS\fR\fR
-Time between capture of multiple frames.
+Time between capture of multiple frames. If SIGUSR1 is received a picture is taken immediately and the interval is reset (see \fBSIGNALS\fR).
 .TP
 \fB\-\-capture\-image\fR
 Capture an image.
@@ -354,6 +354,10 @@
 libusb
 library will print messages. In order to get some debug output, set it to
 \fI1\fR.
+.SH "SIGNALS"
+.TP
+\fBSIGUSR1\fR
+When in time-lapse capture mode, if a SIGUSR1 is received a picture is taken immediately and the time counter is reset. Note that the camera will need some time (from 50ms to a few seconds) to actually capture the image.
 .SH "SEE ALSO"
 .PP
 libgphoto2(3),