Exemplo n.º 1
0
def test_online():
    import imports  # pylint: disable=unused-import
    from kx_lib.kx_board import ConnectionManager
    from kx_lib.kx_util import evkit_config
    from kmx62 import kmx62_data_logger
    from kmx62.kmx62_driver import KMX62Driver

    class CallBack(object):
        def __init__(self):
            self.prediction = Algorithm_prediction()

        def callback(self, data):
            ch, ax, ay, az, mx, my, mz, temp = data
            self.prediction.feed(ax)

            #print("\nThe vacuum cleaner is on the {}".format(self.prediction.result))

    ODR = 50
    callback_object = CallBack()

    connection_manager = ConnectionManager(
        board_config_json='rokix_board_rokix_sensor_node_i2c.json')
    sensor_kmx62 = KMX62Driver()
    try:
        connection_manager.add_sensor(sensor_kmx62)
        kmx62_data_logger.enable_data_logging(sensor_kmx62, odr=ODR)
        stream = kmx62_data_logger.KMX62DataStream([sensor_kmx62])
        stream.read_data_stream(console=False,
                                callback=callback_object.callback)

    finally:
        sensor_kmx62.set_power_off()
        connection_manager.disconnect()
def read_with_stream(sensor, sensor_kmx62, loop):
    stream = bh1726_data_stream(sensor, sensor_kmx62)
    kmx62_data_logger.enable_data_logging(sensor_kmx62,
                                          odr='12p5',
                                          int_number=1)
    stream.read_data_stream(sensor, sensor_kmx62, loop)
    return stream
Exemplo n.º 3
0
def test_online():
    import imports  # pylint: disable=unused-import
    from kx_lib.kx_board import ConnectionManager
    from kx_lib.kx_util import evkit_config
    from kmx62 import kmx62_data_logger
    from kmx62.kmx62_driver import KMX62Driver
    ODR = 50

    connection_manager = ConnectionManager(board_config_json='rokix_board_rokix_sensor_node_i2c.json')
    sensor_kmx62 = KMX62Driver()
    try:
        connection_manager.add_sensor(sensor_kmx62)
        kmx62_data_logger.enable_data_logging(sensor_kmx62, odr=ODR)
        stream = kmx62_data_logger.KMX62DataStream([sensor_kmx62])
        stream.read_data_stream(console=False, callback=callback)

    finally:
        sensor_kmx62.set_power_off()
        connection_manager.disconnect()
Exemplo n.º 4
0
def test_online():
    import imports  # pylint: disable=unused-import
    from kx_lib.kx_board import ConnectionManager
    from kx_lib.kx_util import evkit_config
    from kmx62 import kmx62_data_logger
    from kmx62.kmx62_driver import KMX62Driver

    class CallBack(object):
        def __init__(self):
            self.lateral_g = Algorithm_g_force(['ax', 'ay', 'az'])
            self.longitudinal_g = Algorithm_g_force(['ax', 'ay', 'az'])

        def callback(self, data):
            ch, ax, ay, az, mx, my, mz, temp = data
            self.lateral_g.feed((ay, ax, az))
            self.longitudinal_g.feed((ax, ay, az))
            print('%.02f\t%0.2f' %
                  (self.lateral_g.g_force, self.longitudinal_g.g_force))

    callback_object = CallBack()

    connection_manager = ConnectionManager(
        board_config_json='rokix_board_rokix_sensor_node_i2c.json')
    sensor_kmx62 = KMX62Driver()
    try:
        connection_manager.add_sensor(sensor_kmx62)
        kmx62_data_logger.enable_data_logging(sensor_kmx62,
                                              odr=global_settings.sensor.odr,
                                              max_range_acc='%dG' %
                                              global_settings.sensor.g_range)

        stream = kmx62_data_logger.KMX62DataStream([sensor_kmx62])
        stream.read_data_stream(console=False,
                                callback=callback_object.callback)

    finally:
        sensor_kmx62.set_power_off()
        connection_manager.disconnect()
def read_with_stream(sensor, loop):
    stream = bh1790_data_stream(sensor)
    kmx62_data_logger.enable_data_logging(sensor_kmx62, odr=25, int_number=1)
    stream.read_data_stream(loop)
    return stream
    kmx62_data_logger.enable_data_logging(sensor_kmx62, odr=25, int_number=1)
    stream.read_data_stream(loop)
    return stream


if __name__ == '__main__':
    sensor = bh1790_driver()
    bus = open_bus_or_exit(sensor)
    enable_data_logging(sensor)
    sensor_kmx62 = None

    if evkit_config.get('generic', 'drdy_operation') == 'ADAPTER_GPIO1_INT':
        sensor_kmx62 = kmx62_driver.kmx62_driver()
        bus.probe_sensor(sensor_kmx62)
        kmx62_data_logger.enable_data_logging(sensor_kmx62,
                                              odr='12p5',
                                              int_number=1)

    timing.reset()
    args = get_datalogger_args()
    if args.stream_mode:
        if stream_config_check() is True:
            print "\nBH1790 does not support interrupt pin. Using KMX62 to get drdy.\n"
            read_with_stream(sensor, args.loop)
            sensor_kmx62.set_power_off()
        else:
            logger.error(stream_config_check())
    else:
        read_with_polling(sensor, sensor_kmx62, args.loop)

    sensor.set_power_off()