Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it possible to use in termux environment #46

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cargo-hf2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ readme = "readme.md"
structopt = "0.3.2"
colored = "2.0.0"
hf2 = { version = "^0.3.0", path = "../hf2" }
hidapi = "1.2.1"
hidapi = "1.4.0"
cargo-project = "0.2.4"
pretty_env_logger = "0.3.0"
maplit = "1.0.2"
Expand Down
11 changes: 9 additions & 2 deletions cargo-hf2/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use colored::*;
use hf2::utils::{elf_to_bin, flash_bin, vendor_map};
use hidapi::{HidApi, HidDevice};
use std::env;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use std::time::Instant;
Expand Down Expand Up @@ -70,12 +71,16 @@ fn main() {
exit_with_process_status(status)
}

let api = HidApi::new().expect("Couldn't find system usb");

let d = if let (Some(v), Some(p)) = (opt.vid, opt.pid) {
let api = HidApi::new().expect("Couldn't find system usb");
api.open(v, p)
.expect("Are you sure device is plugged in and in bootloader mode?")
} else if let Ok(v) = env::var("TERMUX_USB_FD") {
let api = HidApi::new_without_enumerate().expect("Couldn't find system usb");
let fd = v.parse().expect("TERMUX_USB_FD must be valid number");
api.wrap_sys_device(fd, -1).expect("Use with termux-usb")
} else {
let api = HidApi::new().expect("Couldn't find system usb");
println!(
" {} for a connected device with known vid/pid pair.",
"Searching".green().bold(),
Expand Down Expand Up @@ -173,4 +178,6 @@ struct Opt {
pid: Option<u16>,
#[structopt(name = "vid", long = "vid", parse(try_from_str = parse_hex_16))]
vid: Option<u16>,
#[structopt(short = "Z")]
unstable_features: Option<Vec<String>>
}