diff --git a/examples/raspberry-pi-threads.rs b/examples/raspberry-pi-threads.rs index f437050c98..41de53ff0f 100644 --- a/examples/raspberry-pi-threads.rs +++ b/examples/raspberry-pi-threads.rs @@ -1,4 +1,4 @@ -use navigator_rs::Navigator; +use navigator_rs::{Navigator, UserLed}; use std::sync::{Arc, Mutex, RwLock}; use std::thread::{self, sleep}; use std::time::Duration; @@ -26,6 +26,26 @@ fn main() { } }); + // This code block creates a thread that updates the `UserLed` according to its position, based on gravity. + // It will keep the LED state on, indicating that the navigator has fully flipped to axes X and Y or turned upside down (Z-axis). + // You can use it to also monitor abrupt collisions! + let sensor_data_cloned = sensor_data.clone(); + let nav_cloned = nav.clone(); + let _ = thread::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) + }; + } + sleep(Duration::from_millis(5000)); + }); + // This code block could be also other thread, but just run on the main one. // This could work as a server get handler, or an instance that can be used by different services to monitor and analysis. loop {