Re-enable motor relays when communication comes back
This commit is contained in:
parent
16bc26d7d2
commit
a1fcd61c53
19
main.py
19
main.py
|
@ -26,17 +26,26 @@ dmm2 = None
|
||||||
|
|
||||||
MOTOR_EN1 = 1
|
MOTOR_EN1 = 1
|
||||||
MOTOR_EN2 = 2
|
MOTOR_EN2 = 2
|
||||||
|
DISABLED = None
|
||||||
|
|
||||||
def enable_motors():
|
def enable_motors():
|
||||||
|
global DISABLED
|
||||||
|
|
||||||
logging.info('Enabling both motors...')
|
logging.info('Enabling both motors...')
|
||||||
relays.relay_on(MOTOR_EN1)
|
relays.relay_on(MOTOR_EN1)
|
||||||
relays.relay_on(MOTOR_EN2)
|
relays.relay_on(MOTOR_EN2)
|
||||||
|
|
||||||
|
DISABLED = False
|
||||||
|
|
||||||
def disable_motors():
|
def disable_motors():
|
||||||
|
global DISABLED
|
||||||
|
|
||||||
logging.info('Disabling both motors...')
|
logging.info('Disabling both motors...')
|
||||||
relays.relay_off(MOTOR_EN1)
|
relays.relay_off(MOTOR_EN1)
|
||||||
relays.relay_off(MOTOR_EN2)
|
relays.relay_off(MOTOR_EN2)
|
||||||
|
|
||||||
|
DISABLED = True
|
||||||
|
|
||||||
|
|
||||||
async def send_mqtt(topic, message):
|
async def send_mqtt(topic, message):
|
||||||
try:
|
try:
|
||||||
|
@ -184,6 +193,16 @@ async def monitor_dyn4():
|
||||||
await send_mqtt(topic, message)
|
await send_mqtt(topic, message)
|
||||||
|
|
||||||
|
|
||||||
|
if ONE_MOTOR:
|
||||||
|
if DISABLED is True and dmm1:
|
||||||
|
logging.info('Motor1 communication back, re-enabling...')
|
||||||
|
enable_motors()
|
||||||
|
else:
|
||||||
|
if DISABLED is True and dmm1 and dmm2:
|
||||||
|
logging.info('Motor1 and Motor2 communication back, re-enabling...')
|
||||||
|
enable_motors()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def task_died(future):
|
def task_died(future):
|
||||||
if os.environ.get('SHELL'):
|
if os.environ.get('SHELL'):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user