Repository: libsdl-org/SDL
File: src/joystick/hidapi/SDL_hidapi_8bitdo.c (C)

Code before:
{
    SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;

    SDL_AssertJoysticksLocked();

    SDL_zeroa(ctx->last_state);

    // Initialize the joystick capabilities
    if (device->product_id == USB_PRODUCT_8BITDO_PRO_2 ||
        device->product_id == USB_PRODUCT_8BITDO_PRO_2_BT ||
        device->product_id == USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS) {
        // This controller has additional buttons
        joystick->nbuttons = SDL_GAMEPAD_NUM_8BITDO_BUTTONS;
    } else {
        joystick->nbuttons = 11;
    }
    joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
    joystick->nhats = 1;

    if (ctx->sensors_supported) {
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, ABITDO_SENSOR_POLLING_RATE);
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, ABITDO_SENSOR_POLLING_RATE);


        ctx->accelScale = SDL_STANDARD_GRAVITY / ABITDO_ACCEL_SCALE;
        ctx->gyroScale = DEG2RAD(ABITDO_GYRO_MAX_DEGREES_PER_SECOND) / INT16_MAX; /* Hardware senses  +/- N Degrees per second mapped to +/- INT16_MAX */
    }

    return true;
}

static bool HIDAPI_Driver8BitDo_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
    SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
    if (ctx->rumble_supported) {
        Uint8 rumble_packet[5] = { 0x05, 0x00, 0x00, 0x00, 0x00 };
        rumble_packet[1] = low_frequency_rumble >> 8;
        rumble_packet[2] = high_frequency_rumble >> 8;

        if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
            return SDL_SetError("Couldn't send rumble packet");
        }
        return true;
    } else {
        return SDL_Unsupported();
    }
}

static bool HIDAPI_Driver8BitDo_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{
    return SDL_Unsupported();

Review comment (suggestion):
```suggestion
        // Hardware senses +/- N Degrees per second mapped to +/- INT16_MAX
        ctx->gyroScale = DEG2RAD(ABITDO_GYRO_MAX_DEGREES_PER_SECOND) / INT16_MAX;
```

Code after:
{
    SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;

    SDL_AssertJoysticksLocked();

    SDL_zeroa(ctx->last_state);

    // Initialize the joystick capabilities
    if (device->product_id == USB_PRODUCT_8BITDO_PRO_2 ||
        device->product_id == USB_PRODUCT_8BITDO_PRO_2_BT ||
        device->product_id == USB_PRODUCT_8BITDO_ULTIMATE2_WIRELESS) {
        // This controller has additional buttons
        joystick->nbuttons = SDL_GAMEPAD_NUM_8BITDO_BUTTONS;
    } else {
        joystick->nbuttons = 11;
    }
    joystick->naxes = SDL_GAMEPAD_AXIS_COUNT;
    joystick->nhats = 1;

    if (ctx->sensors_supported) {
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, ABITDO_SENSOR_POLLING_RATE);
        SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, ABITDO_SENSOR_POLLING_RATE);


        ctx->accelScale = SDL_STANDARD_GRAVITY / ABITDO_ACCEL_SCALE;
        // Hardware senses +/- N Degrees per second mapped to +/- INT16_MAX
        ctx->gyroScale = DEG2RAD(ABITDO_GYRO_MAX_DEGREES_PER_SECOND) / INT16_MAX;
    }

    return true;
}

static bool HIDAPI_Driver8BitDo_RumbleJoystick(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 low_frequency_rumble, Uint16 high_frequency_rumble)
{
    SDL_Driver8BitDo_Context *ctx = (SDL_Driver8BitDo_Context *)device->context;
    if (ctx->rumble_supported) {
        Uint8 rumble_packet[5] = { 0x05, 0x00, 0x00, 0x00, 0x00 };
        rumble_packet[1] = low_frequency_rumble >> 8;
        rumble_packet[2] = high_frequency_rumble >> 8;

        if (SDL_HIDAPI_SendRumble(device, rumble_packet, sizeof(rumble_packet)) != sizeof(rumble_packet)) {
            return SDL_SetError("Couldn't send rumble packet");
        }
        return true;
    } else {
        return SDL_Unsupported();
    }
}

static bool HIDAPI_Driver8BitDo_RumbleJoystickTriggers(SDL_HIDAPI_Device *device, SDL_Joystick *joystick, Uint16 left_rumble, Uint16 right_rumble)
{