Last active
June 2, 2022 03:37
-
-
Save imliubo/895d3f0474210952c5000a96a64ca08c to your computer and use it in GitHub Desktop.
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
import sys | |
import m5 | |
from m5 import lcd | |
import lvgl as lv | |
from imagetools import get_png_info, open_png | |
# M5 init auto detect board type | |
m5.begin() | |
# lvgl init | |
lcd.lvgl_init() | |
lcd.clear(0xff) | |
disp_buf1 = lv.disp_draw_buf_t() | |
buf1_1 = bytearray(lcd.width()*10) | |
disp_buf1.init(buf1_1, None, len(buf1_1) // lv.color_t.__SIZE__) | |
# Register display driver | |
disp_drv = lv.disp_drv_t() | |
disp_drv.init() | |
disp_drv.draw_buf = disp_buf1 | |
disp_drv.flush_cb = lcd.lvgl_flush | |
disp_drv.hor_res = lcd.width() | |
disp_drv.ver_res = lcd.height() | |
disp = disp_drv.register() | |
# touch driver init | |
indev_drv = lv.indev_drv_t() | |
indev_drv.init() | |
indev_drv.type = lv.INDEV_TYPE.POINTER | |
indev_drv.read_cb = lcd.lvgl_read | |
indev_drv.register() | |
# Register PNG image decoder | |
decoder = lv.img.decoder_create() | |
decoder.info_cb = get_png_info | |
decoder.open_cb = open_png | |
# Create widget | |
scr = lv.obj() | |
btn = lv.btn(scr) | |
btn.align(lv.ALIGN.CENTER, 0, -50) | |
label = lv.label(btn) | |
label.set_text("LVGL") | |
lv.scr_load(scr) | |
# Create an image from the png file | |
try: | |
with open('res/img/uiflow.png','rb') as f: | |
png_data = f.read() | |
except: | |
print("Could not find uiflow.png") | |
sys.exit() | |
img_cogwheel_argb = lv.img_dsc_t({ | |
'data_size': len(png_data), | |
'data': png_data | |
}) | |
img1 = lv.img(lv.scr_act()) | |
img1.set_src(img_cogwheel_argb) | |
img1.align(lv.ALIGN.CENTER, 0, 0) | |
img2 = lv.img(lv.scr_act()) | |
img2.set_src(lv.SYMBOL.OK + "Accept") | |
img2.align_to(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment