Skip to content

Commit

Permalink
implementation of make video in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardosgeral committed Mar 6, 2019
1 parent 54bf5b5 commit 38abfd5
Show file tree
Hide file tree
Showing 9 changed files with 26,106 additions and 18,151 deletions.
Binary file added Nextion/320x240/relier_page15-move_make.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Nextion/320x240/relier_page7-timelapse1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Nextion/320x240/relier_page7-timelapse2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Nextion/HMI/relier.HMI
Binary file not shown.
44,182 changes: 26,052 additions & 18,130 deletions Nextion/Illustrator/relier.ai

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion inputs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ filename = testName
google_sheets = no
googlesh = Erosion
share_email= ricardos.geral@gmail.com
duration = 18
duration = 1
interval = 5
no_reads = 1

Expand Down
28 changes: 16 additions & 12 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,6 @@
nxlib.nx_setValue(ser, nxApp.ID_choiceVideoDur[0], nxApp.ID_choiceVideoDur[1], 1)




nxlib.nx_setText(ser, nxApp.ID_freqPics[0], nxApp.ID_freqPics[1],ini['freq'])
nxlib.nx_setText(ser, nxApp.ID_maxVideoDur[0], nxApp.ID_maxVideoDur[1],ini['max_videoDur'])

Expand All @@ -127,7 +125,6 @@
nxlib.nx_setText(ser, nxApp.ID_testDur[0], nxApp.ID_testDur[1],ini['duration'])



##########
## display Ip in page 1 of NEXTION
def get_ip_address(): # get the (local) ip_address of the raspberry pi
Expand Down Expand Up @@ -433,8 +430,10 @@ def read_display_write(e_rdw): # read and display data in page "record" and writ

### time to make video
if doMovie == 1:
nxlib.nx_setcmd_1par(ser,'page', 15)
# make video in a separate thread
t_movie = movie.makemovie(picsLocation, testname[:-4], control, freq, max_vid_dur, elapsed, interval, delImages)
ip = get_ip_address()
t_movie = movie.makemovie(picsLocation, testname[:-4], control, freq, max_vid_dur, elapsed, interval, delImages, ip)
t_movie.start()

# disconnect from database
Expand All @@ -446,10 +445,11 @@ def read_display_write(e_rdw): # read and display data in page "record" and writ
end_rdw.set()
e_rdw.clear()

nxlib.nx_setcmd_1par(ser, 'page', 'credits')
ip = get_ip_address()
nxlib.nx_setValue(ser, nxApp.ID_status[0], nxApp.ID_status[1], 1) # green flag
nxlib.nx_setText(ser, nxApp.ID_ip[0], nxApp.ID_ip[1], ip)
if doMovie != 1:
nxlib.nx_setcmd_1par(ser, 'page','credits')
ip = get_ip_address()
nxlib.nx_setValue(ser, nxApp.ID_status[0], nxApp.ID_status[1], 1) # green flag
nxlib.nx_setText(ser, nxApp.ID_ip[0], nxApp.ID_ip[1], ip)

##################
# update all inputs previous 'analog' and 'sensors' page
Expand Down Expand Up @@ -553,8 +553,6 @@ def detect_touch(e_rd, e_rdw):
end_rdw.clear()
global start, stop, con, cur, doTimelapse, doMovie, delImages, control, freq, max_vid_dur, interval



input_update()
srv.init(int(inp['interval']),
int(inp['no_reads']),
Expand Down Expand Up @@ -650,6 +648,7 @@ def detect_touch(e_rd, e_rdw):
end_rd.clear()
input_update()
while True:

if nxlib.nx_page(ser)== 7 or nxlib.nx_page(ser) == 12 : # page 12 is the keyboard
ratioVideoTest = float(nxlib.nx_getText(ser, nxApp.ID_ratioVideoTest[0], nxApp.ID_ratioVideoTest[1]))
testDur = float(nxlib.nx_getText(ser, nxApp.ID_testDur[0], nxApp.ID_testDur[1]))
Expand All @@ -661,14 +660,14 @@ def detect_touch(e_rd, e_rdw):
duration_srt = "%02d:%02d:%02d" % (hours, minutes, seconds)
nxlib.nx_setText(ser, nxApp.ID_videoDur[0], nxApp.ID_videoDur[1], duration_srt)

else:
if nxlib.nx_page(ser)== 5:

t_rd = threading.Thread(target=read_display, name='Read/Display', args=(e_rd,))
t_rd.start()
sleep(1) # necessary to allow enough time to start the 1º read of the ads1115 and sensor temp
e_rd.set() # start read_display()
break

sleep(0.7) # for stability

elif (pageID_touch, compID_touch) == (6, 1): # back button in flowmeter type selection (comp1) in page 5 is pressed
# the idea is to stop and restart the threads so that the eventual new flowmeter type can be active
Expand Down Expand Up @@ -717,6 +716,11 @@ def detect_touch(e_rd, e_rdw):
sleep(1)
LED.magentaOff()

while True:
if nxlib.nx_page(ser)== 1:
break
sleep(0.3) # for stability

ip = get_ip_address()
nxlib.nx_setValue(ser, nxApp.ID_status[0], nxApp.ID_status[1], 1) # green flag
nxlib.nx_setText(ser, nxApp.ID_ip[0], nxApp.ID_ip[1], ip)
Expand Down
24 changes: 16 additions & 8 deletions movie_timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@
import subprocess
import datetime
import re
import py3nextion_lib as nxlib
import RGBled as LED
import nextionApp as nxApp

class makemovie(threading.Thread):

def __init__(self, picsLocation, testname, control, freq, max_vid_dur, elapsed, interval, delImages):
def __init__(self, picsLocation, testname, control, freq, max_vid_dur, elapsed, interval, delImages, ip):
# initialize the inherited Thread object
threading.Thread.__init__(self)
self.daemon = True
self.picsLocation = picsLocation
self.testname = testname
self.control=control
self.freq = freq
# get the ip
self.ip = ip
self.max_vid_dur=max_vid_dur
self.fps = 1

(h, m, s) = elapsed.split(':')
self.elapsed = (int(h) * 3600 + int(m) * 60 + int(s))/60 # in minutes

self.interval=interval
self.delImages = delImages
# create a data lock
Expand All @@ -37,22 +39,28 @@ def MovieMaker(self):
command = "ffmpeg -r {} -pattern_type glob -i '*.jpg' -c:v libx264 -s 1280x960 {}/{}_{}.mp4".format(self.fps, self.picsLocation, self.testname, self.getDateTime())
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE) # make video

# delete images if desired

LED.whiteOn()
while True:
poll = process.poll()
if poll != None: # A None value indicates that the process hasn't terminated yet.
print('time-lapse movie done')
## go to credits page
nxlib.nx_setcmd_1par(nxlib.ser, 'page', 'credits')
nxlib.nx_setValue(nxlib.ser, nxApp.ID_status[0], nxApp.ID_status[1], 1) # green flag
nxlib.nx_setText(nxlib.ser, nxApp.ID_ip[0], nxApp.ID_ip[1], str(self.ip))

try:
os.remove(os.path.join("/home/pi/relier", "20")) ## fswebcam creates this temporary file
os.remove(os.path.join("/home/pi/relier", "30")) ## fswebcam creates this temporary file
except:
pass
if self.delImages == 1: # delete the photos
if self.delImages == 1: # delete images if desired
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')
break

LED.whiteOff()
def run(self):
self.MovieMaker()
self.MovieMaker()
21 changes: 21 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,27 @@
# while True:
# flag = False
# if flag == True:

if doMovie == 1:
while True: ## wait until movie_timelapse ends the movie and set page to 'credits' page 1
sleep(0.5) # for stability
if nxlib.nx_page(ser) == 1:
break

ip = get_ip_address()
nxlib.nx_setValue(ser, nxApp.ID_status[0], nxApp.ID_status[1], 1) # green flag
nxlib.nx_setText(ser, nxApp.ID_ip[0], nxApp.ID_ip[1], ip)











# print(var_1 + var_2)
import threading
import time
Expand Down

0 comments on commit 38abfd5

Please sign in to comment.