mirror of
https://github.com/kidoman/embd
synced 2024-12-22 04:40:04 +01:00
matrix4x3: client should ensure rpio is initialised before using
This commit is contained in:
parent
d2ffacd22c
commit
cd54380887
@ -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
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user