| 554 | } |
| 555 | |
| 556 | void PadDualshock2::Set(u32 index, float value) |
| 557 | { |
| 558 | if (index > Inputs::LENGTH) |
| 559 | { |
| 560 | return; |
| 561 | } |
| 562 | |
| 563 | if (IsAnalogKey(index)) |
| 564 | { |
| 565 | this->rawInputs[index] = static_cast<u8>(std::clamp(value * this->axisScale * 255.0f, 0.0f, 255.0f)); |
| 566 | |
| 567 | // Left -> -- -> Right |
| 568 | // Value range : FFFF8002 -> 0 -> 7FFE |
| 569 | // Force range : 80 -> 0 -> 7F |
| 570 | // Normal mode : expect value 0 -> 80 -> FF |
| 571 | // Reverse mode: expect value FF -> 7F -> 0 |
| 572 | |
| 573 | // merge left/right or up/down into rx or ry |
| 574 | |
| 575 | #define MERGE(pos, neg) ((this->rawInputs[pos] != 0) ? (127u + ((this->rawInputs[pos] + 1u) / 2u)) : (127u - (this->rawInputs[neg] / 2u))) |
| 576 | if (index <= Inputs::PAD_L_LEFT) |
| 577 | { |
| 578 | // Left Stick |
| 579 | this->analogs.lx = this->analogs.lxInvert ? MERGE(Inputs::PAD_L_LEFT, Inputs::PAD_L_RIGHT) : MERGE(Inputs::PAD_L_RIGHT, Inputs::PAD_L_LEFT); |
| 580 | this->analogs.ly = this->analogs.lyInvert ? MERGE(Inputs::PAD_L_UP, Inputs::PAD_L_DOWN) : MERGE(Inputs::PAD_L_DOWN, Inputs::PAD_L_UP); |
| 581 | } |
| 582 | else |
| 583 | { |
| 584 | // Right Stick |
| 585 | this->analogs.rx = this->analogs.rxInvert ? MERGE(Inputs::PAD_R_LEFT, Inputs::PAD_R_RIGHT) : MERGE(Inputs::PAD_R_RIGHT, Inputs::PAD_R_LEFT); |
| 586 | this->analogs.ry = this->analogs.ryInvert ? MERGE(Inputs::PAD_R_UP, Inputs::PAD_R_DOWN) : MERGE(Inputs::PAD_R_DOWN, Inputs::PAD_R_UP); |
| 587 | } |
| 588 | #undef MERGE |
| 589 | |
| 590 | // Deadzone computation. |
| 591 | const float dz = this->axisDeadzone; |
| 592 | |
| 593 | if (dz > 0.0f) |
| 594 | { |
| 595 | #define MERGE_F(pos, neg) ((this->rawInputs[pos] != 0) ? (static_cast<float>(this->rawInputs[pos]) / 255.0f) : (static_cast<float>(this->rawInputs[neg]) / -255.0f)) |
| 596 | float posX, posY; |
| 597 | if (index <= Inputs::PAD_L_LEFT) |
| 598 | { |
| 599 | posX = this->analogs.lxInvert ? MERGE_F(Inputs::PAD_L_LEFT, Inputs::PAD_L_RIGHT) : MERGE_F(Inputs::PAD_L_RIGHT, Inputs::PAD_L_LEFT); |
| 600 | posY = this->analogs.lyInvert ? MERGE_F(Inputs::PAD_L_UP, Inputs::PAD_L_DOWN) : MERGE_F(Inputs::PAD_L_DOWN, Inputs::PAD_L_UP); |
| 601 | } |
| 602 | else |
| 603 | { |
| 604 | posX = this->analogs.rxInvert ? MERGE_F(Inputs::PAD_R_LEFT, Inputs::PAD_R_RIGHT) : MERGE_F(Inputs::PAD_R_RIGHT, Inputs::PAD_R_LEFT); |
| 605 | posY = this->analogs.ryInvert ? MERGE_F(Inputs::PAD_R_UP, Inputs::PAD_R_DOWN) : MERGE_F(Inputs::PAD_R_DOWN, Inputs::PAD_R_UP); |
| 606 | } |
| 607 | |
| 608 | // No point checking if we're at dead center (usually keyboard with no buttons pressed). |
| 609 | if (posX != 0.0f || posY != 0.0f) |
| 610 | { |
| 611 | // Compute the angle at the given position in the stick's square bounding box. |
| 612 | const float theta = std::atan2(posY, posX); |
| 613 |
nothing calls this directly
no test coverage detected