From 86be30034dc969e3e61fcd4b9f105710efa8792f Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 16 Feb 2024 22:15:15 +0100 Subject: [PATCH] Optimalisations --- CYD-Klipper/platformio.ini | 2 + CYD-Klipper/src/core/lv_setup.cpp | 102 +++++++++---------- CYD-Klipper/src/ui/panels/macros_panel.cpp | 1 + CYD-Klipper/src/ui/panels/settings_panel.cpp | 1 + CYD-Klipper/src/ui/panels/stats_panel.cpp | 4 +- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 7a62560..1c11a68 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -20,8 +20,10 @@ lib_deps = monitor_filters = esp32_exception_decoder build_flags = -DLV_CONF_PATH="../../../../src/conf/lv_conf.h" + -O2 extra_scripts = pre:extract_commit.py +build_unflags = -Os [env:esp32-2432S028R] board = esp32-2432S028R diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index 74a4022..eb9700d 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -15,16 +15,58 @@ typedef void (*lv_indev_drv_read_cb_t)(struct _lv_indev_drv_t * indev_drv, lv_indev_data_t * data); bool is_screen_in_sleep = false; -bool is_in_calibration_mode = false; lv_timer_t *screen_sleep_timer; lv_coord_t point[2] = {0}; +static lv_indev_drv_read_cb_t original_touch_driver = NULL; + +void lv_touch_intercept_calibration(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) +{ + original_touch_driver(indev_driver, data); + + if (data->state == LV_INDEV_STATE_PR){ + point[0] = data->point.x; + point[1] = data->point.y; + + while (data->state == LV_INDEV_STATE_PR){ + original_touch_driver(indev_driver, data); + delay(20); + } + } + + data->state = LV_INDEV_STATE_REL; +} + +void lv_touch_intercept(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) +{ + original_touch_driver(indev_driver, data); + + if (data->state == LV_INDEV_STATE_PR) { + if (is_screen_asleep()) { + while (data->state == LV_INDEV_STATE_PR) { + original_touch_driver(indev_driver, data); + delay(20); + } + + data->state = LV_INDEV_STATE_REL; + } + + screen_timer_wake(); +#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION + data->point.x = round((data->point.x * global_config.screenCalXMult) + global_config.screenCalXOffset); + data->point.y = round((data->point.y * global_config.screenCalYMult) + global_config.screenCalYOffset); +#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION + } +} + void lv_do_calibration(){ if (global_config.screenCalibrated){ return; } - is_in_calibration_mode = true; + lv_indev_t * display_driver = lv_indev_get_next(NULL); + display_driver->driver->read_cb = lv_touch_intercept_calibration; + lv_obj_clean(lv_scr_act()); lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE); @@ -95,7 +137,6 @@ void lv_do_calibration(){ global_config.screenCalibrated = true; WriteGlobalConfig(); - is_in_calibration_mode = false; lv_obj_clean(lv_scr_act()); } @@ -183,58 +224,13 @@ void set_color_scheme() lv_disp_set_theme(dispp, theme); } -static lv_indev_drv_read_cb_t original_touch_driver = NULL; - -void lv_touch_intercept(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) -{ - original_touch_driver(indev_driver, data); - -#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION - if (is_in_calibration_mode){ - if (data->state == LV_INDEV_STATE_PR){ - point[0] = data->point.x; - point[1] = data->point.y; - - while (data->state == LV_INDEV_STATE_PR){ - original_touch_driver(indev_driver, data); - delay(20); - } - } - - data->state = LV_INDEV_STATE_REL; - return; - } -#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION - - if (data->state == LV_INDEV_STATE_PR) { - if (is_screen_asleep()) { - while (data->state == LV_INDEV_STATE_PR) { - original_touch_driver(indev_driver, data); - delay(20); - } - - data->state = LV_INDEV_STATE_REL; - } - - screen_timer_wake(); - } - -#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION - if (data->state == LV_INDEV_STATE_PR) { - //Serial.printf("Before: %d %d\n", data->point.x, data->point.y); - data->point.x = round((data->point.x * global_config.screenCalXMult) + global_config.screenCalXOffset); - data->point.y = round((data->point.y * global_config.screenCalYMult) + global_config.screenCalYOffset); - //Serial.printf("After: %d %d\n", data->point.x, data->point.y); - } -#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION -} - void lv_setup() { - if (original_touch_driver == NULL) { - lv_indev_t * display_driver = lv_indev_get_next(NULL); + lv_indev_t * display_driver = lv_indev_get_next(NULL); + + if (original_touch_driver == NULL) + { original_touch_driver = display_driver->driver->read_cb; - display_driver->driver->read_cb = lv_touch_intercept; } set_color_scheme(); @@ -243,6 +239,8 @@ void lv_setup() lv_do_calibration(); #endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION + display_driver->driver->read_cb = lv_touch_intercept; + screen_timer_setup(); screen_timer_start(); } diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 160cd17..7d61744 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -104,6 +104,7 @@ void macros_panel_init(lv_obj_t* panel) { } lv_obj_t * root_panel = lv_create_empty_panel(panel); + lv_obj_set_scrollbar_mode(root_panel, LV_SCROLLBAR_MODE_OFF); lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2); lv_layout_flex_column(root_panel); diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index ab5a41b..291813d 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -129,6 +129,7 @@ void settings_panel_init(lv_obj_t* panel){ lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(panel); + lv_obj_set_scrollbar_mode(panel, LV_SCROLLBAR_MODE_OFF); btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, reset_wifi_click, LV_EVENT_CLICKED, NULL); diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp index 5650c10..d9b9d72 100644 --- a/CYD-Klipper/src/ui/panels/stats_panel.cpp +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -46,10 +46,8 @@ static void set_zoffset_text_ex(lv_event_t * e) { static void set_zoffset(lv_event_t * e){ char* offset = (char*)lv_event_get_user_data(e); - const char* extra = printer.state == PRINTER_STATE_IDLE ? " MOVE=1" : ""; - char gcode[64]; - sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s%s", offset, extra); + sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s MOVE=1", offset); send_gcode(true, gcode); }