mirror of
https://github.com/AxioDL/boo.git
synced 2025-12-09 13:37:48 +00:00
Merge branch 'master' of https://github.com/RetroView/libBoo
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "boo/inputdev/DeviceBase.hpp"
|
||||
#include "boo/inputdev/DeviceToken.hpp"
|
||||
#include "IHIDDevice.hpp"
|
||||
#include <cstdarg>
|
||||
|
||||
namespace boo
|
||||
{
|
||||
@@ -33,6 +34,14 @@ void DeviceBase::closeDevice()
|
||||
m_token->_deviceClose();
|
||||
}
|
||||
|
||||
void DeviceBase::deviceError(const char* error, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, error);
|
||||
vfprintf(stderr, error, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
bool DeviceBase::sendUSBInterruptTransfer(const uint8_t* data, size_t length)
|
||||
{
|
||||
if (m_hidDev)
|
||||
@@ -47,10 +56,17 @@ size_t DeviceBase::receiveUSBInterruptTransfer(uint8_t* data, size_t length)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool DeviceBase::sendHIDReport(const uint8_t* data, size_t length)
|
||||
bool DeviceBase::sendHIDReport(const uint8_t* data, size_t length, uint16_t message)
|
||||
{
|
||||
if (m_hidDev)
|
||||
return m_hidDev->_sendHIDReport(data, length);
|
||||
return m_hidDev->_sendHIDReport(data, length, message);
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t DeviceBase::receiveReport(uint8_t* data, size_t length, uint16_t message)
|
||||
{
|
||||
if (m_hidDev)
|
||||
return m_hidDev->_recieveReport(data, length, message);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,12 +102,8 @@ void DolphinSmashAdapter::transferCycle()
|
||||
{
|
||||
uint8_t rumbleMessage[5] = {0x11};
|
||||
for (int i=0 ; i<4 ; ++i)
|
||||
{
|
||||
if (rumbleReq & 1<<i)
|
||||
rumbleMessage[i+1] = 1;
|
||||
else
|
||||
rumbleMessage[i+1] = 0;
|
||||
}
|
||||
rumbleMessage[i+1] = (rumbleReq & 1<<i);
|
||||
|
||||
sendUSBInterruptTransfer(rumbleMessage, sizeof(rumbleMessage));
|
||||
m_rumbleState = rumbleReq;
|
||||
}
|
||||
|
||||
@@ -1 +1,138 @@
|
||||
#include "boo/inputdev/DualshockPad.hpp"
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
#include <stdio.h>
|
||||
#include <endian.h>
|
||||
#include <memory.h>
|
||||
|
||||
#define RAD_TO_DEG (180.0/M_PI)
|
||||
|
||||
void hexdump(void *ptr, int buflen) {
|
||||
unsigned char *buf = (unsigned char*)ptr;
|
||||
int i, j;
|
||||
for (i=0; i<buflen; i+=16) {
|
||||
printf("%06x: ", i);
|
||||
for (j=0; j<16; j++)
|
||||
if (i+j < buflen)
|
||||
printf("%02x ", buf[i+j]);
|
||||
else
|
||||
printf(" ");
|
||||
printf(" ");
|
||||
for (j=0; j<16; j++)
|
||||
if (i+j < buflen)
|
||||
printf("%c", isprint(buf[i+j]) ? buf[i+j] : '.');
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
namespace boo
|
||||
{
|
||||
static const uint8_t defaultReport[35] = {
|
||||
0x01, 0xff, 0x00, 0xff, 0x00,
|
||||
0xff, 0x80, 0x00, 0x00, 0x00,
|
||||
0xff, 0x27, 0x10, 0x00, 0x32,
|
||||
0xff, 0x27, 0x10, 0x00, 0x32,
|
||||
0xff, 0x27, 0x10, 0x00, 0x32,
|
||||
0xff, 0x27, 0x10, 0x00, 0x32,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
DualshockPad::DualshockPad(DeviceToken* token)
|
||||
: DeviceBase(token),
|
||||
m_callback(nullptr),
|
||||
m_rumbleRequest(0),
|
||||
m_rumbleState(0)
|
||||
{
|
||||
memcpy(m_report.buf, defaultReport, 35);
|
||||
}
|
||||
|
||||
DualshockPad::~DualshockPad()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void DualshockPad::deviceDisconnected()
|
||||
{
|
||||
if (m_callback)
|
||||
m_callback->controllerDisconnected();
|
||||
}
|
||||
|
||||
void DualshockPad::initialCycle()
|
||||
{
|
||||
uint8_t setupCommand[4] = {0x42, 0x0c, 0x00, 0x00}; //Tells controller to start sending changes on in pipe
|
||||
if (!sendHIDReport(setupCommand, sizeof(setupCommand), 0x03F4))
|
||||
{
|
||||
deviceError("Unable to send complete packet! Request size %x\n", sizeof(setupCommand));
|
||||
return;
|
||||
}
|
||||
uint8_t btAddr[8];
|
||||
receiveReport(btAddr, sizeof(btAddr), 0x03F5);
|
||||
for (int i = 0; i < 6; i++)
|
||||
m_btAddress[5 - i] = btAddr[i + 2]; // Copy into buffer reversed, so it is LSB first
|
||||
}
|
||||
|
||||
void DualshockPad::transferCycle()
|
||||
{
|
||||
DualshockPadState state;
|
||||
size_t recvSz = receiveUSBInterruptTransfer((uint8_t*)&state, 49);
|
||||
if (recvSz != 49)
|
||||
return;
|
||||
|
||||
for (int i = 0; i < 3; i++)
|
||||
state.m_accelerometer[i] = be16toh(state.m_accelerometer[i]);
|
||||
|
||||
state.m_gyrometerZ = be16toh(state.m_gyrometerZ);
|
||||
if (m_callback)
|
||||
m_callback->controllerUpdate(state);
|
||||
|
||||
if (m_rumbleRequest != m_rumbleState)
|
||||
{
|
||||
if (m_rumbleRequest & DS3_MOTOR_LEFT)
|
||||
{
|
||||
m_report.rumble.leftDuration = m_rumbleDuration[0];
|
||||
m_report.rumble.leftForce = m_rumbleIntensity[0];
|
||||
}
|
||||
else
|
||||
{
|
||||
m_report.rumble.leftDuration = 0;
|
||||
m_report.rumble.leftForce = 0;
|
||||
}
|
||||
|
||||
if (m_rumbleRequest & DS3_MOTOR_RIGHT)
|
||||
{
|
||||
m_report.rumble.rightDuration = m_rumbleDuration[0];
|
||||
m_report.rumble.rightOn = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_report.rumble.rightDuration = 0;
|
||||
m_report.rumble.rightOn = false;
|
||||
}
|
||||
sendHIDReport(m_report.buf, sizeof(m_report), 0x0201);
|
||||
m_rumbleState = m_rumbleRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (state.m_reserved5[8] & 0x80)
|
||||
m_rumbleRequest &= ~DS3_MOTOR_RIGHT;
|
||||
if (state.m_reserved5[7] & 0x01)
|
||||
m_rumbleRequest &= ~DS3_MOTOR_LEFT;
|
||||
m_rumbleState = m_rumbleRequest;
|
||||
const double zeroG = 511.5; // 1.65/3.3*1023 (1,65V);
|
||||
float accXval = -((double)state.m_accelerometer[0] - zeroG);
|
||||
float accYval = -((double)state.m_accelerometer[1] - zeroG);
|
||||
float accZval = -((double)state.m_accelerometer[2] - zeroG);
|
||||
state.accPitch = (atan2(accYval, accZval) + M_PI) * RAD_TO_DEG;
|
||||
state.accYaw = (atan2(accXval, accZval) + M_PI) * RAD_TO_DEG;
|
||||
state.gyroZ = (state.m_gyrometerZ / 1023.f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DualshockPad::finalCycle()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
} // boo
|
||||
|
||||
@@ -212,7 +212,7 @@ class CHIDDeviceIOKit final : public IHIDDevice
|
||||
m_runningTransferLoop = false;
|
||||
}
|
||||
|
||||
bool _sendHIDReport(const uint8_t* data, size_t length)
|
||||
bool _sendHIDReport(const uint8_t* data, size_t length, uint16_t message)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class HIDDeviceUdev final : public IHIDDevice
|
||||
{
|
||||
usbdevfs_bulktransfer xfer =
|
||||
{
|
||||
m_usbIntfOutPipe | USB_DIR_OUT,
|
||||
m_usbIntfOutPipe | USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
||||
(unsigned)length,
|
||||
0,
|
||||
(void*)data
|
||||
@@ -57,7 +57,7 @@ class HIDDeviceUdev final : public IHIDDevice
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
size_t _receiveUSBInterruptTransfer(uint8_t* data, size_t length)
|
||||
{
|
||||
if (m_devFd)
|
||||
@@ -193,12 +193,46 @@ class HIDDeviceUdev final : public IHIDDevice
|
||||
m_runningTransferLoop = false;
|
||||
}
|
||||
|
||||
bool _sendHIDReport(const uint8_t* data, size_t length)
|
||||
bool _sendHIDReport(const uint8_t* data, size_t length, uint16_t message)
|
||||
{
|
||||
(void)data;
|
||||
(void)length;
|
||||
if (m_devFd)
|
||||
{
|
||||
usbdevfs_ctrltransfer xfer =
|
||||
{
|
||||
USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
||||
0x09, // HID_SET_REPORT
|
||||
message,
|
||||
0,
|
||||
(uint16_t)length,
|
||||
0,
|
||||
(void*)data
|
||||
};
|
||||
int ret = ioctl(m_devFd, USBDEVFS_CONTROL, &xfer);
|
||||
if (ret != (int)length)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t _recieveReport(const uint8_t *data, size_t length, uint16_t message)
|
||||
{
|
||||
if (m_devFd)
|
||||
{
|
||||
usbdevfs_ctrltransfer xfer =
|
||||
{
|
||||
USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
|
||||
0x01, // HID_GET_REPORT
|
||||
message,
|
||||
0,
|
||||
(uint16_t)length,
|
||||
0,
|
||||
(void*)data
|
||||
};
|
||||
return ioctl(m_devFd, USBDEVFS_CONTROL, &xfer);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ class CHIDDeviceWinUSB final : public IHIDDevice
|
||||
m_runningTransferLoop = false;
|
||||
}
|
||||
|
||||
bool _sendHIDReport(const uint8_t* data, size_t length)
|
||||
bool _sendHIDReport(const uint8_t* data, size_t length, uint16_t message)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -90,7 +90,8 @@ class HIDListenerUdev final : public IHIDListener
|
||||
{
|
||||
const char* interfacesStr = udev_list_entry_get_value(devInterfaces);
|
||||
if (strstr(interfacesStr, ":030104") || /* HID / GenericDesktop / Joystick */
|
||||
strstr(interfacesStr, ":030105")) /* HID / GenericDesktop / Gamepad */
|
||||
strstr(interfacesStr, ":030105") || /* HID / GenericDesktop / Gamepad */
|
||||
strstr(interfacesStr, ":090000")) /* HID / Sony / Dualshock */
|
||||
{
|
||||
udev_enumerate* hidEnum = udev_enumerate_new(UDEV_INST);
|
||||
udev_enumerate_add_match_parent(hidEnum, device);
|
||||
|
||||
@@ -12,7 +12,8 @@ class IHIDDevice
|
||||
virtual void _deviceDisconnected()=0;
|
||||
virtual bool _sendUSBInterruptTransfer(const uint8_t* data, size_t length)=0;
|
||||
virtual size_t _receiveUSBInterruptTransfer(uint8_t* data, size_t length)=0;
|
||||
virtual bool _sendHIDReport(const uint8_t* data, size_t length)=0;
|
||||
virtual bool _sendHIDReport(const uint8_t* data, size_t length, uint16_t message)=0;
|
||||
virtual size_t _recieveReport(const uint8_t* data, size_t length, uint16_t message){}
|
||||
public:
|
||||
inline virtual ~IHIDDevice() {}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user