Skip to content

Commit

Permalink
device: limited support for extended adjustable dpi
Browse files Browse the repository at this point in the history
  • Loading branch information
pfps committed Jan 30, 2024
1 parent 28493f7 commit 90458fe
Showing 1 changed file with 31 additions and 11 deletions.
42 changes: 31 additions & 11 deletions lib/logitech_receiver/settings_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def build(cls, setting_class, device):
class DpiSlidingXY(_RawXYProcessing):

def activate_action(self):
self.dpiSetting = next(filter(lambda s: s.name == 'dpi', self.device.settings), None)
self.dpiSetting = next(filter(lambda s: s.name == 'dpi' or s.name == 'dpi_extended', self.device.settings), None)
self.dpiChoices = list(self.dpiSetting.choices)
self.otherDpiIdx = self.device.persister.get('_dpi-sliding', -1) if self.device.persister else -1
if not isinstance(self.otherDpiIdx, int) or self.otherDpiIdx < 0 or self.otherDpiIdx >= len(self.dpiChoices):
Expand Down Expand Up @@ -567,7 +567,7 @@ def move_action(self, dx, dy):
class MouseGesturesXY(_RawXYProcessing):

def activate_action(self):
self.dpiSetting = next(filter(lambda s: s.name == 'dpi', self.device.settings), None)
self.dpiSetting = next(filter(lambda s: s.name == 'dpi' or s.name == 'dpi_extended', self.device.settings), None)
self.fsmState = 'idle'
self.initialize_data()

Expand Down Expand Up @@ -713,28 +713,36 @@ class AdjustableDpi(_Setting):
feature = _F.ADJUSTABLE_DPI
rw_options = {'read_fnid': 0x20, 'write_fnid': 0x30}
choices_universe = _NamedInts.range(200, 4000, str, 50)
sensor_list_bytes_ignore = 1

class validator_class(_ChoicesV):

@classmethod
def build(cls, setting_class, device):
# [1] getSensorDpiList(sensorIdx)
reply = device.feature_request(_F.ADJUSTABLE_DPI, 0x10)
# [1] getSensorDpiList(sensorIdx) - works for both features
reply = device.feature_request(_F.ADJUSTABLE_DPI, 0x10, 0x00, 0x00)
assert reply, 'Oops, DPI list cannot be retrieved!'
dpi_bytes = reply[setting_class.sensor_list_bytes_ignore:]
i = 1
while _bytes2int(dpi_bytes[-2:]) != 0:
reply = device.feature_request(_F.ADJUSTABLE_DPI, 0x10, 0x00, i)
assert reply, 'Oops, DPI list cannot be retrieved!'
dpi_bytes += reply[setting_class.sensor_list_bytes_ignore:]
dpi_list = []
step = None
for val in _unpack('!7H', reply[1:1 + 14]):
i = 0
while i < len(dpi_bytes):
val = _bytes2int(dpi_bytes[i:i + 2])
if val == 0:
break
if val >> 13 == 0b111:
assert step is None and len(dpi_list) == 1, \
'Invalid DPI list item: %r' % val
step = val & 0x1fff
last = _bytes2int(dpi_bytes[i + 2:i + 4])
assert len(dpi_list) > 0 and last > dpi_list[-1], 'Invalid DPI list item: %r' % val
dpi_list += range(dpi_list[-1] + step, last + 1, step)
i += 4
else:
dpi_list.append(val)
if step:
assert len(dpi_list) == 2, 'Invalid DPI list range: %r' % dpi_list
dpi_list = range(dpi_list[0], dpi_list[1] + 1, step)
i += 2
return cls(choices=_NamedInts.list(dpi_list), byte_count=3) if dpi_list else None

def validate_read(self, reply_bytes): # special validator to use default DPI if needed
Expand All @@ -746,6 +754,17 @@ def validate_read(self, reply_bytes): # special validator to use default DPI if
return valid_value


class ExtendedAdjustableDpi(AdjustableDpi):
# the extended version allows for two dimensions, longer dpi descriptions
# still assume only one sensor (and X only?)
# [5] getSensorDpiParameters(sensorIdx) → sensorIdx, dpiX, defaultDpiX, dpiY, defaultDpiY, lod
# [6] setSensorDpiParameters(sensorIdx, dpiX, dpiY, lod) → sensorIdx, dpiX, dpiY, lod
name = 'dpi_extended'
feature = _F.EXTENDED_ADJUSTABLE_DPI
rw_options = {'read_fnid': 0x50, 'write_fnid': 0x60}
sensor_list_bytes_ignore = 3


class SpeedChange(_Setting):
"""Implements the ability to switch Sensitivity by clicking on the DPI_Change button."""
name = 'speed-change'
Expand Down Expand Up @@ -1224,6 +1243,7 @@ class ADCPower(_Setting):
ReportRate, # working
PointerSpeed, # simple
AdjustableDpi, # working
ExtendedAdjustableDpi,
SpeedChange,
# Backlight, # not working - disabled temporarily
Backlight2, # working
Expand Down

0 comments on commit 90458fe

Please sign in to comment.