classstuds::Gpio
sys::Obj studs::Gpio
Gpio provides high level access to GPIO pins through the Linux /sys/class/gpio interface.
See Gpio chapter for details.
- close
Void close()Close this port.
- listen
Void listen(Str mode, Duration? timeout, |Int callback)Register an interrupt handler to listen for GPIO output changes. The
modeshould be one of the strings "rising", "falling" or "both" to indicate which edge(s) the ISR is to be triggered on. Invoke the given callback function when a change occurs. This method will block listening until close is called.If
timeoutis non-null, thencallbackwill be invoked at every duration oftimeoutregardless of whether a state change occurred. Iftimeoutis null, this method blocks until a state change is detected.Note that after calling
listen, you will receive an initial callback with the state of the pin. This prevents the race condition between getting the initial state of the pin and turning on interrupts.- open
static Gpio open(Int pin, Str dir)Open a GPIO port with given pin and direction, where
diris"in"or"out".- read
Int read()Read the current value of the pin.
- write
Write the given value to the GPIO. The GPIO should be configured as an output. Valid values are
0for logic low, or1for logic high. Other non-zero values will result in logic high being output. Returns this.