Documentation
¶
Overview ¶
Package onewire provides tools to communicate with slave devices connected to 1-Wire bus.
Index ¶
- Constants
- Variables
- func CRC16(crc uint16, data []uint16) uint16
- func CRC8(crc byte, data []byte) byte
- type DCI
- type Dev
- type Master
- func (m *Master) ConvertT() error
- func (m *Master) CopyScratchpad() error
- func (m *Master) MatchROM(d Dev) error
- func (m *Master) Read(data []byte) (int, error)
- func (m *Master) ReadPowerSupply() error
- func (m *Master) ReadROM() (d Dev, err error)
- func (m *Master) ReadScratchpad() (s Scratchpad, err error)
- func (m *Master) RecallEE() error
- func (m *Master) SearchNext(s *Search) bool
- func (m *Master) SkipROM() error
- func (m *Master) Write(data []byte) (int, error)
- func (m *Master) WriteScratchpad(th, tl int8, cfg byte) error
- type Scratchpad
- type Search
- type Type
Constants ¶
const ( T9bit = 0x1f T10bit = 0x3f T11bit = 0x5f T12bit = 0x7f )
Variables ¶
Functions ¶
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 Master ¶
type Master struct {
DCI
}
func (*Master) ConvertT ¶
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 ¶
CopyScratchpad copies the contents of the scratchpad Th, Tl and configuration registers to EEPROM. This command needs extra power.
func (*Master) ReadROM ¶
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) SearchNext ¶
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.
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]).