Skip to content

Commit

Permalink
Merge pull request #243 from MiczFlor/develop
Browse files Browse the repository at this point in the history
Version 1.1.6 dynamic loading for covers in web app and bug fixes
  • Loading branch information
MiczFlor authored Oct 8, 2018
2 parents 76cbc99 + c5d1b38 commit 65d45f7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 174 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ A contactless jukebox for the Raspberry Pi, playing audio files, playlists, podc

*Important update news*

* **Phoniebox 1.1.1 released** Adding *recursive folder playout* and *recording* to the Phoniebox. With version 1.0.0 we switched the audio player to `mpd`, added *resume play* for audiobook lovers, RFID switch for *wifi off*, new *player interface*, *random* and *repeat*. At this stage the *recursive* playout only works in the web app, not RFID cards. (2018-09-13)
* **Upgrade** if you are looking for *how to upgrade* please check out [UPGRADE.md](docs/UPGRADE.md) - and if you found out something that should go there, please create a pull request. (2018-09-10)
* **One Line Install Script** As of version 1.0 there is a much simpler install procedure: copy and paste one line into your terminal and hit *enter*. Find out more about the [one-line Phoniebox install script](docs/INSTALL-stretch.md#oneLineInstall). (2018-08-18)
* **Phoniebox 1.1.6 released** Adding *recursive folder playout* and *recording* to the Phoniebox. With version 1.x we switched the audio player to `mpd`, added *resume play* for audiobook lovers, RFID switch for *wifi off*, new *player interface*, *random* and *repeat*. At this stage the *recursive* playout only works in the web app, not RFID cards. (2018-10-08)
* **Upgrade** if you are looking for *how to upgrade* please check out [UPGRADE.md](docs/UPGRADE.md) - and if you found out something that should go there, please create a pull request. (2018-10-08)
* **One Line Install Script** As of version 1.x there is a much simpler install procedure: copy and paste one line into your terminal and hit *enter*. Find out more about the [one-line Phoniebox install script](docs/INSTALL-stretch.md#oneLineInstall). (2018-08-18)
* **Podcasts!** More for myself than anybody else, I guess, I added the [podcast feature for Phoniebox](docs/MANUAL.md#podcasts) (2018-05-09)
* **Bleeding edge: `develop` branch** The maintenance with a growing contributor team (kudos!) got complicated. I introduced the branch `develop` which is where all new stuff is happening before merged to `master`. (2018-08-30)
---
Expand Down
2 changes: 1 addition & 1 deletion docs/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ There is a file `settings/version` containing the version number.

**Note:*** This is work in progress, please share experience, improvements and insights in the [issue section](https://github.com/MiczFlor/RPi-Jukebox-RFID/issues).

# Upgrade from Version 1.1.1 to 1.1.3
# Upgrade from Version 1.1.1 to 1.1.6

A few important bug fixes. And a new design.
And the option to decide what the 'second swipe' of a card does (see settings in the web app).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ WorkingDirectory=/home/pi/RPi-Jukebox-RFID
ExecStart=/usr/bin/python2 /home/pi/RPi-Jukebox-RFID/scripts/daemon_rfid_reader.py

[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target
166 changes: 34 additions & 132 deletions scripts/Reader.py
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]
23 changes: 12 additions & 11 deletions scripts/RegisterDevice.py
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()
32 changes: 7 additions & 25 deletions scripts/daemon_rfid_reader.py
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:"
2 changes: 1 addition & 1 deletion settings/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.5
1.1.6

0 comments on commit 65d45f7

Please sign in to comment.