onewire

package
v0.0.0-...-168ccc2 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2021 License: BSD-3-Clause Imports: 2 Imported by: 0

Documentation

Overview

Package onewire provides tools to communicate with slave devices connected to 1-Wire bus.

Index

Constants

View Source
const (
	T9bit  = 0x1f
	T10bit = 0x3f
	T11bit = 0x5f
	T12bit = 0x7f
)

Variables

View Source
var (
	ErrNoResponse = errors.New("no response")
	ErrBusFault   = errors.New("bus fault")
	ErrCRC        = errors.New("bad CRC")
	ErrDevType    = errors.New("bad device type")
)

Functions

func CRC16

func CRC16(crc uint16, data []uint16) uint16

CRC16 with poly: x^16+x^15+x^2+1 -> 0x4003==inv(0xc002)

func CRC8

func CRC8(crc byte, data []byte) byte

CRC8 with poly: x^8+x^5+x^4+1 -> 0x31==inv(0x8c)

Types

type DCI

type DCI interface {
	// Reset sends reset pulse. If there is no presence pulse received it
	// returns ErrNoResponse error.
	Reset() error

	// ReadBit generates read time slot on the bus. It returns received bit
	// value (0 or 1) or error.
	ReadBit() (bit byte, err error)

	// WriteBit generates write slot on the bus. It sends 0 if bit == 0 or 1
	// otherwise.
	WriteBit(bit byte) error

	// ReadByte receives a byte by generating 8 read slots on the bus. It
	// returns read byte or error.
	ReadByte() (byte, error)

	// WriteByte sends b by generating 8 write slots on the bus.
	WriteByte(b byte) error
}

DCI means Data and Control Interface. It contains set of methods that should provide access to 1-Wire low-level signaling. It is used by Master to implement higher layer protocols.

type Dev

type Dev [8]byte

func (Dev) Format

func (d Dev) Format(f fmt.State, _ rune)

func (Dev) Type

func (d Dev) Type() Type

type Master

type Master struct {
	DCI
}

func (*Master) ConvertT

func (m *Master) ConvertT() error

ConvertT (DS18x2x) initiates temperature conversion. Temperature conversion needs extra power. In case of parasite power mode the strong pullup is required during the entire conversion so no any other command can't be sent before the duration of tconv. If external supply is used, ReadBit method can be used to pooling conversion state: it returns 0 while the temperature conversion is in progress and a 1 when the conversion is done.

func (*Master) CopyScratchpad

func (m *Master) CopyScratchpad() error

CopyScratchpad copies the contents of the scratchpad Th, Tl and configuration registers to EEPROM. This command needs extra power.

func (*Master) MatchROM

func (m *Master) MatchROM(d Dev) error

MatchROM allows the bus master to address a specific slave device.

func (*Master) Read

func (m *Master) Read(data []byte) (int, error)

Read behaves link io.ReadFull (reads len(data) bytes or returns error).

func (*Master) ReadPowerSupply

func (m *Master) ReadPowerSupply() error

ReadPowerSupply

func (*Master) ReadROM

func (m *Master) ReadROM() (d Dev, err error)

ReadROM allows the bus master to read the slave’s 64-bit ROM code without using the SearchROM method. It can only be used when there is only one slave device on the bus.

func (*Master) ReadScratchpad

func (m *Master) ReadScratchpad() (s Scratchpad, err error)

ReadScratchpad (DS18x2x) reads content of scratchpad and checks its CRC. It retuns readed data and error (ErrCRC in case of bad CRC).

func (*Master) RecallEE

func (m *Master) RecallEE() error

RecallEE

func (*Master) SearchNext

func (m *Master) SearchNext(s *Search) bool

SearchNext can be used to perform a search for 1-Wire slave devices connected to the bus controled by m. It saves current state in s and returns true if next device was found or false if no more devices or error occurred. Use s.Dev() to get the device found, s.Err() to check for error.

func (*Master) SkipROM

func (m *Master) SkipROM() error

SkipROM can be used to address all devices on the bus simultaneously.

func (*Master) Write

func (m *Master) Write(data []byte) (int, error)

func (*Master) WriteScratchpad

func (m *Master) WriteScratchpad(th, tl int8, cfg byte) error

WriteScratchpad writes data to scratchpad. DS18S20 ignores cfg byte.

type Scratchpad

type Scratchpad [9]byte

Scratchpad represents 9 bytes of data that can be read from DS18x2x device.

func (*Scratchpad) CRC

func (s *Scratchpad) CRC() byte

CRC returns value of CRC field. It should be equal to CRC8(0, s[:8]).

func (*Scratchpad) Temp

func (s *Scratchpad) Temp(typ Type) (float32, error)

Temp returns temperature data from s as float32 value T[C].

func (*Scratchpad) Temp16

func (s *Scratchpad) Temp16(typ Type) (int, error)

Temp16 returns temperature data from s equal to T[C] * 16.

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

func MakeSearch

func MakeSearch(typ Type, alarm bool) Search

func (*Search) Dev

func (s *Search) Dev() Dev

func (*Search) Err

func (s *Search) Err() error

func (*Search) Init

func (s *Search) Init(typ Type, alarm bool)

func (*Search) Reset

func (s *Search) Reset()

type Type

type Type byte
const (
	DS1820  Type = 0x10
	DS18S20 Type = 0x10
	DS1822  Type = 0x22
	DS18B20 Type = 0x28
)

Types of DS18x20 family.

Jump to

Keyboard shortcuts

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