yhur / arduplot

MIT License
41 stars 7 forks source link

Adds standard input pipe #17

Closed ancebfer closed 11 months ago

ancebfer commented 11 months ago

Adds standard input pipe command line argument.

For example, 1 Hz sine/cosine wave generator with 10 ms sample period (waves.py):

#!/usr/bin/env python3
import math
import time

freq = 1  # Hz
period = 0.01  # s

t = 0
while True:
    x = 2 * math.pi * freq * t
    y1 = math.sin(x)
    y2 = math.cos(x)
    print(y1, y2)
    t += period
    time.sleep(period)

Can be plotted in real time with:

./waves.py | arduplot -n -w 500 -e 10

Also data samples can be logged simultaeously:

./waves.py | tee waves.log | arduplot -n -w 500 -e 10

Captura

yhur commented 11 months ago

Thank you for the good idea and your contribution. I would appreciate if you modify the code a little, and re-request the merge request.

Your code

    if pipe_in:
         fig.canvas.manager.set_window_title('Standard input')
     elif tcp_socket:
         fig.canvas.manager.set_window_title(ser.port)
     else:
         fig.canvas.manager.set_window_title('tcp://localhost:'+str(tcp_socket))

Suggested code

    if stdin_pipe:
        fig.canvas.manager.set_window_title('Standard input')
    elif tcp_socket:
        fig.canvas.manager.set_window_title('tcp://localhost:'+str(tcp_socket))
    else:
        fig.canvas.manager.set_window_title(ser.port)
ancebfer commented 11 months ago

Fixed.

yhur commented 11 months ago

Thank you Antonio for the fix. Please don't mistake me. The reason I asked you to modify is to merge your work under your name so your contribution is well kept.

And the request is to fix the stdin_pipe and also the elif tcp_socket: clause. When you see the original code, that line is if not tcp_socket so it should look like this.

    if stdin_pipe:
        fig.canvas.manager.set_window_title('Standard input')
    elif tcp_socket:
        fig.canvas.manager.set_window_title('tcp://localhost:'+str(tcp_socket))
    else:
        fig.canvas.manager.set_window_title(ser.port)

So I'll merge your code and modify those lines.

Thank you again for your contribution.