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
63206f90
Commit
63206f90
authored
Aug 01, 2019
by
Tony Mai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
741cbd8b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
237 additions
and
0 deletions
+237
-0
gui.py
python/gui.py
+237
-0
No files found.
python/gui.py
0 → 100755
View file @
63206f90
#!/usr/bin/python3
##
# Prerequisites:
# A Touchscreen properly installed on your system:
# - a device to output to it, e.g. /dev/fb1
# - a device to get input from it, e.g. /dev/input/touchscreen
##
import
pygame
,
time
,
evdev
,
select
,
math
import
subprocess
import
os
import
wireless_copy_files_to_backup
BACKUPPATH
=
"/backup"
file_count
=
None
def
get_file_count
():
f
=
open
(
"file_count"
,
"r"
)
global
file_count
file_count
=
f
.
readline
()
return
file_count
# Here we convert the evdev "hardware" touch coordinates into pygame surface pixel coordinates
def
getPixelsFromCoordinates
(
coords
):
# TODO check divide by 0!
if
tftDelta
[
0
]
<
0
:
x
=
float
(
tftAbsDelta
[
0
]
-
coords
[
0
]
+
tftEnd
[
0
])
/
float
(
tftAbsDelta
[
0
])
*
float
(
surfaceSize
[
0
])
else
:
x
=
float
(
coords
[
0
]
-
tftOrig
[
0
])
/
float
(
tftAbsDelta
[
0
])
*
float
(
surfaceSize
[
0
])
if
tftDelta
[
1
]
<
0
:
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
))
# Was useful to see what pieces I would need from the evdev events
def
printEvent
(
event
):
print
(
evdev
.
categorize
(
event
))
print
(
"Value: {0}"
.
format
(
event
.
value
))
print
(
"Type: {0}"
.
format
(
event
.
type
))
print
(
"Code: {0}"
.
format
(
event
.
code
))
def
text_objects
(
text
,
font
):
textSurface
=
font
.
render
(
text
,
True
,
WHITE
)
return
textSurface
,
textSurface
.
get_rect
()
# This is the important bit
def
refresh
():
# We open the TFT screen's framebuffer as a binary file. Note that we will write bytes into it, hence the "wb" operator
f
=
open
(
"/dev/fb0"
,
"wb"
)
# According to the TFT screen specs, it supports only 16bits pixels depth
# Pygame surfaces use 24bits pixels depth by default, but the surface itself provides a very handy method to convert it.
# once converted, we write the full byte buffer of the pygame surface into the TFT screen framebuffer like we would in a plain file:
f
.
write
(
lcd
.
convert
(
16
,
0
)
.
get_buffer
())
# We can then close our access to the framebuffer
f
.
close
()
time
.
sleep
(
0.1
)
def
button
(
lcd
,
msg
,
x
,
y
,
w
,
h
,
ic
,
ac
,
mouse
,
action
=
None
,
action_param
=
None
):
if
x
+
w
>
mouse
[
0
]
>
x
and
y
+
h
>
mouse
[
1
]
>
y
:
pygame
.
draw
.
rect
(
lcd
,
ac
,(
x
,
y
,
w
,
h
))
#print("clicked "+msg)
if
action
!=
None
:
print
(
"clicked "
+
msg
)
#filename=BACKUPPATH+"/CP_"+get_file_count()
#print (filename)
#if os.path.isdir(filename):
# print ("directroy exist "+filename+" exiting..")
# return
#elif os.path.exists(filename):
# msg ("file exist "+filename+" exiting..")
# return
action
()
else
:
pygame
.
draw
.
rect
(
lcd
,
ic
,(
x
,
y
,
w
,
h
))
text
=
pygame
.
font
.
SysFont
(
"comicsansms"
,
25
)
textSurf
,
textRect
=
text_objects
(
msg
,
text
)
textRect
.
center
=
(
(
x
+
(
w
/
2
)),
(
y
+
(
h
/
2
))
)
lcd
.
blit
(
textSurf
,
textRect
)
def
button_layout
(
lcd
,
mouse
):
button
(
lcd
,
"Copy Fusion to BACKUP"
,
5
,
45
,
200
,
30
,
GREEN
,
BLUE
,
mouse
,
wireless_copy_files_to_backup
.
run
,
"test.out"
)
button
(
lcd
,
"Copy Fusion to NFS"
,
5
,
100
,
200
,
30
,
GREEN
,
BLUE
,
mouse
)
button
(
lcd
,
"Clear"
,
340
,
0
,
100
,
30
,
GREEN
,
BLUE
,
mouse
)
def
open_log
(
filename
):
print
(
"here"
)
file_ptr
=
open
(
filename
,
"r"
)
while
True
:
line
=
file_ptr
.
readline
()
if
line
!=
""
:
print
(
file_ptr
.
readline
())
else
:
break
return
file_ptr
def
read_log
(
file_ptr
):
if
file_ptr
!=
None
:
return
file_ptr
.
readline
()
#------------------------------------------------------------------------------------------------------------------------
# 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
()
# The pygame surface we are going to draw onto.
# /!\ It must be the exact same size of the target display /!\
lcd
=
pygame
.
Surface
(
surfaceSize
)
# 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
]))
#Colours
WHITE
=
(
255
,
255
,
255
)
BLACK
=
(
0
,
0
,
0
)
RED
=
(
255
,
0
,
0
)
GREEN
=
(
0
,
255
,
0
)
BLUE
=
(
0
,
0
,
255
)
lcd
.
fill
(
BLACK
)
lcd
.
blit
(
defaultFont
.
render
(
"Log:"
,
False
,
WHITE
),(
244
,
0
))
pygame
.
draw
.
line
(
lcd
,
WHITE
,(
240
,
0
),(
240
,
480
),
1
)
lcd
.
blit
(
defaultFont
.
render
(
"Log:/naaa/nbbb"
,
False
,
WHITE
),(
244
,
420
))
font_big
=
pygame
.
font
.
Font
(
None
,
50
)
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())
button_layout
(
lcd
,(
0
,
0
))
refresh
()
X
=
0
Y
=
0
#process,file_ptr=open_log("test.out")
#print(read_log(process,file_ptr))
#print(read_log(process,file_ptr))
#print(read_log(process,file_ptr))
#print(read_log(process,file_ptr))
#print(read_log(process,file_ptr))
#print(read_log(process,file_ptr))
#print(read_log(process,file_ptr))
#exit()
#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
],
[],
[])
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
))
button_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
)
refresh
()
exit
()
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