202 lines
6.0 KiB
Python
Executable File
202 lines
6.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Simple test to verify the hardware HAL can display images.
|
|
Creates a test pattern and displays it on the e-ink screen.
|
|
"""
|
|
|
|
import sys
|
|
import asyncio
|
|
from pathlib import Path
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
# Add parent directory to path
|
|
sys.path.insert(0, str(Path(__file__).parent.parent))
|
|
|
|
from dreader.hal_hardware import HardwareDisplayHAL
|
|
|
|
|
|
def create_test_image(width=1404, height=1872 ):
|
|
"""Create a test pattern image."""
|
|
print("Creating test image...")
|
|
|
|
# Create white background
|
|
img = Image.new('RGBA', (width, height), color='white')
|
|
draw = ImageDraw.Draw(img)
|
|
|
|
# Draw border
|
|
border_width = 10
|
|
draw.rectangle(
|
|
[(border_width, border_width),
|
|
(width - border_width, height - border_width)],
|
|
outline='black',
|
|
width=border_width
|
|
)
|
|
|
|
# Draw title
|
|
try:
|
|
font_large = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", 80)
|
|
font_medium = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 50)
|
|
except:
|
|
font_large = ImageFont.load_default()
|
|
font_medium = ImageFont.load_default()
|
|
|
|
# Center text
|
|
title = "Hardware Display Test"
|
|
title_bbox = draw.textbbox((0, 0), title, font=font_large)
|
|
title_width = title_bbox[2] - title_bbox[0]
|
|
title_x = (width - title_width) // 2
|
|
draw.text((title_x, 100), title, fill='black', font=font_large)
|
|
|
|
# Instructions
|
|
instructions = [
|
|
"If you can see this, the display is working!",
|
|
"",
|
|
"Test pattern includes:",
|
|
"• Border around the screen",
|
|
"• Centered text",
|
|
"• Diagonal lines",
|
|
"• Corner markers"
|
|
]
|
|
|
|
y = 250
|
|
for line in instructions:
|
|
if line:
|
|
bbox = draw.textbbox((0, 0), line, font=font_medium)
|
|
line_width = bbox[2] - bbox[0]
|
|
x = (width - line_width) // 2
|
|
draw.text((x, y), line, fill='black', font=font_medium)
|
|
y += 70
|
|
|
|
# Draw diagonal lines
|
|
draw.line([(50, 50), (width-50, height-50)], fill='black', width=3)
|
|
draw.line([(width-50, 50), (50, height-50)], fill='black', width=3)
|
|
|
|
# Draw corner markers
|
|
marker_size = 100
|
|
# Top-left
|
|
draw.rectangle([(20, 20), (20 + marker_size, 20 + marker_size)],
|
|
fill='black')
|
|
draw.text((30, 30), "TL", fill='white', font=font_medium)
|
|
|
|
# Top-right
|
|
draw.rectangle([(width - 20 - marker_size, 20),
|
|
(width - 20, 20 + marker_size)],
|
|
fill='black')
|
|
draw.text((width - 100, 30), "TR", fill='white', font=font_medium)
|
|
|
|
# Bottom-left
|
|
draw.rectangle([(20, height - 20 - marker_size),
|
|
(20 + marker_size, height - 20)],
|
|
fill='black')
|
|
draw.text((30, height - 100), "BL", fill='white', font=font_medium)
|
|
|
|
# Bottom-right
|
|
draw.rectangle([(width - 20 - marker_size, height - 20 - marker_size),
|
|
(width - 20, height - 20)],
|
|
fill='black')
|
|
draw.text((width - 100, height - 100), "BR", fill='white', font=font_medium)
|
|
|
|
print(f"Test image created: {width}x{height} RGBA")
|
|
return img
|
|
|
|
|
|
async def main(args):
|
|
"""Test hardware display."""
|
|
|
|
print("=" * 60)
|
|
print("Hardware Display Test")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
# Get VCOM from args
|
|
vcom = args.vcom if hasattr(args, 'vcom') else -1.65
|
|
print(f"Using VCOM: {vcom}V")
|
|
print()
|
|
|
|
# Create test image
|
|
test_image = create_test_image(1872, 1404)
|
|
|
|
# Save test image for reference
|
|
output_file = "test_pattern.png"
|
|
test_image.save(output_file)
|
|
print(f"Test pattern saved to: {output_file}")
|
|
print()
|
|
|
|
# Initialize hardware HAL
|
|
print("Initializing hardware HAL...")
|
|
hal = HardwareDisplayHAL(
|
|
width=1872,
|
|
height=1404,
|
|
vcom=vcom,
|
|
config_file="hardware_config.json"
|
|
)
|
|
|
|
print("Initializing hardware components...")
|
|
await hal.initialize()
|
|
print("✓ Hardware initialized")
|
|
print()
|
|
|
|
# Display the test image
|
|
print("Displaying test image on e-ink screen...")
|
|
print("(This may take a few seconds for the full refresh)")
|
|
print(f"Converting image from {test_image.mode} to grayscale for e-ink...")
|
|
|
|
# Convert RGBA to grayscale (L mode) for e-ink display
|
|
if test_image.mode == 'RGBA':
|
|
# Convert RGBA to RGB first (flatten alpha)
|
|
rgb_image = Image.new('RGB', test_image.size, (255, 255, 255))
|
|
rgb_image.paste(test_image, mask=test_image.split()[3]) # Use alpha as mask
|
|
test_image_gray = rgb_image.convert('L')
|
|
else:
|
|
test_image_gray = test_image.convert('L')
|
|
|
|
print(f"Image converted to {test_image_gray.mode} mode")
|
|
await hal.show_image(test_image_gray)
|
|
print("✓ Image displayed!")
|
|
print()
|
|
|
|
print("=" * 60)
|
|
print("SUCCESS!")
|
|
print("=" * 60)
|
|
print()
|
|
print("If you can see the test pattern on the screen, the")
|
|
print("hardware display is working correctly!")
|
|
print()
|
|
print("Check that you can see:")
|
|
print(" • Black border around the edges")
|
|
print(" • Title text centered at the top")
|
|
print(" • Diagonal lines crossing the screen")
|
|
print(" • Corner markers labeled TL, TR, BL, BR")
|
|
print()
|
|
print("Press Ctrl+C to exit")
|
|
print()
|
|
|
|
# Keep running so user can see the image
|
|
try:
|
|
while True:
|
|
await asyncio.sleep(1)
|
|
except KeyboardInterrupt:
|
|
print("\nCleaning up...")
|
|
await hal.cleanup()
|
|
print("Done!")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
import argparse
|
|
|
|
parser = argparse.ArgumentParser(description='Test hardware display')
|
|
parser.add_argument('--vcom', type=float, default=-1.65,
|
|
help='VCOM voltage (check your display label, default: -1.65)')
|
|
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
asyncio.run(main(args))
|
|
except KeyboardInterrupt:
|
|
print("\nTest interrupted")
|
|
except Exception as e:
|
|
print(f"\nERROR: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|