Commit e4d68ae3 authored by Antoine Lima's avatar Antoine Lima

RFID integration

parent e9e0ac5a
......@@ -8,7 +8,6 @@ import logging
import time
from threading import Thread
import pyautogui # PyPi library
from pirc522 import RFID # PyPi library
from PyQt5.QtCore import QObject, pyqtSignal
......@@ -17,6 +16,7 @@ from Babyfut.core.player import Side
if ON_RASP:
import RPi.GPIO as GPIO
from pirc522 import RFID # PyPi library
class GPIOThread(Thread, QObject):
_keyButtonBindings = {
......@@ -27,17 +27,17 @@ class GPIOThread(Thread, QObject):
17: 'return',
18: 'escape'
}
rfidReceived = pyqtSignal(str)
def __init__(self):
Thread.__init__(self)
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:
self.rf_reader = RFID(pin_rst=25, pin_ce=8, pin_irq=24, pin_mode=GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
......@@ -81,7 +81,8 @@ class GPIOThread(Thread, QObject):
def stop(self):
self.continueRunning = False
# Falsely trigger the rfid reader to stop it waiting
self.rf_reader.irq.set()
if ON_RASP:
self.rf_reader.irq.set()
def clean(self):
GPIOThread.clean()
......
......@@ -17,7 +17,7 @@ class Replay(Thread):
Thread.__init__(self)
self.replayPath = getContent('Replay {}.mp4'.format(side.name))
self.shutdown = False
if ON_RASP:
self.camera_detected = Replay.detectCam()
......@@ -81,9 +81,12 @@ class Replay(Thread):
@staticmethod
def detectCam():
camdet = subprocess.check_output(["vcgencmd","get_camera"])
return int(chr(camdet[-2]))
if ON_RASP:
camdet = subprocess.check_output(["vcgencmd","get_camera"])
return int(chr(camdet[-2]))
else:
return False
@staticmethod
def isCamAvailable(self=None):
detected = self.camera_detected if self!=None else Replay.detectCam()
......
......@@ -10,11 +10,12 @@ import logging
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QGraphicsBlurEffect, QApplication
from PyQt5.QtCore import Qt, QTime, QTranslator
from PyQt5.QtCore import Qt, QTime, QTranslator, pyqtSlot
from Babyfut import modules
from Babyfut.ui.main_ui import Ui_MainWindow
from Babyfut.core.player import Side
from Babyfut.core.settings import Settings
from Babyfut.ui.main_ui import Ui_MainWindow
class MainWin(QtWidgets.QMainWindow):
DEFAULT_LANG = 'en'
......@@ -80,6 +81,11 @@ class MainWin(QtWidgets.QMainWindow):
for modIdx in modulesIdx:
self.modules[modIdx].other(**msg)
@pyqtSlot(str)
def rfidHandler(self, rfid):
side = Side.Left if Settings['app.side']=='left' else Side.Right
self.dispatchMessage({'rfid': rfid, 'source': side})
def _loadSettings(self):
if Settings['ui.fullscreen']:
self.showFullScreen()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment