forked from Blockstream/Jade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
jade_capture_image_data.py
executable file
·49 lines (38 loc) · 1.29 KB
/
jade_capture_image_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
import sys
import time
import logging
from jadepy import JadeAPI
LOGGING = logging.INFO
QR = True
# Enable jade logging
if LOGGING:
jadehandler = logging.StreamHandler()
jadehandler.setLevel(LOGGING)
logger = logging.getLogger('jadepy.jade')
logger.setLevel(LOGGING)
logger.addHandler(jadehandler)
device_logger = logging.getLogger('jadepy.jade-device')
device_logger.setLevel(LOGGING)
device_logger.addHandler(jadehandler)
if len(sys.argv) > 1 and sys.argv[1] == 'ble':
print('Fetching jade version info over BLE')
serial_number = sys.argv[2] if len(sys.argv) > 2 else None
create_jade_fn = JadeAPI.create_ble
kwargs = {'serial_number': serial_number}
else:
print('Fetching jade version info over serial')
serial_device = sys.argv[1] if len(sys.argv) > 1 else None
create_jade_fn = JadeAPI.create_serial
kwargs = {'device': serial_device, 'timeout': 120}
print("Connecting...")
with create_jade_fn(**kwargs) as jade:
try:
verinfo = jade.get_version_info()
print(f'Connected: {verinfo}')
image_data = jade.capture_image_data(check_qr=QR)
assert image_data
with open('capture.dat', 'wb') as f:
f.write(image_data)
except Exception as e:
print("ERROR:", repr(e))