Added microsecond timestamp to sensor values for PS4 and PS5 controllers using the HIDAPI driver
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811
diff --git a/include/SDL_events.h b/include/SDL_events.h
index 1836fc0..240a8a8 100644
--- a/include/SDL_events.h
+++ b/include/SDL_events.h
@@ -474,6 +474,7 @@ typedef struct SDL_ControllerSensorEvent
SDL_JoystickID which; /**< The joystick instance id */
Sint32 sensor; /**< The type of the sensor, one of the values of ::SDL_SensorType */
float data[3]; /**< Up to 3 values from the sensor, as defined in SDL_sensor.h */
+ Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */
} SDL_ControllerSensorEvent;
/**
@@ -565,6 +566,7 @@ typedef struct SDL_SensorEvent
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
Sint32 which; /**< The instance ID of the sensor */
float data[6]; /**< Up to 6 values from the sensor - additional values can be queried using SDL_SensorGetData() */
+ Uint64 timestamp_us; /**< The timestamp of the sensor reading in microseconds, if the hardware provides this information. */
} SDL_SensorEvent;
/**
diff --git a/include/SDL_gamecontroller.h b/include/SDL_gamecontroller.h
index ace1c16..e32d3e8 100644
--- a/include/SDL_gamecontroller.h
+++ b/include/SDL_gamecontroller.h
@@ -896,6 +896,23 @@ extern DECLSPEC float SDLCALL SDL_GameControllerGetSensorDataRate(SDL_GameContro
extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values);
/**
+ * Get the current state of a game controller sensor with the timestamp of the last update.
+ *
+ * The number of values and interpretation of the data is sensor dependent.
+ * See SDL_sensor.h for the details for each type of sensor.
+ *
+ * \param gamecontroller The controller to query
+ * \param type The type of sensor to query
+ * \param timestamp A pointer filled with the timestamp in microseconds of the current sensor reading if available, or 0 if not
+ * \param data A pointer filled with the current sensor state
+ * \param num_values The number of values to write to data
+ * \return 0 or -1 if an error occurred.
+ *
+ * \since This function is available since SDL 2.26.0.
+ */
+extern DECLSPEC int SDLCALL SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_SensorType type, Uint64 *timestamp, float *data, int num_values);
+
+/**
* Start a rumble effect on a game controller.
*
* Each call to this function cancels any previous rumble effect, and calling
diff --git a/include/SDL_sensor.h b/include/SDL_sensor.h
index 6b07183..823cbbb 100644
--- a/include/SDL_sensor.h
+++ b/include/SDL_sensor.h
@@ -267,7 +267,22 @@ extern DECLSPEC SDL_SensorID SDLCALL SDL_SensorGetInstanceID(SDL_Sensor *sensor)
*
* \since This function is available since SDL 2.0.9.
*/
-extern DECLSPEC int SDLCALL SDL_SensorGetData(SDL_Sensor * sensor, float *data, int num_values);
+extern DECLSPEC int SDLCALL SDL_SensorGetData(SDL_Sensor *sensor, float *data, int num_values);
+
+/**
+ * Get the current state of an opened sensor with the timestamp of the last update.
+ *
+ * The number of values and interpretation of the data is sensor dependent.
+ *
+ * \param sensor The SDL_Sensor object to query
+ * \param timestamp A pointer filled with the timestamp in microseconds of the current sensor reading if available, or 0 if not
+ * \param data A pointer filled with the current sensor state
+ * \param num_values The number of values to write to data
+ * \returns 0 or -1 if an error occurred.
+ *
+ * \since This function is available since SDL 2.0.9.
+ */
+extern DECLSPEC int SDLCALL SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, float *data, int num_values);
/**
* Close a sensor previously opened with SDL_SensorOpen().
@@ -276,7 +291,7 @@ extern DECLSPEC int SDLCALL SDL_SensorGetData(SDL_Sensor * sensor, float *data,
*
* \since This function is available since SDL 2.0.9.
*/
-extern DECLSPEC void SDLCALL SDL_SensorClose(SDL_Sensor * sensor);
+extern DECLSPEC void SDLCALL SDL_SensorClose(SDL_Sensor *sensor);
/**
* Update the current state of the open sensors.
diff --git a/src/dynapi/SDL2.exports b/src/dynapi/SDL2.exports
index d9e3545..c2e903e 100644
--- a/src/dynapi/SDL2.exports
+++ b/src/dynapi/SDL2.exports
@@ -863,3 +863,5 @@
++'_SDL_SetPrimarySelectionText'.'SDL2.dll'.'SDL_SetPrimarySelectionText'
++'_SDL_GetPrimarySelectionText'.'SDL2.dll'.'SDL_GetPrimarySelectionText'
++'_SDL_HasPrimarySelectionText'.'SDL2.dll'.'SDL_HasPrimarySelectionText'
+++'_SDL_GameControllerGetSensorDataWithTimestamp'.'SDL2.dll'.'SDL_GameControllerGetSensorDataWithTimestamp'
+++'_SDL_SensorGetDataWithTimestamp'.'SDL2.dll'.'SDL_SensorGetDataWithTimestamp'
diff --git a/src/dynapi/SDL_dynapi_overrides.h b/src/dynapi/SDL_dynapi_overrides.h
index 2e982b8..fc9255c 100644
--- a/src/dynapi/SDL_dynapi_overrides.h
+++ b/src/dynapi/SDL_dynapi_overrides.h
@@ -889,3 +889,5 @@
#define SDL_SetPrimarySelectionText SDL_SetPrimarySelectionText_REAL
#define SDL_GetPrimarySelectionText SDL_GetPrimarySelectionText_REAL
#define SDL_HasPrimarySelectionText SDL_HasPrimarySelectionText_REAL
+#define SDL_GameControllerGetSensorDataWithTimestamp SDL_GameControllerGetSensorDataWithTimestamp_REAL
+#define SDL_SensorGetDataWithTimestamp SDL_SensorGetDataWithTimestamp_REAL
diff --git a/src/dynapi/SDL_dynapi_procs.h b/src/dynapi/SDL_dynapi_procs.h
index b40efff..f8d858d 100644
--- a/src/dynapi/SDL_dynapi_procs.h
+++ b/src/dynapi/SDL_dynapi_procs.h
@@ -972,3 +972,5 @@ SDL_DYNAPI_PROC(void,SDL_GetJoystickGUIDInfo,(SDL_JoystickGUID a, Uint16 *b, Uin
SDL_DYNAPI_PROC(int,SDL_SetPrimarySelectionText,(const char *a),(a),return)
SDL_DYNAPI_PROC(char*,SDL_GetPrimarySelectionText,(void),(),return)
SDL_DYNAPI_PROC(SDL_bool,SDL_HasPrimarySelectionText,(void),(),return)
+SDL_DYNAPI_PROC(int,SDL_GameControllerGetSensorDataWithTimestamp,(SDL_GameController *a, SDL_SensorType b, Uint64 *c, float *d, int e),(a,b,c,d,e),return)
+SDL_DYNAPI_PROC(int,SDL_SensorGetDataWithTimestamp,(SDL_Sensor *a, Uint64 *b, float *c, int d),(a,b,c,d),return)
diff --git a/src/joystick/SDL_gamecontroller.c b/src/joystick/SDL_gamecontroller.c
index 204ae96..b764980 100644
--- a/src/joystick/SDL_gamecontroller.c
+++ b/src/joystick/SDL_gamecontroller.c
@@ -2441,6 +2441,15 @@ SDL_GameControllerGetSensorDataRate(SDL_GameController *gamecontroller, SDL_Sens
int
SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorType type, float *data, int num_values)
{
+ return SDL_GameControllerGetSensorDataWithTimestamp(gamecontroller, type, NULL, data, num_values);
+}
+
+/*
+ * Get the current state of a game controller sensor.
+ */
+int
+SDL_GameControllerGetSensorDataWithTimestamp(SDL_GameController *gamecontroller, SDL_SensorType type, Uint64 *timestamp, float *data, int num_values)
+{
SDL_Joystick *joystick = SDL_GameControllerGetJoystick(gamecontroller);
int i;
@@ -2454,6 +2463,9 @@ SDL_GameControllerGetSensorData(SDL_GameController *gamecontroller, SDL_SensorTy
if (sensor->type == type) {
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(data, sensor->data, num_values*sizeof(*data));
+ if (timestamp) {
+ *timestamp = sensor->timestamp_us;
+ }
return 0;
}
}
diff --git a/src/joystick/SDL_joystick.c b/src/joystick/SDL_joystick.c
index dc89026..a42951c 100644
--- a/src/joystick/SDL_joystick.c
+++ b/src/joystick/SDL_joystick.c
@@ -2983,7 +2983,7 @@ int SDL_PrivateJoystickTouchpad(SDL_Joystick *joystick, int touchpad, int finger
return posted;
}
-int SDL_PrivateJoystickSensor(SDL_Joystick *joystick, SDL_SensorType type, const float *data, int num_values)
+int SDL_PrivateJoystickSensor(SDL_Joystick *joystick, SDL_SensorType type, Uint64 timestamp_us, const float *data, int num_values)
{
int i;
int posted = 0;
@@ -3004,6 +3004,7 @@ int SDL_PrivateJoystickSensor(SDL_Joystick *joystick, SDL_SensorType type, const
/* Update internal sensor state */
SDL_memcpy(sensor->data, data, num_values*sizeof(*data));
+ sensor->timestamp_us = timestamp_us;
/* Post the event, if desired */
#if !SDL_EVENTS_DISABLED
@@ -3015,6 +3016,7 @@ int SDL_PrivateJoystickSensor(SDL_Joystick *joystick, SDL_SensorType type, const
num_values = SDL_min(num_values, SDL_arraysize(event.csensor.data));
SDL_memset(event.csensor.data, 0, sizeof(event.csensor.data));
SDL_memcpy(event.csensor.data, data, num_values*sizeof(*data));
+ event.csensor.timestamp_us = timestamp_us;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
diff --git a/src/joystick/SDL_joystick_c.h b/src/joystick/SDL_joystick_c.h
index 82311a0..7ed3e63 100644
--- a/src/joystick/SDL_joystick_c.h
+++ b/src/joystick/SDL_joystick_c.h
@@ -160,7 +160,7 @@ extern int SDL_PrivateJoystickButton(SDL_Joystick *joystick,
extern int SDL_PrivateJoystickTouchpad(SDL_Joystick *joystick,
int touchpad, int finger, Uint8 state, float x, float y, float pressure);
extern int SDL_PrivateJoystickSensor(SDL_Joystick *joystick,
- SDL_SensorType type, const float *data, int num_values);
+ SDL_SensorType type, Uint64 timestamp_us, const float *data, int num_values);
extern void SDL_PrivateJoystickBatteryLevel(SDL_Joystick *joystick,
SDL_JoystickPowerLevel ePowerLevel);
diff --git a/src/joystick/SDL_sysjoystick.h b/src/joystick/SDL_sysjoystick.h
index 34a1742..a0400c6 100644
--- a/src/joystick/SDL_sysjoystick.h
+++ b/src/joystick/SDL_sysjoystick.h
@@ -64,6 +64,7 @@ typedef struct _SDL_JoystickSensorInfo
SDL_bool enabled;
float rate;
float data[3]; /* If this needs to expand, update SDL_ControllerSensorEvent */
+ Uint64 timestamp_us;
} SDL_JoystickSensorInfo;
struct _SDL_Joystick
diff --git a/src/joystick/hidapi/SDL_hidapi_ps3.c b/src/joystick/hidapi/SDL_hidapi_ps3.c
index a90d4a3..49913d9 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps3.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps3.c
@@ -487,7 +487,7 @@ HIDAPI_DriverPS3_HandleStatePacket(SDL_Joystick *joystick, SDL_DriverPS3_Context
sensor_data[0] = HIDAPI_DriverPS3_ScaleAccel(LOAD16(data[41], data[42]));
sensor_data[1] = -HIDAPI_DriverPS3_ScaleAccel(LOAD16(data[45], data[46]));
sensor_data[2] = -HIDAPI_DriverPS3_ScaleAccel(LOAD16(data[43], data[44]));
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, sensor_data, SDL_arraysize(sensor_data));
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, 0, sensor_data, SDL_arraysize(sensor_data));
}
SDL_memcpy(ctx->last_state, data, SDL_min(size, sizeof(ctx->last_state)));
diff --git a/src/joystick/hidapi/SDL_hidapi_ps4.c b/src/joystick/hidapi/SDL_hidapi_ps4.c
index 6b4fee3..40884da 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps4.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps4.c
@@ -84,23 +84,24 @@ typedef struct
Uint8 ucLeftJoystickY;
Uint8 ucRightJoystickX;
Uint8 ucRightJoystickY;
- Uint8 rgucButtonsHatAndCounter[ 3 ];
+ Uint8 rgucButtonsHatAndCounter[3];
Uint8 ucTriggerLeft;
Uint8 ucTriggerRight;
- Uint8 _rgucPad0[ 3 ];
+ Uint8 rgucTimestamp[2];
+ Uint8 _rgucPad0[1];
Uint8 rgucGyroX[2];
Uint8 rgucGyroY[2];
Uint8 rgucGyroZ[2];
Uint8 rgucAccelX[2];
Uint8 rgucAccelY[2];
Uint8 rgucAccelZ[2];
- Uint8 _rgucPad1[ 5 ];
+ Uint8 _rgucPad1[5];
Uint8 ucBatteryLevel;
- Uint8 _rgucPad2[ 4 ];
+ Uint8 _rgucPad2[4];
Uint8 ucTouchpadCounter1;
- Uint8 rgucTouchpadData1[ 3 ];
+ Uint8 rgucTouchpadData1[3];
Uint8 ucTouchpadCounter2;
- Uint8 rgucTouchpadData2[ 3 ];
+ Uint8 rgucTouchpadData2[3];
} PS4StatePacket_t;
typedef struct
@@ -147,6 +148,8 @@ typedef struct {
Uint8 led_red;
Uint8 led_green;
Uint8 led_blue;
+ Uint16 last_timestamp;
+ Uint64 timestamp;
PS4StatePacket_t last_state;
} SDL_DriverPS4_Context;
@@ -807,6 +810,7 @@ HIDAPI_DriverPS4_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
HIDAPI_DriverPS4_LoadCalibrationData(device);
}
ctx->report_sensors = enabled;
+ ctx->timestamp = 0;
return 0;
}
@@ -944,17 +948,38 @@ HIDAPI_DriverPS4_HandleStatePacket(SDL_Joystick *joystick, SDL_hid_device *dev,
}
if (ctx->report_sensors) {
+ Uint16 timestamp;
+ Uint64 timestamp_us;
float data[3];
+ timestamp = LOAD16(packet->rgucTimestamp[0], packet->rgucTimestamp[1]);
+ if (ctx->timestamp) {
+ Uint16 delta;
+
+ if (ctx->last_timestamp > timestamp) {
+ delta = (SDL_MAX_UINT16 - ctx->last_timestamp + timestamp + 1);
+ } else {
+ delta = (timestamp - ctx->last_timestamp);
+ }
+ ctx->timestamp += delta;
+ } else {
+ ctx->timestamp = timestamp;
+ }
+ ctx->last_timestamp = timestamp;
+
+ /* Sensor timestamp is in 5.33us units */
+ timestamp_us = (ctx->timestamp * 16) / 3;
+
+
data[0] = HIDAPI_DriverPS4_ApplyCalibrationData(ctx, 0, LOAD16(packet->rgucGyroX[0], packet->rgucGyroX[1]));
data[1] = HIDAPI_DriverPS4_ApplyCalibrationData(ctx, 1, LOAD16(packet->rgucGyroY[0], packet->rgucGyroY[1]));
data[2] = HIDAPI_DriverPS4_ApplyCalibrationData(ctx, 2, LOAD16(packet->rgucGyroZ[0], packet->rgucGyroZ[1]));
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, data, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, timestamp_us, data, 3);
data[0] = HIDAPI_DriverPS4_ApplyCalibrationData(ctx, 3, LOAD16(packet->rgucAccelX[0], packet->rgucAccelX[1]));
data[1] = HIDAPI_DriverPS4_ApplyCalibrationData(ctx, 4, LOAD16(packet->rgucAccelY[0], packet->rgucAccelY[1]));
data[2] = HIDAPI_DriverPS4_ApplyCalibrationData(ctx, 5, LOAD16(packet->rgucAccelZ[0], packet->rgucAccelZ[1]));
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, data, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, timestamp_us, data, 3);
}
SDL_memcpy(&ctx->last_state, packet, sizeof(ctx->last_state));
diff --git a/src/joystick/hidapi/SDL_hidapi_ps5.c b/src/joystick/hidapi/SDL_hidapi_ps5.c
index 3892764..0e41d2e 100644
--- a/src/joystick/hidapi/SDL_hidapi_ps5.c
+++ b/src/joystick/hidapi/SDL_hidapi_ps5.c
@@ -94,6 +94,7 @@ typedef struct
Uint8 rgucAccelX[2]; /* 21 */
Uint8 rgucAccelY[2]; /* 23 */
Uint8 rgucAccelZ[2]; /* 25 */
+ Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
} PS5StatePacketCommon_t;
@@ -114,8 +115,8 @@ typedef struct
Uint8 rgucAccelX[2]; /* 21 */
Uint8 rgucAccelY[2]; /* 23 */
Uint8 rgucAccelZ[2]; /* 25 */
- Uint8 rgucTimer1[4]; /* 27 - 32 bit little endian */
- Uint8 ucBatteryTemp; /* 31 */
+ Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
+ Uint8 ucSensorTemp; /* 31 */
Uint8 ucTouchpadCounter1; /* 32 - high bit clear + counter */
Uint8 rgucTouchpadData1[3]; /* 33 - X/Y, 12 bits per axis */
Uint8 ucTouchpadCounter2; /* 36 - high bit clear + counter */
@@ -145,7 +146,7 @@ typedef struct
Uint8 rgucAccelX[2]; /* 21 */
Uint8 rgucAccelY[2]; /* 23 */
Uint8 rgucAccelZ[2]; /* 25 */
- Uint8 rgucUnknown1[4]; /* 27 */
+ Uint8 rgucSensorTimestamp[4]; /* 27 - 32 bit little endian */
Uint8 ucTouchpadCounter1; /* 31 - high bit clear + counter */
Uint8 rgucTouchpadData1[3]; /* 32 - X/Y, 12 bits per axis */
Uint8 ucTouchpadCounter2; /* 35 - high bit clear + counter */
@@ -225,6 +226,8 @@ typedef struct {
Uint8 led_green;
Uint8 led_blue;
EDS5LEDResetState led_reset_state;
+ Uint32 last_timestamp;
+ Uint64 timestamp;
union
{
PS5SimpleStatePacket_t simple;
@@ -706,21 +709,21 @@ HIDAPI_DriverPS5_CheckPendingLEDReset(SDL_HIDAPI_Device *device)
SDL_DriverPS5_Context *ctx = (SDL_DriverPS5_Context *)device->context;
SDL_bool led_reset_complete = SDL_FALSE;
- if (ctx->use_alternate_report) {
- /* We don't know how to check the timer, just assume it's complete for now */
- led_reset_complete = SDL_TRUE;
- } else {
- const PS5StatePacket_t *packet = &ctx->last_state.full_state;
+ if (ctx->sensors_supported) {
+ const PS5StatePacketCommon_t *packet = &ctx->last_state.state;
/* Check the timer to make sure the Bluetooth connection LED animation is complete */
const Uint32 connection_complete = 10200000;
- Uint32 timer = ((Uint32)packet->rgucTimer1[0] << 0) |
- ((Uint32)packet->rgucTimer1[1] << 8) |
- ((Uint32)packet->rgucTimer1[2] << 16) |
- ((Uint32)packet->rgucTimer1[3] << 24);
- if (SDL_TICKS_PASSED(timer, connection_complete)) {
+ Uint32 timestamp = LOAD32(packet->rgucSensorTimestamp[0],
+ packet->rgucSensorTimestamp[1],
+ packet->rgucSensorTimestamp[2],
+ packet->rgucSensorTimestamp[3]);
+ if (SDL_TICKS_PASSED(timestamp, connection_complete)) {
led_reset_complete = SDL_TRUE;
}
+ } else {
+ /* We don't know how to check the timer, just assume it's complete for now */
+ led_reset_complete = SDL_TRUE;
}
if (led_reset_complete) {
@@ -759,8 +762,14 @@ HIDAPI_DriverPS5_SetEnhancedMode(SDL_HIDAPI_Device *device, SDL_Joystick *joysti
ctx->report_touchpad = SDL_TRUE;
}
if (ctx->sensors_supported) {
- SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
- SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
+ if (device->is_bluetooth) {
+ /* Bluetooth sensor update rate appears to be 1000 Hz */
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 1000.0f);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 1000.0f);
+ } else {
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_GYRO, 250.0f);
+ SDL_PrivateJoystickAddSensor(joystick, SDL_SENSOR_ACCEL, 250.0f);
+ }
}
/* Switch into enhanced report mode */
@@ -989,6 +998,7 @@ HIDAPI_DriverPS5_SetJoystickSensorsEnabled(SDL_HIDAPI_Device *device, SDL_Joysti
HIDAPI_DriverPS5_LoadCalibrationData(device);
}
ctx->report_sensors = enabled;
+ ctx->timestamp = 0;
return 0;
}
@@ -1180,17 +1190,40 @@ HIDAPI_DriverPS5_HandleStatePacketCommon(SDL_Joystick *joystick, SDL_hid_device
SDL_PrivateJoystickAxis(joystick, SDL_CONTROLLER_AXIS_RIGHTY, axis);
if (ctx->report_sensors) {
+ Uint32 timestamp;
+ Uint64 timestamp_us;
float data[3];
+ timestamp = LOAD32(packet->rgucSensorTimestamp[0],
+ packet->rgucSensorTimestamp[1],
+ packet->rgucSensorTimestamp[2],
+ packet->rgucSensorTimestamp[3]);
+ if (ctx->timestamp) {
+ Uint32 delta;
+
+ if (ctx->last_timestamp > timestamp) {
+ delta = (SDL_MAX_UINT32 - ctx->last_timestamp + timestamp + 1);
+ } else {
+ delta = (timestamp - ctx->last_timestamp);
+ }
+ ctx->timestamp += delta;
+ } else {
+ ctx->timestamp = timestamp;
+ }
+ ctx->last_timestamp = timestamp;
+
+ /* Sensor timestamp is in 0.33us units */
+ timestamp_us = ctx->timestamp / 3;
+
data[0] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 0, LOAD16(packet->rgucGyroX[0], packet->rgucGyroX[1]));
data[1] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 1, LOAD16(packet->rgucGyroY[0], packet->rgucGyroY[1]));
data[2] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 2, LOAD16(packet->rgucGyroZ[0], packet->rgucGyroZ[1]));
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, data, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, timestamp_us, data, 3);
data[0] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 3, LOAD16(packet->rgucAccelX[0], packet->rgucAccelX[1]));
data[1] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 4, LOAD16(packet->rgucAccelY[0], packet->rgucAccelY[1]));
data[2] = HIDAPI_DriverPS5_ApplyCalibrationData(ctx, 5, LOAD16(packet->rgucAccelZ[0], packet->rgucAccelZ[1]));
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, data, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, timestamp_us, data, 3);
}
}
diff --git a/src/joystick/hidapi/SDL_hidapi_steam.c b/src/joystick/hidapi/SDL_hidapi_steam.c
index 6df6512..9f4bb72 100644
--- a/src/joystick/hidapi/SDL_hidapi_steam.c
+++ b/src/joystick/hidapi/SDL_hidapi_steam.c
@@ -1241,12 +1241,12 @@ HIDAPI_DriverSteam_UpdateDevice(SDL_HIDAPI_Device *device)
values[0] = (ctx->m_state.sGyroX / 32768.0f) * (2000.0f * (M_PI / 180.0f));
values[1] = (ctx->m_state.sGyroZ / 32768.0f) * (2000.0f * (M_PI / 180.0f));
values[2] = (ctx->m_state.sGyroY / 32768.0f) * (2000.0f * (M_PI / 180.0f));
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, values, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, 0, values, 3);
values[0] = (ctx->m_state.sAccelX / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
values[1] = (ctx->m_state.sAccelZ / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
values[2] = (-ctx->m_state.sAccelY / 32768.0f) * 2.0f * SDL_STANDARD_GRAVITY;
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, values, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, 0, values, 3);
}
ctx->m_last_state = ctx->m_state;
diff --git a/src/joystick/hidapi/SDL_hidapi_switch.c b/src/joystick/hidapi/SDL_hidapi_switch.c
index 8a7c9f0..55641d7 100644
--- a/src/joystick/hidapi/SDL_hidapi_switch.c
+++ b/src/joystick/hidapi/SDL_hidapi_switch.c
@@ -1797,7 +1797,7 @@ static void SendSensorUpdate(SDL_Joystick *joystick, SDL_DriverSwitch_Context *c
data[0] = -tmp;
}
- SDL_PrivateJoystickSensor(joystick, type, data, 3);
+ SDL_PrivateJoystickSensor(joystick, type, 0, data, 3);
}
static void HandleCombinedControllerStateL(SDL_Joystick *joystick, SDL_DriverSwitch_Context *ctx, SwitchStatePacket_t *packet)
diff --git a/src/joystick/hidapi/SDL_hidapi_wii.c b/src/joystick/hidapi/SDL_hidapi_wii.c
index fbf8a83..3f40fcc 100644
--- a/src/joystick/hidapi/SDL_hidapi_wii.c
+++ b/src/joystick/hidapi/SDL_hidapi_wii.c
@@ -1151,7 +1151,7 @@ static void HandleNunchuckButtonData(SDL_DriverWii_Context *ctx, SDL_Joystick *j
values[0] = -((float)x / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
values[1] = ((float)z / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
values[2] = ((float)y / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL_L, values, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL_L, 0, values, 3);
}
}
@@ -1191,7 +1191,7 @@ static void HandleMotionPlusData(SDL_DriverWii_Context *ctx, SDL_Joystick *joyst
values[0] = -((float)z / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
values[1] = ((float)x / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
values[2] = ((float)y / GYRO_RES_PER_DEGREE) * (float)M_PI / 180.0f;
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, values, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, 0, values, 3);
}
}
@@ -1212,7 +1212,7 @@ static void HandleWiiRemoteAccelData(SDL_DriverWii_Context *ctx, SDL_Joystick *j
values[0] = -((float)x / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
values[1] = ((float)z / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
values[2] = ((float)y / ACCEL_RES_PER_G) * SDL_STANDARD_GRAVITY;
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, values, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, 0, values, 3);
}
static void HandleButtonData(SDL_DriverWii_Context *ctx, SDL_Joystick *joystick, WiiButtonData *data)
diff --git a/src/joystick/iphoneos/SDL_mfijoystick.m b/src/joystick/iphoneos/SDL_mfijoystick.m
index dbd1d8c..72f2ffb 100644
--- a/src/joystick/iphoneos/SDL_mfijoystick.m
+++ b/src/joystick/iphoneos/SDL_mfijoystick.m
@@ -1064,14 +1064,14 @@ IOS_MFIJoystickUpdate(SDL_Joystick *joystick)
data[0] = rate.x;
data[1] = rate.z;
data[2] = -rate.y;
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, data, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_GYRO, 0, data, 3);
}
if (motion.hasGravityAndUserAcceleration) {
GCAcceleration accel = motion.acceleration;
data[0] = -accel.x * SDL_STANDARD_GRAVITY;
data[1] = -accel.y * SDL_STANDARD_GRAVITY;
data[2] = -accel.z * SDL_STANDARD_GRAVITY;
- SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, data, 3);
+ SDL_PrivateJoystickSensor(joystick, SDL_SENSOR_ACCEL, 0, data, 3);
}
}
}
diff --git a/src/sensor/SDL_sensor.c b/src/sensor/SDL_sensor.c
index 161026b..ba86528 100644
--- a/src/sensor/SDL_sensor.c
+++ b/src/sensor/SDL_sensor.c
@@ -307,7 +307,7 @@ SDL_SensorFromInstanceID(SDL_SensorID instance_id)
* Checks to make sure the sensor is valid.
*/
static int
-SDL_PrivateSensorValid(SDL_Sensor * sensor)
+SDL_PrivateSensorValid(SDL_Sensor *sensor)
{
int valid;
@@ -325,7 +325,7 @@ SDL_PrivateSensorValid(SDL_Sensor * sensor)
* Get the friendly name of this sensor
*/
const char *
-SDL_SensorGetName(SDL_Sensor * sensor)
+SDL_SensorGetName(SDL_Sensor *sensor)
{
if (!SDL_PrivateSensorValid(sensor)) {
return NULL;
@@ -338,7 +338,7 @@ SDL_SensorGetName(SDL_Sensor * sensor)
* Get the type of this sensor
*/
SDL_SensorType
-SDL_SensorGetType(SDL_Sensor * sensor)
+SDL_SensorGetType(SDL_Sensor *sensor)
{
if (!SDL_PrivateSensorValid(sensor)) {
return SDL_SENSOR_INVALID;
@@ -351,7 +351,7 @@ SDL_SensorGetType(SDL_Sensor * sensor)
* Get the platform dependent type of this sensor
*/
int
-SDL_SensorGetNonPortableType(SDL_Sensor * sensor)
+SDL_SensorGetNonPortableType(SDL_Sensor *sensor)
{
if (!SDL_PrivateSensorValid(sensor)) {
return -1;
@@ -364,7 +364,7 @@ SDL_SensorGetNonPortableType(SDL_Sensor * sensor)
* Get the instance id for this opened sensor
*/
SDL_SensorID
-SDL_SensorGetInstanceID(SDL_Sensor * sensor)
+SDL_SensorGetInstanceID(SDL_Sensor *sensor)
{
if (!SDL_PrivateSensorValid(sensor)) {
return -1;
@@ -377,7 +377,16 @@ SDL_SensorGetInstanceID(SDL_Sensor * sensor)
* Get the current state of this sensor
*/
int
-SDL_SensorGetData(SDL_Sensor * sensor, float *data, int num_values)
+SDL_SensorGetData(SDL_Sensor *sensor, float *data, int num_values)
+{
+ return SDL_SensorGetDataWithTimestamp(sensor, NULL, data, num_values);
+}
+
+/*
+ * Get the current state of this sensor
+ */
+int
+SDL_SensorGetDataWithTimestamp(SDL_Sensor *sensor, Uint64 *timestamp, float *data, int num_values)
{
if (!SDL_PrivateSensorValid(sensor)) {
return -1;
@@ -385,6 +394,9 @@ SDL_SensorGetData(SDL_Sensor * sensor, float *data, int num_values)
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(data, sensor->data, num_values*sizeof(*data));
+ if (timestamp) {
+ *timestamp = sensor->timestamp_us;
+ }
return 0;
}
@@ -392,7 +404,7 @@ SDL_SensorGetData(SDL_Sensor * sensor, float *data, int num_values)
* Close a sensor previously opened with SDL_SensorOpen()
*/
void
-SDL_SensorClose(SDL_Sensor * sensor)
+SDL_SensorClose(SDL_Sensor *sensor)
{
SDL_Sensor *sensorlist;
SDL_Sensor *sensorlistprev;
@@ -478,7 +490,7 @@ SDL_SensorQuit(void)
/* These are global for SDL_syssensor.c and SDL_events.c */
int
-SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values)
+SDL_PrivateSensorUpdate(SDL_Sensor *sensor, Uint64 timestamp_us, float *data, int num_values)
{
int posted;
@@ -487,6 +499,7 @@ SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values)
/* Update internal sensor state */
num_values = SDL_min(num_values, SDL_arraysize(sensor->data));
SDL_memcpy(sensor->data, data, num_values*sizeof(*data));
+ sensor->timestamp_us = timestamp_us;
/* Post the event, if desired */
posted = 0;
@@ -498,6 +511,7 @@ SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values)
num_values = SDL_min(num_values, SDL_arraysize(event.sensor.data));
SDL_memset(event.sensor.data, 0, sizeof(event.sensor.data));
SDL_memcpy(event.sensor.data, data, num_values*sizeof(*data));
+ event.sensor.timestamp_us = timestamp_us;
posted = SDL_PushEvent(&event) == 1;
}
#endif /* !SDL_EVENTS_DISABLED */
diff --git a/src/sensor/SDL_sensor_c.h b/src/sensor/SDL_sensor_c.h
index f116a06..92b93fe 100644
--- a/src/sensor/SDL_sensor_c.h
+++ b/src/sensor/SDL_sensor_c.h
@@ -37,7 +37,7 @@ extern int SDL_SensorInit(void);
extern void SDL_SensorQuit(void);
/* Internal event queueing functions */
-extern int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, float *data, int num_values);
+extern int SDL_PrivateSensorUpdate(SDL_Sensor *sensor, Uint64 timestamp_us, float *data, int num_values);
#endif /* SDL_sensor_c_h_ */
diff --git a/src/sensor/SDL_syssensor.h b/src/sensor/SDL_syssensor.h
index cabbab6..6e601a2 100644
--- a/src/sensor/SDL_syssensor.h
+++ b/src/sensor/SDL_syssensor.h
@@ -37,6 +37,7 @@ struct _SDL_Sensor
SDL_SensorType type; /* Type of the sensor */
int non_portable_type; /* Platform dependent type of the sensor */
+ Uint64 timestamp_us; /* The timestamp of the last sensor update */
float data[16]; /* The current state of the sensor */
struct _SDL_SensorDriver *driver;
diff --git a/src/sensor/android/SDL_androidsensor.c b/src/sensor/android/SDL_androidsensor.c
index e6cfc23..27fb04c 100644
--- a/src/sensor/android/SDL_androidsensor.c
+++ b/src/sensor/android/SDL_androidsensor.c
@@ -174,7 +174,7 @@ SDL_ANDROID_SensorUpdate(SDL_Sensor *sensor)
if (ALooper_pollAll(0, NULL, &events, (void**)&source) == LOOPER_ID_USER) {
SDL_zero(event);
while (ASensorEventQueue_getEvents(sensor->hwdata->eventqueue, &event, 1) > 0) {
- SDL_PrivateSensorUpdate(sensor, event.data, SDL_arraysize(event.data));
+ SDL_PrivateSensorUpdate(sensor, 0, event.data, SDL_arraysize(event.data));
}
}
}
diff --git a/src/sensor/coremotion/SDL_coremotionsensor.m b/src/sensor/coremotion/SDL_coremotionsensor.m
index 7165f6a..735ecf5 100644
--- a/src/sensor/coremotion/SDL_coremotionsensor.m
+++ b/src/sensor/coremotion/SDL_coremotionsensor.m
@@ -162,7 +162,7 @@ SDL_COREMOTION_SensorUpdate(SDL_Sensor *sensor)
data[1] = -acceleration.y * SDL_STANDARD_GRAVITY;
data[2] = -acceleration.z * SDL_STANDARD_GRAVITY;
if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) {
- SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
+ SDL_PrivateSensorUpdate(sensor, 0, data, SDL_arraysize(data));
SDL_memcpy(sensor->hwdata->data, data, sizeof(data));
}
}
@@ -178,7 +178,7 @@ SDL_COREMOTION_SensorUpdate(SDL_Sensor *sensor)
data[1] = rotationRate.y;
data[2] = rotationRate.z;
if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) {
- SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
+ SDL_PrivateSensorUpdate(sensor, 0, data, SDL_arraysize(data));
SDL_memcpy(sensor->hwdata->data, data, sizeof(data));
}
}
diff --git a/src/sensor/vita/SDL_vitasensor.c b/src/sensor/vita/SDL_vitasensor.c
index 5235e9b..a049811 100644
--- a/src/sensor/vita/SDL_vitasensor.c
+++ b/src/sensor/vita/SDL_vitasensor.c
@@ -154,7 +154,24 @@ SDL_VITA_SensorUpdate(SDL_Sensor *sensor)
{
if (sensor->hwdata->counter < motionState[i].counter)
{
+ unsigned int timestamp = motionState[i].timestamp;
+
sensor->hwdata->counter = motionState[i].counter;
+
+ if (sensor->hwdata->timestamp_us) {
+ unsigned int delta;
+ if (sensor->hwdata->last_timestamp > timestamp) {
+ SDL_COMPILE_TIME_ASSERT(sizeof(timestamp) == sizeof(Uint32));
+ delta = (SDL_MAX_UINT32 - sensor->hwdata->last_timestamp + timestamp + 1);
+ } else {
+ delta = (timestamp - sensor->hwdata->last_timestamp);
+ }
+ sensor->hwdata->timestamp_us += delta;
+ } else {
+ sensor->hwdata->timestamp_us = timestamp;
+ }
+ sensor->hwdata->last_timestamp = timestamp;
+
switch (sensor->type)
{
case SDL_SENSOR_ACCEL:
@@ -163,10 +180,7 @@ SDL_VITA_SensorUpdate(SDL_Sensor *sensor)
data[0] = motionState[i].accelerometer.x * SDL_STANDARD_GRAVITY;
data[1] = motionState[i].accelerometer.y * SDL_STANDARD_GRAVITY;
data[2] = motionState[i].accelerometer.z * SDL_STANDARD_GRAVITY;
- if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) {
- SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
- SDL_memcpy(sensor->hwdata->data, data, sizeof(data));
- }
+ SDL_PrivateSensorUpdate(sensor, sensor->hwdata->timestamp_us, data, SDL_arraysize(data));
}
break;
case SDL_SENSOR_GYRO:
@@ -175,10 +189,7 @@ SDL_VITA_SensorUpdate(SDL_Sensor *sensor)
data[0] = motionState[i].gyro.x;
data[1] = motionState[i].gyro.y;
data[2] = motionState[i].gyro.z;
- if (SDL_memcmp(data, sensor->hwdata->data, sizeof(data)) != 0) {
- SDL_PrivateSensorUpdate(sensor, data, SDL_arraysize(data));
- SDL_memcpy(sensor->hwdata->data, data, sizeof(data));
- }
+ SDL_PrivateSensorUpdate(sensor, sensor->hwdata->timestamp_us, data, SDL_arraysize(data));
}
break;
default:
diff --git a/src/sensor/vita/SDL_vitasensor.h b/src/sensor/vita/SDL_vitasensor.h
index 2fca628..a7d6d29 100644
--- a/src/sensor/vita/SDL_vitasensor.h
+++ b/src/sensor/vita/SDL_vitasensor.h
@@ -23,8 +23,9 @@
/* The private structure used to keep track of a sensor */
struct sensor_hwdata
{
- float data[3];
Uint32 counter;
+ unsigned int last_timestamp;
+ Uint64 timestamp_us;
};
/* vi: set ts=4 sw=4 expandtab: */
diff --git a/src/sensor/windows/SDL_windowssensor.c b/src/sensor/windows/SDL_windowssensor.c
index 21b119d..b2edffc 100644
--- a/src/sensor/windows/SDL_windowssensor.c
+++ b/src/sensor/windows/SDL_windowssensor.c
@@ -171,7 +171,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, values, 3);
+ SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, 0, values, 3);
}
break;
case SDL_SENSOR_GYRO:
@@ -186,7 +186,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, values, 3);
+ SDL_PrivateSensorUpdate(SDL_sensors[i].sensor_opened, 0, values, 3);
}
break;
default:
diff --git a/test/testgamecontroller.c b/test/testgamecontroller.c
index 8ecdcd1..93942b1 100644
--- a/test/testgamecontroller.c
+++ b/test/testgamecontroller.c
@@ -592,12 +592,13 @@ loop(void *arg)
#define VERBOSE_SENSORS
#ifdef VERBOSE_SENSORS
case SDL_CONTROLLERSENSORUPDATE:
- SDL_Log("Controller %d sensor %s: %.2f, %.2f, %.2f\n",
+ SDL_Log("Controller %d sensor %s: %.2f, %.2f, %.2f (%"SDL_PRIu64")\n",
event.csensor.which,
GetSensorName((SDL_SensorType)event.csensor.sensor),
event.csensor.data[0],
event.csensor.data[1],
- event.csensor.data[2]);
+ event.csensor.data[2],
+ event.csensor.timestamp_us);
break;
#endif /* VERBOSE_SENSORS */