use haply::HaplyDevice;
use std::io::Write;
use std::time::Duration;
use tokio::time::interval;
const HTTP_BASE: &str = "http://localhost:10001";
const WS_URL: &str = "ws://localhost:10001/";
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let mut device = HaplyDevice::new(HTTP_BASE, WS_URL).await?;
println!("Connected — sending pings (Ctrl+C to stop)");
let mut ticker = interval(Duration::from_millis(500));
loop {
ticker.tick().await;
device.send_ping().await?;
let state = device.read_state().await?;
let mut ids: Vec<String> = Vec::new();
for d in &state.inverse3 {
ids.push(format!("i3:{}", d.device_id));
}
for d in &state.verse_grip {
ids.push(format!("vg:{}", d.device_id));
}
for d in &state.wireless_verse_grip {
ids.push(format!("wvg:{}", d.device_id));
}
for d in &state.custom_verse_grip {
ids.push(format!("cvg:{}", d.device_id));
}
if ids.is_empty() {
print!("\rDevices: (none) total: 0 ");
} else {
print!("\rDevices: [{}] total: {} ", ids.join(", "), ids.len());
}
std::io::stdout().flush().unwrap();
}
}