From d699a855916f70a4c0f49ebd92f0609623b01d33 Mon Sep 17 00:00:00 2001 From: Kevin Hester Date: Mon, 7 Dec 2020 13:07:14 +0800 Subject: [PATCH] add gpio rx handling --- meshtastic/remote_hardware.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/meshtastic/remote_hardware.py b/meshtastic/remote_hardware.py index dca05af..1f28937 100644 --- a/meshtastic/remote_hardware.py +++ b/meshtastic/remote_hardware.py @@ -1,12 +1,21 @@ from . import portnums_pb2, remote_hardware_pb2 +from pubsub import pub + +def onGPIOreceive(packet, interface): + """Callback for received GPIO responses + + FIXME figure out how to do closures with methods in python""" + pb = remote_hardware_pb2.HardwareMessage() + pb.ParseFromString(packet["decoded"]["data"]["payload"]) + print(f"Received RemoteHardware typ={pb.typ}, gpio_value={pb.gpio_value}") -""" -This is the client code to control/monitor simple hardware built into the -meshtastic devices. It is intended to be both a useful API/service and example -code for how you can connect to your own custom meshtastic services -""" class RemoteHardwareClient: + """ + This is the client code to control/monitor simple hardware built into the + meshtastic devices. It is intended to be both a useful API/service and example + code for how you can connect to your own custom meshtastic services + """ def __init__(self, iface): """ @@ -16,6 +25,7 @@ class RemoteHardwareClient: """ self.iface = iface + pub.subscribe(onGPIOreceive, "meshtastic.receive.data.REMOTE_HARDWARE_APP") def writeGPIOs(self, nodeid, mask, vals): """ @@ -30,4 +40,7 @@ class RemoteHardwareClient: def readGPIOs(self, nodeid, mask): """Read the specified bits from GPIO inputs on the device""" - pass \ No newline at end of file + r = remote_hardware_pb2.HardwareMessage() + r.typ = remote_hardware_pb2.HardwareMessage.Type.READ_GPIOS + r.gpio_mask = mask + return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True)