diff --git a/meshtastic/__main__.py b/meshtastic/__main__.py index cf16d3c..0479f02 100644 --- a/meshtastic/__main__.py +++ b/meshtastic/__main__.py @@ -174,7 +174,7 @@ def onConnected(interface): interface.sendData(payload, args.destOrAll, portNum=portnums_pb2.PortNum.REPLY_APP, wantAck=True, wantResponse=True) - if args.gpiowrb or args.gpiord: + if args.gpiowrb or args.gpiord or args.gpiowatch: rhc = remote_hardware.RemoteHardwareClient(interface) if args.gpiowrb: @@ -191,6 +191,11 @@ def onConnected(interface): print(f"Reading GPIO mask 0x{bitmask:x} from {args.dest}") rhc.readGPIOs(args.dest, bitmask) + if args.gpiowatch: + bitmask = int(args.gpiowatch) + print(f"Watching GPIO mask 0x{bitmask:x} from {args.dest}") + rhc.watchGPIOs(args.dest, bitmask) + if args.set or args.setstr or args.setchan or args.seturl or args.router != None: closeNow = True @@ -330,6 +335,9 @@ def main(): parser.add_argument( "--gpiord", help="Read from a GPIO mask") + parser.add_argument( + "--gpiowatch", help="Start watching a GPIO mask for changes") + parser.add_argument( "--settime", help="Set the real time clock on the device", action="store_true") diff --git a/meshtastic/remote_hardware.py b/meshtastic/remote_hardware.py index 1f28937..877b641 100644 --- a/meshtastic/remote_hardware.py +++ b/meshtastic/remote_hardware.py @@ -44,3 +44,10 @@ class RemoteHardwareClient: 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) + + def watchGPIOs(self, nodeid, mask): + """Watch the specified bits from GPIO inputs on the device for changes""" + r = remote_hardware_pb2.HardwareMessage() + r.typ = remote_hardware_pb2.HardwareMessage.Type.WATCH_GPIOS + r.gpio_mask = mask + return self.iface.sendData(r, nodeid, portnums_pb2.REMOTE_HARDWARE_APP, wantAck = True)