#!/usr/bin/env python3
#
# BTZen - Bluetooh Smart sensor reading library.
#
# Copyright (C) 2015-2017 by Artur Wroblewski <wrobell@riseup.net>
#
# 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 3 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.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import argparse
import logging
import time

import btzen

logging.basicConfig(level=logging.DEBUG)

parser = argparse.ArgumentParser()
parser.add_argument('device', help='MAC address of device')
args = parser.parse_args()

print('connecting to {}...'.format(args.device))
sensor = btzen.Pressure(args.device)
sensor.connect()

# not many pressure value changes
start = time.monotonic()
for i in range(10):
    print(sensor.read())
    time.sleep(0.1)
print('elapsed {:.4f}'.format(time.monotonic() - start))

# expected more pressure value changes
sensor.set_interval(0.1)
start = time.monotonic()
for i in range(10):
    print(sensor.read())
    time.sleep(0.1)
print('elapsed {:.4f}'.format(time.monotonic() - start))

sensor.close()

# vim: sw=4:et:ai
