Crates.io | wiringpi |
lib.rs | wiringpi |
version | 0.2.4 |
source | src |
created_at | 2015-04-18 12:09:49.364147 |
updated_at | 2018-03-17 16:01:44.088408 |
description | An API wrapper for WiringPi, implementing the most important functions and provides a bit of type system convenience. See README.md for Raspberry Pi build instructions. |
homepage | |
repository | https://github.com/Ogeon/rust-wiringpi |
max_upload_size | |
id | 1890 |
size | 1,292,538 |
An API wrapper for WiringPi to make it accessible using Rust. It implements the most important functions and provides a bit of type system convenience.
Add the following lines to your Cargo.io
to use rust-wiringpi
:
[dependencies]
wiringpi = "0.2"
extern crate wiringpi;
use wiringpi::pin::Value::{High, Low};
use std::{thread, time};
fn main() {
//Setup WiringPi with its own pin numbering order
let pi = wiringpi::setup();
//Use WiringPi pin 0 as output
let pin = pi.output_pin(0);
let interval = time::Duration::from_millis(1000);
loop {
//Set pin 0 to high and wait one second
pin.digital_write(High);
thread::sleep(interval);
//Set pin 0 to low and wait one second
pin.digital_write(Low);
thread::sleep(interval);
}
}
Follow this guide.
cargo build --target=arm-unknown-linux-gnueabihf # Older models
cargo build --target=armv7-unknown-linux-gnueabihf # Newer models
rust-wiringpi
can also wrap the WiringOP library for the Orange Pi SBC boards.
This can be enabled with the orangepi
feature:
[dependencies.wiringpi]
verson = "0.2"
features = ["orangepi"]
In development mode, rust-wiringpi
is compiled as a rust-native library excluding the original WiringPi.
And binding functions are replaced by dummy functions that output simple logs to stdout.
With this mode, you can build and debug your project on platforms that does not support WiringPi.
# build
$ cargo build --features wiringpi/development
# run
$ cargo run --features wiringpi/development
[wiringpi] `wiringPiSetup` called
[wiringpi] `pinMode` called with: 0, 1
[wiringpi] `digitalWrite` called with: 0, 1
[wiringpi] `digitalWrite` called with: 0, 0
...