Skip to content

Commit 4f34e35

Browse files
committed
debug: add stderr logging to _capture_oled for CI screenshot diagnosis
1 parent 4ed90c7 commit 4f34e35

1 file changed

Lines changed: 35 additions & 24 deletions

File tree

keepkeylib/client.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -462,33 +462,44 @@ def _check_request(self, msg):
462462

463463
def _capture_oled(self):
464464
"""Capture current OLED layout to screenshot directory."""
465-
if not SCREENSHOT or not self.debug:
465+
if not SCREENSHOT:
466+
return
467+
if not self.debug:
468+
import sys
469+
print("[SCREENSHOT] SKIP: no debug link", file=sys.stderr)
466470
return
467471
try:
468472
layout = self.debug.read_layout()
469-
if layout and len(layout) >= 1024:
470-
layout_bytes = len(layout)
471-
height = 64 if layout_bytes >= 2048 else 32
472-
rows = []
473-
for y in range(height):
474-
row = bytearray(256)
475-
for x in range(256):
476-
byte_idx = x + (y // 8) * 256
477-
if byte_idx < layout_bytes:
478-
b = layout[byte_idx] if isinstance(layout[byte_idx], int) else ord(layout[byte_idx])
479-
if (b >> (y % 8)) & 1:
480-
row[x] = 255
481-
rows.append(bytes(row))
482-
while len(rows) < 64:
483-
rows.append(bytes(256))
484-
screenshot_dir = getattr(self, 'screenshot_dir', os.environ.get('SCREENSHOT_DIR', '.'))
485-
os.makedirs(screenshot_dir, exist_ok=True)
486-
png_path = os.path.join(screenshot_dir, 'btn%05d.png' % self.screenshot_id)
487-
with open(png_path, 'wb') as f:
488-
f.write(_write_png(png_path, 256, 64, rows))
489-
self.screenshot_id += 1
490-
except Exception:
491-
pass
473+
if not layout or len(layout) < 1024:
474+
import sys
475+
print("[SCREENSHOT] SKIP: layout too small (%d bytes)" % (len(layout) if layout else 0), file=sys.stderr)
476+
return
477+
layout_bytes = len(layout)
478+
height = 64 if layout_bytes >= 2048 else 32
479+
rows = []
480+
for y in range(height):
481+
row = bytearray(256)
482+
for x in range(256):
483+
byte_idx = x + (y // 8) * 256
484+
if byte_idx < layout_bytes:
485+
b = layout[byte_idx] if isinstance(layout[byte_idx], int) else ord(layout[byte_idx])
486+
if (b >> (y % 8)) & 1:
487+
row[x] = 255
488+
rows.append(bytes(row))
489+
while len(rows) < 64:
490+
rows.append(bytes(256))
491+
screenshot_dir = getattr(self, 'screenshot_dir', os.environ.get('SCREENSHOT_DIR', '.'))
492+
os.makedirs(screenshot_dir, exist_ok=True)
493+
png_path = os.path.join(screenshot_dir, 'btn%05d.png' % self.screenshot_id)
494+
with open(png_path, 'wb') as f:
495+
f.write(_write_png(png_path, 256, 64, rows))
496+
self.screenshot_id += 1
497+
import sys
498+
print("[SCREENSHOT] OK: %s (%d bytes layout)" % (png_path, layout_bytes), file=sys.stderr)
499+
except Exception as e:
500+
import sys, traceback
501+
print("[SCREENSHOT] ERROR: %s" % e, file=sys.stderr)
502+
traceback.print_exc(file=sys.stderr)
492503

493504
def callback_ButtonRequest(self, msg):
494505
if self.verbose:

0 commit comments

Comments
 (0)