@@ -316,22 +316,79 @@ int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) {
316
316
pData[i].angularVelocity .y = states[i].angularVelocity .y ;
317
317
pData[i].angularVelocity .z = states[i].angularVelocity .z ;
318
318
pData[i].orientation = {0 .0f , 0 .0f , 0 .0f , 1 .0f };
319
- if (engine) {
319
+ pData[i].acceleration .x = states[i].acceleration .x * 0.098 ;
320
+ pData[i].acceleration .y = states[i].acceleration .y * 0.098 ;
321
+ pData[i].acceleration .z = states[i].acceleration .z * 0.098 ;
322
+ pData[i].angularVelocity .x = states[i].angularVelocity .x ;
323
+ pData[i].angularVelocity .y = states[i].angularVelocity .y ;
324
+ pData[i].angularVelocity .z = states[i].angularVelocity .z ;
325
+
326
+ if (engine && handle == 1 ) {
320
327
const auto gyro_poll_rate = engine->GetAccelPollRate ();
321
328
if (gyro_poll_rate != 0 .0f ) {
322
- GameController::CalculateOrientation (pData[i].acceleration ,
323
- pData[i].angularVelocity ,
324
- 1 .0f / gyro_poll_rate, pData[i].orientation );
329
+ auto now = std::chrono::steady_clock::now ();
330
+ float deltaTime = std::chrono::duration_cast<std::chrono::microseconds>(
331
+ now - controller->GetLastUpdate ())
332
+ .count () /
333
+ 1000000 .0f ;
334
+ controller->SetLastUpdate (now);
335
+ Libraries::Pad::OrbisFQuaternion lastOrientation = controller->GetLastOrientation ();
336
+ Libraries::Pad::OrbisFQuaternion outputOrientation = {0 .0f , 0 .0f , 0 .0f , 1 .0f };
337
+ GameController::CalculateOrientation (pData->acceleration , pData->angularVelocity ,
338
+ deltaTime, lastOrientation, outputOrientation);
339
+ pData[i].orientation = outputOrientation;
340
+ controller->SetLastOrientation (outputOrientation);
325
341
}
326
342
}
343
+
327
344
pData[i].touchData .touchNum =
328
345
(states[i].touchpad [0 ].state ? 1 : 0 ) + (states[i].touchpad [1 ].state ? 1 : 0 );
346
+
347
+ if (handle == 1 ) {
348
+ if (controller->GetTouchCount () >= 127 ) {
349
+ controller->SetTouchCount (0 );
350
+ }
351
+
352
+ if (controller->GetSecondaryTouchCount () >= 127 ) {
353
+ controller->SetSecondaryTouchCount (0 );
354
+ }
355
+
356
+ if (pData->touchData .touchNum == 1 && controller->GetPreviousTouchNum () == 0 ) {
357
+ controller->SetTouchCount (controller->GetTouchCount () + 1 );
358
+ controller->SetSecondaryTouchCount (controller->GetTouchCount ());
359
+ } else if (pData->touchData .touchNum == 2 && controller->GetPreviousTouchNum () == 1 ) {
360
+ controller->SetSecondaryTouchCount (controller->GetSecondaryTouchCount () + 1 );
361
+ } else if (pData->touchData .touchNum == 0 && controller->GetPreviousTouchNum () > 0 ) {
362
+ if (controller->GetTouchCount () < controller->GetSecondaryTouchCount ()) {
363
+ controller->SetTouchCount (controller->GetSecondaryTouchCount ());
364
+ } else {
365
+ if (controller->WasSecondaryTouchReset ()) {
366
+ controller->SetTouchCount (controller->GetSecondaryTouchCount ());
367
+ controller->UnsetSecondaryTouchResetBool ();
368
+ }
369
+ }
370
+ }
371
+
372
+ controller->SetPreviousTouchNum (pData->touchData .touchNum );
373
+
374
+ if (pData->touchData .touchNum == 1 ) {
375
+ states[i].touchpad [0 ].ID = controller->GetTouchCount ();
376
+ states[i].touchpad [1 ].ID = 0 ;
377
+ } else if (pData->touchData .touchNum == 2 ) {
378
+ states[i].touchpad [0 ].ID = controller->GetTouchCount ();
379
+ states[i].touchpad [1 ].ID = controller->GetSecondaryTouchCount ();
380
+ }
381
+ } else {
382
+ states[i].touchpad [0 ].ID = 1 ;
383
+ states[i].touchpad [1 ].ID = 2 ;
384
+ }
385
+
329
386
pData[i].touchData .touch [0 ].x = states[i].touchpad [0 ].x ;
330
387
pData[i].touchData .touch [0 ].y = states[i].touchpad [0 ].y ;
331
- pData[i].touchData .touch [0 ].id = 1 ;
388
+ pData[i].touchData .touch [0 ].id = states[i]. touchpad [ 0 ]. ID ;
332
389
pData[i].touchData .touch [1 ].x = states[i].touchpad [1 ].x ;
333
390
pData[i].touchData .touch [1 ].y = states[i].touchpad [1 ].y ;
334
- pData[i].touchData .touch [1 ].id = 2 ;
391
+ pData[i].touchData .touch [1 ].id = states[i]. touchpad [ 1 ]. ID ;
335
392
pData[i].connected = connected;
336
393
pData[i].timestamp = states[i].time ;
337
394
pData[i].connectedCount = connected_count;
@@ -376,31 +433,85 @@ int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData) {
376
433
pData->leftStick .x = state.axes [static_cast <int >(Input::Axis::LeftX)];
377
434
pData->leftStick .y = state.axes [static_cast <int >(Input::Axis::LeftY)];
378
435
pData->rightStick .x = state.axes [static_cast <int >(Input::Axis::RightX)];
436
+ pData->rightStick .x = state.axes [static_cast <int >(Input::Axis::RightX)];
379
437
pData->rightStick .y = state.axes [static_cast <int >(Input::Axis::RightY)];
380
438
pData->analogButtons .l2 = state.axes [static_cast <int >(Input::Axis::TriggerLeft)];
381
439
pData->analogButtons .r2 = state.axes [static_cast <int >(Input::Axis::TriggerRight)];
382
- pData->acceleration .x = state.acceleration .x ;
383
- pData->acceleration .y = state.acceleration .y ;
384
- pData->acceleration .z = state.acceleration .z ;
440
+ pData->acceleration .x = state.acceleration .x * 0.098 ;
441
+ pData->acceleration .y = state.acceleration .y * 0.098 ;
442
+ pData->acceleration .z = state.acceleration .z * 0.098 ;
385
443
pData->angularVelocity .x = state.angularVelocity .x ;
386
444
pData->angularVelocity .y = state.angularVelocity .y ;
387
445
pData->angularVelocity .z = state.angularVelocity .z ;
388
446
pData->orientation = {0 .0f , 0 .0f , 0 .0f , 1 .0f };
389
- if (engine) {
447
+
448
+ // Only do this on handle 1 for now
449
+ if (engine && handle == 1 ) {
390
450
const auto gyro_poll_rate = engine->GetAccelPollRate ();
391
451
if (gyro_poll_rate != 0 .0f ) {
452
+ auto now = std::chrono::steady_clock::now ();
453
+ float deltaTime = std::chrono::duration_cast<std::chrono::microseconds>(
454
+ now - controller->GetLastUpdate ())
455
+ .count () /
456
+ 1000000 .0f ;
457
+ controller->SetLastUpdate (now);
458
+ Libraries::Pad::OrbisFQuaternion lastOrientation = controller->GetLastOrientation ();
459
+ Libraries::Pad::OrbisFQuaternion outputOrientation = {0 .0f , 0 .0f , 0 .0f , 1 .0f };
392
460
GameController::CalculateOrientation (pData->acceleration , pData->angularVelocity ,
393
- 1 .0f / gyro_poll_rate, pData->orientation );
461
+ deltaTime, lastOrientation, outputOrientation);
462
+ pData->orientation = outputOrientation;
463
+ controller->SetLastOrientation (outputOrientation);
394
464
}
395
465
}
396
466
pData->touchData .touchNum =
397
467
(state.touchpad [0 ].state ? 1 : 0 ) + (state.touchpad [1 ].state ? 1 : 0 );
468
+
469
+ // Only do this on handle 1 for now
470
+ if (handle == 1 ) {
471
+ if (controller->GetTouchCount () >= 127 ) {
472
+ controller->SetTouchCount (0 );
473
+ }
474
+
475
+ if (controller->GetSecondaryTouchCount () >= 127 ) {
476
+ controller->SetSecondaryTouchCount (0 );
477
+ }
478
+
479
+ if (pData->touchData .touchNum == 1 && controller->GetPreviousTouchNum () == 0 ) {
480
+ controller->SetTouchCount (controller->GetTouchCount () + 1 );
481
+ controller->SetSecondaryTouchCount (controller->GetTouchCount ());
482
+ } else if (pData->touchData .touchNum == 2 && controller->GetPreviousTouchNum () == 1 ) {
483
+ controller->SetSecondaryTouchCount (controller->GetSecondaryTouchCount () + 1 );
484
+ } else if (pData->touchData .touchNum == 0 && controller->GetPreviousTouchNum () > 0 ) {
485
+ if (controller->GetTouchCount () < controller->GetSecondaryTouchCount ()) {
486
+ controller->SetTouchCount (controller->GetSecondaryTouchCount ());
487
+ } else {
488
+ if (controller->WasSecondaryTouchReset ()) {
489
+ controller->SetTouchCount (controller->GetSecondaryTouchCount ());
490
+ controller->UnsetSecondaryTouchResetBool ();
491
+ }
492
+ }
493
+ }
494
+
495
+ controller->SetPreviousTouchNum (pData->touchData .touchNum );
496
+
497
+ if (pData->touchData .touchNum == 1 ) {
498
+ state.touchpad [0 ].ID = controller->GetTouchCount ();
499
+ state.touchpad [1 ].ID = 0 ;
500
+ } else if (pData->touchData .touchNum == 2 ) {
501
+ state.touchpad [0 ].ID = controller->GetTouchCount ();
502
+ state.touchpad [1 ].ID = controller->GetSecondaryTouchCount ();
503
+ }
504
+ } else {
505
+ state.touchpad [0 ].ID = 1 ;
506
+ state.touchpad [1 ].ID = 2 ;
507
+ }
508
+
398
509
pData->touchData .touch [0 ].x = state.touchpad [0 ].x ;
399
510
pData->touchData .touch [0 ].y = state.touchpad [0 ].y ;
400
- pData->touchData .touch [0 ].id = 1 ;
511
+ pData->touchData .touch [0 ].id = state. touchpad [ 0 ]. ID ;
401
512
pData->touchData .touch [1 ].x = state.touchpad [1 ].x ;
402
513
pData->touchData .touch [1 ].y = state.touchpad [1 ].y ;
403
- pData->touchData .touch [1 ].id = 2 ;
514
+ pData->touchData .touch [1 ].id = state. touchpad [ 1 ]. ID ;
404
515
pData->timestamp = state.time ;
405
516
pData->connected = true ; // isConnected; //TODO fix me proper
406
517
pData->connectedCount = 1 ; // connectedCount;
0 commit comments