Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/spider-gazelle/gpio.cr
crystal lang bindings for linux gpiod
https://github.com/spider-gazelle/gpio.cr
Last synced: about 2 months ago
JSON representation
crystal lang bindings for linux gpiod
- Host: GitHub
- URL: https://github.com/spider-gazelle/gpio.cr
- Owner: spider-gazelle
- License: mit
- Created: 2023-10-08T04:35:41.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-05-23T13:47:50.000Z (4 months ago)
- Last Synced: 2024-07-25T18:33:28.705Z (about 2 months ago)
- Language: Crystal
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-crystal - gpio.cr - Bindings for the gpiod library (general purpose IO control and feedback) (C bindings)
README
# gpio
bindings for linux gpiod, a user space interface for general purpose IO control
## Installation
ensure the development dependencies are installed: `sudo apt install libgpiod-dev`
1. Add the dependency to your `shard.yml`:
```yaml
dependencies:
gpio:
github: spider-gazelle/gpio.cr
```2. Run `shards install`
## Usage
You can list the various chips available on a system by running `gpioinfo` this will list chips and IO line details.
```crystal
require "gpio"GPIO.default_consumer = "my app"
all_chips = GPIO::Chip.all# or if you know the name
chip = GPIO::Chip.new "gpiochip0"
chip.lines# take control of a line and set it's state
line = chip.line(5)
line.name
line.request_output
line.set_high
line.high? # => true
sleep 0.5
line.set_low
line.high? # => false# release the line once finished using
# this will also happen on garbage collection
line.release
```You can also configure the line for input and wait for input events to occur
```crystal
require "gpio"
GPIO.default_consumer = "my app"chip = GPIO::Chip.new "gpiochip0"
line = chip.line 0# blocks here until this line is released
# so you might want to do this in a spawn etc
line.on_input_change do |input_is|
case input_is
in .rising?
puts "input is high"
in .falling?
puts "input is low"
end
end```