Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PicoDisplay: Fix misalignment on rotated Pico Displays (fixes #562.) #912

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

Gadgetoid
Copy link
Member

@Gadgetoid Gadgetoid commented Mar 18, 2024

Test script, modified from the repro provided in #562 -

from picographics import PicoGraphics, DISPLAY_PICO_DISPLAY, PEN_P4
import time


def draw_outline(rotate):
    display = PicoGraphics(display=DISPLAY_PICO_DISPLAY, pen_type=PEN_P4, rotate=rotate)

    W, H = display.get_bounds()
    
    MIN_X = 0
    MIN_Y = 0
    
    MAX_X = W - 1
    MAX_Y = H - 1

    print(W, H)

    RED = display.create_pen(255, 0, 0)
    GREEN = display.create_pen(0, 255, 0)
    BLUE = display.create_pen(0, 0, 255)
    WHITE = display.create_pen(255, 255, 255)
    BLACK = display.create_pen(0, 0, 0)
    
    colours = [RED, GREEN, BLUE, WHITE]

    display.set_pen(BLACK)
    display.clear()
    display.set_pen(colours[rotate // 90])
    display.line(MIN_X, MIN_Y, MAX_X, MIN_Y)
    display.line(MAX_X, MIN_Y, MAX_X, MAX_Y)
    display.line(MAX_X, MAX_Y, MIN_X, MAX_Y)
    display.line(MIN_X, MAX_Y, MIN_X, MIN_Y)
    
    display.text(f"angle: {rotate}", 5, 5)
    
    display.update()


while True:
    for a in [0, 90, 180, 270]:
        print(f"angle: {a} degrees")
        draw_outline(a)
        time.sleep(1)

Pico Display would have a pixel offset at 90 and 180 degree rotations.

Add a special case offset tweak for these, and demystify the rotate_180 variable.
@Gadgetoid Gadgetoid merged commit 4c44b77 into main Apr 17, 2024
28 checks passed
@Gadgetoid Gadgetoid deleted the patch-picodisplay-180 branch October 31, 2024 10:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant