Skip to content
Snippets Groups Projects
Commit 60afc1ad authored by Johannes Walcher's avatar Johannes Walcher
Browse files

all those small changes

parent 45249e47
No related branches found
No related tags found
No related merge requests found
......@@ -16,17 +16,17 @@ class Babel:
self.hbf.subscribe('/haspa/power/requestinfo', self.command_requestinfo)
self.hbf.subscribe('/haspa/power/status', self.command_requeststatus)
self.ledstrip_states = [[0, 0, 0, 0], [0, 0, 0, 0]]
self.espids = ['a9495a00', 'c14e5a00']
self.ledstrip_states = [[0] * 8, [0] * 8]
#self.espids = ['a9495a00', 'c14e5a00']
# new 4 channel ESPs
self.espids = ['f97c7300', 'dfd80b00']
# mapps from (color, id) ==> (self.ledstrip indexes)
self.idxpair = {
# The first one has cold and warm swapped...
('w', 2):(0, 0),
('c', 2):(0, 1),
('w', 1):(0, 2),
('c', 1):(0, 3),
# This one has cold and warm right
('c', 2):(0, 0),
('w', 2):(0, 1),
('c', 1):(0, 6),
('w', 1):(0, 7),
('c', 3):(1, 0),
('w', 3):(1, 1),
('c', 4):(1, 2),
......@@ -55,7 +55,7 @@ class Babel:
## The lamp is managed by rupprecht
if lamp in self.rupprecht_map:
msg[self.rupprecht_map[lamp][0]] = int(value)
self.rupprecht_map[lamp][1] = int(value)
self.rupprecht_map[lamp] = (self.rupprecht_map[lamp][0], int(value))
## The lamp is a led strip and needs to be aggregated
if lamp.startswith('ledstrip'):
......
......@@ -54,12 +54,26 @@ class Hackerman:
async def command_action(self, client, message, _):
""" Handle actions like alarm or party """
del client
print(message)
if 'action' in message:
if message['action'] == 'alarm':
print("Performing alarm...")
await self.hbf.publish('/haspa/power', {'alarm':1023})
await asyncio.sleep(2)
await self.hbf.publish('/haspa/power', {'alarm':0})
elif message['action'] == 'strobo':
for i in range(100):
await self.hbf.publish('/haspa/power', {
'ledstrip-c': 0
})
await asyncio.sleep(0.05)
await self.hbf.publish('/haspa/power', {
'ledstrip-c': 1023
})
await asyncio.sleep(0.03)
elif message['action'] == 'party':
await self.hbf.publish('/haspa/power', {
'alarm':0,
......
libconf==1.0.1
paho-mqtt==1.3.1
pyserial==3.4
pyserial-asyncio==0.4
......@@ -92,10 +92,14 @@ class Quigg1000:
async def __send_msg(self, msg):
if self.rupprecht:
print("sending via rupprecht message", msg)
await self.rupprecht.light(msg)
await asyncio.sleep(1)
if self.serial:
print("sending via raw message", msg)
try:
self.ser.write(str.encode(msg))
self.serial.write(str.encode(msg))
await asyncio.sleep(1)
except serial.SerialException:
print('Serial communication failed.')
......@@ -113,6 +117,7 @@ def main():
default=False, action='store_true')
args = parser.parse_args()
loop=asyncio.get_event_loop()
try:
s = serial.Serial(args.device, 9600)
......@@ -121,7 +126,6 @@ def main():
exit()
r = Quigg1000(serial=s, loop=loop, code=args.set_code, subaddr=args.addr)
loop=asyncio.get_event_loop()
loop.run_until_complete(r.state(args.state, args.debug))
if __name__ == '__main__':
......
......@@ -52,9 +52,9 @@ class Rupprecht:
async def teardown(self):
await self.hbf.teardown()
async def command_led(self, source, payload, mqttmsg):
del source, payload
msg = json.loads(mqttmsg.payload.decode('utf-8'))
async def command_led(self, source, msg, mqttmsg):
print("having LED command", msg)
del source, mqttmsg
for devid, value in msg.items():
try:
if value == 0:
......@@ -68,17 +68,16 @@ class Rupprecht:
if msg['open'] and not self.space_is_open:
self.space_is_open = True
await self.hbf.publish('/haspa/status', {'haspa':'open'})
self.rupprecht.text("Status:Open... StuStaNet.e.V....")
await self.rupprecht.text("Status:Open... StuStaNet.e.V....")
elif not msg['open'] and self.space_is_open:
self.space_is_open = False
await self.hbf.publish('/haspa/status', {'haspa':'closed'})
self.rupprecht.text("Status:Closed... StuStaNet.e.V....")
await self.rupprecht.text("Status:Closed... StuStaNet.e.V....")
class RupprechtInterface:
def __init__(self, serial_port, baudrate=115200, loop=None):
self.loop = loop or asyncio.get_event_loop()
self.button_callbacks = [];
coro = serial_asyncio.open_serial_connection(loop=self.loop, url=serial_port,
......@@ -106,17 +105,31 @@ class RupprechtInterface:
async def receive_messages(self):
while True:
line = await self.reader.readline()
line = line.strip()
try:
print("Waiting for input:")
line = await self.reader.readline()
except serial.SerialException:
print("SerialException, will terminate")
self.loop.cancel()
return
print("Received: ", line)
line = line.decode('ascii').strip()
if str.startswith(line, "BUTTON"):
print("Button message")
await self.button_queue.put(line[len("BUTTON"):])
else:
print("Into data queue")
await self.data_queue.put(line)
print("done")
async def handlecallbacks(self):
await self.send_raw("CONFIG ECHO OFF")
# filter out the last echo
await self.data_queue.get()
#await self.data_queue.get()
#print("Waiting for message")
#while "READY" != self.data_queue.get():
# pass
#await self.send_raw("CONFIG ECHO OFF", expect_response=False)
print("Rupprecht finally there")
while True:
button_msg = await self.button_queue.get()
......@@ -128,7 +141,7 @@ class RupprechtInterface:
for callback in self.button_callbacks:
try:
callback(buttons)
await callback(buttons)
except Exception as e:
print("Exception while executing callback for", button_msg , e)
......@@ -141,8 +154,10 @@ class RupprechtInterface:
This will wait, until the preceding message has been processed.
"""
print("Sending RUPPRECHT message: ", msg)
self.writer.write(msg.encode('ascii'))
if msg[-1] != "\n":
self.writer.write(b"\n")
await self.writer.drain()
if expect_response:
return await self.data_queue.get()
......
[Unit]
Description=Hauptbahnhof %i-Module
After=network.target
After=network-online.target
Requires=mosquitto.service
Before=hauptbahnhof.service
[Service]
......
[Unit]
Description=Hauptbahnhof Hackerspace Control System
Wants=mosquitto.service
[Install]
WantedBy=multi-user.target
\ No newline at end of file
WantedBy=multi-user.target
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment