ds18b20

package
v0.0.0-...-27e653a Latest Latest
Warning

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

Go to latest
Published: Aug 6, 2023 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSuchID    = errors.New("there is no sensor with provided ID")
	ErrNoInterface = errors.New("no interface")
)
View Source
var (
	ErrUnexpectedResolution = errors.New("unexpected resolution")
)

Functions

This section is empty.

Types

type Bus

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

func NewBus

func NewBus(options ...BusOption) (*Bus, error)

NewBus creates Bus with BusOption Interface must be presented

func (*Bus) Discover

func (b *Bus) Discover() (s []*Sensor, errs []error)

Discover create slice of Sensors found on Path

func (*Bus) IDs

func (b *Bus) IDs() ([]string, error)

IDs return slice of DS18B20 ID found on provided Path

func (*Bus) NewSensor

func (b *Bus) NewSensor(id string) (*Sensor, error)

NewSensor creates DS18B20 Sensor based on ID

type BusOption

type BusOption func(bus *Bus)

func WithInterface

func WithInterface(o Onewire) BusOption

func WithOnewire

func WithOnewire() BusOption

func WithOnewireOnPath

func WithOnewireOnPath(path string) BusOption

type FileReaderWriter

type FileReaderWriter interface {
	WriteFile(name string, data []byte) error
	ReadFile(name string) ([]byte, error)
}

type Onewire

type Onewire interface {
	Path() string
	FileReaderWriter
}

Onewire represents Linux onewire driver

type Readings

type Readings struct {
	ID          string    `json:"id"`
	Temperature float64   `json:"temperature"`
	Average     float64   `json:"average"`
	Stamp       time.Time `json:"stamp"`
	Error       string    `json:"error"`
}

Readings are returned, when Sensor is used in Poll mode

type Resolution

type Resolution int
const (
	Resolution9Bit  Resolution = 9
	Resolution10Bit Resolution = 10
	Resolution11Bit Resolution = 11
	Resolution12Bit Resolution = 12
)

Possible resolutions

type Sensor

type Sensor struct {
	FileReaderWriter
	// contains filtered or unexported fields
}

Sensor represents DS18b20

func NewSensor

func NewSensor(o FileReaderWriter, id, basePath string) (*Sensor, error)

NewSensor creates new sensor based on args

func (*Sensor) Average

func (s *Sensor) Average() float64

Average returns current average temperature

func (*Sensor) Close

func (s *Sensor) Close()

Close should be called, if user used Poll

func (*Sensor) Configure

func (s *Sensor) Configure(config SensorConfig) error

Configure allows user to configure sensor with SensorConfig

func (*Sensor) FullID

func (s *Sensor) FullID() string

FullID returns Sensor hardware id in convention: w1Path:id

func (*Sensor) GetConfig

func (s *Sensor) GetConfig() SensorConfig

GetConfig returns current config

func (*Sensor) GetReadings

func (s *Sensor) GetReadings() []Readings

GetReadings returns all collected readings and then clears data

func (*Sensor) ID

func (s *Sensor) ID() string

ID returns Sensor hardware id in id

func (*Sensor) Name

func (s *Sensor) Name() string

Name returns user provided name

func (*Sensor) Poll

func (s *Sensor) Poll()

Poll is an option to run temperature updates in background After calling Poll, user can get data from GetReadings

func (*Sensor) Temperature

func (s *Sensor) Temperature() (actual, avg float64, err error)

Temperature returns current temperature and average (which is based on Samples)

type SensorConfig

type SensorConfig struct {
	Name         string        `json:"name"`
	ID           string        `json:"id"`
	Correction   float64       `json:"correction"`
	Resolution   Resolution    `json:"resolution"`
	PollInterval time.Duration `json:"poll_interval"`
	Samples      uint          `json:"samples"`
}

SensorConfig allows user to configure Sensor (except ID, which is unique and can't be changed)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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