From 869c2d882a281443f66a74a973e1a26ab8352ba6 Mon Sep 17 00:00:00 2001 From: Gino D Date: Sat, 7 Jan 2023 21:02:41 +0100 Subject: [PATCH] Help tab implemented and fixed small bugs --- picowatch | 2 +- src/picowatch.py | 78 ++++++++++++++++++++++++++++-------------------- 2 files changed, 46 insertions(+), 34 deletions(-) diff --git a/picowatch b/picowatch index eb50cb8..59fc0ee 100644 --- a/picowatch +++ b/picowatch @@ -1,3 +1,3 @@ #!/bin/bash -python "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/src/picowatch.py" $(pwd) \ No newline at end of file +python "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)/src/picowatch.py" \ No newline at end of file diff --git a/src/picowatch.py b/src/picowatch.py index f3dfb2c..93d0c12 100644 --- a/src/picowatch.py +++ b/src/picowatch.py @@ -246,7 +246,7 @@ class Pyboard(object): while n > 0: self.serial.read(n) - n = self.serial.inWaiting() + n = self.serial.inWaiting() def read_until(self, delimiter: bytes, stream_output: bool = False, show_status: bool = False) -> Optional[bytes]: data = b'' @@ -271,22 +271,21 @@ class Pyboard(object): time.sleep(0.001) def boot(self): + data = b'' self.send_ctrl_c() self.until_nothing_in_waiting() + time.sleep(.5) if not self.read_until(self.send_ctrl_d()): raise Exception('REPL: could not soft reboot') - data = b'' - while not data.startswith(b'.\r\n>>>'): + while not data.endswith(b'\r\nMicroPython v') and not data.endswith(b'.\r\n>>>'): if self.serial.inWaiting(): - output = self.serial.read(1) - data = data[-5:] + output - sys.stdout.buffer.write(output) + data = data[-15:] + self.serial.read(1) + sys.stdout.buffer.write(data[-1:]) sys.stdout.buffer.flush() - print(' ' + ('=' * 50)) - print('REPL: was interrupted') + sys.stdout.buffer.write(b'\r' + b' ' * 20 + b'\r') def __enter__(self): self.send_ctrl_c() @@ -856,16 +855,29 @@ while True: for message in unmessage.split('&'): try: match message.strip().split(' '): - case ['exit']: - sys.exit('Picowatch Terminal disconnected!') - case ['help']: - print('TODO') - case ['boot']: - picowatch.boot() - case ['whois']: - print('TODO') - case ['reboot']: - picowatch.terminal('help()') + case ['?' | 'help']: + print('These are common Picowatch keywords:\n') + tab = Tab(35, 70) + tab.head('Keywords', 'Description') + tab.line('uname', 'Pyboard name and version') + tab.line('exit | ctrl + c', 'Exit Picowatch Terminal') + tab.line('ctrl + c (while is running)', 'Interrupts the currently running code') + tab.line('ls []', 'List information about the file(s) on the Pyboard (the root directory by default)') + tab.line('cat ', 'Concatenate source code to standard output') + tab.line('rm | delete ', 'Delete file or directory contents on the Pyboard') + tab.line('put | upload ', 'Upload file or directory contents from the PC to the Pyboard') + tab.line('get | download ', 'Download file or directory contents from the Pyboard to the PC. Warning: this may cause file corruption.') + tab.line('diff ', 'Compare source code from Pyboard with source code on PC') + tab.line('mpy | compile ', 'Compile source file to mpy file') + tab.line('install ', 'Install a package lib') + tab.line('status', 'Show the working tree status (Git is required)') + tab.line('push', 'Update Pyboard along with associated files (Git is required)') + tab.line('? | help', 'Show keywords and their description') + tab.line('. | boot', 'Do a soft reset and run main.py (if exists) in REPL mode') + tab.line('! | test []', 'Run a script from PC on the Pyboard and print out the results in raw-REPL mode') + tab.line('!! | run []', 'Run a script on the Pyboard and print out the results in raw-REPL mode') + case ['uname']: + picowatch.terminal('import os;print(os.uname().machine, os.uname().version)') case ['ls' | 'list', *source]: picowatch.listing(source[0] if source else '/') case ['cat' | 'code', source]: @@ -876,27 +888,27 @@ while True: picowatch.upload(source) case ['get' | 'download', source]: picowatch.download(source) - case ['diff' | 'compare', filename]: - picowatch.compare(filename) + case ['diff' | 'compare', source]: + picowatch.compare(source) case ['status']: picowatch.status(return_output=False) case ['push']: picowatch.push() - case ['mpy' | 'compile', filename]: - picowatch.compile(filename) + case ['mpy' | 'compile', source]: + picowatch.compile(source) case ['install', package_name]: - pass - case ['test', filename]: - picowatch.test(filename) - case ['!']: - picowatch.test('main.py') - case ['!!']: - picowatch.launch('main.py') + print('# TODO') + case ['!' | 'test', *source]: + picowatch.test(source[0] if source else 'main.py') + case ['!!' | 'run', *source]: + picowatch.launch(source[0] if source else 'main.py') + case ['.'| 'boot']: + picowatch.boot() + case ['exit']: + sys.exit('Picowatch Terminal disconnected!') case _: - if message.startswith('./'): - picowatch.launch(message[2:]) - elif message: - print(f'"{message}" is not recognized.') + if message: + print(f'Picowatch: "{message}" does not matched any keywords. See "help" for more informations.') except Exception as e: print(str(e)) except (KeyboardInterrupt, EOFError):