base: add an argument to peek at the first drawing only

Use --peek to download the first (oldest) drawing on the device but do not
delete it. This is primarily intended as a debugging option, so we can debug
the tablet handling without having to draw new drawings (which cause the
protocol messages to change slightly).

Since the tablet only has a "download oldest file" command this isn't very
useful to end users. If there are two or more files on the tablet, we can only
ever retrieve the oldest one.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
pull/181/head
Peter Hutterer 2019-08-21 13:19:54 +10:00
parent 23989e4291
commit e030b0b3ea
4 changed files with 21 additions and 1 deletions

View File

@ -450,9 +450,14 @@ def main(args=sys.argv):
help='Base directory for configuration',
type=str,
default=DEFAULT_CONFIG_PATH)
parser.add_argument('--peek',
help='Download first drawing only but do not remove it from the device',
action='store_true',
default=False)
ns = parser.parse_args(args[1:])
TuhiConfig.set_base_path(ns.config_dir)
TuhiConfig().peek_at_drawing = ns.peek
setup_logging(ns.config_dir)
if ns.verbose:

View File

@ -41,6 +41,7 @@ class TuhiConfig(GObject.Object):
self._devices = {}
self._scan_config_dir()
self.peek_at_drawing = False
return cls._instance
@GObject.Property

View File

@ -46,6 +46,12 @@ class Application(Gtk.Application):
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
'enable verbose output')
# unused, just here to have option compatibility with the tuhi
# server but we could add some GUI feedback here
self.add_main_option('peek', 0,
GLib.OptionFlags.NONE,
GLib.OptionArg.NONE,
'download first drawing only but do not remove it from the device')
self._tuhi = None
def do_startup(self):

View File

@ -26,6 +26,7 @@ from .uhid import UHIDDevice
import tuhi.protocol
from tuhi.protocol import NordicData, Interactions, Mode, ProtocolVersion, StrokeFile
from .util import list2hex, flatten
from tuhi.config import TuhiConfig
logger = logging.getLogger('tuhi.wacom')
@ -745,7 +746,8 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
def read_offline_data(self):
self.set_paper_mode()
transaction_count = 0
while self.count_available_files():
file_count = self.count_available_files()
while file_count > 0:
count, timestamp = self.get_stroke_data()
logger.info(f'receiving {count} bytes drawn on UTC {time.strftime("%y%m%d%H%M%S", time.gmtime(timestamp))}')
self.start_downloading_oldest_file()
@ -755,6 +757,12 @@ class WacomProtocolBase(WacomProtocolLowLevelComm):
drawing = self.parse_pen_data(pen_data, timestamp)
if drawing:
self.emit('drawing', drawing)
file_count -= 1
if TuhiConfig().peek_at_drawing:
logger.info(f'Not deleting drawing from device')
if file_count > 0:
logger.info(f'{file_count} more files on device but I can only download the oldest one')
break
self.delete_oldest_file()
transaction_count += 1
return transaction_count