From c6963611b1840c84f46e85ef3abf393cb97a7168 Mon Sep 17 00:00:00 2001 From: Flynn Date: Mon, 14 Oct 2024 15:04:15 -0400 Subject: [PATCH] Switch GPIO library to its new name of go-gpiocdev, at version 0.9.0. Signed-off-by: Flynn --- cmd/raspberry-pi/button.go | 32 ++++++++++++++++---------------- cmd/raspberry-pi/hw.go | 10 +++++----- cmd/raspberry-pi/rotary.go | 18 +++++++++--------- go.mod | 2 +- go.sum | 8 ++++---- 5 files changed, 35 insertions(+), 35 deletions(-) diff --git a/cmd/raspberry-pi/button.go b/cmd/raspberry-pi/button.go index f64f978..0798e87 100644 --- a/cmd/raspberry-pi/button.go +++ b/cmd/raspberry-pi/button.go @@ -20,7 +20,7 @@ package main import ( "time" - "github.com/warthog618/gpiod" + "github.com/warthog618/go-gpiocdev" ) type ButtonEvent struct { @@ -32,13 +32,13 @@ type ButtonEvent struct { type Button struct { Name string Debounce time.Duration - Line *gpiod.Line + Line *gpiocdev.Line PressCount int btnChan chan ButtonEvent - evtChan chan gpiod.LineEvent + evtChan chan gpiocdev.LineEvent state int - lastEvent gpiod.LineEvent + lastEvent gpiocdev.LineEvent } 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 PressCount: 0, state: 0, btnChan: btnChan, - evtChan: make(chan gpiod.LineEvent), - lastEvent: gpiod.LineEvent{ - Type: gpiod.LineEventRisingEdge, + evtChan: make(chan gpiocdev.LineEvent), + lastEvent: gpiocdev.LineEvent{ + Type: gpiocdev.LineEventRisingEdge, }, } - line, err := gpiod.RequestLine(chip, pin, gpiod.WithBothEdges, gpiod.WithPullDown, - gpiod.WithEventHandler(func(evt gpiod.LineEvent) { + line, err := gpiocdev.RequestLine(chip, pin, gpiocdev.WithBothEdges, gpiocdev.WithPullDown, + gpiocdev.WithEventHandler(func(evt gpiocdev.LineEvent) { btn.evtChan <- evt })) @@ -74,7 +74,7 @@ func (btn *Button) Close() { } func (btn *Button) watch() { - events := make([]gpiod.LineEvent, 0, 2) + events := make([]gpiocdev.LineEvent, 0, 2) // Wait for button presses for { @@ -83,14 +83,14 @@ func (btn *Button) watch() { if btn.lastEvent.Type == evt.Type { // Insert an event of the other type, 'cause we can't // get two of the same edge in a row! - if evt.Type == gpiod.LineEventRisingEdge { - events = append(events, gpiod.LineEvent{ - Type: gpiod.LineEventFallingEdge, + if evt.Type == gpiocdev.LineEventRisingEdge { + events = append(events, gpiocdev.LineEvent{ + Type: gpiocdev.LineEventFallingEdge, Timestamp: evt.Timestamp, }) } else { - events = append(events, gpiod.LineEvent{ - Type: gpiod.LineEventRisingEdge, + events = append(events, gpiocdev.LineEvent{ + Type: gpiocdev.LineEventRisingEdge, Timestamp: evt.Timestamp, }) } @@ -102,7 +102,7 @@ func (btn *Button) watch() { delta := evt.Timestamp - btn.lastEvent.Timestamp btn.lastEvent = evt - fallingEdge := (evt.Type == gpiod.LineEventFallingEdge) + fallingEdge := (evt.Type == gpiocdev.LineEventFallingEdge) // edge := "UP" diff --git a/cmd/raspberry-pi/hw.go b/cmd/raspberry-pi/hw.go index 10e6563..4a7d1c7 100644 --- a/cmd/raspberry-pi/hw.go +++ b/cmd/raspberry-pi/hw.go @@ -21,7 +21,7 @@ import ( "fmt" "time" - "github.com/warthog618/gpiod" + "github.com/warthog618/go-gpiocdev" ) type HardwareStuff struct { @@ -34,7 +34,7 @@ type HardwareStuff struct { button *Button rotary *RotaryEncoder - leds map[string]*gpiod.Line + leds map[string]*gpiocdev.Line btnChan chan ButtonEvent rotaryChan chan RotaryEvent @@ -59,7 +59,7 @@ func NewHardwareStuff(rotaryAPin, rotaryBPin, buttonPin, ledGreenPin, ledRedPin return nil, fmt.Errorf("could not create rotary encoder on lines %d and %d: %s", rotaryAPin, rotaryBPin, err) } - redLED, err := gpiod.RequestLine("gpiochip0", ledRedPin, gpiod.AsOutput(1), gpiod.LineDrivePushPull) + redLED, err := gpiocdev.RequestLine("gpiochip0", ledRedPin, gpiocdev.AsOutput(1), gpiocdev.LineDrivePushPull) if err != nil { btn.Close() @@ -68,7 +68,7 @@ func NewHardwareStuff(rotaryAPin, rotaryBPin, buttonPin, ledGreenPin, ledRedPin return nil, fmt.Errorf("could not create red LED on line %d: %s", ledRedPin, err) } - greenLED, err := gpiod.RequestLine("gpiochip0", ledGreenPin, gpiod.AsOutput(1), gpiod.LineDrivePushPull) + greenLED, err := gpiocdev.RequestLine("gpiochip0", ledGreenPin, gpiocdev.AsOutput(1), gpiocdev.LineDrivePushPull) if err != nil { btn.Close() @@ -87,7 +87,7 @@ func NewHardwareStuff(rotaryAPin, rotaryBPin, buttonPin, ledGreenPin, ledRedPin button: btn, rotary: rotary, - leds: map[string]*gpiod.Line{ + leds: map[string]*gpiocdev.Line{ "red": redLED, "green": greenLED, }, diff --git a/cmd/raspberry-pi/rotary.go b/cmd/raspberry-pi/rotary.go index 452507c..2e0c66e 100644 --- a/cmd/raspberry-pi/rotary.go +++ b/cmd/raspberry-pi/rotary.go @@ -22,7 +22,7 @@ import ( "sync" "time" - "github.com/warthog618/gpiod" + "github.com/warthog618/go-gpiocdev" ) type RotaryEvent struct { @@ -43,8 +43,8 @@ type rotaryDebugEvent struct { type RotaryEncoder struct { Name string Debounce time.Duration - LineA *gpiod.Line - LineB *gpiod.Line + LineA *gpiocdev.Line + LineB *gpiocdev.Line Position int Debug bool @@ -52,7 +52,7 @@ type RotaryEncoder struct { lock sync.Mutex evtChan chan RotaryEvent - gpioChan chan gpiod.LineEvent + gpioChan chan gpiocdev.LineEvent debounceChan chan interface{} debounceTimer *time.Timer state int @@ -70,13 +70,13 @@ func NewRotaryEncoder(chip string, pinA int, pinB int, debounce time.Duration, n state: 3, // Assume we're starting with the knob stationary with both pins high. evtChan: evtChan, debounceChan: make(chan interface{}), - gpioChan: make(chan gpiod.LineEvent), + gpioChan: make(chan gpiocdev.LineEvent), debugEvents: make([]rotaryDebugEvent, 0, 10), } - lineA, err := gpiod.RequestLine(chip, pinA, gpiod.WithBothEdges, gpiod.WithPullUp, - gpiod.WithEventHandler(func(evt gpiod.LineEvent) { + lineA, err := gpiocdev.RequestLine(chip, pinA, gpiocdev.WithBothEdges, gpiocdev.WithPullUp, + gpiocdev.WithEventHandler(func(evt gpiocdev.LineEvent) { enc.gpioChan <- evt })) @@ -84,8 +84,8 @@ func NewRotaryEncoder(chip string, pinA int, pinB int, debounce time.Duration, n return nil, err } - lineB, err := gpiod.RequestLine(chip, pinB, gpiod.WithBothEdges, gpiod.WithPullUp, - gpiod.WithEventHandler(func(evt gpiod.LineEvent) { + lineB, err := gpiocdev.RequestLine(chip, pinB, gpiocdev.WithBothEdges, gpiocdev.WithPullUp, + gpiocdev.WithEventHandler(func(evt gpiocdev.LineEvent) { enc.gpioChan <- evt })) diff --git a/go.mod b/go.mod index f68ea80..4274bd0 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 toolchain go1.23.2 require ( - github.com/warthog618/gpiod v0.8.2 + github.com/warthog618/go-gpiocdev v0.9.0 google.golang.org/grpc v1.67.1 google.golang.org/protobuf v1.34.2 ) diff --git a/go.sum b/go.sum index fa78ed7..c4aced3 100644 --- a/go.sum +++ b/go.sum @@ -6,12 +6,12 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/warthog618/go-gpiocdev v0.9.0 h1:AZWUq1WObgKCO9cJCACFpwWQw6yu8vJbIE6fRZ+6cbY= +github.com/warthog618/go-gpiocdev v0.9.0/go.mod h1:GV4NZC82fWJERqk7Gu0+KfLSDIBEDNm6aPGiHlmT5fY= github.com/warthog618/go-gpiosim v0.1.0 h1:2rTMTcKUVZxpUuvRKsagnKAbKpd3Bwffp87xywEDVGI= github.com/warthog618/go-gpiosim v0.1.0/go.mod h1:Ngx/LYI5toxHr4E+Vm6vTgCnt0of0tktsSuMUEJ2wCI= -github.com/warthog618/gpiod v0.8.2 h1:2HgQ9pNowPp7W77sXhX5ut5Tqq1WoS3t7bXYDxtYvxc= -github.com/warthog618/gpiod v0.8.2/go.mod h1:O7BNpHjCn/4YS5yFVmoFZAlY1LuYuQ8vhPf0iy/qdi4= golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= golang.org/x/sys v0.24.0 h1:Twjiwq9dn6R1fQcyiK+wQyHWfaz/BJB+YIpzU/Cv3Xg=