From 9531a65a1f9a28cc14ab7cfe72ef66ddf1aacd0d Mon Sep 17 00:00:00 2001 From: Matthias on pi Date: Thu, 22 Nov 2018 13:26:15 -0400 Subject: [PATCH] tweaks on the pi --- makefile | 5 +++-- src/config.c | 50 +++++++++++++++++++++++++++----------------------- src/exif.c | 3 ++- src/main.c | 9 ++++----- src/util.c | 9 +++++++-- 5 files changed, 43 insertions(+), 33 deletions(-) mode change 100644 => 100755 src/config.c mode change 100644 => 100755 src/exif.c mode change 100644 => 100755 src/util.c diff --git a/makefile b/makefile index 98cd77c..c05b039 100755 --- a/makefile +++ b/makefile @@ -11,10 +11,11 @@ all: objdir imgcomp blink_camera_led objdir: @mkdir -p obj -objs = $(OBJ)/main.o $(OBJ)/compare.o $(OBJ)/jpeg2mem.o \ +objs = $(OBJ)/main.o $(OBJ)/config.o $(OBJ)/compare.o $(OBJ)/jpeg2mem.o \ $(OBJ)/jpgfile.o $(OBJ)/exif.o $(OBJ)/start_raspistill.o $(OBJ)/util.o $(OBJ)/jpgfile.o $(OBJ)/exif.o $(OBJ)/start_raspistill.o: $(SRC)/jhead.h +$(OBJ)/main.o $(OBJ)/config.o: $(SRC)/config.h $(OBJ)/%.o:$(SRC)/%.c $(SRC)/imgcomp.h ${CC} $(CFLAGS) -c $< -o $@ @@ -26,7 +27,7 @@ $(SRC)/pi_model.h: $(SRC)/identify_pi >> $(SRC)/pi_model.h blink_camera_led: $(SRC)/blink_camera_led.c $(SRC)/pi_model.h - $(CC) -o blink_camera_led $(SRC)/blink_camera_led.c + $(CC) -o blink_camera_led $(SRC)/blink_camera_led.c libjpeg/libjpeg.a: cd libjpeg; make diff --git a/src/config.c b/src/config.c old mode 100644 new mode 100755 index 7e17973..519b545 --- a/src/config.c +++ b/src/config.c @@ -34,29 +34,33 @@ void usage (void)// complain about bad command line fprintf(stderr, "usage: %s [switches] ", progname); fprintf(stderr, "inputfile outputfile\n"); - fprintf(stderr, "Switches (names may be abbreviated):\n"); - fprintf(stderr, " -scale N Scale before detection by 1/N. Default 1/4\n"); - fprintf(stderr, " -region x1-x2,y1-y2 Specify region of interest\n"); - fprintf(stderr, " -exclude x1-x2,y1-y2 Exclude from area of interest\n"); - fprintf(stderr, " -diffmap A file to use as diff map\n"); - fprintf(stderr, " -dodir Compare images in dir, in order\n"); - fprintf(stderr, " -followdir Do dir and monitor for new images\n"); - fprintf(stderr, " -savedir Where to save images with changes\n"); - fprintf(stderr, " -savenames Output naming scheme. Uses strftime\n" - " to format the output name. May include\n" - " '/' characters for directories.\n"); - fprintf(stderr, " -sensitivity N Set sensitivity. Lower=more sensitive\n"); - fprintf(stderr, " -blink_cmd Run this command when motion detected\n" - " (used to blink the camera LED)\n"); - fprintf(stderr, " -tl N Save image every N seconds regardless\n"); - fprintf(stderr, " -spurious Ignore any change that returns to\n" - " previous image in the next frame\n"); - fprintf(stderr, " -sendsigs Send signal to raspistil every second\n"); - fprintf(stderr, " For continous AE rapsistill, default off\n"); - fprintf(stderr, " -brmonitor Restart raspistill on brightness\n"); - fprintf(stderr, " changes (default on)\n"); - fprintf(stderr, " -verbose or -debug Emit more verbose output\n"); - + fprintf(stderr, + "Switches (names may be abbreviated):\n" + " -scale N Scale before detection by 1/N. Default 1/4\n" + " -region x1-x2,y1-y2 Specify region of interest\n" + " -exclude x1-x2,y1-y2 Exclude from area of interest\n" + " -diffmap A file to use as diff map\n" + " -dodir Compare images in dir, in order\n" + " -followdir Do dir and monitor for new images\n" + " -savedir Where to save images with changes\n" + " -savenames Output naming scheme. Uses strftime\n" + " to format the output name. May include\n" + " '/' characters for directories.\n" + " -sensitivity N Set sensitivity. Lower=more sensitive\n" + " -blink_cmd Run this command when motion detected\n" + " (used to blink the camera LED)\n" + " -tl N Save image every N seconds regardless\n" + " -spurious Ignore any change that returns to\n" + " previous image in the next frame\n" + " -sendsigs Send signal to raspistil every second\n" + " For continous AE rapsistill, default off\n" + " -brmonitor Restart raspistill on brightness\n" + " changes (default on)\n" + " -verbose or -debug Emit more verbose output\n" + " -logtofile Log to file instead of stdout\n" + " -movelognames Rotate log files, scheme works just like\n" + " it does for savenames\n"); + exit(-1); } diff --git a/src/exif.c b/src/exif.c old mode 100644 new mode 100755 index d3ee7eb..bae9438 --- a/src/exif.c +++ b/src/exif.c @@ -22,6 +22,7 @@ typedef struct { //-------------------------------------------------------------------------- // Table of Jpeg encoding process names +/* static const TagTable_t ProcessTable[] = { { M_SOF0, "Baseline"}, { M_SOF1, "Extended sequential"}, @@ -37,7 +38,7 @@ static const TagTable_t ProcessTable[] = { { M_SOF14, "Differential progressive, arithmetic coding"}, { M_SOF15, "Differential lossless, arithmetic coding"}, }; - +*/ #define PROCESS_TABLE_SIZE (sizeof(ProcessTable) / sizeof(TagTable_t)) // 1 - "The 0th row is at the visual top of the image, and the 0th column is the visual left-hand side." diff --git a/src/main.c b/src/main.c index e5c0b8e..90bb4de 100755 --- a/src/main.c +++ b/src/main.c @@ -175,7 +175,7 @@ static int ProcessImage(LastPic_t * New) fprintf(Log,"Mouse left box!\n"); SinceMotionFrames = 0; // Just to be on the safe side. } - if (SinceMotionFrames == 5){ // adjust + if (SinceMotionFrames == 50){ // adjust if (SawMouse){ SawMouse = 0; fprintf(Log,"Move the gate\n"); @@ -189,7 +189,7 @@ static int ProcessImage(LastPic_t * New) if (LastPics[2].Image != NULL){ // Third picture now falls out of the window. Free it and delete it. - if (SinceMotionFrames > 5){ // adjust + if (SinceMotionFrames > 200){ // adjust // If it's been 200 images ince we saw motion, save this image // as a background image for later mouse detection. //printf("Save image as background"); @@ -245,7 +245,7 @@ static int DoDirectoryFunc(char * Directory) //printf("sorted dir: %s\n",FileNames[a]); NewPic.Image = LoadJPEG(NewPic.Name, ScaleDenom, 0, ReadExif); if (NewPic.Image == NULL){ - fprintf(stderr, "Failed to load %s\n",NewPic.Name); + fprintf(Log, "Failed to load %s\n",NewPic.Name); if (FollowDir){ // Raspberry pi timelapse mode may at times dump a corrupt // picture at the end of timelapse mode. Just delete and go on. @@ -297,7 +297,6 @@ int DoDirectory(char * Directory) break; } } -// if (LastPic != NULL) free(LastPic); return a; } @@ -319,7 +318,7 @@ int main(int argc, char **argv) Log = stdout; - printf("Imgcomp version 0.8 (January 2016) by Matthias Wandel\n\n"); + printf("Imgcomp version 0.9 (Nov 2018) by Matthias Wandel\n\n"); progname = argv[0]; diff --git a/src/util.c b/src/util.c old mode 100644 new mode 100755 index b09adc4..95e0a31 --- a/src/util.c +++ b/src/util.c @@ -348,10 +348,10 @@ void LogFileMaintain() } if (MoveLogNames[0]){ strftime(NewLogTo, PATH_MAX, MoveLogNames, localtime(&LastPic_mtime)); - printf("log name: %s\n",NewLogTo); + //printf("log name: %s\n",NewLogTo); if (strcmp(ThisLogTo, NewLogTo)){ if (Log != NULL){ - printf("Log rotate %s --> %s\n", ThisLogTo, NewLogTo); + fprintf(Log,"Log rotate %s --> %s\n", ThisLogTo, NewLogTo); fclose(Log); Log = NULL; EnsurePathExists(NewLogTo); @@ -364,10 +364,15 @@ void LogFileMaintain() if (Log == NULL){ Log = fopen(LogToFile,"w"); + if (Log == NULL){ + fprintf(stderr, "Failed to open log file %s\n",LogToFile); + } if (ThisLogTo[0]){ strncpy(ThisLogTo, NewLogTo, PATH_MAX); } return; + }else{ + fflush(Log); // Do log to ram disk, or this wears out flash! } }