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-08 11:10:28 +01:00 committed by Peter Hutterer
parent ecd99ea9b6
commit 4b494917b1
2 changed files with 16 additions and 3 deletions

View File

@ -134,7 +134,7 @@ class TuhiDevice(GObject.Object):
def _on_bluez_device_connected(self, bluez_device):
logger.debug(f'{bluez_device.address}: connected')
if self._wacom_device is None:
self._wacom_device = WacomDevice(bluez_device, self._uuid)
self._wacom_device = WacomDevice(bluez_device, self.config)
self._wacom_device.connect('drawing', self._on_drawing_received)
self._wacom_device.connect('done', self._on_fetching_finished, bluez_device)
self._wacom_device.connect('button-press-required', self._on_button_press_required)

View File

@ -118,7 +118,7 @@ class WacomDevice(GObject.Object):
(GObject.SignalFlags.RUN_FIRST, None, (GObject.TYPE_INT, GObject.TYPE_BOOLEAN)),
}
def __init__(self, device, uuid=None):
def __init__(self, device, config):
GObject.Object.__init__(self)
self.device = device
self.nordic_answer = None
@ -127,10 +127,23 @@ class WacomDevice(GObject.Object):
self.width = WACOM_SLATE_WIDTH
self.height = WACOM_SLATE_HEIGHT
self.name = device.name
self._uuid = uuid
self._config = None
self.fw_logger = logging.getLogger('tuhi.fw')
self._is_running = False
try:
self._config = config.devices[device.address]
except KeyError:
self._uuid = None
self._wacom_protocol = None
else:
self._uuid = self._config['uuid']
try:
self._protocol = next(p for p in Protocol if p.value == self._config['Protocol'])
except StopIteration:
logger.error(f'Unknown protocol in configuration: {self._config["Protocol"]}')
raise WacomCorruptDataException(f'Unknown Protocol {self._config["Protocol"]}')
device.connect_gatt_value(WACOM_CHRC_LIVE_PEN_DATA_UUID,
self._on_pen_data_changed)
device.connect_gatt_value(WACOM_OFFLINE_CHRC_PEN_DATA_UUID,