Documentation ¶
Index ¶
- Constants
- type BusResolution
- type BusVoltageTolerance
- type CalibrationSetting
- type Configuration
- type Gain
- type OperatingMode
- type Sensor
- func (me *Sensor) Close() error
- func (me *Sensor) GetBusVoltage() (float64, error)
- func (me *Sensor) GetCurrent() (float64, error)
- func (me *Sensor) GetPower() (float64, error)
- func (me *Sensor) GetShuntVoltage() (float64, error)
- func (me *Sensor) SetCalibrationRegister(val CalibrationSetting) error
- func (me *Sensor) SetConfig(config Configuration) error
- func (me *Sensor) SetPowerSavingMode(enabled bool) error
- type ShuntResolution
Constants ¶
const ( // BusDefault bind power sensor to the first available I2C bus BusDefault string = "" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BusResolution ¶
type BusResolution uint16
BusResolution the ADC bit resolution for the bus
const ( // BusRes9 9 bit resolution BusRes9 BusResolution = 0x0000 // BusRes10 10 bit resolution BusRes10 BusResolution = 0x0080 // BusRes11 11 bit resolution BusRes11 BusResolution = 0x0100 // BusRes12 12 bit resolution BusRes12 BusResolution = 0x0180 )
type BusVoltageTolerance ¶
type BusVoltageTolerance uint16
BusVoltageTolerance defines the tolerated range of voltage values
const ( // BusVoltageRange16 0-16 Volt range BusVoltageRange16 BusVoltageTolerance = 0x0000 // BusVoltageRange32 0-32 Volt range BusVoltageRange32 BusVoltageTolerance = 0x2000 )
type CalibrationSetting ¶
type CalibrationSetting uint16
CalibrationSetting predefined sensor calibration settings
const ( // V32A2 calibration for 32 Volts, 2 Amps V32A2 CalibrationSetting = 4096 // V32A1 calibration for 32 Volts, 1 Amp V32A1 CalibrationSetting = 10240 // V16A04 calibration for 16 Volts, 400 mA V16A04 CalibrationSetting = 8192 )
type Configuration ¶
type Configuration struct { Tolerance BusVoltageTolerance ShuntResolution ShuntResolution BusResolution BusResolution OperatingMode OperatingMode Gain Gain }
Configuration INA219 configuration bit flags
func DefaultConfiguration ¶
func DefaultConfiguration() Configuration
DefaultConfiguration returns the default configuration for the INA219 sensor
func (Configuration) Flatten ¶
func (me Configuration) Flatten() uint16
Flatten combines all the bit flags in this configuration into a single 16 bit value
type OperatingMode ¶
type OperatingMode uint16
OperatingMode defines an operating mode for the INA219 sensor
const ( // ModePowerDown power down the sensor ModePowerDown OperatingMode = 0x0000 // ModeShuntTriggered read shunt sensor values ModeShuntTriggered OperatingMode = 0x0001 // ModeBusTriggered read bus sensor values ModeBusTriggered OperatingMode = 0x0002 // ModeShuntBusTriggered read shunt and bus sensor values ModeShuntBusTriggered OperatingMode = 0x0003 // ModeADCOff turn ADC off ModeADCOff OperatingMode = 0x0004 // ModeShuntContinuous read shunt sensor values continuously ModeShuntContinuous OperatingMode = 0x0005 // ModeBusContinuous read bus sensor values continuously ModeBusContinuous OperatingMode = 0x0006 // ModeShuntBusContinuous read shunt and bus sensor values continuously ModeShuntBusContinuous OperatingMode = 0x0007 )
type Sensor ¶
type Sensor struct {
// contains filtered or unexported fields
}
Sensor handles interfacing with the INA219 power sensor via I2C
func (*Sensor) GetBusVoltage ¶
GetBusVoltage returns the current voltage from the bus sensor in V, or any errors encountered while reading the sensor
func (*Sensor) GetCurrent ¶
GetCurrent returns the current amp draw from the sensor in mA, or any errors encountered while reading the sensor
func (*Sensor) GetPower ¶
GetPower returns the current power from the sensor in mW, or any errors encountered while reading the sensor
func (*Sensor) GetShuntVoltage ¶
GetShuntVoltage returns the current voltage from the shunt sensor in mV, or any errors encountered while reading the sensor
func (*Sensor) SetCalibrationRegister ¶
func (me *Sensor) SetCalibrationRegister(val CalibrationSetting) error
SetCalibrationRegister set the calibration value for this sensor. Returns any errors that occur during calibration writing
func (*Sensor) SetConfig ¶
func (me *Sensor) SetConfig(config Configuration) error
SetConfig set the configuration options for this sensor
func (*Sensor) SetPowerSavingMode ¶
SetPowerSavingMode enables or disables the power saving operating mode on this sensor. Returns any errors that occur during operating mode change.
type ShuntResolution ¶
type ShuntResolution uint16
ShuntResolution the bit resolution for samples taken by the shunt sensor
const ( // Res9Bit 9 bit ADC resolution Res9Bit ShuntResolution = 0x0000 // Res10Bit 10 bit ADC resolution Res10Bit ShuntResolution = 0x0008 // Res11Bit 11 bit ADC resolution Res11Bit ShuntResolution = 0x0010 // Res12Bit 12 bit ADC resolution Res12Bit ShuntResolution = 0x0018 // Res12BitX2 12 bit ADC resolution sampled 2 times Res12BitX2 ShuntResolution = 0x0048 // Res12BitX4 12 bit ADC resolution sampled 4 times Res12BitX4 ShuntResolution = 0x0050 // Res12BitX8 12 bit ADC resolution sampled 8 times Res12BitX8 ShuntResolution = 0x0058 // Res12BitX16 12 bit ADC resolution sampled 16 times Res12BitX16 ShuntResolution = 0x0060 // Res12BitX32 12 bit ADC resolution sampled 32 times Res12BitX32 ShuntResolution = 0x0068 // Res12BitX64 12 bit ADC resolution sampled 64 times Res12BitX64 ShuntResolution = 0x0070 // Res12BitX128 12 bit ADC resolution sampled 128 times Res12BitX128 ShuntResolution = 0x0078 )