Skip to content

Commit e05a20a

Browse files
committed
Issue periph#60, fix onewire not present, and hanging when it is.
1 parent b69b28c commit e05a20a

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

host_linux.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ package host
77
import (
88
// Make sure required drivers are registered.
99
_ "periph.io/x/host/v3/gpioioctl"
10+
_ "periph.io/x/host/v3/netlink"
1011
_ "periph.io/x/host/v3/sysfs"
1112
)

netlink/netlink_linux.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package netlink
66

77
import (
88
"fmt"
9+
"path/filepath"
910
"syscall"
1011
)
1112

@@ -52,3 +53,17 @@ func (s *connSocket) close() error {
5253
s.fd = 0
5354
return syscall.Close(fd)
5455
}
56+
57+
// isOneWireAvailable checks to see if the Linux onewire bus drivers are loaded.
58+
// It does this by looking for entries in the /sys/bus pseudo-filesystem.
59+
//
60+
// On a Raspberry Pi SBC, the onewire bus is enabled by creating entries in the
61+
// kernel config.txt file which is located in /boot, or /boot/firmware depending
62+
// on OS/kernel levels.
63+
func isOneWireAvailable() bool {
64+
items, err := filepath.Glob("/sys/bus/w1/devices/*")
65+
if err != nil || len(items) == 0 {
66+
return false
67+
}
68+
return true
69+
}

netlink/netlink_other.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,7 @@ func (*connSocket) recv(_ []byte) (int, error) {
2828
func (*connSocket) close() error {
2929
return errors.New("not implemented")
3030
}
31+
32+
func isOneWireAvailable() bool {
33+
return false
34+
}

netlink/onewire.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ func (d *driver1W) After() []string {
463463
}
464464

465465
func (d *driver1W) Init() (bool, error) {
466+
if !isOneWireAvailable() {
467+
return false, errors.New("no onewire buses found")
468+
}
466469
s, err := newW1Socket()
467470
if err != nil {
468471
return false, fmt.Errorf("netlink-onewire: failed to open socket: %v", err)

0 commit comments

Comments
 (0)