-
Notifications
You must be signed in to change notification settings - Fork 3
/
NfcActor.py
38 lines (28 loc) · 1.03 KB
/
NfcActor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from subprocess import Popen, PIPE
import re, logging
from TickActor import TickActor
LONG_PRESS_IN_SECONDS = 5
class NfcActor(TickActor):
def __init__(self, tagActor, sleepSeconds):
super(NfcActor, self).__init__(sleepSeconds)
self.tagActor = tagActor
self.currentTag = None
def doTick(self):
tag = self.getTag()
if tag != self.currentTag:
self.currentTag = tag
if tag != None:
self.doAction(tag)
def doAction(self, tag):
logging.getLogger('zbap').info('Calling tagActor.playByTag() with tag: %s' % tag)
self.tagActor.playByTag(tag)
def getCurrentTag(self):
return self.currentTag
def getTag(self):
p = Popen("nfc-list", shell=True, stdout=PIPE, stderr=PIPE)
out, err = p.communicate()
for line in out.decode("utf-8").split("\n"):
m = re.match(r"[\s]*UID \(NFCID1\): ([a-z0-9 ]+)\b", line)
if m:
return m.group(1).replace(" ", "")
return None