Only send LED and rumble messages on state changes to avoid flooding the USB bus
This commit is contained in:
parent
429d808d4e
commit
d991fe5f83
16 changed files with 84 additions and 57 deletions
|
@ -29,7 +29,10 @@ Controller::Controller() :
|
|||
m_activation_cb(),
|
||||
m_is_disconnected(false),
|
||||
m_is_active(true),
|
||||
m_udev_device()
|
||||
m_udev_device(),
|
||||
m_led_status(0),
|
||||
m_rumble_left(0),
|
||||
m_rumble_right(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -47,6 +50,30 @@ Controller::submit_msg(const XboxGenericMsg& msg)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
Controller::set_rumble(uint8_t left, uint8_t right)
|
||||
{
|
||||
if (m_rumble_left != left ||
|
||||
m_rumble_right != right)
|
||||
{
|
||||
m_rumble_left = left;
|
||||
m_rumble_right = right;
|
||||
|
||||
set_rumble_real(m_rumble_left, m_rumble_right);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Controller::set_led(uint8_t status)
|
||||
{
|
||||
if (m_led_status != status)
|
||||
{
|
||||
m_led_status = status;
|
||||
|
||||
set_led_real(m_led_status);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
Controller::set_udev_device(udev_device* udev_dev)
|
||||
{
|
||||
|
|
|
@ -38,12 +38,21 @@ protected:
|
|||
bool m_is_active;
|
||||
udev_device* m_udev_device;
|
||||
|
||||
uint8_t m_led_status;
|
||||
uint8_t m_rumble_left;
|
||||
uint8_t m_rumble_right;
|
||||
|
||||
public:
|
||||
Controller();
|
||||
virtual ~Controller();
|
||||
|
||||
virtual void set_rumble(uint8_t left, uint8_t right) =0;
|
||||
virtual void set_led(uint8_t status) =0;
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
|
||||
uint8_t get_led() const { return m_led_status; }
|
||||
void set_led(uint8_t status);
|
||||
|
||||
virtual void set_rumble_real(uint8_t left, uint8_t right) =0;
|
||||
virtual void set_led_real(uint8_t status) =0;
|
||||
|
||||
/** Wireless Controller start out inactive when they are not synced
|
||||
with their receiver and become active after the sync. Regular
|
||||
|
|
|
@ -150,13 +150,13 @@ EvdevController::~EvdevController()
|
|||
}
|
||||
|
||||
void
|
||||
EvdevController::set_rumble(uint8_t left, uint8_t right)
|
||||
EvdevController::set_rumble_real(uint8_t left, uint8_t right)
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
|
||||
void
|
||||
EvdevController::set_led(uint8_t status)
|
||||
EvdevController::set_led_real(uint8_t status)
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
|
|
|
@ -58,8 +58,8 @@ public:
|
|||
bool debug);
|
||||
~EvdevController();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
void set_rumble_real(uint8_t left, uint8_t right);
|
||||
void set_led_real(uint8_t status);
|
||||
|
||||
/** @param timeout timeout in msec, 0 means forever */
|
||||
bool read(XboxGenericMsg& msg, int timeout);
|
||||
|
|
|
@ -83,9 +83,7 @@ struct FirestormMsg
|
|||
|
||||
FirestormDualController::FirestormDualController(libusb_device* dev, bool is_vsb_, bool try_detach) :
|
||||
USBController(dev),
|
||||
is_vsb(is_vsb_),
|
||||
left_rumble(-1),
|
||||
right_rumble(-1)
|
||||
is_vsb(is_vsb_)
|
||||
{
|
||||
usb_claim_interface(0, try_detach);
|
||||
|
||||
|
@ -106,28 +104,21 @@ FirestormDualController::~FirestormDualController()
|
|||
}
|
||||
|
||||
void
|
||||
FirestormDualController::set_rumble(uint8_t left, uint8_t right)
|
||||
FirestormDualController::set_rumble_real(uint8_t left, uint8_t right)
|
||||
{
|
||||
if (left_rumble != left ||
|
||||
right_rumble != right)
|
||||
uint8_t cmd[] = { left, right, 0x00, 0x00 };
|
||||
if (is_vsb)
|
||||
{
|
||||
left_rumble = left;
|
||||
right_rumble = right;
|
||||
|
||||
uint8_t cmd[] = { left, right, 0x00, 0x00 };
|
||||
if (is_vsb)
|
||||
{
|
||||
usb_control(0x21, 0x09, 0x0200, 0x00, cmd, sizeof(cmd));
|
||||
}
|
||||
else
|
||||
{
|
||||
usb_control(0x21, 0x09, 0x02, 0x00, cmd, sizeof(cmd));
|
||||
}
|
||||
usb_control(0x21, 0x09, 0x0200, 0x00, cmd, sizeof(cmd));
|
||||
}
|
||||
else
|
||||
{
|
||||
usb_control(0x21, 0x09, 0x02, 0x00, cmd, sizeof(cmd));
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
FirestormDualController::set_led(uint8_t status)
|
||||
FirestormDualController::set_led_real(uint8_t status)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
|
|
@ -27,15 +27,13 @@ class FirestormDualController : public USBController
|
|||
{
|
||||
private:
|
||||
bool is_vsb;
|
||||
int left_rumble;
|
||||
int right_rumble;
|
||||
|
||||
public:
|
||||
FirestormDualController(libusb_device* dev, bool is_vsb, bool try_detach);
|
||||
~FirestormDualController();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
void set_rumble_real(uint8_t left, uint8_t right);
|
||||
void set_led_real(uint8_t status);
|
||||
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
|
|
|
@ -42,13 +42,13 @@ Playstation3USBController::~Playstation3USBController()
|
|||
}
|
||||
|
||||
void
|
||||
Playstation3USBController::set_rumble(uint8_t left, uint8_t right)
|
||||
Playstation3USBController::set_rumble_real(uint8_t left, uint8_t right)
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
|
||||
void
|
||||
Playstation3USBController::set_led(uint8_t status)
|
||||
Playstation3USBController::set_led_real(uint8_t status)
|
||||
{
|
||||
// not implemented
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ public:
|
|||
Playstation3USBController(libusb_device* dev, bool try_detach);
|
||||
~Playstation3USBController();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
void set_rumble_real(uint8_t left, uint8_t right);
|
||||
void set_led_real(uint8_t status);
|
||||
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
|
|
|
@ -71,13 +71,13 @@ SaitekP2500Controller::~SaitekP2500Controller()
|
|||
}
|
||||
|
||||
void
|
||||
SaitekP2500Controller::set_rumble(uint8_t left, uint8_t right)
|
||||
SaitekP2500Controller::set_rumble_real(uint8_t left, uint8_t right)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
||||
void
|
||||
SaitekP2500Controller::set_led(uint8_t status)
|
||||
SaitekP2500Controller::set_led_real(uint8_t status)
|
||||
{
|
||||
// not supported
|
||||
}
|
||||
|
|
|
@ -33,8 +33,8 @@ public:
|
|||
SaitekP2500Controller(libusb_device* dev, bool try_detach);
|
||||
~SaitekP2500Controller();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
void set_rumble_real(uint8_t left, uint8_t right);
|
||||
void set_led_real(uint8_t status);
|
||||
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
|
|
|
@ -38,7 +38,9 @@ Xbox360Controller::Xbox360Controller(libusb_device* dev,
|
|||
endpoint_in(1),
|
||||
endpoint_out(2),
|
||||
m_chatpad(),
|
||||
m_headset()
|
||||
m_headset(),
|
||||
m_rumble_left(0),
|
||||
m_rumble_right(0)
|
||||
{
|
||||
// find endpoints
|
||||
endpoint_in = usb_find_ep(LIBUSB_ENDPOINT_IN, LIBUSB_CLASS_VENDOR_SPEC, 93, 1);
|
||||
|
@ -89,14 +91,14 @@ Xbox360Controller::~Xbox360Controller()
|
|||
}
|
||||
|
||||
void
|
||||
Xbox360Controller::set_rumble(uint8_t left, uint8_t right)
|
||||
Xbox360Controller::set_rumble_real(uint8_t left, uint8_t right)
|
||||
{
|
||||
uint8_t rumblecmd[] = { 0x00, 0x08, 0x00, left, right, 0x00, 0x00, 0x00 };
|
||||
usb_write(endpoint_out, rumblecmd, sizeof(rumblecmd));
|
||||
}
|
||||
|
||||
void
|
||||
Xbox360Controller::set_led(uint8_t status)
|
||||
Xbox360Controller::set_led_real(uint8_t status)
|
||||
{
|
||||
uint8_t ledcmd[] = { 0x01, 0x03, status };
|
||||
usb_write(endpoint_out, ledcmd, sizeof(ledcmd));
|
||||
|
|
|
@ -40,6 +40,9 @@ private:
|
|||
std::auto_ptr<Chatpad> m_chatpad;
|
||||
std::auto_ptr<Headset> m_headset;
|
||||
|
||||
uint8_t m_rumble_left;
|
||||
uint8_t m_rumble_right;
|
||||
|
||||
public:
|
||||
Xbox360Controller(libusb_device* dev,
|
||||
bool chatpad, bool chatpad_no_init, bool chatpad_debug,
|
||||
|
@ -50,8 +53,8 @@ public:
|
|||
bool try_detach);
|
||||
~Xbox360Controller();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
void set_rumble_real(uint8_t left, uint8_t right);
|
||||
void set_led_real(uint8_t status);
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
private:
|
||||
|
|
|
@ -33,8 +33,7 @@ Xbox360WirelessController::Xbox360WirelessController(libusb_device* dev, int con
|
|||
m_endpoint(),
|
||||
m_interface(),
|
||||
m_battery_status(),
|
||||
m_serial(),
|
||||
m_led_status(0)
|
||||
m_serial()
|
||||
{
|
||||
// FIXME: A little bit of a hack
|
||||
m_is_active = false;
|
||||
|
@ -56,7 +55,7 @@ Xbox360WirelessController::~Xbox360WirelessController()
|
|||
}
|
||||
|
||||
void
|
||||
Xbox360WirelessController::set_rumble(uint8_t left, uint8_t right)
|
||||
Xbox360WirelessController::set_rumble_real(uint8_t left, uint8_t right)
|
||||
{
|
||||
// +-- typo? might be 0x0c, i.e. length
|
||||
// v
|
||||
|
@ -65,9 +64,8 @@ Xbox360WirelessController::set_rumble(uint8_t left, uint8_t right)
|
|||
}
|
||||
|
||||
void
|
||||
Xbox360WirelessController::set_led(uint8_t status)
|
||||
Xbox360WirelessController::set_led_real(uint8_t status)
|
||||
{
|
||||
m_led_status = status;
|
||||
// +--- Why not just status?
|
||||
// v
|
||||
uint8_t ledcmd[] = { 0x00, 0x00, 0x08, 0x40 + (status % 0x0e), 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
|
@ -98,7 +96,7 @@ Xbox360WirelessController::parse(uint8_t* data, int len, XboxGenericMsg* msg_out
|
|||
else if (data[1] == 0x80)
|
||||
{
|
||||
log_info("connection status: controller connected");
|
||||
set_led(m_led_status);
|
||||
set_led(get_led());
|
||||
set_active(true);
|
||||
}
|
||||
else if (data[1] == 0x40)
|
||||
|
@ -108,7 +106,7 @@ Xbox360WirelessController::parse(uint8_t* data, int len, XboxGenericMsg* msg_out
|
|||
else if (data[1] == 0xc0)
|
||||
{
|
||||
log_info("Connection status: controller and headset connected");
|
||||
set_led(m_led_status);
|
||||
set_led(get_led());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
|
@ -34,7 +34,6 @@ private:
|
|||
int m_interface;
|
||||
int m_battery_status;
|
||||
std::string m_serial;
|
||||
int m_led_status;
|
||||
|
||||
public:
|
||||
Xbox360WirelessController(libusb_device* dev, int controller_id, bool try_detach);
|
||||
|
@ -42,8 +41,8 @@ public:
|
|||
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
void set_rumble_real(uint8_t left, uint8_t right);
|
||||
void set_led_real(uint8_t status);
|
||||
uint8_t get_battery_status() const;
|
||||
|
||||
private:
|
||||
|
|
|
@ -46,7 +46,7 @@ XboxController::~XboxController()
|
|||
}
|
||||
|
||||
void
|
||||
XboxController::set_rumble(uint8_t left, uint8_t right)
|
||||
XboxController::set_rumble_real(uint8_t left, uint8_t right)
|
||||
{
|
||||
uint8_t rumblecmd[] = { 0x00, 0x06, 0x00, left, 0x00, right };
|
||||
int transferred = 0;
|
||||
|
@ -59,7 +59,7 @@ XboxController::set_rumble(uint8_t left, uint8_t right)
|
|||
}
|
||||
|
||||
void
|
||||
XboxController::set_led(uint8_t status)
|
||||
XboxController::set_led_real(uint8_t status)
|
||||
{
|
||||
// Controller doesn't have a LED
|
||||
}
|
||||
|
|
|
@ -35,8 +35,8 @@ public:
|
|||
XboxController(libusb_device* dev, bool try_detach);
|
||||
virtual ~XboxController();
|
||||
|
||||
void set_rumble(uint8_t left, uint8_t right);
|
||||
void set_led(uint8_t status);
|
||||
void set_rumble_real(uint8_t left, uint8_t right);
|
||||
void set_led_real(uint8_t status);
|
||||
bool parse(uint8_t* data, int len, XboxGenericMsg* msg_out);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Reference in a new issue