Skip to content

Commit e878b2b

Browse files
committed
Switch GPIO library to its new name of go-gpiocdev, at version 0.9.0.
Signed-off-by: Flynn <[email protected]>
1 parent 38f7be0 commit e878b2b

File tree

5 files changed

+35
-35
lines changed

5 files changed

+35
-35
lines changed

cmd/raspberry-pi/button.go

+16-16
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ package main
2020
import (
2121
"time"
2222

23-
"github.com/warthog618/gpiod"
23+
"github.com/warthog618/go-gpiocdev"
2424
)
2525

2626
type ButtonEvent struct {
@@ -32,13 +32,13 @@ type ButtonEvent struct {
3232
type Button struct {
3333
Name string
3434
Debounce time.Duration
35-
Line *gpiod.Line
35+
Line *gpiocdev.Line
3636
PressCount int
3737

3838
btnChan chan ButtonEvent
39-
evtChan chan gpiod.LineEvent
39+
evtChan chan gpiocdev.LineEvent
4040
state int
41-
lastEvent gpiod.LineEvent
41+
lastEvent gpiocdev.LineEvent
4242
}
4343

4444
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
4848
PressCount: 0,
4949
state: 0,
5050
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,
5454
},
5555
}
5656

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) {
5959
btn.evtChan <- evt
6060
}))
6161

@@ -74,7 +74,7 @@ func (btn *Button) Close() {
7474
}
7575

7676
func (btn *Button) watch() {
77-
events := make([]gpiod.LineEvent, 0, 2)
77+
events := make([]gpiocdev.LineEvent, 0, 2)
7878

7979
// Wait for button presses
8080
for {
@@ -83,14 +83,14 @@ func (btn *Button) watch() {
8383
if btn.lastEvent.Type == evt.Type {
8484
// Insert an event of the other type, 'cause we can't
8585
// 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,
8989
Timestamp: evt.Timestamp,
9090
})
9191
} else {
92-
events = append(events, gpiod.LineEvent{
93-
Type: gpiod.LineEventRisingEdge,
92+
events = append(events, gpiocdev.LineEvent{
93+
Type: gpiocdev.LineEventRisingEdge,
9494
Timestamp: evt.Timestamp,
9595
})
9696
}
@@ -102,7 +102,7 @@ func (btn *Button) watch() {
102102
delta := evt.Timestamp - btn.lastEvent.Timestamp
103103
btn.lastEvent = evt
104104

105-
fallingEdge := (evt.Type == gpiod.LineEventFallingEdge)
105+
fallingEdge := (evt.Type == gpiocdev.LineEventFallingEdge)
106106

107107
// edge := "UP"
108108

cmd/raspberry-pi/hw.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"fmt"
2222
"time"
2323

24-
"github.com/warthog618/gpiod"
24+
"github.com/warthog618/go-gpiocdev"
2525
)
2626

2727
type HardwareStuff struct {
@@ -34,7 +34,7 @@ type HardwareStuff struct {
3434
button *Button
3535
rotary *RotaryEncoder
3636

37-
leds map[string]*gpiod.Line
37+
leds map[string]*gpiocdev.Line
3838

3939
btnChan chan ButtonEvent
4040
rotaryChan chan RotaryEvent
@@ -59,7 +59,7 @@ func NewHardwareStuff(rotaryAPin, rotaryBPin, buttonPin, ledGreenPin, ledRedPin
5959
return nil, fmt.Errorf("could not create rotary encoder on lines %d and %d: %s", rotaryAPin, rotaryBPin, err)
6060
}
6161

62-
redLED, err := gpiod.RequestLine("gpiochip0", ledRedPin, gpiod.AsOutput(1), gpiod.LineDrivePushPull)
62+
redLED, err := gpiocdev.RequestLine("gpiochip0", ledRedPin, gpiocdev.AsOutput(1), gpiocdev.LineDrivePushPull)
6363

6464
if err != nil {
6565
btn.Close()
@@ -68,7 +68,7 @@ func NewHardwareStuff(rotaryAPin, rotaryBPin, buttonPin, ledGreenPin, ledRedPin
6868
return nil, fmt.Errorf("could not create red LED on line %d: %s", ledRedPin, err)
6969
}
7070

71-
greenLED, err := gpiod.RequestLine("gpiochip0", ledGreenPin, gpiod.AsOutput(1), gpiod.LineDrivePushPull)
71+
greenLED, err := gpiocdev.RequestLine("gpiochip0", ledGreenPin, gpiocdev.AsOutput(1), gpiocdev.LineDrivePushPull)
7272

7373
if err != nil {
7474
btn.Close()
@@ -87,7 +87,7 @@ func NewHardwareStuff(rotaryAPin, rotaryBPin, buttonPin, ledGreenPin, ledRedPin
8787

8888
button: btn,
8989
rotary: rotary,
90-
leds: map[string]*gpiod.Line{
90+
leds: map[string]*gpiocdev.Line{
9191
"red": redLED,
9292
"green": greenLED,
9393
},

cmd/raspberry-pi/rotary.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"sync"
2323
"time"
2424

25-
"github.com/warthog618/gpiod"
25+
"github.com/warthog618/go-gpiocdev"
2626
)
2727

2828
type RotaryEvent struct {
@@ -43,16 +43,16 @@ type rotaryDebugEvent struct {
4343
type RotaryEncoder struct {
4444
Name string
4545
Debounce time.Duration
46-
LineA *gpiod.Line
47-
LineB *gpiod.Line
46+
LineA *gpiocdev.Line
47+
LineB *gpiocdev.Line
4848
Position int
4949

5050
Debug bool
5151

5252
lock sync.Mutex
5353

5454
evtChan chan RotaryEvent
55-
gpioChan chan gpiod.LineEvent
55+
gpioChan chan gpiocdev.LineEvent
5656
debounceChan chan interface{}
5757
debounceTimer *time.Timer
5858
state int
@@ -70,22 +70,22 @@ func NewRotaryEncoder(chip string, pinA int, pinB int, debounce time.Duration, n
7070
state: 3, // Assume we're starting with the knob stationary with both pins high.
7171
evtChan: evtChan,
7272
debounceChan: make(chan interface{}),
73-
gpioChan: make(chan gpiod.LineEvent),
73+
gpioChan: make(chan gpiocdev.LineEvent),
7474

7575
debugEvents: make([]rotaryDebugEvent, 0, 10),
7676
}
7777

78-
lineA, err := gpiod.RequestLine(chip, pinA, gpiod.WithBothEdges, gpiod.WithPullUp,
79-
gpiod.WithEventHandler(func(evt gpiod.LineEvent) {
78+
lineA, err := gpiocdev.RequestLine(chip, pinA, gpiocdev.WithBothEdges, gpiocdev.WithPullUp,
79+
gpiocdev.WithEventHandler(func(evt gpiocdev.LineEvent) {
8080
enc.gpioChan <- evt
8181
}))
8282

8383
if err != nil {
8484
return nil, err
8585
}
8686

87-
lineB, err := gpiod.RequestLine(chip, pinB, gpiod.WithBothEdges, gpiod.WithPullUp,
88-
gpiod.WithEventHandler(func(evt gpiod.LineEvent) {
87+
lineB, err := gpiocdev.RequestLine(chip, pinB, gpiocdev.WithBothEdges, gpiocdev.WithPullUp,
88+
gpiocdev.WithEventHandler(func(evt gpiocdev.LineEvent) {
8989
enc.gpioChan <- evt
9090
}))
9191

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.23
55
toolchain go1.23.2
66

77
require (
8-
github.com/warthog618/gpiod v0.8.2
8+
github.com/warthog618/go-gpiocdev v0.9.0
99
google.golang.org/grpc v1.67.1
1010
google.golang.org/protobuf v1.34.2
1111
)

go.sum

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
66
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
77
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
88
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9-
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
10-
github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
9+
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
10+
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
11+
github.com/warthog618/go-gpiocdev v0.9.0 h1:AZWUq1WObgKCO9cJCACFpwWQw6yu8vJbIE6fRZ+6cbY=
12+
github.com/warthog618/go-gpiocdev v0.9.0/go.mod h1:GV4NZC82fWJERqk7Gu0+KfLSDIBEDNm6aPGiHlmT5fY=
1113
github.com/warthog618/go-gpiosim v0.1.0 h1:2rTMTcKUVZxpUuvRKsagnKAbKpd3Bwffp87xywEDVGI=
1214
github.com/warthog618/go-gpiosim v0.1.0/go.mod h1:Ngx/LYI5toxHr4E+Vm6vTgCnt0of0tktsSuMUEJ2wCI=
13-
github.com/warthog618/gpiod v0.8.2 h1:2HgQ9pNowPp7W77sXhX5ut5Tqq1WoS3t7bXYDxtYvxc=
14-
github.com/warthog618/gpiod v0.8.2/go.mod h1:O7BNpHjCn/4YS5yFVmoFZAlY1LuYuQ8vhPf0iy/qdi4=
1515
golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE=
1616
golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg=
1717
golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=

0 commit comments

Comments
 (0)