From 530ab885b27d3e59b97cd094690d588e6e2fdfe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Wed, 27 Nov 2024 12:02:59 -0300 Subject: [PATCH] {bmp280, icm20698, leak, pca9685}: Add better error messages for tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Patrick José Pereira --- src/bmp280.rs | 4 +++- src/icm20689.rs | 4 +++- src/leak.rs | 4 +++- src/pca9685.rs | 27 +++++++++++++++++++++------ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/bmp280.rs b/src/bmp280.rs index bd658008b..dfe67c9c4 100644 --- a/src/bmp280.rs +++ b/src/bmp280.rs @@ -110,7 +110,9 @@ mod tests { #[test] fn test_bmp280_pi_4() { - let mut baro = Bmp280Device::builder().build().unwrap(); + let mut baro = Bmp280Device::builder().build().unwrap_or_else(|error| { + panic!("Failed to build BMP280: {error}"); + }); for _ in 0..10 { println!("BMP280 temperature: {:?}", baro.read_temperature()); println!("BMP280 pressure: {:?}", baro.read_pressure()); diff --git a/src/icm20689.rs b/src/icm20689.rs index 600daf79e..80e6d00d2 100644 --- a/src/icm20689.rs +++ b/src/icm20689.rs @@ -123,7 +123,9 @@ mod tests { #[test] fn test_icm20689_pi_4() { - let mut imu = Icm20689Device::builder().build().unwrap(); + let mut imu = Icm20689Device::builder().build().unwrap_or_else(|error| { + panic!("Failed to build ICM20689: {error:?}"); + }); for _ in 0..10 { println!("ICM20689 gyroscope: {:?}", imu.read_angular_velocity()); println!("ICM20689 accelerometers: {:?}", imu.read_acceleration()); diff --git a/src/leak.rs b/src/leak.rs index b33d4dae4..53c0c894a 100644 --- a/src/leak.rs +++ b/src/leak.rs @@ -82,7 +82,9 @@ mod tests { #[test] fn test_leak_pi_4() { - let leak = LeakDetector::builder().build().unwrap(); + let leak = LeakDetector::builder().build().unwrap_or_else(|error| { + panic!("Failed to build leak detector: {error:?}"); + }); for _ in 0..10 { println!("Leak detector: {}", leak.is_leak_detected().unwrap()); sleep(Duration::from_millis(1000)); diff --git a/src/pca9685.rs b/src/pca9685.rs index daf301f2d..b9dc0df03 100644 --- a/src/pca9685.rs +++ b/src/pca9685.rs @@ -191,18 +191,33 @@ mod tests { //TODO: Not working #[test] fn test_pca9685_pi_4() { - let mut pwm = Pca9685Device::builder().build().unwrap(); + let mut pwm = Pca9685Device::builder().build().unwrap_or_else(|error| { + panic!("Error building PCA9685: {error:?}"); + }); + println!("PCA9685: Start initial configuration"); - pwm.enable_output(false).unwrap(); - pwm.set_frequency(60.0).unwrap(); - pwm.set_duty_cycle_all(0.5).unwrap(); + + pwm.enable_output(false).unwrap_or_else(|error| { + panic!("Error in while enabling output: {error:?}"); + }); + pwm.set_frequency(60.0).unwrap_or_else(|error| { + panic!("Error in setting frequency: {error:?}"); + }); + pwm.set_duty_cycle_all(0.5).unwrap_or_else(|error| { + panic!("Error in configuring duty cycle: {error:?}"); + }); + println!("PCA9685: Enabling PWM output"); - pwm.enable_output(true).unwrap(); + pwm.enable_output(true).unwrap_or_else(|error| { + panic!("Error in enabling output: {error:?}"); + }); sleep(Duration::from_millis(1000)); for duty_cycle in [0.0, 1.0, 0.0, 1.0, 0.5] { for channel in 0..16 { println!("PCA9685: Channel {channel} value {duty_cycle:.1}"); - pwm.set_duty_cycle(channel, duty_cycle).unwrap(); + pwm.set_duty_cycle(channel, duty_cycle).unwrap_or_else(|error| { + panic!("Error in setting duty cycle: {error:?}"); + }); sleep(Duration::from_millis(100)); } }