#usb #driver #communicating #brick #motor #tokio #nxt

nxtusb

用于与NXT砖块通信的USB驱动程序

2个不稳定版本

0.2.0 2024年1月7日
0.1.0 2024年1月1日

#1326 in 硬件支持

MPL-2.0 许可证

76KB
1.5K SLoC

nxtusb

用于与NXT砖块通信的USB驱动程序。请参阅示例以获取示例代码。

示例

use nxtusb::{motor::*, *};

const POWER: i8 = 80;

#[tokio::main]
async fn main() -> nxtusb::Result<()> {
    let nxt = Nxt::first_usb().await?;
    let _nxt2 = nxtusb::Bluetooth::wait_for_nxt().await?;

    println!("Running motor A at {POWER}");
    nxt.set_output_state(
        OutPort::A,
        POWER,
        OutMode::ON | OutMode::REGULATED,
        RegulationMode::Speed,
        0,
        RunState::Running,
        RUN_FOREVER,
    ).await?;

    std::thread::sleep(std::time::Duration::from_secs(5));

    println!("Stop");
    nxt.set_output_state(
        OutPort::A,
        0,
        OutMode::IDLE,
        RegulationMode::default(),
        0,
        RunState::Running,
        RUN_FOREVER,
    ).await?;

    let bat = nxt.get_battery_level().await?;
    println!("Battery level is {bat} mV");

    Ok(())
}

依赖关系

~3–24MB
~355K SLoC