roboglia.i2c.I2CDevice¶
-
class
I2CDevice
(**kwargs)[source]¶ Bases:
roboglia.base.device.BaseDevice
Implements a representation of an I2C device.
It only adds an override for the
get_model_path()
in order to localize the device definitions in thedevice
directory of thei2c
module and the methodopen()
that will attempt to read all the registers not marked assync
.-
get_model_path
()[source]¶ Builds the path to the .yml documents.
- Returns
- the path to the standard` directory with device
definitions. In this case
devices
in thei2c
module directory.
- Return type
str
-
__str__
()¶ Return str(self).
-
property
bus
¶ The bus where the device is connected to.
-
close
()¶ Perform device closure.
BaseDevice
implementation does nothing.
-
default_register
()¶ Default register for the device in case is not explicitly provided in the device definition file.
Subclasses of
BaseDevice
can overide the method to derive their own class.BaseDevice
suggests as default registerBaseRegister
.
-
property
dev_id
¶ The device number.
- Returns
The device number
- Return type
int
-
property
name
¶ Device name.
- Returns
The name of the device
- Return type
str
-
open
()¶ Performs initialization of the device by reading all registers that are not flagged for
sync
replication and, ifinit
parameter provided initializes the indicated registers with the values from theinit
paramters.
-
read_register
(register)¶ Implements the read of a register using the associated bus. More complex devices should overwrite the method to provide specific functionality.
BaseDevice
simply calls the bus’sread
function and returns the value received.
-
register_by_address
(address)¶ Returns the register identified by the given address. If the address is not available in the device it will return
None
.- Returns
The device at address or
None
if no register with that address exits.- Return type
BaseDevice or subclass or
None
-
property
registers
¶ Device registers as dict.
- Returns
The dictionary of registers with the register name as key.
- Return type
dict
-
write_register
(register, value)¶ Implements the write of a register using the associated bus. More complex devices should overwrite the method to provide specific functionality.
BaseDevice
simply calls the bus’swrite
function and returns the value received.
-