Fix bluetooth reconnection events

This commit is contained in:
PixlOne 2019-09-21 13:29:12 -04:00
parent ac414bf33e
commit 0002d9f536
2 changed files with 42 additions and 3 deletions

View File

@ -193,9 +193,15 @@ void Device::set_dpi(int dpi)
void Device::start()
{
configure();
listener->addEventHandler( std::make_unique<ButtonHandler>(hidpp_dev, this) );
try { listener->addEventHandler(std::make_unique<ButtonHandler>(this)); }
catch(HIDPP20::UnsupportedFeature &e) { }
if(index != HIDPP::DefaultDevice && index != HIDPP::CordedDevice)
listener->addEventHandler( std::make_unique<ReceiverHandler>(this) );
else
{
try { listener->addEventHandler( std::make_unique<WirelessStatusHandler>(this) ); }
catch(HIDPP20::UnsupportedFeature &e) { }
}
listener->start();
}
@ -274,6 +280,25 @@ void ReceiverHandler::handleEvent(const HIDPP::Report &event)
}
}
void WirelessStatusHandler::handleEvent(const HIDPP::Report &event)
{
switch(event.function())
{
case HIDPP20::IWirelessDeviceStatus::StatusBroadcast:
{
auto status = HIDPP20::IWirelessDeviceStatus::statusBroadcastEvent(event);
if(status.ReconfNeeded)
dev->configure();
break;
}
default:
{
log_printf(DEBUG, "Undocumented event %02x from WirelessDeviceStatus", event.function());
break;
}
}
}
void EventListener::removeEventHandlers ()
{
for (const auto &p: iterators)

View File

@ -10,6 +10,7 @@
#include <hidpp/Dispatcher.h>
#include <hidpp/SimpleDispatcher.h>
#include <hidpp10/IReceiver.h>
#include <hidpp20/IWirelessDeviceStatus.h>
class EventListener;
class DeviceConfig;
@ -68,15 +69,15 @@ public:
class ButtonHandler : public EventHandler
{
public:
ButtonHandler (HIDPP20::Device *hidppdev, Device *d) : _irc (HIDPP20::IReprogControls::auto_version(hidppdev)), dev (d) { }
ButtonHandler (Device *d) : dev (d), _irc (HIDPP20::IReprogControls::auto_version(d->hidpp_dev)) { }
const HIDPP20::FeatureInterface *feature () const
{
return &_irc;
}
void handleEvent (const HIDPP::Report &event);
protected:
HIDPP20::IReprogControls _irc;
Device* dev;
HIDPP20::IReprogControls _irc;
std::vector<uint16_t> states;
std::vector<uint16_t> new_states;
};
@ -96,6 +97,19 @@ public:
protected:
Device* dev;
};
class WirelessStatusHandler : public EventHandler
{
public:
WirelessStatusHandler (Device *d) : dev (d), _iws (d->hidpp_dev) { }
const HIDPP20::FeatureInterface *feature () const
{
return &_iws;
}
void handleEvent (const HIDPP::Report &event);
protected:
Device* dev;
HIDPP20::IWirelessDeviceStatus _iws;
};
class EventListener
{