Last active
April 8, 2019 04:46
-
-
Save cordx56/1ba363274cb35b5e68d8a0ae850a309c to your computer and use it in GitHub Desktop.
Get student id from SIT student id card using Felica reader and write list.txt & LCD display
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
#!/usr/bin/env python2 | |
import time | |
from smbus2 import SMBusWrapper | |
class LCDctrl: | |
LCDaddr = 0x50 | |
def send(self, dtype, data): | |
with SMBusWrapper(1) as bus: | |
bus.write_i2c_block_data(self.LCDaddr, dtype, [data]) | |
self.wait(0.02) | |
def sendCmd(self, cmd): | |
self.send(0x00, cmd) | |
def sendData(self, data): | |
self.send(0x80, data) | |
def initDisplay(self): | |
self.sendCmd(0x01) | |
self.sendCmd(0x38) | |
self.sendCmd(0x0c) | |
self.sendCmd(0x06) | |
def setCursorPos(self, pos): | |
self.sendCmd(0x80 | pos) | |
def lineBreak(self): | |
self.setCursorPos(0x40) | |
def wait(self, sec): | |
time.sleep(sec) | |
def displayStr(self, l1, l2): | |
self.initDisplay() | |
self.wait(0.2) | |
for b in l1.encode("utf-8"): | |
self.sendData(ord(b)) | |
self.lineBreak() | |
for b in l2.encode("utf-8"): | |
self.sendData(ord(b)) |
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
#!/usr/bin/env python2 | |
from idreader import IDReader | |
from ctrlACM1602NI import LCDctrl | |
lcd = LCDctrl() | |
def printid(studentid, afrom, ato): | |
print("ID: " + studentid) | |
print("from: " + afrom + ", to: " + ato) | |
try: | |
with open("./list.txt", mode="a+") as f: | |
if (studentid.decode("utf-8").lower() + "@shibaura-it.ac.jp\n" not in f.readlines()): | |
f.write(studentid.decode("utf-8").lower() + "@shibaura-it.ac.jp\n") | |
lcd.displayStr(studentid.decode("utf-8"), "Ready") | |
except Exception as e: | |
print(e) | |
lcd.displayStr(studentid.decode("utf-8"), "Error (File IO?)") | |
idr = IDReader(printid) | |
lcd.displayStr("Program started", "waiting...") | |
while True: | |
try: | |
idr.read() | |
except Exception as e: | |
print(e) | |
lcd.displayStr("", "Error (Felica?)") |
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
#!/usr/bin/env python2 | |
import nfc | |
class IDReader: | |
callback = None | |
def __init__(self, cbfunc): | |
self.callback = cbfunc | |
def on_connect(self, tag): | |
try: | |
sc1 = nfc.tag.tt3.ServiceCode(4, 0x010B) | |
bc1 = nfc.tag.tt3.BlockCode(0, service=0) | |
data = tag.read_without_encryption([sc1], [bc1]) | |
studentid = data[3:10] | |
bc1 = nfc.tag.tt3.BlockCode(1, service=0) | |
data = tag.read_without_encryption([sc1], [bc1]) | |
afrom = data[0:8] | |
ato = data[8:16] | |
self.callback(studentid, afrom, ato) | |
except nfc.tag.TagCommandError as e: | |
print("NFC tag read error") | |
def read(self): | |
with nfc.ContactlessFrontend('usb') as clf: | |
clf.connect(rdwr={'on-connect': self.on_connect}) |
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
[[source]] | |
url = "https://pypi.org/simple" | |
verify_ssl = true | |
name = "pypi" | |
[packages] | |
nfcpy = "*" | |
pip = "==18.0" | |
"smbus2" = "*" | |
[dev-packages] | |
[requires] | |
python_version = "2.7" |
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
{ | |
"_meta": { | |
"hash": { | |
"sha256": "c22288f445483a1954f066a0361ae09dc75d358e131f0eb8d85fd6a5853f8042" | |
}, | |
"pipfile-spec": 6, | |
"requires": { | |
"python_version": "2.7" | |
}, | |
"sources": [ | |
{ | |
"name": "pypi", | |
"url": "https://pypi.org/simple", | |
"verify_ssl": true | |
} | |
] | |
}, | |
"default": { | |
"libusb1": { | |
"hashes": [ | |
"sha256:9d4f66d2ed699986b06bc3082cd262101cb26af7a76a34bd15b7eb56cba37e0f" | |
], | |
"version": "==1.7" | |
}, | |
"ndeflib": { | |
"hashes": [ | |
"sha256:4a9d8733e22a28bc26d444f5eb3f6ab499a268c47fba5786cdc3489b3835f65a", | |
"sha256:ef4e139a0ee8c8379b75809d70e49d295cd28ad40aeed4a9d6ec3bff618d7c95" | |
], | |
"version": "==0.3.2" | |
}, | |
"nfcpy": { | |
"hashes": [ | |
"sha256:188943c97c1b008172bf44720129bc39ccfece42a7c75030ac4ba5f7027f37b2", | |
"sha256:b6107a70d78ea41135e64f5bde7b2afccb43e65328bfaa752072f4485dea0b6e" | |
], | |
"index": "pypi", | |
"version": "==0.13.5" | |
}, | |
"pydes": { | |
"hashes": [ | |
"sha256:e2ab8e21d2b83e90d90dbfdcb6fb8ac0000b813238b7ecaede04f8435c389012" | |
], | |
"version": "==2.0.1" | |
}, | |
"pyserial": { | |
"hashes": [ | |
"sha256:6e2d401fdee0eab996cf734e67773a0143b932772ca8b42451440cfed942c627", | |
"sha256:e0770fadba80c31013896c7e6ef703f72e7834965954a78e71a3049488d4d7d8" | |
], | |
"version": "==3.4" | |
}, | |
"smbus2": { | |
"hashes": [ | |
"sha256:4d5aae2f65d39056bb44e8906d5c503f8ee7e02fadb0a6433f1091a9ce528dde" | |
], | |
"index": "pypi", | |
"version": "==0.2.3" | |
} | |
}, | |
"develop": {} | |
} |
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
[Unit] | |
Description=studentid script | |
[Service] | |
User=digicre | |
WorkingDirectory=/studentid | |
ExecStart=/usr/local/bin/pipenv run ./getstudentid.py | |
EnvironmentFile=/etc/environment | |
Type=simple | |
Restart=always | |
[Install] | |
WantedBy=multi-user.target |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment