Skip to content

Commit

Permalink
bux fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ricardosgeral committed Feb 28, 2019
1 parent 892fc2e commit 638c5c9
Show file tree
Hide file tree
Showing 24 changed files with 33,760 additions and 18,136 deletions.
Binary file modified Nextion/320x240/relier_page1-credits0.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_page1-credits1.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_page10-progressbar0.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_page10-progressbar1.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_page3-settings1.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_page4-testtype0.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_page4-testtype1.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_page5-analag1.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_page5-analog0.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_page6-Flowmeter0.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_page6-Flowmeter1.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/320x240/relier_page8-sensors0.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_page9-stop0.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_page9-stop1.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_page9-wait.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.
51,584 changes: 33,608 additions & 17,976 deletions Nextion/Illustrator/relier.ai

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion camera_timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import threading
import datetime, subprocess, os
import re

class capture(threading.Thread):

def __init__(self, picsLocation, testname, testtype, elapsed, flowrate):
Expand Down
2 changes: 1 addition & 1 deletion inputs.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[settings]
filename = 1stHETtest
filename = asasfsd
google_sheets = no
googlesh = Erosion
share_email= ricardos.geral@gmail.com
Expand Down
90 changes: 38 additions & 52 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def input_settings(): # inputs from 'settings' and 'testType' pages
'lastip' : lastip
}

def input_analog(): #inputs from page "sensors", page "flowmeter" and page timelapse
def input_analog(): #inputs from page "sensors", page "flowmeter" and page time-lapse
mu = nxlib.nx_getText(ser, nxApp.ID_mu[0], nxApp.ID_mu[1])
mi = nxlib.nx_getText(ser, nxApp.ID_mi[0], nxApp.ID_mi[1])
md = nxlib.nx_getText(ser, nxApp.ID_md[0], nxApp.ID_md[1])
Expand Down Expand Up @@ -225,7 +225,6 @@ def input_analog(): #inputs from page "sensors", page "flowmeter" and page tim
'control_video':control_video,
'freq':freq,
'max_videoDur':max_videoDur,

}

def display_analog(data): #outputs
Expand Down Expand Up @@ -300,18 +299,7 @@ def read_display(e_rd): #read and display data in page "sensors"
##################

def read_display_write(e_rdw): # read and display data in page "record" and write to file
global stop, con, cur

# 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]) # 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]) # 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])

global stop, con, cur, doTimelapse, doMovie, delImages, control, freq, max_vid_dur, interval

#first, check if HET test is selected
if inp['test_type'] == '3': # if HET test is the selection
Expand Down Expand Up @@ -355,11 +343,11 @@ def read_display_write(e_rdw): # read and display data in page "record" and writ
# determine test type
rg = nxlib.nx_getValue(ser, nxApp.ID_rg[0], nxApp.ID_rg[1])
if rg == 0:
testtype = 'HET'
elif rg == 1:
testtype = 'FLET'
elif rg == 2:
elif rg == 1:
testtype = 'CFET'
elif rg == 2:
testtype = 'HET'
elif rg == 3:
testtype = nxlib.nx_getText(ser, nxApp.ID_othername[0], nxApp.ID_othername[1]) # r3
else:
Expand Down Expand Up @@ -548,7 +536,19 @@ def detect_touch(e_rd, e_rdw):

elif (pageID_touch,compID_touch) == (2,3): # button start record (comp3) in page 2 is pressed
end_rdw.clear()
global start, stop, con, cur
global start, stop, con, cur, doTimelapse, doMovie, delImages, control, freq, max_vid_dur, interval

# inputs about 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]) # 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]) # 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])

input_update()
srv.init(int(inp['interval']),
int(inp['no_reads']),
Expand Down Expand Up @@ -634,7 +634,7 @@ def detect_touch(e_rd, e_rdw):
e_rd.set()


elif (pageID_touch, compID_touch) == (5, 21): # button timelapse is selected (comp21) in page 5 is pressed
elif (pageID_touch, compID_touch) == (5, 21): # button timelapse is selected (comp21) in page 5 is pressed goes to page 7
print("Enter time-lapse-settings: page= {}, component= {}, event= {}".format(pageID_touch, compID_touch, event_touch))
#stop the reading thread
end_rd.set()
Expand All @@ -643,40 +643,26 @@ 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]))
duration_min = testDur / ratioVideoTest # in minutes
# convert to string in form hh:mm:s
seconds = duration_min * 60
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
duration_srt = "%02d:%02d:%02d" % (hours, minutes, seconds)
nxlib.nx_setText(ser, nxApp.ID_videoDur[0], nxApp.ID_videoDur[1], duration_srt)

else:

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

while True: # this loop is to estimate the duration of the video

try:
touch = ser.read_until(EndCom)
if hex(touch[0]) == '0x65': # touch event. If it's empty, do nothing
pageID_touch = touch[1]
compID_touch = touch[2]
event_touch = touch[3]

if (pageID_touch, compID_touch) == (7, 6): # leave the time-lapse page and enter the sensors page

#restart the readind thread
print("Leaving time-lapse settings : page= {}, component= {}, event= {}".format(pageID_touch, compID_touch, event_touch))

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
except:
pass

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]))
duration_min = testDur / ratioVideoTest # in minutes
# convert to string in form hh:mm:s
seconds = duration_min * 60
minutes, seconds = divmod(seconds, 60)
hours, minutes = divmod(minutes, 60)
duration_srt = "%02d:%02d:%02d" % (hours, minutes, seconds)
nxlib.nx_setText(ser, nxApp.ID_videoDur[0], nxApp.ID_videoDur[1], duration_srt)

sleep(0.8) # 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
12 changes: 8 additions & 4 deletions movie_timelapse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ def __init__(self, picsLocation, testname, control, freq, max_vid_dur, elapsed,
self.control=control
self.freq = freq
self.max_vid_dur=max_vid_dur
self.elapsed=elapsed
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 @@ -27,10 +31,10 @@ def getDateTime(self):
def MovieMaker(self):
os.chdir(self.picsLocation)
if self.control ==1: ## selected a maximum duration for the video
self.freq = (int(self.elapsed)/60)/(int(self.interval)*int(self.max_vid_dur))
self.fps = self.elapsed/(int(self.interval)*int(self.max_vid_dur))
else:
self.freq = int(self.freq)
command = "ffmpeg -r {} -pattern_type glob -i '*.jpg' -c:v libx264 -s 1280x960 {}/{}_{}.mp4".format(self.freq, self.picsLocation, self.testname, self.getDateTime())
self.fps = int(self.freq)
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
Expand Down
206 changes: 104 additions & 102 deletions py3nextion_lib.py
Original file line number Diff line number Diff line change
@@ -1,103 +1,105 @@
#uncoment lines below to use the examples in the bottom of file

import serial
BAUD =38400 # for new monitor please put 9600 and then run nx_setsys(ser, 'bauds', newBAUD)
ser = serial.Serial(
port='/dev/ttyAMA0',
baudrate = BAUD,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0.15)

ser.reset_output_buffer()

EndCom = "\xff\xff\xff"

def nx_setsys(ser, sysvar,value): # Set system variables. sysvar as text. example: sysvar='dim'
#Possible commands: 'bkcmd', 'dp', 'dim', 'dims', 'baud', 'bauds','ussp', 'thsp', 'thup', 'delay', 'sleep'
# see instruction set of NEXTION device to see possible values for each system variable
set = sysvar + '=' + str(value)
ser.write((set+EndCom).encode('latin-1'))
return None

def nx_setcmd_0par(ser, command): #Set operational Commands without parameters
# Possible commands: 'ref_stop', 'ref_star', 'touch_j' (calibrate), 'com_stop', 'com_start', 'code_c','rest', 'doevents'
# see instruction set of NEXTION device to know the possible commands and what they do
ser.write((command+EndCom).encode('latin-1'))
return None

def nx_setcmd_1par(ser, command, value): #Set operational Commands with 1 parameters
# Possible commands: 'page', 'ref'
# see instruction set of NEXTION device to know the possible commands and what they do
if value is str:
set=command +' '+ value # example 'page initial'
else:
set=command +' '+str(value) #example 'page 1'
ser.write((set+EndCom).encode('latin-1'))
return None

def nx_setcmd_2par(ser, command, value1, value2=1): #Set operational Commands with 2 parameters
# Possible commands: 'click', 'vis', 'tsw'
# value2 can only be 0 or 1
# see instruction set of NEXTION device to know the possible commands and what they do
if value1 is str:
set=command + ' ' + str(value1) + ',' + str(value2) #example 'vis t0,1 show componente t0'
else:
set = command + ' ' + str(value1) + ',' + str(value2) # vis 2,0 hide componentID 2 in current page'
ser.write((set+EndCom).encode('latin-1'))
return None

def nx_page(ser): # reads number of current page show in display
ser.write(('sendme ' + EndCom).encode('latin-1'))
page=ser.read_until(EndCom)
page=str(page)
page=page.lstrip("b\\'f\\x")
page=page.rstrip("\\xff\\xff\\xff\\'")
page = int(page, 16)
return page

def nx_getText(ser, pageID, componentID): # Returns the .txt from a component in a page as text
send = 'get ' + 'p[' + str(pageID) + '].b[' + str(componentID)+']''.txt'
ser.write((send+EndCom).encode('latin-1'))
text=ser.read_until(EndCom)
text = str(text)
text = text.lstrip("b\\'p")
text = text.rstrip("\\xff\\xff\\xff\\'")
return text # as string"

def nx_getValue(ser, pageID, componentID): # Returns the .val from a component in a page as text
send = 'get ' + 'p[' + str(pageID) + '].b[' + str(componentID)+']'+'.val'
ser.write((send+EndCom).encode('latin-1'))
value=ser.read_until(EndCom)
try:
if hex(value[0]) == '0x71':
value = value[1]+value[2]*256+value[3]*65536+value[4]*16777216 # little endian
return value # as float
except:
pass

def nx_setText(ser, pageID, componentID, text): # writes the text in the text component atribute .txt
text = 'p[' + str(pageID) + '].b[' + str(componentID)+']''.txt="' + text + '"'
ser.write((text+EndCom).encode('latin-1'))
return None

def nx_setValue(ser, pageID, componentID, value): # writes the value in the number component atribute .val
value_str = 'p[' + str(pageID) + '].b[' + str(componentID)+']''.val=' + str(value) # test here the "'"
ser.write((value_str+EndCom).encode('latin-1'))
return None


####### examples of usage (uncommrnt the top part)

#nx_setsys(ser, 'bauds', BAUD) # set default baud

#nx_setsys(ser, 'dim',80) # sets backlight of device 1 to 100
#nx_setsys(ser, 'bkcmd',0) # avoids receiving bytes used in debugging

#nx_setcmd_1par(ser, 'page','initial') # go to page named 'initial'
#nx_setcmd_0par(ser, 'rest') # reboot the device

#nx_getValue(ser, 2,3)
#nx_setText(ser, 2,3,'3000')
#uncoment lines below to use the examples in the bottom of file

import serial
BAUD =38400 # for new monitor please put 9600 and then run nx_setsys(ser, 'bauds', newBAUD)
ser = serial.Serial(
port='/dev/ttyAMA0',
baudrate = BAUD,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
bytesize=serial.EIGHTBITS,
timeout=0.15)

ser.reset_output_buffer()

EndCom = "\xff\xff\xff"

def nx_setsys(ser, sysvar,value): # Set system variables. sysvar as text. example: sysvar='dim'
#Possible commands: 'bkcmd', 'dp', 'dim', 'dims', 'baud', 'bauds','ussp', 'thsp', 'thup', 'delay', 'sleep'
# see instruction set of NEXTION device to see possible values for each system variable
set = sysvar + '=' + str(value)
ser.write((set+EndCom).encode('latin-1'))
return None

def nx_setcmd_0par(ser, command): #Set operational Commands without parameters
# Possible commands: 'ref_stop', 'ref_star', 'touch_j' (calibrate), 'com_stop', 'com_start', 'code_c','rest', 'doevents'
# see instruction set of NEXTION device to know the possible commands and what they do
ser.write((command+EndCom).encode('latin-1'))
return None

def nx_setcmd_1par(ser, command, value): #Set operational Commands with 1 parameters
# Possible commands: 'page', 'ref'
# see instruction set of NEXTION device to know the possible commands and what they do
if value is str:
set=command +' '+ value # example 'page initial'
else:
set=command +' '+str(value) #example 'page 1'
ser.write((set+EndCom).encode('latin-1'))
return None

def nx_setcmd_2par(ser, command, value1, value2=1): #Set operational Commands with 2 parameters
# Possible commands: 'click', 'vis', 'tsw'
# value2 can only be 0 or 1
# see instruction set of NEXTION device to know the possible commands and what they do
if value1 is str:
set=command + ' ' + str(value1) + ',' + str(value2) #example 'vis t0,1 show componente t0'
else:
set = command + ' ' + str(value1) + ',' + str(value2) # vis 2,0 hide componentID 2 in current page'
ser.write((set+EndCom).encode('latin-1'))
return None

def nx_page(ser): # reads number of current page show in display
ser.write(('sendme ' + EndCom).encode('latin-1'))
page=ser.read_until(EndCom)
page=str(page)
page=page.lstrip("b\\'f\\x")
page=page.rstrip("\\xff\\xff\\xff\\'")
page = int(page, 16)
return page

def nx_getText(ser, pageID, componentID): # Returns the .txt from a component in a page as text
send = 'get ' + 'p[' + str(pageID) + '].b[' + str(componentID)+']''.txt'
ser.write((send+EndCom).encode('latin-1'))
text=ser.read_until(EndCom)
text = str(text)
text = text[3:]
#text = text.lstrip("b\\'p")
#text = text.rstrip("\\xff\\xff\\xff\\'")
text = text[:-13]
return text # as string"

def nx_getValue(ser, pageID, componentID): # Returns the .val from a component in a page as text
send = 'get ' + 'p[' + str(pageID) + '].b[' + str(componentID)+']'+'.val'
ser.write((send+EndCom).encode('latin-1'))
value=ser.read_until(EndCom)
try:
if hex(value[0]) == '0x71':
value = value[1]+value[2]*256+value[3]*65536+value[4]*16777216 # little endian
return value # as float
except:
pass

def nx_setText(ser, pageID, componentID, text): # writes the text in the text component atribute .txt
text = 'p[' + str(pageID) + '].b[' + str(componentID)+']''.txt="' + text + '"'
ser.write((text+EndCom).encode('latin-1'))
return None

def nx_setValue(ser, pageID, componentID, value): # writes the value in the number component atribute .val
value_str = 'p[' + str(pageID) + '].b[' + str(componentID)+']''.val=' + str(value) # test here the "'"
ser.write((value_str+EndCom).encode('latin-1'))
return None


####### examples of usage (uncommrnt the top part)

#nx_setsys(ser, 'bauds', BAUD) # set default baud

#nx_setsys(ser, 'dim',80) # sets backlight of device 1 to 100
#nx_setsys(ser, 'bkcmd',0) # avoids receiving bytes used in debugging

#nx_setcmd_1par(ser, 'page','initial') # go to page named 'initial'
#nx_setcmd_0par(ser, 'rest') # reboot the device

#nx_getValue(ser, 2,3)
#nx_setText(ser, 2,3,'3000')
#nx_setValue(ser, pageID=4,componentID=3,80)

0 comments on commit 638c5c9

Please sign in to comment.