sacada 999 Bytes
Newer Older
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#!/usr/bin/env python3

from time import sleep
import click
from tqdm import tqdm
from sacada.SACADA import SACADA

@click.group()
@click.option('--port', default="/dev/ttyACM0", help='serial port location eg.: /dev/ttyACM0 (default)')
@click.pass_context
def cli(ctx, port):
    ctx.obj['s'] = SACADA(port)

@cli.command()
@click.pass_context
def show(ctx):
    click.echo(ctx.obj['s'].identify())

@cli.command()
@click.argument('channel')
@click.pass_context
def read(ctx, channel):
    click.echo(ctx.obj['s'].readVoltage(channel))

@cli.command()
@click.argument('channel')
@click.option('--interval', default=1000, help='interval bewteen readings (ms)')
@click.pass_context
def monitor(ctx, channel, interval):
    with tqdm(total=18, desc="Channel {}".format(channel), bar_format="{desc}|{bar}|{n_fmt}V") as bar:
        while True:
            bar.n = ctx.obj['s'].readVoltage(channel)
            bar.refresh()
            sleep(interval/1000.0)

if __name__ == '__main__':
    cli(obj={})