From 91203701cf257768c8798785cc08f5e71e688d18 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 14 Aug 2019 12:32:56 +1000 Subject: [PATCH] wacom: group the list2hex output Group by size 8 by default. Signed-off-by: Peter Hutterer --- tuhi/wacom.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 91c603f..11292b0 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -108,10 +108,16 @@ def b2hex(bs): return ' '.join([''.join(s) for s in zip(hx[::2], hx[1::2])]) -def list2hex(l): +def list2hex(l, groupsize=8): '''Converts a list of integers to a two-letter hex string in the form "1a 2b c3"''' - return ' '.join([f'{x:02x}' for x in l]) + + slices = [] + for idx in range(0, len(l), groupsize): + s = ' '.join([f'{x:02x}' for x in l[idx:idx + groupsize]]) + slices.append(s) + + return ' '.join(slices) def list2hexlist(l):