From 5f8a0fced0d2b266f9d12fb253f066374fc115ef Mon Sep 17 00:00:00 2001 From: SjB Date: Wed, 9 Apr 2014 00:38:19 -0400 Subject: [PATCH] Stop Watching pin when Closing Closing a pin will automatically check and close any pin that where being watch for interrupt. --- gpiodriver.go | 6 ++++++ host/generic/digitalpin.go | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/gpiodriver.go b/gpiodriver.go index 69d0516..d2f4808 100644 --- a/gpiodriver.go +++ b/gpiodriver.go @@ -100,6 +100,12 @@ func (io *gpioDriver) RegisterInterrupt(p InterruptPin) error { func (io *gpioDriver) UnregisterInterrupt(p InterruptPin) error { fd := p.Fd() + + // check if we are watching this pin + if _, ok := io.watchEventCallbacks[fd]; !ok { + return nil + } + if err := syscall.EpollCtl(epollFD, syscall.EPOLL_CTL_DEL, fd, nil); err != nil { return err } diff --git a/host/generic/digitalpin.go b/host/generic/digitalpin.go index 1a50d5c..955e30f 100644 --- a/host/generic/digitalpin.go +++ b/host/generic/digitalpin.go @@ -276,6 +276,10 @@ func (p *digitalPin) Close() error { return err } + if err := p.StopWatching(); err != nil { + return err + } + if !p.initialized { return nil }