示例#1
0
def module_test():
    from i2cdevice import I2CDevice
    import time
    logger = Logger()

    logger.debug("Performing module test")

    try:
        i2c_device = I2CDevice(device=I2CDevice.DEV_I2C_1, logger=logger)
    except I2CDeviceError as err:
        logger.fatal("Unable to instantiate Psoc hardware", err)

    psoc_device = PsocI2CDevice(name='psoc device', device=i2c_device)

    for i in range(10):
        msg = psoc_device.recv()
        logger.debug(msg)
        time.sleep(1)
示例#2
0
def load_calibration():
    global CALIBRATION_DATA
    logger = Logger()

    try:
        # To load the calibration data it is necessary to get the absolutate path.  The calibration data is stored in the
        # same directory as this module.  The __file__ attribute contains the needed path information.
        abs_path = os.path.dirname(os.path.abspath(__file__))
        f = open(os.path.join(abs_path, 'bno055.cal'), 'r')
    except IOError as err:
        logger.fatal(
            "Unable to load calibration data from bno055.cal - {}".format(err))
    else:
        with f:
            l = f.readline()
            s = l[1:-1]
            try:
                CALIBRATION_DATA = [int(i) for i in s.split(', ')]
                logger.debug(
                    "Calibration Data Loaded: {}".format(CALIBRATION_DATA))
            except ValueError as err:
                logger.fatal("Invalid calibration data: {} - {}".format(
                    s, err))