Skip to content

Unexport digital pins on Close().#44

Open
wujiang wants to merge 1 commit intokidoman:masterfrom
wujiang:wujiang/digital-pin-close
Open

Unexport digital pins on Close().#44
wujiang wants to merge 1 commit intokidoman:masterfrom
wujiang:wujiang/digital-pin-close

Conversation

@wujiang
Copy link
Contributor

@wujiang wujiang commented Dec 29, 2015

Exported digital pins can be uninitialized.

How to reproduce the problem

package main

import (
        "fmt"

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

func main() {
        embd.InitGPIO()
        defer embd.CloseGPIO()
        fmt.Println(embd.SetDirection(12, embd.Out))
}
/tmp $ go build
/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied
/tmp $ ./tmp
write /sys/class/gpio/export: device or resource busy
/tmp $ ./tmp
write /sys/class/gpio/export: device or resource busy
/tmp $ ls /sys/class/gpio/
export  gpio12  gpiochip0  unexport

After the change:

/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied
/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied
/tmp $ ./tmp
open /sys/class/gpio/gpio12/direction: permission denied

Exported digital pins can be uninitialized.
@jpillora
Copy link

👍 Just ran into this issue

@tve
Copy link
Contributor

tve commented Sep 25, 2016

While I understand the problem, it seems to me that the unexporting should happen last after closing the exported files. So it seems that the Close() calls should be skipped on !initialized but the order of events shouldn't be changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants