Rust crate for connecting to a PiShock hub over USB. Linux only for at the moment.
  • Rust 76.9%
  • Nix 23.1%
Find a file
2026-04-25 10:43:31 -07:00
.idea initial working code. could use some cleanup 2026-04-24 11:25:54 -07:00
src fix: commands not working sometimes. oops 2026-04-25 10:43:31 -07:00
.envrc initial git and rust flake 2026-04-19 13:30:52 -07:00
.gitignore initial working code. could use some cleanup 2026-04-24 11:25:54 -07:00
Cargo.lock initial working code. could use some cleanup 2026-04-24 11:25:54 -07:00
Cargo.toml initial working code. could use some cleanup 2026-04-24 11:25:54 -07:00
flake.lock initial working code. could use some cleanup 2026-04-24 11:25:54 -07:00
flake.nix initial working code. could use some cleanup 2026-04-24 11:25:54 -07:00
README.md use repo in cargo rather than cloning and using local 2026-04-24 21:37:13 -07:00

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(())
}