badicsalex / ar-drivers-rs

Opensource Rust driver for various AR glasses
MIT License
135 stars 21 forks source link

For XReal Air 1/Air 2 Pro on Windows, its IMU HID Device aways timeout on the first command to turn off IMU stream #13

Open tribbloid opened 6 months ago

tribbloid commented 6 months ago

Just started testing it on Windows (x86 processor, running read_sensors example), both the glasses HID & IMU HID devices can be found. But on initialisation, read_timeout will return 0 bit of data (debugging screenshot attached)

image

this will lead to the following error:

thread 'main' panicked at examples\read_sensors.rs:8:37:
called `Result::unwrap()` on an `Err` value: NotFound
stack backtrace:
   0: std::panicking::begin_panic_handler
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\std\src\panicking.rs:647
   1: core::panicking::panic_fmt
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\core\src\panicking.rs:72
   2: core::result::unwrap_failed
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97/library\core\src\result.rs:1649
   3: enum2$<core::result::Result<alloc::boxed::Box<dyn$<ar_drivers::ARGlasses>,alloc::alloc::Global>,enum2$<ar_drivers::Error> > >::unwrap
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\result.rs:1073
   4: read_sensors::main
             at .\examples\read_sensors.rs:8
   5: core::ops::function::FnOnce::call_once<void (*)(),tuple$<> >
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\ops\function.rs:250
   6: core::hint::black_box
             at /rustc/7cf61ebde7b22796c69757901dd346d0fe70bd97\library\core\src\hint.rs:334
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

I wonder if you have seen similar things on Windows? Is there a configuration I have to set before using it?

SimDoes commented 6 months ago

I also have the same issue using the XReal Air 2 Pro. The same code works on Mac OS but not Windows.

badicsalex commented 6 months ago

I have to admit, I never tried the code on windows.

This seems like an issue with the hidapi crate, and should probably be debugged there. It might be worthwhile to try the new-ish windows-native feature flag on it: https://www.reddit.com/r/rust/comments/192aa3h/comment/kh6h8lu/

SimDoes commented 6 months ago

Tried with hidapi 2.6.1 (where the reddit comment issue was already fixed) with windows-native feature enabled but still get the same error.

tribbloid commented 6 months ago

@SimDoes thanks, just changed the title.

hidapi-rs only has 1 unit test, which runs successfully but doesn't show much. That's my only attempt to fix it so far :-< Will try to compile & test the C library later

tribbloid commented 6 months ago

there are 2 rust runtime in Windows: one built on MSVC (which I used for test) and the other on GCC

@SimDoes are you also using the MSVC one?

SimDoes commented 5 months ago

there are 2 rust runtime in Windows: one built on MSVC (which I used for test) and the other on GCC

@SimDoes are you also using the MSVC one?

To be honest I have no clue, all I know is that I tried with windows-native feature flag enabled/not for hidapi-rs. Source code here might help.

kkota1 commented 4 months ago

This fixed Rokid Max on windows for me. Can someone confirm Xreal:

https://github.com/3rl-io/headset-utils/commit/1afb8794a1d55d28a8b4d43ba8c445eacd0c40ce

badicsalex commented 4 months ago

@kkota1 It's really weird that "not detaching" the kernel driver helps. I don't really know what that even means on windows, because I never dove that deep into libusb.

Which driver are you using?

kkota1 commented 4 months ago

@badicsalex the error message was something like “that method does not exist” so libusb for windows doesn’t have it . I forked peng’s fusion code and made some changes in the repo linked above

tribbloid commented 4 months ago

I'll test XReal Air 1 on Windows in the weekend, thanks a lot @kkota1 !

tribbloid commented 4 months ago

nope, got the same error:

can't find RokidAir: Glasses not found
can't find NrealAir: Packet timeout
can't find NrealLight: Hidapi error
can't find GrawoowG530: Glasses not found
can't find MadGazeGlow: Glasses not found
Glasses not found

The problem is always IMU, not the glasses itself.