-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): Add tests for MicroPython test suite.
- Loading branch information
Showing
7 changed files
with
477 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import lvgl as lv | ||
import sys | ||
import asyncio | ||
import os | ||
|
||
sys.path.append("..") | ||
sys.path.append(os.getcwd()) | ||
import testrunner | ||
|
||
# This is a basic test to test buttons, labels, | ||
# RGB colors, layout aligment and events. | ||
|
||
|
||
async def demo(scr, display=None): | ||
def get_button(scr, text, align, color): | ||
_btn = lv.button(scr) | ||
_btn.set_size(lv.pct(25), lv.pct(10)) | ||
_lab = lv.label(_btn) | ||
_lab.set_text(text) | ||
_lab.center() | ||
_btn.set_style_align(align, 0) | ||
_btn.set_style_bg_color(lv.color_make(*color), 0) | ||
return _btn, text | ||
|
||
buttons = [ | ||
("RED", lv.ALIGN.TOP_MID, (255, 0, 0)), | ||
("GREEN", lv.ALIGN.BOTTOM_MID, (0, 255, 0)), | ||
("BLUE", lv.ALIGN.CENTER, (0, 0, 255)), | ||
] | ||
|
||
def button_cb(event, name): | ||
print(f"{name} PRESSED") | ||
|
||
_all_btns = [get_button(scr, *btn) for btn in buttons] | ||
|
||
for btn, name in _all_btns: | ||
btn.add_event_cb( | ||
lambda event, button_name=name: button_cb(event, button_name), | ||
lv.EVENT.CLICKED, | ||
None, | ||
) | ||
|
||
await asyncio.sleep_ms(500) # await so the frame can be rendered | ||
print("EVENT TEST:") | ||
for _btn, name in _all_btns: | ||
_btn.send_event(lv.EVENT.CLICKED, None) | ||
await asyncio.sleep_ms(200) | ||
|
||
return _all_btns | ||
|
||
|
||
__file__ = globals().get("__file__", "test") | ||
|
||
testrunner.run(demo, __file__) | ||
testrunner.devicereset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
|
||
FRAME: 0 (0, 0, 240, 32, 23040) | ||
d5c5d09cff879bb12cb926dc44bf10161cded58d2057806e7cbde536540b1421 | ||
|
||
FRAME: 1 (0, 32, 240, 32, 23040) | ||
f281e1fce42dc013342ad8a4573d74874238d995e6dff46dc29a1d68b780f920 | ||
|
||
FRAME: 2 (0, 64, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 3 (0, 96, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 4 (0, 128, 240, 32, 23040) | ||
424125778438a53da017c2dca09964ec2cec5ad4e2689038dd0e830125112fd8 | ||
|
||
FRAME: 5 (0, 160, 240, 32, 23040) | ||
9abb7f9219bb7ccc8784119c784b1bf41c451f9957989fd2a9fc12a15606b1d0 | ||
|
||
FRAME: 6 (0, 192, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 7 (0, 224, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 8 (0, 256, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 9 (0, 288, 240, 32, 23040) | ||
f546d8ae7340f5fb71e30358ef0d6f33a4f2d72946d9b312444b07fa9d659396 | ||
EVENT TEST: | ||
RED PRESSED | ||
GREEN PRESSED | ||
BLUE PRESSED |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import lvgl as lv | ||
import sys | ||
import asyncio | ||
import os | ||
|
||
sys.path.append("..") | ||
sys.path.append(os.getcwd()) | ||
import testrunner | ||
|
||
# This is a basic test to test buttons, labels, | ||
# RGB colors, layout aligment and events. | ||
|
||
|
||
async def demo(scr, display=None): | ||
def get_button(scr, text, align, color): | ||
_btn = lv.button(scr) | ||
_btn.set_size(lv.pct(25), lv.pct(10)) | ||
_lab = lv.label(_btn) | ||
_lab.set_text(text) | ||
_lab.center() | ||
_btn.set_style_align(align, 0) | ||
_btn.set_style_bg_color(lv.color_make(*color), 0) | ||
return _btn, text | ||
|
||
buttons = [ | ||
("RED", lv.ALIGN.TOP_MID, (255, 0, 0)), | ||
("GREEN", lv.ALIGN.BOTTOM_MID, (0, 255, 0)), | ||
("BLUE", lv.ALIGN.CENTER, (0, 0, 255)), | ||
] | ||
|
||
def button_cb(event, name): | ||
print(f"{name} PRESSED") | ||
|
||
_all_btns = [get_button(scr, *btn) for btn in buttons] | ||
|
||
for btn, name in _all_btns: | ||
btn.add_event_cb( | ||
lambda event, button_name=name: button_cb(event, button_name), | ||
lv.EVENT.CLICKED, | ||
None, | ||
) | ||
|
||
await asyncio.sleep_ms(500) # await so the frame can be rendered | ||
print("EVENT TEST:") | ||
for _btn, name in _all_btns: | ||
_btn.send_event(lv.EVENT.CLICKED, None) | ||
await asyncio.sleep_ms(200) | ||
|
||
# simulate touch events | ||
if display: | ||
print("INDEV TEST:") | ||
await display.touch(100, 100) | ||
|
||
await asyncio.sleep_ms(500) | ||
|
||
print("INDEV + BUTTONS TEST:") | ||
# display.debug_indev(press=False, release=False) | ||
display.display_drv.debug = False | ||
for _btn, name in _all_btns: | ||
pos = _btn.get_x(), _btn.get_y() | ||
await display.touch(*pos) | ||
await asyncio.sleep_ms(1000) | ||
|
||
await asyncio.sleep_ms(500) | ||
|
||
return _all_btns | ||
|
||
|
||
__file__ = globals().get("__file__", "test") | ||
|
||
testrunner.run(demo, __file__) | ||
testrunner.devicereset() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
|
||
FRAME: 0 (0, 0, 240, 32, 23040) | ||
d5c5d09cff879bb12cb926dc44bf10161cded58d2057806e7cbde536540b1421 | ||
|
||
FRAME: 1 (0, 32, 240, 32, 23040) | ||
f281e1fce42dc013342ad8a4573d74874238d995e6dff46dc29a1d68b780f920 | ||
|
||
FRAME: 2 (0, 64, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 3 (0, 96, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 4 (0, 128, 240, 32, 23040) | ||
424125778438a53da017c2dca09964ec2cec5ad4e2689038dd0e830125112fd8 | ||
|
||
FRAME: 5 (0, 160, 240, 32, 23040) | ||
9abb7f9219bb7ccc8784119c784b1bf41c451f9957989fd2a9fc12a15606b1d0 | ||
|
||
FRAME: 6 (0, 192, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 7 (0, 224, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 8 (0, 256, 240, 32, 23040) | ||
46e2096b907947368d310929303a04005b39c4a278e3a7de2225c355b4522694 | ||
|
||
FRAME: 9 (0, 288, 240, 32, 23040) | ||
f546d8ae7340f5fb71e30358ef0d6f33a4f2d72946d9b312444b07fa9d659396 | ||
EVENT TEST: | ||
RED PRESSED | ||
GREEN PRESSED | ||
BLUE PRESSED | ||
INDEV TEST: | ||
[PRESSED]: (100,100) | ||
[RELEASED]: (100,100) | ||
INDEV + BUTTONS TEST: | ||
[PRESSED]: (90,0) | ||
RED PRESSED | ||
[RELEASED]: (90,0) | ||
[PRESSED]: (90,288) | ||
GREEN PRESSED | ||
[RELEASED]: (90,288) | ||
[PRESSED]: (90,144) | ||
BLUE PRESSED | ||
[RELEASED]: (90,144) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from PIL import Image | ||
import sys | ||
import argparse | ||
|
||
parser = argparse.ArgumentParser(description="RGB888 to PNG converter") | ||
parser.add_argument("file", help="file/s name", nargs="*") | ||
|
||
args = parser.parse_args() | ||
|
||
for file in args.file: | ||
with open(file, "rb") as ff: | ||
w, h, cs = ff.readline().split(b":") | ||
width, height = int(w.decode()), int(h.decode()) | ||
frame = ff.read() | ||
assert len(frame) == width * height * int(cs) | ||
|
||
image = Image.new("RGB", (width, height)) | ||
image.frombytes(frame) | ||
image.save(file.replace(".bin", ".png"), "PNG") | ||
image.close() |
Oops, something went wrong.