diff --git a/camera_timelapse.py b/camera_timelapse.py index ffc5974..0e29422 100644 --- a/camera_timelapse.py +++ b/camera_timelapse.py @@ -44,7 +44,3 @@ def run(self): self.CaptureImage() -def delImages(picsLocation): - for f in os.listdir(picsLocation): - if re.search(".jpg", f): # if the file has the extension .jpg - os.remove(os.path.join(picsLocation, f)) #remove the file \ No newline at end of file diff --git a/main.py b/main.py index 210bacb..7b20e2f 100644 --- a/main.py +++ b/main.py @@ -357,10 +357,10 @@ def read_display_write(e_rdw): # read and display data in page "record" and writ # check if timelapse, movie and delete photos are selected doTimelapse = nxlib.nx_getValue(ser, nxApp.ID_doTimeLapse[0], nxApp.ID_doTimeLapse[1]) # 1 = yes - doMovie = nxlib.nx_getValue(ser, nxApp.ID_doVideo[0], nxApp.ID_doVideo[1]) - delImages = nxlib.nx_getValue(ser, nxApp.ID_delImages[0], nxApp.ID_delImages[1]) + doMovie = nxlib.nx_getValue(ser, nxApp.ID_doVideo[0], nxApp.ID_doVideo[1]) # 1 = yes + delImages = nxlib.nx_getValue(ser, nxApp.ID_delImages[0], nxApp.ID_delImages[1]) # 1 = yes # parameters required for the video - control = nxlib.nx_getValue(ser, nxApp.ID_choiceVideoDur[0], nxApp.ID_choiceVideoDur[1]) + control = nxlib.nx_getValue(ser, nxApp.ID_choiceVideoDur[0], nxApp.ID_choiceVideoDur[1]) # 0 = freq; 1 = max duration freq = nxlib.nx_getText(ser, nxApp.ID_freqPics[0], nxApp.ID_freqPics[1]) max_vid_dur = nxlib.nx_getText(ser, nxApp.ID_maxVideoDur[0], nxApp.ID_maxVideoDur[1]) interval = nxlib.nx_getText(ser, nxApp.ID_interval[0], nxApp.ID_interval[1]) @@ -432,13 +432,9 @@ def read_display_write(e_rdw): # read and display data in page "record" and writ ### time to make video if doMovie == 1: # make video in a separate thread - t_movie = movie.makemovie(picsLocation, testname[:-4], control, freq, max_vid_dur, elapsed, interval) + t_movie = movie.makemovie(picsLocation, testname[:-4], control, freq, max_vid_dur, elapsed, interval, delImages) t_movie.start() - if delImages == 1: - # delete images - cm.delImages(picsLocation) - # disconnect from database test_end() # morse code sounds to alert for final test diff --git a/movie_timelapse.py b/movie_timelapse.py index ace9d9d..0fadaaa 100644 --- a/movie_timelapse.py +++ b/movie_timelapse.py @@ -2,9 +2,11 @@ import threading import subprocess import datetime +import re + class makemovie(threading.Thread): - def __init__(self, picsLocation, testname, control, freq, max_vid_dur, elapsed, interval): + def __init__(self, picsLocation, testname, control, freq, max_vid_dur, elapsed, interval, delImages): # initialize the inherited Thread object threading.Thread.__init__(self) self.daemon = True @@ -15,6 +17,7 @@ def __init__(self, picsLocation, testname, control, freq, max_vid_dur, elapsed, self.max_vid_dur=max_vid_dur self.elapsed=elapsed self.interval=interval + self.delImages = delImages # create a data lock self.my_lock = threading.Lock() @@ -32,5 +35,11 @@ def MovieMaker(self): process.wait(timeout=10) print('time-lapse movie done') + # delete images if desired + if self.delImages == 1: + for f in os.listdir(self.picsLocation): + if re.search(".jpg", f): # if the file has the extension .jpg + os.remove(os.path.join(self.picsLocation, f)) # remove the file + print('time-lapse images deleted') def run(self): self.MovieMaker() diff --git a/shutdown_reboot.py b/shutdown_reboot.py index f123a95..d4d8e75 100644 --- a/shutdown_reboot.py +++ b/shutdown_reboot.py @@ -12,4 +12,4 @@ def reboot_pi(): def shutdown_pi(): nxlib.nx_setsys(ser, 'bkcmd',0) # sets in NEXTION 'no return error/success codes' - nxlib.nx_setcmd_1par(ser,'page',10) # sends screen to page 9 "shutdown" + nxlib.nx_setcmd_1par(ser,'page',11) # sends screen to page 9 "shutdown"