-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aabce06
commit 70fc8ea
Showing
24 changed files
with
443 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]>. | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
find_line_by_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-FileCopyrightText: 2024 Kent Gibson <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
// A simple example that finds a line by name. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/warthog618/go-gpiocdev" | ||
) | ||
|
||
// Finds the chip and offset of a named line. | ||
func main() { | ||
name := "GPIO22" | ||
if len(os.Args) > 1 { | ||
name = os.Args[1] | ||
} | ||
chip, offset, err := gpiocdev.FindLine(name) | ||
if err != nil { | ||
fmt.Printf("Finding line %s returned error: %s\n", name, err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("%s:%d %s\n", chip, offset, name) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]>. | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
get_chip_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// SPDX-FileCopyrightText: 2020 Kent Gibson <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
// A simple example that read the info for gpiochip0. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/warthog618/go-gpiocdev" | ||
) | ||
|
||
// Reads the info for gpiochip0. | ||
func main() { | ||
c, err := gpiocdev.NewChip("gpiochip0") | ||
if err != nil { | ||
fmt.Printf("Opening chip returned error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer c.Close() | ||
|
||
fmt.Printf("%s (%s): %d lines\n", c.Name, c.Label, c.Lines()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]>. | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
get_line_info |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// SPDX-FileCopyrightText: 2020 Kent Gibson <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
// A simple example that read the info for line 22 on gpiochip0. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/warthog618/go-gpiocdev" | ||
) | ||
|
||
// Reads the info for line 22 on gpiochip0. | ||
func main() { | ||
c, err := gpiocdev.NewChip("gpiochip0") | ||
if err != nil { | ||
fmt.Printf("Opening chip returned error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer c.Close() | ||
|
||
info, err := c.LineInfo(22) | ||
if err != nil { | ||
fmt.Printf("Reading line info returned error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
fmt.Printf("%v\n", info) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
get_line_value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// SPDX-FileCopyrightText: 2020 Kent Gibson <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
// A simple example that reads an input pin. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/warthog618/go-gpiocdev" | ||
) | ||
|
||
// This example reads line 22 on gpiochip0. | ||
func main() { | ||
offset := 22 | ||
chip := "gpiochip0" | ||
l, err := gpiocdev.RequestLine(chip, offset, gpiocdev.AsInput) | ||
if err != nil { | ||
panic(err) | ||
} | ||
defer l.Close() | ||
|
||
values := map[int]string{0: "inactive", 1: "active"} | ||
v, err := l.Value() | ||
fmt.Printf("%s:%d %s\n", chip, offset, values[v]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
get_multiple_line_values |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-FileCopyrightText: 2020 Kent Gibson <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
// A simple example that reads multiple input pins. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/warthog618/go-gpiocdev" | ||
) | ||
|
||
// This example reads lines 21 and 22 on gpiochip0. | ||
func main() { | ||
offsets := []int{21, 22} | ||
chip := "gpiochip0" | ||
l, err := gpiocdev.RequestLines(chip, offsets, gpiocdev.AsInput) | ||
if err != nil { | ||
fmt.Printf("Requesting lines returned error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
defer l.Close() | ||
|
||
values := map[int]string{0: "inactive", 1: "active"} | ||
vv := []int{0, 0} | ||
err = l.Values(vv) | ||
if err != nil { | ||
fmt.Printf("Reading values returned error: %s\n", err) | ||
os.Exit(1) | ||
} | ||
for i, o := range offsets { | ||
fmt.Printf("%s:%d %s\n", chip, o, values[vv[i]]) | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
reconfigure_input_to_output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-FileCopyrightText: 2020 Kent Gibson <[email protected]> | ||
// | ||
// SPDX-License-Identifier: MIT | ||
|
||
//go:build linux | ||
// +build linux | ||
|
||
// A simple example that requests a line as an input and subsequently switches it to an output. | ||
// DO NOT run this on a platform where that line is externally driven. | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/warthog618/go-gpiocdev" | ||
) | ||
|
||
// This example requests line 23 on gpiochip0 as an input then switches it to an output. | ||
// DO NOT run this on a platform where that line is externally driven. | ||
func main() { | ||
offset := 23 | ||
chip := "gpiochip0" | ||
l, err := gpiocdev.RequestLine(chip, offset, gpiocdev.AsInput) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// revert line to input on the way out. | ||
defer func() { | ||
l.Reconfigure(gpiocdev.AsInput) | ||
fmt.Printf("Input pin: %s:%d\n", chip, offset) | ||
l.Close() | ||
}() | ||
|
||
values := map[int]string{0: "inactive", 1: "active"} | ||
v, err := l.Value() | ||
fmt.Printf("Read pin: %s:%d %s\n", chip, offset, values[v]) | ||
|
||
l.Reconfigure(gpiocdev.AsOutput(v)) | ||
fmt.Printf("Set pin %s:%d %s\n", chip, offset, values[v]) | ||
time.Sleep(500 * time.Millisecond) | ||
v ^= 1 | ||
l.SetValue(v) | ||
fmt.Printf("Set pin %s:%d %s\n", chip, offset, values[v]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# SPDX-FileCopyrightText: 2019 Kent Gibson <[email protected]> | ||
# | ||
# SPDX-License-Identifier: CC0-1.0 | ||
toggle_multiple_line_values |
Oops, something went wrong.