Add a utility function module
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
parent
91203701cf
commit
541077a65b
|
@ -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)
|
|
@ -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]"'''
|
||||
|
|
Loading…
Reference in New Issue