Give rpi some time to link digital pin property

It looks like Raspberry pi needs some time to get a digital pin
link properly after it is being exported.

Sample code to run:

```go
package main

import (
        "fmt"

        "github.com/kidoman/embd"
         _ "github.com/kidoman/embd/host/rpi"
)

func main() {
        defer embd.CloseGPIO()
        fmt.Println(embd.SetDirection(10, embd.Out))
}

```

- before the change, the output is:
`open /sys/class/gpio/gpio10/direction: permission denied`

- after the change, the output is `<nil>`

Close #52
This commit is contained in:
Wu Jiang 2016-01-21 15:42:27 -05:00
parent bfcd1345fe
commit b02fcae87d
1 changed files with 2 additions and 0 deletions

View File

@ -47,6 +47,8 @@ func (p *digitalPin) init() error {
if err = p.export(); err != nil {
return err
}
// give rpi some time to link digital pin property
time.Sleep(100 * time.Millisecond)
if p.dir, err = p.directionFile(); err != nil {
return err
}