|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025 Tim C for Adafruit Industries |
| 2 | +# SPDX-FileCopyrightText: Copyright (c) 2025 Anne Barela for Adafruit Industries |
| 3 | +# |
| 4 | +# SPDX-License-Identifier: MIT |
| 5 | +# |
| 6 | +# Make a simple terminalio.Terminal using an LVGL .bin font |
| 7 | +# Shows use of required OnDiskFont function |
| 8 | +# |
| 9 | +import gc |
| 10 | +from terminalio import Terminal |
| 11 | +import displayio |
| 12 | +from lvfontio import OnDiskFont |
| 13 | +from adafruit_fruitjam.peripherals import request_display_config |
| 14 | +import supervisor |
| 15 | + |
| 16 | +# Use the easy library call to set the resolution |
| 17 | +request_display_config(640, 480) |
| 18 | + |
| 19 | +print(f"\nfree: {gc.mem_free()}") |
| 20 | + |
| 21 | +# Initialize display |
| 22 | + |
| 23 | +main_group = displayio.Group() |
| 24 | +display = supervisor.runtime.display |
| 25 | +display.root_group = main_group |
| 26 | + |
| 27 | +print(f"free: {gc.mem_free()}") |
| 28 | + |
| 29 | +font = OnDiskFont("fonts/cp437_16h.bin") # LVGL .bin font |
| 30 | + |
| 31 | +char_size = font.get_bounding_box() |
| 32 | +print(f"Character size: {char_size}") |
| 33 | +screen_size = (display.width // char_size[0], display.height // char_size[1]) |
| 34 | +print(f"Screen size: {screen_size}") |
| 35 | + |
| 36 | +terminal_palette = displayio.Palette(2) |
| 37 | +terminal_palette[0] = 0x000000 |
| 38 | +terminal_palette[1] = 0xFFFFFF |
| 39 | + |
| 40 | +print(f"free: {gc.mem_free()}") |
| 41 | +terminal_area = displayio.TileGrid( |
| 42 | + bitmap=font.bitmap, |
| 43 | + width=screen_size[0], |
| 44 | + height=screen_size[1], |
| 45 | + tile_width=char_size[0], |
| 46 | + tile_height=char_size[1], |
| 47 | + pixel_shader=terminal_palette, |
| 48 | +) |
| 49 | + |
| 50 | +main_group.append(terminal_area) |
| 51 | +terminal = Terminal(terminal_area, font) |
| 52 | + |
| 53 | +message = " Hello World\n This is LVGL text\r\n " |
| 54 | +terminal.write(message) |
| 55 | + |
| 56 | +while True: |
| 57 | + pass |
0 commit comments