mirror of
https://github.com/kidoman/embd
synced 2025-07-03 20:07:40 +02:00
OneWire bus impl
This commit is contained in:
parent
bfcd1345fe
commit
82f119fadb
72 changed files with 568 additions and 174 deletions
72
samples/onewire.go
Normal file
72
samples/onewire.go
Normal file
|
@ -0,0 +1,72 @@
|
|||
// +build ignore
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/zlowred/embd"
|
||||
_ "github.com/zlowred/embd/host/all"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err := embd.InitW1(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer embd.CloseW1()
|
||||
|
||||
w1 := embd.NewW1Bus(0)
|
||||
|
||||
devs, err := w1.ListDevices()
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for _, dev := range devs {
|
||||
fmt.Println("OneWire device: %s", dev)
|
||||
}
|
||||
|
||||
w1d, err := w1.Open("28-011572120bff")
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Printf("%v\n", w1d)
|
||||
|
||||
err = w1d.WriteByte(0x44)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
for ret, err := w1d.ReadByte(); ret == 0 && err != nil; {}
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = w1d.WriteByte(0xBE)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
res, err := w1d.ReadBytes(9)
|
||||
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Print("res: ")
|
||||
for _, val := range res {
|
||||
fmt.Printf("0x%02X ", val)
|
||||
}
|
||||
fmt.Println()
|
||||
|
||||
var temp float64 = float64(float64(res[1]) * 256. + float64(res[0])) / 16.
|
||||
fmt.Printf("%f\n", temp)
|
||||
|
||||
fmt.Println("Done")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue