Closed nkpro2000sr closed 3 years ago
Perhaps pslab.bus.busio.I2C
could keep track of connected slaves with a dictionary? Every time a read or write method is called, check if the address is already in the dictionary. If it is, use the associated slave instance. If not, create a new one and add it to the dictionary.
If that doesn't work, option 1 is preferable, i.e. adding static methods to I2CSlave.
OK, I will do with dictionary.
I would like to add two static methods in
pslab.bus.i2c.I2CSlave
for the implementation ofpslab.bus.busio
.I2CSlave.read_from(device: SerialHandler, address: int, bytes_to_read: int) -> bytearray
I2CSlave.write_to(device: SerialHandler, address: int, bytes_to_write: bytearray)
OR changing address as optional parameter in
I2CSlave.__init__
I2CSlave.read_from(address: int, bytes_to_read: int) -> bytearray
I2CSlave.write_to(address: int, bytes_to_write: bytearray)
OR moving these methods to
I2CMaster
.otherwise busio's read and write methods have to create I2CSlave object for each call.