From 4c62b4d5a5bafbc6620abc0732fa6d1a84c75a3b Mon Sep 17 00:00:00 2001 From: Aux1r Date: Sat, 16 Nov 2024 13:57:36 +0000 Subject: [PATCH] finding the bad u8 part 2 --- lib/sensors/src/tof.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/sensors/src/tof.rs b/lib/sensors/src/tof.rs index 1c93586..6c2780d 100644 --- a/lib/sensors/src/tof.rs +++ b/lib/sensors/src/tof.rs @@ -22,6 +22,16 @@ impl<'a, T: HypedI2c> TimeOfFlight<'a, T> { pub fn new(i2c: &'a mut T, device_address: ToFAddresses) -> Result { // SR03 Settings as seen in Application Sheet let device_address = device_address as u8; + for (reg, val) in PRIVATE_REGISTERS_u8 { + // writing to private registers + if let Err(e) = i2c.write_byte_to_register( + device_address, + reg, + val, + ) { + panic!("Error writing private registers u8s REG: {:?}", reg); + } + } for (reg,val) in PRIVATE_REGISTERS_u16 { // writing to private registers u16 if let Err(e) = i2c.write_byte_to_register_16( @@ -233,10 +243,17 @@ mod tests { let i2c_values = FnvIndexMap::new(); let mut i2c = MockI2c::new(i2c_values); let _ = TimeOfFlight::new(&mut i2c, ToFAddresses::Address29); + for (reg,val) in PRIVATE_REGISTERS_u8 { + assert_eq!( + i2c.get_writes() + .get(&(ToFAddresses::Address29 as u8, reg.into())), + Some(&Some(val)) + ) + } for (reg,val) in PRIVATE_REGISTERS_u16 { assert_eq!( i2c.get_writes() - .get(&(ToFAddresses::Address29 as u8, reg)), + .get(&(ToFAddresses::Address29 as u8, reg.into())), Some(&Some(val)) ) }