DUDS
Distributed Update of Data from Something
duds::hardware::devices::instruments::INA219 Class Reference

Preliminary support for TI's INA219 voltage and current sensor. More...

#include <INA219.hpp>

Inheritance diagram for duds::hardware::devices::instruments::INA219:
Collaboration diagram for duds::hardware::devices::instruments::INA219:

Public Member Functions

 INA219 (std::unique_ptr< duds::hardware::interface::Smbus > &c, double sr)
 
 ~INA219 ()
 
duds::data::Quantity busCurrent () const
 Returns the computed bus current using the sampled shunt voltage and the shunt resistance. More...
 
duds::data::Quantity busPower () const
 Returns the computed bus power using the sampled bus voltage and the computed bus current. More...
 
duds::data::Quantity busVoltage () const
 Returns the sampled bus voltage. More...
 
duds::data::Quantity maxCurrent () const
 Returns the maximum current that can be measured by the device. More...
 
void sample ()
 Reads sample data from the device. More...
 
duds::data::Quantity shuntResistance () const
 Returns the shunt resistance. More...
 
duds::data::Quantity shuntVoltage () const
 Returns the sampled shunt voltage. More...
 
void vals (std::int16_t &sV, std::int16_t &bV)
 

Private Attributes

std::int16_t busV
 The raw data for the sampled bus voltage. More...
 
std::unique_ptr< duds::hardware::interface::Smbuscom
 Communication bus. More...
 
double shunt
 Shunt resistance; used to compute current. More...
 
std::int16_t shuntV
 The raw data for the sampled shunt voltage. More...
 

Detailed Description

Preliminary support for TI's INA219 voltage and current sensor.

This device measures two voltages in a way that allows computation of current and power. The current must pass through a shunt resistor. The voltage across that resistor, and the voltage between there and ground, is measured. This class can compute the power and current based on these measurements, but it needs to know the shunt resistance for these computations.

Normally uses address 0x40. Does not use PEC; not really a SMBus device.

Author
Jeff Jackowski
Examples:
ina219test.cpp.

Definition at line 31 of file INA219.hpp.

Constructor & Destructor Documentation

◆ INA219()

duds::hardware::devices::instruments::INA219::INA219 ( std::unique_ptr< duds::hardware::interface::Smbus > &  c,
double  sr 
)
Todo:
Find way to reject bad SMBus config.

Maybe find way to produce SMBus config.

Parameters
cThe SMBus interface to use for communication. PEC must be disabled.
srThe shunt resistance in ohms.

Definition at line 14 of file INA219.cpp.

◆ ~INA219()

duds::hardware::devices::instruments::INA219::~INA219 ( )

Definition at line 25 of file INA219.cpp.

Member Function Documentation

◆ busCurrent()

duds::data::Quantity duds::hardware::devices::instruments::INA219::busCurrent ( ) const

Returns the computed bus current using the sampled shunt voltage and the shunt resistance.

Examples:
ina219test.cpp.

Definition at line 48 of file INA219.cpp.

Referenced by busPower().

◆ busPower()

duds::data::Quantity duds::hardware::devices::instruments::INA219::busPower ( ) const

Returns the computed bus power using the sampled bus voltage and the computed bus current.

Definition at line 52 of file INA219.cpp.

◆ busVoltage()

duds::data::Quantity duds::hardware::devices::instruments::INA219::busVoltage ( ) const

Returns the sampled bus voltage.

Examples:
ina219test.cpp.

Definition at line 44 of file INA219.cpp.

Referenced by busPower().

◆ maxCurrent()

duds::data::Quantity duds::hardware::devices::instruments::INA219::maxCurrent ( ) const

Returns the maximum current that can be measured by the device.

This value changes with the shunt resistance.

Definition at line 32 of file INA219.cpp.

◆ sample()

void duds::hardware::devices::instruments::INA219::sample ( )

Reads sample data from the device.

Examples:
ina219test.cpp.

Definition at line 56 of file INA219.cpp.

◆ shuntResistance()

duds::data::Quantity duds::hardware::devices::instruments::INA219::shuntResistance ( ) const

Returns the shunt resistance.

Definition at line 36 of file INA219.cpp.

Referenced by busCurrent().

◆ shuntVoltage()

duds::data::Quantity duds::hardware::devices::instruments::INA219::shuntVoltage ( ) const

Returns the sampled shunt voltage.

Examples:
ina219test.cpp.

Definition at line 40 of file INA219.cpp.

Referenced by busCurrent().

◆ vals()

void duds::hardware::devices::instruments::INA219::vals ( std::int16_t &  sV,
std::int16_t &  bV 
)
inline
Examples:
ina219test.cpp.

Definition at line 93 of file INA219.hpp.

Member Data Documentation

◆ busV

std::int16_t duds::hardware::devices::instruments::INA219::busV
private

The raw data for the sampled bus voltage.

Definition at line 47 of file INA219.hpp.

Referenced by busVoltage(), sample(), and vals().

◆ com

std::unique_ptr<duds::hardware::interface::Smbus> duds::hardware::devices::instruments::INA219::com
private

Communication bus.

Definition at line 35 of file INA219.hpp.

Referenced by INA219(), sample(), and ~INA219().

◆ shunt

double duds::hardware::devices::instruments::INA219::shunt
private

Shunt resistance; used to compute current.

Definition at line 39 of file INA219.hpp.

Referenced by maxCurrent(), and shuntResistance().

◆ shuntV

std::int16_t duds::hardware::devices::instruments::INA219::shuntV
private

The raw data for the sampled shunt voltage.

Definition at line 43 of file INA219.hpp.

Referenced by sample(), shuntVoltage(), and vals().


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