This code is uploaded to esp32, On clicking the button 9, going into the btn9_event_cb(e) function and the bar is not showing, instead parser() function is calling, afterwards bar is displayed in the display.
I Need to display bar then parser function need to execute.
I’m New to LVGL, pls provide the solution for this.
import ubinascii
import machine
from time import sleep,time
import os
from machine import Pin
from machine import Pin, SoftI2C
from micropython import const
push_button = Pin(14, Pin.IN)
i2c = machine.I2C(scl=machine.Pin(5), sda=machine.Pin(4))
import usys as sys
sys.path.append('') # See: https://github.com/micropython/micropython/issues/6419
import lv_utils
import lvgl as lv
from time import sleep
from ili9341 import ili9341
disp = ili9341(rot = 0x20, width=320, height=240)
from xpt2046 import xpt2046
#touch = xpt2046()
touch = xpt2046(transpose=False, cal_x0 = 3622, cal_y0 = 3327, cal_x1 = 182, cal_y1 = 341)
scr1 = lv.obj()
scr2 = lv.obj()
scr3 = lv.obj()
scr4 = lv.obj()
scr5 = lv.obj()
scr6 = lv.obj()
lv.scr_load(scr1)
btn0 = lv.btn(scr1)
btn0.align(lv.ALIGN.CENTER, 0, -80)
label = lv.label(btn0)
label.set_text("Machine1")
btn1 = lv.btn(scr1)
btn1.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn1)
label.set_text("Start New Ste")
btn2 = lv.btn(scr1)
btn2.align(lv.ALIGN.CENTER, 0, 60)
label = lv.label(btn2)
label.set_text("Resume Step")
btn3 = lv.btn(scr2)
btn3.align(lv.ALIGN.CENTER, 0, 0)
label = lv.label(btn3)
label.set_text("Show Show")
start_btn = lv.btn(scr3)
start_btn.align(lv.ALIGN.CENTER, 0, 100)
label = lv.label(start_btn)
label.set_text("Play")
btn5 = lv.btn(scr3)
btn5.align(lv.ALIGN.CENTER, 50, 0)
label = lv.label(btn5)
label.set_text("back")
btn6 = lv.btn(scr4)
btn6.align(lv.ALIGN.CENTER, 50, 80)
label = lv.label(btn6)
label.set_text("PAUSE")
btn7 = lv.btn(scr5)
btn7.align(lv.ALIGN.CENTER, 50, 80)
label = lv.label(btn7)
label.set_text("HOME")
btn8 = lv.btn(scr5)
btn8.align(lv.ALIGN.CENTER, -50, 80)
label = lv.label(btn8)
label.set_text("RESUME")
btn9 = lv.btn(scr6)
btn9.align(lv.ALIGN.CENTER, -50, 80)
label = lv.label(btn9)
label.set_text("YES")
btn10 = lv.btn(scr6)
btn10.align(lv.ALIGN.CENTER, 50, 80)
label = lv.label(btn10)
label.set_text("NO")
def btn1_event_cb(e):
print(e)
lv.scr_load(scr3)
global option
def event_handler(e):
global option
code = e.get_code()
obj = e.get_target()
if code == lv.EVENT.VALUE_CHANGED:
option = " "*30 # should be large enough to store the option
obj.get_selected_str(option, len(option))
# .strip() removes trailing spaces
print("Option: \"%s\"" % option.strip())
l1 = ["Select "]
import os
for file in os.listdir("."):
if file.endswith(".txt"):
l1.append(file)
print(l1)
# Create a normal drop down list
#lv_obj_set_width(obj, new_width)
dd = lv.dropdown(lv.scr_act())
dd.set_size(300, 40);
dd.set_options("\n".join(l1))
dd.align(lv.ALIGN.TOP_MID, 0, 40)
dd.add_event_cb(event_handler, lv.EVENT.ALL, None)
def btn3_event_cb(event):
lv.scr_load(scr1)
def start_btn_event_cb(event):
global option
lv.scr_load(scr6)
text2 = lv.label(lv.scr_act())
text2.set_text(f"Are you sure want to play\n {option}???")
text2.align(lv.ALIGN.CENTER, 0, -10)
def btn5_event_cb(e):
lv.scr_load(scr1)
def btn6_event_cb(e):
lv.scr_load(scr5)
text1 = lv.label(lv.scr_act())
text1.set_text("Paused")
text1.align(lv.ALIGN.CENTER, 50, 80)
text1.center()
def btn7_event_cb(e):
lv.scr_load(scr1)
def btn9_event_cb(e):
bar1 = lv.bar(lv.scr_act())
bar1.set_size(200, 20)
bar1.center()
bar1.set_value(20, lv.ANIM.OFF)
i = 0
print("hi")
parser()
def parser():
sleep(10)
print("IN PARSER")
def btn10_event_cb(e):
lv.scr_load(scr4)
btn1.add_event_cb(btn1_event_cb, lv.EVENT.CLICKED, None)
btn3.add_event_cb(btn3_event_cb, lv.EVENT.CLICKED, None)
btn5.add_event_cb(btn5_event_cb, lv.EVENT.CLICKED, None)
btn6.add_event_cb(btn6_event_cb, lv.EVENT.CLICKED, None)
btn7.add_event_cb(btn7_event_cb, lv.EVENT.CLICKED, None)
btn9.add_event_cb(btn9_event_cb, lv.EVENT.CLICKED, None)
btn10.add_event_cb(btn10_event_cb, lv.EVENT.CLICKED, None)
start_btn.add_event_cb(start_btn_event_cb, lv.EVENT.CLICKED, None)