feat(hid): 增加 HID 后端健康检查与错误码上报,完善前端掉线恢复状态同步及错误提示展示

This commit is contained in:
mofeng-git
2026-02-20 20:30:12 +08:00
parent 016c0d5dbb
commit 486db7b4aa
10 changed files with 378 additions and 24 deletions

View File

@@ -940,6 +940,30 @@ impl HidBackend for OtgBackend {
Ok(())
}
fn health_check(&self) -> Result<()> {
if !self.check_devices_exist() {
let missing = self.get_missing_devices();
self.online.store(false, Ordering::Relaxed);
return Err(AppError::HidError {
backend: "otg".to_string(),
reason: format!("HID device node missing: {}", missing.join(", ")),
error_code: "enoent".to_string(),
});
}
if !self.is_udc_configured() {
self.online.store(false, Ordering::Relaxed);
return Err(AppError::HidError {
backend: "otg".to_string(),
reason: "UDC is not in configured state".to_string(),
error_code: "udc_not_configured".to_string(),
});
}
self.online.store(true, Ordering::Relaxed);
Ok(())
}
fn supports_absolute_mouse(&self) -> bool {
self.mouse_abs_path.as_ref().is_some_and(|p| p.exists())
}