Composition is one solution. Pass the i2c object to the constructor instead of constructing the i2c object inside the driver. How the i2c object is constructed is implementation detail and it should not concern the driver. This way you also don't tie the driver to a specific implementation of the I2C driver. For example something like:pythoncoder wrote: ↑Mon Feb 19, 2018 6:57 amMy existing driver uses soft I2C which is not supported hereA programmatic means of determining the port would be generally useful as there are inevitable differences.Code: Select all
# Standard port i2c = I2C(-1, scl=scl_pin, sda=sda_pin) # Loboris port doesn't support soft I2C i2c = I2C(scl=scl_pin, sda=sda_pin)
Code: Select all
i2c = I2C(scl=Pin(22), sda=Pin(21))
sensor = MPU9250(i2c)
Code: Select all
i2c = I2C(-1, scl=scl_pin, sda=sda_pin)
sensor = MPU9250(i2c)