From a8f89009a463724b9d4460ad2fb5cc4ff7c91979 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 16 Nov 2017 14:39:57 +0800 Subject: [PATCH 1/2] feat(monitor): add new feature allowing disabling log display. --- docs/get-started/idf-monitor.rst | 8 ++++++++ tools/idf_monitor.py | 20 ++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/docs/get-started/idf-monitor.rst b/docs/get-started/idf-monitor.rst index 4dac96c59..488b96abb 100644 --- a/docs/get-started/idf-monitor.rst +++ b/docs/get-started/idf-monitor.rst @@ -89,6 +89,14 @@ Quick Reset The keyboard shortcut ``Ctrl-T Ctrl-R`` will reset the target board via the RTS line (if it is connected.) +Toggle Output Display +===================== + +Sometimes you may want to stop new output printed to screen, to see the log before. The keyboard shortcut ``Ctrl-T Ctrl-Y`` will +toggle the display (discard all serial data when the display is off) so that you can stop to see the log, and revert +again quickly without quitting the monitor. + + Simple Monitor ============== diff --git a/tools/idf_monitor.py b/tools/idf_monitor.py index 49e2b74b8..d1de35579 100755 --- a/tools/idf_monitor.py +++ b/tools/idf_monitor.py @@ -55,6 +55,7 @@ CTRL_F = '\x06' CTRL_H = '\x08' CTRL_R = '\x12' CTRL_T = '\x14' +CTRL_Y = '\x19' CTRL_RBRACKET = '\x1d' # Ctrl+] # ANSI terminal codes @@ -256,6 +257,7 @@ class Monitor(object): self._pressed_menu_key = False self._read_line = b"" self._gdb_buffer = b"" + self._output_enabled = True def main_loop(self): self.console_reader.start() @@ -299,7 +301,8 @@ class Monitor(object): # this may need to be made more efficient, as it pushes out a byte # at a time to the console for b in data: - self.console.write_bytes(b) + if self._output_enabled: + self.console.write_bytes(b) if b == b'\n': # end of line self.handle_serial_input_line(self._read_line.strip()) self._read_line = b"" @@ -320,10 +323,13 @@ class Monitor(object): self.serial.setRTS(True) time.sleep(0.2) self.serial.setRTS(False) + self.output_enable(True) elif c == CTRL_F: # Recompile & upload self.run_make("flash") elif c == CTRL_A: # Recompile & upload app only self.run_make("app-flash") + elif c == CTRL_Y: # Toggle output display + self.output_toggle() else: red_print('--- unknown menu character {} --'.format(key_description(c))) @@ -340,13 +346,14 @@ class Monitor(object): --- {reset:7} Reset target board via RTS line --- {make:7} Run 'make flash' to build & flash --- {appmake:7} Run 'make app-flash to build & flash app +--- {output:7} Toggle output display """.format(version=__version__, exit=key_description(self.exit_key), menu=key_description(self.menu_key), reset=key_description(CTRL_R), make=key_description(CTRL_F), appmake=key_description(CTRL_A), - + output=key_description(CTRL_Y), ) def __enter__(self): @@ -393,6 +400,8 @@ class Monitor(object): p.wait() if p.returncode != 0: self.prompt_next_action("Build failed") + else: + self.output_enable(True) def lookup_pc_address(self, pc_addr): translation = subprocess.check_output( @@ -430,6 +439,13 @@ class Monitor(object): pass # happens on Windows, maybe other OSes self.prompt_next_action("gdb exited") + def output_enable(self, enable): + self._output_enabled = enable + + def output_toggle(self): + self._output_enabled = not self._output_enabled + yellow_print("\nToggle output display: {}, Type Ctrl-T Ctrl-Y to show/disable output again.".format(self._output_enabled)) + def main(): parser = argparse.ArgumentParser("idf_monitor - a serial output monitor for esp-idf") From cb810ccbe11e6c837720d6efc46061b165a36609 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 30 Nov 2017 12:46:08 +0800 Subject: [PATCH 2/2] feat(monitor): add pause feature. --- docs/get-started/idf-monitor.rst | 8 ++++++++ tools/idf_monitor.py | 13 +++++++++++++ 2 files changed, 21 insertions(+) diff --git a/docs/get-started/idf-monitor.rst b/docs/get-started/idf-monitor.rst index 488b96abb..e1ec23cb3 100644 --- a/docs/get-started/idf-monitor.rst +++ b/docs/get-started/idf-monitor.rst @@ -89,6 +89,14 @@ Quick Reset The keyboard shortcut ``Ctrl-T Ctrl-R`` will reset the target board via the RTS line (if it is connected.) +Pause the Application +===================== + +The keyboard shortcut ``Ctrl-T Ctrl-P`` will reset the target into bootloader, so that the board will run nothing. This is +useful when you want to wait for another device to startup. Then shortcut ``Ctrl-T Ctrl-R`` can be used to restart the +application. + + Toggle Output Display ===================== diff --git a/tools/idf_monitor.py b/tools/idf_monitor.py index d1de35579..21b59a103 100755 --- a/tools/idf_monitor.py +++ b/tools/idf_monitor.py @@ -56,6 +56,7 @@ CTRL_H = '\x08' CTRL_R = '\x12' CTRL_T = '\x14' CTRL_Y = '\x19' +CTRL_P = '\x10' CTRL_RBRACKET = '\x1d' # Ctrl+] # ANSI terminal codes @@ -330,6 +331,16 @@ class Monitor(object): self.run_make("app-flash") elif c == CTRL_Y: # Toggle output display self.output_toggle() + elif c == CTRL_P: + yellow_print("Pause app (enter bootloader mode), press Ctrl-T Ctrl-R to restart") + # to fast trigger pause without press menu key + self.serial.setDTR(False) # IO0=HIGH + self.serial.setRTS(True) # EN=LOW, chip in reset + time.sleep(1.3) # timeouts taken from esptool.py, includes esp32r0 workaround. defaults: 0.1 + self.serial.setDTR(True) # IO0=LOW + self.serial.setRTS(False) # EN=HIGH, chip out of reset + time.sleep(0.45) # timeouts taken from esptool.py, includes esp32r0 workaround. defaults: 0.05 + self.serial.setDTR(False) # IO0=HIGH, done else: red_print('--- unknown menu character {} --'.format(key_description(c))) @@ -347,6 +358,7 @@ class Monitor(object): --- {make:7} Run 'make flash' to build & flash --- {appmake:7} Run 'make app-flash to build & flash app --- {output:7} Toggle output display +--- {pause:7} Reset target into bootloader to pause app via RTS line """.format(version=__version__, exit=key_description(self.exit_key), menu=key_description(self.menu_key), @@ -354,6 +366,7 @@ class Monitor(object): make=key_description(CTRL_F), appmake=key_description(CTRL_A), output=key_description(CTRL_Y), + pause=key_description(CTRL_P), ) def __enter__(self):