- added RFID tag reading with the MFRC522 lib

This commit is contained in:
Bernhard Stampfer
2016-04-10 19:46:20 +02:00
parent cd38d16430
commit f55fa181ba
10 changed files with 83 additions and 9 deletions

View File

@@ -76,6 +76,24 @@ def get_user_by_name(name):
print u
return u
def get_user_by_rfid(rfidid):
row = query_db("SELECT * FROM USERS WHERE RFID_ID = ?", [rfidid], one=True)
u = User()
if row is None:
return None
u.id=row[0]
u.name=row[1]
u.password=row[2]
u.longname=row[3]
u.email=row[4]
u.rfid_id=row[5]
u.isblack=row[6]
u.isbaron=row[7]
u.isshown=row[8]
u.autoblack=row[9]
print u
return u
def get_users():
rows = query_db("SELECT * FROM USERS")
users = []

View File

@@ -6,7 +6,8 @@ from plot import *
from database import *
from settings import *
import flask as fla
if settings.enableRFID:
import rfid
class MainWindow(wx.Frame):
@@ -17,8 +18,11 @@ class MainWindow(wx.Frame):
self.panelUsers = PanelUsers(self)
self.panelThanks = PanelThanks(self)
self.panelSorry = PanelSorry(self)
self.panelRFID = PanelRFID(self)
if settings.enableRFID:
self.rfid = rfid.RFID(self.on_rfid)
self.settings = Settings()
self.user = User()
self.drinkl = str()
self.active = 0
@@ -57,10 +61,23 @@ class MainWindow(wx.Frame):
for user in get_users():
if user.longname == longn:
self.user = user
if not self.user.isblack:
self.active = 1 #getränkeauswahl
if self.user.isblack:
self.active = 4 #Sorry Bro
else:
self.active = 4 #Sorry Bro Panel
self.active = 1 #Drinks
self.switchPanels()
def on_rfid(self, rfidid):
if self.active != 0:
return
self.user = get_user_by_rfid(rfidid)
if self.user is None:
self.panelRFID.label_1.SetLabel(rfidid)
self.active = 5 #TODO: Screen showing RFID ID
elif self.user.isblack:
self.active = 4 #Sorry Bro
else:
self.active = 1 #Drinks
self.switchPanels()
def onProduct(self, e):
@@ -80,6 +97,7 @@ class MainWindow(wx.Frame):
self.panelUsers.Hide()
self.panelThanks.Hide()
self.panelSorry.Hide()
self.panelRFID.Hide()
if self.active == 0:
self.panelStart.Show()
elif self.active == 1:
@@ -101,7 +119,8 @@ class MainWindow(wx.Frame):
elif self.active == 4:
self.panelSorry.label_1.SetLabel(self.user.longname)
self.panelSorry.Show()
elif self.active == 5:
self.panelRFID.Show()
class PanelStart (wx.Panel):
@@ -154,7 +173,7 @@ class PanelSorry (wx.Panel):
self.Destroy()
class PanelRfid (wx.Panel):
class PanelRFID (wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent, id=wx.ID_ANY, pos=(0, 0), size=(480, 320))

37
app/rfid.py Normal file
View File

@@ -0,0 +1,37 @@
try:
import MFRC522
except:
print "ERROR: Need MFRC522 Library to read RFID tags, disable RFID if no reader is present!"
exit()
import signal
import thread
class RFID:
def __init__(self, callbackf):
self.reader = MFRC522.MFRC522()
signal.signal(signal.SIGINT, self.stop)
self.callback = callbackf
self.loop = True
thread.start_new_thread(self.read, ())
def read(self):
while self.loop:
(status, tagtype) = self.reader.MFRC522_Request(self.reader.PICC_REQIDL)
print "RFID Status:", status
if status == self.reader.MI_OK:
(status, uid) = self.reader.MFRC522_Anticoll()
if status == self.reader.MI_OK:
uids = "0x" + "".join(format(x, '02x') for x in uid)
self.callback(uids)
print "RFID Detect:",uids
def start(self):
print "RFID reader started"
self.loop = True
thread.start_new_thread(self.read, ())
def stop(self):
print "RFID reader stopped"
self.loop = False

View File

@@ -22,7 +22,7 @@ class Settings:
##User Interaction
#Gui
self.hideGuiList = False #Show the consumers in the gui
self.disableRFID = False #Disable RFID Reading
self.enableRFID = False #Enable RFID Reading
self.allowHiding = False #Allow a user to hide from the gui consumer list
self.onlyOneDrink = False #Hide selection for amount in the gui
self.drinkLimit = 20 #Max amount of consumptions in the gui (default 20)

BIN
gui/rfid.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

BIN
gui/rfid.xcf Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

BIN
gui/thanks.xcf Normal file

Binary file not shown.

BIN
gui/users.xcf Normal file

Binary file not shown.