@@ -20,7 +20,7 @@ package main
20
20
import (
21
21
"time"
22
22
23
- "github.com/warthog618/gpiod "
23
+ "github.com/warthog618/go-gpiocdev "
24
24
)
25
25
26
26
type ButtonEvent struct {
@@ -32,13 +32,13 @@ type ButtonEvent struct {
32
32
type Button struct {
33
33
Name string
34
34
Debounce time.Duration
35
- Line * gpiod .Line
35
+ Line * gpiocdev .Line
36
36
PressCount int
37
37
38
38
btnChan chan ButtonEvent
39
- evtChan chan gpiod .LineEvent
39
+ evtChan chan gpiocdev .LineEvent
40
40
state int
41
- lastEvent gpiod .LineEvent
41
+ lastEvent gpiocdev .LineEvent
42
42
}
43
43
44
44
func NewButton (chip string , pin int , debounce time.Duration , name string , btnChan chan ButtonEvent ) (* Button , error ) {
@@ -48,14 +48,14 @@ func NewButton(chip string, pin int, debounce time.Duration, name string, btnCha
48
48
PressCount : 0 ,
49
49
state : 0 ,
50
50
btnChan : btnChan ,
51
- evtChan : make (chan gpiod .LineEvent ),
52
- lastEvent : gpiod .LineEvent {
53
- Type : gpiod .LineEventRisingEdge ,
51
+ evtChan : make (chan gpiocdev .LineEvent ),
52
+ lastEvent : gpiocdev .LineEvent {
53
+ Type : gpiocdev .LineEventRisingEdge ,
54
54
},
55
55
}
56
56
57
- line , err := gpiod .RequestLine (chip , pin , gpiod .WithBothEdges , gpiod .WithPullDown ,
58
- gpiod .WithEventHandler (func (evt gpiod .LineEvent ) {
57
+ line , err := gpiocdev .RequestLine (chip , pin , gpiocdev .WithBothEdges , gpiocdev .WithPullDown ,
58
+ gpiocdev .WithEventHandler (func (evt gpiocdev .LineEvent ) {
59
59
btn .evtChan <- evt
60
60
}))
61
61
@@ -74,7 +74,7 @@ func (btn *Button) Close() {
74
74
}
75
75
76
76
func (btn * Button ) watch () {
77
- events := make ([]gpiod .LineEvent , 0 , 2 )
77
+ events := make ([]gpiocdev .LineEvent , 0 , 2 )
78
78
79
79
// Wait for button presses
80
80
for {
@@ -83,14 +83,14 @@ func (btn *Button) watch() {
83
83
if btn .lastEvent .Type == evt .Type {
84
84
// Insert an event of the other type, 'cause we can't
85
85
// get two of the same edge in a row!
86
- if evt .Type == gpiod .LineEventRisingEdge {
87
- events = append (events , gpiod .LineEvent {
88
- Type : gpiod .LineEventFallingEdge ,
86
+ if evt .Type == gpiocdev .LineEventRisingEdge {
87
+ events = append (events , gpiocdev .LineEvent {
88
+ Type : gpiocdev .LineEventFallingEdge ,
89
89
Timestamp : evt .Timestamp ,
90
90
})
91
91
} else {
92
- events = append (events , gpiod .LineEvent {
93
- Type : gpiod .LineEventRisingEdge ,
92
+ events = append (events , gpiocdev .LineEvent {
93
+ Type : gpiocdev .LineEventRisingEdge ,
94
94
Timestamp : evt .Timestamp ,
95
95
})
96
96
}
@@ -102,7 +102,7 @@ func (btn *Button) watch() {
102
102
delta := evt .Timestamp - btn .lastEvent .Timestamp
103
103
btn .lastEvent = evt
104
104
105
- fallingEdge := (evt .Type == gpiod .LineEventFallingEdge )
105
+ fallingEdge := (evt .Type == gpiocdev .LineEventFallingEdge )
106
106
107
107
// edge := "UP"
108
108
0 commit comments