From 0002d9f5361a7ee01e8a50a8abae26c3fd41955e Mon Sep 17 00:00:00 2001 From: PixlOne <8843371+PixlOne@users.noreply.github.com> Date: Sat, 21 Sep 2019 13:29:12 -0400 Subject: [PATCH] Fix bluetooth reconnection events --- src/logid/Device.cpp | 27 ++++++++++++++++++++++++++- src/logid/Device.h | 18 ++++++++++++++++-- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/logid/Device.cpp b/src/logid/Device.cpp index fec0e6c..8213815 100644 --- a/src/logid/Device.cpp +++ b/src/logid/Device.cpp @@ -193,9 +193,15 @@ void Device::set_dpi(int dpi) void Device::start() { configure(); - listener->addEventHandler( std::make_unique(hidpp_dev, this) ); + try { listener->addEventHandler(std::make_unique(this)); } + catch(HIDPP20::UnsupportedFeature &e) { } if(index != HIDPP::DefaultDevice && index != HIDPP::CordedDevice) listener->addEventHandler( std::make_unique(this) ); + else + { + try { listener->addEventHandler( std::make_unique(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) diff --git a/src/logid/Device.h b/src/logid/Device.h index ad10ffd..3311513 100644 --- a/src/logid/Device.h +++ b/src/logid/Device.h @@ -10,6 +10,7 @@ #include #include #include +#include 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 states; std::vector 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 {