The timestamp_us member of the sensor events has been renamed sensor_timestamp and now represents nanoseconds.

This commit is contained in:
Sam Lantinga 2022-12-04 08:31:19 -08:00
parent 73f4aeee6a
commit b8760a3ffe
26 changed files with 134 additions and 128 deletions

View file

@ -143,6 +143,7 @@ static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnStateChanged(ISensorEvents
static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents *This, ISensor *pSensor, ISensorDataReport *pNewData)
{
int i;
Uint64 timestamp = SDL_GetTicks();
SDL_LockSensors();
for (i = 0; i < SDL_num_sensors; ++i) {
@ -150,10 +151,23 @@ static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents *
if (SDL_sensors[i].sensor_opened) {
HRESULT hrX, hrY, hrZ;
PROPVARIANT valueX, valueY, valueZ;
SYSTEMTIME sensor_systemtime;
FILETIME sensor_filetime;
Uint64 sensor_timestamp;
#ifdef DEBUG_SENSORS
SDL_Log("Sensor %s data updated\n", SDL_sensors[i].name);
#endif
if (SUCCEEDED(ISensorDataReport_GetTimestamp(pNewData, &sensor_systemtime)) &&
SystemTimeToFileTime(&sensor_systemtime, &sensor_filetime)) {
ULARGE_INTEGER sensor_time;
sensor_time.u.HighPart = sensor_filetime.dwHighDateTime;
sensor_time.u.LowPart = sensor_filetime.dwLowDateTime;
sensor_timestamp = sensor_time.QuadPart * 100;
} else {
sensor_timestamp = timestamp;
}
switch (SDL_sensors[i].type) {
case SDL_SENSOR_ACCEL:
hrX = ISensorDataReport_GetSensorValue(pNewData, &SENSOR_DATA_TYPE_ACCELERATION_X_G, &valueX);
@ -166,7 +180,7 @@ static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents *
values[0] = (float)valueX.dblVal * SDL_STANDARD_GRAVITY;
values[1] = (float)valueY.dblVal * SDL_STANDARD_GRAVITY;
values[2] = (float)valueZ.dblVal * SDL_STANDARD_GRAVITY;
SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, 0, values, 3);
SDL_PrivateSensorUpdate(timestamp, SDL_sensors[i].sensor_opened, sensor_timestamp, values, 3);
}
break;
case SDL_SENSOR_GYRO:
@ -181,7 +195,7 @@ static HRESULT STDMETHODCALLTYPE ISensorEventsVtbl_OnDataUpdated(ISensorEvents *
values[0] = (float)valueX.dblVal * DEGREES_TO_RADIANS;
values[1] = (float)valueY.dblVal * DEGREES_TO_RADIANS;
values[2] = (float)valueZ.dblVal * DEGREES_TO_RADIANS;
SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, 0, values, 3);
SDL_PrivateSensorUpdate(timestamp, SDL_sensors[i].sensor_opened, sensor_timestamp, values, 3);
}
break;
default: