Skip to content

Commit

Permalink
examples: raspberry-pi-threads: Make it more iteractive
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric authored and RaulTrombin committed Nov 26, 2024
1 parent e875549 commit 3f2d1c9
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions examples/raspberry-pi-threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn main() {
*sensor_data = nav_cloned.lock().unwrap().read_all();
println!("Updated value: {sensor_data:?}");
}
sleep(Duration::from_millis(10000));
sleep(Duration::from_millis(200));
})
.expect("Failed to spawn the sensor reader thread");

Expand All @@ -33,17 +33,20 @@ fn main() {
.name("Flip monitor".into())
.spawn(move || loop {
if let Ok(sensor_data) = sensor_data_cloned.read() {
if sensor_data.accelerometer.x.abs() > 8.00 {
nav_cloned.lock().unwrap().set_led(UserLed::Led1, true)
};
if sensor_data.accelerometer.y.abs() > 8.00 {
nav_cloned.lock().unwrap().set_led(UserLed::Led2, true)
};
if sensor_data.accelerometer.z < -8.00 {
nav_cloned.lock().unwrap().set_led(UserLed::Led3, true)
};
nav_cloned
.lock()
.unwrap()
.set_led(UserLed::Led1, sensor_data.accelerometer.x.abs() > 8.00);
nav_cloned
.lock()
.unwrap()
.set_led(UserLed::Led2, sensor_data.accelerometer.y.abs() > 8.00);
nav_cloned
.lock()
.unwrap()
.set_led(UserLed::Led3, sensor_data.accelerometer.z < -8.00)
}
sleep(Duration::from_millis(5000));
sleep(Duration::from_millis(10));
})
.expect("Failed to spawn the flip monitor thread");

Expand All @@ -53,6 +56,6 @@ fn main() {
if let Ok(sensor_data) = sensor_data.read() {
println!("Read SensorData: {sensor_data:?}");
}
sleep(Duration::from_millis(1000));
sleep(Duration::from_millis(300));
}
}

0 comments on commit 3f2d1c9

Please sign in to comment.