diff --git a/examples/raspberry-pi-threads.rs b/examples/raspberry-pi-threads.rs index b3fdc4268f..b6c9ad1267 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_update_thread_lock = sensor_data_lock.clone(); + let navigator_lock = nav.clone(); + let _ = thread::spawn(move || loop { + if let Ok(lock) = sensor_update_thread_lock.read() { + if lock.accelerometer.x.abs() > 8.00 { + navigator_lock.lock().unwrap().set_led(UserLed::Led1, true) + }; + if lock.accelerometer.y.abs() > 8.00 { + navigator_lock.lock().unwrap().set_led(UserLed::Led2, true) + }; + if lock.accelerometer.z < -8.00 { + navigator_lock.lock().unwrap().set_led(UserLed::Led3, true) + }; + } + sleep(Duration::from_millis(10000)); + }); + // This code block could be also other thread, but just run on the main one. // This could could work as a server get handler, or a instance that can be used by different services to monitor and analysis. loop {