-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect.go
41 lines (35 loc) · 787 Bytes
/
detect.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]>
//
// SPDX-License-Identifier: MIT
package main
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/warthog618/go-gpiocdev"
)
func init() {
rootCmd.AddCommand(detectCmd)
}
var detectCmd = &cobra.Command{
Use: "detect",
Short: "Detect available GPIO chips",
Long: `List all GPIO chips, print their labels and number of GPIO lines.`,
Run: detect,
}
func detect(cmd *cobra.Command, args []string) {
rc := 0
cc := gpiocdev.Chips()
for _, path := range cc {
c, err := gpiocdev.NewChip(path)
if err != nil {
logErr(cmd, err)
rc = 1
continue
}
fmt.Printf("%s [%s] (%d lines) using kernel uAPI v%d\n",
c.Name, c.Label, c.Lines(), c.UapiAbiVersion())
c.Close()
}
os.Exit(rc)
}