From 1a8d22521219cb2708eda343cdbd73ce362dc8b8 Mon Sep 17 00:00:00 2001 From: Jonathan Cave Date: Fri, 13 Nov 2020 14:54:35 +0000 Subject: roundtrip_qr.py: detect the active tty UC20 seems to deviate from the norm of tty1 being the active tty after install. Update the script to detect which is active. --- bin/roundtrip_qr.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'bin') diff --git a/bin/roundtrip_qr.py b/bin/roundtrip_qr.py index e2eb5b5..c3494e2 100755 --- a/bin/roundtrip_qr.py +++ b/bin/roundtrip_qr.py @@ -61,8 +61,14 @@ def generate_qr_code(data): return pyqrcode.create(data) -def display_code(qr): - with open('/dev/tty1', 'wb+', buffering=0) as term: +def get_active_tty(): + with open('/sys/class/tty/tty0/active', 'r') as active_f: + return active_f.read().strip() + + +def display_code(qr, tty): + device = '/dev/{}'.format(tty) + with open(device, 'wb+', buffering=0) as term: # clear the tty so the qr is always printed at the top of the sceen term.write(str.encode('\033c')) # print the qr code @@ -98,8 +104,15 @@ def main(): print('Generating QR code...', flush=True) qr = generate_qr_code(test_str) + tty = 'tty1' + try: + tty = get_active_tty() + print('Identified {} as the active vt'.format(tty)) + except IOError: + print('Failed to read active tty, using default {}'.format(tty)) + print('Displaying on screen', flush=True) - display_code(qr) + display_code(qr, tty) print('Capture image of screen', flush=True) if name == 'vchiq': -- cgit v1.2.3