Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:nycresistor/Hexascroller

  • Loading branch information...
commit 011220946807432e70755ae5fe4bcc6caa01e06c 2 parents 999047d + 5468cd8
@phooky phooky authored
Showing with 53 additions and 27 deletions.
  1. +12 −9 scripts/image.py
  2. +41 −18 scripts/relay.py
View
21 scripts/image.py
@@ -20,8 +20,10 @@ def open(self,portName,baud=9600):
def close(self):
self.serialPort.close()
-mon = Monitor()
-mon.open("/dev/ttyACM0")
+mon = [ Monitor(), Monitor(), Monitor() ]
+mon[0].open("/dev/ttyACM0")
+mon[1].open("/dev/ttyACM1")
+mon[2].open("/dev/ttyACM2")
def show(x,y,img):
s = ""
@@ -32,13 +34,14 @@ def show(x,y,img):
if v:
n |= 1 << (7-j)
s = s + struct.pack("B",n)
- mon.serialPort.write(struct.pack("BB",0xA2,120))
- mon.serialPort.write(s)
- rsp = mon.serialPort.read(2)
- ok = len(rsp) == 2 and rsp[0] == '\x00' and rsp[1] == '\x00'
- if not ok:
- print("Did not receive correct response!")
- print("Response: "+",".join(map(lambda x:hex(ord(x)),rsp)))
+ for m in mon:
+ m.serialPort.write(struct.pack("BB",0xA2,120))
+ m.serialPort.write(s)
+ rsp = m.serialPort.read(2)
+ ok = len(rsp) == 2 and rsp[0] == '\x00' and rsp[1] == '\x00'
+ if not ok:
+ print("Did not receive correct response!")
+ print("Response: "+",".join(map(lambda x:hex(ord(x)),rsp)))
x = 0
y = 0
View
59 scripts/relay.py
@@ -4,7 +4,14 @@
import sys
import struct
-class Monitor:
+CC_TEXT = 0xA1
+CC_BITMAP = 0xA2
+CC_SET_ID = 0xA3
+CC_GET_ID = 0xA4
+CC_UART = 0xA5
+CC_RELAY = 0xA6
+
+class Panel:
def __init__(self):
self.serialPort = None
@@ -14,28 +21,44 @@ def open(self,portName,baud=9600):
self.serialPort.open()
except serial.SerialException, e:
sys.stderr.write("Could not open serial port %s: %s\n" % (self.serialPort.portstr, e))
+
+ def command(self,command,payload,expected):
+ l = len(payload)
+ self.serialPort.write(struct.pack("BB",command,l))
+ if l > 0:
+ self.serialPort.write(payload)
+ rsp = self.serialPort.read(2)
+ if len(rsp) < 2 or ord(rsp[0]) != 0:
+ print("Error on command {0}".format(command))
+ return ""
+ l = ord(rsp[1])
+ rpay = self.serialPort.read(l)
+ return rpay
+
def close(self):
self.serialPort.close()
-mon = Monitor()
-mon.open("/dev/ttyACM0")
+panels = [None]*3
+for port in range(0,3):
+ name = "/dev/ttyACM{0}".format(port)
+ p = Panel()
+ p.open(name)
+ v = p.command(CC_GET_ID,"",0)
+ id = ord(v[0])
+ panels[id] = p
+
+relOn = 0
+import sys
if len(sys.argv) > 1:
- if sys.argv[1] == 'on':
- state = 1
- elif sys.argv[1] == 'off':
- state = 0
- else:
- print("bad state, exiting")
- sys.exit(1)
- mon.serialPort.write(struct.pack("BBB",0xA6,1,state))
- rsp = mon.serialPort.read(2)
- ok = len(rsp) == 2 and rsp[0] == '\x00' and rsp[1] == '\x00'
- if not ok:
- print("Did not receive correct response!")
- print("Response: "+",".join(map(lambda x:hex(ord(x)),rsp)))
-
-mon.close()
+ if sys.argv[1] == '1':
+ relOn = 1
+
+panels[0].command(CC_RELAY,struct.pack("B",relOn),0)
+
+for p in panels:
+ p.close()
+
Please sign in to comment.
Something went wrong with that request. Please try again.