mrmorphic / hwio

Go library for hardware I/O control, in the programming style of Arduino
BSD 3-Clause "New" or "Revised" License
328 stars 40 forks source link

cannot reconnect to a closed pin #30

Closed mikedewar closed 10 years ago

mikedewar commented 10 years ago

If I connect to a pin, then close that pin, then try to connect again I receive the error

Pin 43 is already assigned to module gpio

Code below.

package main

import (
    "github.com/mrmorphic/hwio"
)

func main() {
    pin, e := hwio.GetPinWithMode("P9.11", hwio.INPUT)
    if e != nil {
        panic(e)
    }
    err := hwio.ClosePin(pin)
    if err != nil {
        panic(e)
    }
    pin, e = hwio.GetPinWithMode("P9.11", hwio.INPUT)
    if e != nil {
        panic(e)
    }
}

which pukes as follows, on a BeagleBoneBlack:

panic: Pin 43 is already assigned to module gpio

goroutine 1 [running]:
runtime.panic(0xf9e20, 0x10500bb8)
    /home/root/go/src/pkg/runtime/panic.c:266 +0x134
main.main()
    /home/root/projects/go/src/github.com/nytlabs/magnet/main.go:18 +0x154
mrmorphic commented 10 years ago

I just committed a fix for that if you want to take a look. The close function was unexporting, but not updating the list of assigned pins.

mikedewar commented 10 years ago

Brilliant! Thanks so much.