diff --git a/tuhi/util.py b/tuhi/util.py new file mode 100644 index 0000000..e8ac1ee --- /dev/null +++ b/tuhi/util.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + + +def list2hex(l, groupsize=8): + '''Converts a list of integers to a two-letter hex string in the form + "1a 2b c3"''' + + 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) diff --git a/tuhi/wacom.py b/tuhi/wacom.py index 11292b0..73e13c0 100644 --- a/tuhi/wacom.py +++ b/tuhi/wacom.py @@ -26,6 +26,7 @@ from .drawing import Drawing from .uhid import UHIDDevice import tuhi.protocol from tuhi.protocol import NordicData, Interactions, Mode, ProtocolVersion +from .util import list2hex logger = logging.getLogger('tuhi.wacom') @@ -108,18 +109,6 @@ def b2hex(bs): return ' '.join([''.join(s) for s in zip(hx[::2], hx[1::2])]) -def list2hex(l, groupsize=8): - '''Converts a list of integers to a two-letter hex string in the form - "1a 2b c3"''' - - 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): '''Converts a list of integers to a two-letter prefixed hex string in the form "[0x1a, 0x32, 0xab]"'''