Skip to content

Commit

Permalink
Added haptic enable state checks on most modes supporting it
Browse files Browse the repository at this point in the history
  • Loading branch information
mikepparks committed Sep 3, 2024
1 parent f3c98dc commit ed19a4b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 17 deletions.
12 changes: 12 additions & 0 deletions src/drivers/ps3/PS3Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "drivers/ps3/PS3Driver.h"
#include "drivers/ps3/PS3Descriptors.h"
#include "drivers/shared/driverhelper.h"
#include "storagemanager.h"

void PS3Driver::initialize() {
//stdio_init_all();
Expand Down Expand Up @@ -262,7 +263,18 @@ void PS3Driver::set_report(uint8_t report_id, hid_report_type_t report_type, uin
}
switch(report_id) {
case PS3ReportTypes::PS3_FEATURE_01:
Gamepad * gamepad = Storage::getInstance().GetGamepad();
memcpy(&ps3Features, buf, bufsize);

if (gamepad->auxState.haptics.leftActuator.enabled) {
gamepad->auxState.haptics.leftActuator.active = (ps3Features.leftMotorPower > 0);
gamepad->auxState.haptics.leftActuator.intensity = ps3Features.leftMotorPower;
}

if (gamepad->auxState.haptics.rightActuator.enabled) {
gamepad->auxState.haptics.rightActuator.active = (ps3Features.rightMotorPower > 0);
gamepad->auxState.haptics.rightActuator.intensity = ps3Features.rightMotorPower;
}
break;
}
}
Expand Down
25 changes: 16 additions & 9 deletions src/drivers/ps4/PS4Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,15 +417,22 @@ void PS4Driver::set_report(uint8_t report_id, hid_report_type_t report_type, uin
//report[8] = Flash On Period
//report[9] = Flash Off Period

gamepad->auxState.haptics.leftActuator.active = (buffer[4] > 0);
gamepad->auxState.haptics.leftActuator.intensity = buffer[4];
gamepad->auxState.haptics.rightActuator.active = (buffer[5] > 0);
gamepad->auxState.haptics.rightActuator.intensity = buffer[5];

gamepad->auxState.sensors.statusLight.enabled = true;
gamepad->auxState.sensors.statusLight.color.red = buffer[6];
gamepad->auxState.sensors.statusLight.color.green = buffer[7];
gamepad->auxState.sensors.statusLight.color.blue = buffer[8];
if (gamepad->auxState.haptics.leftActuator.enabled) {
gamepad->auxState.haptics.leftActuator.active = (buffer[4] > 0);
gamepad->auxState.haptics.leftActuator.intensity = buffer[4];
}

if (gamepad->auxState.haptics.rightActuator.enabled) {
gamepad->auxState.haptics.rightActuator.active = (buffer[5] > 0);
gamepad->auxState.haptics.rightActuator.intensity = buffer[5];
}

if (gamepad->auxState.sensors.statusLight.enabled) {
gamepad->auxState.sensors.statusLight.active = true;
gamepad->auxState.sensors.statusLight.color.red = buffer[6];
gamepad->auxState.sensors.statusLight.color.green = buffer[7];
gamepad->auxState.sensors.statusLight.color.blue = buffer[8];
}
} else {
//for (uint8_t i = 0; i < bufsize; i++) {
// printf("%02x ", buffer[i]);
Expand Down
14 changes: 10 additions & 4 deletions src/drivers/xboxog/XboxOriginalDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@ void XboxOriginalDriver::process(Gamepad * gamepad, uint8_t * outBuffer) {
{
uint8_t leftValue = (xboxOriginalReportOut.lValue >> 8);
uint8_t rightValue = (xboxOriginalReportOut.rValue >> 8);
gamepad->auxState.haptics.leftActuator.active = (leftValue > 0);
gamepad->auxState.haptics.leftActuator.intensity = leftValue;
gamepad->auxState.haptics.rightActuator.active = (rightValue > 0);
gamepad->auxState.haptics.rightActuator.intensity = rightValue;

if (gamepad->auxState.haptics.leftActuator.enabled) {
gamepad->auxState.haptics.leftActuator.active = (leftValue > 0);
gamepad->auxState.haptics.leftActuator.intensity = leftValue;
}

if (gamepad->auxState.haptics.rightActuator.enabled) {
gamepad->auxState.haptics.rightActuator.active = (rightValue > 0);
gamepad->auxState.haptics.rightActuator.intensity = rightValue;
}
}
}

Expand Down
13 changes: 9 additions & 4 deletions src/drivers/xinput/XInputDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,15 @@ static void check_and_set_rumble(Gamepad * gamepad, uint8_t * buffer) {
if (!(buffer[0] == 0x00 && buffer[1] == 0x08))
return;

gamepad->auxState.haptics.leftActuator.active = (buffer[3] > 0);
gamepad->auxState.haptics.leftActuator.intensity = buffer[3];
gamepad->auxState.haptics.rightActuator.active = (buffer[4] > 0);
gamepad->auxState.haptics.rightActuator.intensity = buffer[4];
if (gamepad->auxState.haptics.leftActuator.enabled) {
gamepad->auxState.haptics.leftActuator.active = (buffer[3] > 0);
gamepad->auxState.haptics.leftActuator.intensity = buffer[3];
}

if (gamepad->auxState.haptics.rightActuator.enabled) {
gamepad->auxState.haptics.rightActuator.active = (buffer[4] > 0);
gamepad->auxState.haptics.rightActuator.intensity = buffer[4];
}
}

void XInputDriver::initialize() {
Expand Down

0 comments on commit ed19a4b

Please sign in to comment.