ConnectionManager

Struct ConnectionManager 

Source
pub struct ConnectionManager {}

Implementations§

Source§

impl ConnectionManager

Source

pub fn new() -> Self

Examples found in repository?
examples/calibrating_steering.rs (line 96)
90async fn get_hub(address:  &str) -> Result<Hub> {
91    
92    // Converting the MAC string to btleplug::api::BDAddr type
93    let address = BDAddr::from_str(address)?;
94
95    // The ConnectionManager connects stuff - so ask it for the hub...
96    let cm = ConnectionManager::new();
97
98    // It is possible to use the name of the hub or its MAC address. That's why it's Option<>
99    // Here, only address is implemented
100    let hub = cm.get_hub(None, Some(address), 5).await?;
101    
102    // Great! Let's get on with this...
103    Ok(hub)
104}
More examples
Hide additional examples
examples/use_a_motor_with_arrow_keys.rs (line 135)
129async fn get_hub(address:  &str) -> Result<Hub> {
130    
131    // Converting the MAC string to btleplug::api::BDAddr type
132    let address = BDAddr::from_str(address)?;
133
134    // The ConnectionManager connects stuff - so ask it for the hub...
135    let cm = ConnectionManager::new();
136
137    // It is possible to use the name of the hub or its MAC address. That's why it's Option<>
138    // Here, only address is implemented
139    let hub = cm.get_hub(None, Some(address), 5).await?;
140    
141    // Great! Let's get on with this...
142    Ok(hub)
143}
examples/plug_and_play.rs (line 44)
34async fn main() -> Result<()> {
35    // Hub "MAC" address can be found in several ways. 
36    // Connect it to a computer and continue from there...
37    let hub_mac_address = "90:84:2b:4e:5b:96";
38    let port_id = TechnicHubPorts::B;
39
40    // Converting the MAC string to btleplug::api::BDAddr type
41    let address = BDAddr::from_str(hub_mac_address)?;
42
43    // The ConnectionManager connects stuff - so ask it for the hub...
44    let cm = ConnectionManager::new();
45
46    // It is possible to use the name of the hub or its MAC address. That's why it's Option<>
47    // Here, only address is implemented
48    let hub = cm.get_hub(None, Some(address), 5).await?;
49
50    // Ask to get the motor object (pay attention to the port_id)
51    let motor = hub.get_motor(port_id as u8).await?;
52
53    // Initiate the motor with power
54    _ = motor.start_power(100, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
55
56    // Let it hang there for 3 seconds
57    time::sleep(Duration::from_secs(3)).await;
58
59    // And stop
60    _ = motor.stop_motor(EndState::FLOAT, Profile::AccDec, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
61
62    Ok(())
63}
Source

pub async fn get_hub( &self, peripheral_name: Option<String>, bd_add: Option<BDAddr>, scan_time_seconds: u64, ) -> Result<Hub>

Examples found in repository?
examples/calibrating_steering.rs (line 100)
90async fn get_hub(address:  &str) -> Result<Hub> {
91    
92    // Converting the MAC string to btleplug::api::BDAddr type
93    let address = BDAddr::from_str(address)?;
94
95    // The ConnectionManager connects stuff - so ask it for the hub...
96    let cm = ConnectionManager::new();
97
98    // It is possible to use the name of the hub or its MAC address. That's why it's Option<>
99    // Here, only address is implemented
100    let hub = cm.get_hub(None, Some(address), 5).await?;
101    
102    // Great! Let's get on with this...
103    Ok(hub)
104}
More examples
Hide additional examples
examples/use_a_motor_with_arrow_keys.rs (line 139)
129async fn get_hub(address:  &str) -> Result<Hub> {
130    
131    // Converting the MAC string to btleplug::api::BDAddr type
132    let address = BDAddr::from_str(address)?;
133
134    // The ConnectionManager connects stuff - so ask it for the hub...
135    let cm = ConnectionManager::new();
136
137    // It is possible to use the name of the hub or its MAC address. That's why it's Option<>
138    // Here, only address is implemented
139    let hub = cm.get_hub(None, Some(address), 5).await?;
140    
141    // Great! Let's get on with this...
142    Ok(hub)
143}
examples/plug_and_play.rs (line 48)
34async fn main() -> Result<()> {
35    // Hub "MAC" address can be found in several ways. 
36    // Connect it to a computer and continue from there...
37    let hub_mac_address = "90:84:2b:4e:5b:96";
38    let port_id = TechnicHubPorts::B;
39
40    // Converting the MAC string to btleplug::api::BDAddr type
41    let address = BDAddr::from_str(hub_mac_address)?;
42
43    // The ConnectionManager connects stuff - so ask it for the hub...
44    let cm = ConnectionManager::new();
45
46    // It is possible to use the name of the hub or its MAC address. That's why it's Option<>
47    // Here, only address is implemented
48    let hub = cm.get_hub(None, Some(address), 5).await?;
49
50    // Ask to get the motor object (pay attention to the port_id)
51    let motor = hub.get_motor(port_id as u8).await?;
52
53    // Initiate the motor with power
54    _ = motor.start_power(100, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
55
56    // Let it hang there for 3 seconds
57    time::sleep(Duration::from_secs(3)).await;
58
59    // And stop
60    _ = motor.stop_motor(EndState::FLOAT, Profile::AccDec, StartupAndCompletionInfo::ExecuteImmediatelyAndNoAction).await?;
61
62    Ok(())
63}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V