Fix undetected CIDs

This commit is contained in:
pixl 2020-07-13 15:29:40 -04:00
parent 0f60c3896c
commit a2718d9023
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
3 changed files with 18 additions and 12 deletions

View File

@ -79,20 +79,23 @@ ReprogControls::ControlInfo ReprogControls::getControlInfo(uint8_t index)
return info; return info;
} }
void ReprogControls::initCidMap()
{
std::unique_lock<std::mutex> 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) ReprogControls::ControlInfo ReprogControls::getControlIdInfo(uint16_t cid)
{ {
if(!_cids_initialized) { if(!_cids_initialized)
std::unique_lock<std::mutex> lock(_cids_populating); initCidMap();
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;
}
}
auto it = _cids.find(cid); auto it = _cids.find(cid);
if(it == _cids.end()) if(it == _cids.end())

View File

@ -95,6 +95,8 @@ namespace hidpp20
virtual ControlInfo getControlIdInfo(uint16_t cid); virtual ControlInfo getControlIdInfo(uint16_t cid);
virtual void initCidMap();
// Onlu controlId and flags will be set // Onlu controlId and flags will be set
virtual ControlInfo getControlReporting(uint16_t cid); virtual ControlInfo getControlReporting(uint16_t cid);

View File

@ -32,6 +32,7 @@ using namespace logid::actions;
RemapButton::RemapButton(Device *dev): DeviceFeature(dev), _config (dev), RemapButton::RemapButton(Device *dev): DeviceFeature(dev), _config (dev),
_reprog_controls (hidpp20::ReprogControls::autoVersion(&dev->hidpp20())) _reprog_controls (hidpp20::ReprogControls::autoVersion(&dev->hidpp20()))
{ {
_reprog_controls->initCidMap();
} }
RemapButton::~RemapButton() RemapButton::~RemapButton()