Rust crate for connecting to a PiShock hub over USB. Linux only for at the moment.
- Rust 76.9%
- Nix 23.1%
| .idea | ||
| src | ||
| .envrc | ||
| .gitignore | ||
| Cargo.lock | ||
| Cargo.toml | ||
| flake.lock | ||
| flake.nix | ||
| README.md | ||
pishock_serial_rs
Usage Example
Installation
Add the repository to your project's Cargo.toml:
[dependencies]
pishock_serial_rs = { git = "https://git.insberr.com/insberr/pishock-serial-rs" }
Example main.rs
use pishock_serial_rs::PiShock;
use anyhow::Result;
// The shocker's id
const SHOCKER_ID: u32 = 31625;
#[tokio::main]
async fn main() -> Result<()> {
// Find the hub and create a connection to it
let mut device = PiShock::from_hardware(
pishock_serial_rs::port::Hardware::Next
).await?;
// Get hub info
let json_string = device.info().await?;
println!("{}", json_string);
// Vibrate shocker for 500ms at intensity 255.
device.vibrate(SHOCKER_ID, 500, 255).await?;
// Shock shocker for 10ms at intensity 10.
device.shock(SHOCKER_ID, 10, 10).await?;
// Beep shocker for 20ms
device.beep(SHOCKER_ID, 200).await?;
Ok(())
}