#!/usr/bin/env python3 """ Simplest possible test - half black, half white screen. This verifies the display can show black pixels. """ import sys import asyncio from pathlib import Path from PIL import Image, ImageDraw # Add parent directory to path sys.path.insert(0, str(Path(__file__).parent.parent)) from dreader.hal_hardware import HardwareDisplayHAL def create_simple_test(): """Create a simple half-black, half-white test image.""" print("Creating simple test pattern...") print("Left half: BLACK") print("Right half: WHITE") width, height = 1872, 1404 # Create grayscale image (L mode = 8-bit grayscale) img = Image.new('L', (width, height), color=255) # Start with white draw = ImageDraw.Draw(img) # Draw left half black draw.rectangle( [(0, 0), (width // 2, height)], fill=0 # 0 = black ) print(f"Test image created: {width}x{height} grayscale") print(f" Left half ({width//2}px): BLACK (0)") print(f" Right half ({width//2}px): WHITE (255)") return img async def main(args): """Test hardware display with simple pattern.""" print("=" * 60) print("Simple Display Test - Half Black, Half White") print("=" * 60) print() vcom = args.vcom print(f"Using VCOM: {vcom}V") print() # Create simple test image test_image = create_simple_test() # Save test image for reference output_file = "simple_test.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 pattern on e-ink screen...") print("(This may take a few seconds for the full refresh)") await hal.show_image(test_image) print("✓ Image displayed!") print() print("=" * 60) print("CHECK YOUR SCREEN:") print("=" * 60) print() print("You should see:") print(" • LEFT HALF: BLACK") print(" • RIGHT HALF: WHITE") print() print("If you see this, the display is working!") print("If the screen is all white, there may be a driver issue.") 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='Simple display test') 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)