Documentation ¶
Index ¶
- Constants
- Variables
- func GetDefaultSerialPortConfig() *serial.SerialPortConfig
- type Option
- type Sensor
- func (*Sensor) ConcentrationSpecs() []*pm.ConcentrationSpec
- func (s *Sensor) Concentrations() <-chan *pm.Concentration
- func (s *Sensor) MeasurementInterval() time.Duration
- func (s *Sensor) ReconnectTimeout() time.Duration
- func (s *Sensor) RecoverableErrorHandler() ShouldTerminate
- func (s *Sensor) Run(ctx context.Context) error
- type ShouldTerminate
Constants ¶
const ( DefaultMeasurementInterval = 1 * time.Second DefaultReconnectTimeout = 5 * time.Second )
const (
PM2_5UpperBoundSize = 2500 * units.Nanometer
)
Variables ¶
var ( // Command to write to the sensor to invoke its measurement routine ReadMeasurementCommand = []byte{0x11, 0x02, 0x0B, 0x01, 0xE1} // Header of a valid measurement ReadingHeader = []byte{0x16, 0x11, 0x0B} )
Functions ¶
func GetDefaultSerialPortConfig ¶
func GetDefaultSerialPortConfig() *serial.SerialPortConfig
GetDefaultSerialPortConfig gets the manufacturer-specified defaults for connecting to the sensor
Types ¶
type Option ¶
type Option struct {
// contains filtered or unexported fields
}
Option is a configured option that may be applied to a Sensor
func WithMeasurementInterval ¶
WithMeasurementInterval specifies the duration to wait between reading measurements
func WithReconnectTimeout ¶
WithReconnectTimeout specifies the duration to wait before reconnecting after a recoverable error
func WithRecoverableErrorHandler ¶
func WithRecoverableErrorHandler(f ShouldTerminate) *Option
WithRecoverableErrorHandler registers a function that will be called when a recoverable error occurs
type Sensor ¶
type Sensor struct {
// contains filtered or unexported fields
}
Sensor represents a configured Cubic PM1003 particulate matter sensor
func NewSensor ¶
func NewSensor(portFactory coreio.PortFactory, options ...*Option) *Sensor
NewSensor creates a Sensor with optional configuration
func (*Sensor) ConcentrationSpecs ¶
func (*Sensor) ConcentrationSpecs() []*pm.ConcentrationSpec
ConcentrationSpecs returns a collection of specified measurement ranges supported by the sensor
func (*Sensor) Concentrations ¶
func (s *Sensor) Concentrations() <-chan *pm.Concentration
Concentrations returns a channel of PM concentration readings as they become available from the sensor
func (*Sensor) MeasurementInterval ¶
MeasurementInterval is the duration to wait between reading measurements
func (*Sensor) ReconnectTimeout ¶
ReconnectTimeout is the duration to wait before reconnecting after a recoverable error
func (*Sensor) RecoverableErrorHandler ¶
func (s *Sensor) RecoverableErrorHandler() ShouldTerminate
RecoverableErrorHandler a function that will be called when a recoverable error occurs
type ShouldTerminate ¶
ShouldTerminate is a function that returns a result indicating whether the Sensor should terminate after a recoverable error