Documentation ¶
Index ¶
- Variables
- type Accelerometer
- func (a *Accelerometer) GetMode() (AccelerometerMode, error)
- func (a *Accelerometer) GetRange() (AccelerometerRange, error)
- func (a *Accelerometer) Sense() (physic.Force, physic.Force, physic.Force, error)
- func (a *Accelerometer) SenseRaw() (int16, int16, int16, error)
- func (a *Accelerometer) SetMode(mode AccelerometerMode) error
- func (a *Accelerometer) SetRange(range_ AccelerometerRange) error
- func (a *Accelerometer) String() string
- type AccelerometerDatasheet
- type AccelerometerMode
- type AccelerometerOption
- type AccelerometerOptionFunc
- type AccelerometerOpts
- type AccelerometerRange
- type Magnetometer
- func (m *Magnetometer) GetGain() (MagnetometerGain, error)
- func (m *Magnetometer) GetRate() (MagnetometerRate, error)
- func (m *Magnetometer) SenseRaw() (int16, int16, int16, error)
- func (m *Magnetometer) SenseRelativeTemperature() (physic.Temperature, error)
- func (m *Magnetometer) SetGain(gain MagnetometerGain) error
- func (m *Magnetometer) SetRate(mode MagnetometerRate) error
- type MagnetometerDatasheet
- type MagnetometerGain
- type MagnetometerOption
- func WithDatasheet(datasheet MagnetometerDatasheet) MagnetometerOption
- func WithGain(gain MagnetometerGain) MagnetometerOption
- func WithMagnetometerAddress(addr uint16) MagnetometerOption
- func WithMagnetometerSensorType(sensorType SensorType) MagnetometerOption
- func WithRate(rate MagnetometerRate) MagnetometerOption
- type MagnetometerOptionFunc
- type MagnetometerOpts
- type MagnetometerRate
- type SensorType
Constants ¶
This section is empty.
Variables ¶
var DefaultAccelerometerOpts = AccelerometerOpts{ Range: ACCELEROMETER_RANGE_4G, Mode: ACCELEROMETER_MODE_NORMAL, }
DefaultAccelerometerOpts is the recommended default options.
var DefaultMagnetometerOpts = MagnetometerOpts{ Gain: MAGNETOMETER_GAIN_4_0, Rate: MAGNETOMETER_RATE_30, }
DefaultMagnetometerOpts is the recommended default options.
Functions ¶
This section is empty.
Types ¶
type Accelerometer ¶
type Accelerometer struct {
// contains filtered or unexported fields
}
This is a handle to the LSM303 accelerometer sensor.
func NewAccelerometer ¶
func NewAccelerometer(bus i2c.Bus, opts ...AccelerometerOption) (*Accelerometer, error)
New accelerometer opens a handle to an LSM303 accelerometer sensor.
func (*Accelerometer) GetMode ¶
func (a *Accelerometer) GetMode() (AccelerometerMode, error)
func (*Accelerometer) GetRange ¶
func (a *Accelerometer) GetRange() (AccelerometerRange, error)
func (*Accelerometer) SetMode ¶
func (a *Accelerometer) SetMode(mode AccelerometerMode) error
func (*Accelerometer) SetRange ¶
func (a *Accelerometer) SetRange(range_ AccelerometerRange) error
func (*Accelerometer) String ¶
func (a *Accelerometer) String() string
type AccelerometerDatasheet ¶
type AccelerometerDatasheet struct { ADDRESS uint16 WHO_AM_I_A uint8 CHIP_ID uint8 CTRL_REG1_A uint8 // CTRL_REG2_A uint8 // CTRL_REG3_A uint8 CTRL_REG4_A uint8 // CTRL_REG5_A uint8 // CTRL_REG6_A uint8 // REFERENCE_A uint8 // STATUS_REG_A uint8 OUT_X_L_A uint8 OUT_X_H_A uint8 OUT_Y_L_A uint8 OUT_Y_H_A uint8 OUT_Z_L_A uint8 OUT_Z_H_A uint8 }
type AccelerometerMode ¶
type AccelerometerMode int
const ( ACCELEROMETER_MODE_NORMAL AccelerometerMode = iota ACCELEROMETER_MODE_HIGH_RESOLUTION ACCELEROMETER_MODE_LOW_POWER )
func (AccelerometerMode) String ¶
func (mode AccelerometerMode) String() string
type AccelerometerOption ¶
type AccelerometerOption interface {
Apply(*Accelerometer)
}
AccelerometerOption configures a LSM303 accelerometer.
func WithAccelerometerAddress ¶
func WithAccelerometerAddress(addr uint16) AccelerometerOption
WithAccelerometerAddress can be used to specify I²C address for Accelerometer. Default is 0x19 for LSM303 and 0x1E for LSM303C.
func WithAccelerometerSensorType ¶
func WithAccelerometerSensorType(sensorType SensorType) AccelerometerOption
WithAccelerometerSensorType can be used to specify LSM303 family sensor type. Default is LSM303DLHC.
func WithMode ¶
func WithMode(mode AccelerometerMode) AccelerometerOption
WithMode can be used to specify accelerometer mode. Default is ACCELEROMETER_MODE_NORMAL.
func WithRange ¶
func WithRange(rng AccelerometerRange) AccelerometerOption
WithRange can be used to specify accelerometer range. Default is ACCELEROMETER_RANGE_4G.
type AccelerometerOptionFunc ¶
type AccelerometerOptionFunc func(*Accelerometer)
AccelerometerOptionFunc is a function that configures a device.
func (AccelerometerOptionFunc) Apply ¶
func (f AccelerometerOptionFunc) Apply(dev *Accelerometer)
Apply calls OptionFunc on device instance
type AccelerometerOpts ¶
type AccelerometerOpts struct { Range AccelerometerRange Mode AccelerometerMode }
Opts holds the configuration options. These options are obsolete, use WithRange and\or WithMode instead.
func (AccelerometerOpts) Apply ¶
func (ao AccelerometerOpts) Apply(accelerometer *Accelerometer)
type AccelerometerRange ¶
type AccelerometerRange int
const ( ACCELEROMETER_RANGE_2G AccelerometerRange = iota ACCELEROMETER_RANGE_4G ACCELEROMETER_RANGE_8G ACCELEROMETER_RANGE_16G )
func (AccelerometerRange) String ¶
func (range_ AccelerometerRange) String() string
type Magnetometer ¶
type Magnetometer struct {
// contains filtered or unexported fields
}
This is a handle to the LSM303 magnetometer sensor.
func NewMagnetometer ¶
func NewMagnetometer(bus i2c.Bus, opts ...MagnetometerOption) (*Magnetometer, error)
New magnetometer opens a handle to an LSM303 magnetometer sensor.
func (*Magnetometer) GetGain ¶
func (m *Magnetometer) GetGain() (MagnetometerGain, error)
func (*Magnetometer) GetRate ¶
func (m *Magnetometer) GetRate() (MagnetometerRate, error)
func (*Magnetometer) SenseRelativeTemperature ¶
func (m *Magnetometer) SenseRelativeTemperature() (physic.Temperature, error)
The temperature sensor is technically on the same line as the magnetometer, so that's why I'm putting as a Magnetometer method. Note that the sensor is uncalibrated, so it can't return an absolute temperature, but from what I've read online, adding about 20 degrees C should get you close.
func (*Magnetometer) SetGain ¶
func (m *Magnetometer) SetGain(gain MagnetometerGain) error
func (*Magnetometer) SetRate ¶
func (m *Magnetometer) SetRate(mode MagnetometerRate) error
type MagnetometerDatasheet ¶
type MagnetometerDatasheet struct { ADDRESS uint16 WHO_AM_I_M uint8 CHIP_ID uint8 CRA_REG_M uint8 CRB_REG_M uint8 MR_REG_M uint8 OUT_X_H_M uint8 OUT_X_L_M uint8 OUT_Z_H_M uint8 OUT_Z_L_M uint8 OUT_Y_H_M uint8 OUT_Y_L_M uint8 // SR_REG_M uint8 IRA_REG_M uint8 // IRB_REG_M uint8 // IRC_REG_M uint8 TEMP_OUT_H_M uint8 TEMP_OUT_L_M uint8 }
type MagnetometerGain ¶
type MagnetometerGain int
const ( MAGNETOMETER_GAIN_1_3 MagnetometerGain = iota MAGNETOMETER_GAIN_1_9 MAGNETOMETER_GAIN_2_5 MAGNETOMETER_GAIN_4_0 MAGNETOMETER_GAIN_4_7 MAGNETOMETER_GAIN_5_6 MAGNETOMETER_GAIN_8_1 )
func (MagnetometerGain) String ¶
func (mode MagnetometerGain) String() string
type MagnetometerOption ¶
type MagnetometerOption interface {
Apply(*Magnetometer)
}
MagnetometerOption configures a LSM303 magnetometer.
func WithDatasheet ¶
func WithDatasheet(datasheet MagnetometerDatasheet) MagnetometerOption
WithDatasheet can be used to specify datasheet addresses, in case new LSM family device appears.
func WithGain ¶
func WithGain(gain MagnetometerGain) MagnetometerOption
WithGain can be used to specify magnetometer gain. Default is MAGNETOMETER_GAIN_4_0.
func WithMagnetometerAddress ¶
func WithMagnetometerAddress(addr uint16) MagnetometerOption
WithMagnetometerAddress can be used to specify I²C address for Magnetometer. Default is 0x1E.
func WithMagnetometerSensorType ¶
func WithMagnetometerSensorType(sensorType SensorType) MagnetometerOption
WithMagnetometerSensorType can be used to specify LSM303 family sensor type. Default is LSM303DLHC.
func WithRate ¶
func WithRate(rate MagnetometerRate) MagnetometerOption
WithRange can be used to specify magnetometer rate. Default is MAGNETOMETER_RATE_30.
type MagnetometerOptionFunc ¶
type MagnetometerOptionFunc func(*Magnetometer)
MagnetometerOptionFunc is a function that configures a device.
func (MagnetometerOptionFunc) Apply ¶
func (f MagnetometerOptionFunc) Apply(dev *Magnetometer)
Apply calls OptionFunc on device instance
type MagnetometerOpts ¶
type MagnetometerOpts struct { Gain MagnetometerGain Rate MagnetometerRate }
Opts holds the configuration options. These options are obsolete, use WithGain and\or WithRate instead.
func (MagnetometerOpts) Apply ¶
func (mo MagnetometerOpts) Apply(magnetometer *Magnetometer)
type MagnetometerRate ¶
type MagnetometerRate int
const ( MAGNETOMETER_RATE_0_75 MagnetometerRate = iota MAGNETOMETER_RATE_1_5 MAGNETOMETER_RATE_3_0 MAGNETOMETER_RATE_7_5 MAGNETOMETER_RATE_15 MAGNETOMETER_RATE_30 MAGNETOMETER_RATE_75 MAGNETOMETER_RATE_220 )
func (MagnetometerRate) String ¶
func (range_ MagnetometerRate) String() string
type SensorType ¶
type SensorType string
const ( LSM303DLHC SensorType = "LSM303DLHC" LSM303AGR SensorType = "LSM303AGR" LSM303C SensorType = "LSM303C" )