periphery

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 3, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Conversion constants
	ADS1115_SAMPLES_PER_READ = 32767.0
	ADS1115_VOLTS_PER_SAMPLE = 5

	ADS1115_DEVICE_ID_REGISTER = 0x0E
	ADS1115_DEVICE_ID          = 0x80
)

ADS1115 ADC chip constants.

Variables

This section is empty.

Functions

This section is empty.

Types

type ADC

type ADC interface {
	// Init performs ADC driver initialisation.
	Init() error
	// Read returns single analog sensor reading value.
	Read() float64
	// RMS aggregates `n` readings from analog sensor and calculates Root Mean Square function.
	RMS(n int, t *time.Duration) float64
	// Max returns max value from `n` analog sensor readings.
	Max(n int, t *time.Duration) float64
	// Min returns min value from `n` analog sensor readings.
	Min(n int, t *time.Duration) float64
	// Verify identifies ADC device and checks it according to implemented driver.
	Verify() bool
	// Active determines whether the ADC device is active.
	Active() bool
	// Close closes connection to ADC device.
	Close() error
}

ADC defines analog to digital peripheral interface.

type ADCOption

type ADCOption interface {
	Apply(adc *ADS1115)
}

An ADCOption configures a ADC driver.

func WithBias

func WithBias(bias float64) ADCOption

WithBias can be used to specify ADC readings bias. Default is 0.

func WithConversion

func WithConversion(convertor func(v float64) float64) ADCOption

WithConversion can be used to setup ADC readings conversion. Default is a function that returns input value as is.

func WithI2CMutex

func WithI2CMutex(mutex *sync.Mutex) ADCOption

WithI2CMutex can be used to specify mutex for I2C bus driver. Default is a new sync.Mutex instance.

type ADCOptionFunc

type ADCOptionFunc func(d *ADS1115)

ADCOptionFunc is a function that configures a ADC driver.

func (ADCOptionFunc) Apply

func (f ADCOptionFunc) Apply(adc *ADS1115)

Apply calls ADCOptionFunc on the driver instance.

type ADS1115

type ADS1115 struct {
	*ads.ADS
	*I2C
	Addr uint16
	Bus  string
	// contains filtered or unexported fields
}

ADS1115 implements ADC driver for ADS1115 device.

func NewADC

func NewADC(addr uint16, bus int, options ...ADCOption) *ADS1115

NewADC constructs a new ADC implementation via ADS1115 device driver.

func (*ADS1115) Active

func (d *ADS1115) Active() bool

func (*ADS1115) Close

func (d *ADS1115) Close() error

func (*ADS1115) Init

func (d *ADS1115) Init() (err error)

Init sets up the device for communication.

func (*ADS1115) Max

func (d *ADS1115) Max(n int, t *time.Duration) float64

func (*ADS1115) Min

func (d *ADS1115) Min(n int, t *time.Duration) float64

func (*ADS1115) RMS

func (d *ADS1115) RMS(n int, t *time.Duration) float64

func (*ADS1115) Read

func (d *ADS1115) Read() float64

func (*ADS1115) Verify

func (d *ADS1115) Verify() bool

type Bluetooth

type Bluetooth struct {
	ble.Device
	// contains filtered or unexported fields
}

Bluetooth defines BLE peripheral interface.

func NewBluetooth

func NewBluetooth(options ...BluetoothOption) *Bluetooth

NewBluetooth creates new Bluetooth driver instance.

func (*Bluetooth) Advertise

func (b *Bluetooth) Advertise(ctx context.Context) error

Advertise advertises device with previously configured name.

func (*Bluetooth) ApplyOptions

func (b *Bluetooth) ApplyOptions(options ...BluetoothOption) *Bluetooth

ApplyOptions applies Bluetooth configuration parameters by given `options`.

func (*Bluetooth) Close

func (b *Bluetooth) Close() error

Close closes Bluetooth connection and clears allocated resources.

func (*Bluetooth) Init

func (b *Bluetooth) Init(options ...BluetoothOption) error

Init performs initialisation of the Bluetooth driver.

func (*Bluetooth) Scan

func (b *Bluetooth) Scan(ctx context.Context) error

Scan performs scan for currently advertising bluetooth device.

type BluetoothOption

type BluetoothOption interface {
	Apply(d *Bluetooth)
}

An BluetoothOption configures a Bluetooth driver.

func WithAdvertisementDuration

func WithAdvertisementDuration(du time.Duration) BluetoothOption

WithAdvertisementDuration can be used to specify timeout for Bluetooth advertisement. Default is the one specified in the configuration: viper.GetString("bluetooth.advertise_duration").

func WithAdvertisementServices

func WithAdvertisementServices(uuids ...ble.UUID) BluetoothOption

WithAdvertisementServices can be used to specify service to expose during Bluetooth advertisement. Default is no service being exposed.

func WithDeviceName

func WithDeviceName(name string) BluetoothOption

WithDeviceName can be used to specify Bluetooth device identifier name. Default is the one specified in the configuration: viper.GetString("bluetooth.device_name").

func WithScanDuration

func WithScanDuration(du time.Duration) BluetoothOption

WithScanDuration can be used to specify timeout for Bluetooth scanning. Default is the one specified in the configuration: viper.GetString("bluetooth.scan_duration").

type BluetoothOptionFunc

type BluetoothOptionFunc func(d *Bluetooth)

BluetoothOptionFunc is a function that configures a Bluetooth driver.

func (BluetoothOptionFunc) Apply

func (f BluetoothOptionFunc) Apply(d *Bluetooth)

Apply calls BluetoothOptionFunc on the driver instance.

type GPIO

type GPIO struct {
	gpio.PinIO
	// contains filtered or unexported fields
}

GPIO provides wrapper for GPIO peripheral.

func NewGPIO

func NewGPIO(pin int) *GPIO

NewGPIO constructs new GPIO driver instance.

func (*GPIO) High

func (g *GPIO) High() error

High sends high level signal to GPIO pin.

func (*GPIO) Init

func (g *GPIO) Init() error

Init performs GPIO driver initialization.

func (*GPIO) IsHigh

func (g *GPIO) IsHigh() bool

IsHigh determines whether the GPIO pin is on High state.

func (*GPIO) IsLow

func (g *GPIO) IsLow() bool

IsLow determines whether the GPIO pin is on Low state.

func (*GPIO) Low

func (g *GPIO) Low() error

Low sends low level signal to GPIO pin.

type I2C

type I2C struct {
	i2c.Dev
	*sync.Mutex
	// contains filtered or unexported fields
}

I2C provides wrapper for I2C peripheral.

func NewI2C

func NewI2C(addr uint16, bus int, options ...I2COption) *I2C

NewI2C constructs new I2C driver instance.

func (*I2C) Active

func (i *I2C) Active() bool

Active checks whether the I2C device is connected and active.

func (*I2C) Close

func (i *I2C) Close() error

Close closes connection to I2C device and clears allocated resources.

func (*I2C) Init

func (i *I2C) Init() (err error)

Init performs I2C device initialization.

func (*I2C) Read

func (i *I2C) Read() (byte, error)

Read reads a single byte from an active register.

func (*I2C) ReadBytes

func (i *I2C) ReadBytes(n int) ([]byte, error)

ReadBytes reads `n` bytes from an active register.

func (*I2C) ReadReg

func (i *I2C) ReadReg(reg byte) (byte, error)

ReadReg reads a single byte from a specified `reg` register.

func (*I2C) ReadRegBytes

func (i *I2C) ReadRegBytes(reg byte, n int) ([]byte, error)

ReadRegBytes reads `n` bytes from a specified `reg` register.

func (*I2C) ReadRegS16BE

func (i *I2C) ReadRegS16BE(reg byte) (int16, error)

ReadRegS16BE reads signed big endian word (16 bits) from a specified `reg` register.

func (*I2C) ReadRegS16LE

func (i *I2C) ReadRegS16LE(reg byte) (int16, error)

ReadRegS16LE reads signed little endian word (16 bits) from a specified `reg` register.

func (*I2C) ReadRegU16BE

func (i *I2C) ReadRegU16BE(reg byte) (uint16, error)

ReadRegU16BE reads unsigned big endian word (16 bits) from a specified `reg` register.

func (*I2C) ReadRegU16LE

func (i *I2C) ReadRegU16LE(reg byte) (uint16, error)

ReadRegU16LE reads unsigned little endian word (16 bits) from a specified `reg` register.

func (*I2C) Tx

func (i *I2C) Tx(w, r []byte) error

Tx wraps i2c.Dev Tx() method with activeness check.

func (*I2C) Verify

func (i *I2C) Verify() bool

Verify verifies I2C bus connectivity. It will perform Init if driver is not Active.

func (*I2C) WriteBytes

func (i *I2C) WriteBytes(data ...byte) error

WriteBytes writes `data` bytes to an active register.

func (*I2C) WriteRegBytes

func (i *I2C) WriteRegBytes(reg byte, data ...byte) error

WriteRegBytes writes `data` bytes to a specified `reg` register.

func (*I2C) WriteRegU16BE

func (i *I2C) WriteRegU16BE(reg byte, value uint16) error

WriteRegU16BE writes unsigned big endian word (16 bits) value to I2C-device starting from address specified in reg.

func (*I2C) WriteRegU16LE

func (i *I2C) WriteRegU16LE(reg byte, value uint16) error

WriteRegU16LE writes unsigned little endian word (16 bits) value to I2C-device starting from address specified in reg.

type I2COption

type I2COption interface {
	Apply(adc *I2C)
}

An I2COption configures a ADC driver.

func WithMutex

func WithMutex(mutex *sync.Mutex) I2COption

WithMutex can be used to setup mutex I2C driver. Default is a new sync.Mutex instance.

type I2COptionFunc

type I2COptionFunc func(d *I2C)

I2COptionFunc is a function that configures a I2C driver.

func (I2COptionFunc) Apply

func (f I2COptionFunc) Apply(i2c *I2C)

Apply calls I2COptionFunc on the driver instance.

type SPI

type SPI struct {
	conn.Conn
	// contains filtered or unexported fields
}

SPI provides wrapper for SPI peripheral.

func NewSPI

func NewSPI(name string) *SPI

NewSPI constructs new SPI driver instance.

func (*SPI) Active

func (s *SPI) Active() bool

Active checks whether the SPI device is connected and active.

func (*SPI) Close

func (s *SPI) Close() error

Close closes connection to SPI device and clears allocated resources.

func (*SPI) Init

func (s *SPI) Init() (err error)

Init performs SPI device initialization.

func (*SPI) Port

func (s *SPI) Port() spi.Port

Port returns SPI port.

func (*SPI) SendCommand

func (s *SPI) SendCommand(cmd byte) error

SendCommand sends `cmd` command on SPI device.

func (*SPI) SendCommandArgs

func (s *SPI) SendCommandArgs(cmd byte, data ...byte) error

SendCommandArgs sends `cmd` command with `data` as arguments on SPI device.

func (*SPI) SendData

func (s *SPI) SendData(data ...byte) error

SendData sends `data` on SPI device.

Jump to

Keyboard shortcuts

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