Init template repo

This commit is contained in:
Lars Westermann 2021-09-03 09:52:00 +02:00
commit d2a68c5f90
No known key found for this signature in database
GPG Key ID: 9D417FA5BB9D5E1D
7 changed files with 158 additions and 0 deletions

8
.cargo/config Normal file
View File

@ -0,0 +1,8 @@
[target.armv5te-unknown-linux-gnueabi]
linker = "/usr/bin/arm-linux-gnueabi-gcc"
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "vendor"

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/target
/vendor

72
Cargo.lock generated Normal file
View File

@ -0,0 +1,72 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "ev3dev-lang-rust"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4150f08651eaa689b4ccc4170a514a5331c3a02b0e3042883e72f2de7e61468"
dependencies = [
"ev3dev-lang-rust-derive",
"libc",
]
[[package]]
name = "ev3dev-lang-rust-derive"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddd7a95543e9418e8ad0b08b6a2a47a1c33d260c97b5a056fbf8b0fdb648e9a6"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "ev3dev-lang-rust-template"
version = "0.1.0"
dependencies = [
"ev3dev-lang-rust",
]
[[package]]
name = "libc"
version = "0.2.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3cb00336871be5ed2c8ed44b60ae9959dc5b9f08539422ed43f09e34ecaeba21"
[[package]]
name = "proc-macro2"
version = "1.0.29"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b9f5105d4fdaab20335ca9565e106a5d9b82b6219b5ba735731124ac6711d23d"
dependencies = [
"unicode-xid",
]
[[package]]
name = "quote"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3d0b9745dc2debf507c8422de05d7226cc1f0644216dfdfead988f9b1ab32a7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "syn"
version = "1.0.75"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b7f58f7e8eaa0009c5fec437aabf511bd9933e4b2d7407bd05273c01a8906ea7"
dependencies = [
"proc-macro2",
"quote",
"unicode-xid",
]
[[package]]
name = "unicode-xid"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"

10
Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[package]
name = "ev3dev-lang-rust-template"
version = "0.1.0"
edition = "2018"
[dependencies]
ev3dev-lang-rust = "0.10.2"
[profile.release]
lto = true

10
Makefile Normal file
View File

@ -0,0 +1,10 @@
ARTIFACT := $(shell cargo pkgid | rev | cut -d "/" -f1 | rev | cut -d "\#" -f1) # Try to determine the artifact name. If this does not work replace it with the explicit name.
install-dependencies:
cargo vendor
build:
docker run --rm -v $(PWD):/opt/project/ -w /opt/project/ pixix4/ev3dev-rust /bin/bash -c "cargo build --release --target armv5te-unknown-linux-gnueabi && /usr/bin/arm-linux-gnueabi-strip /opt/project/target/armv5te-unknown-linux-gnueabi/release/$(ARTIFACT)"
clean:
cargo clean

28
README.md Normal file
View File

@ -0,0 +1,28 @@
# Template for ev3dev-lang-rust
This is a template for creating and building projects with [`ev3dev-lang-rust`](https://github.com/pixix4/ev3dev-lang-rust). It contains all the necessary files to cross compile the "Hello World" example for ev3dev platform.
## Dependencies
- `cargo`
- `docker`
- `make` (optional)
## Initial setup
This template uses `cargo vendor` to cache all dependencies for the docker build. Before the first run and after changes to your dependencies you need to rebuild this dependency cache
```bash
make install-dependencies
# or
cargo vendor
```
## Usage
```bash
make build
# or
docker run --rm -v $(PWD):/opt/project/ -w /opt/project/ pixix4/ev3dev-rust /bin/bash -c "cargo build --release --target armv5te-unknown-linux-gnueabi && /usr/bin/arm-linux-gnueabi-strip /opt/project/target/armv5te-unknown-linux-gnueabi/release/<ARTIFACT>"
```
The resulting binary can be found at `./target/armv5te-unknown-linux-gnueabi/release/<ARTIFACT>`.

28
src/main.rs Normal file
View File

@ -0,0 +1,28 @@
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(())
}