Simple test¶
Ensure your device works with this simple test.
examples/softkeyboard_simpletest.py¶
1# SPDX-FileCopyrightText: 2023 DJDevon3
2# SPDX-License-Identifier: MIT
3# Started as ESP32-S3 Feather Weather MQTT Touchscreen
4# Coded for Circuit Python 8.2.x
5# Modified for SoftKeyboard by Tim C
6
7import time
8import board
9import displayio
10import terminalio
11from adafruit_display_text import label
12from adafruit_bitmap_font import bitmap_font
13import adafruit_touchscreen
14from soft_keyboard.soft_keyboard import SoftKeyboard, PRINTABLE_CHARACTERS
15
16_now = time.monotonic()
17
18DISPLAY_WIDTH = 480
19DISPLAY_HEIGHT = 320
20
21_touch_flip = (False, True)
22
23# Initialize 3.5" TFT Featherwing Touchscreen
24# ts_cs_pin = digitalio.DigitalInOut(board.D6)
25# touchscreen = adafruit_stmpe610.Adafruit_STMPE610_SPI(
26# board.SPI(),
27# ts_cs_pin,
28# calibration=((231, 3703), (287, 3787)),
29# size=(display.width, display.height),
30# disp_rotation=display.rotation,
31# touch_flip=_touch_flip,
32# )
33
34
35print("Init touchscreen")
36# pylint: disable=no-member
37touchscreen = adafruit_touchscreen.Touchscreen(
38 board.TOUCH_XL,
39 board.TOUCH_XR,
40 board.TOUCH_YD,
41 board.TOUCH_YU,
42 calibration=((6856, 60565), (9337, 56924)),
43 size=(board.DISPLAY.width, board.DISPLAY.height),
44)
45
46
47def _format_date(datetime):
48 return "{:02}/{:02}/{:02}".format(
49 datetime.tm_year,
50 datetime.tm_mon,
51 datetime.tm_mday,
52 )
53
54
55def _format_time(datetime):
56 return "{:02}:{:02}".format(
57 datetime.tm_hour,
58 datetime.tm_min,
59 # datetime.tm_sec,
60 )
61
62
63# Quick Colors for Labels
64TEXT_BLACK = 0x000000
65TEXT_BLUE = 0x0000FF
66TEXT_CYAN = 0x00FFFF
67TEXT_GRAY = 0x8B8B8B
68TEXT_GREEN = 0x00FF00
69TEXT_LIGHTBLUE = 0x90C7FF
70TEXT_MAGENTA = 0xFF00FF
71TEXT_ORANGE = 0xFFA500
72TEXT_PURPLE = 0x800080
73TEXT_RED = 0xFF0000
74TEXT_WHITE = 0xFFFFFF
75TEXT_YELLOW = 0xFFFF00
76
77forkawesome_font = bitmap_font.load_font("/fonts/forkawesome-12.pcf")
78
79input_lbl = label.Label(
80 terminalio.FONT, scale=2, text="", color=0xFFFFFF, background_color=0x00000
81)
82input_lbl.x = 10
83input_lbl.y = 10
84
85# Create subgroups
86splash = displayio.Group()
87text_group = displayio.Group()
88main_group = displayio.Group()
89
90main_group.append(input_lbl)
91board.DISPLAY.root_group = main_group
92
93soft_kbd = SoftKeyboard(
94 2, 100, DISPLAY_WIDTH - 2, DISPLAY_HEIGHT - 100, terminalio.FONT, forkawesome_font
95)
96
97main_group.append(soft_kbd)
98
99print(f"size: {soft_kbd.width}, {soft_kbd.height}")
100print(f"cell size: {soft_kbd.layout.cell_size_pixels}")
101
102while True:
103 p = touchscreen.touch_point
104
105 # print(p)
106 key_value = soft_kbd.check_touches(p)
107 if key_value in PRINTABLE_CHARACTERS:
108 input_lbl.text += key_value
109 elif key_value == 42: # 0x2a backspace key
110 input_lbl.text = input_lbl.text[:-1]