upm  1.7.1
Sensor/Actuator repository for libmraa (v2.0.0)
Public Types | Public Member Functions | Static Public Attributes | Protected Attributes

API for the DS2413 1-Wire Dual Channel Addressable Switch. More...

Detailed Description

The DS2413 is a dual-channel programmable I/O 1-Wire(r) chip. The PIO outputs are configured as open-drain and provide up to 20mA continuous sink capability and off-state operating voltage up to 28V. Control and sensing of the PIO pins is performed with a dedicated device-level command protocol.

This device requires the use of a UART to provide access to a Dallas 1-wire bus, via a new facility supported by MRAA (once the relevant PR is accepted), using the UartOW access class. It is important to realize that the UART is only being used to access and control a Dallas 1-wire compliant bus, it is not actually a UART device.

Multiple DS2413 devices can be connected to this bus. This module will identify all such devices connected, and allow you to access them using an index starting at 0.

// Instantiate a DS2413 Module on a Dallas 1-wire bus connected to UART 0
upm::DS2413 sensor(0);
// find all of the DS2413 devices present on the bus
sensor.init();
// how many devices were found?
cout << "Found " << sensor.devicesFound() << " device(s)" << endl;
// read the gpio and latch values from the first device
// the lower 4 bits are of the form:
// <gpioB latch> <gpioB value> <gpioA latch> <gpioA value>
cout << "GPIO device 0 values: " << sensor.readGpios(0) << endl;
// set the gpio latch values of the first device
cout << "Setting GPIO latches to on" << endl;
sensor.writeGpios(0, 0x03);
cout << "Exiting..." << endl;

Public Types

enum  DS2413_CMD_T { ACCESS_READ = 0xf5, ACCESS_WRITE = 0x5a }
 
enum  DS2413_ACK_T { ACK_SUCCESS = 0xaa, ACK_FAILURE = 0xff }
 

Public Member Functions

 DS2413 (int uart=DS2413_DEFAULT_UART)
 
 ~DS2413 ()
 
void init ()
 
int devicesFound ()
 
int readGpios (int index=0)
 
void writeGpios (int index, int value)
 
std::string getId (int index)
 

Static Public Attributes

static const uint8_t DS2413_FAMILY_CODE = 0x3a
 

Protected Attributes

mraa::UartOW m_uart
 
int m_devicesFound
 
std::map< int, std::string > m_deviceMap
 

Constructor & Destructor Documentation

DS2413 ( int  uart = DS2413_DEFAULT_UART)

DS2413 object constructor

Parameters
uartDefault UART to use (0 or 1). Default is 0.
~DS2413 ( )

DS2413 object destructor

Member Function Documentation

void init ( )

This method will search the 1-wire bus and store information on each device detected on the bus. If no devices are found, an exception is thrown. Once this function completes successfully, you can use devicesFound() to determine how many devices were detected.

int devicesFound ( )
inline

This method will return the number of DS2413 devices that were found on the bus.

Returns
number of DS2413's that were found on the bus

Here is the call graph for this function:

int readGpios ( int  index = 0)

Read the GPIO latches and values for a given device. Only the lower 4 bits of the return value have any meaning. The bits are formatted as follows (from msb to lsb): <gpioB latch>=""> <gpioB value>=""> <gpioA latch>=""> <gpioA value>="">

Parameters
indexThe device index to access (starts at 0). Default is the first device (index = 0)
Returns
the 4 bit status of the 2 gpios

Here is the caller graph for this function:

void writeGpios ( int  index,
int  value 
)

Write the given values to the gpio latches for a given device. Only the lower 2 bits of the value have any meaning. The lsb is gor gpioA and the next lsb is for gpioB: <gpioB latch>=""> <gpioA latch>="">

Parameters
indexThe device index to access (starts at 0).
valuethe value to write to the gpio latches

Here is the caller graph for this function:

std::string getId ( int  index)
inline

Return an 8 byte string representing the unique device ID for a given device index. If the index is invalid, an empty strig will be returned.

Parameters
indexThe device index to access (starts at 0).
Returns
8 byte string representing the 1-wire device's unique rom code.

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