Fixed Firestorm gamepad, implemented USBController::usb_control()
This commit is contained in:
parent
1cc2b36269
commit
94dd5aa052
4 changed files with 53 additions and 22 deletions
|
@ -88,7 +88,15 @@ FirestormDualController::FirestormDualController(libusb_device* dev, bool is_vsb
|
|||
right_rumble(-1)
|
||||
{
|
||||
usb_claim_interface(0, try_detach);
|
||||
usb_submit_read(1, 32); // FIXME: do we need the correct size?!
|
||||
|
||||
if (is_vsb)
|
||||
{
|
||||
usb_submit_read(1, sizeof(Firestorm_vsb_Msg));
|
||||
}
|
||||
else
|
||||
{
|
||||
usb_submit_read(1, sizeof(FirestormMsg));
|
||||
}
|
||||
}
|
||||
|
||||
FirestormDualController::~FirestormDualController()
|
||||
|
@ -109,11 +117,11 @@ FirestormDualController::set_rumble(uint8_t left, uint8_t right)
|
|||
uint8_t cmd[] = { left, right, 0x00, 0x00 };
|
||||
if (is_vsb)
|
||||
{
|
||||
libusb_control_transfer(m_handle, 0x21, 0x09, 0x0200, 0x00, cmd, sizeof(cmd), 0);
|
||||
usb_control(0x21, 0x09, 0x0200, 0x00, cmd, sizeof(cmd));
|
||||
}
|
||||
else
|
||||
{
|
||||
libusb_control_transfer(m_handle, 0x21, 0x09, 0x02, 0x00, cmd, sizeof(cmd), 0);
|
||||
usb_control(0x21, 0x09, 0x02, 0x00, cmd, sizeof(cmd));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,18 +73,7 @@ SaitekP2500Controller::~SaitekP2500Controller()
|
|||
void
|
||||
SaitekP2500Controller::set_rumble(uint8_t left, uint8_t right)
|
||||
{
|
||||
/*
|
||||
if (left_rumble != left ||
|
||||
right_rumble != right)
|
||||
{
|
||||
left_rumble = left;
|
||||
right_rumble = right;
|
||||
|
||||
char cmd[] = { left, right, 0x00, 0x00 };
|
||||
|
||||
libusb_control_transfer(handle, 0x21, 0x09, 0x02, 0x00, cmd, sizeof(cmd), 0);
|
||||
}
|
||||
*/
|
||||
// not supported
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -78,13 +78,6 @@ USBController::USBController(libusb_device* dev) :
|
|||
|
||||
USBController::~USBController()
|
||||
{
|
||||
usb_cancel_read();
|
||||
if (m_read_transfer)
|
||||
{
|
||||
libusb_free_transfer(m_read_transfer);
|
||||
}
|
||||
|
||||
//libusb_release_interface(m_handle, 0);
|
||||
libusb_close(m_handle);
|
||||
}
|
||||
|
||||
|
@ -153,6 +146,37 @@ USBController::usb_write(int endpoint, uint8_t* data_in, int len)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
USBController::usb_control(uint8_t bmRequestType, uint8_t bRequest,
|
||||
uint16_t wValue, uint16_t wIndex,
|
||||
uint8_t* data_in, uint16_t wLength)
|
||||
{
|
||||
libusb_transfer* transfer = libusb_alloc_transfer(0);
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_BUFFER;
|
||||
transfer->flags |= LIBUSB_TRANSFER_FREE_TRANSFER;
|
||||
|
||||
// create and fill control buffer
|
||||
uint8_t* data = static_cast<uint8_t*>(malloc(wLength + 8));
|
||||
libusb_fill_control_setup(data, bmRequestType, bRequest, wValue, wIndex, wLength);
|
||||
memcpy(data + 8, data_in, wLength);
|
||||
libusb_fill_control_transfer(transfer, m_handle, data,
|
||||
&USBController::on_control_wrap, this,
|
||||
0);
|
||||
|
||||
int ret;
|
||||
ret = libusb_submit_transfer(transfer);
|
||||
if (ret != LIBUSB_SUCCESS)
|
||||
{
|
||||
raise_exception(std::runtime_error, "libusb_submit_transfer(): " << usb_strerror(ret));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
USBController::on_control(libusb_transfer* transfer)
|
||||
{
|
||||
log_debug("control transfer");
|
||||
}
|
||||
|
||||
void
|
||||
USBController::on_write_data(libusb_transfer* transfer)
|
||||
{
|
||||
|
@ -167,6 +191,7 @@ USBController::usb_cancel_read()
|
|||
{
|
||||
assert(m_read_transfer);
|
||||
libusb_cancel_transfer(m_read_transfer);
|
||||
libusb_free_transfer(m_read_transfer);
|
||||
m_read_transfer = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -56,6 +56,9 @@ public:
|
|||
void usb_cancel_read();
|
||||
|
||||
void usb_write(int endpoint, uint8_t* data, int len);
|
||||
void usb_control(uint8_t bmRequestType, uint8_t bRequest,
|
||||
uint16_t wValue, uint16_t wIndex,
|
||||
uint8_t* data, uint16_t len);
|
||||
|
||||
private:
|
||||
void on_read_data(libusb_transfer *transfer);
|
||||
|
@ -70,6 +73,12 @@ private:
|
|||
static_cast<USBController*>(transfer->user_data)->on_write_data(transfer);
|
||||
}
|
||||
|
||||
void on_control(libusb_transfer* transfer);
|
||||
static void on_control_wrap(libusb_transfer* transfer)
|
||||
{
|
||||
static_cast<USBController*>(transfer->user_data)->on_control(transfer);
|
||||
}
|
||||
|
||||
private:
|
||||
USBController(const USBController&);
|
||||
USBController& operator=(const USBController&);
|
||||
|
|
Loading…
Reference in a new issue