config: store the protocol used by the device in the config file
Instead of having to detect the protocol multiple times, we should just store it once so we can detect oddities when they arrive.pull/81/merge
parent
8f2ad50fa5
commit
ecd99ea9b6
|
@ -21,6 +21,7 @@ from gi.repository import GObject, GLib
|
||||||
from tuhi.dbusserver import TuhiDBusServer
|
from tuhi.dbusserver import TuhiDBusServer
|
||||||
from tuhi.ble import BlueZDeviceManager
|
from tuhi.ble import BlueZDeviceManager
|
||||||
from tuhi.wacom import WacomDevice
|
from tuhi.wacom import WacomDevice
|
||||||
|
from tuhi.wacom import Protocol
|
||||||
from tuhi.config import TuhiConfig
|
from tuhi.config import TuhiConfig
|
||||||
|
|
||||||
logging.basicConfig(format='%(levelname)s: %(name)s: %(message)s',
|
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()
|
self._tuhi_dbus_device.notify_button_press_required()
|
||||||
|
|
||||||
def _on_uuid_updated(self, wacom_device, pspec, bluez_device):
|
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
|
self.registered = True
|
||||||
|
|
||||||
def _on_listening_updated(self, dbus_device, pspec):
|
def _on_listening_updated(self, dbus_device, pspec):
|
||||||
|
@ -287,7 +291,7 @@ class Tuhi(GObject.Object):
|
||||||
if uuid is None:
|
if uuid is None:
|
||||||
logger.info(f'{bluez_device.address}: device without config, must be registered first')
|
logger.info(f'{bluez_device.address}: device without config, must be registered first')
|
||||||
return
|
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
|
# create the device if unknown from us
|
||||||
if bluez_device.address not in self.devices:
|
if bluez_device.address not in self.devices:
|
||||||
|
|
|
@ -19,6 +19,7 @@ import configparser
|
||||||
import re
|
import re
|
||||||
import logging
|
import logging
|
||||||
from .drawing import Drawing
|
from .drawing import Drawing
|
||||||
|
from .wacom import Protocol
|
||||||
|
|
||||||
logger = logging.getLogger('tuhi.config')
|
logger = logging.getLogger('tuhi.config')
|
||||||
|
|
||||||
|
@ -67,11 +68,14 @@ class TuhiConfig(GObject.Object):
|
||||||
self._purge_drawings(entry)
|
self._purge_drawings(entry)
|
||||||
|
|
||||||
assert config['Device']['Address'] == entry.name
|
assert config['Device']['Address'] == entry.name
|
||||||
|
if 'Protocol' not in config['Device']:
|
||||||
|
config['Device']['Protocol'] = Protocol.UNKNOWN.value
|
||||||
self._devices[entry.name] = config['Device']
|
self._devices[entry.name] = config['Device']
|
||||||
|
|
||||||
def new_device(self, address, uuid):
|
def new_device(self, address, uuid, protocol):
|
||||||
assert is_btaddr(address)
|
assert is_btaddr(address)
|
||||||
assert len(uuid) == 12
|
assert len(uuid) == 12
|
||||||
|
assert protocol != Protocol.UNKNOWN
|
||||||
|
|
||||||
logger.debug(f'{address}: adding new config, UUID {uuid}')
|
logger.debug(f'{address}: adding new config, UUID {uuid}')
|
||||||
path = os.path.join(ROOT_PATH, address)
|
path = os.path.join(ROOT_PATH, address)
|
||||||
|
@ -92,6 +96,7 @@ class TuhiConfig(GObject.Object):
|
||||||
config['Device'] = {
|
config['Device'] = {
|
||||||
'Address': address,
|
'Address': address,
|
||||||
'UUID': uuid,
|
'UUID': uuid,
|
||||||
|
'Protocol': protocol.value,
|
||||||
}
|
}
|
||||||
|
|
||||||
with open(path, 'w') as configfile:
|
with open(path, 'w') as configfile:
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
import binascii
|
import binascii
|
||||||
import calendar
|
import calendar
|
||||||
|
import enum
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import time
|
import time
|
||||||
|
@ -42,6 +43,14 @@ WACOM_SLATE_WIDTH = 21600
|
||||||
WACOM_SLATE_HEIGHT = 14800
|
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):
|
def signed_char_to_int(v):
|
||||||
return int.from_bytes([v], byteorder='little', signed=True)
|
return int.from_bytes([v], byteorder='little', signed=True)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue