-
Notifications
You must be signed in to change notification settings - Fork 402
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from MiczFlor/develop
Version 1.1.6 dynamic loading for covers in web app and bug fixes
- Loading branch information
Showing
7 changed files
with
59 additions
and
174 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,39 @@ | ||
# Forked from Francisco Sahli's https://github.com/fsahli/music-cards/blob/master/Reader.py | ||
|
||
import string | ||
#import csv | ||
import os.path | ||
import sys | ||
import serial | ||
import string | ||
import RPi.GPIO as GPIO | ||
|
||
from evdev import InputDevice, categorize, ecodes, list_devices | ||
import MFRC522 | ||
|
||
|
||
def get_devices(): | ||
devices = [InputDevice(fn) for fn in list_devices()] | ||
devices.append(NonUsbDevice('MFRC522')) | ||
devices.append(NonUsbDevice('RDM6300')) | ||
return devices | ||
|
||
|
||
class NonUsbDevice(object): | ||
name = None | ||
|
||
def __init__(self, name): | ||
self.name = name | ||
|
||
|
||
class UsbReader(object): | ||
def __init__(self, device): | ||
self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" | ||
self.dev = device | ||
|
||
def read_card(self): | ||
from select import select | ||
stri = '' | ||
key = '' | ||
while key != 'KEY_ENTER': | ||
select([self.dev], [], []) | ||
for event in self.dev.read(): | ||
if event.type == 1 and event.value == 1: | ||
stri += self.keys[event.code] | ||
key = ecodes.KEY[event.code] | ||
return stri[:-1] | ||
|
||
|
||
class Mfrc522Reader(object): | ||
def __init__(self): | ||
self.device = MFRC522.MFRC522() | ||
|
||
def read_card(self): | ||
# Scan for cards | ||
status, tag_type = self.device.MFRC522_Request(self.device.PICC_REQIDL) | ||
|
||
# If a card is found | ||
if status == self.device.MI_OK: | ||
print "Card detected" | ||
|
||
# Get the UID of the card | ||
(status, uid) = self.device.MFRC522_Anticoll() | ||
|
||
# If we have the UID, continue | ||
if status == self.device.MI_OK: | ||
return ''.join((str(x) for x in uid)) | ||
else: | ||
print "No Device ID found." | ||
return None | ||
|
||
@staticmethod | ||
def cleanup(): | ||
GPIO.cleanup() | ||
|
||
|
||
class Rdm6300Reader: | ||
def __init__(self): | ||
device = '/dev/ttyS0' | ||
baudrate = 9600 | ||
ser_timeout = 0.1 | ||
self.last_card_id = '' | ||
try: | ||
self.rfid_serial = serial.Serial(device, baudrate, timeout=ser_timeout) | ||
except serial.SerialException as e: | ||
print(e) | ||
exit(1) | ||
|
||
def read_card(self): | ||
byte_card_id = b'' | ||
|
||
try: | ||
while True: | ||
try: | ||
read_byte = self.rfid_serial.read() | ||
|
||
if read_byte == b'\x02': # start byte | ||
while read_byte != b'\x03': # end bye | ||
read_byte = self.rfid_serial.read() | ||
byte_card_id += read_byte | ||
|
||
card_id = byte_card_id.decode('utf-8') | ||
byte_card_id = '' | ||
card_id = ''.join(x for x in card_id if x in string.printable) | ||
|
||
# Only return UUIDs with correct length | ||
if len(card_id) == 12 and card_id != self.last_card_id: | ||
self.last_card_id = card_id | ||
self.rfid_serial.reset_input_buffer() | ||
return self.last_card_id | ||
|
||
else: # wrong UUID length or already send that UUID last time | ||
self.rfid_serial.reset_input_buffer() | ||
|
||
except ValueError as ve: | ||
print(ve) | ||
|
||
except serial.SerialException as se: | ||
print(se) | ||
|
||
def cleanup(self): | ||
self.rfid_serial.close() | ||
|
||
|
||
class Reader(object): | ||
def __init__(self): | ||
path = os.path.dirname(os.path.realpath(__file__)) | ||
if not os.path.isfile(path + '/deviceName.txt'): | ||
sys.exit('Please run config.py first') | ||
else: | ||
with open(path + '/deviceName.txt', 'r') as f: | ||
device_name = f.read() | ||
|
||
if device_name == 'MFRC522': | ||
self.reader = Mfrc522Reader() | ||
elif device_name == 'RDM6300': | ||
self.reader = Rdm6300Reader() | ||
else: | ||
try: | ||
device = [device for device in get_devices() if device.name == device_name][0] | ||
self.reader = UsbReader(device) | ||
except IndexError: | ||
sys.exit('Could not find the device %s.\n Make sure it is connected' % device_name) | ||
from select import select | ||
class Reader: | ||
def __init__(self): | ||
path = os.path.dirname(os.path.realpath(__file__)) | ||
self.keys = "X^1234567890XXXXqwertzuiopXXXXasdfghjklXXXXXyxcvbnmXXXXXXXXXXXXXXXXXXXXXXX" | ||
if not os.path.isfile(path + '/deviceName.txt'): | ||
sys.exit('Please run RegisterDevice.py first') | ||
else: | ||
with open(path + '/deviceName.txt','r') as f: | ||
deviceName = f.read() | ||
devices = [InputDevice(fn) for fn in list_devices()] | ||
for device in devices: | ||
if device.name == deviceName: | ||
self.dev = device | ||
break | ||
try: | ||
self.dev | ||
except: | ||
sys.exit('Could not find the device %s\n. Make sure is connected' % deviceName) | ||
|
||
def readCard(self): | ||
stri='' | ||
key = '' | ||
while key != 'KEY_ENTER': | ||
r,w,x = select([self.dev], [], []) | ||
for event in self.dev.read(): | ||
if event.type==1 and event.value==1: | ||
stri+=self.keys[ event.code ] | ||
#print( keys[ event.code ] ) | ||
key = ecodes.KEY[ event.code ] | ||
return stri[:-1] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
#!/usr/bin/env python2 | ||
# Forked from Francisco Sahli's https://github.com/fsahli/music-cards/blob/master/config.py | ||
import os.path | ||
from Reader import get_devices | ||
|
||
devices = get_devices() | ||
import os.path | ||
from evdev import InputDevice, list_devices | ||
|
||
print "Choose the reader from list:" | ||
for i in range(len(devices)): | ||
print i, devices[i].name | ||
devices = [InputDevice(fn) for fn in list_devices()] | ||
path = os.path.dirname(os.path.realpath(__file__)) | ||
i = 0 | ||
print "Choose the reader from list" | ||
for dev in devices: | ||
print i, dev.name | ||
i += 1 | ||
|
||
dev_id = int(raw_input('Device Number: ')) | ||
|
||
path = os.path.dirname(os.path.realpath(__file__)) | ||
with open(path + '/deviceName.txt', 'w') as f: | ||
f.write(devices[dev_id].name) | ||
f.close() | ||
with open(path + '/deviceName.txt','w') as f: | ||
f.write(devices[dev_id].name) | ||
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,19 @@ | ||
#!/usr/bin/env python2 | ||
import subprocess | ||
import os | ||
import signal | ||
|
||
import os | ||
from Reader import Reader | ||
|
||
reader = Reader() | ||
continue_reading = True | ||
|
||
# get absolute path of this script | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
print dir_path | ||
|
||
# Capture SIGINT for cleanup when the script is aborted | ||
def end_read(signal, frame): | ||
global continue_reading | ||
print "Ctrl+C captured, ending read." | ||
continue_reading = False | ||
reader.reader.cleanup() | ||
|
||
|
||
# Welcome message | ||
print "Press Ctrl-C to stop." | ||
|
||
# Hook the SIGINT | ||
signal.signal(signal.SIGINT, end_read) | ||
|
||
while continue_reading: | ||
# reading the card id | ||
cardid = reader.reader.read_card() | ||
if cardid is not None: | ||
while True: | ||
# reading the card id | ||
cardid = reader.readCard() | ||
try: | ||
# start the player script and pass on the card id | ||
# start the player script and pass on the cardid | ||
subprocess.call([dir_path + '/rfid_trigger_play.sh --cardid=' + cardid], shell=True) | ||
except OSError as e: | ||
print "Execution failed:" + str(e) | ||
print "Execution failed:" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.1.5 | ||
1.1.6 |