wacom: load the protocol of the device from the config file

We can store this once for all, which will allow to keep the logic
of detecting the protocol while registering only
This commit is contained in:
Benjamin Tissoires 2018-02-07 19:59:02 +01:00
parent 1e78495e4b
commit 3133558661
2 changed files with 26 additions and 2 deletions

View File

@ -38,6 +38,13 @@ class TuhiConfig(GObject.Object):
SLATE = 2
INTUOS_PRO = 3
@classmethod
def from_string(cls, e):
for attr in [a for a in dir(cls) if not a.startswith('__')]:
if e in ('Protocol.' + attr, attr):
return getattr(cls, attr)
return TuhiConfig.Protocol.UNKNOWN
def __init__(self):
GObject.Object.__init__(self)
try:

View File

@ -694,10 +694,27 @@ class WacomDevice(GObject.Object):
self._init_protocol()
def _init_protocol(self):
if WacomProtocol.is_spark(self._device):
self._wacom_protocol = WacomProtocolSpark(self._device, self._uuid)
protocol = TuhiConfig.Protocol.UNKNOWN
if self._config is not None and 'Protocol' in self._config:
protocol = TuhiConfig.Protocol.from_string(self._config['Protocol'])
else:
# we are registering a new device, or we might have an early
# config file from ab older tuhi version
if WacomProtocol.is_spark(self._device):
protocol = TuhiConfig.Protocol.SPARK
else:
protocol = TuhiConfig.Protocol.SLATE
if protocol == TuhiConfig.Protocol.SPARK:
self._wacom_protocol = WacomProtocolSpark(self._device, self._uuid)
elif protocol == TuhiConfig.Protocol.SLATE:
self._wacom_protocol = WacomProtocolSlate(self._device, self._uuid)
else:
log.error(f'Unknown Protocol {protocol}')
raise WacomCorruptDataException(f'Unknown Protocol {protocol}')
logger.debug(f'{self._device.name} is using {type(self._wacom_protocol)}')
self._wacom_protocol.connect('drawing', self._on_drawing_received)
self._wacom_protocol.connect('button-press-required', self._on_button_press_required)
self._wacom_protocol.connect('battery-status', self._on_battery_status)