1
0
mirror of https://github.com/pommi/python-itho-wpu.git synced 2024-11-21 13:52:15 +01:00

refactor(itho-wpu): rm wait type

The wait type is unreliable. No reason to keep maintaining this.
This commit is contained in:
Pim van den Berg 2020-11-05 13:31:30 +01:00
parent c7b5171a66
commit e3bc670050

View File

@ -28,9 +28,6 @@ def parse_args():
] ]
parser.add_argument('--action', nargs='?', required=True, parser.add_argument('--action', nargs='?', required=True,
choices=actions, help="Execute an action") 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='?', parser.add_argument('--loglevel', nargs='?',
choices=["debug", "info", "warning", "error", "critical"], choices=["debug", "info", "warning", "error", "critical"],
help="Loglevel") help="Loglevel")
@ -73,26 +70,6 @@ class I2CSlave():
else: else:
logger.error(f"Received number of bytes was {b}") 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): def is_checksum_valid(self, b):
s = 0x80 s = 0x80
for i in b[:-1]: for i in b[:-1]:
@ -138,10 +115,7 @@ if __name__ == "__main__":
if not args.master_only: if not args.master_only:
slave = I2CSlave(address=0x40) slave = I2CSlave(address=0x40)
if args.type == 'callback': slave_thread = threading.Thread(target=slave.set_callback, args=[q, args.slave_timeout])
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.start() slave_thread.start()
if not args.slave_only: if not args.slave_only:
@ -149,7 +123,3 @@ if __name__ == "__main__":
if args.action: if args.action:
master.execute_action(args.action) master.execute_action(args.action)
master.close() master.close()
if args.type == 'wait' and not args.master_only:
result = q.get()
logger.info(f"Response: {result}")