From 6958032121e44b5e987b14e140f7f111ac1902d1 Mon Sep 17 00:00:00 2001 From: Pim van den Berg Date: Thu, 5 Nov 2020 13:31:30 +0100 Subject: [PATCH] refactor(itho-wpu): rm wait type The wait type is unreliable. No reason to keep maintaining this. --- itho-wpu.py | 32 +------------------------------- 1 file changed, 1 insertion(+), 31 deletions(-) diff --git a/itho-wpu.py b/itho-wpu.py index fbc6e8c..5cb119f 100755 --- a/itho-wpu.py +++ b/itho-wpu.py @@ -28,9 +28,6 @@ def parse_args(): ] parser.add_argument('--action', nargs='?', required=True, choices=actions, help="Execute an action") - parser.add_argument('--type', nargs='?', required=True, - choices=["callback", "wait"], - help="Pigpio slave type") parser.add_argument('--loglevel', nargs='?', choices=["debug", "info", "warning", "error", "critical"], help="Loglevel") @@ -73,26 +70,6 @@ class I2CSlave(): else: logger.error(f"Received number of bytes was {b}") - def wait(self, q): - try: - self.pi.bsc_i2c(self.address) - if self.pi.wait_for_event(pigpio.EVENT_BSC, 5): - s, b, d = self.pi.bsc_i2c(self.address) - result = None - if b: - logger.debug(f"Received {b} bytes! Status {s}") - result = [hex(c) for c in d] - if self.is_checksum_valid(result): - q.put(result) - else: - logger.error(f"Received number of bytes was {b}") - else: - logger.error("pi.wait_for_event timed out") - except(KeyboardInterrupt): - self.close() - else: - self.close() - def is_checksum_valid(self, b): s = 0x80 for i in b[:-1]: @@ -138,10 +115,7 @@ if __name__ == "__main__": if not args.master_only: slave = I2CSlave(address=0x40) - if args.type == 'callback': - slave_thread = threading.Thread(target=slave.set_callback, args=[q, args.slave_timeout]) - elif args.type == 'wait': - slave_thread = threading.Thread(target=slave.wait, args=[q]) + slave_thread = threading.Thread(target=slave.set_callback, args=[q, args.slave_timeout]) slave_thread.start() if not args.slave_only: @@ -149,7 +123,3 @@ if __name__ == "__main__": if args.action: master.execute_action(args.action) master.close() - - if args.type == 'wait' and not args.master_only: - result = q.get() - logger.info(f"Response: {result}")