Simple test

Ensure your device works with this simple test.

examples/framebuf_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4import adafruit_framebuf
 5
 6print("framebuf test will draw to the REPL")
 7
 8WIDTH = 32
 9HEIGHT = 8
10
11buffer = bytearray(round(WIDTH * HEIGHT / 8))
12fb = adafruit_framebuf.FrameBuffer(
13    buffer, WIDTH, HEIGHT, buf_format=adafruit_framebuf.MVLSB
14)
15
16# Ascii printer for very small framebufs!
17def print_buffer(the_fb):
18    print("." * (the_fb.width + 2))
19    for y in range(the_fb.height):
20        print(".", end="")
21        for x in range(the_fb.width):
22            if fb.pixel(x, y):
23                print("*", end="")
24            else:
25                print(" ", end="")
26        print(".")
27    print("." * (the_fb.width + 2))
28
29
30# Small function to clear the buffer
31def clear_buffer():
32    for i, _ in enumerate(buffer):
33        buffer[i] = 0
34
35
36print("Shapes test: ")
37fb.pixel(3, 5, True)
38fb.rect(0, 0, fb.width, fb.height, True)
39fb.line(1, 1, fb.width - 2, fb.height - 2, True)
40fb.fill_rect(25, 2, 2, 2, True)
41print_buffer(fb)
42
43print("Text test: ")
44# empty
45fb.fill_rect(0, 0, WIDTH, HEIGHT, False)
46
47# write some text
48fb.text("hello", 0, 0, True)
49print_buffer(fb)
50clear_buffer()
51
52# write some larger text
53fb.text("hello", 8, 0, True, size=2)
54print_buffer(fb)