-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathledsignlib.py
More file actions
58 lines (44 loc) · 1.45 KB
/
ledsignlib.py
File metadata and controls
58 lines (44 loc) · 1.45 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import serial
from time import sleep
from Queue import Queue
display = serial.Serial("/dev/ttyUSB1", 9600)
def buildPacketHeader(payload, id = 0x01):
packet = "<ID%02x>" % id
packet += payload
checksum = 0
for byte in (payload):
checksum ^= ord(byte)
packet += ("%02x" % checksum).upper()
# terminator
packet += "<E>"
return packet
def pageContentPayload(message, line = 1, page = 'A', lead = 'A', display = 'A', wait = 'F', lag = 'A'):
payload = "<L%s><P%s><F%s><M%s><W%s><F%s>%s" % (line, page, lead, display, wait, lag, message)
return payload
def graphicBlockPayload(data, page = 'A', block = 1):
payload = "<G%s%s>%s" % (page, block, data)
return payload
blockWidth = 32
blockHeight = 8
numUnits = 4
unitWidth = 8
pixelsPerByte = 4
bytes = (blockWidth * blockHeight) / pixelsPerByte
packetQueue = Queue()
def send(packet):
global display, packetQueue
packet = buildPacketHeader(packet)
print(repr(packet) + " queued")
packetQueue.put(packet)
def run(forever=False):
if not packetQueue.empty():
display.write(packetQueue.get())
while not (not forever and packetQueue.empty()):
sleep(0.2)
if display.inWaiting():
msg = display.read(display.inWaiting())
if msg == 'ACK':
print("sent queued packet")
display.write(packetQueue.get())
else:
print "Got a %s" % msg