From a2718d9023691565b3d92142e1b77478ceb86062 Mon Sep 17 00:00:00 2001 From: pixl Date: Mon, 13 Jul 2020 15:29:40 -0400 Subject: [PATCH] Fix undetected CIDs --- .../hidpp20/features/ReprogControls.cpp | 27 ++++++++++--------- .../backend/hidpp20/features/ReprogControls.h | 2 ++ src/logid/features/RemapButton.cpp | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/logid/backend/hidpp20/features/ReprogControls.cpp b/src/logid/backend/hidpp20/features/ReprogControls.cpp index 82af1d4..34334c4 100644 --- a/src/logid/backend/hidpp20/features/ReprogControls.cpp +++ b/src/logid/backend/hidpp20/features/ReprogControls.cpp @@ -79,20 +79,23 @@ ReprogControls::ControlInfo ReprogControls::getControlInfo(uint8_t index) return info; } +void ReprogControls::initCidMap() +{ + std::unique_lock lock(_cids_populating); + if(_cids_initialized) + return; + uint8_t controls = getControlCount(); + for(uint8_t i = 0; i < controls; i++) { + auto info = getControlInfo(i); + _cids.emplace(info.controlID, info); + } + _cids_initialized = true; +} + ReprogControls::ControlInfo ReprogControls::getControlIdInfo(uint16_t cid) { - if(!_cids_initialized) { - std::unique_lock lock(_cids_populating); - if(!_cids_initialized) { - uint8_t controls = getControlCount(); - for(uint8_t i = 0; i < controls; i++) { - auto info = getControlInfo(i); - _cids.emplace(info.controlID, info); - } - _cids_populating.unlock(); - _cids_initialized = true; - } - } + if(!_cids_initialized) + initCidMap(); auto it = _cids.find(cid); if(it == _cids.end()) diff --git a/src/logid/backend/hidpp20/features/ReprogControls.h b/src/logid/backend/hidpp20/features/ReprogControls.h index 07567f8..a3d342c 100644 --- a/src/logid/backend/hidpp20/features/ReprogControls.h +++ b/src/logid/backend/hidpp20/features/ReprogControls.h @@ -95,6 +95,8 @@ namespace hidpp20 virtual ControlInfo getControlIdInfo(uint16_t cid); + virtual void initCidMap(); + // Onlu controlId and flags will be set virtual ControlInfo getControlReporting(uint16_t cid); diff --git a/src/logid/features/RemapButton.cpp b/src/logid/features/RemapButton.cpp index 32fdd6e..13204b0 100644 --- a/src/logid/features/RemapButton.cpp +++ b/src/logid/features/RemapButton.cpp @@ -32,6 +32,7 @@ using namespace logid::actions; RemapButton::RemapButton(Device *dev): DeviceFeature(dev), _config (dev), _reprog_controls (hidpp20::ReprogControls::autoVersion(&dev->hidpp20())) { + _reprog_controls->initCidMap(); } RemapButton::~RemapButton()