This commit is contained in:
jeremygan2021
2026-03-05 22:02:01 +08:00
parent 9558ea4b35
commit 2392d0d705
2 changed files with 30 additions and 51 deletions

41
main.py
View File

@@ -119,22 +119,21 @@ def process_message(msg, display, image_state, image_data_list, printer_uart=Non
if isinstance(msg, (bytes, bytearray)):
if image_state == IMAGE_STATE_RECEIVING:
try:
if len(image_data_list) < 3:
if len(image_data_list) < 2:
# 异常情况,重置
return IMAGE_STATE_IDLE, None
width = image_data_list[0]
height = image_data_list[1]
current_offset = image_data_list[2]
img_size = image_data_list[0]
current_offset = image_data_list[1]
# Stream directly to display
if display and display.tft:
x = (240 - width) // 2
y = (240 - height) // 2
display.show_image_chunk(x, y, width, height, msg, current_offset)
x = (240 - img_size) // 2
y = (240 - img_size) // 2
display.show_image_chunk(x, y, img_size, img_size, msg, current_offset)
# Update offset
image_data_list[2] += len(msg)
image_data_list[1] += len(msg)
except Exception as e:
print(f"Stream image error: {e}")
@@ -196,28 +195,22 @@ def process_message(msg, display, image_state, image_data_list, printer_uart=Non
try:
parts = msg.split(":")
size = int(parts[1])
img_size = int(parts[2]) if len(parts) > 2 else 64
model_name = parts[3] if len(parts) > 3 else "Unknown Model"
width = 64
height = 64
print(f"Image start, size: {size}, img_size: {img_size}")
convert_img.print_model_info(model_name)
if len(parts) >= 4:
width = int(parts[2])
height = int(parts[3])
elif len(parts) == 3:
width = int(parts[2])
height = int(parts[2]) # assume square
print(f"Image start, size: {size}, dim: {width}x{height}")
image_data_list.clear()
image_data_list.append(width) # index 0
image_data_list.append(height) # index 1
image_data_list.append(0) # index 2: offset
image_data_list.append(img_size) # Store metadata at index 0
image_data_list.append(0) # Store current received bytes offset at index 1
# Prepare display for streaming
if display and display.tft:
# Clear screen area where image will be
# optional, but good practice if new image is smaller
pass
# Calculate position
x = (240 - img_size) // 2
y = (240 - img_size) // 2
# Pre-set window (this will be done in first chunk call)
return IMAGE_STATE_RECEIVING, None
except Exception as e: