Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for the Ultimarc Ultrastik 360 to the gamepad plugin #1226

Merged
merged 1 commit into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions headers/addons/gamepad_usb_host_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,33 @@ typedef struct TU_ATTR_PACKED
uint8_t VEN_GamePad0021[54];
} dualshock4_t;

// Ultrastik 360
typedef struct TU_ATTR_PACKED
{
uint8_t GD_GamePadPointerX;
uint8_t GD_GamePadPointerY;

struct {
uint8_t BTN_GamePadButton1 : 1;
uint8_t BTN_GamePadButton2 : 1;
uint8_t BTN_GamePadButton3 : 1;
uint8_t BTN_GamePadButton4 : 1;
uint8_t BTN_GamePadButton5 : 1;
uint8_t BTN_GamePadButton6 : 1;
uint8_t BTN_GamePadButton7 : 1;
uint8_t BTN_GamePadButton8 : 1;
uint8_t BTN_GamePadButton9 : 1;
uint8_t BTN_GamePadButton10 : 1;
uint8_t BTN_GamePadButton11 : 1;
uint8_t BTN_GamePadButton12 : 1;
uint8_t BTN_GamePadButton13 : 1;
uint8_t BTN_GamePadButton14 : 1;
uint8_t BTN_GamePadButton15 : 1;
uint8_t padding : 1;
};

} ultrastik360_t;

// Add other controller structs here
class GamepadUSBHostListener : public USBListener {
public:// USB Listener Features
Expand All @@ -105,6 +132,7 @@ class GamepadUSBHostListener : public USBListener {
// Controller report processor functions
void process_ds4(uint8_t const* report);
void process_stadia(uint8_t const* report);
void process_ultrastik360(uint8_t const* report);

uint16_t controller_pid, controller_vid;

Expand Down
24 changes: 24 additions & 0 deletions src/addons/gamepad_usb_host_listener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ void GamepadUSBHostListener::process_ctrlr_report(uint8_t dev_addr, uint8_t cons
case 0x9400:// Google Stadia controller
process_stadia(report);
break;

case 0x0510: // pre-2015 Ultrakstik 360
case 0x0511: // Ultrakstik 360
process_ultrastik360(report);
break;
default:
break;
}
Expand Down Expand Up @@ -181,3 +186,22 @@ void GamepadUSBHostListener::process_stadia(uint8_t const* report) {
if (controller_report.GD_GamePadHatSwitch == 6) _controller_host_state.dpad |= GAMEPAD_MASK_LEFT;
if (controller_report.GD_GamePadHatSwitch == 7) _controller_host_state.dpad |= GAMEPAD_MASK_LEFT | GAMEPAD_MASK_UP;
}

void GamepadUSBHostListener::process_ultrastik360(uint8_t const* report) {

ultrastik360_t controller_report;

memcpy(&controller_report, report, sizeof(controller_report));

_controller_host_state.lx = map(controller_report.GD_GamePadPointerX, 0, 255, GAMEPAD_JOYSTICK_MIN,GAMEPAD_JOYSTICK_MAX);
_controller_host_state.ly = map(controller_report.GD_GamePadPointerY, 0, 255, GAMEPAD_JOYSTICK_MIN,GAMEPAD_JOYSTICK_MAX);

if (controller_report.BTN_GamePadButton1 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_B1;
if (controller_report.BTN_GamePadButton2 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_B2;
if (controller_report.BTN_GamePadButton3 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_B3;
if (controller_report.BTN_GamePadButton4 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_B4;
if (controller_report.BTN_GamePadButton5 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_L1;
if (controller_report.BTN_GamePadButton6 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_L2;
if (controller_report.BTN_GamePadButton7 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_R1;
if (controller_report.BTN_GamePadButton8 == 1) _controller_host_state.buttons |= GAMEPAD_MASK_R2;
}
Loading