max30102

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IntStat1         = 0x00
	IntStat2         = 0x01
	IntEna1          = 0x02
	IntEna2          = 0x03
	FIFOWrPtr        = 0x04
	OvfCount         = 0x05
	FIFORdPtr        = 0x06
	FIFOData         = 0x07
	FIFOCfg          = 0x08
	ModeCfg          = 0x09
	SpO2Cfg          = 0x0A
	Led1PA           = 0x0C
	Led2PA           = 0x0D
	MultiLedModeS2S1 = 0x11
	MultiLedModeS4S3 = 0x12
	TempInt          = 0x1F
	TempFrac         = 0x20
	TempCfg          = 0x21
	RegRevID         = 0xFE
	RegPartID        = 0xFF
)

Register addresses

View Source
const (
	// Status 1
	AlmostFull            byte = (1 << 7)
	NewFIFOData           byte = (1 << 6)
	AmbientLightCancelOvf byte = (1 << 5)
	PowerReady            byte = (1 << 0)

	// Status 2
	DieTempReady byte = (1 << 1)
)

Interrupt flags

View Source
const (
	Addr   = 0x57
	PartID = 0x15
)

Device constants

View Source
const (
	TempEna      byte = 0b0000_0001
	ModeHR       byte = 0b010
	ModeSpO2     byte = 0b011
	ModeMultiLed byte = 0b111

	ResetControl = 0b0100_0000
)

Settings

View Source
const (
	SR50 = (iota << 2)
	SR100
	SR200
	SR400
	SR800
	SR1000
	SR1600
	SR3200
)

SpO2 Sample Rate Control

View Source
const (
	PW69 = iota
	PW118
	PW215
	PW411
)

LED Pulse Width Control

Variables

View Source
var (
	// ErrNotDevice throws an error when the device part ID does not match a
	// MAX30102 signature (0x15).
	ErrNotDevice error = errors.New("max30102: part ID does not match (0x15)")
)

Functions

This section is empty.

Types

type Device

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

Device defines a MAX30102 device.

func New

func New(busName string, addr uint16) (*Device, error)

New returns a new MAX30102 device. By default, this sets the LED pulse amplitude to 2.4mA, with a pulse width of 411us and a sample rate of 100 samples/s.

Argument "busName" can be used to specify the exact bus to use ("/dev/i2c-2", "I2C2", "2"). Argument "addr" can be used to specify alternative address if default (0x57) is unavailable and changed. If "busName" argument is specified as an empty string "" the first available bus will be used.

func (*Device) Calibrate

func (d *Device) Calibrate() error

Calibrate auto-calibrates the current of each LED.

func (*Device) Close

func (d *Device) Close()

Close closes the device and cleans after itself.

func (*Device) IRRed

func (d *Device) IRRed() (ir, red float64, err error)

IRRed returns the value of the red LED and IR LED. The values are normalized from 0.0 to 1.0.

func (*Device) IRRedBatch

func (d *Device) IRRedBatch() (ir, red []float64, err error)

IRRedBatch returns a batch of IR and red LED values based on the AlmostFull flag. The amount of data returned can be configured by setting the AlmostFullValue leftover value, which is set to 0 by default. Therefore, this function returns 32 samples by default.

func (*Device) Options

func (d *Device) Options(options ...Option) (Option, error)

Options sets different configuration options and returns the previous value of the last option passed.

func (*Device) Read

func (d *Device) Read(reg byte) (byte, error)

Read reads a single byte from a register.

func (*Device) ReadBytes

func (d *Device) ReadBytes(reg byte, n int) ([]byte, error)

ReadBytes reads n bytes from a register.

func (*Device) Reset

func (d *Device) Reset() error

Reset resets the device. All configurations, thresholds, and data registers are reset to their power-on state.

func (*Device) RevID

func (d *Device) RevID() (byte, error)

RevID returns the revision ID of the device.

func (*Device) Shutdown

func (d *Device) Shutdown() error

Shutdown sets the device into power-save mode.

func (*Device) Startup

func (d *Device) Startup() error

Startup wakes the device from power-save mode.

func (*Device) Temperature

func (d *Device) Temperature() (float64, error)

Temperature returns the current temperature of the device.

func (*Device) Write

func (d *Device) Write(reg, data byte) error

Write writes a byte to a register.

type Option

type Option func(d *Device) (Option, error)

Option defines a functional option for the device.

func AlmostFullValue

func AlmostFullValue(left byte) Option

AlmostFullValue sets when the AlmostFull interrupt should be triggered. It can take values from 0 to 15.

func IRPulseAmp

func IRPulseAmp(current float64) Option

IRPulseAmp sets the pulse amplitude of the red LED. It accepts values from 0.0 to 51.0 mA and the value is rounded down to the nearest multiple of 0.2.

func InterruptEnable

func InterruptEnable(i byte) Option

InterruptEnable enables interrupts.

func Mode

func Mode(mode byte) Option

Mode sets the operation mode of the device.

func PulseWidth

func PulseWidth(pw byte) Option

PulseWidth sets the pulse width of the device.

func RedPulseAmp

func RedPulseAmp(current float64) Option

RedPulseAmp sets the pulse amplitude of the red LED. It accepts values from 0.0 to 51.0 mA and the value is rounded down to the nearest multiple of 0.2.

func SampleRate

func SampleRate(sr byte) Option

SampleRate sets the SpO2 sample rate control of the device.

Jump to

Keyboard shortcuts

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