Instrument Neutral Distributed Interface INDI 2.2.5
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Connection::I2C Class Reference

The I2C class manages connection with I2C devices on Linux systems. I2C communication is commonly used for sensors and other embedded devices. The default I2C bus is /dev/i2c-1 and default address is 0x28. After I2C connection is established successfully, a handshake is performed to verify device communication. More...

#include <connectioni2c.h>

Inheritance diagram for Connection::I2C:
Connection::Interface

Public Types

enum  I2CConnectionText { I2C_BUS = 0 , I2C_ADDRESS }
 
- Public Types inherited from Connection::Interface
enum  Type {
  CONNECTION_NONE = 1 << 0 , CONNECTION_SERIAL = 1 << 1 , CONNECTION_TCP = 1 << 2 , CONNECTION_USB = 1 << 3 ,
  CONNECTION_I2C = 1 << 4 , CONNECTION_CUSTOM = 1 << 15
}
 

Public Member Functions

 I2C (INDI::DefaultDevice *dev, IPerm permission=IP_RW)
 
virtual ~I2C ()
 
virtual bool Connect () override
 Connect Connect to device via the implemented communication medium. Do not perform any handshakes.
 
virtual bool Disconnect () override
 Disconnect Disconnect from device.
 
virtual void Activated () override
 Activated Function called by the framework when the plugin is activated (i.e. selected by the user). It is usually used to define properties pertaining to the specific plugin functionalities.
 
virtual void Deactivated () override
 Deactivated Function called by the framework when the plugin is deactivated. It is usually used to delete properties by were defined previously since the plugin is no longer active.
 
virtual std::string name () override
 
virtual std::string label () override
 
virtual const char * busPath ()
 
virtual uint8_t address ()
 
void setDefaultBusPath (const char *path)
 setDefaultBusPath Set default I2C bus path. Call this function in initProperties() of your driver if you want to change default bus path.
 
void setDefaultAddress (uint8_t addr)
 setDefaultAddress Set default I2C address. The default address is 0x28 unless otherwise changed by this function. Call this function in initProperties() of your driver.
 
int getPortFD () const
 
virtual bool ISNewText (const char *dev, const char *name, char *texts[], char *names[], int n) override
 
virtual bool saveConfigItems (FILE *fp) override
 
- Public Member Functions inherited from Connection::Interface
virtual Type type ()
 type Return connection type
 
virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n)
 
virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n)
 
virtual bool ISNewBLOB (const char *dev, const char *name, int sizes[], int blobsizes[], char *blobs[], char *formats[], char *names[], int n)
 
void registerHandshake (std::function< bool()> callback)
 registerHandshake Register a handshake function to be called once the initial connection to the device is established.
 

Protected Member Functions

virtual bool Connect (const char *busPath, uint8_t address)
 Connect to I2C device.
 
virtual bool processHandshake ()
 
- Protected Member Functions inherited from Connection::Interface
 Interface (INDI::DefaultDevice *dev, Type type=CONNECTION_NONE)
 
virtual ~Interface ()
 
const char * getDeviceName ()
 

Protected Attributes

INDI::PropertyText I2CConnectionTP {2}
 
int PortFD = -1
 
IPerm m_Permission = IP_RW
 
std::string m_ConfigBusPath
 
int m_ConfigAddress {-1}
 
- Protected Attributes inherited from Connection::Interface
std::function< bool()> Handshake
 
INDI::DefaultDevice * m_Device { nullptr }
 
Type m_Type { CONNECTION_NONE }
 

Detailed Description

The I2C class manages connection with I2C devices on Linux systems. I2C communication is commonly used for sensors and other embedded devices. The default I2C bus is /dev/i2c-1 and default address is 0x28. After I2C connection is established successfully, a handshake is performed to verify device communication.

Definition at line 36 of file connectioni2c.h.

Member Enumeration Documentation

◆ I2CConnectionText

Enumerator
I2C_BUS 
I2C_ADDRESS 

Definition at line 39 of file connectioni2c.h.

Constructor & Destructor Documentation

◆ I2C()

Connection::I2C::I2C ( INDI::DefaultDevice *  dev,
IPerm  permission = IP_RW 
)

Definition at line 40 of file connectioni2c.cpp.

◆ ~I2C()

Connection::I2C::~I2C ( )
virtual

Definition at line 61 of file connectioni2c.cpp.

Member Function Documentation

◆ Activated()

void Connection::I2C::Activated ( )
overridevirtual

Activated Function called by the framework when the plugin is activated (i.e. selected by the user). It is usually used to define properties pertaining to the specific plugin functionalities.

Implements Connection::Interface.

Definition at line 171 of file connectioni2c.cpp.

◆ address()

uint8_t Connection::I2C::address ( )
virtual
Returns
Currently active I2C device address

Definition at line 219 of file connectioni2c.cpp.

◆ busPath()

const char * Connection::I2C::busPath ( )
virtual
Returns
Currently active I2C bus path

Definition at line 191 of file connectioni2c.cpp.

◆ Connect() [1/2]

bool Connection::I2C::Connect ( )
overridevirtual

Connect Connect to device via the implemented communication medium. Do not perform any handshakes.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

Definition at line 84 of file connectioni2c.cpp.

◆ Connect() [2/2]

bool Connection::I2C::Connect ( const char *  busPath,
uint8_t  address 
)
protectedvirtual

Connect to I2C device.

Parameters
busPathI2C bus path to connect to.
addressI2C device address
Returns
True if connection is successful, false otherwise
Warning
Do not call this function directly, it is called by Connection::I2C Connect() function.

Definition at line 125 of file connectioni2c.cpp.

◆ Deactivated()

void Connection::I2C::Deactivated ( )
overridevirtual

Deactivated Function called by the framework when the plugin is deactivated. It is usually used to delete properties by were defined previously since the plugin is no longer active.

Implements Connection::Interface.

Definition at line 176 of file connectioni2c.cpp.

◆ Disconnect()

bool Connection::I2C::Disconnect ( )
overridevirtual

Disconnect Disconnect from device.

Returns
True if successful, false otherwise.

Implements Connection::Interface.

Definition at line 159 of file connectioni2c.cpp.

◆ getPortFD()

int Connection::I2C::getPortFD ( ) const
inline
Returns
Return I2C file descriptor. If connection is successful, I2CFD is a positive integer otherwise it is set to -1

Definition at line 93 of file connectioni2c.h.

◆ ISNewText()

bool Connection::I2C::ISNewText ( const char *  dev,
const char *  name,
char *  texts[],
char *  names[],
int  n 
)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 65 of file connectioni2c.cpp.

◆ label()

virtual std::string Connection::I2C::label ( )
inlineoverridevirtual
Returns
Plugin friendly label presented to the client/user.

Implements Connection::Interface.

Definition at line 60 of file connectioni2c.h.

◆ name()

virtual std::string Connection::I2C::name ( )
inlineoverridevirtual
Returns
Plugin name

Implements Connection::Interface.

Definition at line 55 of file connectioni2c.h.

◆ processHandshake()

bool Connection::I2C::processHandshake ( )
protectedvirtual

Definition at line 106 of file connectioni2c.cpp.

◆ saveConfigItems()

bool Connection::I2C::saveConfigItems ( FILE *  fp)
overridevirtual

Reimplemented from Connection::Interface.

Definition at line 181 of file connectioni2c.cpp.

◆ setDefaultAddress()

void Connection::I2C::setDefaultAddress ( uint8_t  addr)

setDefaultAddress Set default I2C address. The default address is 0x28 unless otherwise changed by this function. Call this function in initProperties() of your driver.

Parameters
addrDesired new address

Definition at line 205 of file connectioni2c.cpp.

◆ setDefaultBusPath()

void Connection::I2C::setDefaultBusPath ( const char *  path)

setDefaultBusPath Set default I2C bus path. Call this function in initProperties() of your driver if you want to change default bus path.

Parameters
pathName of desired default bus path

Definition at line 196 of file connectioni2c.cpp.

Member Data Documentation

◆ I2CConnectionTP

INDI::PropertyText Connection::I2C::I2CConnectionTP {2}
protected

Definition at line 113 of file connectioni2c.h.

◆ m_ConfigAddress

int Connection::I2C::m_ConfigAddress {-1}
protected

Definition at line 120 of file connectioni2c.h.

◆ m_ConfigBusPath

std::string Connection::I2C::m_ConfigBusPath
protected

Definition at line 119 of file connectioni2c.h.

◆ m_Permission

IPerm Connection::I2C::m_Permission = IP_RW
protected

Definition at line 117 of file connectioni2c.h.

◆ PortFD

int Connection::I2C::PortFD = -1
protected

Definition at line 115 of file connectioni2c.h.


The documentation for this class was generated from the following files: