Giter Site home page Giter Site logo

ev3dev-lang-rust's Introduction

Rust language bindings for ev3dev

Build Status Latest version

Notice

Currently this project is not compatible with the BrickPi platform.

Usage

extern crate ev3dev_lang_rust;

use ev3dev_lang_rust::Ev3Result;
use ev3dev_lang_rust::motors::{LargeMotor, MotorPort};
use ev3dev_lang_rust::sensors::ColorSensor;

fn main() -> Ev3Result<()> {

    // Get large motor on port outA.
    let large_motor = LargeMotor::get(MotorPort::OutA)?;

    // Set command "run-direct".
    large_motor.run_direct()?;

    // Run motor.
    large_motor.set_duty_cycle_sp(50)?;

    // Find color sensor. Always returns the first recognised one.
    let color_sensor = ColorSensor::find()?;

    // Switch to rgb mode.
    color_sensor.set_mode_rgb_raw()?;

    // Get current rgb color tuple.
    println!("Current rgb color: {:?}", color_sensor.get_rgb()?);

    Ok(())
}

Cross compile for ev3 brick

  1. Create target configuration .cargo/config

    [target.armv5te-unknown-linux-gnueabi]
    linker = "/usr/bin/arm-linux-gnueabi-gcc"
  2. Create Dockerfile

    FROM debian:stretch
    
    RUN dpkg --add-architecture armel
    RUN apt update
    
    # Fix debian package alias
    RUN sed -i "s#deb http://security.debian.org/debian-security stretch/updates main#deb http://deb.debian.org/debian-security stretch/updates main#g" /etc/apt/sources.list
    
    # Install curl for rust installation
    # Install g++ as buildscript compiler
    # Install g++-arm-linux-gnueabi as cross compiler
    RUN apt --yes install curl g++ g++-arm-linux-gnueabi crossbuild-essential-armel
    
    # Instull rust for host platform
    RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
    
    ENV PATH "$PATH:/root/.cargo/bin"
    
    # Add stdlib for target platform
    RUN rustup target add armv5te-unknown-linux-gnueabi
    
    # docker run -it --rm -v $PWD:/build/ -w /build pixix4/ev3dev-rust-cross
    # cargo build --release --target armv5te-unknown-linux-gnueabi
  3. Build docker image

    docker build . -t pixix4/ev3dev-rust-cross --no-cache
  4. Start docker image

    docker run -it --rm -v $PWD:/build/ -w /build pixix4/ev3dev-rust-cross
  5. Build binary for ev3dev

    cargo build --release --target armv5te-unknown-linux-gnueabi

    The --release flag is optional. However, it can speedup the execution time by a factor of 30.

The target binary is now in target/armv5te-unknown-linux-gnueabi/release/{application_name}

ev3dev-lang-rust's People

Contributors

pixix4 avatar janf-04 avatar massiminoiltrace avatar voragain avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.