GpioLine class
Provides access to a single GPIO line / pin.
Basically has 3 states that define the methods you can call:
unrequested
, requested input
, requested output
Example usage of GpioLine:
import 'package:gpiod/proxy_gpiod.dart';
final gpio = ProxyGpiod.getInstance()
// get the line with index 22 from the first chip
final line = gpio.chips.singleWhere(
(chip) => chip.label == 'pinctrl-bcm2835'
);
print("pinctrl-bcm2835, line 22: $(await line.info)");
// request is as output and initialize it with false
await line.requestOutput(
consumer: "flutter_gpiod output test",
initialValue: false
));
// set the line active
line.setValue(true);
await Future.delayed(Duration(milliseconds: 500));
// set the line inactive again
line.setValue(false);
await line.release();
// request the line as input, and listen for both edges
// we don't use `line.reconfigure` because that doesn't
// allow us to specify triggers.
line.requestInput(
consumer: "flutter_gpiod input test",
triggers: const {SignalEdge.rising, SignalEdge.falling}
));
// print line events for eternity
for (final event in line.onEvent) {
print("gpio line signal event: $event");
}
// line.release();
Notice that access to the methods in GpioLine is synchronized.
This will throw an error:
final gpio = ProxyGpiod.getInstance();
final line = gpio.chips.singleWhere(
(chip) => chip.label == 'pinctrl-bcm2835'
);
line.requestInput() // notice the missing await
print("is line requested? ${line.requested}"); // this will throw the error.
// The line ownership is undefined until the Future returned by line.requestInput() finishes.
// Because this code doesn't wait until the returned Future completes,
// the request may still be running when `line.requested` is queried.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- info → LineInfo
-
Returns the line info for this line.
no setter
-
onEdge
→ Stream<
SignalEdge> -
Broadcast stream of signal edges.
no setter
-
onEvent
→ Stream<
SignalEvent> -
Gets a broadcast stream of
SignalEvent
s for this line.no setter - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
triggers
→ Set<
SignalEdge> -
Provides synchronous access to info.
no setter
Methods
-
getValue(
) → bool - Reads the value of the line (active / inactive)
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
reconfigureInput(
{Bias bias = Bias.unknown, ActiveState activeState = ActiveState.high}) → void - Reconfigures the line as input with the given configuration.
-
reconfigureOutput(
{OutputMode outputMode = OutputMode.pushPull, Bias bias = Bias.unknown, ActiveState activeState = ActiveState.high, bool initialValue = false}) → void - Reconfigures the line as output with the given configuration.
-
release(
) → void - Releases the line, so you don't own it anymore.
-
requestInput(
{String? consumer, Bias bias = Bias.unknown, ActiveState activeState = ActiveState.high, Set< SignalEdge> triggers = const {}}) → void - Requests ownership of a GPIO line with the given configuration.
-
requestOutput(
{String consumer = '', OutputMode outputMode = OutputMode.pushPull, Bias bias = Bias.unknown, ActiveState activeState = ActiveState.high, bool initialValue = false}) → void -
setValue(
bool value) → void - Sets the value of the line to active (true) or inactive (false).
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited