usestd::{error::Error,io,thread};usetinkerforge::{accelerometer_bricklet::*,ip_connection::IpConnection};constHOST:&str="localhost";constPORT:u16=4223;constUID:&str="XYZ";// Change XYZ to the UID of your Accelerometer Bricklet.fnmain()->Result<(),Box<dynError>>{letipcon=IpConnection::new();// Create IP connection.leta=AccelerometerBricklet::new(UID,&ipcon);// Create device object.ipcon.connect((HOST,PORT)).recv()??;// Connect to brickd.// Don't use device before ipcon is connected.letacceleration_receiver=a.get_acceleration_callback_receiver();// Spawn thread to handle received callback messages.// This thread ends when the `a` object// is dropped, so there is no need for manual cleanup.thread::spawn(move||{foraccelerationinacceleration_receiver{println!("Acceleration [X]: {} g",acceleration.xasf32/1000.0);println!("Acceleration [Y]: {} g",acceleration.yasf32/1000.0);println!("Acceleration [Z]: {} g",acceleration.zasf32/1000.0);println!();}});// Set period for acceleration receiver to 1s (1000ms).// Note: The acceleration callback is only called every second// if the acceleration has changed since the last call!a.set_acceleration_callback_period(1000);println!("Press enter to exit.");letmut_input=String::new();io::stdin().read_line(&mut_input)?;ipcon.disconnect();Ok(())}