Skip to content

Commit 5904d1d

Browse files
committed
Update SensorTypes to match SDL bindings
1 parent afac1b9 commit 5904d1d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/sdl2/sensor.rs

+20
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,22 @@ impl SensorSubsystem {
6969
pub enum SensorType {
7070
Unknown,
7171
Gyroscope,
72+
LeftGyroscope,
73+
RightGyroscope,
7274
Accelerometer,
75+
LeftAccelerometer,
76+
RightAccelerometer,
7377
}
7478

7579
impl SensorType {
7680
pub fn from_ll(raw: i32) -> Self {
7781
match raw {
7882
x if x == SDL_SensorType::SDL_SENSOR_GYRO as i32 => SensorType::Gyroscope,
83+
x if x == SDL_SensorType::SDL_SENSOR_GYRO_L as i32 => SensorType::LeftGyroscope,
84+
x if x == SDL_SensorType::SDL_SENSOR_GYRO_R as i32 => SensorType::RightGyroscope,
7985
x if x == SDL_SensorType::SDL_SENSOR_ACCEL as i32 => SensorType::Accelerometer,
86+
x if x == SDL_SensorType::SDL_SENSOR_ACCEL_L as i32 => SensorType::LeftAccelerometer,
87+
x if x == SDL_SensorType::SDL_SENSOR_ACCEL_R as i32 => SensorType::RightAccelerometer,
8088
_ => SensorType::Unknown,
8189
}
8290
}
@@ -87,7 +95,11 @@ impl From<SensorType> for SDL_SensorType {
8795
match val {
8896
SensorType::Unknown => SDL_SensorType::SDL_SENSOR_UNKNOWN,
8997
SensorType::Gyroscope => SDL_SensorType::SDL_SENSOR_GYRO,
98+
SensorType::LeftGyroscope => SDL_SensorType::SDL_SENSOR_GYRO_L,
99+
SensorType::RightGyroscope => SDL_SensorType::SDL_SENSOR_GYRO_R,
90100
SensorType::Accelerometer => SDL_SensorType::SDL_SENSOR_ACCEL,
101+
SensorType::LeftAccelerometer => SDL_SensorType::SDL_SENSOR_ACCEL_L,
102+
SensorType::RightAccelerometer => SDL_SensorType::SDL_SENSOR_ACCEL_R,
91103
}
92104
}
93105
}
@@ -136,7 +148,11 @@ impl Sensor {
136148
}
137149
sys::SDL_SensorType::SDL_SENSOR_UNKNOWN => SensorType::Unknown,
138150
sys::SDL_SensorType::SDL_SENSOR_ACCEL => SensorType::Accelerometer,
151+
sys::SDL_SensorType::SDL_SENSOR_ACCEL_L => SensorType::LeftAccelerometer,
152+
sys::SDL_SensorType::SDL_SENSOR_ACCEL_R => SensorType::RightAccelerometer,
139153
sys::SDL_SensorType::SDL_SENSOR_GYRO => SensorType::Gyroscope,
154+
sys::SDL_SensorType::SDL_SENSOR_GYRO_L => SensorType::LeftGyroscope,
155+
sys::SDL_SensorType::SDL_SENSOR_GYRO_R => SensorType::RightGyroscope,
140156
}
141157
}
142158

@@ -153,7 +169,11 @@ impl Sensor {
153169
} else {
154170
Ok(match self.sensor_type() {
155171
SensorType::Gyroscope => SensorData::Gyro([data[0], data[1], data[2]]),
172+
SensorType::LeftGyroscope => SensorData::Gyro([data[0], data[1], data[2]]),
173+
SensorType::RightGyroscope => SensorData::Gyro([data[0], data[1], data[2]]),
156174
SensorType::Accelerometer => SensorData::Accel([data[0], data[1], data[2]]),
175+
SensorType::LeftAccelerometer => SensorData::Accel([data[0], data[1], data[2]]),
176+
SensorType::RightAccelerometer => SensorData::Accel([data[0], data[1], data[2]]),
157177
SensorType::Unknown => SensorData::Unknown(data),
158178
})
159179
}

0 commit comments

Comments
 (0)