-
Notifications
You must be signed in to change notification settings - Fork 4
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
5378ccd
commit fe9174d
Showing
1 changed file
with
39 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// SPDX-FileCopyrightText: 2024 Kent Gibson <[email protected]> | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
// Basic piece of wire example mirroring an input to an output. | ||
|
||
use anyhow::Context; | ||
use gpiocdev::line::{EdgeDetection, EdgeKind, Value}; | ||
use gpiocdev::Request; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let input = Request::builder() | ||
.on_chip("/dev/gpiochip0") | ||
.with_consumer("softwire") | ||
.with_line(22) | ||
.with_edge_detection(EdgeDetection::BothEdges) | ||
.request() | ||
.context("Failed to request input")?; | ||
|
||
// copy value to output | ||
let value = input.value(22)?; | ||
let output = Request::builder() | ||
.on_chip("/dev/gpiochip0") | ||
.with_consumer("softwire") | ||
.with_line(23) | ||
.as_output(value) | ||
.request() | ||
.context("Failed to request output")?; | ||
|
||
// track value | ||
for event in input.edge_events() { | ||
let value = match event?.kind { | ||
EdgeKind::Rising => Value::Active, | ||
EdgeKind::Falling => Value::Inactive, | ||
}; | ||
output.set_lone_value(value)?; | ||
} | ||
Ok(()) | ||
} |