Skip to content

Commit

Permalink
parametrize paths
Browse files Browse the repository at this point in the history
  • Loading branch information
mc-cat-tty committed Mar 22, 2021
1 parent 513d714 commit bf432a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
9 changes: 5 additions & 4 deletions tools/bitmap_over_fifo.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def clear(self) -> None:
self.__check_ack()


def main(fifo_path: str, show: bool, toggle_animation: bool, stop_animation: bool, refresh_rate: int, clear: bool, use_stdin: bool):
with open('fifo.in', 'wb', 0) as fifo_out, open('fifo.out', 'rb', 0) as fifo_in:
def main(fifo_path_in: str, fifo_path_out: str, show: bool, toggle_animation: bool, stop_animation: bool, refresh_rate: int, clear: bool, use_stdin: bool):
with open(fifo_path_in, 'wb', 0) as fifo_out, open(fifo_path_out, 'rb', 0) as fifo_in:
fd_in = fifo_in.fileno()
os.set_blocking(fd_in, True)

Expand All @@ -146,7 +146,8 @@ def main(fifo_path: str, show: bool, toggle_animation: bool, stop_animation: boo

if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--fifo', help='Named pipe (FIFO) path', type=str, default='fifo')
parser.add_argument('--fifo-in', help='Named pipe (FIFO) for UART communication (debug_uart.py). Input endpoint', type=str, default='fifo.in')
parser.add_argument('--fifo-out', help='Named pipe (FIFO) for UART communication (debug_uart.py). Output endpoint', type=str, default='fifo.out')
parser.add_argument('-s', '--show', help='Show piped image (on the PC) before sending', default=False, action='store_true')
parser.add_argument('--toggle-animation', help='Start animation on the target device. Inhibit default behavior (send bitmap). No piped image', default=False, action='store_true')
parser.add_argument('--stop-animation', help='Stop animation on the target device. Inhibit default behavior (send bitmap). No piped image', default=False, action='store_true')
Expand All @@ -156,5 +157,5 @@ def main(fifo_path: str, show: bool, toggle_animation: bool, stop_animation: boo

parser.add_argument('--clear', help='Clear frame buffer stored on the embedded device. Inhibit default behavior (send bitmap). No piped image', default=False, action='store_true')
args = parser.parse_args()
main(args.fifo, args.show, args.toggle_animation, args.stop_animation, args.refresh_rate, args.clear, args.nostdin)
main(args.fifo_in, args.fifo_out, args.show, args.toggle_animation, args.stop_animation, args.refresh_rate, args.clear, args.nostdin)

17 changes: 9 additions & 8 deletions tools/uart_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ def create_fifo(path: str) -> None:
def delete_fifo(path: str) -> None:
os.unlink(path)

def main(port: str, fifo_path: str) -> None:
create_fifo('fifo.in')
create_fifo('fifo.out')
def main(port: str, fifo_path_in: str, fifo_path_out: str) -> None:
create_fifo(fifo_path_in)
create_fifo(fifo_path_out)
try:
with serial.Serial(port=port, baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0) as uart, open('fifo.in', 'rb', 0) as fifo_in, open('fifo.out', 'wb', 0) as fifo_out:
with serial.Serial(port=port, baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=0) as uart, open(fifo_path_in, 'rb', 0) as fifo_in, open(fifo_path_out, 'wb', 0) as fifo_out:
fd_in = fifo_in.fileno()
os.set_blocking(fd_in, False)
uart.flushInput()
Expand All @@ -51,14 +51,15 @@ def main(port: str, fifo_path: str) -> None:

except Exception as e:
logging.debug(e)
delete_fifo('fifo.in')
delete_fifo('fifo.out')
delete_fifo(fifo_path_in)
delete_fifo(fifo_path_out)


if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG, filemode="a", format="%(asctime)s - %(levelname)s -> %(message)s")
parser = argparse.ArgumentParser()
parser.add_argument('-p', '--port', help='Serial port name', type=str, default=SERIAL_PORT_NAME)
parser.add_argument('-f', '--fifo', help='Named pipe (FIFO) for UART communication (debug_uart.py)', type=str, default='fifo')
parser.add_argument('--fifo-in', help='Named pipe (FIFO) for UART communication (debug_uart.py). Input endpoint', type=str, default='fifo.in')
parser.add_argument('--fifo-out', help='Named pipe (FIFO) for UART communication (debug_uart.py). Output endpoint', type=str, default='fifo.out')
args = parser.parse_args()
main(args.port, args.fifo)
main(args.port, args.fifo_in, args.fifo_out)

0 comments on commit bf432a6

Please sign in to comment.