maruel / dlibox

Home automation that does not depend on the internet
http://www.dlibox.com
Apache License 2.0
26 stars 1 forks source link

pio: sysfs-gpio fails on Function() due to write #11

Closed tve closed 8 years ago

tve commented 8 years ago

Error: write /sys/class/gpio/gpio34/direction: invalid argument Cause: Function calls seekWrite instead of reading: https://github.com/maruel/dlibox/blob/master/go/pio/host/sysfs/gpio.go#L70 Fix:

diff --git a/go/pio/host/sysfs/gpio.go b/go/pio/host/sysfs/gpio.go
index 35e4b1d..e265853 100644
--- a/go/pio/host/sysfs/gpio.go
+++ b/go/pio/host/sysfs/gpio.go
@@ -66,8 +66,11 @@ func (p *Pin) Function() string {
        if err := p.open(); err != nil {
                return err.Error()
        }
+       if _, err := p.fDirection.Seek(0, 0); err != nil {
+               return err.Error()
+       }
        var buf [4]byte
-       if err := seekWrite(p.fDirection, buf[:]); err != nil {
+       if _, err := p.fDirection.Read(buf[:]); err != nil {
                return err.Error()
        }
        if buf[0] == 'i' && buf[1] == 'n' {