Created
August 4, 2012 04:54
-
-
Save mapmeld/3254625 to your computer and use it in GitHub Desktop.
OLPC-NFC-IO
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
# Reader.py | |
# RFID / NFC Card Reader | |
# For adding names to each card and reading them out loud | |
import sys, os | |
# test if pyserial library is installed | |
try: | |
import serial | |
except: | |
print "To install the reader program:" | |
print "In Terminal activity, enter:" | |
print "sudo python /home/olpc/Activities/Pippy.py/pyserial-2.5/setup.py install" | |
sys.exit() | |
ser = serial.Serial('/dev/ttyACM0', 9600) | |
line = "" | |
lastCard = "" | |
waitTime = 200 | |
cardList = {} | |
while 1: | |
line = line + ser.readline() | |
if(line.find('#') > -1 and line.find('!') > -1): | |
seeCard = line[line.rfind('#')+1:line.rfind('!')] | |
if((lastCard != seeCard) or (waitTime < 0)): | |
# write the name of the card | |
print "Card: " + seeCard | |
# check if the card has been seen before | |
if(cardList.has_key(seeCard)): | |
# speak the name of the card | |
os.system('espeak -v en "' + cardList[seeCard] + '"') | |
else: | |
# ask for the name of the new card | |
cardList[seeCard] = raw_input("What is the name of the card? ") | |
waitTime = 200 | |
lastCard = seeCard | |
line = "" | |
else: | |
waitTime = waitTime - 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment