Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
Babyfut
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PR-Baby-A18
Babyfut
Commits
af9f258d
Commit
af9f258d
authored
Jan 21, 2019
by
Antoine Lima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test scripts
parent
7e4f6d67
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
155 additions
and
0 deletions
+155
-0
tests/test_input.py
tests/test_input.py
+37
-0
tests/test_sr04.py
tests/test_sr04.py
+92
-0
tests/testrfid.py
tests/testrfid.py
+26
-0
No files found.
tests/test_input.py
0 → 100644
View file @
af9f258d
import
logging
import
time
import
RPi.GPIO
as
GPIO
keyButtonBindings
=
{
16
:
'up'
,
6
:
'left'
,
12
:
'right'
,
13
:
'down'
,
26
:
'return'
,
20
:
'del'
,
19
:
'escape'
}
def
fun
(
pin
):
global
last_input
arrival_time
=
time
.
time
()
if
pin
not
in
keyButtonBindings
.
keys
():
print
(
'Unknown button pin: {}'
.
format
(
pin
))
elif
arrival_time
-
last_input
>
0.5
:
key
=
keyButtonBindings
[
pin
]
print
(
'Sending {} as {}'
.
format
(
pin
,
key
))
last_input
=
arrival_time
if
__name__
==
'__main__'
:
GPIO
.
setmode
(
GPIO
.
BCM
)
for
pin
in
keyButtonBindings
.
keys
():
GPIO
.
setup
(
pin
,
GPIO
.
IN
,
pull_up_down
=
GPIO
.
PUD_UP
)
GPIO
.
add_event_detect
(
pin
,
GPIO
.
RISING
,
callback
=
fun
)
try
:
last_input
=
time
.
time
()
while
True
:
pass
finally
:
GPIO
.
cleanup
()
tests/test_sr04.py
0 → 100644
View file @
af9f258d
import
time
import
RPi.GPIO
as
GPIO
from
threading
import
Thread
class
GPIOThread
(
Thread
):
def
__init__
(
self
):
Thread
.
__init__
(
self
)
self
.
_running
=
True
def
running
(
self
):
return
self
.
_running
def
start
(
self
):
Thread
.
start
(
self
)
def
stop
(
self
):
self
.
_running
=
False
def
clean
(
self
):
GPIO
.
cleanup
()
class
GoalThread
(
GPIOThread
):
def
__init__
(
self
,
parent
,
pin_trig
,
pin_echo
):
GPIOThread
.
__init__
(
self
)
self
.
parent
=
parent
self
.
pin_trig
=
pin_trig
self
.
pin_echo
=
pin_echo
self
.
last_goal
=
time
.
time
()
GPIO
.
setmode
(
GPIO
.
BCM
)
GPIO
.
setup
(
self
.
pin_echo
,
GPIO
.
IN
)
GPIO
.
setup
(
self
.
pin_trig
,
GPIO
.
OUT
)
GPIO
.
output
(
self
.
pin_trig
,
GPIO
.
LOW
)
def
run
(
self
):
try
:
# Waiting for sensor to settle
time
.
sleep
(
2
)
while
self
.
running
():
# Trigger a scan with a 10us pulse
GPIO
.
output
(
self
.
pin_trig
,
GPIO
.
HIGH
)
time
.
sleep
(
0.00001
)
GPIO
.
output
(
self
.
pin_trig
,
GPIO
.
LOW
)
timeout
=
False
start_read
=
time
.
time
()
# Read the echo
while
self
.
running
()
and
GPIO
.
input
(
self
.
pin_echo
)
==
0
:
pulse_start_time
=
time
.
time
()
# Prevent infinite loops, add timeout.
if
(
time
.
time
()
-
start_read
)
>
0.06
:
timeout
=
True
break
while
self
.
running
()
and
GPIO
.
input
(
self
.
pin_echo
)
==
1
:
pulse_end_time
=
time
.
time
()
# Prevent infinite loops, add timeout.
if
(
time
.
time
()
-
start_read
)
>
0.06
:
timeout
=
True
break
if
self
.
running
()
and
not
timeout
:
pulse_duration
=
pulse_end_time
-
pulse_start_time
distance
=
round
(
pulse_duration
*
17150
,
2
)
self
.
_handle_dist
(
distance
)
finally
:
self
.
clean
()
def
_handle_dist
(
self
,
dist
):
print
(
'Distance: {}cm'
.
format
(
dist
))
if
dist
<
10
:
if
(
time
.
time
()
-
self
.
last_goal
)
>
1
:
print
(
'goal'
)
#self.parent.goalDetected.emit(self.parent.side)
self
.
last_goal
=
time
.
time
()
if
__name__
==
'__main__'
:
try
:
_GoalPins
=
{
'pin_trig'
:
3
,
'pin_echo'
:
2
}
goalThread
=
GoalThread
(
None
,
**
_GoalPins
)
goalThread
.
start
()
while
True
:
pass
finally
:
goalThread
.
stop
()
tests/testrfid.py
0 → 100644
View file @
af9f258d
from
pirc522
import
RFID
import
signal
import
time
rf_reader
=
RFID
()
try
:
print
(
'Starting...'
)
while
True
:
print
(
'Waiting for a tag'
)
rf_reader
.
wait_for_tag
()
(
error
,
tag_type
)
=
rf_reader
.
request
()
if
error
:
print
(
'Error: {}'
.
format
(
error
))
else
:
(
error
,
id
)
=
rf_reader
.
anticoll
()
if
error
:
print
(
'Error: {}'
.
format
(
error
))
else
:
(
error
,
tag_type
)
=
rf_reader
.
request
()
print
(
'RFID: {}'
.
format
([
hex
(
x
)
for
x
in
id
]))
except
KeyboardInterrupt
:
print
(
'Closing...'
)
rf_reader
.
cleanup
()
\ No newline at end of file
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