Skip to content

Commit a26e5f3

Browse files
authored
Gyro degrees per second is 2000 across all 8bitdo controllers (#13147)
1 parent fc1c061 commit a26e5f3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/joystick/hidapi/SDL_hidapi_8bitdo.c

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ enum
4848
#define SDL_8BITDO_BT_REPORTID_SDL_REPORTID 0x01
4949

5050
#define ABITDO_ACCEL_SCALE 4096.f
51-
#define SENSOR_INTERVAL_NS 8000000ULL
51+
#define ABITDO_SENSOR_POLLING_RATE 125.f
52+
#define SENSOR_INTERVAL_NS 8000000ULL
53+
#define ABITDO_GYRO_MAX_DEGREES_PER_SECOND 2000.f
5254

5355
typedef struct
5456
{
@@ -67,7 +69,7 @@ typedef struct
6769
float accelScale;
6870
float gyroScale;
6971
Uint8 last_state[USB_PACKET_LENGTH];
70-
Uint64 sensor_timestamp; // Microseconds. Simulate onboard clock. Advance by known rate: SENSOR_INTERVAL_NS == 8ms = 125 Hz
72+
Uint64 sensor_timestamp; // Nanoseconds. Simulate onboard clock. Advance by known rate: SENSOR_INTERVAL_NS == 8ms = 125 Hz
7173
} SDL_Driver8BitDo_Context;
7274

7375
#pragma pack(push,1)
@@ -240,12 +242,13 @@ static bool HIDAPI_Driver8BitDo_OpenJoystick(SDL_HIDAPI_Device *device, SDL_Joys
240242
joystick->nhats = 1;
241243

242244
if (ctx->sensors_supported) {
243-
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 125.0f);
244-
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 125.0f);
245+
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, ABITDO_SENSOR_POLLING_RATE);
246+
SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, ABITDO_SENSOR_POLLING_RATE);
245247

246248

247249
ctx->accelScale = SDL_STANDARD_GRAVITY / ABITDO_ACCEL_SCALE;
248-
ctx->gyroScale = DEG2RAD(2048) / INT16_MAX; // Hardware senses +/- 2048 Degrees per second mapped to +/- INT16_MAX
250+
// Hardware senses +/- N Degrees per second mapped to +/- INT16_MAX
251+
ctx->gyroScale = DEG2RAD(ABITDO_GYRO_MAX_DEGREES_PER_SECOND) / INT16_MAX;
249252
}
250253

251254
return true;

0 commit comments

Comments
 (0)