Skip to content

Commit

Permalink
switch from gpiod to go-gpiocdev
Browse files Browse the repository at this point in the history
  • Loading branch information
warthog618 committed Mar 16, 2024
1 parent fead708 commit 6362cde
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tools into a single tool.
On Linux:

```shell
go install -o gpiocdev get github.com/warthog618/go-gpiocdev-cli
go install github.com/warthog618/go-gpiocdev-cli
```

## Usage
Expand Down
6 changes: 3 additions & 3 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"os"

"github.com/spf13/cobra"
"github.com/warthog618/gpiod"
"github.com/warthog618/go-gpiocdev"
)

func init() {
Expand All @@ -25,9 +25,9 @@ var detectCmd = &cobra.Command{

func detect(cmd *cobra.Command, args []string) {
rc := 0
cc := gpiod.Chips()
cc := gpiocdev.Chips()
for _, path := range cc {
c, err := gpiod.NewChip(path)
c, err := gpiocdev.NewChip(path)
if err != nil {
logErr(cmd, err)
rc = 1
Expand Down
10 changes: 5 additions & 5 deletions find.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"fmt"

"github.com/spf13/cobra"
"github.com/warthog618/gpiod"
"github.com/warthog618/go-gpiocdev"
)

func init() {
Expand All @@ -32,13 +32,13 @@ var (
)

func find(cmd *cobra.Command, args []string) {
copts := []gpiod.ChipOption{}
copts := []gpiocdev.ChipOption{}
if findOpts.AbiV != 0 {
copts = append(copts, gpiod.WithABIVersion(findOpts.AbiV))
copts = append(copts, gpiocdev.WithABIVersion(findOpts.AbiV))
}
for _, linename := range args {
for _, cname := range gpiod.Chips() {
c, err := gpiod.NewChip(cname, copts...)
for _, cname := range gpiocdev.Chips() {
c, err := gpiocdev.NewChip(cname, copts...)
if err != nil {
continue
}
Expand Down
20 changes: 10 additions & 10 deletions get.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/warthog618/gpiod"
"github.com/warthog618/go-gpiocdev"
)

func init() {
Expand Down Expand Up @@ -54,7 +54,7 @@ func get(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
c, err := gpiod.NewChip(name, gpiod.WithConsumer("gpiodctl-get"))
c, err := gpiocdev.NewChip(name, gpiocdev.WithConsumer("gpiocdevctl-get"))
if err != nil {
return err
}
Expand All @@ -78,28 +78,28 @@ func get(cmd *cobra.Command, args []string) error {
return nil
}

func makeGetOpts() []gpiod.LineReqOption {
opts := []gpiod.LineReqOption{}
func makeGetOpts() []gpiocdev.LineReqOption {
opts := []gpiocdev.LineReqOption{}
if getOpts.ActiveLow {
opts = append(opts, gpiod.AsActiveLow)
opts = append(opts, gpiocdev.AsActiveLow)
}
if !getOpts.AsIs {
opts = append(opts, gpiod.AsInput)
opts = append(opts, gpiocdev.AsInput)
}
bias := strings.ToLower(getOpts.Bias)
switch bias {
case "pull-up":
opts = append(opts, gpiod.WithPullUp)
opts = append(opts, gpiocdev.WithPullUp)
case "pull-down":
opts = append(opts, gpiod.WithPullDown)
opts = append(opts, gpiocdev.WithPullDown)
case "disable":
opts = append(opts, gpiod.WithBiasDisabled)
opts = append(opts, gpiocdev.WithBiasDisabled)
case "as-is":
fallthrough
default:
}
if getOpts.AbiV != 0 {
opts = append(opts, gpiod.WithABIVersion(getOpts.AbiV))
opts = append(opts, gpiocdev.WithABIVersion(getOpts.AbiV))
}
return opts
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/spf13/cobra v1.8.0
github.com/warthog618/gpiod v0.8.2
github.com/warthog618/go-gpiocdev v0.9.0
)

require (
Expand Down
6 changes: 3 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
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/gpiod v0.8.2 h1:2HgQ9pNowPp7W77sXhX5ut5Tqq1WoS3t7bXYDxtYvxc=
github.com/warthog618/gpiod v0.8.2/go.mod h1:O7BNpHjCn/4YS5yFVmoFZAlY1LuYuQ8vhPf0iy/qdi4=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand Down
24 changes: 12 additions & 12 deletions info.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"strings"

"github.com/spf13/cobra"
"github.com/warthog618/gpiod"
"github.com/warthog618/go-gpiocdev"
)

func init() {
Expand All @@ -37,14 +37,14 @@ func info(cmd *cobra.Command, args []string) {
cc := []string(nil)
cc = append(cc, args...)
if len(cc) == 0 {
cc = gpiod.Chips()
cc = gpiocdev.Chips()
}
copts := []gpiod.ChipOption{}
copts := []gpiocdev.ChipOption{}
if infoOpts.AbiV != 0 {
copts = append(copts, gpiod.WithABIVersion(infoOpts.AbiV))
copts = append(copts, gpiocdev.WithABIVersion(infoOpts.AbiV))
}
for _, path := range cc {
c, err := gpiod.NewChip(path, copts...)
c, err := gpiocdev.NewChip(path, copts...)
if err != nil {
logErr(cmd, err)
rc = 1
Expand All @@ -65,7 +65,7 @@ func info(cmd *cobra.Command, args []string) {
os.Exit(rc)
}

func printLineInfo(li gpiod.LineInfo) {
func printLineInfo(li gpiocdev.LineInfo) {
if len(li.Name) == 0 {
li.Name = "unnamed"
}
Expand All @@ -80,7 +80,7 @@ func printLineInfo(li gpiod.LineInfo) {
li.Consumer = "unused"
}
attrs := []string(nil)
if li.Config.Direction == gpiod.LineDirectionOutput {
if li.Config.Direction == gpiocdev.LineDirectionOutput {
attrs = append(attrs, "output")
} else {
attrs = append(attrs, "input")
Expand All @@ -92,17 +92,17 @@ func printLineInfo(li gpiod.LineInfo) {
attrs = append(attrs, "used")
}
switch li.Config.Drive {
case gpiod.LineDriveOpenDrain:
case gpiocdev.LineDriveOpenDrain:
attrs = append(attrs, "open-drain")
case gpiod.LineDriveOpenSource:
case gpiocdev.LineDriveOpenSource:
attrs = append(attrs, "open-source")
}
switch li.Config.Bias {
case gpiod.LineBiasPullUp:
case gpiocdev.LineBiasPullUp:
attrs = append(attrs, "pull-up")
case gpiod.LineBiasPullDown:
case gpiocdev.LineBiasPullDown:
attrs = append(attrs, "pull-down")
case gpiod.LineBiasDisabled:
case gpiocdev.LineBiasDisabled:
attrs = append(attrs, "bias-disabled")
}
if li.Config.DebouncePeriod != 0 {
Expand Down
8 changes: 4 additions & 4 deletions gpiodctl.go → main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
)

var rootCmd = &cobra.Command{
Use: "gpiodctl",
Short: "gpiodctl is a utility to control GPIO lines",
Long: "gpiodctl is a utility to control GPIO lines on Linux GPIO character devices",
Use: "gpiocdev",
Short: "gpiocdev is a utility to control GPIO lines",
Long: "gpiocdev is a utility to control GPIO lines on Linux GPIO character devices",
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
},
Expand All @@ -32,5 +32,5 @@ func main() {
}

func logErr(cmd *cobra.Command, err error) {
fmt.Fprintf(os.Stderr, "gpiodctl %s: %s\n", cmd.Name(), err)
fmt.Fprintf(os.Stderr, "gpiocdev %s: %s\n", cmd.Name(), err)
}
36 changes: 18 additions & 18 deletions mon.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"time"

"github.com/spf13/cobra"
"github.com/warthog618/gpiod"
"github.com/warthog618/go-gpiocdev"
)

func init() {
Expand Down Expand Up @@ -69,17 +69,17 @@ func mon(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
copts := []gpiod.ChipOption{gpiod.WithConsumer("gpiodctl-mon")}
copts := []gpiocdev.ChipOption{gpiocdev.WithConsumer("gpiocdevctl-mon")}
if monOpts.AbiV != 0 {
copts = append(copts, gpiod.WithABIVersion(monOpts.AbiV))
copts = append(copts, gpiocdev.WithABIVersion(monOpts.AbiV))
}
c, err := gpiod.NewChip(name, copts...)
c, err := gpiocdev.NewChip(name, copts...)
if err != nil {
return err
}
defer c.Close()
evtchan := make(chan gpiod.LineEvent)
eh := func(evt gpiod.LineEvent) {
evtchan := make(chan gpiocdev.LineEvent)
eh := func(evt gpiocdev.LineEvent) {
evtchan <- evt
}
opts := makeMonOpts(eh)
Expand All @@ -92,7 +92,7 @@ func mon(cmd *cobra.Command, args []string) error {
return nil
}

func monWait(evtchan <-chan gpiod.LineEvent) {
func monWait(evtchan <-chan gpiocdev.LineEvent) {
sigdone := make(chan os.Signal, 1)
signal.Notify(sigdone, os.Interrupt, syscall.SIGTERM)
defer signal.Stop(sigdone)
Expand All @@ -103,7 +103,7 @@ func monWait(evtchan <-chan gpiod.LineEvent) {
if !monOpts.Quiet {
t := time.Now()
edge := "rising"
if evt.Type == gpiod.LineEventFallingEdge {
if evt.Type == gpiocdev.LineEventFallingEdge {
edge = "falling"
}
if evt.Seqno != 0 {
Expand Down Expand Up @@ -132,36 +132,36 @@ func monWait(evtchan <-chan gpiod.LineEvent) {
}
}

func makeMonOpts(eh gpiod.EventHandler) []gpiod.LineReqOption {
opts := []gpiod.LineReqOption{gpiod.WithEventHandler(eh)}
func makeMonOpts(eh gpiocdev.EventHandler) []gpiocdev.LineReqOption {
opts := []gpiocdev.LineReqOption{gpiocdev.WithEventHandler(eh)}
if monOpts.ActiveLow {
opts = append(opts, gpiod.AsActiveLow)
opts = append(opts, gpiocdev.AsActiveLow)
}
edge := strings.ToLower(monOpts.Edge)
switch edge {
case "falling":
opts = append(opts, gpiod.WithFallingEdge)
opts = append(opts, gpiocdev.WithFallingEdge)
case "rising":
opts = append(opts, gpiod.WithRisingEdge)
opts = append(opts, gpiocdev.WithRisingEdge)
case "both":
fallthrough
default:
opts = append(opts, gpiod.WithBothEdges)
opts = append(opts, gpiocdev.WithBothEdges)
}
bias := strings.ToLower(monOpts.Bias)
switch bias {
case "pull-up":
opts = append(opts, gpiod.WithPullUp)
opts = append(opts, gpiocdev.WithPullUp)
case "pull-down":
opts = append(opts, gpiod.WithPullDown)
opts = append(opts, gpiocdev.WithPullDown)
case "disable":
opts = append(opts, gpiod.WithBiasDisabled)
opts = append(opts, gpiocdev.WithBiasDisabled)
case "as-is":
fallthrough
default:
}
if monOpts.DebouncePeriod != 0 {
opts = append(opts, gpiod.WithDebounce(monOpts.DebouncePeriod))
opts = append(opts, gpiocdev.WithDebounce(monOpts.DebouncePeriod))
}
return opts
}
22 changes: 11 additions & 11 deletions set.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"time"

"github.com/spf13/cobra"
"github.com/warthog618/gpiod"
"github.com/warthog618/go-gpiocdev"
)

func init() {
Expand Down Expand Up @@ -99,7 +99,7 @@ func set(cmd *cobra.Command, args []string) error {
ll = append(ll, o)
vv = append(vv, v)
}
c, err := gpiod.NewChip(name, gpiod.WithConsumer("gpiodctl-set"))
c, err := gpiocdev.NewChip(name, gpiocdev.WithConsumer("gpiocdevctl-set"))
if err != nil {
return err
}
Expand Down Expand Up @@ -147,35 +147,35 @@ func setWait() {
}
}

func makeSetOpts(vv []int) []gpiod.LineReqOption {
opts := []gpiod.LineReqOption{gpiod.AsOutput(vv...)}
func makeSetOpts(vv []int) []gpiocdev.LineReqOption {
opts := []gpiocdev.LineReqOption{gpiocdev.AsOutput(vv...)}
if setOpts.ActiveLow {
opts = append(opts, gpiod.AsActiveLow)
opts = append(opts, gpiocdev.AsActiveLow)
}
bias := strings.ToLower(setOpts.Bias)
switch bias {
case "pull-up":
opts = append(opts, gpiod.WithPullUp)
opts = append(opts, gpiocdev.WithPullUp)
case "pull-down":
opts = append(opts, gpiod.WithPullDown)
opts = append(opts, gpiocdev.WithPullDown)
case "disable":
opts = append(opts, gpiod.WithBiasDisabled)
opts = append(opts, gpiocdev.WithBiasDisabled)
case "as-is":
fallthrough
default:
}
drive := strings.ToLower(setOpts.Drive)
switch drive {
case "open-drain":
opts = append(opts, gpiod.AsOpenDrain)
opts = append(opts, gpiocdev.AsOpenDrain)
case "open-source":
opts = append(opts, gpiod.AsOpenSource)
opts = append(opts, gpiocdev.AsOpenSource)
case "push-pull":
fallthrough
default:
}
if setOpts.AbiV != 0 {
opts = append(opts, gpiod.WithABIVersion(setOpts.AbiV))
opts = append(opts, gpiocdev.WithABIVersion(setOpts.AbiV))
}
return opts
}
Expand Down
4 changes: 2 additions & 2 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ func init() {
var versionCmd = &cobra.Command{
Use: "version",
Short: "Display the version",
Long: `All software has versions. This is gpiod's`,
Long: `All software has versions. This is gpiocdev's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("%s (gpiod) %s\n", os.Args[0], version)
fmt.Printf("%s (gpiocdev) %s\n", os.Args[0], version)
},
}
Loading

0 comments on commit 6362cde

Please sign in to comment.