iio

package
v0.0.0-...-9474aff Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 28, 2022 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BootTime

func BootTime() (time.Duration, error)

BootTime returns the duration from the boot time of the DUT to now.

func Validate

func Validate(rs []*SensorReading, start, end time.Duration, sn *Sensor, collectTime time.Duration) error

Validate ensures the sample timestamps are within expected range.

Types

type ActivityID

type ActivityID int

ActivityID is the ID of the activity which is reported by the EC.

const (
	// SigMotionID is the ID of the activity, significant motion.
	SigMotionID ActivityID = 1
	// DoubleTapID is the ID of the activity, double tap.
	DoubleTapID ActivityID = 2
	// OrientationID is the ID of the activity, orientation.
	OrientationID ActivityID = 3
	// OnBodyDetectionID is the ID of the activity, on-body detection.
	OnBodyDetectionID ActivityID = 4
)

type Buffer

type Buffer struct {
	Channels []*ChannelSpec
	// contains filtered or unexported fields
}

Buffer provides a means to read continuous data captured from a sensor. See https://01.org/linuxgraphics/gfx-docs/drm/driver-api/iio/buffers.html#buffers.

func (*Buffer) Close

func (b *Buffer) Close() error

Close closes an open buffer file and disables the buffer.

func (*Buffer) Open

func (b *Buffer) Open() (<-chan BufferData, error)

Open enables a sensor's buffer for reading and returns a channel to read data from the buffer.

func (*Buffer) SetLength

func (b *Buffer) SetLength(len int) error

SetLength sets the maximun number of elements that can be buffered in the sensor's fifo.

type BufferData

type BufferData struct {
	// contains filtered or unexported fields
}

BufferData is a single reading of data from a sensor's buffer.

func (*BufferData) GetRaw

func (d *BufferData) GetRaw(ix int) ([]byte, error)

GetRaw gets the raw bytes from channel ix.

func (*BufferData) Int16

func (d *BufferData) Int16(ix int) (int16, error)

Int16 gets an int16 from channel ix.

func (*BufferData) Int32

func (d *BufferData) Int32(ix int) (int32, error)

Int32 gets an int32 from channel ix.

func (*BufferData) Int64

func (d *BufferData) Int64(ix int) (int64, error)

Int64 gets an int64 from channel ix.

func (*BufferData) Int8

func (d *BufferData) Int8(ix int) (int8, error)

Int8 gets an int8 from channel ix.

func (*BufferData) Uint16

func (d *BufferData) Uint16(ix int) (uint16, error)

Uint16 gets an uint16 from channel ix.

func (*BufferData) Uint32

func (d *BufferData) Uint32(ix int) (uint32, error)

Uint32 gets an uint32 from channel ix.

func (*BufferData) Uint64

func (d *BufferData) Uint64(ix int) (uint64, error)

Uint64 gets an uint64 from channel ix.

func (*BufferData) Uint8

func (d *BufferData) Uint8(ix int) (uint8, error)

Uint8 gets an uint8 from channel ix.

type ChannelSpec

type ChannelSpec struct {
	Index       int
	Name        string
	Signed      bool
	RealBits    uint
	StorageBits uint
	Shift       uint
	Endianness  Endianness
	// contains filtered or unexported fields
}

ChannelSpec describes one piece of data that is read from an iio buffer.

type CrosRing

type CrosRing struct {
	// Sensors is a list of all of the cros ec sensors that will produce data
	// on the cros-ec-ring. The cros ec ring itself will not be present in this
	// list.
	Sensors map[uint]ringSensor
	// contains filtered or unexported fields
}

CrosRing is an instance of a cros-ec-ring iio device. The buffer for this device is used to receive sensor data for all cros-ec-* sensors on a DUT.

Each datum read from the cros-ec-ring buffer contains a sensor ID field which coresponds to ID of the cros ec sensor which produced the data.

func NewRing

func NewRing(sensors []*Sensor) (*CrosRing, error)

NewRing creates a CrosRing from a list of Sensors on the DUT.

func (*CrosRing) Close

func (cr *CrosRing) Close() error

Close will close an open ring buffer.

func (*CrosRing) Open

func (cr *CrosRing) Open(ctx context.Context) (<-chan *SensorReading, error)

Open will prepare the ring buffer to be read and open the buffer for reading. Once open it will flush all existing data from the sensors and return a channel of SensorReading which all new sensor readings will be published to.

type Device

type Device struct {
	Path string
}

Device is a object we can read and write attributes from.

func (*Device) ReadAttr

func (d *Device) ReadAttr(attr string) (string, error)

ReadAttr reads the device's attr file and returns the value.

func (*Device) ReadIntegerAttr

func (d *Device) ReadIntegerAttr(attr string) (int, error)

ReadIntegerAttr reads the device's attr file and returns the integer value.

func (*Device) WriteAttr

func (d *Device) WriteAttr(attr, value string) error

WriteAttr writes value to the device's attr file.

type Endianness

type Endianness int

Endianness defines the endianness of a Buffer channel.

const (
	// BE specifies that channel data is big endian.
	BE Endianness = iota
	// LE specifies that channel data is little endian.
	LE
)

type Sensor

type Sensor struct {
	Device
	Name          SensorName
	Location      SensorLocation
	IioID         uint
	ID            uint
	Scale         float64
	MinFrequency  int
	MaxFrequency  int
	OldSysfsStyle bool
}

Sensor represents one sensor on the DUT.

func GetSensors

func GetSensors(ctx context.Context) ([]*Sensor, error)

GetSensors enumerates sensors that are exposed by Cros EC as iio devices.

func (*Sensor) NewBuffer

func (s *Sensor) NewBuffer() (*Buffer, error)

NewBuffer reads the sysfs directory of a sensor and returns a Buffer associated with a that sensor.

func (*Sensor) Read

func (s *Sensor) Read() (*SensorReading, error)

Read returns the current readings of the sensor.

type SensorLocation

type SensorLocation string

SensorLocation is the location of the sensor in the DUT which is reported by the EC and exposed by the kernel in /sys/bus/iio/devices/iio:device*/location.

const (
	// Base means that the sensor is located in the base of the DUT.
	Base SensorLocation = "base"
	// Lid means that the sensor is located in the lid of the DUT.
	Lid SensorLocation = "lid"
	// Camera means that the sensor is located near the camera.
	Camera SensorLocation = "camera"
	// None means that the sensor location is not known or not applicable.
	None SensorLocation = "none"
)

type SensorName

type SensorName string

SensorName is the kind of sensor which is reported by the EC and exposed by the kernel in /sys/bus/iio/devices/iio:device*/name. The name is in the form cros-ec-*.

const (
	// Accel is an accelerometer sensor.
	Accel SensorName = "cros-ec-accel"
	// Gyro is a gyroscope sensor.
	Gyro SensorName = "cros-ec-gyro"
	// Mag is a magnetometer sensor.
	Mag SensorName = "cros-ec-mag"
	// Light is a light or proximity sensor.
	Light SensorName = "cros-ec-light"
	// Baro is a barometer.
	Baro SensorName = "cros-ec-baro"
	// Ring is a special sensor for ChromeOS that produces a stream of data from
	// all sensors on the DUT.
	Ring SensorName = "cros-ec-ring"
	// Activity is a special sensor for ChromeOS that produces several kind of
	// activity events by the data of other sensors.
	Activity SensorName = "cros-ec-activity"
)

type SensorReading

type SensorReading struct {
	// Data contains all values read from the sensor.
	// Its length depends on the type of sensor being used.
	Data  []float64
	ID    uint
	Flags uint8
	// Timestamp is the duration from the boot time of the DUT to the time the
	// reading was taken
	Timestamp time.Duration
}

SensorReading is one reading from a sensor.

type Trigger

type Trigger struct {
	Type TriggerType
	Name string
}

Trigger : device that can be used to trigger events.

func GetTriggers

func GetTriggers() ([]*Trigger, error)

GetTriggers enumerates triggers that are exposed by the kernel.

type TriggerType

type TriggerType string

TriggerType defines the trigger supported by chromeos. sysfs trigger, and ring trigger for <= 3.18 kernels.

const (
	SysfsTrigger TriggerType = "sysfs"
	RingTrigger  TriggerType = "cros-ec-ring-"
)

Known type of triggers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL