Skip to content

Commit

Permalink
{bmp280, icm20698, leak, pca9685}: Add better error messages for tests
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Nov 27, 2024
1 parent 292c4a3 commit 530ab88
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
4 changes: 3 additions & 1 deletion src/bmp280.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/icm20689.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 3 additions & 1 deletion src/leak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
27 changes: 21 additions & 6 deletions src/pca9685.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Expand Down

0 comments on commit 530ab88

Please sign in to comment.