rust-powered-lego
This crate aims to control a regular Powered Up motor using a Technic Hub.
Technically it should support all kinds of motors and hubs - But it wasn't tested with all the variety of lego technic Powered Up tools.
See examples directory.
#[tokio::main]
async fn main() -> Result<()> {
let hub_mac_address = "90:84:2b:4e:5b:96";
let port_id = TechnicHubPorts::B;
let address = BDAddr::from_str(hub_mac_address)?;
let cm = ConnectionManager::new();
let hub = cm.get_hub(None, Some(address), 5).await?;
let motor = hub.get_motor(port_id as u8).await?;
_ = motor.start_power(100, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
time::sleep(Duration::from_secs(3)).await;
_ = motor.stop_motor(EndState::FLOAT, Profile::AccDec, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
Ok(())
}