def __init__(self, port, deviceAddress, simPort=None): """Constructor. :param port: The I2C port the device is connected to. :param deviceAddress: The address of the device on the I2C bus. :param simPort: This must be an object that implements all of the i2c* functions from hal_impl that you use. See ``test_i2c.py`` for an example. """ if hal.HALIsSimulation(): if simPort is None: raise ValueError("You will need to use a mock for this i2c port, or provide a simPort implementation") # Just check for basic functionality assert hasattr(simPort, "i2CInitialize") assert hasattr(simPort, "i2CClose") self._port = (simPort, port) else: self._port = port self.deviceAddress = deviceAddress hal.i2CInitialize(self._port) self.__finalizer = weakref.finalize(self, _freeI2C, self._port) hal.HALReport(hal.HALUsageReporting.kResourceType_I2C, deviceAddress)
def __init__(self, port, deviceAddress, simPort=None): """Constructor. :param port: The I2C port the device is connected to. :param deviceAddress: The address of the device on the I2C bus. :param simPort: This must be an object that implements all of the i2c* functions from hal_impl that you use. See ``test_i2c.py`` for an example. """ if hal.HALIsSimulation(): if simPort is None: # If you want more functionality, implement your own mock from hal_impl.i2c_helpers import I2CSimBase simPort = I2CSimBase() msg = "Using stub simulator for I2C port %s" % port warnings.warn(msg) # Just check for basic functionality assert hasattr(simPort, 'i2CInitialize') assert hasattr(simPort, 'i2CClose') self._port = (simPort, port) else: self._port = port self.deviceAddress = deviceAddress hal.i2CInitialize(self._port) self.__finalizer = weakref.finalize(self, _freeI2C, self._port) hal.HALReport(hal.HALUsageReporting.kResourceType_I2C, deviceAddress)
def __init__(self, port, deviceAddress): """Constructor. :param port: The I2C port the device is connected to. :param deviceAddress: The address of the device on the I2C bus. """ self.port = port self.deviceAddress = deviceAddress hal.i2CInitialize(self.port) self._i2c_finalizer = weakref.finalize(self, _freeI2C, self.port) hal.HALReport(hal.HALUsageReporting.kResourceType_I2C, deviceAddress)
def __init__(self, port, deviceAddress, simPort=None): """Constructor. :param port: The I2C port the device is connected to. :type port: :class:`.I2C.Port` :param deviceAddress: The address of the device on the I2C bus. :param simPort: This must be an object that implements all of the i2c* functions from hal_impl that you use. See ``test_i2c.py`` for an example. """ if port not in [self.Port.kOnboard, self.Port.kMXP]: raise ValueError("Invalid value '%s' for I2C port" % port) if hal.HALIsSimulation(): if simPort is None: # If you want more functionality, implement your own mock from hal_impl.i2c_helpers import I2CSimBase simPort = I2CSimBase() msg = "Using stub simulator for I2C port %s" % port warnings.warn(msg) # Just check for basic functionality assert hasattr(simPort, 'i2CInitialize') assert hasattr(simPort, 'i2CClose') self._port = (simPort, port) else: self._port = port self.deviceAddress = deviceAddress hal.i2CInitialize(self._port) self.__finalizer = weakref.finalize(self, _freeI2C, self._port) hal.HALReport(hal.HALUsageReporting.kResourceType_I2C, deviceAddress)