forked from fsahli/music-cards
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
136 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import csv | ||
import os.path | ||
import sys | ||
|
||
class CardList: | ||
def __init__(self): | ||
self.path = os.path.dirname(os.path.realpath(__file__)) | ||
self.cardList = self.readList() | ||
|
||
def readList(self): | ||
with open(self.path + '/cardList.csv', mode='r') as infile: | ||
reader = csv.reader(infile) | ||
cardList = {rows[0]:rows[1] for rows in reader} | ||
infile.close() | ||
return cardList | ||
|
||
def getPlaylist(self,card): | ||
self.cardList = self.readList() | ||
try: | ||
return self.cardList[card] | ||
except: | ||
print 'Card %s is not card list' % card | ||
return '' | ||
|
||
def addPlaylist(self, card, plist): | ||
try: | ||
if card not in self.cardList.keys(): | ||
f = open(self.path + '/cardList.csv', 'a') | ||
f.write(card + ',' + plist + '\n') | ||
self.cardList[card] = plist | ||
else: | ||
print 'Card %s is already used' % card | ||
except: | ||
print 'Could not write file' | ||
if not os.path.isfile(self.path + '/cardList.csv'): | ||
print 'File cardList.csv does not exist' | ||
|
||
|
||
|
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import string | ||
import csv | ||
import os.path | ||
import sys | ||
|
||
from evdev import InputDevice, categorize, ecodes, list_devices | ||
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 config.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
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os.path | ||
from evdev import InputDevice, list_devices | ||
|
||
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: ')) | ||
|
||
with open(path + '/deviceName.txt','w') as f: | ||
f.write(devices[dev_id].name) | ||
f.close() | ||
|
||
|