Skip to content

Commit

Permalink
Add latency option for app console
Browse files Browse the repository at this point in the history
  • Loading branch information
blavka committed May 17, 2022
1 parent f668648 commit dcbdfeb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/hardwario/chester/cli/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,11 @@ def command_reset(ctx, halt):

@cli.command('console')
@click.option('--reset', is_flag=True, help='Reset application firmware.')
@click.option('--latency', type=int, help='Latency for RTT readout in ms.', show_default=True, default=50)
@click.option('--history-file', type=click.Path(writable=True), show_default=True, default=default_history_file)
@click.option('--console-file', type=click.File('a', 'utf-8'), show_default=True, default=default_console_file)
@click.pass_context
def command_console(ctx, reset, history_file, console_file):
def command_console(ctx, reset, latency, history_file, console_file):
'''Start interactive console for shell and logging.'''
logger.remove(2) # Remove stderr logger

Expand All @@ -75,7 +76,7 @@ def command_console(ctx, reset, history_file, console_file):
if reset:
prog.reset()
prog.go()
console.run(prog, console_file)
console.run(prog, console_file, latency=latency)


def validate_pib_param(ctx, param, value):
Expand Down
13 changes: 11 additions & 2 deletions src/hardwario/chester/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _(event):
clipboard=PyperclipClipboard()
)

def run(self, prog: NRFJProg, console_file):
def run(self, prog: NRFJProg, console_file, latency=50):
channels = prog.rtt_start()

if 'Logger' not in channels:
Expand All @@ -145,6 +145,8 @@ def run(self, prog: NRFJProg, console_file):
if 'Terminal' not in channels:
raise Exception('Not found RTT Terminal channel')

rtt_read_delay = latency / 1000.0

async def task_rtt_read(channel, buffer):
while prog.rtt_is_running:
with logger.catch(message='task_rtt_read', reraise=True):
Expand All @@ -162,7 +164,7 @@ async def task_rtt_read(channel, buffer):

line = line.replace('\r', '')
buffer.set_document(Document(buffer.text + line, None), True)
await asyncio.sleep(0.05)
await asyncio.sleep(rtt_read_delay)

console_file.write(f'{ "*" * 80 }\n')

Expand All @@ -176,6 +178,13 @@ async def task_rtt_read_terminal():
loop.create_task(task_rtt_read_logger())
loop.create_task(task_rtt_read_terminal())

# t1 = threading.Thread(target=task_rtt_read, args=('Logger', self.logger_buffer))
# t2 = threading.Thread(target=task_rtt_read, args=('Terminal', self.shell_buffer))
# t1.daemon = True
# t2.daemon = True
# t1.start()
# t2.start()

def accept(buff):
line = f'{buff.text}\n'.replace('\r', '')
# self.shell_buffer.insert_text(line)
Expand Down

0 comments on commit dcbdfeb

Please sign in to comment.