sdlxGetSensorData function sensor

bool sdlxGetSensorData(
  1. Pointer<SdlSensor> sensor,
  2. SdlxSensorData data, {
  3. int numValues = 6,
})

Get the current state of an opened sensor.

The number of values and interpretation of the data is sensor dependent.

\param sensor the SDL_Sensor object to query. \param data a pointer filled with the current sensor state. \param num_values the number of values to write to data. \returns true on success or false on failure; call SDL_GetError() for more information.

\since This function is available since SDL 3.2.0.

extern SDL_DECLSPEC bool SDLCALL SDL_GetSensorData(SDL_Sensor *sensor, float *data, int num_values)

Implementation

bool sdlxGetSensorData(
  Pointer<SdlSensor> sensor,
  SdlxSensorData data, {
  int numValues = 6,
}) {
  final dataPointer = ffi.calloc<Float>(numValues);
  final result = sdlGetSensorData(sensor, dataPointer, numValues);
  if (result) {
    for (var i = 0; i < numValues; i++) {
      data.data.add(dataPointer[i]);
    }
  }
  dataPointer.callocFree();
  return result;
}