diff --git a/controller/src/main.rs b/controller/src/main.rs index 6313cbb..a010e8f 100644 --- a/controller/src/main.rs +++ b/controller/src/main.rs @@ -9,6 +9,7 @@ mod vl53l0; use core::array; use core::borrow::BorrowMut; +use core::cell::RefCell; use core::fmt::Formatter; use core::panic::PanicInfo; use core::str::from_utf8; @@ -17,6 +18,7 @@ use bt_hci::cmd::info; use cyw43_pio::PioSpi; use embassy_rp::i2c::{Async, I2c}; use embassy_rp::pwm::{self, Pwm}; +use embedded_hal_bus::i2c::RefCellDevice; use fixed::FixedU16; use log::*; //use embassy_rp::i2c::InterruptHandler; @@ -95,10 +97,23 @@ async fn main(spawner: Spawner) { let scl = p.PIN_27; let config = embassy_rp::i2c::Config::default(); let bus1 = embassy_rp::i2c::I2c::new_async(p.I2C1, scl, sda, Irqs, config); + let bus1 = RefCell::new(bus1); - let mut tof = vl53l0x::VL53L0x::new(bus1).unwrap(); + info!("made RefCell"); + + let mut tof2on = Output::new(p.PIN_16, Level::Low); + info!("2"); + Timer::after_millis(1).await; + let mut tof = vl53l0x::VL53L0x::new(RefCellDevice::new(&bus1)).unwrap(); + info!("3"); + tof.set_address(0x32).unwrap(); + info!("4"); + tof2on.set_high(); + Timer::after_millis(13).await; + info!("5"); + let mut tof2 = vl53l0x::VL53L0x::new(RefCellDevice::new(&bus1)).unwrap(); + info!("6"); - tof.start_continuous(0).unwrap(); let mut gyro = Mpu6050::new_with_addr(bus,0x68); @@ -114,8 +129,12 @@ async fn main(spawner: Spawner) { //info!("pos: {}", gyro.get_gyro().unwrap().x); //info!("jerk: {}", gyro.get_acc().unwrap().x); //info!("temp: {}", gyro.get_temp().unwrap() * (9./5.) + 32.); - if let Ok(dist) = tof.read_range_mm() { - info!("dist: {dist}mm"); + if let Ok(dist) = tof.read_range_single_millimeters_blocking() { + info!("dist1: {dist}mm"); + } + Timer::after_millis(3).await; + if let Ok(dist) = tof2.read_range_single_millimeters_blocking() { + info!("dist2: {dist}mm"); } Timer::after_millis(23).await; }