Closed oddcitizenape closed 6 months ago
if _, err := driverreg.Init(); err != nil {
should be
if _, err := host.Init(); err != nil {
See the example..
Maybe worth reopening to improve the documentation that led you to settle with driverreg. If you can document how you ended up using it, then we can convert this issue in a documentation fix.
Oh wait I just realized you do both. I'm surprised the second call doesn't fail. This is a bug.
The behavior was intentional, I had forgotten about it; https://github.com/periph/conn/blob/main/driver/driverreg/driverreg.go#L57
Can you state on which configuration you are running this? The behavior highly depends on the hardware.
@maruel thank you for your reply
It took a while to figure it out, but the fact that my test stopped working after a restart (it always remained low) gave me a clue that something was wrong with the access rights. Here's what I did wrong: instead of running a binary as root, I tried to give the go run command enough rights to the /sys/class/gpio directory and the export/unexport therein as well as exported pins. For some reason this worked fine for a while, but only if I called the Pin object's Function() method at least once. Long story short for posterity: compile a binary (go build .) and run it as root instead of changing groups and adjusting access rights.
Describe the bug The actual state of the pin is only read if the pin's Function() method is called beforehand.
To Reproduce Steps to reproduce the behavior:
import ( "fmt" "log"
)
func main() { _, err := host.Init() if err != nil { log.Fatal(err) }
}
In/Low Low
In/High High
fmt.Println(p.Function())
Low