Skip to content

Commit

Permalink
bringing repo in line with what's deployed
Browse files Browse the repository at this point in the history
  • Loading branch information
phooky committed Feb 26, 2018
1 parent 7a45744 commit 0e7f66c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion hexaservice/hexascroller.service
Expand Up @@ -3,7 +3,7 @@ Description=Hexascroller
After=syslog.target

[Service]
WorkingDirectory=/root/Hexascroller/hexaservice
WorkingDirectory=/home/pi/Hexascroller/hexaservice
ExecStart=/usr/bin/python2 ./service.py
Restart=always

Expand Down
20 changes: 15 additions & 5 deletions hexaservice/led_panel.py
Expand Up @@ -65,12 +65,17 @@ def command(self,command,payload,expected):
return

l = len(payload)
self.serialPort.write(struct.pack("BB",command,l))
packet = struct.pack("BB",command,l)
if l > 0:
self.serialPort.write(payload)
packet = packet + payload
self.serialPort.write(packet)
rsp = self.serialPort.read(2)
if len(rsp) < 2 or ord(rsp[0]) != 0:
print("Error on command {0}".format(command))
#print("Error on panel {1} command {0}".format(command,self.id))
if len(rsp) == 2:
epl = ord(rsp[1])
if epl > 0: rsp = rsp + self.serialPort.read(epl)
#print("Rsp length {0}, {1}".format(len(rsp),map(ord,rsp)))
return ""
l = ord(rsp[1])
rpay = self.serialPort.read(l)
Expand Down Expand Up @@ -102,19 +107,23 @@ def getID(self):
if self.debug: return self.id

v = self.command(CC_GET_ID,"",1)
id = ord(v[0])
return id
self.id = ord(v[0])
print("ID'd panel {0}".format(self.id))
return self.id


panels = [None]*3
import glob
import time

def init(debug = False):
if debug:
for port_num in range(0,3):
port = 9990 + port_num
p = Panel(port_num)
p.open(port)
time.sleep(0.1)
return true

else:
for candidate in glob.glob('/dev/ttyACM*'):
Expand All @@ -127,6 +136,7 @@ def init(debug = False):
except:
p.close()
print("{} failed".format(candidate))
return reduce(lambda a,b: a & (b != None), panels, True)

def shutdown():
for p in panels:
Expand Down
8 changes: 4 additions & 4 deletions hexaservice/service.py
Expand Up @@ -51,7 +51,9 @@ class ServiceThread:
if len(sys.argv) > 1 and sys.argv[1] == 'debug':
debug = True

led_panel.init(debug)
if not led_panel.init(debug):
print("Could not find all three panels; aborting.")
sys.exit(0)
panels[0].setRelay(True)

def sigint_handler(signal,frame):
Expand All @@ -67,9 +69,7 @@ def sigint_handler(signal,frame):

for j in range(3):
panels[j].setCompiledImage(bitmap)

time.sleep(0.10)

time.sleep(0.06)
panels[0].setRelay(False)

led_panel.shutdown()

0 comments on commit 0e7f66c

Please sign in to comment.