Ejemplo n.º 1
0
    def popup_confirm_stop(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_stop = lv.mbox(bg)
        popup_stop.set_text(
            'Do you really want to stop the soldering process?')
        btns = ['OK', 'Cancel', '']
        popup_stop.add_btns(btns)
        this = self

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                if popup_stop.get_active_btn() == 0:
                    this.set_reflow_process_on(False)
                else:
                    pass

                bg.del_async()
                popup_stop.start_auto_close(5)

        popup_stop.set_event_cb(event_handler)
        popup_stop.align(None, lv.ALIGN.CENTER, 0, 0)
    def popup_calibration(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_cali = lv.mbox(bg)
        popup_cali.set_text('What would you like to calibrate?')
        btns = ['Temp Sensor', '\n', 'Touch Screen', '\n', 'Cancel', '']
        popup_cali.add_btns(btns)

        lv.cont.set_fit(popup_cali, lv.FIT.NONE)
        mbox_style = popup_cali.get_style(popup_cali.STYLE.BTN_REL)
        popup_cali_style = lv.style_t()
        lv.style_copy(popup_cali_style, mbox_style)
        popup_cali_style.body.padding.bottom = 96
        popup_cali.set_style(popup_cali.STYLE.BTN_REL, popup_cali_style)

        popup_cali.set_height(186)

        this = self

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_cali.get_active_btn_text()
                tim = machine.Timer(-1)
                if active_btn_text == 'Temp Sensor':
                    this.config['has_calibrated'] = False
                    with open('config.json', 'w') as f:
                        ujson.dump(this.config, f)
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                elif active_btn_text == 'Touch Screen':
                    uos.remove(this.config.get('touch_cali_file'))
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                else:
                    tim.deinit()

                bg.del_async()
                popup_cali.start_auto_close(5)

        popup_cali.set_event_cb(event_handler)
        popup_cali.align(None, lv.ALIGN.CENTER, 0, 0)
        self.popup_cali = popup_cali
        return self.popup_cali
Ejemplo n.º 3
0
    def popup_settings(self):
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        popup_settings = lv.mbox(bg)
        popup_settings.set_text('Settings')
        btns = ['Set PID Params', '\n', 'Calibrate Touch', '\n', 'Close', '']
        popup_settings.add_btns(btns)

        lv.cont.set_fit(popup_settings, lv.FIT.NONE)
        mbox_style = popup_settings.get_style(popup_settings.STYLE.BTN_REL)
        popup_cali_style = lv.style_t()
        lv.style_copy(popup_cali_style, mbox_style)
        popup_cali_style.body.padding.bottom = 115
        popup_settings.set_style(popup_settings.STYLE.BTN_REL,
                                 popup_cali_style)
        popup_settings.set_height(186)

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_settings.get_active_btn_text()
                tim = machine.Timer(-1)
                # Note: With PID, temp calibration no longer needed
                # if active_btn_text == 'Temp Sensor':
                #     this.config['has_calibrated'] = False
                #     with open('config.json', 'w') as f:
                #         ujson.dump(this.config, f)
                #     tim.init(period=500, mode=machine.Timer.ONE_SHOT, callback=lambda t:machine.reset())
                # elif active_btn_text == 'Touch Screen':
                if active_btn_text == 'Calibrate Touch':
                    uos.remove(self.config.get('touch_cali_file'))
                    tim.init(period=500,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: machine.reset())
                elif active_btn_text == 'Set PID Params':
                    tim.init(period=50,
                             mode=machine.Timer.ONE_SHOT,
                             callback=lambda t: self.popup_pid_params())
                else:
                    tim.deinit()
                bg.del_async()
                popup_settings.start_auto_close(5)

        popup_settings.set_event_cb(event_handler)
        popup_settings.align(None, lv.ALIGN.CENTER, 0, 0)
Ejemplo n.º 4
0
    def __init__(self, parent, *args, **kwargs):
        # Create a base object for the modal background
        super().__init__(parent, *args, **kwargs)

        # Create a full-screen background
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        # Set the background's style
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50

        self.set_style(modal_style)
        self.set_pos(0, 0)
        self.set_size(parent.get_width(), parent.get_height())

        self.mbox = lv.mbox(self)
        self.mbox.set_width(400)
        self.mbox.align(None, lv.ALIGN.IN_TOP_MID, 0, 200)
Ejemplo n.º 5
0
    def confirm_exit(self):

        mnemonic = self.table.get_mnemonic()
        if len(mnemonic) == 0:
            self.set_value(None)
            return

        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        # Set the background's style
        modal_style.body.main_color = lv.color_make(0, 0, 0)
        modal_style.body.grad_color = modal_style.body.main_color
        modal_style.body.opa = lv.OPA._50

        # Create a base object for the modal background
        bg = lv.obj(self)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.get_width(), self.get_height())
        # Enable opacity scaling for the animation
        bg.set_opa_scale_enable(True)

        btns = ["No, stay here", "Yes, leave", ""]

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                if lv.mbox.get_active_btn_text(obj) == btns[1]:
                    self.set_value(None)
                else:
                    obj.del_async()
                    bg.del_async()

        mbox = lv.mbox(self)
        mbox.set_text(
            "\nAre you sure you want to exit?\n\n"
            "Everything you entered will be forgotten!\n\n"
        )
        mbox.add_btns(btns)
        mbox.set_width(400)
        mbox.set_event_cb(event_handler)
        mbox.align(None, lv.ALIGN.CENTER, 0, 0)
Ejemplo n.º 6
0
label.set_text("Press me")
label.set_size(20,20)

#create semi-transparrent background and set it to hidden
bg = lv.obj(scr)
bg.set_pos(0, 0)
bg.set_size(scr.get_width(), scr.get_height())
modal_style = lv.style_t()
lv.style_copy(modal_style, lv.style_plain_color)
modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(0,0,50)
modal_style.body.opa = 75
bg.set_style(modal_style)
bg.set_hidden(1)

#create message box and set it to hidden
box = lv.mbox(scr)
box.set_text("Congratulations, you pressed the button! Now do it again, here");
box.add_btns(["OK", ""])
box.set_width(200)
box.set_event_cb(event_handler)
box.align(None, lv.ALIGN.CENTER, 0, 0)
box.set_hidden(1)

lv.scr_load(scr)

def on_timer(timer):
    lv.tick_inc(5)
    lv.task_handler()
    gc.collect()

timer = Timer(Timer.TIMER0, Timer.CHANNEL0, mode=Timer.MODE_PERIODIC, period=5, unit=Timer.UNIT_MS, callback=on_timer, arg=None)
Ejemplo n.º 7
0
    def popup_pid_params(self):
        """
        The popup window of PID params settings
        """
        modal_style = lv.style_t()
        lv.style_copy(modal_style, lv.style_plain_color)
        modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(
            0, 0, 0)
        modal_style.body.opa = lv.OPA._50
        bg = lv.obj(self.main_scr)
        bg.set_style(modal_style)
        bg.set_pos(0, 0)
        bg.set_size(self.main_scr.get_width(), self.main_scr.get_height())
        bg.set_opa_scale_enable(True)

        # init mbox and title
        popup_pid = lv.mbox(bg)
        popup_pid.set_text('Set PID Params')
        popup_pid.set_size(220, 300)
        popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)

        input_cont = lv.cont(popup_pid)
        input_cont.set_size(210, 180)

        def input_event_cb(ta, event):
            if event == lv.EVENT.CLICKED:
                self.current_input_placeholder = ta.get_placeholder_text()
                if self.current_input_placeholder == 'Set Offset':
                    popup_pid.align(bg, lv.ALIGN.CENTER, 0, -55)
                else:
                    popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)
                if kb.get_hidden():
                    kb.set_hidden(False)
                # Focus on the clicked text area
                kb.set_ta(ta)

        def keyboard_event_cb(event_kb, event):
            event_kb.def_event_cb(event)
            if event == lv.EVENT.CANCEL or event == lv.EVENT.APPLY:
                kb.set_hidden(True)
                if self.current_input_placeholder == 'Set Offset':
                    popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)

        # init keyboard
        kb = lv.kb(bg)
        kb.set_cursor_manage(True)
        kb.set_event_cb(keyboard_event_cb)
        lv.kb.set_mode(kb, lv.kb.MODE.NUM)
        rel_style = lv.style_t()
        pr_style = lv.style_t()
        lv.style_copy(rel_style, lv.style_btn_rel)
        rel_style.body.radius = 0
        rel_style.body.border.width = 1
        lv.style_copy(pr_style, lv.style_btn_pr)
        pr_style.body.radius = 0
        pr_style.body.border.width = 1
        kb.set_style(lv.kb.STYLE.BG, lv.style_transp_tight)
        kb.set_style(lv.kb.STYLE.BTN_REL, rel_style)
        kb.set_style(lv.kb.STYLE.BTN_PR, pr_style)

        # init text areas
        kp_input = lv.ta(input_cont)
        kp_input.set_text(str(self.pid_params.get('kp')))
        kp_input.set_placeholder_text('Set Kp')
        kp_input.set_accepted_chars('0123456789.+-')
        kp_input.set_one_line(True)
        kp_input.set_width(120)
        kp_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 20)
        kp_input.set_event_cb(input_event_cb)
        kp_label = lv.label(input_cont)
        kp_label.set_text("Kp: ")
        kp_label.align(kp_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)
        pid_title_label = lv.label(input_cont)
        pid_title_label.set_text("PID Params:")
        pid_title_label.align(kp_input, lv.ALIGN.OUT_TOP_LEFT, -65, 0)

        ki_input = lv.ta(input_cont)
        ki_input.set_text(str(self.pid_params.get('ki')))
        ki_input.set_placeholder_text('Set Ki')
        ki_input.set_accepted_chars('0123456789.+-')
        ki_input.set_one_line(True)
        ki_input.set_width(120)
        ki_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 55)
        ki_input.set_event_cb(input_event_cb)
        ki_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN)
        ki_label = lv.label(input_cont)
        ki_label.set_text("Ki: ")
        ki_label.align(ki_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)

        kd_input = lv.ta(input_cont)
        kd_input.set_text(str(self.pid_params.get('kd')))
        kd_input.set_placeholder_text('Set Kd')
        kd_input.set_accepted_chars('0123456789.+-')
        kd_input.set_one_line(True)
        kd_input.set_width(120)
        kd_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 90)
        kd_input.set_event_cb(input_event_cb)
        kd_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN)
        kd_label = lv.label(input_cont)
        kd_label.set_text("Kd: ")
        kd_label.align(kd_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)

        temp_offset_input = lv.ta(input_cont)
        temp_offset_input.set_text(str(self.temp_offset))
        temp_offset_input.set_placeholder_text('Set Offset')
        temp_offset_input.set_accepted_chars('0123456789.+-')
        temp_offset_input.set_one_line(True)
        temp_offset_input.set_width(120)
        temp_offset_input.align(input_cont, lv.ALIGN.IN_TOP_MID, 30, 145)
        temp_offset_input.set_event_cb(input_event_cb)
        temp_offset_input.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN)
        temp_offset_label = lv.label(input_cont)
        temp_offset_label.set_text("Offset: ")
        temp_offset_label.align(temp_offset_input, lv.ALIGN.OUT_LEFT_MID, 0, 0)
        offset_title_label = lv.label(input_cont)
        offset_title_label.set_text("Temp Correction:")
        offset_title_label.align(temp_offset_input, lv.ALIGN.OUT_TOP_LEFT, -65,
                                 0)

        # set btns to mbox
        btns = ['Save', 'Cancel', '']
        popup_pid.add_btns(btns)

        lv.cont.set_fit(popup_pid, lv.FIT.NONE)
        mbox_style = popup_pid.get_style(popup_pid.STYLE.BTN_REL)
        popup_pid_style = lv.style_t()
        lv.style_copy(popup_pid_style, mbox_style)
        popup_pid_style.body.padding.bottom = 46
        popup_pid.set_style(popup_pid.STYLE.BTN_REL, popup_pid_style)
        popup_pid.set_size(220, 300)

        def event_handler(obj, event):
            if event == lv.EVENT.VALUE_CHANGED:
                active_btn_text = popup_pid.get_active_btn_text()
                if active_btn_text == 'Save':
                    kp_value = float(kp_input.get_text())
                    ki_value = float(ki_input.get_text())
                    kd_value = float(kd_input.get_text())
                    temp_offset_value = float(temp_offset_input.get_text())
                    self.config['pid'] = {
                        'kp': kp_value,
                        'ki': ki_value,
                        'kd': kd_value
                    }
                    self.config['sensor_offset'] = temp_offset_value
                    self.pid_params = self.config.get('pid')
                    self.temp_offset = self.config.get('sensor_offset')
                    # Save settings to config.json
                    with open('config.json', 'w') as f:
                        ujson.dump(self.config, f)
                    # Apply settings immediately
                    self.pid.reset(kp_value, ki_value, kd_value)
                    self.sensor.set_offset(temp_offset_value)
                bg.del_async()
                popup_pid.start_auto_close(5)

        popup_pid.set_event_cb(event_handler)
        popup_pid.align(bg, lv.ALIGN.CENTER, 0, 0)
        kb.set_ta(kp_input)
        kb.set_hidden(True)
Ejemplo n.º 8
0
    touch = xpt2046(
        cs=TOUCH_CS,
        transpose=TFT_IS_PORTRAIT,
        cal_x0=touch_x0,
        cal_x1=touch_x1,
        cal_y0=touch_y0,
        cal_y1=touch_y1,
    )

    TOUCH_READY = 1  #表示已经配置好触摸参数


#############################################
#############      Message box   ############
#############################################
def event_handler(obj, event):
    if event == lv.EVENT.VALUE_CHANGED:
        print("Button: %s" % lv.mbox.get_active_btn_text(obj))


if TOUCH_READY:

    btns = ["Apply", "Close", ""]

    mbox1 = lv.mbox(lv.scr_act())
    mbox1.set_text("A message box with two buttons.")
    mbox1.add_btns(btns)
    mbox1.set_width(200)
    mbox1.set_event_cb(event_handler)
    mbox1.align(None, lv.ALIGN.CENTER, 0, 0)  # Align to the corner