Fixed Windows accelerometer data units
authorSam Lantinga <slouken@libsdl.org>
Wed, 08 Apr 2020 10:27:30 -0700
changeset 13716d2647d9e93c7
parent 13715 e8788447f3a6
child 13717 3b90978ddf04
Fixed Windows accelerometer data units
src/sensor/windows/SDL_windowssensor.c
     1.1 --- a/src/sensor/windows/SDL_windowssensor.c	Wed Apr 08 09:02:02 2020 -0700
     1.2 +++ b/src/sensor/windows/SDL_windowssensor.c	Wed Apr 08 10:27:30 2020 -0700
     1.3 @@ -47,12 +47,12 @@
     1.4  
     1.5  typedef struct
     1.6  {
     1.7 -	SDL_SensorID id;
     1.8 -	ISensor *sensor;
     1.9 -	SENSOR_ID sensor_id;
    1.10 -	char *name;
    1.11 -	SDL_SensorType type;
    1.12 -	SDL_Sensor *sensor_opened;
    1.13 +    SDL_SensorID id;
    1.14 +    ISensor *sensor;
    1.15 +    SENSOR_ID sensor_id;
    1.16 +    char *name;
    1.17 +    SDL_SensorType type;
    1.18 +    SDL_Sensor *sensor_opened;
    1.19  
    1.20  } SDL_Windows_Sensor;
    1.21  
    1.22 @@ -66,320 +66,322 @@
    1.23  
    1.24  static HRESULT STDMETHODCALLTYPE ISensorManagerEventsVtbl_QueryInterface(ISensorManagerEvents * This, REFIID riid, void **ppvObject)
    1.25  {
    1.26 -	if (!ppvObject) {
    1.27 -		return E_INVALIDARG;
    1.28 -	}
    1.29 +    if (!ppvObject) {
    1.30 +        return E_INVALIDARG;
    1.31 +    }
    1.32  
    1.33 -	*ppvObject = NULL;
    1.34 -	if (WIN_IsEqualIID(riid, &IID_IUnknown) || WIN_IsEqualIID(riid, &IID_SensorManagerEvents)) {
    1.35 -		*ppvObject = This;
    1.36 -		return S_OK;
    1.37 -	}
    1.38 -	return E_NOINTERFACE;
    1.39 +    *ppvObject = NULL;
    1.40 +    if (WIN_IsEqualIID(riid, &IID_IUnknown) || WIN_IsEqualIID(riid, &IID_SensorManagerEvents)) {
    1.41 +        *ppvObject = This;
    1.42 +        return S_OK;
    1.43 +    }
    1.44 +    return E_NOINTERFACE;
    1.45  }
    1.46  
    1.47  static ULONG STDMETHODCALLTYPE ISensorManagerEventsVtbl_AddRef(ISensorManagerEvents * This)
    1.48  {
    1.49 -	return 1;
    1.50 +    return 1;
    1.51  }
    1.52  
    1.53  static ULONG STDMETHODCALLTYPE ISensorManagerEventsVtbl_Release(ISensorManagerEvents * This)
    1.54  {
    1.55 -	return 1;
    1.56 +    return 1;
    1.57  }
    1.58  
    1.59  static HRESULT STDMETHODCALLTYPE ISensorManagerEventsVtbl_OnSensorEnter(ISensorManagerEvents * This, ISensor *pSensor, SensorState state)
    1.60  {
    1.61 -	ConnectSensor(pSensor);
    1.62 -	return S_OK;
    1.63 +    ConnectSensor(pSensor);
    1.64 +    return S_OK;
    1.65  }
    1.66  
    1.67  static ISensorManagerEventsVtbl sensor_manager_events_vtbl = {
    1.68 -	ISensorManagerEventsVtbl_QueryInterface,
    1.69 -	ISensorManagerEventsVtbl_AddRef,
    1.70 -	ISensorManagerEventsVtbl_Release,
    1.71 -	ISensorManagerEventsVtbl_OnSensorEnter
    1.72 +    ISensorManagerEventsVtbl_QueryInterface,
    1.73 +    ISensorManagerEventsVtbl_AddRef,
    1.74 +    ISensorManagerEventsVtbl_Release,
    1.75 +    ISensorManagerEventsVtbl_OnSensorEnter
    1.76  };
    1.77  static ISensorManagerEvents sensor_manager_events = {
    1.78 -	&sensor_manager_events_vtbl
    1.79 +    &sensor_manager_events_vtbl
    1.80  };
    1.81  
    1.82  static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_QueryInterface(ISensorEvents * This, REFIID riid, void **ppvObject)
    1.83  {
    1.84 -	if (!ppvObject) {
    1.85 -		return E_INVALIDARG;
    1.86 -	}
    1.87 +    if (!ppvObject) {
    1.88 +        return E_INVALIDARG;
    1.89 +    }
    1.90  
    1.91 -	*ppvObject = NULL;
    1.92 -	if (WIN_IsEqualIID(riid, &IID_IUnknown) || WIN_IsEqualIID(riid, &IID_SensorEvents)) {
    1.93 -		*ppvObject = This;
    1.94 -		return S_OK;
    1.95 -	}
    1.96 -	return E_NOINTERFACE;
    1.97 +    *ppvObject = NULL;
    1.98 +    if (WIN_IsEqualIID(riid, &IID_IUnknown) || WIN_IsEqualIID(riid, &IID_SensorEvents)) {
    1.99 +        *ppvObject = This;
   1.100 +        return S_OK;
   1.101 +    }
   1.102 +    return E_NOINTERFACE;
   1.103  }
   1.104  
   1.105  static ULONG STDMETHODCALLTYPE ISensorEventsVtbl_AddRef(ISensorEvents * This)
   1.106  {
   1.107 -	return 1;
   1.108 +    return 1;
   1.109  }
   1.110  
   1.111  static ULONG STDMETHODCALLTYPE ISensorEventsVtbl_Release(ISensorEvents * This)
   1.112  {
   1.113 -	return 1;
   1.114 +    return 1;
   1.115  }
   1.116  
   1.117  static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnStateChanged(ISensorEvents * This, ISensor *pSensor, SensorState state)
   1.118  {
   1.119  #ifdef DEBUG_SENSORS
   1.120 -	int i;
   1.121 +    int i;
   1.122  
   1.123 -	SDL_LockSensors();
   1.124 -	for (i = 0; i < SDL_num_sensors; ++i) {
   1.125 -		if (pSensor == SDL_sensors[i].sensor) {
   1.126 -			SDL_Log("Sensor %s state changed to %d\n", SDL_sensors[i].name, state);
   1.127 -		}
   1.128 -	}
   1.129 -	SDL_UnlockSensors();
   1.130 +    SDL_LockSensors();
   1.131 +    for (i = 0; i < SDL_num_sensors; ++i) {
   1.132 +        if (pSensor == SDL_sensors[i].sensor) {
   1.133 +            SDL_Log("Sensor %s state changed to %d\n", SDL_sensors[i].name, state);
   1.134 +        }
   1.135 +    }
   1.136 +    SDL_UnlockSensors();
   1.137  #endif
   1.138 -	return S_OK;
   1.139 +    return S_OK;
   1.140  }
   1.141  
   1.142  static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents * This, ISensor *pSensor, ISensorDataReport *pNewData)
   1.143  {
   1.144 -	int i;
   1.145 +    int i;
   1.146  
   1.147 -	SDL_LockSensors();
   1.148 -	for (i = 0; i < SDL_num_sensors; ++i) {
   1.149 -		if (pSensor == SDL_sensors[i].sensor) {
   1.150 -			if (SDL_sensors[i].sensor_opened) {
   1.151 -				HRESULT hrX, hrY, hrZ;
   1.152 -				PROPVARIANT valueX, valueY, valueZ;
   1.153 +    SDL_LockSensors();
   1.154 +    for (i = 0; i < SDL_num_sensors; ++i) {
   1.155 +        if (pSensor == SDL_sensors[i].sensor) {
   1.156 +            if (SDL_sensors[i].sensor_opened) {
   1.157 +                HRESULT hrX, hrY, hrZ;
   1.158 +                PROPVARIANT valueX, valueY, valueZ;
   1.159  
   1.160  #ifdef DEBUG_SENSORS
   1.161 -				SDL_Log("Sensor %s data updated\n", SDL_sensors[i].name);
   1.162 +                SDL_Log("Sensor %s data updated\n", SDL_sensors[i].name);
   1.163  #endif
   1.164 -				switch (SDL_sensors[i].type) {
   1.165 -				case SDL_SENSOR_ACCEL:
   1.166 -					hrX = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_X_G, &valueX);
   1.167 -					hrY = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_Y_G, &valueY);
   1.168 -					hrZ = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_Z_G, &valueZ);
   1.169 -					if (SUCCEEDED(hrX) && SUCCEEDED(hrY) && SUCCEEDED(hrZ) &&
   1.170 -						valueX.vt == VT_R8 && valueY.vt == VT_R8 && valueZ.vt == VT_R8) {
   1.171 -						float values[3];
   1.172 +                switch (SDL_sensors[i].type) {
   1.173 +                case SDL_SENSOR_ACCEL:
   1.174 +                    hrX = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_X_G, &valueX);
   1.175 +                    hrY = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_Y_G, &valueY);
   1.176 +                    hrZ = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_Z_G, &valueZ);
   1.177 +                    if (SUCCEEDED(hrX) && SUCCEEDED(hrY) && SUCCEEDED(hrZ) &&
   1.178 +                        valueX.vt == VT_R8 && valueY.vt == VT_R8 && valueZ.vt == VT_R8) {
   1.179 +                        float values[3];
   1.180  
   1.181 -						values[0] = (float)valueX.dblVal;
   1.182 -						values[1] = (float)valueY.dblVal;
   1.183 -						values[2] = (float)valueZ.dblVal;
   1.184 -						SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, values, 3);
   1.185 -					}
   1.186 -					break;
   1.187 -				case SDL_SENSOR_GYRO:
   1.188 -					hrX = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, &valueX);
   1.189 -					hrY = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, &valueY);
   1.190 -					hrZ = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, &valueZ);
   1.191 -					if (SUCCEEDED(hrX) && SUCCEEDED(hrY) && SUCCEEDED(hrZ) &&
   1.192 -						valueX.vt == VT_R8 && valueY.vt == VT_R8 && valueZ.vt == VT_R8) {
   1.193 -						float values[3];
   1.194 +                        values[0] = (float)valueX.dblVal * SDL_STANDARD_GRAVITY;
   1.195 +                        values[1] = (float)valueY.dblVal * SDL_STANDARD_GRAVITY;
   1.196 +                        values[2] = (float)valueZ.dblVal * SDL_STANDARD_GRAVITY;
   1.197 +                        SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, values, 3);
   1.198 +                    }
   1.199 +                    break;
   1.200 +                case SDL_SENSOR_GYRO:
   1.201 +                    hrX = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ANGULAR_VELOCITY_X_DEGREES_PER_SECOND, &valueX);
   1.202 +                    hrY = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Y_DEGREES_PER_SECOND, &valueY);
   1.203 +                    hrZ = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ANGULAR_VELOCITY_Z_DEGREES_PER_SECOND, &valueZ);
   1.204 +                    if (SUCCEEDED(hrX) && SUCCEEDED(hrY) && SUCCEEDED(hrZ) &&
   1.205 +                        valueX.vt == VT_R8 && valueY.vt == VT_R8 && valueZ.vt == VT_R8) {
   1.206 +                        const float DEGREES_TO_RADIANS = (float)(M_PI / 180.0f);
   1.207 +                        float values[3];
   1.208  
   1.209 -						values[0] = (float)(valueX.dblVal * (M_PI / 180.0));
   1.210 -						values[1] = (float)(valueY.dblVal * (M_PI / 180.0));
   1.211 -						values[2] = (float)(valueZ.dblVal * (M_PI / 180.0));
   1.212 -						SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, values, 3);
   1.213 -					}
   1.214 -					break;
   1.215 -				default:
   1.216 -					/* FIXME: Need to know how to interpret the data for this sensor */
   1.217 -					break;
   1.218 -				}
   1.219 -			}
   1.220 -			break;
   1.221 -		}
   1.222 -	}
   1.223 -	SDL_UnlockSensors();
   1.224 +                        values[0] = (float)valueX.dblVal * DEGREES_TO_RADIANS;
   1.225 +                        values[1] = (float)valueY.dblVal * DEGREES_TO_RADIANS;
   1.226 +                        values[2] = (float)valueZ.dblVal * DEGREES_TO_RADIANS;
   1.227 +                        SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, values, 3);
   1.228 +                    }
   1.229 +                    break;
   1.230 +                default:
   1.231 +                    /* FIXME: Need to know how to interpret the data for this sensor */
   1.232 +                    break;
   1.233 +                }
   1.234 +            }
   1.235 +            break;
   1.236 +        }
   1.237 +    }
   1.238 +    SDL_UnlockSensors();
   1.239  
   1.240 -	return S_OK;
   1.241 +    return S_OK;
   1.242  }
   1.243  
   1.244  static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnEvent(ISensorEvents * This, ISensor *pSensor, REFGUID eventID, IPortableDeviceValues *pEventData)
   1.245  {
   1.246  #ifdef DEBUG_SENSORS
   1.247 -	int i;
   1.248 +    int i;
   1.249  
   1.250 -	SDL_LockSensors();
   1.251 -	for (i = 0; i < SDL_num_sensors; ++i) {
   1.252 -		if (pSensor == SDL_sensors[i].sensor) {
   1.253 -			SDL_Log("Sensor %s event occurred\n", SDL_sensors[i].name);
   1.254 -		}
   1.255 -	}
   1.256 -	SDL_UnlockSensors();
   1.257 +    SDL_LockSensors();
   1.258 +    for (i = 0; i < SDL_num_sensors; ++i) {
   1.259 +        if (pSensor == SDL_sensors[i].sensor) {
   1.260 +            SDL_Log("Sensor %s event occurred\n", SDL_sensors[i].name);
   1.261 +        }
   1.262 +    }
   1.263 +    SDL_UnlockSensors();
   1.264  #endif
   1.265 -	return S_OK;
   1.266 +    return S_OK;
   1.267  }
   1.268  
   1.269  static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnLeave(ISensorEvents * This, REFSENSOR_ID ID)
   1.270  {
   1.271 -	int i;
   1.272 +    int i;
   1.273  
   1.274 -	SDL_LockSensors();
   1.275 -	for (i = 0; i < SDL_num_sensors; ++i) {
   1.276 -		if (WIN_IsEqualIID(ID, &SDL_sensors[i].sensor_id)) {
   1.277 +    SDL_LockSensors();
   1.278 +    for (i = 0; i < SDL_num_sensors; ++i) {
   1.279 +        if (WIN_IsEqualIID(ID, &SDL_sensors[i].sensor_id)) {
   1.280  #ifdef DEBUG_SENSORS
   1.281 -			SDL_Log("Sensor %s disconnected\n", SDL_sensors[i].name);
   1.282 +            SDL_Log("Sensor %s disconnected\n", SDL_sensors[i].name);
   1.283  #endif
   1.284 -			DisconnectSensor(SDL_sensors[i].sensor);
   1.285 -		}
   1.286 -	}
   1.287 -	SDL_UnlockSensors();
   1.288 +            DisconnectSensor(SDL_sensors[i].sensor);
   1.289 +        }
   1.290 +    }
   1.291 +    SDL_UnlockSensors();
   1.292  
   1.293 -	return S_OK;
   1.294 +    return S_OK;
   1.295  }
   1.296  
   1.297  static ISensorEventsVtbl sensor_events_vtbl = {
   1.298 -	ISensorEventsVtbl_QueryInterface,
   1.299 -	ISensorEventsVtbl_AddRef,
   1.300 -	ISensorEventsVtbl_Release,
   1.301 -	ISensorEventsVtbl_OnStateChanged,
   1.302 -	ISensorEventsVtbl_OnDataUpdated,
   1.303 -	ISensorEventsVtbl_OnEvent,
   1.304 -	ISensorEventsVtbl_OnLeave
   1.305 +    ISensorEventsVtbl_QueryInterface,
   1.306 +    ISensorEventsVtbl_AddRef,
   1.307 +    ISensorEventsVtbl_Release,
   1.308 +    ISensorEventsVtbl_OnStateChanged,
   1.309 +    ISensorEventsVtbl_OnDataUpdated,
   1.310 +    ISensorEventsVtbl_OnEvent,
   1.311 +    ISensorEventsVtbl_OnLeave
   1.312  };
   1.313  static ISensorEvents sensor_events = {
   1.314 -	&sensor_events_vtbl
   1.315 +    &sensor_events_vtbl
   1.316  };
   1.317  
   1.318  static int ConnectSensor(ISensor *sensor)
   1.319  {
   1.320 -	SDL_Windows_Sensor *new_sensor, *new_sensors;
   1.321 -	HRESULT hr;
   1.322 -	SENSOR_ID sensor_id;
   1.323 -	SENSOR_TYPE_ID type_id;
   1.324 -	SDL_SensorType type;
   1.325 -	BSTR bstr_name = NULL;
   1.326 -	char *name;
   1.327 +    SDL_Windows_Sensor *new_sensor, *new_sensors;
   1.328 +    HRESULT hr;
   1.329 +    SENSOR_ID sensor_id;
   1.330 +    SENSOR_TYPE_ID type_id;
   1.331 +    SDL_SensorType type;
   1.332 +    BSTR bstr_name = NULL;
   1.333 +    char *name;
   1.334  
   1.335 -	hr = ISensor_GetID(sensor, &sensor_id);
   1.336 -	if (FAILED(hr)) {
   1.337 -		return SDL_SetError("Couldn't get sensor ID: 0x%.4x", hr);
   1.338 -	}
   1.339 +    hr = ISensor_GetID(sensor, &sensor_id);
   1.340 +    if (FAILED(hr)) {
   1.341 +        return SDL_SetError("Couldn't get sensor ID: 0x%.4x", hr);
   1.342 +    }
   1.343  
   1.344 -	hr = ISensor_GetType(sensor, &type_id);
   1.345 -	if (FAILED(hr)) {
   1.346 -		return SDL_SetError("Couldn't get sensor type: 0x%.4x", hr);
   1.347 -	}
   1.348 +    hr = ISensor_GetType(sensor, &type_id);
   1.349 +    if (FAILED(hr)) {
   1.350 +        return SDL_SetError("Couldn't get sensor type: 0x%.4x", hr);
   1.351 +    }
   1.352  
   1.353 -	if (WIN_IsEqualIID(&type_id, &SENSOR_TYPE_ACCELEROMETER_3D)) {
   1.354 -		type = SDL_SENSOR_ACCEL;
   1.355 -	} else if (WIN_IsEqualIID(&type_id, &SENSOR_TYPE_GYROMETER_3D)) {
   1.356 -		type = SDL_SENSOR_GYRO;
   1.357 -	} else {
   1.358 -		return SDL_SetError("Unknown sensor type");
   1.359 -	}
   1.360 +    if (WIN_IsEqualIID(&type_id, &SENSOR_TYPE_ACCELEROMETER_3D)) {
   1.361 +        type = SDL_SENSOR_ACCEL;
   1.362 +    } else if (WIN_IsEqualIID(&type_id, &SENSOR_TYPE_GYROMETER_3D)) {
   1.363 +        type = SDL_SENSOR_GYRO;
   1.364 +    } else {
   1.365 +        return SDL_SetError("Unknown sensor type");
   1.366 +    }
   1.367  
   1.368 -	hr = ISensor_GetFriendlyName(sensor, &bstr_name);
   1.369 -	if (SUCCEEDED(hr) && bstr_name) {
   1.370 -		name = WIN_StringToUTF8(bstr_name);
   1.371 -	} else {
   1.372 -		name = SDL_strdup("Unknown Sensor");
   1.373 -	}
   1.374 +    hr = ISensor_GetFriendlyName(sensor, &bstr_name);
   1.375 +    if (SUCCEEDED(hr) && bstr_name) {
   1.376 +        name = WIN_StringToUTF8(bstr_name);
   1.377 +    } else {
   1.378 +        name = SDL_strdup("Unknown Sensor");
   1.379 +    }
   1.380      if (bstr_name != NULL) {
   1.381          SysFreeString(bstr_name);
   1.382      }
   1.383 -	if (!name) {
   1.384 -		return SDL_OutOfMemory();
   1.385 -	}
   1.386 +    if (!name) {
   1.387 +        return SDL_OutOfMemory();
   1.388 +    }
   1.389  
   1.390 -	SDL_LockSensors();
   1.391 -	new_sensors = (SDL_Windows_Sensor *)SDL_realloc(SDL_sensors, (SDL_num_sensors + 1) * sizeof(SDL_Windows_Sensor));
   1.392 -	if (new_sensors == NULL) {
   1.393 -		SDL_UnlockSensors();
   1.394 -		return SDL_OutOfMemory();
   1.395 -	}
   1.396 +    SDL_LockSensors();
   1.397 +    new_sensors = (SDL_Windows_Sensor *)SDL_realloc(SDL_sensors, (SDL_num_sensors + 1) * sizeof(SDL_Windows_Sensor));
   1.398 +    if (new_sensors == NULL) {
   1.399 +        SDL_UnlockSensors();
   1.400 +        return SDL_OutOfMemory();
   1.401 +    }
   1.402 +
   1.403 +    ISensor_AddRef(sensor);
   1.404 +    ISensor_SetEventSink(sensor, &sensor_events);
   1.405  
   1.406 -	ISensor_AddRef(sensor);
   1.407 -	ISensor_SetEventSink(sensor, &sensor_events);
   1.408 -
   1.409 -	SDL_sensors = new_sensors;
   1.410 -	new_sensor = &SDL_sensors[SDL_num_sensors];
   1.411 -	++SDL_num_sensors;
   1.412 +    SDL_sensors = new_sensors;
   1.413 +    new_sensor = &SDL_sensors[SDL_num_sensors];
   1.414 +    ++SDL_num_sensors;
   1.415  
   1.416 -	new_sensor->id = SDL_GetNextSensorInstanceID();
   1.417 -	new_sensor->sensor = sensor;
   1.418 -	new_sensor->type = type;
   1.419 -	new_sensor->name = name;
   1.420 +    SDL_zerop(new_sensor);
   1.421 +    new_sensor->id = SDL_GetNextSensorInstanceID();
   1.422 +    new_sensor->sensor = sensor;
   1.423 +    new_sensor->type = type;
   1.424 +    new_sensor->name = name;
   1.425  
   1.426 -	SDL_UnlockSensors();
   1.427 +    SDL_UnlockSensors();
   1.428  
   1.429 -	return 0;
   1.430 +    return 0;
   1.431  }
   1.432  
   1.433  static int DisconnectSensor(ISensor *sensor)
   1.434  {
   1.435 -	SDL_Windows_Sensor *old_sensor;
   1.436 -	int i;
   1.437 +    SDL_Windows_Sensor *old_sensor;
   1.438 +    int i;
   1.439  
   1.440 -	SDL_LockSensors();
   1.441 -	for (i = 0; i < SDL_num_sensors; ++i) {
   1.442 -		old_sensor = &SDL_sensors[i];
   1.443 -		if (sensor == old_sensor->sensor) {
   1.444 -			ISensor_SetEventSink(sensor, NULL);
   1.445 -			ISensor_Release(sensor);
   1.446 -			SDL_free(old_sensor->name);
   1.447 -			--SDL_num_sensors;
   1.448 -			if (i < SDL_num_sensors) {
   1.449 -				SDL_memmove(&SDL_sensors[i], &SDL_sensors[i + 1], (SDL_num_sensors - i) * sizeof(SDL_sensors[i]));
   1.450 -			}
   1.451 -			break;
   1.452 -		}
   1.453 -	}
   1.454 -	SDL_UnlockSensors();
   1.455 +    SDL_LockSensors();
   1.456 +    for (i = 0; i < SDL_num_sensors; ++i) {
   1.457 +        old_sensor = &SDL_sensors[i];
   1.458 +        if (sensor == old_sensor->sensor) {
   1.459 +            ISensor_SetEventSink(sensor, NULL);
   1.460 +            ISensor_Release(sensor);
   1.461 +            SDL_free(old_sensor->name);
   1.462 +            --SDL_num_sensors;
   1.463 +            if (i < SDL_num_sensors) {
   1.464 +                SDL_memmove(&SDL_sensors[i], &SDL_sensors[i + 1], (SDL_num_sensors - i) * sizeof(SDL_sensors[i]));
   1.465 +            }
   1.466 +            break;
   1.467 +        }
   1.468 +    }
   1.469 +    SDL_UnlockSensors();
   1.470  
   1.471 -	return 0;
   1.472 +    return 0;
   1.473  }
   1.474  
   1.475  static int
   1.476  SDL_WINDOWS_SensorInit(void)
   1.477  {
   1.478 -	HRESULT hr;
   1.479 -	ISensorCollection *sensor_collection = NULL;
   1.480 +    HRESULT hr;
   1.481 +    ISensorCollection *sensor_collection = NULL;
   1.482  
   1.483 -	if (WIN_CoInitialize() == S_OK) {
   1.484 -		SDL_windowscoinit = SDL_TRUE;
   1.485 -	}
   1.486 +    if (WIN_CoInitialize() == S_OK) {
   1.487 +        SDL_windowscoinit = SDL_TRUE;
   1.488 +    }
   1.489  
   1.490 -	hr = CoCreateInstance(&CLSID_SensorManager, NULL, CLSCTX_INPROC_SERVER, &IID_SensorManager, &SDL_sensor_manager);
   1.491 -	if (FAILED(hr)) {
   1.492 -		return SDL_SetError("Couldn't create the sensor manager: 0x%.4x", hr);
   1.493 -	}
   1.494 +    hr = CoCreateInstance(&CLSID_SensorManager, NULL, CLSCTX_INPROC_SERVER, &IID_SensorManager, &SDL_sensor_manager);
   1.495 +    if (FAILED(hr)) {
   1.496 +        return SDL_SetError("Couldn't create the sensor manager: 0x%.4x", hr);
   1.497 +    }
   1.498  
   1.499 -	hr = ISensorManager_SetEventSink(SDL_sensor_manager, &sensor_manager_events);
   1.500 -	if (FAILED(hr)) {
   1.501 -		ISensorManager_Release(SDL_sensor_manager);
   1.502 -		return SDL_SetError("Couldn't set the sensor manager event sink: 0x%.4x", hr);
   1.503 -	}
   1.504 +    hr = ISensorManager_SetEventSink(SDL_sensor_manager, &sensor_manager_events);
   1.505 +    if (FAILED(hr)) {
   1.506 +        ISensorManager_Release(SDL_sensor_manager);
   1.507 +        return SDL_SetError("Couldn't set the sensor manager event sink: 0x%.4x", hr);
   1.508 +    }
   1.509  
   1.510 -	hr = ISensorManager_GetSensorsByCategory(SDL_sensor_manager, &SENSOR_CATEGORY_ALL, &sensor_collection);
   1.511 -	if (SUCCEEDED(hr)) {
   1.512 -		ULONG i, count;
   1.513 +    hr = ISensorManager_GetSensorsByCategory(SDL_sensor_manager, &SENSOR_CATEGORY_ALL, &sensor_collection);
   1.514 +    if (SUCCEEDED(hr)) {
   1.515 +        ULONG i, count;
   1.516  
   1.517 -		hr = ISensorCollection_GetCount(sensor_collection, &count);
   1.518 -		if (SUCCEEDED(hr)) {
   1.519 -			for (i = 0; i < count; ++i) {
   1.520 -				ISensor *sensor;
   1.521 +        hr = ISensorCollection_GetCount(sensor_collection, &count);
   1.522 +        if (SUCCEEDED(hr)) {
   1.523 +            for (i = 0; i < count; ++i) {
   1.524 +                ISensor *sensor;
   1.525  
   1.526 -				hr = ISensorCollection_GetAt(sensor_collection, i, &sensor);
   1.527 -				if (SUCCEEDED(hr)) {
   1.528 -					SensorState state;
   1.529 +                hr = ISensorCollection_GetAt(sensor_collection, i, &sensor);
   1.530 +                if (SUCCEEDED(hr)) {
   1.531 +                    SensorState state;
   1.532  
   1.533 -					hr = ISensor_GetState(sensor, &state);
   1.534 -					if (SUCCEEDED(hr)) {
   1.535 -						ISensorManagerEventsVtbl_OnSensorEnter(&sensor_manager_events, sensor, state);
   1.536 -					}
   1.537 -					ISensorManager_Release(sensor);
   1.538 -				}
   1.539 -			}
   1.540 -		}
   1.541 -		ISensorCollection_Release(sensor_collection);
   1.542 -	}
   1.543 +                    hr = ISensor_GetState(sensor, &state);
   1.544 +                    if (SUCCEEDED(hr)) {
   1.545 +                        ISensorManagerEventsVtbl_OnSensorEnter(&sensor_manager_events, sensor, state);
   1.546 +                    }
   1.547 +                    ISensorManager_Release(sensor);
   1.548 +                }
   1.549 +            }
   1.550 +        }
   1.551 +        ISensorCollection_Release(sensor_collection);
   1.552 +    }
   1.553      return 0;
   1.554  }
   1.555  
   1.556 @@ -403,7 +405,7 @@
   1.557  static SDL_SensorType
   1.558  SDL_WINDOWS_SensorGetDeviceType(int device_index)
   1.559  {
   1.560 -	return SDL_sensors[device_index].type;
   1.561 +    return SDL_sensors[device_index].type;
   1.562  }
   1.563  
   1.564  static int
   1.565 @@ -421,7 +423,7 @@
   1.566  static int
   1.567  SDL_WINDOWS_SensorOpen(SDL_Sensor *sensor, int device_index)
   1.568  {
   1.569 -	SDL_sensors[device_index].sensor_opened = sensor;
   1.570 +    SDL_sensors[device_index].sensor_opened = sensor;
   1.571      return 0;
   1.572  }
   1.573  
   1.574 @@ -433,32 +435,32 @@
   1.575  static void
   1.576  SDL_WINDOWS_SensorClose(SDL_Sensor *sensor)
   1.577  {
   1.578 -	int i;
   1.579 +    int i;
   1.580  
   1.581 -	for (i = 0; i < SDL_num_sensors; ++i) {
   1.582 -		if (sensor == SDL_sensors[i].sensor_opened) {
   1.583 -			SDL_sensors[i].sensor_opened = NULL;
   1.584 -			break;
   1.585 -		}
   1.586 -	}
   1.587 +    for (i = 0; i < SDL_num_sensors; ++i) {
   1.588 +        if (sensor == SDL_sensors[i].sensor_opened) {
   1.589 +            SDL_sensors[i].sensor_opened = NULL;
   1.590 +            break;
   1.591 +        }
   1.592 +    }
   1.593  }
   1.594  
   1.595  static void
   1.596  SDL_WINDOWS_SensorQuit(void)
   1.597  {
   1.598 -	while (SDL_num_sensors > 0) {
   1.599 -		DisconnectSensor(SDL_sensors[0].sensor);
   1.600 -	}
   1.601 +    while (SDL_num_sensors > 0) {
   1.602 +        DisconnectSensor(SDL_sensors[0].sensor);
   1.603 +    }
   1.604  
   1.605 -	if (SDL_sensor_manager) {
   1.606 -		ISensorManager_SetEventSink(SDL_sensor_manager, NULL);
   1.607 -		ISensorManager_Release(SDL_sensor_manager);
   1.608 -		SDL_sensor_manager = NULL;
   1.609 -	}
   1.610 +    if (SDL_sensor_manager) {
   1.611 +        ISensorManager_SetEventSink(SDL_sensor_manager, NULL);
   1.612 +        ISensorManager_Release(SDL_sensor_manager);
   1.613 +        SDL_sensor_manager = NULL;
   1.614 +    }
   1.615  
   1.616 -	if (SDL_windowscoinit) {
   1.617 -		WIN_CoUninitialize();
   1.618 -	}
   1.619 +    if (SDL_windowscoinit) {
   1.620 +        WIN_CoUninitialize();
   1.621 +    }
   1.622  }
   1.623  
   1.624  SDL_SensorDriver SDL_WINDOWS_SensorDriver =