loco_control/
loco_control.rs1use roco_z21_driver::{Loco, Z21Station};
2use std::sync::Arc;
3use tokio;
4
5#[tokio::main]
6async fn main() -> std::io::Result<()> {
7 let station = Arc::new(Z21Station::new("192.168.0.111:21105").await?);
8
9 let loco = Loco::control(station.clone(), 4).await?;
11
12 loco.subscribe_loco_state(Box::new(|state| {
14 println!(
15 "Locomotive speed: {}%",
16 state.speed_percentage.unwrap_or(0.)
17 );
18 }));
19
20 loco.set_headlights(true).await?;
22
23 loco.drive(50.0).await?;
25
26 tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
28
29 loco.stop().await?;
31
32 Ok(())
33}