Documentation ¶
Index ¶
- Constants
- Variables
- type Accelerometer
- func (accelerometer *Accelerometer) GetMode() (AccelerometerMode, error)
- func (accelerometer *Accelerometer) GetRange() (AccelerometerRange, error)
- func (accelerometer *Accelerometer) Sense() (physic.Force, physic.Force, physic.Force, error)
- func (accelerometer *Accelerometer) SenseRaw() (int16, int16, int16, error)
- func (accelerometer *Accelerometer) SetMode(mode AccelerometerMode) error
- func (accelerometer *Accelerometer) SetRange(range_ AccelerometerRange) error
- func (accelerometer *Accelerometer) String() string
- type AccelerometerMode
- type AccelerometerOpts
- type AccelerometerRange
- type Magnetometer
- func (magnetometer *Magnetometer) GetGain() (MagnetometerGain, error)
- func (magnetometer *Magnetometer) GetRate() (MagnetometerRate, error)
- func (magnetometer *Magnetometer) SenseRaw() (int16, int16, int16, error)
- func (magnetometer *Magnetometer) SenseRelativeTemperature() (physic.Temperature, error)
- func (magnetometer *Magnetometer) SetGain(gain MagnetometerGain) error
- func (magnetometer *Magnetometer) SetRate(mode MagnetometerRate) error
- type MagnetometerGain
- type MagnetometerOpts
- type MagnetometerRate
Constants ¶
const ( // Copied from the data sheet. Unused values are commented out. ACCELEROMETER_IDENTIFY = 0x0F ACCELEROMETER_CTRL_REG1_A = 0x20 //ACCELEROMETER_CTRL_REG2_A = 0x21 //ACCELEROMETER_CTRL_REG3_A = 0x22 ACCELEROMETER_CTRL_REG4_A = 0x23 //ACCELEROMETER_CTRL_REG5_A = 0x24 //ACCELEROMETER_CTRL_REG6_A = 0x25 //ACCELEROMETER_REFERENCE_A = 0x26 //ACCELEROMETER_STATUS_REG_A = 0x27 ACCELEROMETER_OUT_X_L_A = 0x28 ACCELEROMETER_OUT_X_H_A = 0x29 ACCELEROMETER_OUT_Y_L_A = 0x2A ACCELEROMETER_OUT_Y_H_A = 0x2B ACCELEROMETER_OUT_Z_L_A = 0x2C ACCELEROMETER_OUT_Z_H_A = 0x2D )
const ( // Copied from the data sheet. Unused values are commented out. MAGNETOMETER_CRA_REG_M = 0x00 MAGNETOMETER_CRB_REG_M = 0x01 MAGNETOMETER_MR_REG_M = 0x02 MAGNETOMETER_OUT_X_H_M = 0x03 MAGNETOMETER_OUT_X_L_M = 0x04 MAGNETOMETER_OUT_Z_H_M = 0x05 MAGNETOMETER_OUT_Z_L_M = 0x06 MAGNETOMETER_OUT_Y_H_M = 0x07 MAGNETOMETER_OUT_Y_L_M = 0x08 //MAGNETOMETER_SR_REG_M = 0x09 MAGNETOMETER_IRA_REG_M = 0x0A //MAGNETOMETER_IRB_REG_M = 0x0B //MAGNETOMETER_IRC_REG_M = 0x0C MAGNETOMETER_TEMP_OUT_H_M = 0x31 MAGNETOMETER_TEMP_OUT_L_M = 0x32 )
const ACCELEROMETER_ADDRESS = 0x19
const MAGNETOMETER_ADDRESS = 0x1E
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 *AccelerometerOpts) (*Accelerometer, error)
New accelerometer opens a handle to an LSM303 accelerometer sensor.
func (*Accelerometer) GetMode ¶
func (accelerometer *Accelerometer) GetMode() (AccelerometerMode, error)
func (*Accelerometer) GetRange ¶
func (accelerometer *Accelerometer) GetRange() (AccelerometerRange, error)
func (*Accelerometer) SenseRaw ¶
func (accelerometer *Accelerometer) SenseRaw() (int16, int16, int16, error)
func (*Accelerometer) SetMode ¶
func (accelerometer *Accelerometer) SetMode(mode AccelerometerMode) error
func (*Accelerometer) SetRange ¶
func (accelerometer *Accelerometer) SetRange(range_ AccelerometerRange) error
func (*Accelerometer) String ¶
func (accelerometer *Accelerometer) String() string
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 AccelerometerOpts ¶
type AccelerometerOpts struct { Range AccelerometerRange Mode AccelerometerMode }
Opts holds the configuration options.
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 *MagnetometerOpts) (*Magnetometer, error)
New magnetometer opens a handle to an LSM303 magnetometer sensor.
func (*Magnetometer) GetGain ¶
func (magnetometer *Magnetometer) GetGain() (MagnetometerGain, error)
func (*Magnetometer) GetRate ¶
func (magnetometer *Magnetometer) GetRate() (MagnetometerRate, error)
func (*Magnetometer) SenseRaw ¶
func (magnetometer *Magnetometer) SenseRaw() (int16, int16, int16, error)
func (*Magnetometer) SenseRelativeTemperature ¶
func (magnetometer *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 (magnetometer *Magnetometer) SetGain(gain MagnetometerGain) error
func (*Magnetometer) SetRate ¶
func (magnetometer *Magnetometer) SetRate(mode MagnetometerRate) error
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 MagnetometerOpts ¶
type MagnetometerOpts struct { Gain MagnetometerGain Rate MagnetometerRate }
Opts holds the configuration options.
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