lego-powered-up

Crates.iolego-powered-up
lib.rslego-powered-up
version0.4.0
sourcesrc
created_at2021-12-05 22:08:26.204005
updated_at2024-01-07 20:09:08.625302
descriptionControl Lego PoweredUp hubs and devices
homepage
repositoryhttps://github.com/bricks-rs/lego-powered-up
max_upload_size
id492879
size225,446
David Young (sciguy16)

documentation

README

Rust communication library for Lego Powered Up

Example

See the examples directory for more!

use lego_powered_up::{notifications::Power, PoweredUp};
use std::time::Duration;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    println!("Listening for hubs...");
    let mut pu = PoweredUp::init().await?;
    let hub = pu.wait_for_hub().await?;

    println!("Connecting to hub `{}`", hub.name);
    let hub = pu.create_hub(&hub).await?;

    println!("Change the hub LED to green");
    let mut hub_led = hub.port(lego_powered_up::hubs::Port::HubLed).await?;
    hub_led.set_rgb(&[0, 0xff, 0]).await?;

    println!("Run motors");
    let mut motor_c = hub.port(lego_powered_up::hubs::Port::C).await?;
    let mut motor_d = hub.port(lego_powered_up::hubs::Port::D).await?;
    motor_c.start_speed(50, Power::Cw(50)).await?;
    motor_d.start_speed(50, Power::Cw(50)).await?;

    tokio::time::sleep(Duration::from_secs(3)).await;

    println!("Stop motors");
    motor_c.start_speed(0, Power::Float).await?;
    motor_d.start_speed(0, Power::Brake).await?;

    println!("Disconnect from hub `{}`", hub.name().await?);
    hub.disconnect().await?;

    println!("Done!");

    Ok(())
}

Contributing

Contributions are welcome, particularly in the following areas:

  • Bug reports and feature requests
  • Support for hubs other than the Technic Medium Hub (I don't have any other types to test with at the moment)
  • Support for peripherals other than the simple motors and hub LEDs
  • Good APIs to control e.g. motor position
  • More examples to demonstrate cool things we can do
  • Client implementation
  • #![no_std] support (controller & client)
  • Testing on/porting to non-linux operating systems, e.g. Windows & Mac

License

This library is available under the terms of the Mozilla Public License 2.0.

The examples provided in the examples directory are dedicated to the public domain

Commit count: 83

cargo fmt