This commit is contained in:
jeremygan2021
2026-03-03 22:45:09 +08:00
parent 700bc55657
commit 05f02a1454
14 changed files with 574 additions and 149 deletions

View File

@@ -47,9 +47,9 @@ class Display:
if self.font:
self.font.set_ws(ws)
def text(self, text, x, y, color):
def text(self, text, x, y, color, wait=True):
if self.tft:
self.font.text(self.tft, text, x, y, color)
self.font.text(self.tft, text, x, y, color, wait=wait)
def init_ui(self):
"""初始化 UI 背景"""
@@ -93,3 +93,59 @@ class Display:
self.tft.blit_buffer(rgb565_data, x, y, width, height)
except Exception as e:
print(f"Show image error: {e}")
def show_image_chunk(self, x, y, width, height, data, offset):
"""流式显示图片数据块"""
if not self.tft: return
# ST7789 blit_buffer expects a complete buffer for the window
# But we can calculate which pixels this chunk corresponds to
# This is tricky because blit_buffer sets a window and then writes data.
# If we want to stream, we should probably set the window once and then write chunks.
# But st7789py library might not expose raw write easily without window set.
# Alternative: Calculate the sub-window for this chunk.
# Data is a linear sequence of pixels (2 bytes per pixel)
# We assume data length is even.
try:
# Simple approach: If offset is 0, we set the window for the whole image
# And then write data. But st7789py's blit_buffer does both.
# Let's look at st7789py implementation.
# fill_rect sets window then writes.
# blit_buffer sets window then writes.
# We can use a modified approach:
# If it's the first chunk, set window.
# Then write data.
# But we can't easily modify the library state from here.
# So we calculate the rect for this chunk.
# Total pixels
total_pixels = width * height
# Current pixel offset
pixel_offset = offset // 2
num_pixels = len(data) // 2
# This only works if chunks align with rows, or if we can write partial rows.
# ST7789 supports writing continuous memory.
# Let's try to determine the x, y, w, h for this chunk.
# This is complex if it wraps around lines.
# Easier approach for ESP32 memory constrained environment:
# We just need to use the raw write method of the display driver if available.
if offset == 0:
# Set window for the whole image
self.tft.set_window(x, y, x + width - 1, y + height - 1)
# Write raw data
self.tft.write(None, data)
except Exception as e:
print(f"Show chunk error: {e}")