Tools: allow to decode devid in hex

This commit is contained in:
Lucas De Marchi 2018-09-12 09:01:47 -07:00 committed by Lucas De Marchi
parent 34fb98b1e0
commit e85b37ffc4

View File

@ -9,6 +9,13 @@ the sensor library, such as libraries/AP_Compass/AP_Compass_Backend.h
import sys import sys
import optparse import optparse
def num(s):
try:
return int(s)
except ValueError:
return int(s, 16)
parser = optparse.OptionParser("decode_devid.py") parser = optparse.OptionParser("decode_devid.py")
parser.add_option("-C", "--compass", action='store_true', help='decode compass IDs') parser.add_option("-C", "--compass", action='store_true', help='decode compass IDs')
parser.add_option("-I", "--imu", action='store_true', help='decode IMU IDs') parser.add_option("-I", "--imu", action='store_true', help='decode IMU IDs')
@ -19,7 +26,7 @@ if len(args) == 0:
print("Please supply a device ID") print("Please supply a device ID")
sys.exit(1) sys.exit(1)
devid=int(args[0]) devid=num(args[0])
bus_type=devid & 0x07 bus_type=devid & 0x07
bus=(devid>>3) & 0x1F bus=(devid>>3) & 0x1F