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
afa27fda
Commit
afa27fda
authored
Aug 03, 2019
by
Tony Mai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
f199c2ea
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
89 additions
and
57 deletions
+89
-57
gui.py
python/gui.py
+46
-27
wireless_copy_files_to_nfs.py
python/wireless_copy_files_to_nfs.py
+43
-30
No files found.
python/gui.py
View file @
afa27fda
...
...
@@ -13,6 +13,13 @@ import subprocess
import
os
import
netifaces
#Colours
WHITE
=
(
255
,
255
,
255
)
BLACK
=
(
0
,
0
,
0
)
RED
=
(
255
,
0
,
0
)
GREEN
=
(
0
,
255
,
0
)
BLUE
=
(
0
,
0
,
255
)
def
write_log
(
str
):
global
log
...
...
@@ -26,6 +33,7 @@ def write_log(str):
refresh
()
time
.
sleep
(
0.1
)
...
...
@@ -49,8 +57,8 @@ def printEvent(event):
print
(
"Type: {0}"
.
format
(
event
.
type
))
print
(
"Code: {0}"
.
format
(
event
.
code
))
def
text_objects
(
text
,
font
):
textSurface
=
font
.
render
(
text
,
True
,
WHITE
)
def
text_objects
(
text
,
font
,
color
=
WHITE
):
textSurface
=
font
.
render
(
text
,
True
,
color
)
return
textSurface
,
textSurface
.
get_rect
()
# This is the important bit
...
...
@@ -63,17 +71,23 @@ def refresh():
f
.
write
(
lcd
.
convert
(
16
,
0
)
.
get_buffer
())
# We can then close our access to the framebuffer
f
.
close
()
time
.
sleep
(
0.1
)
#
time.sleep(0.1)
def
button
(
lcd
,
msg
,
x
,
y
,
w
,
h
,
ic
,
ac
,
mouse
,
action
=
None
,
next_layout
=
None
):
if
x
+
w
>
mouse
[
0
]
>
x
and
y
+
h
>
mouse
[
1
]
>
y
:
pygame
.
draw
.
rect
(
lcd
,
ac
,(
x
,
y
,
w
,
h
))
pygame
.
draw
.
rect
(
lcd
,
ic
,(
x
,
y
,
w
,
h
))
text
=
pygame
.
font
.
SysFont
(
"comicsansms"
,
25
)
textSurf
,
textRect
=
text_objects
(
msg
,
text
,
ac
)
textRect
.
center
=
(
(
x
+
(
w
/
2
)),
(
y
+
(
h
/
2
))
)
lcd
.
blit
(
textSurf
,
textRect
)
refresh
()
time
.
sleep
(
0.1
)
#scroll_up()
lcd
.
fill
(
BLACK
)
refresh
()
if
action
!=
None
:
print
(
"clicked "
+
msg
)
action
()
global
layout
layout
=
next_layout
...
...
@@ -82,29 +96,37 @@ def button(lcd,msg,x,y,w,h,ic,ac,mouse,action=None,next_layout=None):
return
0
else
:
pygame
.
draw
.
rect
(
lcd
,
ic
,(
x
,
y
,
w
,
h
),
1
)
text
=
pygame
.
font
.
SysFont
(
"comicsansms"
,
25
)
textSurf
,
textRect
=
text_objects
(
msg
,
text
)
textSurf
,
textRect
=
text_objects
(
msg
,
text
,
ic
)
textRect
.
center
=
(
(
x
+
(
w
/
2
)),
(
y
+
(
h
/
2
))
)
lcd
.
blit
(
textSurf
,
textRect
)
return
1
def
main_layout
(
lcd
,
mouse
):
button
(
lcd
,
"Copy Fusion to BACKUP"
,
5
,
45
,
230
,
50
,
WHITE
,
WHITE
,
mouse
,
wireless_copy_files_to_backup
.
run
,
log_layout
)
and
\
button
(
lcd
,
"Copy Fusion to NFS"
,
5
,
100
,
230
,
50
,
WHITE
,
WHITE
,
mouse
,
wireless_copy_files_to_nfs
.
run
,
log_layout
)
and
\
button
(
lcd
,
"Network Info."
,
5
,
155
,
230
,
50
,
WHITE
,
WHITE
,
mouse
,
show_network_info
,
log_layout
)
and
\
button
(
lcd
,
"Shutdown..."
,
5
,
210
,
230
,
50
,
WHITE
,
WHITE
,
mouse
,
None
,
dialog_shutdown_layout
)
and
\
button
(
lcd
,
"Reboot..."
,
240
,
210
,
230
,
50
,
WHITE
,
WHITE
,
mouse
,
None
,
dialog_reboot_layout
)
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
)
def
dialog_shutdown_layout
(
lcd
,
mouse
):
lcd
.
blit
(
defaultFont
.
render
(
"Shutdown?"
,
False
,
WHITE
),(
190
,
70
))
button
(
lcd
,
"Yes"
,
65
,
145
,
140
,
50
,
WHITE
,
WHITE
,
mouse
,
shutdown
,
main_layout
)
and
\
button
(
lcd
,
"No"
,
265
,
145
,
140
,
50
,
WHITE
,
WHITE
,
mouse
,
None
,
main_layout
)
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
)
def
dialog_reboot_layout
(
lcd
,
mouse
):
lcd
.
blit
(
defaultFont
.
render
(
"Reboot?"
,
False
,
WHITE
),(
190
,
70
))
button
(
lcd
,
"Yes"
,
65
,
145
,
140
,
50
,
WHITE
,
WHITE
,
mouse
,
reboot
,
main_layout
)
and
\
button
(
lcd
,
"No"
,
265
,
145
,
140
,
50
,
WHITE
,
WHITE
,
mouse
,
None
,
main_layout
)
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
)
def
scroll_up
():
for
i
in
range
(
0
,
surfaceSize
[
1
],
1
):
pygame
.
draw
.
rect
(
lcd
,
BLACK
,(
0
,
surfaceSize
[
1
]
-
i
,
surfaceSize
[
0
],
i
))
refresh
()
lcd
.
fill
(
BLACK
)
refresh
()
def
reboot
():
os
.
system
(
'shutdown -r'
)
...
...
@@ -115,12 +137,13 @@ def shutdown():
exit
()
def
show_network_info
():
reset_log_buffer
()
write_log
(
"SSID: WAPPI"
)
write_log
(
netifaces
.
ifaddresses
(
'wlan0'
)[
netifaces
.
AF_INET
][
0
][
'addr'
])
def
log_layout
(
lcd
,
mouse
):
lcd
.
blit
(
defaultFont
.
render
(
"Log:"
,
False
,
WHITE
),(
0
,
0
))
button
(
lcd
,
"Done"
,
340
,
0
,
100
,
50
,
WHITE
,
WHITE
,
mouse
,
None
,
main_layout
)
button
(
lcd
,
"Done"
,
340
,
0
,
100
,
50
,
WHITE
,
BLACK
,
mouse
,
None
,
main_layout
)
...
...
@@ -141,6 +164,10 @@ def read_log(file_ptr):
return
file_ptr
.
readline
()
def
reset_log_buffer
():
global
log
log
=
[
""
]
*
LOGSIZE
#------------------------------------------------------------------------------------------------------------------------
...
...
@@ -160,13 +187,12 @@ LOGSIZE=25
log
=
[
""
]
*
LOGSIZE
import
wireless_copy_files_to_backup
import
wireless_copy_files_to_nfs
# 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
)
...
...
@@ -193,13 +219,6 @@ tftAbsDelta = (abs(tftEnd [0] - tftOrig [0]), abs(tftEnd [1] - tftOrig [1]))
#Colours
WHITE
=
(
255
,
255
,
255
)
BLACK
=
(
0
,
0
,
0
)
RED
=
(
255
,
0
,
0
)
GREEN
=
(
0
,
255
,
0
)
BLUE
=
(
0
,
0
,
255
)
lcd
.
fill
(
BLACK
)
...
...
python/wireless_copy_files_to_nfs.py
View file @
afa27fda
...
...
@@ -8,9 +8,10 @@ import os
import
sys
import
re
import
time
import
netifaces
NFSPATH
=
"/nfs/ANGELICA/
videos/
"
NFSPATH
=
"/nfs/ANGELICA/
camera
"
method_ptr
=
None
...
...
@@ -46,6 +47,11 @@ def camera_info(cam_ptr):
msg
(
"firmware version: "
+
""
+
cam_ptr
.
infoCamera
(
constants
.
Camera
.
Firmware
))
msg
(
"serial number: "
+
""
+
cam_ptr
.
infoCamera
(
constants
.
Camera
.
SerialNumber
))
def
ping
(
hostname
):
#returns 0 if hostame is up
return
os
.
system
(
"ping -c 1 "
+
hostname
)
def
run
(
folder_dst
=
None
,
ptr
=
None
):
...
...
@@ -53,18 +59,17 @@ def run(folder_dst=None,ptr=None):
if
(
ptr
):
log_ptr
=
ptr
os
.
system
(
"umount
/nfs/ANGELICA/videos"
)
if
os
.
system
(
"mount 192.168.0.2:/mnt/user/
videos /nfs/ANGELICA/videos"
)
!=
0
:
msg
(
"fail to mount 192.168.0.2:/mnt/user/
videos
... exiting.."
)
os
.
system
(
"umount
"
+
NFSPATH
)
if
os
.
system
(
"mount 192.168.0.2:/mnt/user/
camera "
+
NFSPATH
)
!=
0
:
msg
(
"fail to mount 192.168.0.2:/mnt/user/
camera
... exiting.."
)
return
msg
(
"192.168.0.2:/mnt/user/
videos
mounted..."
)
msg
(
"192.168.0.2:/mnt/user/
camera
mounted..."
)
if
folder_dst
==
None
:
msg
(
"Generating generic folder..."
)
for
i
in
range
(
0
,
1000
):
folder_dst
=
NFSPATH
+
"/CP_"
+
str
(
i
)
#if not(os.path.isdir(BACKUPPATH+"/CP_"+str(i))) or not(os.path.exists(BACKUPPATH+"/CP_"+str(i))):
folder_dst
=
NFSPATH
+
"/fusion/CP_"
+
str
(
i
)
if
not
(
os
.
path
.
isdir
(
folder_dst
))
or
not
(
os
.
path
.
exists
(
folder_dst
)):
break
if
i
==
1000
:
...
...
@@ -83,11 +88,6 @@ def run(folder_dst=None,ptr=None):
os
.
system
(
"mkdir "
+
folder_dst
)
msg
(
"mkdir "
+
folder_dst
)
msg
(
"Checking wlan1..."
)
try
:
print
(
netifaces
.
ifaddresses
(
'wlan1'
)[
netifaces
.
AF_INET
][
0
][
'addr'
])
...
...
@@ -95,18 +95,31 @@ def run(folder_dst=None,ptr=None):
msg
(
"wlan1 not connected to Gopro SSID. exiting..."
)
return
gpCam
=
GoProCamera
.
GoPro
()
#if ping(gpCam.ip_addr):
# msg ("Ping gopro ("+gpCam.ip_addr+") failed. Exit...")
# return
#else:
# msg ("Ping gopro ok.")
gpCam
=
GoProCamera
.
GoPro
()
gpCam
.
pair
(
usepin
=
False
)
#gpCam.pair(usepin=True)
print
(
"Start..."
)
os
.
system
(
"mkdir "
+
folder_dst
)
msg
(
"mkdir "
+
folder_dst
)
msg
(
"Start..."
)
localtime
=
time
.
asctime
(
time
.
localtime
(
time
.
time
())
)
start_time
=
time
.
time
()
print
(
"Start time :"
,
localtime
)
msg
(
"Start time :"
+
str
(
localtime
)
)
camera_info
(
gpCam
)
data
=
gpCam
.
listMedia
(
True
,
True
)
for
i
in
range
(
len
(
data
)):
...
...
@@ -116,27 +129,27 @@ def run(folder_dst=None,ptr=None):
for
i
in
data
:
folder
=
i
[
0
]
if
not
os
.
path
.
exists
(
f
ile_path
+
"/"
+
folder
):
os
.
makedirs
(
f
ile_path
+
"/"
+
folder
);
if
not
os
.
path
.
exists
(
f
older_dst
+
"/"
+
folder
):
os
.
makedirs
(
f
older_dst
+
"/"
+
folder
);
mp4_file
=
i
[
1
]
lrv_file
=
re
.
sub
(
".MP4"
,
".LRV"
,
mp4_file
)
msg
(
"copy "
+
folder
+
"/"
+
mp4_file
+
" to "
+
f
ile_path
);
gpCam
.
downloadMedia
(
folder
,
mp4_file
,
f
ile_path
+
"/"
+
folder
+
"/"
+
mp4_file
)
msg
(
"copy "
+
folder
+
"/"
+
lrv_file
+
" to "
+
f
ile_path
);
gpCam
.
downloadMedia
(
folder
,
lrv_file
,
f
ile_path
+
"/"
+
folder
+
"/"
+
lrv_file
)
msg
(
"copy "
+
folder
+
"/"
+
mp4_file
+
" to "
+
f
older_dst
);
gpCam
.
downloadMedia
(
folder
,
mp4_file
,
f
older_dst
+
"/"
+
folder
+
"/"
+
mp4_file
)
msg
(
"copy "
+
folder
+
"/"
+
lrv_file
+
" to "
+
f
older_dst
);
gpCam
.
downloadMedia
(
folder
,
lrv_file
,
f
older_dst
+
"/"
+
folder
+
"/"
+
lrv_file
)
if
re
.
search
(
"GPBK"
,
mp4_file
)
or
re
.
search
(
"GB"
,
mp4_file
):
wav_file
=
re
.
sub
(
".MP4"
,
".WAV"
,
mp4_file
)
#msg("copy "+folder+"/"+wav_file+" to "+f
ile_path
);
gpCam
.
downloadMedia
(
folder
,
wav_file
,
f
ile_path
+
"/"
+
folder
+
"/"
+
wav_file
)
#msg("copy "+folder+"/"+wav_file+" to "+f
older_dst
);
gpCam
.
downloadMedia
(
folder
,
wav_file
,
f
older_dst
+
"/"
+
folder
+
"/"
+
wav_file
)
if
re
.
search
(
"GPBK"
,
mp4_file
):
thm_file
=
re
.
sub
(
".MP4"
,
".THM"
,
mp4_file
)
#msg("copy "+folder+"/"+thm_file+" to "+f
ile_path
);
gpCam
.
downloadMedia
(
folder
,
thm_file
,
f
ile_path
+
"/"
+
folder
+
"/"
+
thm_file
)
#msg("copy "+folder+"/"+thm_file+" to "+f
older_dst
);
gpCam
.
downloadMedia
(
folder
,
thm_file
,
f
older_dst
+
"/"
+
folder
+
"/"
+
thm_file
)
if
re
.
search
(
"GPFR"
,
mp4_file
):
thm_file
=
re
.
sub
(
".MP4"
,
".THM"
,
mp4_file
)
#msg("copy "+folder+"/"+thm_file+" to "+f
ile_path
);
gpCam
.
downloadMedia
(
folder
,
thm_file
,
f
ile_path
+
"/"
+
folder
+
"/"
+
thm_file
)
#msg("copy "+folder+"/"+thm_file+" to "+f
older_dst
);
gpCam
.
downloadMedia
(
folder
,
thm_file
,
f
older_dst
+
"/"
+
folder
+
"/"
+
thm_file
)
...
...
@@ -145,7 +158,7 @@ def run(folder_dst=None,ptr=None):
localtime
=
time
.
asctime
(
time
.
localtime
(
time
.
time
())
)
elapsed_time
=
time
.
time
()
-
start_time
msg
(
"End time :"
,
localtime
)
msg
(
"End time :"
+
str
(
localtime
)
)
hours
,
rem
=
divmod
(
elapsed_time
,
3600
)
minutes
,
seconds
=
divmod
(
rem
,
60
)
...
...
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