Documentation ¶
Overview ¶
Package accel3xdigital allows developers to read x,y,z and acceleratation. Currently this library doesn't support any of the interrupts: Front/Back Interrupt, Up/Down/Left/Right Interrupt, Tap Detection Interrupt, GINT (real-time motion tracking), Shake on X-axis, Shake on Y-axis, and Shake on Z-axis.
Example ¶
package main import ( "fmt" "time" "github.com/goiot/devices/accel3xdigital" "golang.org/x/exp/io/i2c" ) func main() { accel, err := accel3xdigital.Open(&i2c.Devfs{ Dev: "/dev/i2c-1", }) if err != nil { panic(err) } defer accel.Close() for i := 0; i < 20; i++ { accel.Update() fmt.Println(accel.State) time.Sleep(500 * time.Millisecond) } }
Output:
Index ¶
Examples ¶
Constants ¶
const ( // Standby Mode is ideal for battery operated products. When Standby Mode is active the device outputs are turned off // providing a significant reduction in operating current. When the device is in Standby Mode the current will be reduced to // approximately 3 µA. Standby Mode is entered as soon as both analog and digital power supplies are up. // In this mode, the device can read and write to the registers with I2C, but no new measurements can be taken. StandBy = Mode(accelStandBy) // Active Mode, continuous measurement on all three axes is enabled. In addition, the user can choose to enable: // Shake Detection, Tap Detection, Orientation Detection, and/or Auto-Wake/Sleep Feature and in this mode the digital analysis for // any of these functions is done. Active = Mode(accelActive) )
Variables ¶
var ( // ErrNotReady warns the user that the device isn't not (yet) ready ErrNotReady = errors.New("device is not ready") )
Functions ¶
This section is empty.
Types ¶
type Accel3xDigital ¶
type Accel3xDigital struct { Device *i2c.Device State *State // TapEnabled lets devs know if the feature is on or off (default) TapEnabled bool }
Accel3xDigital reresents the Grove 3-Axis Digital Accelerometer(±1.5g)
func Open ¶
func Open(o driver.Opener) (*Accel3xDigital, error)
Open connects to the passed driver and sets things up. At this point the sensor will sample 32 times a second and will store its information in registries you can read from by calling update. Note that by default the tap detection is not on. You need to enable this feature manually.
func (*Accel3xDigital) ChangeMode ¶
func (a *Accel3xDigital) ChangeMode(m Mode) (err error)
ChangeMode allows developers to switch between standy and active (default).
func (*Accel3xDigital) Close ¶
func (a *Accel3xDigital) Close() error
Close puts the device on standby
func (*Accel3xDigital) EnableTap ¶
func (a *Accel3xDigital) EnableTap() error
Enable tap enables checking for taps by increasing the sample rate
func (*Accel3xDigital) SetTapSensitivity ¶
func (a *Accel3xDigital) SetTapSensitivity(n uint8) error
SetTapSensitivity sets the debounce filtering requirement to n adjacent tap detection tests to be the same to trigger a tap event. Note that the sampling rate is 120 samples/second when tap is enabled.
func (*Accel3xDigital) Update ¶
func (a *Accel3xDigital) Update() error
Update reads the sensor and update the state in memory
type Mode ¶
type Mode byte
Mode The sensor has three power modes: Off Mode, Standby Mode, and Active Mode to offer the customer different power consumption options. The sensor is only capable of running in one of these modes at a time.
type Position ¶
type Position int
Position indicates the position of the sensor/device
const ( // Unknown condition of up or down or left or right Unknown Position = iota // Left is true if in landscape mode to the left Left // Right is true if in landscape mode to the right Right // Down is true if standing vertically in inverted orientation Down // Up is true if standing vertically in normal orientation Up )
type State ¶
type State struct { // Front is true if the equipment is lying on its front Front bool // Back is true if the equipment is lying on its back Back bool Position Position // Tapped reports that the device was tapped, after reading the data once, the flag is cleared. Tapped bool // Shaken reports that the device was shaken, after reading the data once, the flag is cleared. Shaken bool // Alert can be triggered if there was a race condition when we tried to read (the sensor was updating the data at the same time) // If you get an alert, ignore the data and read again. Alert bool // X axis value X float64 // Y axis value Y float64 // Z axis value Z float64 }
State contains the last read state of the device
func (*State) Acceleration ¶
Acceleration returns the acceleration (g) for each axis (x,y,z)