diff --git a/tuhi/base.py b/tuhi/base.py index 6fd833d..332223f 100644 --- a/tuhi/base.py +++ b/tuhi/base.py @@ -21,6 +21,7 @@ from gi.repository import GObject, GLib from tuhi.dbusserver import TuhiDBusServer from tuhi.ble import BlueZDeviceManager from tuhi.wacom import WacomDevice +from tuhi.wacom import Protocol from tuhi.config import TuhiConfig logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s', @@ -167,7 +168,10 @@ class TuhiDevice(GObject.Object): self._tuhi_dbus_device.notify_button_press_required() def _on_uuid_updated(self, wacom_device, pspec, bluez_device): - self.config.new_device(bluez_device.address, wacom_device.uuid) + protocol = Protocol.SLATE + if wacom_device.is_spark(): + protocol = Protocol.SPARK + self.config.new_device(bluez_device.address, wacom_device.uuid, protocol) self.registered = True def _on_listening_updated(self, dbus_device, pspec): @@ -287,7 +291,7 @@ class Tuhi(GObject.Object): if uuid is None: logger.info(f'{bluez_device.address}: device without config, must be registered first') return - logger.debug(f'{bluez_device.address}: UUID {uuid}') + logger.debug(f'{bluez_device.address}: UUID {uuid} protocol: {config["Protocol"]}') # create the device if unknown from us if bluez_device.address not in self.devices: diff --git a/tuhi/config.py b/tuhi/config.py index 8be0bed..d3f3da9 100644 --- a/tuhi/config.py +++ b/tuhi/config.py @@ -19,6 +19,7 @@ import configparser import re import logging from .drawing import Drawing +from .wacom import Protocol logger = logging.getLogger('tuhi.config') @@ -67,11 +68,14 @@ class TuhiConfig(GObject.Object): self._purge_drawings(entry) assert config['Device']['Address'] == entry.name + if 'Protocol' not in config['Device']: + config['Device']['Protocol'] = Protocol.UNKNOWN.value self._devices[entry.name] = config['Device'] - def new_device(self, address, uuid): + def new_device(self, address, uuid, protocol): assert is_btaddr(address) assert len(uuid) == 12 + assert protocol != Protocol.UNKNOWN logger.debug(f'{address}: adding new config, UUID {uuid}') path = os.path.join(ROOT_PATH, address) @@ -92,6 +96,7 @@ class TuhiConfig(GObject.Object): config['Device'] = { 'Address': address, 'UUID': uuid, + 'Protocol': protocol.value, } with open(path, 'w') as configfile: diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 7396c1d..6304220 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -14,6 +14,7 @@ import binascii import calendar +import enum import logging import threading import time @@ -42,6 +43,14 @@ WACOM_SLATE_WIDTH = 21600 WACOM_SLATE_HEIGHT = 14800 +@enum.unique +class Protocol(enum.Enum): + UNKNOWN = 'unknown' + SPARK = 'spark' + SLATE = 'slate' + INTUOS_PRO = 'intuos-pro' + + def signed_char_to_int(v): return int.from_bytes([v], byteorder='little', signed=True)