frontend overhaul, minor backend bugfixes
This commit is contained in:
parent
acc38950e7
commit
c1325c0eda
28 changed files with 767 additions and 481 deletions
|
@ -23,11 +23,11 @@ portList = serial.tools.list_ports.comports()
|
|||
if len(portList) < 1:
|
||||
sys.exit("No serial port found")
|
||||
#TODO if multiple ports idk, shouldn't ever happen but still
|
||||
(serport, serdesc, serhwid) = portList[0]
|
||||
(serport, serdesc, serhwid) = portList[0] #TODO CHECK FOR TTYUSB0
|
||||
#TODO if port provided from conf, set, otherwise autodetect magical thing just works
|
||||
|
||||
aser: aioserial.AioSerial = aioserial.AioSerial(
|
||||
port=serport,
|
||||
port=serport,
|
||||
baudrate=1200,
|
||||
parity=serial.PARITY_NONE,
|
||||
bytesize=serial.EIGHTBITS,
|
||||
|
@ -120,7 +120,7 @@ async def handleTsePower(client, sysSelect, cmd):
|
|||
|
||||
async def handleTseSencilo(client, cmd):
|
||||
#relName = tval.split('/')[3]
|
||||
topicPub = f'{room}/firanki/status'
|
||||
topicPub = f'{room}/shades/status'
|
||||
if cmd == "MOVE_UP":
|
||||
rel = RelayState(shades_mapping['UP'], True)
|
||||
await executeAndPublish(client, topicPub, "MOVING_UP", rel)
|
||||
|
@ -132,14 +132,17 @@ async def handleTseSencilo(client, cmd):
|
|||
await executeAndPublish(client, topicPub, "STOPPED", RelayState(shades_mapping['DOWN'], False))
|
||||
|
||||
|
||||
platnoBckgdMoving = False # mucho importante variable prav zares dedoles
|
||||
platnoBckgdMoving = {
|
||||
'main': False,
|
||||
'side': False,
|
||||
} # mucho importante variable prav zares dedoles
|
||||
|
||||
async def platnoTimeout(mqttClient, pubTopic, pubPayload, relStat: RelayState, intent):
|
||||
async def platnoTimeout(mqttClient, pubTopic, pubPayload, relStat: RelayState, intent, select):
|
||||
global platnoBckgdMoving
|
||||
await asyncio.sleep(25) #TODO time actual delay
|
||||
relStat.state = False
|
||||
await executeAndPublish(mqttClient, pubTopic, intent, relStat)
|
||||
platnoBckgdMoving = False #TODO properly document why this is here and what it does
|
||||
platnoBckgdMoving[select] = False #TODO properly document why this is here and what it does
|
||||
|
||||
async def handleTsePlatno(client, proj, cmdType, cmd):
|
||||
global platnoBckgdMoving
|
||||
|
@ -148,49 +151,56 @@ async def handleTsePlatno(client, proj, cmdType, cmd):
|
|||
#projector = topicSplit[2]
|
||||
#command = topicSplit[4]
|
||||
pubTop = f'{room}/projectors/{proj}/platno/status'
|
||||
|
||||
if platnoBckgdMoving:
|
||||
if not (proj == "main" or proj == "side"):
|
||||
return
|
||||
if platnoBckgdMoving[proj]:
|
||||
if cmd == 'STOP':
|
||||
pubPld = 'UNKNOWN'
|
||||
rel1 = RelayState(platno_mapping[proj]['UP'], False)
|
||||
rel2 = RelayState(platno_mapping[proj]['DOWN'], False)
|
||||
await executeAndPublish(client,pubTop, pubPld, rel1)
|
||||
await executeAndPublish(client,pubTop, pubPld, rel2)
|
||||
platnoBckgdMoving = False
|
||||
platnoBckgdMoving[proj] = False
|
||||
else:
|
||||
return #TODO print ignore any other move commands while moving
|
||||
|
||||
#movement cmds
|
||||
elif cmdType == 'move':
|
||||
print("Ignored command because already moving", proj, cmdType, cmd)
|
||||
return
|
||||
|
||||
if cmdType == 'move':
|
||||
print('move')
|
||||
rel: RelayState
|
||||
if cmd == 'UP':
|
||||
rel = RelayState(platno_mapping[proj]['UP'], True)
|
||||
pubPld = 'MOVING_UP'
|
||||
elif cmd == 'DOWN':
|
||||
rel = RelayState(platno_mapping[proj]['DOWN'], True)
|
||||
pubPld = 'MOVING_DOWN'
|
||||
else:
|
||||
return # in case of invalid input skip
|
||||
platnoBckgdMoving = True #TODO rename to moving, add comment how it works
|
||||
pubPld = 'MOVING'
|
||||
platnoBckgdMoving[proj] = True #TODO rename to moving, add comment how it works
|
||||
await executeAndPublish(client, pubTop, pubPld, rel)
|
||||
#TODO WTF HAPPENS IF YOU SEND UP AND DOWN AT ONCE?? (screenshot?)
|
||||
#TODO WTF HAPPENS IF YOU SEND UP AND DOWN AT ONCE?? (screenshot?)
|
||||
#TODO daj ignore print ko je locked up
|
||||
|
||||
elif cmdType == 'goto':
|
||||
# print('received GOTO')
|
||||
print('received GOTO')
|
||||
rel: RelayState
|
||||
if cmd == 'UP':
|
||||
rel = RelayState(platno_mapping[proj]['UP'], True)
|
||||
intent = 'UP'
|
||||
pubPld = 'MOVING_UP'
|
||||
elif cmd == 'DOWN':
|
||||
rel = RelayState(platno_mapping[proj]['DOWN'], True)
|
||||
intent = 'DOWN'
|
||||
pubPld = 'MOVING_DOWN'
|
||||
else:
|
||||
return # in case of invalid input skip
|
||||
platnoBckgdMoving = True
|
||||
pubPld = 'MOVING'
|
||||
platnoBckgdMoving[proj] = True
|
||||
# pubPld = 'MOVING'
|
||||
await executeAndPublish(client, pubTop, pubPld, rel)
|
||||
asyncio.create_task(platnoTimeout(client, pubTop, pubPld, rel, intent))
|
||||
asyncio.create_task(platnoTimeout(client, pubTop, pubPld, rel, intent, proj))
|
||||
|
||||
return
|
||||
else:
|
||||
print('unknown command')
|
||||
|
||||
async def task_command2serial(controlClient: aiomqtt.Client):
|
||||
#print('oge')
|
||||
|
@ -208,16 +218,21 @@ async def task_command2serial(controlClient: aiomqtt.Client):
|
|||
cmnd = mesg.payload.decode()
|
||||
#print('Received on: ', topicVal, ' with:', cmnd)
|
||||
#print('bfr')
|
||||
if mesg.topic.matches(f'{room}/projectors/+/platno/#'):
|
||||
proj = msgTopic[2] # glavni / stranski
|
||||
cmdType = msgTopic[4] # move / goto
|
||||
if mesg.topic.matches(f'{room}/projectors/+/platno/move') or mesg.topic.matches(f'{room}/projectors/+/platno/goto'):
|
||||
proj = msgTopic[-3]
|
||||
cmdType = msgTopic[-1] # move / goto
|
||||
print(f'on {topicVal} received: {cmnd}')
|
||||
await handleTsePlatno(controlClient, proj, cmdType, cmnd) #TODO odzadi index
|
||||
|
||||
elif mesg.topic.matches(f'{room}/power/+/set'):
|
||||
systype = msgTopic[2]
|
||||
systype = msgTopic[-2]
|
||||
print(f'on {topicVal} received: {cmnd}')
|
||||
print('calling power')
|
||||
await handleTsePower(controlClient, systype, cmnd)
|
||||
|
||||
elif mesg.topic.matches(f'{room}/firanki/move'):
|
||||
elif mesg.topic.matches(f'{room}/shades/move'):
|
||||
print(f'on {topicVal} received: {cmnd}')
|
||||
print('calling move')
|
||||
await handleTseSencilo(controlClient, cmnd)
|
||||
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue