NXShield  v1.07
NXShield Library Reference by OpenElectrons.com
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
NXShieldI2C Class Reference

This class implements I2C interfaces used by NXShield. More...

#include <NXShieldI2C.h>

Inheritance diagram for NXShieldI2C:
BaseI2CDevice SoftI2cMaster AbsoluteIMU ACCLNx AngleSensor CurrentMeter DISTNx EV3SensorAdapter LineLeader MagicWand NumericPad NXShieldBank NXTCam NXTHID NXTMMX NXTPowerMeter NXTServo PFMate PiLight PSPNx RTC VoltMeter

Public Member Functions

 NXShieldI2C (uint8_t i2c_address)
 
void init (void *shield, SH_BankPort bp)
 
uint8_t readByte (uint8_t location)
 
uint16_t readInteger (uint8_t location)
 
uint32_t readLong (uint8_t location)
 
uint8_t * readRegisters (uint8_t start_register, uint8_t bytes, uint8_t *buf)
 
char * readString (uint8_t location, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0)
 
bool writeRegisters (uint8_t start_register, uint8_t bytes_to_write, uint8_t *buffer=0)
 
bool writeByte (uint8_t location, uint8_t data)
 
bool writeInteger (uint8_t location, uint16_t data)
 
bool writeLong (uint8_t location, uint32_t data)
 
char * getFirmwareVersion ()
 
char * getVendorID ()
 
char * getDeviceID ()
 
char * getFeatureSet ()
 
uint8_t getErrorCode ()
 
bool checkAddress ()
 
bool setAddress (uint8_t address)
 
- Public Member Functions inherited from BaseI2CDevice
 BaseI2CDevice (uint8_t i2c_address)
 
void initProtocol ()
 
uint8_t * readRegisters (uint8_t start_register, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0, bool clear_buffer=false)
 
uint8_t readByte (uint8_t location)
 
int16_t readInteger (uint8_t location)
 
uint32_t readLong (uint8_t location)
 
char * readString (uint8_t location, uint8_t bytes_to_read, uint8_t *buffer=0, uint8_t buffer_length=0)
 
bool writeRegisters (uint8_t start_register, uint8_t bytes_to_write, uint8_t *buffer=0)
 
bool writeByte (uint8_t location, uint8_t data)
 
bool writeInteger (uint8_t location, uint16_t data)
 
bool writeLong (uint8_t location, uint32_t data)
 
bool checkAddress ()
 
bool setAddress (uint8_t i2c_address)
 
uint8_t getAddress ()
 
uint8_t getWriteErrorCode ()
 
char * getFirmwareVersion ()
 
char * getVendorID ()
 
char * getDeviceID ()
 
char * getFeatureSet ()
 
- Public Member Functions inherited from SoftI2cMaster
uint8_t start (uint8_t addressRW)
 
void stop (void)
 
uint8_t restart (uint8_t addressRW)
 
uint8_t write (uint8_t b)
 
uint8_t read (uint8_t last)
 
 SoftI2cMaster (uint8_t devAddr)
 
void initProtocol (uint8_t sclPin=NULL, uint8_t sdaPin=NULL)
 
uint8_t * readRegisters (uint8_t startRegister, uint8_t bytes, uint8_t *buf=NULL)
 
bool writeRegistersWithLocation (int bytes, uint8_t *buf)
 
bool writeRegisters (uint8_t location, uint8_t bytes_to_write, uint8_t *buffer=0)
 
bool writeByte (uint8_t location, uint8_t data)
 
bool writeInteger (uint8_t location, uint16_t data)
 
bool writeLong (uint8_t location, uint32_t data)
 
char * readString (uint8_t startRegister, uint8_t bytes, uint8_t *buf=NULL, uint8_t len=0)
 
uint8_t readByte (uint8_t location)
 
int16_t readInteger (uint8_t location)
 
uint32_t readLong (uint8_t location)
 
char * getFirmwareVersion ()
 
char * getVendorID ()
 
char * getDeviceID ()
 
uint8_t getWriteErrorCode ()
 
bool checkAddress ()
 
bool setAddress (uint8_t address)
 

Public Attributes

void * mp_shield
 
uint8_t * _i2c_buffer
 
uint8_t m_protocol
 
- Public Attributes inherited from SoftI2cMaster
uint8_t * _so_buffer
 

Additional Inherited Members

- Static Public Attributes inherited from BaseI2CDevice
static uint8_t * _buffer = 0
 
static bool b_initialized = false
 
- Protected Member Functions inherited from BaseI2CDevice
void setWriteErrorCode (uint8_t code)
 

Detailed Description

This class implements I2C interfaces used by NXShield.

Constructor & Destructor Documentation

NXShieldI2C::NXShieldI2C ( uint8_t  i2c_address)

Class constructor for the NXShieldI2C; derived from both BaseI2CDevice and SoftI2cMaster; i2c address must be passes as a parameter

Member Function Documentation

char * NXShieldI2C::getDeviceID ( )

get the name of the device

uint8_t NXShieldI2C::getErrorCode ( )

get the error code of last i2c operation

char * NXShieldI2C::getFeatureSet ( )

get the features the device is capable of; only supported by some devices

char * NXShieldI2C::getFirmwareVersion ( )

get the firmware version of the device

char * NXShieldI2C::getVendorID ( )

get the name of the vendor of the device

void NXShieldI2C::init ( void *  shield,
SH_BankPort  bp 
)

initialized this i2c address with a pointed to the NXShield and the bankport it is connected to

uint8_t NXShieldI2C::readByte ( uint8_t  location)

Read a byte from specified location

Parameters
locationaddress to read at
Returns
a byte value read from the location
uint16_t NXShieldI2C::readInteger ( uint8_t  location)

Read an integer from specified location. Integer comprises of 2 bytes.

Parameters
locationaddress to read at
Returns
an integer value read from the location
uint32_t NXShieldI2C::readLong ( uint8_t  location)

Read a long from specified location. Long comprises of 4 bytes.

Parameters
locationaddress to read at
Returns
a long value read from the location
uint8_t * NXShieldI2C::readRegisters ( uint8_t  start_register,
uint8_t  bytes,
uint8_t *  buf 
)

read the specified number of bytes from the buffer starting from the specified start register

Parameters
start_registerlocation to start reading from
bytesNumber of bytes to read
bufbuffer to read the data into
Returns
the character array that was read.
char * NXShieldI2C::readString ( uint8_t  location,
uint8_t  bytes_to_read,
uint8_t *  buffer = 0,
uint8_t  buffer_length = 0 
)

Read a string from specified location

Parameters
locationaddress to read at
bytes_to_readnumber of bytes to read
bufferoptional, a buffer to read the data into.
buffer_lengthoptional, length of the buffer supplied.
Returns
a char array read from the location
bool NXShieldI2C::setAddress ( uint8_t  address)
set the i2c address for this device 
Parameters
addressnew device address.
bool NXShieldI2C::writeByte ( uint8_t  location,
uint8_t  data 
)
write one byte to the specified register location
Parameters
locationlocation to write to.
datathe data to write.
bool NXShieldI2C::writeInteger ( uint8_t  location,
uint16_t  data 
)
write two bytes (int) to the specified register location
Parameters
locationlocation to write to.
datathe data to write.
bool NXShieldI2C::writeLong ( uint8_t  location,
uint32_t  data 
)
write four bytes (long) to the specified register location 
Parameters
locationlocation to write to.
datathe data to write.
bool NXShieldI2C::writeRegisters ( uint8_t  start_register,
uint8_t  bytes_to_write,
uint8_t *  buffer = 0 
)
write data bytes to the i2c device starting from the start register
Parameters
start_registerlocation to write at.
bytes_to_writeNumber of bytes to write
buffer(optional) data buffer, if not supplied, data from internal buffer is used.

Member Data Documentation

uint8_t* NXShieldI2C::_i2c_buffer

Pointer to internal i2c buffer

uint8_t NXShieldI2C::m_protocol

global variable of the i2c protocol used

void* NXShieldI2C::mp_shield

Pointer to the NXShield


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