-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from pollen-robotics/3dof_zero
3dof zero
- Loading branch information
Showing
17 changed files
with
821 additions
and
619 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,48 @@ | ||
use std::process::Command; | ||
use std::{env, fs::File, io::Write, path::Path}; | ||
fn main() { | ||
println!("cargo:rustc-link-arg-bins=--nmagic"); | ||
println!("cargo:rustc-link-arg-bins=-Tlink.x"); | ||
println!("cargo:rustc-link-arg-bins=-Tdefmt.x"); | ||
|
||
// Create a build time file for constants | ||
let out_dir = env::var("OUT_DIR").expect("No out dir"); | ||
let dest_path = Path::new(&out_dir).join("constants.rs"); | ||
let mut f = File::create(&dest_path).expect("Could not create file"); | ||
|
||
// Trick to get the current commit hash and pass it to the firmware | ||
let output = Command::new("git") | ||
.args(&["rev-parse", "HEAD"]) | ||
.output() | ||
.unwrap(); | ||
let mut git_hash = String::from_utf8(output.stdout).unwrap(); | ||
git_hash.pop(); //remove trainling '\n' | ||
// println!("cargo:rustc-env=GIT_HASH={}", git_hash); | ||
write!(&mut f, "pub const GIT_HASH: &str = \"{}\";", git_hash).expect("Could not write file"); | ||
// Get firmware zero values | ||
let zeros = option_env!("ZEROS"); | ||
if let Some(zeros) = zeros { | ||
let zeros: Vec<f32> = zeros | ||
.split(",") | ||
.filter_map(|s| s.parse::<f32>().ok()) | ||
.collect(); | ||
writeln!( | ||
&mut f, | ||
"pub const HARDWARE_ZEROS: [f32;3] = [{:.32}, {:.32}, {:.32}];", | ||
zeros[0], zeros[1], zeros[2] | ||
) | ||
.expect("Could not write file"); // {:.32} to be sure to print the full precision. It counts... | ||
} else { | ||
writeln!(&mut f, "pub const HARDWARE_ZEROS: [f32;3] = [0.0,0.0,0.0];") | ||
.expect("Could not write file"); | ||
} | ||
|
||
// Get Dynamixel id | ||
let id = option_env!("DXL_ID"); | ||
if let Some(id) = id { | ||
let id = id.parse::<u8>().ok().unwrap(); | ||
writeln!(&mut f, "pub static DXL_ID: u8 = {:?};", id).expect("Could not write file"); | ||
} else { | ||
writeln!(&mut f, "pub static DXL_ID: u8 = 42;").expect("Could not write file"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.