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

[enh] ported to v1.0.0 of embedded-hal #19

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

chmousset
Copy link

Migrated to the new API of embedded-hal which unified some traits.

Tested on Linux with both linux_embedded_hal and ftdi_embedded_hal:

use clap::Parser;
// use ftdi;
// use ftdi_embedded_hal as hal;
use linux_embedded_hal::I2cdev;
use vl6180x;

use std::{thread, time};

/// Simple vl6180x scanner
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
    /// Bus number (/dev/i2c<x>)
    #[arg()]
    bus: u8,
}

fn main() {
    let args = Args::parse();
    let mut i2c = I2cdev::new(format!("/dev/i2c-{}", args.bus)).unwrap();

    // let device = ftdi::find_by_vid_pid(0x0403, 0x6011)
    //     .interface(ftdi::Interface::B)
    //     .open()
    //     .unwrap();
    // let hal = hal::FtHal::init_freq(device, 100_000).unwrap();
    // let mut i2c = hal.i2c().unwrap();

    let mut tof = vl6180x::VL6180X::new(&mut i2c).expect("vl");
    loop {
        thread::sleep(time::Duration::from_micros(500));
        match tof.poll_range_mm_single_blocking() {
            Ok(range) => println!("Range Single Poll: {}mm", range),
            Err(e) => println!("Error reading TOF sensor Single Poll! {:?}", e),
        }
    }
}

Cargo.toml:

[package]
name = "vl6180x-test"
version = "0.1.0"
edition = "2021"

[dependencies]
clap = { version = "4.5.21", features = ["derive"] }
embedded-hal = "1.0.0"
# ftdi = "0.1.3"
# libftd2xx = "0.33.1"
# ftdi-embedded-hal = { version = "0.9.1", features = ["libftd2xx"] }
linux-embedded-hal = "0.4.0"
vl6180x = { path = "../vl6180x" }

@chmousset
Copy link
Author

@lucazulian this means #14 and #18 can be closed

@chmousset chmousset marked this pull request as draft December 19, 2024 15:25
@chmousset chmousset force-pushed the enh/embedded-hal-v1 branch 2 times, most recently from 9a05f38 to 297d9cb Compare December 19, 2024 15:33
@lucazulian
Copy link
Collaborator

@lucazulian this means #14 and #18 can be closed

Super cool; thank you so much! Let me give it a try with a real board!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants