Skip to content

Commit

Permalink
timeval_diff simplification
Browse files Browse the repository at this point in the history
  • Loading branch information
asalamon74 committed Apr 18, 2018
1 parent 90305f0 commit 6e25448
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
6 changes: 3 additions & 3 deletions pktriggercord-cli.c
Expand Up @@ -319,7 +319,7 @@ void bulb_old(pslr_handle_t camhandle, pslr_rational_t shutter_speed, struct tim
pslr_bulb( camhandle, true );
pslr_shutter(camhandle);
gettimeofday(&current_time, NULL);
double waitsec = 1.0 * shutter_speed.nom / shutter_speed.denom - timeval_diff(&current_time, &prev_time) / 1000000.0;
double waitsec = 1.0 * shutter_speed.nom / shutter_speed.denom - timeval_diff_sec(&current_time, &prev_time);
if ( waitsec < 0 ) {
waitsec = 0;
}
Expand Down Expand Up @@ -1067,7 +1067,7 @@ int main(int argc, char **argv) {
}
pslr_connect(camhandle);
}
waitsec = 1.0 * delay - timeval_diff(&current_time, &prev_time) / 1000000.0;
waitsec = 1.0 * delay - timeval_diff_sec(&current_time, &prev_time);
if ( waitsec > 0 ) {
printf("Waiting for %.2f sec\n", waitsec);
sleep_sec( waitsec );
Expand All @@ -1086,7 +1086,7 @@ int main(int argc, char **argv) {
}

gettimeofday (&current_time, NULL);
if ( timeout != 0 && ( timeval_diff(&current_time, &prev_time) / 1000000.0 >= timeout) ) {
if ( timeout != 0 && ( timeval_diff_sec(&current_time, &prev_time) >= timeout) ) {
printf("Timeout %d sec passed!\n", timeout);
break;
}
Expand Down
9 changes: 5 additions & 4 deletions pktriggercord-servermode.c
Expand Up @@ -41,8 +41,9 @@
#include "pslr.h"
#include "pslr_lens.h"

long int timeval_diff(struct timeval *t2, struct timeval *t1) {
return (t2->tv_usec - t1->tv_usec) + 1000000 * (t2->tv_sec - t1->tv_sec);
double timeval_diff_sec(struct timeval *t2, struct timeval *t1) {
//DPRINT("tv2 %ld %ld t1 %ld %ld\n", t2->tv_sec, t2->tv_usec, t1->tv_sec, t1->tv_usec);
return (t2->tv_usec - t1->tv_usec) / 1000000.0 + (t2->tv_sec - t1->tv_sec);
}

void camera_close(pslr_handle_t camhandle) {
Expand All @@ -59,8 +60,8 @@ pslr_handle_t camera_connect( char *model, char *device, int timeout, char *erro
gettimeofday(&prev_time, NULL);
while (!(camhandle = pslr_init( model, device ))) {
gettimeofday(&current_time, NULL);
DPRINT("diff: %f\n", timeval_diff(&current_time, &prev_time) / 1000000.0);
if ( timeout == 0 || timeout > timeval_diff(&current_time, &prev_time) / 1000000.0 ) {
DPRINT("diff: %f\n", timeval_diff_sec(&current_time, &prev_time));
if ( timeout == 0 || timeout > timeval_diff_sec(&current_time, &prev_time)) {
DPRINT("sleep 1 sec\n");
sleep_sec(1);
} else {
Expand Down
2 changes: 1 addition & 1 deletion pktriggercord-servermode.h
Expand Up @@ -35,6 +35,6 @@ pslr_handle_t camera_connect( char *model, char *device, int timeout, char *erro

void camera_close(pslr_handle_t camhandle);

long int timeval_diff(struct timeval *t2, struct timeval *t1);
double timeval_diff_sec(struct timeval *t2, struct timeval *t1);

#endif
6 changes: 3 additions & 3 deletions pktriggercord.c
Expand Up @@ -1070,16 +1070,16 @@ static void update_image_areas(int buffer, bool main) {
DPRINT("update_image_areas\n");
struct timeval current_time;
gettimeofday(&current_time, NULL);
long int bulb_remain_sec = timeval_diff(&expected_bulb_end_time, &current_time) / 1000000.0;
double bulb_remain_sec = timeval_diff_sec(&expected_bulb_end_time, &current_time);
GtkButton *shutterButton = (GtkButton *)GW("shutter_button");
while (bulb_remain_sec>0) {
static gchar bulb_message[100];
sprintf (bulb_message, "BULB -> wait : %ld seconds", bulb_remain_sec);
sprintf (bulb_message, "BULB -> wait : %.0f seconds", bulb_remain_sec);
gtk_button_set_label(shutterButton, bulb_message);
sleep_sec(1);
wait_for_gtk_events_pending();
gettimeofday(&current_time, NULL);
bulb_remain_sec = timeval_diff(&expected_bulb_end_time, &current_time) / 1000000.0;
bulb_remain_sec = timeval_diff_sec(&expected_bulb_end_time, &current_time);
}
gtk_button_set_label(shutterButton, "Take picture");

Expand Down

0 comments on commit 6e25448

Please sign in to comment.