add gpio rx handling

This commit is contained in:
Kevin Hester
2020-12-07 13:07:14 +08:00
parent cc77a2ab1e
commit d699a85591

View File

@@ -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
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)