feat(monitor): add new feature allowing disabling log display.

This commit is contained in:
michael 2017-11-16 14:39:57 +08:00 committed by Ivan Grokhotkov
parent 5afafb0050
commit c015dd6c41
2 changed files with 26 additions and 2 deletions

View file

@ -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
==============

View file

@ -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")