Compare commits
No commits in common. "38b4e0abdcae7e6da666e09759bbedd69e8c24bc" and "cbc1f161c1fbb58fbdaeb227326a35f934573d5b" have entirely different histories.
38b4e0abdc
...
cbc1f161c1
5 changed files with 6 additions and 99 deletions
|
@ -1,3 +0,0 @@
|
|||
This package provides support for using 1-wire DS18B20 with gokrazy!
|
||||
|
||||
The package just loads the kernel module.
|
|
@ -1,91 +0,0 @@
|
|||
// w1-therm is a gokrazy helper that loads 1-wire kernel modules on boot.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// Include the w1-therm package in your gokr-packer command:
|
||||
// % gokr-packer -update=yes \
|
||||
// github.com/gokrazy/breakglass \
|
||||
// git.joco.dk/snr/fermentord/cmd/w1-therm
|
||||
package main
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
func logic() error {
|
||||
flag.Parse()
|
||||
|
||||
for _, mod := range []string{
|
||||
"kernel/drivers/w1/wire.ko",
|
||||
"kernel/drivers/w1/masters/w1-gpio.ko",
|
||||
"kernel/drivers/w1/slaves/w1-therm.ko",
|
||||
} {
|
||||
if err := loadModule(mod); err != nil && !os.IsNotExist(err) {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
dev := "w1_bus_master1"
|
||||
target, err := checkOneWireInterface(dev)
|
||||
if err != nil {
|
||||
log.Printf("Bluetooth interface %v not found.", target)
|
||||
} else {
|
||||
fmt.Printf("Bluetooth device %v: %v\n", dev, target)
|
||||
}
|
||||
|
||||
// gokrazy should not supervise this process even when manually started.
|
||||
os.Exit(125)
|
||||
return nil
|
||||
}
|
||||
|
||||
func checkOneWireInterface(device string) (string, error) {
|
||||
name := fmt.Sprintf("/sys/bus/w1/devices/%v", device)
|
||||
target, err := os.Readlink(name)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("OneWire bus master %v not found", device)
|
||||
}
|
||||
return target, nil
|
||||
}
|
||||
|
||||
func loadModule(mod string) error {
|
||||
f, err := os.Open(filepath.Join("/lib/modules", release, mod))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
if err := unix.FinitModule(int(f.Fd()), "", 0); err != nil {
|
||||
if err != unix.EEXIST &&
|
||||
err != unix.EBUSY &&
|
||||
err != unix.ENODEV &&
|
||||
err != unix.ENOENT {
|
||||
return fmt.Errorf("FinitModule(%v): %v", mod, err)
|
||||
}
|
||||
}
|
||||
modname := strings.TrimSuffix(filepath.Base(mod), ".ko")
|
||||
log.Printf("modprobe %v", modname)
|
||||
return nil
|
||||
}
|
||||
|
||||
var release = func() string {
|
||||
var uts unix.Utsname
|
||||
if err := unix.Uname(&uts); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "minitrd: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return string(uts.Release[:bytes.IndexByte(uts.Release[:], 0)])
|
||||
}()
|
||||
|
||||
func main() {
|
||||
if err := logic(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
|
@ -23,9 +23,9 @@ tilt = "DWJONDAHL.ingest.fermentor.ingest_tilt_reading"
|
|||
port = 8000
|
||||
|
||||
[sensors]
|
||||
wort = "28-021892458c02"
|
||||
chamber = "28-02319245083c"
|
||||
ambient = "28-02319245022b"
|
||||
wort = ""
|
||||
chamber = ""
|
||||
ambient = ""
|
||||
weight = 0.8
|
||||
|
||||
[i2c]
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
@ -224,7 +225,7 @@ func triggerBulkRead() error {
|
|||
}
|
||||
|
||||
func pollBusState() (BulkReadBusState, error) {
|
||||
b, err := os.ReadFile("/sys/bus/w1/devices/w1_bus_master1/therm_bulk_read")
|
||||
b, err := ioutil.ReadFile("/sys/bus/w1/devices/w1_bus_master1/therm_bulk_read")
|
||||
if err != nil {
|
||||
return BulkReadIdle, err
|
||||
}
|
||||
|
@ -240,7 +241,7 @@ func pollBusState() (BulkReadBusState, error) {
|
|||
// read returns the temperature of the specified sensor in millidegrees celcius.
|
||||
func read(sensor string) (int64, error) {
|
||||
path := filepath.Join("/sys/bus/w1/devices", sensor, "w1_slave")
|
||||
data, err := os.ReadFile(path)
|
||||
data, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return NaN, err
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue