Added Xbox360WirelessController::is_active()

This commit is contained in:
Ingo Ruhnke 2011-02-03 05:14:18 +01:00
parent 14a6fa483c
commit 1194d15750
2 changed files with 21 additions and 0 deletions

View file

@ -28,6 +28,7 @@
Xbox360WirelessController::Xbox360WirelessController(libusb_device* dev_, int controller_id,
bool try_detach) :
m_active(false),
dev(dev_),
handle(),
endpoint(),
@ -121,11 +122,13 @@ Xbox360WirelessController::read(XboxGenericMsg& msg, int timeout)
if (data[1] == 0x00)
{
log_info("connection status: nothing");
set_active(false);
}
else if (data[1] == 0x80)
{
log_info("connection status: controller connected");
set_led(led_status);
set_active(true);
}
else if (data[1] == 0x40)
{
@ -143,6 +146,8 @@ Xbox360WirelessController::read(XboxGenericMsg& msg, int timeout)
}
else if (len == 29)
{
set_active(true);
if (data[0] == 0x00 && data[1] == 0x0f && data[2] == 0x00 && data[3] == 0xf0)
{ // Initial Announc Message
serial = (boost::format("%2x:%2x:%2x:%2x:%2x:%2x:%2x")
@ -190,4 +195,14 @@ Xbox360WirelessController::read(XboxGenericMsg& msg, int timeout)
return false;
}
void
Xbox360WirelessController::set_active(bool v)
{
if (m_active != v)
{
m_active = v;
// FIXME: insert code to signal the daemon, probablly best done with a boost::function<>
}
}
/* EOF */

View file

@ -31,6 +31,7 @@ struct XPadDevice;
class Xbox360WirelessController : public XboxGenericController
{
private:
bool m_active;
libusb_device* dev;
libusb_device_handle* handle;
int endpoint;
@ -47,6 +48,11 @@ public:
void set_led(uint8_t status);
bool read(XboxGenericMsg& msg, int timeout);
uint8_t get_battery_status() const;
bool is_active() const { return m_active; }
private:
void set_active(bool v);
private:
Xbox360WirelessController (const Xbox360WirelessController&);
Xbox360WirelessController& operator= (const Xbox360WirelessController&);