summaryrefslogtreecommitdiff
diff options
authorPMR <pmr@pmr-lander>2020-11-13 18:00:47 +0000
committerPMR <pmr@pmr-lander>2020-11-13 18:00:47 +0000
commit22dda6a1fa8d68d0466b5cfc87b96e0c5ed36180 (patch)
treecf0bc217abd879e6b014ef91f1f8e7dab621754c
parentbdc86628231781b858ebae9f06d5f9701de3c3d9 (diff)
parent1a8d22521219cb2708eda343cdbd73ce362dc8b8 (diff)
Merge #393725 from ~jocave/plainbox-provider-checkbox:camera-qrcode-tty-detect
-rwxr-xr-xbin/roundtrip_qr.py19
1 files changed, 16 insertions, 3 deletions
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':