ui: handle onboard profiles notifications
This commit is contained in:
parent
42c65e1e4d
commit
0548bde44f
|
@ -453,5 +453,39 @@ def _process_feature_notification(device, status, n, feature):
|
|||
if _log.isEnabledFor(_INFO):
|
||||
_log.info('%s: unknown WHEEL %s', device, n)
|
||||
|
||||
elif feature == _F.ONBOARD_PROFILES:
|
||||
if (n.address > 0x10):
|
||||
if _log.isEnabledFor(_INFO):
|
||||
_log.info('%s: unknown ONBOARD PROFILES %s', device, n)
|
||||
else:
|
||||
if (n.address == 0x00):
|
||||
resolution_index = None
|
||||
profile_sector = _unpack('!H', n.data[:2])[0]
|
||||
elif (n.address == 0x10):
|
||||
resolution_index = _unpack('!B', n.data[:1])[0]
|
||||
profile_sector = _unpack('!H', device.feature_request(_F.ONBOARD_PROFILES, 0x40)[:2])[0]
|
||||
if profile_sector:
|
||||
profile_change(device, profile_sector, resolution_index)
|
||||
|
||||
_diversion.process_notification(device, status, n, feature)
|
||||
return True
|
||||
|
||||
|
||||
# change UI to show result of onboard profile change
|
||||
def profile_change(device, profile_sector, resolution_index=None):
|
||||
from solaar.ui.config_panel import record_setting # prevent circular import
|
||||
setting = next((s for s in device.settings if s.name == _st.OnboardProfiles.name), None)
|
||||
if setting:
|
||||
record_setting(device, setting, [profile_sector])
|
||||
from solaar.ui.config_panel import record_setting # prevent circular import
|
||||
for profile in device.profiles.profiles.values() if device.profiles else []:
|
||||
if profile.sector == profile_sector:
|
||||
if resolution_index is None:
|
||||
resolution_index = profile.resolution_default_index
|
||||
setting = next((s for s in device.settings if s.name == _st.AdjustableDpi.name), None)
|
||||
if setting:
|
||||
record_setting(device, setting, [profile.resolutions[resolution_index]])
|
||||
setting = next((s for s in device.settings if s.name == _st.ReportRate.name), None)
|
||||
if setting:
|
||||
record_setting(device, setting, [profile.report_rate])
|
||||
break
|
||||
|
|
|
@ -466,11 +466,13 @@ class OnboardProfiles(_Setting):
|
|||
return b'\x00\x00'
|
||||
|
||||
def write(self, device, data_bytes):
|
||||
from . import notifications as _notifications # prevent circular import
|
||||
if data_bytes == b'\x00\x00':
|
||||
result = device.feature_request(_F.ONBOARD_PROFILES, 0x10, b'\x02')
|
||||
else:
|
||||
device.feature_request(_F.ONBOARD_PROFILES, 0x10, b'\x01')
|
||||
result = device.feature_request(_F.ONBOARD_PROFILES, 0x30, data_bytes)
|
||||
_notifications.profile_change(device, _bytes2int(data_bytes))
|
||||
return result
|
||||
|
||||
class validator_class(_ChoicesV):
|
||||
|
|
Loading…
Reference in New Issue