Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: hidapi feature SensorType implementation #1428

Open
Goldenbough44 opened this issue Aug 28, 2024 · 0 comments
Open

bug: hidapi feature SensorType implementation #1428

Goldenbough44 opened this issue Aug 28, 2024 · 0 comments

Comments

@Goldenbough44
Copy link

Rust error E0004 (https://doc.rust-lang.org/error_codes/E0004.html) when enabling the library's hidapi feature due to the difference between the library's SensorType implementation and SDL's SDL_SensorType implementation.

The error would be vanished simply by editing sensor.rs file from:

impl From<SensorType> for SDL_SensorType {
    fn from(val: SensorType) -> Self {
        match val {
            SensorType::Unknown => SDL_SensorType::SDL_SENSOR_UNKNOWN,
            SensorType::Gyroscope => SDL_SensorType::SDL_SENSOR_GYRO,
            SensorType::Accelerometer => SDL_SensorType::SDL_SENSOR_ACCEL,
        }
    }
}

into:

impl From<SensorType> for SDL_SensorType {
    fn from(val: SensorType) -> Self {
        match val {
            SensorType::Unknown => SDL_SensorType::SDL_SENSOR_UNKNOWN,
            SensorType::Gyroscope => SDL_SensorType::SDL_SENSOR_GYRO,
            SensorType::Accelerometer => SDL_SensorType::SDL_SENSOR_ACCEL,
            _ => SDL_SensorType::SDL_SENSOR_UNKNOWN,
        }
    }
}

However, this approach doesn't really solve the problem.

Current SDL-sys bindings are:

#[repr(i32)]
#[derive(Copy, Clone, Hash, PartialEq, Eq)]
pub enum SDL_SensorType {
    #[doc = "< Returned for an invalid sensor"]
    SDL_SENSOR_INVALID = -1,
    #[doc = "< Unknown sensor type"]
    SDL_SENSOR_UNKNOWN = 0,
    #[doc = "< Accelerometer"]
    SDL_SENSOR_ACCEL = 1,
    #[doc = "< Gyroscope"]
    SDL_SENSOR_GYRO = 2,
    #[doc = "< Accelerometer for left Joy-Con controller and Wii nunchuk"]
    SDL_SENSOR_ACCEL_L = 3,
    #[doc = "< Gyroscope for left Joy-Con controller"]
    SDL_SENSOR_GYRO_L = 4,
    #[doc = "< Accelerometer for right Joy-Con controller"]
    SDL_SENSOR_ACCEL_R = 5,
    #[doc = "< Gyroscope for right Joy-Con controller"]
    SDL_SENSOR_GYRO_R = 6,
}

but the library's SensorType implementation is:

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SensorType {
    Unknown,
    Gyroscope,
    Accelerometer,
}

I'm not sure why this difference occurs as I haven't looked at the library in detail, but I guess the library needs to be modified to match the SDL-sys implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant