#powered #hub #motor #up #lego #control #regular

rust-powered-lego

本软件包旨在使用技术中心控制常规Power Up电机。

2个不稳定版本

0.2.0 2022年11月22日
0.1.0 2022年11月17日

12#lego

自定义许可证

54KB
1K SLoC

rust-powered-lego

本软件包旨在使用技术中心控制常规Power Up电机。

理论上它应该支持所有类型的电机和中心 - 但它没有与所有类型的乐高技术Power Up工具进行过测试。

请参阅示例目录

#[tokio::main]
async fn main() -> Result<()> {
    // Hub "MAC" address can be found in several ways. 
    // Connect it to a computer and continue from there...
    let hub_mac_address = "90:84:2b:4e:5b:96";
    let port_id = TechnicHubPorts::B;

    // Converting the MAC string to btleplug::api::BDAddr type
    let address = BDAddr::from_str(hub_mac_address)?;

    // The ConnectionManager connects stuff - so ask it for the hub...
    let cm = ConnectionManager::new();

    // It is possible to use the name of the hub or its MAC address. That's why it's Option<>
    // Here, only address is implemented
    let hub = cm.get_hub(None, Some(address), 5).await?;

    // Ask to get the motor object (pay attention to the port_id)
    let motor = hub.get_motor(port_id as u8).await?;

    // Initiate the motor with power
    _ = motor.start_power(100, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;

    // Let it hang there for 3 seconds
    time::sleep(Duration::from_secs(3)).await;

    // And stop
    _ = motor.stop_motor(EndState::FLOAT, Profile::AccDec, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;

    Ok(())
}

依赖项

~8–41MB
~635K SLoC