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
66c779b4
Commit
66c779b4
authored
Dec 13, 2018
by
Antoine Lima
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
RFID Integration
parent
c2b449fa
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
10 deletions
+43
-10
babyfut.py
babyfut.py
+4
-1
core/downloader.py
core/downloader.py
+1
-1
core/input.py
core/input.py
+36
-6
devtools.sh
devtools.sh
+2
-2
No files found.
babyfut.py
View file @
66c779b4
...
...
@@ -28,6 +28,7 @@ def getMainWin():
ON_RASP
=
os
.
uname
()[
1
]
==
'raspberrypi'
IMG_PATH
=
getContent
(
'img'
)
SIDE
=
None
if
__name__
==
'__main__'
:
__package__
=
'Babyfut'
...
...
@@ -40,6 +41,7 @@ if __name__=='__main__':
from
Babyfut.core.replay
import
Replay
as
ReplayThread
try
:
SIDE
=
Side
.
Left
#logging.basicConfig(filename='babyfoot.log', level=logging.DEBUG)
logging
.
basicConfig
(
level
=
logging
.
DEBUG
)
...
...
@@ -54,7 +56,8 @@ if __name__=='__main__':
threadReplay
.
start
()
myapp
.
dispatchMessage
({
'replayThread'
:
threadReplay
},
toType
=
GameModule
)
threadGPIO
=
GPIOThread
(
myapp
)
threadGPIO
=
GPIOThread
()
threadGPIO
.
rfidReceived
.
connect
(
myapp
.
rfidHandler
)
threadGPIO
.
start
()
threadDownloader
=
Downloader
.
instance
()
...
...
core/downloader.py
View file @
66c779b4
...
...
@@ -16,7 +16,7 @@ from PyQt5.QtCore import QObject, pyqtSignal, pyqtSlot
class
Downloader
(
Thread
,
QObject
):
'''
Helper for downloading images
with the help of
queues
Helper for downloading images
using
queues
'''
N_ATTEMPS
=
5
...
...
core/input.py
View file @
66c779b4
...
...
@@ -5,8 +5,12 @@
"""
import
logging
import
pyautogui
# PyPi library
import
time
from
threading
import
Thread
import
pyautogui
# PyPi library
from
pirc522
import
RFID
# PyPi library
from
PyQt5.QtCore
import
QObject
,
pyqtSignal
from
Babyfut.babyfut
import
ON_RASP
from
Babyfut.core.player
import
Side
...
...
@@ -14,7 +18,7 @@ from Babyfut.core.player import Side
if
ON_RASP
:
import
RPi.GPIO
as
GPIO
class
GPIOThread
(
Thread
):
class
GPIOThread
(
Thread
,
QObject
):
_keyButtonBindings
=
{
26
:
'up'
,
22
:
'left'
,
...
...
@@ -23,11 +27,15 @@ class GPIOThread(Thread):
17
:
'return'
,
18
:
'escape'
}
rfidReceived
=
pyqtSignal
(
str
)
def
__init__
(
self
,
dispatcher
):
def
__init__
(
self
):
Thread
.
__init__
(
self
)
self
.
dispatcher
=
dispatcher
QObject
.
__init__
(
self
)
self
.
rf_reader
=
RFID
(
pin_rst
=
25
,
pin_ce
=
8
,
pin_irq
=
24
,
pin_mode
=
GPIO
.
BCM
)
self
.
continueRunning
=
True
self
.
lastRFIDReception
=
0
if
ON_RASP
:
GPIO
.
setwarnings
(
False
)
...
...
@@ -42,9 +50,25 @@ class GPIOThread(Thread):
if
ON_RASP
:
try
:
while
self
.
continueRunning
:
pass
self
.
rf_reader
.
wait_for_tag
()
(
error
,
tag_type
)
=
self
.
rf_reader
.
request
()
if
not
error
:
self
.
handleRFID
()
finally
:
GPIOThread
.
clean
()
self
.
clean
()
def
handleRFID
(
self
):
(
error
,
id
)
=
self
.
rf_reader
.
anticoll
()
if
not
error
:
# Prevent RFID "spam" (one second removal delay)
now
=
time
.
time
()
if
self
.
lastRFIDReception
!=
0
and
abs
(
self
.
lastRFIDReception
-
now
)
>
1
:
self
.
lastRFIDReception
=
0
receivedRFID
=
':'
.
join
([
str
(
x
)
for
x
in
id
])
self
.
rfidReceived
.
emit
(
receivedRFID
)
logging
.
debug
(
'Received RFID: {}'
.
format
(
receivedRFID
))
else
:
self
.
lastRFIDReception
=
now
def
handleButtonPress
(
self
,
button_pin
):
if
button_pin
not
in
GPIOThread
.
_keyButtonBindings
.
keys
():
...
...
@@ -56,6 +80,12 @@ class GPIOThread(Thread):
def
stop
(
self
):
self
.
continueRunning
=
False
# Falsely trigger the rfid reader to stop it waiting
self
.
rf_reader
.
irq
.
set
()
def
clean
(
self
):
GPIOThread
.
clean
()
self
.
rf_reader
.
cleanup
()
@
staticmethod
def
clean
():
...
...
devtools.sh
View file @
66c779b4
...
...
@@ -59,12 +59,12 @@ case "$1" in
bash ./devtools.sh
"clean"
bash ./devtools.sh
"all"
;;
"exec"
)
"
run"
|
"
exec"
)
cd
..
python
-m
Babyfut.babyfut
;;
*
)
echo
"Unknown command
\"
$1
\"
. See
content of
script for available commands."
echo
"Unknown command
\"
$1
\"
. See script for available commands."
;;
esac
...
...
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