def init_gui_stm32(self): import rk043fn48h as lcd hres = 480 vres = 272 # Register display driver self.event_loop = event_loop() lcd.init(w=hres, h=vres) disp_buf1 = lv.disp_draw_buf_t() buf1_1 = bytearray(hres * 50 * lv.color_t.__SIZE__) buf1_2 = bytearray(hres * 50 * lv.color_t.__SIZE__) disp_buf1.init(buf1_1, buf1_2, len(buf1_1) // lv.color_t.__SIZE__) disp_drv = lv.disp_drv_t() disp_drv.init() disp_drv.draw_buf = disp_buf1 disp_drv.flush_cb = lcd.flush disp_drv.hor_res = hres disp_drv.ver_res = vres disp_drv.register() # Register touch sensor indev_drv = lv.indev_drv_t() indev_drv.init() indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.read_cb = lcd.ts_read indev_drv.register()
def init_gui_SDL(self): import SDL SDL.init(auto_refresh=False) self.event_loop = event_loop(refresh_cb=SDL.refresh) # Register SDL display driver. disp_buf1 = lv.disp_draw_buf_t() buf1_1 = bytes(480 * 10) disp_buf1.init(buf1_1, None, len(buf1_1) // 4) disp_drv = lv.disp_drv_t() disp_drv.init() disp_drv.draw_buf = disp_buf1 disp_drv.flush_cb = SDL.monitor_flush disp_drv.hor_res = 480 disp_drv.ver_res = 320 disp_drv.register() # Regsiter SDL mouse driver indev_drv = lv.indev_drv_t() indev_drv.init() indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.read_cb = SDL.mouse_read indev_drv.register()
def init_gui_SDL(self): import SDL SDL.init(w=self.width, h=self.height, auto_refresh=False) self.event_loop = lv_utils.event_loop(refresh_cb=SDL.refresh) # Register SDL display driver. disp_buf1 = lv.disp_draw_buf_t() buf1_1 = bytearray(self.width * 10) disp_buf1.init(buf1_1, None, len(buf1_1) // 4) disp_drv = lv.disp_drv_t() disp_drv.init() disp_drv.draw_buf = disp_buf1 disp_drv.flush_cb = SDL.monitor_flush disp_drv.hor_res = self.width disp_drv.ver_res = self.height disp_drv.register() # Register SDL mouse driver indev_drv = lv.indev_drv_t() indev_drv.init() indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.read_cb = SDL.mouse_read indev_drv.register() self.type = "SDL" print("Running the SDL lvgl version")
import ustruct as struct import lodepng as png import lvgl as lv from lv_utils import event_loop lv.init() lv.log_register_print_cb(lambda msg: print('%s' % msg)) if not event_loop.is_running(): import SDL SDL.init() # Register SDL display driver. disp_buf1 = lv.disp_draw_buf_t() buf1_1 = bytes(480 * 10) disp_buf1.init(buf1_1, None, len(buf1_1) // 4) disp_drv = lv.disp_drv_t() disp_drv.init() disp_drv.draw_buf = disp_buf1 disp_drv.flush_cb = SDL.monitor_flush disp_drv.hor_res = 480 disp_drv.ver_res = 320 disp_drv.register() # Regsiter SDL mouse driver indev_drv = lv.indev_drv_t() indev_drv.init() indev_drv.type = lv.INDEV_TYPE.POINTER
def __init__(self, m5stack=M5Stack(), miso=5, mosi=18, clk=19, cs=13, dc=12, backlight=100, backlight_on=1, power_on=1, spihost=esp.HSPI_HOST, mhz=40, factor=4, hybrid=True, width=240, height=320, start_x=0, start_y=0, invert=False, double_buffer=True, half_duplex=True, display_type=0, asynchronous=False, initialize=True): # Initializations if not lv.is_initialized(): lv.init() self.asynchronous = asynchronous self.initialize = initialize self.m5stack = m5stack self.width = width self.height = height self.start_x = start_x self.start_y = start_y self.miso = miso self.mosi = mosi self.clk = clk self.cs = cs self.dc = dc self.backlight = backlight self.backlight_on = backlight_on self.power_on = power_on self.spihost = spihost self.mhz = mhz self.factor = factor self.hybrid = hybrid self.half_duplex = half_duplex self.display_type = display_type self.buf_size = (self.width * self.height * lv.color_t.__SIZE__) // factor if invert: self.init_cmds.append({'cmd': 0x21}) # Register display driver self.buf1 = esp.heap_caps_malloc(self.buf_size, esp.MALLOC_CAP.DMA) self.buf2 = esp.heap_caps_malloc( self.buf_size, esp.MALLOC_CAP.DMA) if double_buffer else None if self.buf1 and self.buf2: print("Double buffer") elif self.buf1: print("Single buffer") else: raise RuntimeError( "Not enough DMA-able memory to allocate display buffer") self.disp_buf = lv.disp_draw_buf_t() self.disp_drv = lv.disp_drv_t() self.disp_buf.init(self.buf1, self.buf2, self.buf_size // lv.color_t.__SIZE__) self.disp_drv.init() self.disp_spi_init() self.disp_drv.user_data = { 'dc': self.dc, 'spi': self.spi, 'dt': self.display_type, 'start_x': self.start_x, 'start_y': self.start_y } self.disp_drv.draw_buf = self.disp_buf self.disp_drv.flush_cb = esp.ili9xxx_flush if hybrid and hasattr( esp, 'ili9xxx_flush') else self.flush self.disp_drv.monitor_cb = self.monitor self.disp_drv.hor_res = self.width self.disp_drv.ver_res = self.height if self.initialize: self.init() if not lv_utils.event_loop.is_running(): self.event_loop = lv_utils.event_loop( asynchronous=self.asynchronous)
#lvgl python test case import lvgl as lv lv.init() import display display.init() draw_buf = lv.disp_draw_buf_t() buf1_1 = bytearray(51200) buf1_2 = bytearray(51200) draw_buf.init(buf1_1, buf1_2, 25600) disp_drv = lv.disp_drv_t() disp_drv.init() disp_drv.draw_buf = draw_buf disp_drv.flush_cb = display.flush disp_drv.hor_res = 320 disp_drv.ver_res = 240 disp_drv.register() indev_drv = lv.indev_drv_t() indev_drv.init() indev_drv.read_cb = display.touch_read indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.register() scr = lv.obj() btn = lv.btn(scr) btn.align_to(lv.scr_act(), lv.ALIGN.CENTER, 0, 0) label = lv.label(btn) label.set_text("Hello World!") lv.scr_load(scr)