wacom: use the DeviceError for the invalid state message

Nothing throws the previous exception anymore anyway.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer 2019-08-21 21:01:15 +10:00 committed by Benjamin Tissoires
parent 723b4fec35
commit fc280ce555
1 changed files with 16 additions and 11 deletions

View File

@ -24,7 +24,7 @@ from gi.repository import GObject
from .drawing import Drawing from .drawing import Drawing
from .uhid import UHIDDevice from .uhid import UHIDDevice
import tuhi.protocol import tuhi.protocol
from tuhi.protocol import NordicData, Interactions, Mode, ProtocolVersion, StrokeFile, UnexpectedDataError from tuhi.protocol import NordicData, Interactions, Mode, ProtocolVersion, StrokeFile, UnexpectedDataError, DeviceError
from .util import list2hex, flatten from .util import list2hex, flatten
from tuhi.config import TuhiConfig from tuhi.config import TuhiConfig
@ -250,10 +250,6 @@ class WacomException(Exception):
errno = errno.ENOSYS errno = errno.ENOSYS
class WacomEEAGAINException(WacomException):
errno = errno.EAGAIN
class WacomTimeoutException(WacomException): class WacomTimeoutException(WacomException):
errno = errno.ETIME errno = errno.ETIME
@ -660,8 +656,11 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
self.update_dimensions() self.update_dimensions()
if not self.read_offline_data(): if not self.read_offline_data():
logger.info('no data to retrieve') logger.info('no data to retrieve')
except WacomEEAGAINException: except DeviceError as e:
logger.warning('no data, please make sure the LED is blue and the button is pressed to switch it back to green') if e.errorcode == DeviceError.ErrorCode.INVALID_STATE:
logger.warning('no data, please make sure the LED is blue and the button is pressed to switch it back to green')
else:
raise e
def delete_oldest_file(self): def delete_oldest_file(self):
self.p.execute(Interactions.DELETE_OLDEST_FILE) self.p.execute(Interactions.DELETE_OLDEST_FILE)
@ -754,8 +753,11 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
self.start_live(uhid) self.start_live(uhid)
else: else:
self.stop_live() self.stop_live()
except WacomEEAGAINException: except DeviceError as e:
logger.warning("no data, please make sure the LED is blue and the button is pressed to switch it back to green") if e.errorcode == DeviceError.ErrorCode.INVALID_STATE:
logger.warning("no data, please make sure the LED is blue and the button is pressed to switch it back to green")
else:
raise e
class WacomProtocolSpark(WacomProtocolBase): class WacomProtocolSpark(WacomProtocolBase):
@ -849,8 +851,11 @@ class WacomProtocolSlate(WacomProtocolSpark):
self.select_transfer_gatt() self.select_transfer_gatt()
if not self.read_offline_data(): if not self.read_offline_data():
logger.info('no data to retrieve') logger.info('no data to retrieve')
except WacomEEAGAINException: except DeviceError as e:
logger.warning('no data, please make sure the LED is blue and the button is pressed to switch it back to green') if e.errorcode == DeviceError.ErrorCode.INVALID_STATE:
logger.warning('no data, please make sure the LED is blue and the button is pressed to switch it back to green')
else:
raise e
def wait_for_end_read(self): def wait_for_end_read(self):
data = self.wait_nordic_unless_pen_data(0xc8, timeout=5) data = self.wait_nordic_unless_pen_data(0xc8, timeout=5)