plug_and_play/
plug_and_play.rs1use std::{
7 str::FromStr,
8 time::Duration
9};
10
11use tokio::time;
12
13use anyhow::Result;
14use btleplug::api::BDAddr;
15
16use rust_powered_lego::{
17 connection_manager::ConnectionManager,
18 HubType,
19 MotorType,
20 lego::message_parameters::{
21 StartupAndCompletionInfo,
22 },
23 lego::{
24 consts::{
25 TechnicHubPorts,
26 EndState,
27 Profile,
28 },
29 },
30};
31
32
33#[tokio::main]
34async fn main() -> Result<()> {
35 let hub_mac_address = "90:84:2b:4e:5b:96";
38 let port_id = TechnicHubPorts::B;
39
40 let address = BDAddr::from_str(hub_mac_address)?;
42
43 let cm = ConnectionManager::new();
45
46 let hub = cm.get_hub(None, Some(address), 5).await?;
49
50 let motor = hub.get_motor(port_id as u8).await?;
52
53 _ = motor.start_power(100, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
55
56 time::sleep(Duration::from_secs(3)).await;
58
59 _ = motor.stop_motor(EndState::FLOAT, Profile::AccDec, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
61
62 Ok(())
63}