herosdevices.core.bus.i2c ========================= .. py:module:: herosdevices.core.bus.i2c .. autoapi-nested-parse:: Primitive functions and classes representing I2C connections. Module Contents --------------- .. py:data:: smbus2 :value: None .. py:class:: I2CConnection(bus_id: int, keep_alive: bool = True) A class to manage I2C communication connections via smbus2. :param bus_id: I2C bus id (e.g. 1 for /dev/i2c-1). :param keep_alive: if True, keep the bus open between operations. .. py:attribute:: bus_id .. py:attribute:: keep_alive :value: True .. py:attribute:: connection .. py:property:: is_open :type: bool Return whether the bus is currently open. :returns: True if the bus file descriptor is open. .. py:method:: open() -> None Open the I2C bus if not already open. .. py:method:: close() -> None Close the I2C bus. .. py:method:: operation() -> collections.abc.Iterator[None] Context manager for I2C operations. Ensures the bus is open before performing operations and closes it afterward if keep_alive is False. :Yields: Yields control back to the caller.