mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-09-13 02:54:26 +08:00
feat(bluetooth-hid): 支持经典蓝牙 HID 后端
This commit is contained in:
49
libs/bluetooth-hid/examples/pairing_probe.rs
Normal file
49
libs/bluetooth-hid/examples/pairing_probe.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
//! Explicit hardware regression: opens a 10-second pairing window without
|
||||
//! removing existing bonds or sending input. Stop the production HID first.
|
||||
use one_kvm_bluetooth_hid::{Action, Config, Peripheral};
|
||||
use std::time::Duration;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), String> {
|
||||
let peripheral = Peripheral::start(Config {
|
||||
adapter: "hci0".into(),
|
||||
name: "One-KVM HID".into(),
|
||||
peer: None,
|
||||
})?;
|
||||
let result = async {
|
||||
for _ in 0..50 {
|
||||
if peripheral.status().initialized {
|
||||
break;
|
||||
}
|
||||
tokio::time::sleep(Duration::from_millis(100)).await;
|
||||
}
|
||||
let before = peripheral.status();
|
||||
if !before.initialized {
|
||||
return Err(format!("Initialization failed: {:?}", before.error));
|
||||
}
|
||||
if !before
|
||||
.devices
|
||||
.iter()
|
||||
.any(|d| Some(&d.address) == before.peer.as_ref() && d.paired)
|
||||
{
|
||||
return Err("This regression needs an existing bonded computer".into());
|
||||
}
|
||||
peripheral.action(Action::Pair(10)).await?;
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let open = peripheral.status();
|
||||
println!("open: {}", serde_json::to_string(&open).unwrap());
|
||||
if open.pairing_seconds == 0 {
|
||||
return Err("Existing bond prematurely closed pairing".into());
|
||||
}
|
||||
tokio::time::sleep(Duration::from_secs(10)).await;
|
||||
let expired = peripheral.status();
|
||||
println!("expired: {}", serde_json::to_string(&expired).unwrap());
|
||||
if expired.pairing_seconds != 0 || expired.peer != before.peer {
|
||||
return Err("Window did not expire while preserving the bonded peer".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
.await;
|
||||
let cleanup = peripheral.shutdown().await;
|
||||
result.and(cleanup)
|
||||
}
|
||||
24
libs/bluetooth-hid/examples/probe.rs
Normal file
24
libs/bluetooth-hid/examples/probe.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
//! Native hardware smoke check. Registers for 12 seconds, sends no input,
|
||||
//! opens no pairing window, then restores the adapter configuration.
|
||||
use one_kvm_bluetooth_hid::{Config, Peripheral};
|
||||
use std::time::Duration;
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), String> {
|
||||
let peripheral = Peripheral::start(Config {
|
||||
adapter: "hci0".into(),
|
||||
name: "One-KVM HID".into(),
|
||||
peer: None,
|
||||
})?;
|
||||
let mut initialized = false;
|
||||
for _ in 0..12 {
|
||||
tokio::time::sleep(Duration::from_secs(1)).await;
|
||||
let status = peripheral.status();
|
||||
initialized |= status.initialized;
|
||||
println!("{}", serde_json::to_string(&status).unwrap());
|
||||
}
|
||||
peripheral.shutdown().await?;
|
||||
if !initialized {
|
||||
return Err("Native BlueZ peripheral never initialized".into());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user