|
|
|
@ -58,18 +58,23 @@ uint16_t getClosestDPI(hidpp20::AdjustableDPI::SensorDPIList& dpi_list, |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
DPI::DPI(Device* device) : DeviceFeature(device), _config (device), |
|
|
|
|
_adjustable_dpi (&device->hidpp20()) |
|
|
|
|
DPI::DPI(Device* device) : DeviceFeature(device), _config (device) |
|
|
|
|
{ |
|
|
|
|
try { |
|
|
|
|
_adjustable_dpi = std::make_shared<hidpp20::AdjustableDPI> |
|
|
|
|
(&device->hidpp20()); |
|
|
|
|
} catch (hidpp20::UnsupportedFeature& e) { |
|
|
|
|
throw UnsupportedFeature(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DPI::configure() |
|
|
|
|
{ |
|
|
|
|
const uint8_t sensors = _adjustable_dpi.getSensorCount(); |
|
|
|
|
const uint8_t sensors = _adjustable_dpi->getSensorCount(); |
|
|
|
|
for(uint8_t i = 0; i < _config.getSensorCount(); i++) { |
|
|
|
|
hidpp20::AdjustableDPI::SensorDPIList dpi_list; |
|
|
|
|
if(_dpi_lists.size() <= i) { |
|
|
|
|
dpi_list = _adjustable_dpi.getSensorDPIList(i); |
|
|
|
|
dpi_list = _adjustable_dpi->getSensorDPIList(i); |
|
|
|
|
_dpi_lists.push_back(dpi_list); |
|
|
|
|
} else { |
|
|
|
|
dpi_list = _dpi_lists[i]; |
|
|
|
@ -77,7 +82,7 @@ void DPI::configure() |
|
|
|
|
if(i < sensors) { |
|
|
|
|
auto dpi = _config.getDPI(i); |
|
|
|
|
if(dpi) { |
|
|
|
|
_adjustable_dpi.setSensorDPI(i, getClosestDPI(dpi_list, |
|
|
|
|
_adjustable_dpi->setSensorDPI(i, getClosestDPI(dpi_list, |
|
|
|
|
dpi)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -90,20 +95,20 @@ void DPI::listen() |
|
|
|
|
|
|
|
|
|
uint16_t DPI::getDPI(uint8_t sensor) |
|
|
|
|
{ |
|
|
|
|
return _adjustable_dpi.getSensorDPI(sensor); |
|
|
|
|
return _adjustable_dpi->getSensorDPI(sensor); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void DPI::setDPI(uint16_t dpi, uint8_t sensor) |
|
|
|
|
{ |
|
|
|
|
hidpp20::AdjustableDPI::SensorDPIList dpi_list; |
|
|
|
|
if(_dpi_lists.size() <= sensor) { |
|
|
|
|
dpi_list = _adjustable_dpi.getSensorDPIList(sensor); |
|
|
|
|
dpi_list = _adjustable_dpi->getSensorDPIList(sensor); |
|
|
|
|
for(std::size_t i = _dpi_lists.size()-1; i <= sensor; i++) { |
|
|
|
|
_dpi_lists.push_back(_adjustable_dpi.getSensorDPIList(i)); |
|
|
|
|
_dpi_lists.push_back(_adjustable_dpi->getSensorDPIList(i)); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
dpi_list = _dpi_lists[sensor]; |
|
|
|
|
_adjustable_dpi.setSensorDPI(sensor, getClosestDPI(dpi_list, dpi)); |
|
|
|
|
_adjustable_dpi->setSensorDPI(sensor, getClosestDPI(dpi_list, dpi)); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* Some devices have multiple sensors, but an older config format
|
|
|
|
|