vibrate method

void vibrate({
  1. int leftMotorSpeed = 0,
  2. int rightMotorSpeed = 0,
})

Activate a gamepad controller's vibration motors.

Either the left or right motor can be activated. The value should be between 0 and 65535.

Implementation

void vibrate({int leftMotorSpeed = 0, int rightMotorSpeed = 0}) {
  if (leftMotorSpeed < 0 ||
      leftMotorSpeed > 65535 ||
      rightMotorSpeed < 0 ||
      rightMotorSpeed > 65535) {
    throw ArgumentError('Vibration value must be in range 0..65535');
  }

  final pVibration = calloc<XINPUT_VIBRATION>()
    ..ref.wLeftMotorSpeed = leftMotorSpeed
    ..ref.wRightMotorSpeed = rightMotorSpeed;
  try {
    final dwResult = XInputSetState(controller, pVibration);
    if (dwResult == WIN32_ERROR.ERROR_DEVICE_NOT_CONNECTED) {
      throw DeviceNotConnectedError();
    } else if (dwResult != WIN32_ERROR.ERROR_SUCCESS) {
      throw WindowsException(dwResult);
    }
  } finally {
    free(pVibration);
  }
}