From cd54380887d2bce263b75a3e186e70da03cc5f67 Mon Sep 17 00:00:00 2001 From: Karan Misra Date: Sat, 8 Feb 2014 02:21:18 +0530 Subject: [PATCH] matrix4x3: client should ensure rpio is initialised before using --- interface/keypad/matrix4x3/matrix4x3.go | 12 ++---------- samples/keypad/matrix4x3.go | 4 ++++ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/interface/keypad/matrix4x3/matrix4x3.go b/interface/keypad/matrix4x3/matrix4x3.go index 8cfc3ef..8bdce6e 100644 --- a/interface/keypad/matrix4x3/matrix4x3.go +++ b/interface/keypad/matrix4x3/matrix4x3.go @@ -78,7 +78,7 @@ type Matrix4x3 interface { PressedKey() (Key, error) // Close. - Close() error + Close() } type matrix4x3 struct { @@ -127,10 +127,6 @@ func (d *matrix4x3) setup() (err error) { d.mu.Lock() defer d.mu.Unlock() - if err = rpio.Open(); err != nil { - return - } - for i := 0; i < rows; i++ { d.rpioRowPins[i].Input() d.rpioRowPins[i].PullUp() @@ -210,12 +206,8 @@ func (d *matrix4x3) Run() { } // Close. -func (d *matrix4x3) Close() (err error) { +func (d *matrix4x3) Close() { if d.quit != nil { d.quit <- true } - - rpio.Close() - - return } diff --git a/samples/keypad/matrix4x3.go b/samples/keypad/matrix4x3.go index 4a0eb1f..5677d01 100644 --- a/samples/keypad/matrix4x3.go +++ b/samples/keypad/matrix4x3.go @@ -5,12 +5,16 @@ import ( "time" "github.com/kid0m4n/go-rpi/interface/keypad/matrix4x3" + "github.com/stianeikeland/go-rpio" ) func main() { rowPins := []int{4, 17, 27, 22} colPins := []int{23, 24, 25} + rpio.Open() + defer rpio.Close() + keypad := matrix4x3.New(rowPins, colPins) for {