示例#1
0
文件: cli.py 项目: myoung34/tilty
def scan_and_emit_thread(device: tilt_device.TiltDevice,
                         config: configparser.ConfigParser,
                         keep_running: bool = False) -> None:
    """ method that calls the needful

    Args:
        device (TiltDevice): The bluetooth device to operate on.
        config (dict): The parsed configuration
        keep_running (bool): Whether or not to keep running. Default: False
    """
    emitters = parse_config(config)
    click.echo('Scanning for Tilt data...')

    gravity_offset = float(
        safe_get_key(CONFIG, 'general', {}).get('gravity_offset', '0'))
    LOGGER.debug('Gravity offset: %f', gravity_offset)
    temperature_offset = float(
        safe_get_key(CONFIG, 'general', {}).get('temperature_offset', '0'))
    LOGGER.debug('Temperature offset: %f', temperature_offset)

    scan_and_emit(device, emitters, gravity_offset, temperature_offset)
    while keep_running:
        LOGGER.debug('Scanning for Tilt data...')
        try:
            scan_and_emit(device, emitters, gravity_offset, temperature_offset)
        except Exception as exception:  # pylint: disable=broad-except
            LOGGER.error("%s\n%s", str(exception),
                         traceback.format_tb(exception.__traceback__))
        sleep_time = int(CONFIG['general'].get('sleep_interval', '1'))
        LOGGER.debug('Sleeping for %s....', sleep_time)
        sleep(sleep_time)
示例#2
0
文件: cli.py 项目: nalabelle/tilty
def scan_and_emit_thread(device: tilt_device.TiltDevice,
                         config: configparser.ConfigParser,
                         keep_running: threading.Event) -> None:
    """ method that calls the needful

    Args:
        device (TiltDevice): The bluetooth device to operate on.
        config (dict): The parsed configuration
        keep_running (threading.Event): Whether or not to keep running. Default: False
    """
    emitters = parse_config(config)
    click.echo('Scanning for Tilt data...')
    scan_and_emit(device, emitters)
    while keep_running.is_set():
        LOGGER.debug('Scanning for Tilt data...')
        try:
            scan_and_emit(device, emitters)
        except Exception as exception:  # pylint: disable=broad-except
            LOGGER.error("%s\n%s", str(exception),
                         traceback.format_tb(exception.__traceback__))
        sleep_time = int(CONFIG['general'].get('sleep_interval', '1'))
        LOGGER.debug('Sleeping for %s....', sleep_time)
        sleep(sleep_time)