Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
G
gopro
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tony Mai
gopro
Commits
e067c977
Commit
e067c977
authored
Aug 05, 2019
by
Tony Mai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
afa27fda
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
281 additions
and
185 deletions
+281
-185
gui.py
python/gui.py
+239
-159
wireless_copy_files_to_nfs.py
python/wireless_copy_files_to_nfs.py
+42
-26
No files found.
python/gui.py
View file @
e067c977
...
...
@@ -12,6 +12,7 @@ import pygame, time, evdev, select, math
import
subprocess
import
os
import
netifaces
import
multiprocessing
#Colours
WHITE
=
(
255
,
255
,
255
)
...
...
@@ -20,6 +21,16 @@ RED = (255,0,0)
GREEN
=
(
0
,
255
,
0
)
BLUE
=
(
0
,
0
,
255
)
#interface status
eth0_ok
=
0
wlan0_ok
=
0
wlan1_ok
=
0
wlan2_ok
=
0
mouse
=
[
0
,
0
]
def
write_log
(
str
):
global
log
...
...
@@ -48,7 +59,8 @@ def getPixelsFromCoordinates(coords):
y
=
float
(
tftAbsDelta
[
1
]
-
coords
[
1
]
+
tftEnd
[
1
])
/
float
(
tftAbsDelta
[
1
])
*
float
(
surfaceSize
[
1
])
else
:
y
=
float
(
coords
[
1
]
-
tftOrig
[
1
])
/
float
(
tftAbsDelta
[
1
])
*
float
(
surfaceSize
[
1
])
return
(
int
(
x
),
int
(
y
))
#return (int(x), int(y))
return
[
int
(
x
),
int
(
y
)]
# Was useful to see what pieces I would need from the evdev events
def
printEvent
(
event
):
...
...
@@ -74,7 +86,8 @@ def refresh():
#time.sleep(0.1)
def
button
(
lcd
,
msg
,
x
,
y
,
w
,
h
,
ic
,
ac
,
mouse
,
action
=
None
,
next_layout
=
None
):
def
button
(
lcd
,
msg
,
x
,
y
,
w
,
h
,
ic
,
ac
,
mouse
,
enable
,
action
=
None
,
next_layout
=
None
):
if
enable
:
if
x
+
w
>
mouse
[
0
]
>
x
and
y
+
h
>
mouse
[
1
]
>
y
:
pygame
.
draw
.
rect
(
lcd
,
ic
,(
x
,
y
,
w
,
h
))
text
=
pygame
.
font
.
SysFont
(
"comicsansms"
,
25
)
...
...
@@ -101,23 +114,32 @@ def button(lcd,msg,x,y,w,h,ic,ac,mouse,action=None,next_layout=None):
textRect
.
center
=
(
(
x
+
(
w
/
2
)),
(
y
+
(
h
/
2
))
)
lcd
.
blit
(
textSurf
,
textRect
)
return
1
else
:
pygame
.
draw
.
rect
(
lcd
,
BLACK
,(
x
,
y
,
w
,
h
))
refresh
()
return
1
def
main_layout
(
lcd
,
mouse
):
button
(
lcd
,
"Copy Fusion to BACKUP"
,
5
,
45
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
wireless_copy_files_to_backup
.
run
,
log_layout
)
and
\
button
(
lcd
,
"Copy Fusion to NFS"
,
5
,
100
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
wireless_copy_files_to_nfs
.
run
,
log_layout
)
and
\
button
(
lcd
,
"Network Info."
,
5
,
155
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
show_network_info
,
log_layout
)
and
\
button
(
lcd
,
"Shutdown..."
,
5
,
210
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
None
,
dialog_shutdown_layout
)
and
\
button
(
lcd
,
"Reboot..."
,
240
,
210
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
None
,
dialog_reboot_layout
)
global
eth0_ok
global
wlan0_ok
global
wlan1_ok
global
wlan2_ok
button
(
lcd
,
"Copy Fusion to BACKUP"
,
5
,
45
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
wlan1_ok
,
wireless_copy_files_to_backup
.
run
,
log_layout
)
and
\
button
(
lcd
,
"Copy Fusion to NFS"
,
5
,
100
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
wlan1_ok
and
(
wlan2_ok
or
eth0_ok
),
wireless_copy_files_to_nfs
.
run
,
log_layout
)
and
\
button
(
lcd
,
"Network Info."
,
5
,
155
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
show_network_info
,
log_layout
)
and
\
button
(
lcd
,
"Shutdown..."
,
5
,
210
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
None
,
dialog_shutdown_layout
)
and
\
button
(
lcd
,
"Reboot..."
,
240
,
210
,
230
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
None
,
dialog_reboot_layout
)
def
dialog_shutdown_layout
(
lcd
,
mouse
):
lcd
.
blit
(
defaultFont
.
render
(
"Shutdown?"
,
False
,
WHITE
),(
190
,
70
))
button
(
lcd
,
"Yes"
,
65
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
shutdown
,
main_layout
)
and
\
button
(
lcd
,
"No"
,
265
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
None
,
main_layout
)
button
(
lcd
,
"Yes"
,
65
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
shutdown
,
main_layout
)
and
\
button
(
lcd
,
"No"
,
265
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
None
,
main_layout
)
def
dialog_reboot_layout
(
lcd
,
mouse
):
lcd
.
blit
(
defaultFont
.
render
(
"Reboot?"
,
False
,
WHITE
),(
190
,
70
))
button
(
lcd
,
"Yes"
,
65
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
reboot
,
main_layout
)
and
\
button
(
lcd
,
"No"
,
265
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
None
,
main_layout
)
button
(
lcd
,
"Yes"
,
65
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
reboot
,
main_layout
)
and
\
button
(
lcd
,
"No"
,
265
,
145
,
140
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
None
,
main_layout
)
def
scroll_up
():
for
i
in
range
(
0
,
surfaceSize
[
1
],
1
):
...
...
@@ -139,11 +161,66 @@ def shutdown():
def
show_network_info
():
reset_log_buffer
()
write_log
(
"SSID: WAPPI"
)
write_log
(
netifaces
.
ifaddresses
(
'wlan0'
)[
netifaces
.
AF_INET
][
0
][
'addr'
])
try
:
write_log
(
"eth0 (NIC) : "
+
netifaces
.
ifaddresses
(
'eth0'
)[
netifaces
.
AF_INET
][
0
][
'addr'
])
except
:
write_log
(
"eth0 (NIC) : No IP Address"
)
try
:
write_log
(
"wlan0 (internal wireless): "
+
netifaces
.
ifaddresses
(
'wlan0'
)[
netifaces
.
AF_INET
][
0
][
'addr'
])
except
:
write_log
(
"wlan0 (internal wireless): No IP Address"
)
try
:
write_log
(
"wlan1 (5G USB): "
+
netifaces
.
ifaddresses
(
'wlan1'
)[
netifaces
.
AF_INET
][
0
][
'addr'
])
except
:
write_log
(
"wlan1 (5G USB): No IP Adress"
)
try
:
write_log
(
"wlan2 (TPLINK 3G USB): "
+
netifaces
.
ifaddresses
(
'wlan2'
)[
netifaces
.
AF_INET
][
0
][
'addr'
])
except
:
write_log
(
"wlan2 (TPLINK 3G USB): No IP Address"
)
def
get_status
():
global
eth0_ok
global
wlan0_ok
global
wlan1_ok
global
wlan2_ok
try
:
netifaces
.
ifaddresses
(
'eth0'
)[
netifaces
.
AF_INET
][
0
][
'addr'
]
eth0_ok
=
1
except
:
eth0_ok
=
0
try
:
netifaces
.
ifaddresses
(
'wlan0'
)[
netifaces
.
AF_INET
][
0
][
'addr'
]
wlan0_ok
=
1
except
:
wlan0_ok
=
0
wlan1_ok
=
not
os
.
system
(
"nc -z -n -w 1 10.5.5.9 80"
)
#print(aa)
#try:
# netifaces.ifaddresses('wlan1')[netifaces.AF_INET][0]['addr']
# wlan1_ok=1
#except:
# wlan1_ok=0
try
:
netifaces
.
ifaddresses
(
'wlan2'
)[
netifaces
.
AF_INET
][
0
][
'addr'
]
wlan2_ok
=
1
except
:
wlan2_ok
=
0
def
log_layout
(
lcd
,
mouse
):
lcd
.
blit
(
defaultFont
.
render
(
"Log:"
,
False
,
WHITE
),(
0
,
0
))
button
(
lcd
,
"Done"
,
340
,
0
,
100
,
50
,
WHITE
,
BLACK
,
mouse
,
None
,
main_layout
)
button
(
lcd
,
"Done"
,
340
,
0
,
100
,
50
,
WHITE
,
BLACK
,
mouse
,
1
,
None
,
main_layout
)
...
...
@@ -169,130 +246,133 @@ def reset_log_buffer():
log
=
[
""
]
*
LOGSIZE
#------------------------------------------------------------------------------------------------------------------------
import
signal
def
handler
(
signum
,
frame
):
pass
try
:
signal
.
signal
(
signal
.
SIGHUP
,
handler
)
except
AttributeError
:
# Windows compatibility
pass
LOGSIZE
=
25
log
=
[
""
]
*
LOGSIZE
def
service_touchscreen
(
coor
):
X
=
0
Y
=
0
while
True
:
# TODO get the right ecodes instead of int
r
,
w
,
x
=
select
.
select
([
touch
],
[],
[])
import
wireless_copy_files_to_backup
import
wireless_copy_files_to_nfs
for
event
in
touch
.
read
():
#printEvent(event)
if
event
.
type
==
evdev
.
ecodes
.
EV_ABS
:
if
event
.
code
==
1
:
X
=
event
.
value
elif
event
.
code
==
0
:
Y
=
event
.
value
elif
event
.
code
==
24
:
P
=
event
.
value
#elif event.type == evdev.ecodes.EV_KEY:
if
event
.
type
==
evdev
.
ecodes
.
EV_KEY
:
if
event
.
code
==
330
and
event
.
value
==
0
:
p
=
getPixelsFromCoordinates
((
X
,
Y
))
coor
.
put_nowait
([
p
[
0
],
p
[
1
]])
#oy=p[1]
#print ("service" + str(ox) +" "+ str(oy))
#w_pipe.write(str(p[0]) +" "+ str(p[1]))
#w_pipe.flush()
# Very important: the exact pixel size of the TFT screen must be known so we can build graphics at this exact format
surfaceSize
=
(
480
,
320
)
#so you can run this systemD
import
signal
def
handler
(
signum
,
frame
):
pass
# Note that we don't instantiate any display!
pygame
.
init
()
#------------------------------------------------------------------------------------------------------------------------
lcd
=
pygame
.
Surface
(
surfaceSize
)
if
__name__
==
"__main__"
:
try
:
signal
.
signal
(
signal
.
SIGHUP
,
handler
)
except
AttributeError
:
# Windows compatibility
pass
# Now we've got a function that can get the bytes from a pygame surface to the TFT framebuffer,
# we can use the usual pygame primitives to draw on our surface before calling the refresh function.
pygame
.
font
.
init
()
defaultFont
=
pygame
.
font
.
SysFont
(
None
,
20
)
# Used to map touch event from the screen hardware to the pygame surface pixels.
# (Those values have been found empirically, use evtest to get numbers
#tftOrig = (3750, 0)
tftOrig
=
(
3901
,
295
)
#tftEnd = (150, 3750)
tftEnd
=
(
246
,
3775
)
tftDelta
=
(
tftEnd
[
0
]
-
tftOrig
[
0
],
tftEnd
[
1
]
-
tftOrig
[
1
])
tftAbsDelta
=
(
abs
(
tftEnd
[
0
]
-
tftOrig
[
0
]),
abs
(
tftEnd
[
1
]
-
tftOrig
[
1
]))
LOGSIZE
=
25
log
=
[
""
]
*
LOGSIZE
import
wireless_copy_files_to_backup
import
wireless_copy_files_to_nfs
lcd
.
fill
(
BLACK
)
#lcd.blit(defaultFont.render("Log:", False, WHITE),(244, 0))
#pygame.draw.line(lcd,WHITE,(240,0),(240,480),1)
# Very important: the exact pixel size of the TFT screen must be known so we can build graphics at this exact format
surfaceSize
=
(
480
,
320
)
# Note that we don't instantiate any display!
pygame
.
init
()
lcd
.
blit
(
defaultFont
.
render
(
"Log:"
,
False
,
WHITE
),(
244
,
420
)
)
lcd
=
pygame
.
Surface
(
surfaceSize
)
font_big
=
pygame
.
font
.
Font
(
None
,
50
)
refresh
()
# Now we've got a function that can get the bytes from a pygame surface to the TFT framebuffer,
# we can use the usual pygame primitives to draw on our surface before calling the refresh function.
# We use evdev to read events from our touchscreen
# (The device must exist and be properly installed for this to work)
touch
=
evdev
.
InputDevice
(
'/dev/input/event0'
)
pygame
.
font
.
init
()
defaultFont
=
pygame
.
font
.
SysFont
(
None
,
20
)
# We make sure the events from the touchscreen will be handled only by this program
# (so the mouse pointer won't move on X when we touch the TFT screen)
touch
.
grab
()
# Prints some info on how evdev sees our input device
print
(
touch
)
# Even more info for curious people
# print(touch.capabilities())
# Used to map touch event from the screen hardware to the pygame surface pixels.
# (Those values have been found empirically, use evtest to get numbers
#tftOrig = (3750, 0)
tftOrig
=
(
3901
,
295
)
#tftEnd = (150, 3750)
tftEnd
=
(
246
,
3775
)
tftDelta
=
(
tftEnd
[
0
]
-
tftOrig
[
0
],
tftEnd
[
1
]
-
tftOrig
[
1
])
tftAbsDelta
=
(
abs
(
tftEnd
[
0
]
-
tftOrig
[
0
]),
abs
(
tftEnd
[
1
]
-
tftOrig
[
1
]))
layout
=
main_layout
layout
(
lcd
,(
0
,
0
))
lcd
.
fill
(
BLACK
)
font_big
=
pygame
.
font
.
Font
(
None
,
50
)
refresh
()
wireless_copy_files_to_backup
.
set_log_method
(
write_log
)
wireless_copy_files_to_nfs
.
set_log_method
(
write_log
)
refresh
(
)
# We use evdev to read events from our touchscreen
# (The device must exist and be properly installed for this to work
)
touch
=
evdev
.
InputDevice
(
'/dev/input/event0'
)
# We make sure the events from the touchscreen will be handled only by this program
# (so the mouse pointer won't move on X when we touch the TFT screen)
touch
.
grab
()
# Prints some info on how evdev sees our input device
print
(
touch
)
# Even more info for curious people
# print(touch.capabilities())
X
=
0
Y
=
0
get_status
()
layout
=
main_layout
layout
(
lcd
,(
0
,
0
))
#newpid=os.fork()
# This loop allows us to write red dots on the screen where we touch it
while
True
:
#if newpid==0:
# aa=read_log(file_ptr)
# if aa != "":
# print (aa)
#
#
# else:
# TODO get the right ecodes instead of int
r
,
w
,
x
=
select
.
select
([
touch
],
[],
[])
wireless_copy_files_to_backup
.
set_log_method
(
write_log
)
wireless_copy_files_to_nfs
.
set_log_method
(
write_log
)
refresh
()
#write_log(str(X))
#run service_touchscreen in a queue process
coor
=
multiprocessing
.
Queue
()
p
=
multiprocessing
.
Process
(
target
=
service_touchscreen
,
args
=
(
coor
,))
for
event
in
touch
.
read
():
#printEvent(event)
if
event
.
type
==
evdev
.
ecodes
.
EV_ABS
:
if
event
.
code
==
1
:
X
=
event
.
value
elif
event
.
code
==
0
:
Y
=
event
.
value
elif
event
.
code
==
24
:
P
=
event
.
value
p
.
start
()
#elif event.type == evdev.ecodes.EV_KEY:
if
event
.
type
==
evdev
.
ecodes
.
EV_KEY
:
if
event
.
code
==
330
and
event
.
value
==
0
:
p
=
getPixelsFromCoordinates
((
X
,
Y
))
layout
(
lcd
,
p
)
#print("TFT: {0}:{1} | Pixels: {2}:{3}".format(X, Y, p [0], p [1]))
#pygame.draw.circle(lcd, RED, p , 2, 2)
while
True
:
#print (coor[:])
if
(
coor
.
empty
()):
get_status
()
#print ("wlan1 "+str(wlan1_ok))
layout
(
lcd
,
mouse
)
refresh
()
else
:
mouse
=
coor
.
get
()
layout
(
lcd
,
mouse
)
refresh
()
exit
()
p
.
join
()
exit
()
python/wireless_copy_files_to_nfs.py
View file @
e067c977
...
...
@@ -87,6 +87,9 @@ def run(folder_dst=None,ptr=None):
#msg("Restart wlan1...")
#os.system("systemctl daemon-reload")
#os.system("systemctl restart dhcpcd")
msg
(
"Checking wlan1..."
)
try
:
...
...
@@ -97,6 +100,16 @@ def run(folder_dst=None,ptr=None):
gpCam
=
GoProCamera
.
GoPro
()
try
:
gpCam
.
pair
(
usepin
=
False
)
#gpCam.pair(usepin=True)
except
:
msg
(
"Cannot Pair to Gopro. Exit..."
)
return
#if ping(gpCam.ip_addr):
# msg ("Ping gopro ("+gpCam.ip_addr+") failed. Exit...")
# return
...
...
@@ -104,9 +117,6 @@ def run(folder_dst=None,ptr=None):
# msg ("Ping gopro ok.")
gpCam
.
pair
(
usepin
=
False
)
#gpCam.pair(usepin=True)
os
.
system
(
"mkdir "
+
folder_dst
)
...
...
@@ -121,12 +131,17 @@ def run(folder_dst=None,ptr=None):
start_time
=
time
.
time
()
msg
(
"Start time :"
+
str
(
localtime
))
camera_info
(
gpCam
)
data
=
gpCam
.
listMedia
(
True
,
True
)
for
i
in
range
(
len
(
data
)):
msg
(
str
(
data
[
i
]))
#data=gpCam.listMedia(True,True)
try
:
for
i
in
data
:
folder
=
i
[
0
]
if
not
os
.
path
.
exists
(
folder_dst
+
"/"
+
folder
):
...
...
@@ -150,7 +165,8 @@ def run(folder_dst=None,ptr=None):
thm_file
=
re
.
sub
(
".MP4"
,
".THM"
,
mp4_file
)
#msg("copy "+folder+"/"+thm_file+" to "+folder_dst);
gpCam
.
downloadMedia
(
folder
,
thm_file
,
folder_dst
+
"/"
+
folder
+
"/"
+
thm_file
)
except
:
msg
(
"Fail copy to "
+
folder_dst
);
msg
(
"Done"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment