From 45779b5a139a64b7f0de2a10aee5fd50ec0e82a1 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 24 Feb 2024 14:27:03 +0100 Subject: [PATCH 01/42] Make calibration work with smartdisplay driver --- .../boards/esp32-2432S028R-smartdisplay.json | 3 +- CYD-Klipper/src/core/lv_setup.cpp | 60 +++++++++++++------ 2 files changed, 43 insertions(+), 20 deletions(-) diff --git a/CYD-Klipper/boards/esp32-2432S028R-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S028R-smartdisplay.json index 2d8de26..19af945 100644 --- a/CYD-Klipper/boards/esp32-2432S028R-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S028R-smartdisplay.json @@ -91,8 +91,7 @@ "-DCYD_SCREEN_FONT=lv_font_montserrat_14", "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", - "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1", - "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1" + "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1" ], "f_cpu": "240000000L", "f_flash": "40000000L", diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index eb9700d..4b41b2c 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -74,19 +74,25 @@ void lv_do_calibration(){ lv_label_set_text(label, "Calibrate Screen"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); - lv_obj_t * line = lv_line_create(lv_scr_act()); + lv_obj_t * line_x = lv_line_create(lv_scr_act()); + lv_obj_t * line_y = lv_line_create(lv_scr_act()); + static lv_point_t line_points_x[] = { {0, 10}, {21, 10} }; static lv_point_t line_points_y[] = { {10, 0}, {10, 21} }; - lv_line_set_points(line, line_points_x, 2); - lv_obj_align(line, LV_ALIGN_TOP_LEFT, 0, 0); - lv_obj_set_style_line_width(line, 1, 0); - - lv_obj_t * line2 = lv_line_create(lv_scr_act()); - lv_line_set_points(line2, line_points_y, 2); - lv_obj_align(line2, LV_ALIGN_TOP_LEFT, 0, 0); - lv_obj_set_style_line_width(line2, 1, 0); + lv_line_set_points(line_x, line_points_x, 2); + lv_obj_set_style_line_width(line_x, 1, 0); + lv_line_set_points(line_y, line_points_y, 2); + lv_obj_set_style_line_width(line_y, 1, 0); +#ifdef CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY + lv_obj_align(line_x, LV_ALIGN_TOP_RIGHT, 1, 0); + lv_obj_align(line_y, LV_ALIGN_TOP_RIGHT, -10, 0); +#else + lv_obj_align(line_x, LV_ALIGN_TOP_LEFT, 0, 0); + lv_obj_align(line_y, LV_ALIGN_TOP_LEFT, 0, 0); +#endif + while (true){ lv_timer_handler(); lv_task_handler(); @@ -101,17 +107,24 @@ void lv_do_calibration(){ point[0] = 0; point[1] = 0; - lv_obj_del(line); - lv_obj_del(line2); + lv_obj_del(line_x); + lv_obj_del(line_y); - line = lv_line_create(lv_scr_act()); - lv_line_set_points(line, line_points_x, 2); - lv_obj_align(line, LV_ALIGN_BOTTOM_RIGHT, 1, -10); - lv_obj_set_style_line_width(line, 1, 0); + line_x = lv_line_create(lv_scr_act()); + line_y = lv_line_create(lv_scr_act()); + lv_line_set_points(line_x, line_points_x, 2); + lv_line_set_points(line_y, line_points_y, 2); + lv_obj_set_style_line_width(line_x, 1, 0); + lv_obj_set_style_line_width(line_y, 1, 0); - line = lv_line_create(lv_scr_act()); - lv_line_set_points(line, line_points_y, 2); - lv_obj_align(line, LV_ALIGN_BOTTOM_RIGHT, -10, 1); + +#ifdef CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY + lv_obj_align(line_x, LV_ALIGN_BOTTOM_LEFT, 0, -10); + lv_obj_align(line_y, LV_ALIGN_BOTTOM_LEFT, 0, 1); +#else + lv_obj_align(line_x, LV_ALIGN_BOTTOM_RIGHT, 1, -10); + lv_obj_align(line_y, LV_ALIGN_BOTTOM_RIGHT, -10, 1); +#endif while (true){ lv_timer_handler(); @@ -125,8 +138,13 @@ void lv_do_calibration(){ lv_coord_t x2 = point[0]; lv_coord_t y2 = point[1]; +#ifdef CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY + int16_t xDist = CYD_SCREEN_HEIGHT_PX - 20; + int16_t yDist = CYD_SCREEN_WIDTH_PX - 20; +#else int16_t xDist = CYD_SCREEN_WIDTH_PX - 20; int16_t yDist = CYD_SCREEN_HEIGHT_PX - 20; +#endif global_config.screenCalXMult = (float)xDist / (float)(x2 - x1); global_config.screenCalXOffset = 10.0 - ((float)x1 * global_config.screenCalXMult); @@ -134,10 +152,16 @@ void lv_do_calibration(){ global_config.screenCalYMult = (float)yDist / (float)(y2 - y1); global_config.screenCalYOffset = 10.0 - ((float)y1 * global_config.screenCalYMult); + if (global_config.screenCalXMult == std::numeric_limits::infinity() || global_config.screenCalYMult == std::numeric_limits::infinity()){ + Serial.println("Calibration failed, please try again"); + ESP.restart(); + } + global_config.screenCalibrated = true; WriteGlobalConfig(); lv_obj_clean(lv_scr_act()); + Serial.printf("Calibration done: X*%.2f + %.2f, Y*%.2f + %.2f\n", global_config.screenCalXMult, global_config.screenCalXOffset, global_config.screenCalYMult, global_config.screenCalYOffset); } void set_screen_brightness() From f467e8a604d0f78857e7082705a6b6f3865884df Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 27 Feb 2024 21:32:00 +0100 Subject: [PATCH 02/42] Add esp32-8048S043C --- .../boards/esp32-8048S043C-smartdisplay.json | 140 ++++++++++++++++++ CYD-Klipper/platformio.ini | 3 + ci.py | 2 +- 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json diff --git a/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json new file mode 100644 index 0000000..3e8d985 --- /dev/null +++ b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json @@ -0,0 +1,140 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "'-D ARDUINO_ESP32S3_DEV'", + "'-D BOARD_HAS_PSRAM'", + "'-D ARDUINO_USB_MODE=1'", + "'-D ARDUINO_RUNNING_CORE=1'", + "'-D ARDUINO_EVENT_RUNNING_CORE=1'", + "'-D ARDUINO_USB_CDC_ON_BOOT=0'", + "'-D ESP32_8048S043C'", + "'-D LCD_WIDTH=800'", + "'-D LCD_HEIGHT=480'", + "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT)'", + "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT)'", + "'-D BCKL=2'", + "'-D LCD_ST7262_PAR'", + "'-D ST7262_PANEL_CONFIG_CLK_SRC=LCD_CLK_SRC_PLL160M'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_PCLK_HZ=(8*1000000)'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_H_RES=LCD_WIDTH'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_V_RES=LCD_HEIGHT'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_HSYNC_PULSE_WIDTH=4'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_HSYNC_BACK_PORCH=8'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_HSYNC_FRONT_PORCH=8'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_VSYNC_PULSE_WIDTH=4'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_VSYNC_BACK_PORCH=8'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_VSYNC_FRONT_PORCH=8'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_HSYNC_IDLE_LOW=false'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_VSYNC_IDLE_LOW=false'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_DE_IDLE_HIGH=false'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_PCLK_ACTIVE_NEG=true'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_PCLK_IDLE_HIGH=false'", + "'-D ST7262_PANEL_CONFIG_DATA_WIDTH=16'", + "'-D ST7262_PANEL_CONFIG_SRAM_TRANS_ALIGN=4'", + "'-D ST7262_PANEL_CONFIG_PSRAM_TRANS_ALIGN=64'", + "'-D ST7262_PANEL_CONFIG_HSYNC_GPIO_NUM=39'", + "'-D ST7262_PANEL_CONFIG_VSYNC_GPIO_NUM=41'", + "'-D ST7262_PANEL_CONFIG_DE_GPIO_NUM=40'", + "'-D ST7262_PANEL_CONFIG_PCLK_GPIO_NUM=42'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R0=8'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R1=3'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R2=46'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R3=9'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R4=1'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G0=5'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G1=6'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G2=7'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G3=15'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G4=16'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G5=4'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B0=45'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B1=48'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B2=47'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B3=21'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B4=14'", + "'-D ST7262_PANEL_CONFIG_DISP_GPIO_NUM=GPIO_NUM_NC'", + "'-D ST7262_PANEL_CONFIG_FLAGS_DISP_ACTIVE_LOW=false'", + "'-D ST7262_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE=false'", + "'-D ST7262_PANEL_CONFIG_FLAGS_FB_IN_PSRAM=true'", + "'-D BOARD_HAS_TOUCH'", + "'-D TOUCH_GT911_I2C'", + "'-D GT911_I2C_HOST=0'", + "'-D GT911_I2C_CONFIG_SDA_IO_NUM=19'", + "'-D GT911_I2C_CONFIG_SCL_IO_NUM=20'", + "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_MASTER_CLK_SPEED=400000'", + "'-D GT911_I2C_CONFIG_CLK_FLAGS=0'", + "'-D GT911_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS'", + "'-D GT911_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", + "'-D GT911_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", + "'-D GT911_IO_I2C_CONFIG_LCD_CMD_BITS=16'", + "'-D GT911_IO_I2C_CONFIG_LCD_PARAM_BITS=0'", + "'-D GT911_IO_I2C_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D GT911_IO_I2C_CONFIG_FLAGS_DISABLE_CONTROL_PHASE=true'", + "'-D GT911_TOUCH_CONFIG_X_MAX=LCD_WIDTH'", + "'-D GT911_TOUCH_CONFIG_Y_MAX=LCD_HEIGHT'", + "'-D GT911_TOUCH_CONFIG_RST_GPIO_NUM=38'", + "'-D GT911_TOUCH_CONFIG_INT_GPIO_NUM=18'", + "'-D GT911_TOUCH_CONFIG_LEVELS_RESET=0'", + "'-D GT911_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", + "'-D TOUCH_SWAP_XY=true'", + "'-D TOUCH_SWAP_X=false'", + "'-D TOUCH_SWAP_Y=false'", + "'-D BOARD_HAS_TF'", + "'-D TF_CS=10'", + "'-D TF_SPI_MOSI=11'", + "'-D TF_SPI_SCLK=12'", + "'-D TF_SPI_MISO=13'", + + "-DCYD_SCREEN_GAP_PX=10", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=40", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=40", + "-DCYD_SCREEN_FONT=lv_font_montserrat_16", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=50", + "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1", + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1", + "-DCYD_SCREEN_DISABLE_INVERT_COLORS=1" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-8048S043C", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005006110360174.html", + "vendor": "Sunton" + } \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 7a62560..66b8e73 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -48,3 +48,6 @@ board = esp32-3248S035C-smartdisplay [env:esp32-2432S028R-smartdisplay] board = esp32-2432S028R-smartdisplay + +[env:esp32-8048S043C-smartdisplay] +board = esp32-8048S043C-smartdisplay \ No newline at end of file diff --git a/ci.py b/ci.py index f22f181..6f2b59c 100644 --- a/ci.py +++ b/ci.py @@ -1,6 +1,6 @@ import subprocess, os, shutil, json -CYD_PORTS = ["esp32-3248S035C", "esp32-2432S028R"] +CYD_PORTS = ["esp32-3248S035C", "esp32-2432S028R", "esp32-8048S043C-smartdisplay"] BASE_DIR = os.getcwd() def get_manifest(base_path : str, device_name : str): From 55e9ce3d818ed9a0b72d6dd3982836344bf04e25 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 1 Mar 2024 22:28:35 +0100 Subject: [PATCH 03/42] Vertical UI, round 2 --- .../src/core/device/ESP32-2432S028R.cpp | 4 +++ .../src/core/device/ESP32-3248S035C.cpp | 5 +++ .../src/core/device/ESP32-smartdisplay.cpp | 10 +++++- CYD-Klipper/src/ui/nav_buttons.cpp | 16 +++++++++- CYD-Klipper/src/ui/panels/macros_panel.cpp | 2 +- CYD-Klipper/src/ui/panels/move_panel.cpp | 4 +-- CYD-Klipper/src/ui/panels/print_panel.cpp | 2 +- CYD-Klipper/src/ui/panels/stats_panel.cpp | 4 +-- CYD-Klipper/src/ui/panels/temp_panel.cpp | 6 ++-- CYD-Klipper/src/ui/ui_utils.h | 31 ++++++++++++++----- 10 files changed, 65 insertions(+), 19 deletions(-) diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index 1543e2c..22ea562 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -1,6 +1,10 @@ #ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R #include "../screen_driver.h" +#ifdef CYD_SCREEN_VERTICAL + #error "Vertical screen not supported with the ESP32_2432S028R driver" +#endif + #include #include #include "../../conf/global_config.h" diff --git a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp index 630107f..b66b236 100644 --- a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp +++ b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp @@ -1,4 +1,9 @@ #ifdef CYD_SCREEN_DRIVER_ESP32_3248S035C +#include "../screen_driver.h" + +#ifdef CYD_SCREEN_VERTICAL + #error "Vertical screen not supported with the ESP32_3248S035C driver" +#endif #include "lvgl.h" #include diff --git a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp index e338982..39f692c 100644 --- a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp +++ b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp @@ -33,6 +33,14 @@ void lv_screen_intercept(_lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_col original_screen_driver(disp_drv, area, color_p); } +#ifdef CYD_SCREEN_VERTICAL +#define ROTATION_INVERTED LV_DISP_ROT_180 +#define ROTATION_NORMAL LV_DISP_ROT_NONE +#else +#define ROTATION_INVERTED LV_DISP_ROT_270 +#define ROTATION_NORMAL LV_DISP_ROT_90 +#endif + void screen_setup() { smartdisplay_init(); @@ -44,7 +52,7 @@ void screen_setup() } #endif // CYD_SCREEN_DISABLE_INVERT_COLORS - lv_disp_set_rotation(lv_disp_get_default(), (global_config.rotateScreen) ? LV_DISP_ROT_270 : LV_DISP_ROT_90); + lv_disp_set_rotation(lv_disp_get_default(), (global_config.rotateScreen) ? ROTATION_INVERTED : ROTATION_NORMAL); } #endif // CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY \ No newline at end of file diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index 3bfc6ec..3a489ae 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -79,7 +79,13 @@ static void btn_click_macros(lv_event_t * e){ void create_button(const char* icon, const char* name, lv_event_cb_t button_click, lv_event_cb_t label_update, lv_obj_t * root){ lv_obj_t* btn = lv_btn_create(root); lv_obj_set_flex_grow(btn, 1); + +#ifdef CYD_SCREEN_VERTICAL + lv_obj_set_height(btn, CYD_SCREEN_SIDEBAR_SIZE_PX); +#else lv_obj_set_width(btn, CYD_SCREEN_SIDEBAR_SIZE_PX); +#endif + lv_obj_add_style(btn, &nav_button_style, 0); if (button_click != NULL) lv_obj_add_event_cb(btn, button_click, LV_EVENT_CLICKED, NULL); @@ -101,10 +107,18 @@ void nav_buttons_setup(unsigned char active_panel){ lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE); lv_obj_t * root_panel = lv_create_empty_panel(lv_scr_act()); + +#ifdef CYD_SCREEN_VERTICAL + lv_obj_set_size(root_panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_SIDEBAR_SIZE_PX); + lv_obj_align(root_panel, LV_ALIGN_BOTTOM_LEFT, 0, 0); + lv_layout_flex_row(root_panel, LV_FLEX_ALIGN_START, 0, 0); +#else lv_obj_set_size(root_panel, CYD_SCREEN_SIDEBAR_SIZE_PX, CYD_SCREEN_HEIGHT_PX); lv_obj_align(root_panel, LV_ALIGN_TOP_LEFT, 0, 0); lv_layout_flex_column(root_panel, LV_FLEX_ALIGN_START, 0, 0); +#endif + // Files/Print create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); @@ -118,7 +132,7 @@ void nav_buttons_setup(unsigned char active_panel){ create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel); lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0); switch (active_panel){ diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 7d61744..0481f6c 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -105,7 +105,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_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_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/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 2f19873..2ffc264 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -92,7 +92,7 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){ const auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, 0, 0); @@ -155,7 +155,7 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){ inline void root_panel_steppers_unlocked(lv_obj_t * root_panel){ lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER); diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index 83819f9..e51d88f 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -95,7 +95,7 @@ void print_panel_init(lv_obj_t* panel){ lv_obj_set_style_radius(list, 0, 0); lv_obj_set_style_border_width(list, 0, 0); lv_obj_set_style_bg_opa(list, LV_OPA_TRANSP, 0); - lv_obj_set_size(list, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_obj_set_size(list, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_obj_align(list, LV_ALIGN_CENTER, 0, 0); FILESYSTEM_FILE* files = get_files(25); diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp index 8ef4687..b55793b 100644 --- a/CYD-Klipper/src/ui/panels/stats_panel.cpp +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -228,7 +228,7 @@ void stats_panel_init(lv_obj_t* panel) { auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 3; lv_obj_t * left_panel = lv_create_empty_panel(panel); - lv_obj_set_size(left_panel, panel_width, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); + lv_obj_set_size(left_panel, panel_width, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_layout_flex_column(left_panel); lv_obj_set_flex_align(left_panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); lv_obj_align(left_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); @@ -244,7 +244,7 @@ void stats_panel_init(lv_obj_t* panel) { create_stat_text_block(left_panel, "Feedrate:", label_feedrate); lv_obj_t * right_panel = lv_create_empty_panel(panel); - lv_obj_set_size(right_panel, panel_width, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); + lv_obj_set_size(right_panel, panel_width, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_layout_flex_column(right_panel, LV_FLEX_ALIGN_CENTER); lv_obj_align(right_panel, LV_ALIGN_TOP_RIGHT, -1 * CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index 7f4042f..7a866f1 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -126,7 +126,7 @@ static void keyboard_callback(lv_event_t * e){ static void show_keyboard(lv_event_t * e){ lv_obj_t * parent = lv_create_empty_panel(root_panel); lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0); - lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN); lv_obj_t * empty_panel = lv_create_empty_panel(parent); @@ -261,7 +261,7 @@ void temp_panel_init(lv_obj_t * panel){ edit_mode = false; lv_obj_t * root_temp_panel = lv_create_empty_panel(panel); - lv_obj_set_size(root_temp_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_obj_set_size(root_temp_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_obj_align(root_temp_panel, LV_ALIGN_TOP_RIGHT, 0, 0); lv_obj_set_style_pad_all(root_temp_panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(root_temp_panel); @@ -293,7 +293,7 @@ void temp_panel_init(lv_obj_t * panel){ lv_msg_subscribe_obj(DATA_PRINTER_DATA, chart, NULL); lv_obj_t * single_screen_panel = lv_create_empty_panel(root_temp_panel); - lv_obj_set_size(single_screen_panel, element_width, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2 - CYD_SCREEN_GAP_PX / 2); + lv_obj_set_size(single_screen_panel, element_width, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2 - CYD_SCREEN_GAP_PX / 2); lv_layout_flex_column(single_screen_panel); lv_obj_t * temp_rows[2] = {0}; diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index bd437e3..d58ecc2 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -1,15 +1,30 @@ #pragma once -#ifndef CYD_SCREEN_WIDTH_PX -#define CYD_SCREEN_WIDTH_PX LCD_HEIGHT -#endif +#ifdef CYD_SCREEN_VERTICAL + #ifndef CYD_SCREEN_WIDTH_PX + #define CYD_SCREEN_WIDTH_PX LCD_WIDTH + #endif -#ifndef CYD_SCREEN_HEIGHT_PX -#define CYD_SCREEN_HEIGHT_PX LCD_WIDTH -#endif + #ifndef CYD_SCREEN_HEIGHT_PX + #define CYD_SCREEN_HEIGHT_PX LCD_HEIGHT + #endif -#define CYD_SCREEN_PANEL_WIDTH_PX \ - (CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) + #define CYD_SCREEN_PANEL_HEIGHT_PX \ + (CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) + #define CYD_SCREEN_PANEL_WIDTH_PX CYD_SCREEN_WIDTH_PX +#else + #ifndef CYD_SCREEN_WIDTH_PX + #define CYD_SCREEN_WIDTH_PX LCD_HEIGHT + #endif + + #ifndef CYD_SCREEN_HEIGHT_PX + #define CYD_SCREEN_HEIGHT_PX LCD_WIDTH + #endif + + #define CYD_SCREEN_PANEL_HEIGHT_PX CYD_SCREEN_HEIGHT_PX + #define CYD_SCREEN_PANEL_WIDTH_PX \ + (CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) +#endif typedef struct { lv_event_cb_t event; From 801432c3a6ed87da1e058f2908f5665d47aaabf5 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:19:03 +0100 Subject: [PATCH 04/42] Driver configuration improvements --- .../src/core/device/ESP32-2432S028R.cpp | 1 - .../src/core/device/ESP32-3248S035C.cpp | 1 - .../src/core/device/ESP32-smartdisplay.cpp | 24 +++++++++++++------ CYD-Klipper/src/core/lv_setup.cpp | 10 +++++--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index 22ea562..d2734d8 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -85,7 +85,6 @@ void screen_setup() tft.setRotation(global_config.rotateScreen ? 3 : 1); tft.fillScreen(TFT_BLACK); - set_screen_brightness(); set_invert_display(); touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); diff --git a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp index b66b236..fd39f00 100644 --- a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp +++ b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp @@ -116,7 +116,6 @@ void screen_setup() ledcAttachPin(TFT_BL, 0); tft.setRotation(global_config.rotateScreen ? 3 : 1); tft.fillScreen(TFT_BLACK); - set_screen_brightness(); set_invert_display(); LED_init(); diff --git a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp index 39f692c..5e29e05 100644 --- a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp +++ b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp @@ -15,7 +15,8 @@ void screen_setBrightness(byte brightness) smartdisplay_lcd_set_backlight(brightness / 255.0f); } -void set_invert_display(){ +void set_invert_display() +{ lv_obj_invalidate(lv_scr_act()); } @@ -33,12 +34,21 @@ void lv_screen_intercept(_lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_col original_screen_driver(disp_drv, area, color_p); } -#ifdef CYD_SCREEN_VERTICAL -#define ROTATION_INVERTED LV_DISP_ROT_180 -#define ROTATION_NORMAL LV_DISP_ROT_NONE -#else -#define ROTATION_INVERTED LV_DISP_ROT_270 -#define ROTATION_NORMAL LV_DISP_ROT_90 + +#ifndef ROTATION_INVERTED + #ifdef CYD_SCREEN_VERTICAL + #define ROTATION_INVERTED LV_DISP_ROT_180 + #else + #define ROTATION_INVERTED LV_DISP_ROT_270 + #endif +#endif + +#ifndef ROTATION_NORMAL + #ifdef CYD_SCREEN_VERTICAL + #define ROTATION_NORMAL LV_DISP_ROT_NONE + #else + #define ROTATION_NORMAL LV_DISP_ROT_90 + #endif #endif void screen_setup() diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index 4b41b2c..5b2d53c 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -25,13 +25,14 @@ void lv_touch_intercept_calibration(lv_indev_drv_t *indev_driver, lv_indev_data_ original_touch_driver(indev_driver, data); if (data->state == LV_INDEV_STATE_PR){ - point[0] = data->point.x; - point[1] = data->point.y; - + lv_coord_t local_point[] = {data->point.x, data->point.y}; while (data->state == LV_INDEV_STATE_PR){ original_touch_driver(indev_driver, data); delay(20); } + + point[0] = local_point[0]; + point[1] = local_point[1]; } data->state = LV_INDEV_STATE_REL; @@ -102,6 +103,8 @@ void lv_do_calibration(){ } } + delay(300); + lv_coord_t x1 = point[0]; lv_coord_t y1 = point[1]; point[0] = 0; @@ -267,6 +270,7 @@ void lv_setup() screen_timer_setup(); screen_timer_start(); + set_screen_brightness(); } bool is_screen_asleep() From 49c27f2b019cc7cc129c3d13838a75ba75a9e28c Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:21:09 +0100 Subject: [PATCH 05/42] Add esp32-2432S032C --- .../boards/esp32-2432S032C-smartdisplay.json | 125 ++++++++++++++++++ CYD-Klipper/platformio.ini | 7 +- 2 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json diff --git a/CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json new file mode 100644 index 0000000..f377ad4 --- /dev/null +++ b/CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json @@ -0,0 +1,125 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "'-D ARDUINO_ESP32_DEV'", + "'-D ESP32_2432S032C'", + "'-D LCD_WIDTH=240'", + "'-D LCD_HEIGHT=320'", + "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", + "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", + "'-D BCKL=27'", + "'-D LCD_IPS'", + "'-D LCD_ST7789_SPI'", + "'-D ST7789_SPI_HOST=SPI2_HOST'", + "'-D ST7789_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", + "'-D ST7789_SPI_BUS_MOSI_IO_NUM=13'", + "'-D ST7789_SPI_BUS_MISO_IO_NUM=12'", + "'-D ST7789_SPI_BUS_SCLK_IO_NUM=14'", + "'-D ST7789_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", + "'-D ST7789_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", + "'-D ST7789_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ST7789_SPI_BUS_FLAGS=0'", + "'-D ST7789_SPI_BUS_INTR_FLAGS=0'", + "'-D ST7789_SPI_CONFIG_CS_GPIO_NUM=15'", + "'-D ST7789_SPI_CONFIG_DC_GPIO_NUM=2'", + "'-D ST7789_SPI_CONFIG_SPI_MODE=SPI_MODE3'", + "'-D ST7789_SPI_CONFIG_PCLK_HZ=24000000'", + "'-D ST7789_SPI_CONFIG_TRANS_QUEUE_DEPTH=10'", + "'-D ST7789_SPI_CONFIG_LCD_CMD_BITS=8'", + "'-D ST7789_SPI_CONFIG_LCD_PARAM_BITS=8'", + "'-D ST7789_SPI_CONFIG_FLAGS_DC_AS_CMD_PHASE=false'", + "'-D ST7789_SPI_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D ST7789_SPI_CONFIG_FLAGS_OCTAL_MODE=false'", + "'-D ST7789_SPI_CONFIG_FLAGS_LSB_FIRST=false'", + "'-D ST7789_DEV_CONFIG_RESET_GPIO_NUM=GPIO_NUM_NC'", + "'-D ST7789_DEV_CONFIG_COLOR_SPACE=ESP_LCD_COLOR_SPACE_RGB'", + "'-D ST7789_DEV_CONFIG_BITS_PER_PIXEL=16'", + "'-D ST7789_DEV_CONFIG_FLAGS_RESET_ACTIVE_HIGH=false'", + "'-D ST7789_DEV_CONFIG_VENDOR_CONFIG=NULL'", + "'-D LCD_SWAP_XY=false'", + "'-D LCD_MIRROR_X=false'", + "'-D LCD_MIRROR_Y=false'", + "'-D BOARD_HAS_TOUCH'", + "'-D TOUCH_GT911_I2C'", + "'-D GT911_I2C_HOST=0'", + "'-D GT911_I2C_CONFIG_SDA_IO_NUM=33'", + "'-D GT911_I2C_CONFIG_SCL_IO_NUM=32'", + "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_MASTER_CLK_SPEED=400000'", + "'-D GT911_I2C_CONFIG_CLK_FLAGS=0'", + "'-D GT911_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS'", + "'-D GT911_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", + "'-D GT911_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", + "'-D GT911_IO_I2C_CONFIG_LCD_CMD_BITS=16'", + "'-D GT911_IO_I2C_CONFIG_LCD_PARAM_BITS=0'", + "'-D GT911_IO_I2C_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D GT911_IO_I2C_CONFIG_FLAGS_DISABLE_CONTROL_PHASE=true'", + "'-D GT911_TOUCH_CONFIG_X_MAX=LCD_WIDTH'", + "'-D GT911_TOUCH_CONFIG_Y_MAX=LCD_HEIGHT'", + "'-D GT911_TOUCH_CONFIG_RST_GPIO_NUM=25'", + "'-D GT911_TOUCH_CONFIG_INT_GPIO_NUM=21'", + "'-D GT911_TOUCH_CONFIG_LEVELS_RESET=0'", + "'-D GT911_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", + "'-D TOUCH_SWAP_XY=true'", + "'-D TOUCH_SWAP_X=false'", + "'-D TOUCH_SWAP_Y=false'", + "'-D BOARD_HAS_TF'", + "'-D TF_CS=5'", + "'-D TF_SPI_MOSI=23'", + "'-D TF_SPI_SCLK=18'", + "'-D TF_SPI_MISO=19'", + "'-D BOARD_HAS_RGB_LED'", + "'-D RGB_LED_R=4'", + "'-D RGB_LED_G=16'", + "'-D RGB_LED_B=17'", + "'-D BOARD_HAS_CDS'", + "'-D CDS=34'", + "'-D BOARD_HAS_SPEAK'", + "'-D SPEAK=26'", + + "-DCYD_SCREEN_HEIGHT_PX=240", + "-DCYD_SCREEN_WIDTH_PX=320", + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", + "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1", + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-2432S032C-SD", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005006224494145.html", + "vendor": "Sunton" + } \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 7a62560..f3bb4fb 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -43,8 +43,11 @@ lib_deps = bblanchon/ArduinoJson@^7.0.0 plageoj/UrlEncode@^1.0.1 -[env:esp32-3248S035C-smartdisplay] +[env:esp32-3248S035C-SD] board = esp32-3248S035C-smartdisplay -[env:esp32-2432S028R-smartdisplay] +[env:esp32-2432S028R-SD] board = esp32-2432S028R-smartdisplay + +[env:esp32-2432S032C-SD] +board = esp32-2432S032C-smartdisplay \ No newline at end of file From fc7cfbd85b1b5c5b4af5c9c8141b13f07c5707c4 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:22:18 +0100 Subject: [PATCH 06/42] Add esp32-2432S032C to CI --- ci.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci.py b/ci.py index f22f181..6e259f1 100644 --- a/ci.py +++ b/ci.py @@ -1,6 +1,6 @@ import subprocess, os, shutil, json -CYD_PORTS = ["esp32-3248S035C", "esp32-2432S028R"] +CYD_PORTS = ["esp32-3248S035C", "esp32-2432S028R", "esp32-2432S032C-SD"] BASE_DIR = os.getcwd() def get_manifest(base_path : str, device_name : str): From 3fbd14f15491e4627b100c6f04b7c7ebd5c15aaf Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 10:38:34 +0100 Subject: [PATCH 07/42] Hopefully fix esp32-8048S043C --- CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json index d2a8eac..cdf84a2 100644 --- a/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json @@ -21,7 +21,7 @@ "'-D BCKL=2'", "'-D LCD_ST7262_PAR'", "'-D ST7262_PANEL_CONFIG_CLK_SRC=LCD_CLK_SRC_PLL160M'", - "'-D ST7262_PANEL_CONFIG_TIMINGS_PCLK_HZ=(8*1000000)'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_PCLK_HZ=(12.5*1000000)'", "'-D ST7262_PANEL_CONFIG_TIMINGS_H_RES=LCD_WIDTH'", "'-D ST7262_PANEL_CONFIG_TIMINGS_V_RES=LCD_HEIGHT'", "'-D ST7262_PANEL_CONFIG_TIMINGS_HSYNC_PULSE_WIDTH=4'", @@ -84,7 +84,7 @@ "'-D GT911_TOUCH_CONFIG_INT_GPIO_NUM=18'", "'-D GT911_TOUCH_CONFIG_LEVELS_RESET=0'", "'-D GT911_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", - "'-D TOUCH_SWAP_XY=true'", + "'-D TOUCH_SWAP_XY=false'", "'-D TOUCH_SWAP_X=false'", "'-D TOUCH_SWAP_Y=false'", "'-D BOARD_HAS_TF'", @@ -93,6 +93,10 @@ "'-D TF_SPI_SCLK=12'", "'-D TF_SPI_MISO=13'", + "-DCYD_SCREEN_HEIGHT_PX=480", + "-DCYD_SCREEN_WIDTH_PX=800", + "-DROTATION_INVERTED=LV_DISP_ROT_180", + "-DROTATION_NORMAL=LV_DISP_ROT_NONE", "-DCYD_SCREEN_GAP_PX=10", "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=40", "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=40", @@ -100,8 +104,7 @@ "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12", "-DCYD_SCREEN_SIDEBAR_SIZE_PX=50", "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1", - "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1", - "-DCYD_SCREEN_DISABLE_INVERT_COLORS=1" + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1" ], "f_cpu": "240000000L", "f_flash": "80000000L", From 64290afd89b33e45204060001db2e30ff0d1794b Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 14:18:37 +0100 Subject: [PATCH 08/42] Set size for settings dropdown --- CYD-Klipper/src/ui/panels/settings_panel.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 915964a..165679a 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -130,6 +130,9 @@ void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); } +#define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75 +#define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2 + void settings_panel_init(lv_obj_t* panel){ lv_obj_t * toggle = NULL; lv_obj_t * btn = NULL; @@ -162,7 +165,7 @@ void settings_panel_init(lv_obj_t* panel){ #ifndef CYD_SCREEN_DISABLE_INVERT_COLORS toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); + lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, invert_color_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.invertColors) @@ -172,7 +175,7 @@ void settings_panel_init(lv_obj_t* panel){ #endif // CYD_SCREEN_DISABLE_INVERT_COLORS toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); + lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, light_mode_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.lightMode) @@ -183,12 +186,14 @@ void settings_panel_init(lv_obj_t* panel){ dropdown = lv_dropdown_create(panel); lv_dropdown_set_options(dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple"); lv_dropdown_set_selected(dropdown, global_config.color_scheme); + lv_obj_set_width(dropdown, DROPDOWN_WIDTH); lv_obj_add_event_cb(dropdown, theme_dropdown, LV_EVENT_VALUE_CHANGED, NULL); create_settings_widget("Theme", dropdown, panel); dropdown = lv_dropdown_create(panel); lv_dropdown_set_options(dropdown, brightness_options); + lv_obj_set_width(dropdown, DROPDOWN_WIDTH); lv_obj_add_event_cb(dropdown, brightness_dropdown, LV_EVENT_VALUE_CHANGED, NULL); for (int i = 0; i < SIZEOF(brightness_options_values); i++){ @@ -203,6 +208,7 @@ void settings_panel_init(lv_obj_t* panel){ #ifndef CYD_SCREEN_DISABLE_TIMEOUT dropdown = lv_dropdown_create(panel); lv_dropdown_set_options(dropdown, wake_timeout_options); + lv_obj_set_width(dropdown, DROPDOWN_WIDTH); lv_obj_add_event_cb(dropdown, wake_timeout_dropdown, LV_EVENT_VALUE_CHANGED, NULL); for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){ @@ -217,13 +223,14 @@ void settings_panel_init(lv_obj_t* panel){ dropdown = lv_dropdown_create(panel); lv_dropdown_set_options(dropdown, estimated_time_options); + lv_obj_set_width(dropdown, DROPDOWN_WIDTH); lv_obj_add_event_cb(dropdown, estimated_time_dropdown, LV_EVENT_VALUE_CHANGED, NULL); lv_dropdown_set_selected(dropdown, global_config.remaining_time_calc_mode); create_settings_widget("Estimated Time", dropdown, panel); toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); + lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, rotate_screen_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.rotateScreen) @@ -233,7 +240,7 @@ void settings_panel_init(lv_obj_t* panel){ #ifndef CYD_SCREEN_DISABLE_TIMEOUT toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); + lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, on_during_print_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.onDuringPrint) @@ -243,7 +250,7 @@ void settings_panel_init(lv_obj_t* panel){ #endif toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); + lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, auto_ota_update_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.autoOtaUpdate) From 1adb966ee1466a6439bc1df63a7812054e0a6f15 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:05:16 +0100 Subject: [PATCH 09/42] Image load round 2 (slightly less unstable) --- CYD-Klipper/src/conf/lv_conf.h | 16 +- .../src/core/device/ESP32-smartdisplay.cpp | 1 - CYD-Klipper/src/core/lv_setup.cpp | 1 + CYD-Klipper/src/ui/gcode_img.cpp | 149 ++++++++++++++++++ CYD-Klipper/src/ui/gcode_img.h | 6 + CYD-Klipper/src/ui/panels/print_panel.cpp | 9 ++ 6 files changed, 173 insertions(+), 9 deletions(-) create mode 100644 CYD-Klipper/src/ui/gcode_img.cpp create mode 100644 CYD-Klipper/src/ui/gcode_img.h diff --git a/CYD-Klipper/src/conf/lv_conf.h b/CYD-Klipper/src/conf/lv_conf.h index 76bbcbe..a404d70 100644 --- a/CYD-Klipper/src/conf/lv_conf.h +++ b/CYD-Klipper/src/conf/lv_conf.h @@ -49,7 +49,7 @@ #define LV_MEM_CUSTOM 0 #if LV_MEM_CUSTOM == 0 /*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/ - #define LV_MEM_SIZE (32U * 1024U) /*[bytes]*/ + #define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/ /*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/ #define LV_MEM_ADR 0 /*0: unused*/ @@ -194,7 +194,7 @@ *-----------*/ /*Enable the log module*/ -#define LV_USE_LOG 1 +#define LV_USE_LOG 0 #if LV_USE_LOG /*How important log should be added: @@ -204,7 +204,7 @@ *LV_LOG_LEVEL_ERROR Only critical issue, when the system may fail *LV_LOG_LEVEL_USER Only logs added by the user *LV_LOG_LEVEL_NONE Do not log anything*/ - #define LV_LOG_LEVEL LV_LOG_LEVEL_USER + #define LV_LOG_LEVEL LV_LOG_LEVEL_NONE /*1: Print the log with 'printf'; *0: User need to register a callback with `lv_log_register_print_cb()`*/ @@ -254,7 +254,7 @@ /*1: Show the used memory and the memory fragmentation * Requires LV_MEM_CUSTOM = 0*/ -#define LV_USE_MEM_MONITOR 0 +#define LV_USE_MEM_MONITOR 1 #if LV_USE_MEM_MONITOR #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT #endif @@ -607,7 +607,7 @@ #endif /*PNG decoder library*/ -#define LV_USE_PNG 0 +#define LV_USE_PNG 1 /*BMP decoder library*/ #define LV_USE_BMP 0 @@ -678,16 +678,16 @@ ====================*/ /*Show some widget. It might be required to increase `LV_MEM_SIZE` */ -#define LV_USE_DEMO_WIDGETS 1 +#define LV_USE_DEMO_WIDGETS 0 #if LV_USE_DEMO_WIDGETS #define LV_DEMO_WIDGETS_SLIDESHOW 1 #endif /*Demonstrate the usage of encoder and keyboard*/ -#define LV_USE_DEMO_KEYPAD_AND_ENCODER 1 +#define LV_USE_DEMO_KEYPAD_AND_ENCODER 0 /*Benchmark your system*/ -#define LV_USE_DEMO_BENCHMARK 1 +#define LV_USE_DEMO_BENCHMARK 0 /*Stress test for LVGL*/ #define LV_USE_DEMO_STRESS 0 diff --git a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp index 5e29e05..3ca7b3a 100644 --- a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp +++ b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp @@ -1,4 +1,3 @@ - #ifdef CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY #include "../screen_driver.h" diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index 5b2d53c..176916b 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -271,6 +271,7 @@ void lv_setup() screen_timer_setup(); screen_timer_start(); set_screen_brightness(); + lv_png_init(); } bool is_screen_asleep() diff --git a/CYD-Klipper/src/ui/gcode_img.cpp b/CYD-Klipper/src/ui/gcode_img.cpp new file mode 100644 index 0000000..be238a0 --- /dev/null +++ b/CYD-Klipper/src/ui/gcode_img.cpp @@ -0,0 +1,149 @@ +#include "gcode_img.h" +#include "lvgl.h" +#include "ui_utils.h" +#include +#include +#include "../conf/global_config.h" +#include + +static unsigned char * data_png = NULL; +static char img_filename_path[256] = {0}; +static lv_img_dsc_t img_header = {0}; + +static void close_button_click(lv_event_t * e){ + lv_obj_t * root = (lv_obj_t *)lv_event_get_user_data(e); + lv_obj_del(root); + clear_img_mem(); +} + +bool has_128_128_gcode(const char* filename) +{ + if (filename == NULL){ + Serial.println("No gcode filename"); + return false; + } + + String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/server/files/thumbnails?filename=" + String(filename); + HTTPClient client; + int httpCode = 0; + try { + client.begin(url.c_str()); + httpCode = client.GET(); + } + catch (...){ + Serial.println("Exception while fetching gcode img location"); + return {0}; + } + + if (httpCode == 200) + { + String payload = client.getString(); + JsonDocument doc; + deserializeJson(doc, payload); + auto result = doc["result"].as(); + const char* chosen_thumb = NULL; + + for (auto file : result){ + int width = file["width"]; + int height = file["height"]; + int size = file["size"]; + const char* thumbnail = file["thumbnail_path"]; + + if (width != height || width != 32) + continue; + + if (strcmp(thumbnail + strlen(thumbnail) - 4, ".png")) + continue; + + chosen_thumb = thumbnail; + break; + } + + if (chosen_thumb != NULL){ + Serial.printf("Found 128x128 PNG gcode img at %s\n", filename); + strcpy(img_filename_path, chosen_thumb); + return true; + } + } + + return false; +} + +lv_obj_t* draw_gcode_img() +{ + clear_img_mem(); + + if (img_filename_path[0] == 0){ + Serial.println("No gcode img path"); + return NULL; + } + + HTTPClient client; + int httpCode = 0; + try { + String img_url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/server/files/gcodes/" + String(img_filename_path); + client.begin(img_url); + httpCode = client.GET(); + } + catch (...){ + Serial.println("Exception while fetching gcode img"); + return NULL; + } + + if (httpCode == 200) + { + size_t len = client.getSize(); + if (len <= 0) + { + Serial.println("No gcode img data"); + return NULL; + } + + data_png = (unsigned char*)malloc(len + 1); + if (len != client.getStream().readBytes(data_png, len)){ + Serial.println("Failed to read gcode img data"); + clear_img_mem(); + return NULL; + } + + Serial.println((char*)data_png); + + memset(&img_header, 0, sizeof(img_header)); + img_header.header.w = 32; + img_header.header.h = 32; + img_header.data_size = len; + img_header.header.cf = LV_IMG_CF_RAW_ALPHA; + img_header.data = data_png; + + lv_obj_t * img = lv_img_create(lv_scr_act()); + lv_img_set_src(img, &img_header); + //lv_img_set_zoom(img, 512); + + return img; + } + + return NULL; +} + +lv_obj_t* show_gcode_img(const char* filename) +{ + if (filename == NULL){ + Serial.println("No gcode filename"); + return NULL; + } + + if (!has_128_128_gcode(filename)){ + Serial.println("No 128x128 gcode img found"); + return NULL; + } + + return draw_gcode_img(); +} + +void clear_img_mem() +{ + if (data_png != NULL){ + free(data_png); + data_png = NULL; + } +} \ No newline at end of file diff --git a/CYD-Klipper/src/ui/gcode_img.h b/CYD-Klipper/src/ui/gcode_img.h new file mode 100644 index 0000000..75f7074 --- /dev/null +++ b/CYD-Klipper/src/ui/gcode_img.h @@ -0,0 +1,6 @@ +#pragma once +#include "lvgl.h" + +lv_obj_t* show_gcode_img(const char* filename); +bool has_128_128_gcode(const char* filename); +void clear_img_mem(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index e51d88f..af1f576 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -7,6 +7,7 @@ #include #include "../ui_utils.h" #include "../../core/lv_setup.h" +#include "../gcode_img.h" FILESYSTEM_FILE* selected_file = NULL; @@ -83,6 +84,14 @@ static void btn_print_file_verify(lv_event_t * e){ label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_OK); lv_obj_center(label); + + lv_obj_t* img = show_gcode_img(selected_file->name); + + if (img != NULL){ + lv_obj_set_parent(img, panel); + lv_obj_align(img, LV_ALIGN_BOTTOM_MID, 0, 0); + //lv_obj_set_size(img, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); + } } void print_panel_init(lv_obj_t* panel){ From 639eb50371429ebce4091bbc2b4aac8e1fcf657e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:16:31 +0100 Subject: [PATCH 10/42] A --- CYD-Klipper/src/conf/lv_conf.h | 2 +- CYD-Klipper/src/ui/gcode_img.cpp | 2 -- CYD-Klipper/src/ui/panels/print_panel.cpp | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CYD-Klipper/src/conf/lv_conf.h b/CYD-Klipper/src/conf/lv_conf.h index a404d70..6b6ab9c 100644 --- a/CYD-Klipper/src/conf/lv_conf.h +++ b/CYD-Klipper/src/conf/lv_conf.h @@ -49,7 +49,7 @@ #define LV_MEM_CUSTOM 0 #if LV_MEM_CUSTOM == 0 /*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/ - #define LV_MEM_SIZE (48U * 1024U) /*[bytes]*/ + #define LV_MEM_SIZE (41U * 1024U) /*[bytes]*/ /*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/ #define LV_MEM_ADR 0 /*0: unused*/ diff --git a/CYD-Klipper/src/ui/gcode_img.cpp b/CYD-Klipper/src/ui/gcode_img.cpp index be238a0..507b948 100644 --- a/CYD-Klipper/src/ui/gcode_img.cpp +++ b/CYD-Klipper/src/ui/gcode_img.cpp @@ -106,8 +106,6 @@ lv_obj_t* draw_gcode_img() return NULL; } - Serial.println((char*)data_png); - memset(&img_header, 0, sizeof(img_header)); img_header.header.w = 32; img_header.header.h = 32; diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index af1f576..ffade1a 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -100,6 +100,8 @@ void print_panel_init(lv_obj_t* panel){ return; } + clear_img_mem(); + lv_obj_t * list = lv_list_create(panel); lv_obj_set_style_radius(list, 0, 0); lv_obj_set_style_border_width(list, 0, 0); From bc3ca3892f5753bebd678246f0aaeb31a8c43025 Mon Sep 17 00:00:00 2001 From: themacboy Date: Sat, 2 Mar 2024 21:57:00 +0100 Subject: [PATCH 11/42] Some visual UI tweaks for ESP32-8048S043C (#57) * Some visual UI tweaks * more visual UI tweaks adjustements --- CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json | 12 ++++++------ CYD-Klipper/src/conf/lv_conf.h | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json index cdf84a2..d98466a 100644 --- a/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json @@ -97,12 +97,12 @@ "-DCYD_SCREEN_WIDTH_PX=800", "-DROTATION_INVERTED=LV_DISP_ROT_180", "-DROTATION_NORMAL=LV_DISP_ROT_NONE", - "-DCYD_SCREEN_GAP_PX=10", - "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=40", - "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=40", - "-DCYD_SCREEN_FONT=lv_font_montserrat_16", - "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12", - "-DCYD_SCREEN_SIDEBAR_SIZE_PX=50", + "-DCYD_SCREEN_GAP_PX=15", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=60", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=60", + "-DCYD_SCREEN_FONT=lv_font_montserrat_22", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_16", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=70", "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1", "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1" ], diff --git a/CYD-Klipper/src/conf/lv_conf.h b/CYD-Klipper/src/conf/lv_conf.h index 76bbcbe..dde62e5 100644 --- a/CYD-Klipper/src/conf/lv_conf.h +++ b/CYD-Klipper/src/conf/lv_conf.h @@ -336,7 +336,7 @@ #define LV_FONT_MONTSERRAT_16 1 #define LV_FONT_MONTSERRAT_18 0 #define LV_FONT_MONTSERRAT_20 0 -#define LV_FONT_MONTSERRAT_22 0 +#define LV_FONT_MONTSERRAT_22 1 #define LV_FONT_MONTSERRAT_24 0 #define LV_FONT_MONTSERRAT_26 0 #define LV_FONT_MONTSERRAT_28 1 From 4e6457c7295fdcb052f7afe3f8156814016a1328 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:02:20 +0100 Subject: [PATCH 12/42] Misc fixes --- CYD-Klipper/src/conf/lv_conf.h | 4 ++-- CYD-Klipper/src/core/device/ESP32-2432S028R.cpp | 2 +- CYD-Klipper/src/ui/gcode_img.cpp | 1 - CYD-Klipper/src/ui/panels/print_panel.cpp | 1 - 4 files changed, 3 insertions(+), 5 deletions(-) diff --git a/CYD-Klipper/src/conf/lv_conf.h b/CYD-Klipper/src/conf/lv_conf.h index 6b6ab9c..9c14919 100644 --- a/CYD-Klipper/src/conf/lv_conf.h +++ b/CYD-Klipper/src/conf/lv_conf.h @@ -49,7 +49,7 @@ #define LV_MEM_CUSTOM 0 #if LV_MEM_CUSTOM == 0 /*Size of the memory available for `lv_mem_alloc()` in bytes (>= 2kB)*/ - #define LV_MEM_SIZE (41U * 1024U) /*[bytes]*/ + #define LV_MEM_SIZE (40U * 1024U) /*[bytes]*/ /*Set an address for the memory pool instead of allocating it as a normal array. Can be in external SRAM too.*/ #define LV_MEM_ADR 0 /*0: unused*/ @@ -254,7 +254,7 @@ /*1: Show the used memory and the memory fragmentation * Requires LV_MEM_CUSTOM = 0*/ -#define LV_USE_MEM_MONITOR 1 +#define LV_USE_MEM_MONITOR 0 #if LV_USE_MEM_MONITOR #define LV_USE_MEM_MONITOR_POS LV_ALIGN_BOTTOM_LEFT #endif diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index d2734d8..65f234f 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -86,7 +86,7 @@ void screen_setup() tft.setRotation(global_config.rotateScreen ? 3 : 1); tft.fillScreen(TFT_BLACK); set_invert_display(); - + set_screen_brightness(); touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); touchscreen.begin(touchscreen_spi); diff --git a/CYD-Klipper/src/ui/gcode_img.cpp b/CYD-Klipper/src/ui/gcode_img.cpp index 507b948..ad1ab07 100644 --- a/CYD-Klipper/src/ui/gcode_img.cpp +++ b/CYD-Klipper/src/ui/gcode_img.cpp @@ -115,7 +115,6 @@ lv_obj_t* draw_gcode_img() lv_obj_t * img = lv_img_create(lv_scr_act()); lv_img_set_src(img, &img_header); - //lv_img_set_zoom(img, 512); return img; } diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index ffade1a..357861e 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -90,7 +90,6 @@ static void btn_print_file_verify(lv_event_t * e){ if (img != NULL){ lv_obj_set_parent(img, panel); lv_obj_align(img, LV_ALIGN_BOTTOM_MID, 0, 0); - //lv_obj_set_size(img, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); } } From c061164edf884743927f9b36b49233597313cf26 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:06:15 +0100 Subject: [PATCH 13/42] Fix compile on linux --- CYD-Klipper/src/ui/gcode_img.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CYD-Klipper/src/ui/gcode_img.cpp b/CYD-Klipper/src/ui/gcode_img.cpp index ad1ab07..ac9872b 100644 --- a/CYD-Klipper/src/ui/gcode_img.cpp +++ b/CYD-Klipper/src/ui/gcode_img.cpp @@ -1,7 +1,7 @@ #include "gcode_img.h" #include "lvgl.h" #include "ui_utils.h" -#include +#include #include #include "../conf/global_config.h" #include From cb242240d38bd80c5edf7250bc38d3cb5e5d5fbb Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:11:39 +0100 Subject: [PATCH 14/42] Remove unneeded code --- CYD-Klipper/src/ui/gcode_img.cpp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/CYD-Klipper/src/ui/gcode_img.cpp b/CYD-Klipper/src/ui/gcode_img.cpp index ac9872b..fe4523a 100644 --- a/CYD-Klipper/src/ui/gcode_img.cpp +++ b/CYD-Klipper/src/ui/gcode_img.cpp @@ -10,12 +10,6 @@ static unsigned char * data_png = NULL; static char img_filename_path[256] = {0}; static lv_img_dsc_t img_header = {0}; -static void close_button_click(lv_event_t * e){ - lv_obj_t * root = (lv_obj_t *)lv_event_get_user_data(e); - lv_obj_del(root); - clear_img_mem(); -} - bool has_128_128_gcode(const char* filename) { if (filename == NULL){ @@ -60,7 +54,7 @@ bool has_128_128_gcode(const char* filename) } if (chosen_thumb != NULL){ - Serial.printf("Found 128x128 PNG gcode img at %s\n", filename); + Serial.printf("Found 32x32 PNG gcode img at %s\n", filename); strcpy(img_filename_path, chosen_thumb); return true; } @@ -130,7 +124,7 @@ lv_obj_t* show_gcode_img(const char* filename) } if (!has_128_128_gcode(filename)){ - Serial.println("No 128x128 gcode img found"); + Serial.println("No 32x32 gcode img found"); return NULL; } From b65003e40b6e2d914416eecda59772090dae5469 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Mar 2024 23:50:24 +0100 Subject: [PATCH 15/42] Better button sizes for esp32-3248S035C --- CYD-Klipper/boards/esp32-3248S035C.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CYD-Klipper/boards/esp32-3248S035C.json b/CYD-Klipper/boards/esp32-3248S035C.json index 5c39227..6086533 100644 --- a/CYD-Klipper/boards/esp32-3248S035C.json +++ b/CYD-Klipper/boards/esp32-3248S035C.json @@ -24,8 +24,8 @@ "-DCYD_SCREEN_HEIGHT_PX=320", "-DCYD_SCREEN_WIDTH_PX=480", "-DCYD_SCREEN_GAP_PX=10", - "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=40", - "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=40", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=45", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=45", "-DCYD_SCREEN_FONT=lv_font_montserrat_16", "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12", "-DCYD_SCREEN_SIDEBAR_SIZE_PX=50", From 02e27e6d8377f4150db58aa821ca2a9ba29536bf Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 3 Mar 2024 01:00:09 +0100 Subject: [PATCH 16/42] Set screen brightness in lvgl setup --- CYD-Klipper/src/core/device/ESP32-2432S028R.cpp | 1 - CYD-Klipper/src/core/lv_setup.cpp | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index 65f234f..e8a3f70 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -86,7 +86,6 @@ void screen_setup() tft.setRotation(global_config.rotateScreen ? 3 : 1); tft.fillScreen(TFT_BLACK); set_invert_display(); - set_screen_brightness(); touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); touchscreen.begin(touchscreen_spi); diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index 176916b..880af74 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -253,6 +253,8 @@ void set_color_scheme() void lv_setup() { + set_screen_brightness(); + lv_indev_t * display_driver = lv_indev_get_next(NULL); if (original_touch_driver == NULL) @@ -270,7 +272,6 @@ void lv_setup() screen_timer_setup(); screen_timer_start(); - set_screen_brightness(); lv_png_init(); } From 9427381e051d91d296a985561bb1d27d84a9a869 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 3 Mar 2024 01:02:52 +0100 Subject: [PATCH 17/42] Add other CYD 2.8R inch models for smartdisplay --- .../esp32-2432S028RV1-smartdisplay.json | 125 ++++++++++++++++++ .../esp32-2432S028RV2-smartdisplay.json | 125 ++++++++++++++++++ ...on => esp32-2432S028RV3-smartdisplay.json} | 2 +- CYD-Klipper/platformio.ini | 18 ++- 4 files changed, 263 insertions(+), 7 deletions(-) create mode 100644 CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json create mode 100644 CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json rename CYD-Klipper/boards/{esp32-2432S028R-smartdisplay.json => esp32-2432S028RV3-smartdisplay.json} (99%) diff --git a/CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json new file mode 100644 index 0000000..9db9ad3 --- /dev/null +++ b/CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json @@ -0,0 +1,125 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "'-D ARDUINO_ESP32_DEV'", + "'-D ESP32_2432S028R'", + "'-D LCD_WIDTH=240'", + "'-D LCD_HEIGHT=320'", + "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", + "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", + "'-D BCKL=21'", + "'-D LCD_ILI9341_SPI'", + "'-D ILI9341_SPI_HOST=SPI2_HOST'", + "'-D ILI9341_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", + "'-D ILI9341_SPI_BUS_MOSI_IO_NUM=13'", + "'-D ILI9341_SPI_BUS_MISO_IO_NUM=12'", + "'-D ILI9341_SPI_BUS_SCLK_IO_NUM=14'", + "'-D ILI9341_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ILI9341_SPI_BUS_FLAGS=0'", + "'-D ILI9341_SPI_BUS_INTR_FLAGS=0'", + "'-D ILI9341_SPI_CONFIG_CS_GPIO_NUM=15'", + "'-D ILI9341_SPI_CONFIG_DC_GPIO_NUM=2'", + "'-D ILI9341_SPI_CONFIG_SPI_MODE=SPI_MODE0'", + "'-D ILI9341_SPI_CONFIG_PCLK_HZ=24000000'", + "'-D ILI9341_SPI_CONFIG_TRANS_QUEUE_DEPTH=10'", + "'-D ILI9341_SPI_CONFIG_LCD_CMD_BITS=8'", + "'-D ILI9341_SPI_CONFIG_LCD_PARAM_BITS=8'", + "'-D ILI9341_SPI_CONFIG_FLAGS_DC_AS_CMD_PHASE=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_OCTAL_MODE=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_LSB_FIRST=false'", + "'-D ILI9341_DEV_CONFIG_RESET_GPIO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_DEV_CONFIG_COLOR_SPACE=ESP_LCD_COLOR_SPACE_BGR'", + "'-D ILI9341_DEV_CONFIG_BITS_PER_PIXEL=16'", + "'-D ILI9341_DEV_CONFIG_FLAGS_RESET_ACTIVE_HIGH=false'", + "'-D ILI9341_DEV_CONFIG_VENDOR_CONFIG=NULL'", + "'-D LCD_SWAP_XY=false'", + "'-D LCD_MIRROR_X=true'", + "'-D LCD_MIRROR_Y=false'", + "'-D BOARD_HAS_TOUCH'", + "'-D TOUCH_XPT2046_SPI'", + "'-D XPT2046_SPI_HOST=SPI3_HOST'", + "'-D XPT2046_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", + "'-D XPT2046_SPI_BUS_MOSI_IO_NUM=32'", + "'-D XPT2046_SPI_BUS_MISO_IO_NUM=39'", + "'-D XPT2046_SPI_BUS_SCLK_IO_NUM=25'", + "'-D XPT2046_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_SPI_CONFIG_CS_GPIO_NUM=33'", + "'-D XPT2046_SPI_CONFIG_DC_GPIO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_SPI_CONFIG_SPI_MODE=SPI_MODE0'", + "'-D XPT2046_SPI_CONFIG_PCLK_HZ=2000000'", + "'-D XPT2046_SPI_CONFIG_TRANS_QUEUE_DEPTH=3'", + "'-D XPT2046_SPI_CONFIG_LCD_CMD_BITS=8'", + "'-D XPT2046_SPI_CONFIG_LCD_PARAM_BITS=8'", + "'-D XPT2046_SPI_CONFIG_FLAGS_DC_AS_CMD_PHASE=false'", + "'-D XPT2046_SPI_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D XPT2046_SPI_CONFIG_FLAGS_OCTAL_MODE=false'", + "'-D XPT2046_SPI_CONFIG_FLAGS_LSB_FIRST=false'", + "'-D XPT2046_TOUCH_CONFIG_X_MAX=LCD_WIDTH'", + "'-D XPT2046_TOUCH_CONFIG_Y_MAX=LCD_HEIGHT'", + "'-D XPT2046_TOUCH_CONFIG_RST_GPIO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_TOUCH_CONFIG_INT_GPIO_NUM=36'", + "'-D XPT2046_TOUCH_CONFIG_LEVELS_RESET=0'", + "'-D XPT2046_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", + "'-D TOUCH_SWAP_XY=true'", + "'-D TOUCH_SWAP_X=true'", + "'-D TOUCH_SWAP_Y=false'", + "'-D BOARD_HAS_TF'", + "'-D TF_CS=5'", + "'-D TF_SPI_MOSI=23'", + "'-D TF_SPI_SCLK=18'", + "'-D TF_SPI_MISO=19'", + "'-D BOARD_HAS_RGB_LED'", + "'-D RGB_LED_R=4'", + "'-D RGB_LED_G=16'", + "'-D RGB_LED_B=17'", + "'-D BOARD_HAS_CDS'", + "'-D CDS=34'", + "'-D BOARD_HAS_SPEAK'", + "'-D SPEAK=26'", + + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", + "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-2432S028Rv1-SD", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005004502250619.html", + "vendor": "Sunton" + } \ No newline at end of file diff --git a/CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json new file mode 100644 index 0000000..b99744c --- /dev/null +++ b/CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json @@ -0,0 +1,125 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "'-D ARDUINO_ESP32_DEV'", + "'-D ESP32_2432S028Rv2'", + "'-D LCD_WIDTH=240'", + "'-D LCD_HEIGHT=320'", + "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", + "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", + "'-D BCKL=21'", + "'-D LCD_ILI9341_SPI'", + "'-D ILI9341_SPI_HOST=SPI2_HOST'", + "'-D ILI9341_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", + "'-D ILI9341_SPI_BUS_MOSI_IO_NUM=13'", + "'-D ILI9341_SPI_BUS_MISO_IO_NUM=12'", + "'-D ILI9341_SPI_BUS_SCLK_IO_NUM=14'", + "'-D ILI9341_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ILI9341_SPI_BUS_FLAGS=0'", + "'-D ILI9341_SPI_BUS_INTR_FLAGS=0'", + "'-D ILI9341_SPI_CONFIG_CS_GPIO_NUM=15'", + "'-D ILI9341_SPI_CONFIG_DC_GPIO_NUM=2'", + "'-D ILI9341_SPI_CONFIG_SPI_MODE=SPI_MODE0'", + "'-D ILI9341_SPI_CONFIG_PCLK_HZ=24000000'", + "'-D ILI9341_SPI_CONFIG_TRANS_QUEUE_DEPTH=10'", + "'-D ILI9341_SPI_CONFIG_LCD_CMD_BITS=8'", + "'-D ILI9341_SPI_CONFIG_LCD_PARAM_BITS=8'", + "'-D ILI9341_SPI_CONFIG_FLAGS_DC_AS_CMD_PHASE=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_OCTAL_MODE=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_LSB_FIRST=false'", + "'-D ILI9341_DEV_CONFIG_RESET_GPIO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_DEV_CONFIG_COLOR_SPACE=ESP_LCD_COLOR_SPACE_BGR'", + "'-D ILI9341_DEV_CONFIG_BITS_PER_PIXEL=16'", + "'-D ILI9341_DEV_CONFIG_FLAGS_RESET_ACTIVE_HIGH=false'", + "'-D ILI9341_DEV_CONFIG_VENDOR_CONFIG=\"(ili9341_vendor_config_t[]){{.init_cmds=(ili9341_lcd_init_cmd_t[]){{.cmd=0xCF,.data=(uint8_t[]){0x00,0xC1,0x30},.data_bytes=3},{.cmd=0xED,.data=(uint8_t[]){0x64,0x03,0x12,0x81},.data_bytes=4},{.cmd=0xE8,.data=(uint8_t[]){0x85,0x00,0x78},.data_bytes=3},{.cmd=0xCB,.data=(uint8_t[]){0x39,0x2C,0x00,0x34,0x02},.data_bytes=5},{.cmd=0xF7,.data=(uint8_t[]){0x20},.data_bytes=1},{.cmd=0xEA,.data=(uint8_t[]){0x00,0x00},.data_bytes=2},{.cmd=0xC0,.data=(uint8_t[]){0x10},.data_bytes=1},{.cmd=0xC1,.data=(uint8_t[]){0x00},.data_bytes=1},{.cmd=0xC5,.data=(uint8_t[]){0x30,0x30},.data_bytes=2,},{.cmd=0xC7,.data=(uint8_t[]){0xB7},.data_bytes=1},{.cmd=0x3A,.data=(uint8_t[]){0x55},.data_bytes=1},{.cmd=0x36,.data=(uint8_t[]){0x08},.data_bytes=1},{.cmd=0xB1,.data=(uint8_t[]){0x00,0x1A},.data_bytes=2},{.cmd=0xB6,.data=(uint8_t[]){0x08,0x82,0x27},.data_bytes=3},{.cmd=0xF2,.data=(uint8_t[]){0x00},.data_bytes=1},{.cmd=0x26,.data=(uint8_t[]){0x01},.data_bytes=1},{.cmd=0xE0,.data=(uint8_t[]){0x0F,0x2A,0x28,0x08,0x0E,0x08,0x54,0xA9,0x43,0x0A,0x0F,0x00,0x00,0x00,0x00},.data_bytes=15},{.cmd=0xE1,.data=(uint8_t[]){0x00,0x15,0x17,0x07,0x11,0x06,0x2B,0x56,0x3C,0x05,0x10,0x0F,0x3F,0x3F,0x0F},.data_bytes=15},{.cmd=0x2B,.data=(uint8_t[]){0x00,0x00,0x01,0x3F},.data_bytes=4},{.cmd=0x2A,.data=(uint8_t[]){0x00,0x00,0x00,0xEF},.data_bytes=4},{.cmd=0x21},{.cmd=0x11,.delay_ms=120},{.cmd=0x29,.delay_ms=1}},.init_cmds_size=23}}\"'", + "'-D LCD_SWAP_XY=false'", + "'-D LCD_MIRROR_X=true'", + "'-D LCD_MIRROR_Y=false'", + "'-D BOARD_HAS_TOUCH'", + "'-D TOUCH_XPT2046_SPI'", + "'-D XPT2046_SPI_HOST=SPI3_HOST'", + "'-D XPT2046_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", + "'-D XPT2046_SPI_BUS_MOSI_IO_NUM=32'", + "'-D XPT2046_SPI_BUS_MISO_IO_NUM=39'", + "'-D XPT2046_SPI_BUS_SCLK_IO_NUM=25'", + "'-D XPT2046_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_SPI_CONFIG_CS_GPIO_NUM=33'", + "'-D XPT2046_SPI_CONFIG_DC_GPIO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_SPI_CONFIG_SPI_MODE=SPI_MODE0'", + "'-D XPT2046_SPI_CONFIG_PCLK_HZ=2000000'", + "'-D XPT2046_SPI_CONFIG_TRANS_QUEUE_DEPTH=3'", + "'-D XPT2046_SPI_CONFIG_LCD_CMD_BITS=8'", + "'-D XPT2046_SPI_CONFIG_LCD_PARAM_BITS=8'", + "'-D XPT2046_SPI_CONFIG_FLAGS_DC_AS_CMD_PHASE=false'", + "'-D XPT2046_SPI_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D XPT2046_SPI_CONFIG_FLAGS_OCTAL_MODE=false'", + "'-D XPT2046_SPI_CONFIG_FLAGS_LSB_FIRST=false'", + "'-D XPT2046_TOUCH_CONFIG_X_MAX=LCD_WIDTH'", + "'-D XPT2046_TOUCH_CONFIG_Y_MAX=LCD_HEIGHT'", + "'-D XPT2046_TOUCH_CONFIG_RST_GPIO_NUM=GPIO_NUM_NC'", + "'-D XPT2046_TOUCH_CONFIG_INT_GPIO_NUM=36'", + "'-D XPT2046_TOUCH_CONFIG_LEVELS_RESET=0'", + "'-D XPT2046_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", + "'-D TOUCH_SWAP_XY=true'", + "'-D TOUCH_SWAP_X=true'", + "'-D TOUCH_SWAP_Y=false'", + "'-D BOARD_HAS_TF'", + "'-D TF_CS=5'", + "'-D TF_SPI_MOSI=23'", + "'-D TF_SPI_SCLK=18'", + "'-D TF_SPI_MISO=19'", + "'-D BOARD_HAS_RGB_LED'", + "'-D RGB_LED_R=4'", + "'-D RGB_LED_G=16'", + "'-D RGB_LED_B=17'", + "'-D BOARD_HAS_CDS'", + "'-D CDS=34'", + "'-D BOARD_HAS_SPEAK'", + "'-D SPEAK=26'", + + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", + "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-2432S028Rv2-SD", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005004502250619.html", + "vendor": "Sunton" + } \ No newline at end of file diff --git a/CYD-Klipper/boards/esp32-2432S028R-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S028RV3-smartdisplay.json similarity index 99% rename from CYD-Klipper/boards/esp32-2432S028R-smartdisplay.json rename to CYD-Klipper/boards/esp32-2432S028RV3-smartdisplay.json index 19af945..088d369 100644 --- a/CYD-Klipper/boards/esp32-2432S028R-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S028RV3-smartdisplay.json @@ -112,7 +112,7 @@ "arduino", "espidf" ], - "name": "esp32-2432S028Rv3", + "name": "esp32-2432S028Rv3-SD", "upload": { "flash_size": "4MB", "maximum_ram_size": 327680, diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 617451b..b6dfe46 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -43,14 +43,20 @@ lib_deps = bblanchon/ArduinoJson@^7.0.0 plageoj/UrlEncode@^1.0.1 -[env:esp32-3248S035C-SD] -board = esp32-3248S035C-smartdisplay +[env:esp32-2432S028Rv1-SD] +board = esp32-2432S028RV1-smartdisplay -[env:esp32-2432S028R-SD] -board = esp32-2432S028R-smartdisplay +[env:esp32-2432S028Rv2-SD] +board = esp32-2432S028RV2-smartdisplay -[env:esp32-8048S043C-SD] -board = esp32-8048S043C-smartdisplay +[env:esp32-2432S028Rv3-SD] +board = esp32-2432S028RV3-smartdisplay [env:esp32-2432S032C-SD] board = esp32-2432S032C-smartdisplay + +[env:esp32-3248S035C-SD] +board = esp32-3248S035C-smartdisplay + +[env:esp32-8048S043C-SD] +board = esp32-8048S043C-smartdisplay \ No newline at end of file From f0cc211e30715e2e09653553ae865097c9a4bf7d Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:32:49 +0100 Subject: [PATCH 18/42] Unify http client creation --- CYD-Klipper/src/core/data_setup.cpp | 36 ++++------------------- CYD-Klipper/src/core/files_query.cpp | 12 ++------ CYD-Klipper/src/core/http_client.cpp | 26 ++++++++++++++++ CYD-Klipper/src/core/http_client.h | 11 +++++++ CYD-Klipper/src/core/macros_query.cpp | 28 +++--------------- CYD-Klipper/src/ui/gcode_img.cpp | 12 ++++---- CYD-Klipper/src/ui/ip_setup.cpp | 13 ++------ CYD-Klipper/src/ui/panels/print_panel.cpp | 30 ++----------------- 8 files changed, 60 insertions(+), 108 deletions(-) create mode 100644 CYD-Klipper/src/core/http_client.cpp create mode 100644 CYD-Klipper/src/core/http_client.h diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index d60de6e..d104ad3 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -2,11 +2,11 @@ #include "data_setup.h" #include "lvgl.h" #include "../conf/global_config.h" -#include #include #include #include "macros_query.h" #include +#include "http_client.h" const char *printer_state_messages[] = { "Error", @@ -45,22 +45,12 @@ void unfreeze_render_thread(){ void send_gcode(bool wait, const char *gcode) { Serial.printf("Sending gcode: %s\n", gcode); - char buff[256] = {}; - sprintf(buff, "http://%s:%d/printer/gcode/script?script=%s", global_config.klipperHost, global_config.klipperPort, urlEncode(gcode).c_str()); - HTTPClient client; - client.begin(buff); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); - - if (!wait) - { - client.setTimeout(1000); - } + SETUP_HTTP_CLIENT_FULL("/printer/gcode/script?script=" + urlEncode(gcode), false, wait ? 5000 : 750); try { - client.GET(); + int result = client.GET(); + Serial.printf("Send gcode result: %d\n", result); } catch (...) { @@ -75,14 +65,7 @@ int get_slicer_time_estimate_s() delay(10); - char buff[256] = {}; - sprintf(buff, "http://%s:%d/server/files/metadata?filename=%s", global_config.klipperHost, global_config.klipperPort, urlEncode(printer.print_filename).c_str()); - HTTPClient client; - client.useHTTP10(true); - client.begin(buff); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); + SETUP_HTTP_CLIENT("/server/files/metadata?filename=" + urlEncode(printer.print_filename)); int httpCode = client.GET(); @@ -128,14 +111,7 @@ int last_slicer_time_query = -15000; void fetch_printer_data() { freeze_request_thread(); - char buff[256] = {}; - sprintf(buff, "http://%s:%d/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks&fan", global_config.klipperHost, global_config.klipperPort); - HTTPClient client; - client.useHTTP10(true); - client.begin(buff); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); + SETUP_HTTP_CLIENT("/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks&fan") int httpCode = client.GET(); delay(10); diff --git a/CYD-Klipper/src/core/files_query.cpp b/CYD-Klipper/src/core/files_query.cpp index 326623b..57e0983 100644 --- a/CYD-Klipper/src/core/files_query.cpp +++ b/CYD-Klipper/src/core/files_query.cpp @@ -2,9 +2,9 @@ #include "files_query.h" #include "../conf/global_config.h" #include "data_setup.h" -#include #include #include +#include "http_client.h" // Always has +1 entry with a null'd name FILESYSTEM_FILE* last_query = NULL; @@ -27,15 +27,7 @@ FILESYSTEM_FILE* get_files(int limit){ std::list files; auto timer_request = millis(); - char buff[256] = {}; - sprintf(buff, "http://%s:%d/server/files/list", global_config.klipperHost, global_config.klipperPort); - HTTPClient client; - client.useHTTP10(true); - client.setTimeout(5000); - client.begin(buff); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); + SETUP_HTTP_CLIENT_FULL("/server/files/list", true, 5000); int httpCode = client.GET(); auto timer_parse = millis(); diff --git a/CYD-Klipper/src/core/http_client.cpp b/CYD-Klipper/src/core/http_client.cpp new file mode 100644 index 0000000..fb135bf --- /dev/null +++ b/CYD-Klipper/src/core/http_client.cpp @@ -0,0 +1,26 @@ +#include "http_client.h" +#include "../conf/global_config.h" + +String get_full_url(String url_part) +{ + return "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + url_part; +} + +void configure_http_client(HTTPClient &client, String url, bool stream, int timeout) +{ + Serial.println(url); + if (stream){ + client.useHTTP10(true); + } + + if (timeout > 0){ + client.setTimeout(timeout); + client.setConnectTimeout(timeout); + } + + client.begin(url); + + if (global_config.auth_configured) { + client.addHeader("X-Api-Key", global_config.klipper_auth); + } +} \ No newline at end of file diff --git a/CYD-Klipper/src/core/http_client.h b/CYD-Klipper/src/core/http_client.h new file mode 100644 index 0000000..d5c6d61 --- /dev/null +++ b/CYD-Klipper/src/core/http_client.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +String get_full_url(String url_part); + +void configure_http_client(HTTPClient &client, String url, bool stream = true, int timeout = 1000); + +#define SETUP_HTTP_CLIENT(url_part) HTTPClient client; configure_http_client(client, get_full_url(url_part)); + +#define SETUP_HTTP_CLIENT_FULL(url_part, stream, timeout) HTTPClient client; configure_http_client(client, get_full_url(url_part), stream, timeout); \ No newline at end of file diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index 53e639d..fcbf900 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -1,10 +1,10 @@ #include "lvgl.h" #include "macros_query.h" #include "./data_setup.h" -#include #include "../conf/global_config.h" #include #include +#include "http_client.h" static char* macros[64] = {0}; static int macros_count = 0; @@ -14,13 +14,7 @@ static bool power_device_states[16] = {0}; static int power_devices_count = 0; static void _macros_query_internal(){ - String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/printer/gcode/help"; - HTTPClient client; - client.useHTTP10(true); - client.begin(url.c_str()); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); + SETUP_HTTP_CLIENT("/printer/gcode/help") int httpCode = client.GET(); if (httpCode == 200){ @@ -55,15 +49,7 @@ void power_devices_clear(){ } void _power_devices_query_internal(){ - String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/machine/device_power/devices"; - HTTPClient client; - client.useHTTP10(true); - client.setTimeout(500); - client.setConnectTimeout(1000); - client.begin(url.c_str()); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); + SETUP_HTTP_CLIENT("/machine/device_power/devices") int httpCode = client.GET(); if (httpCode == 200){ @@ -94,13 +80,7 @@ static void on_state_change(void * s, lv_msg_t * m) { } bool set_power_state(const char* device_name, bool state) { - String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/machine/device_power/device?device=" + urlEncode(device_name) + "&action=" + (state ? "on" : "off"); - HTTPClient client; - client.useHTTP10(true); - client.begin(url.c_str()); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); + SETUP_HTTP_CLIENT("/machine/device_power/device?device=" + urlEncode(device_name) + "&action=" + (state ? "on" : "off")); if (client.POST("") != 200) return false; diff --git a/CYD-Klipper/src/ui/gcode_img.cpp b/CYD-Klipper/src/ui/gcode_img.cpp index fe4523a..eb7cbe9 100644 --- a/CYD-Klipper/src/ui/gcode_img.cpp +++ b/CYD-Klipper/src/ui/gcode_img.cpp @@ -4,7 +4,7 @@ #include #include #include "../conf/global_config.h" -#include +#include "../core/http_client.h" static unsigned char * data_png = NULL; static char img_filename_path[256] = {0}; @@ -17,11 +17,10 @@ bool has_128_128_gcode(const char* filename) return false; } - String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/server/files/thumbnails?filename=" + String(filename); - HTTPClient client; + SETUP_HTTP_CLIENT("/server/files/thumbnails?filename=" + String(filename)); + int httpCode = 0; try { - client.begin(url.c_str()); httpCode = client.GET(); } catch (...){ @@ -72,11 +71,10 @@ lv_obj_t* draw_gcode_img() return NULL; } - HTTPClient client; + SETUP_HTTP_CLIENT_FULL("/server/files/gcodes/" + String(img_filename_path), false, 2000); + int httpCode = 0; try { - String img_url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/server/files/gcodes/" + String(img_filename_path); - client.begin(img_url); httpCode = client.GET(); } catch (...){ diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index 8cfbbbd..fbea738 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -6,6 +6,7 @@ #include "ui_utils.h" #include "../core/macros_query.h" #include "panels/panel.h" +#include "../core/http_client.h" bool connect_ok = false; lv_obj_t * hostEntry; @@ -36,19 +37,11 @@ enum connection_status_t { }; connection_status_t verify_ip(){ - HTTPClient client; - String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/printer/info"; + SETUP_HTTP_CLIENT_FULL("/printer/info", true, 1000); + int httpCode; try { - client.setTimeout(500); - client.setConnectTimeout(1000); - client.begin(url.c_str()); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); - httpCode = client.GET(); - Serial.printf("%d %s\n", httpCode, url.c_str()); if (httpCode == 401) return CONNECT_AUTH_REQUIRED; diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index 357861e..d869c53 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -4,10 +4,11 @@ #include "../../core/files_query.h" #include "../../conf/global_config.h" #include -#include #include "../ui_utils.h" #include "../../core/lv_setup.h" #include "../gcode_img.h" +#include "../../core/http_client.h" +#include FILESYSTEM_FILE* selected_file = NULL; @@ -15,32 +16,7 @@ static void btn_print_file(lv_event_t * e){ lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e); lv_obj_del(panel); - char* buff = (char*)malloc(128 + (strlen(selected_file->name) * 3)); - sprintf(buff, "http://%s:%d/printer/print/start?filename=", global_config.klipperHost, global_config.klipperPort); - - char* ptr = buff + strlen(buff); - int filename_length = strlen(selected_file->name); - for (int i = 0; i < filename_length; i++){ - char c = selected_file->name[i]; - if (c == ' '){ - *ptr = '%'; - ptr++; - *ptr = '2'; - ptr++; - *ptr = '0'; - } else { - *ptr = c; - } - ptr++; - } - - *ptr = 0; - - HTTPClient client; - client.begin(buff); - - if (global_config.auth_configured) - client.addHeader("X-Api-Key", global_config.klipper_auth); + SETUP_HTTP_CLIENT("/printer/print/start?filename=" + urlEncode(selected_file->name)); int httpCode = client.POST(""); Serial.printf("Print start: HTTP %d\n", httpCode); From 3b7b49c62b88813e2685d7ffca52e511b4ac720c Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 7 Mar 2024 23:25:12 +0100 Subject: [PATCH 19/42] Split configuration; start printer panel --- CYD-Klipper/src/conf/global_config.cpp | 80 +++++++-- CYD-Klipper/src/conf/global_config.h | 82 +++++---- CYD-Klipper/src/core/data_setup.cpp | 108 +++++++++++- CYD-Klipper/src/core/data_setup.h | 8 + .../src/core/device/ESP32-2432S028R.cpp | 6 +- .../src/core/device/ESP32-3248S035C.cpp | 6 +- .../src/core/device/ESP32-smartdisplay.cpp | 4 +- CYD-Klipper/src/core/http_client.cpp | 7 +- CYD-Klipper/src/core/lv_setup.cpp | 37 +++-- CYD-Klipper/src/main.cpp | 2 +- CYD-Klipper/src/ui/ip_setup.cpp | 30 ++-- CYD-Klipper/src/ui/main_ui.cpp | 2 +- CYD-Klipper/src/ui/nav_buttons.cpp | 13 ++ CYD-Klipper/src/ui/ota_setup.cpp | 2 +- CYD-Klipper/src/ui/panels/panel.h | 1 + CYD-Klipper/src/ui/panels/printer_panel.cpp | 155 ++++++++++++++++++ CYD-Klipper/src/ui/panels/settings_panel.cpp | 96 +++++++---- CYD-Klipper/src/ui/panels/temp_panel.cpp | 26 +-- CYD-Klipper/src/ui/wifi_setup.cpp | 16 +- 19 files changed, 533 insertions(+), 148 deletions(-) create mode 100644 CYD-Klipper/src/ui/panels/printer_panel.cpp diff --git a/CYD-Klipper/src/conf/global_config.cpp b/CYD-Klipper/src/conf/global_config.cpp index 7e86626..e717eee 100644 --- a/CYD-Klipper/src/conf/global_config.cpp +++ b/CYD-Klipper/src/conf/global_config.cpp @@ -14,14 +14,16 @@ COLOR_DEF color_defs[] = { {LV_PALETTE_PURPLE, 0, LV_PALETTE_GREY}, }; -void WriteGlobalConfig() { +void write_global_config() +{ Preferences preferences; preferences.begin("global_config", false); preferences.putBytes("global_config", &global_config, sizeof(global_config)); preferences.end(); } -void VerifyVersion(){ +void verify_version() +{ Preferences preferences; if (!preferences.begin("global_config", false)) return; @@ -37,17 +39,73 @@ void VerifyVersion(){ preferences.end(); } -void LoadGlobalConfig() { +PRINTER_CONFIG* get_current_printer_config() +{ + return &global_config.printer_config[global_config.printer_index]; +} + +int get_printer_config_count() +{ + int count = 0; + for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) { + if (global_config.printer_config[i].ip_configured) + count++; + } + return count; +} + +int get_printer_config_free_index() +{ + for (int i = 0; i < PRINTER_CONFIG_COUNT; i++) { + if (!global_config.printer_config[i].ip_configured) + return i; + } + return -1; +} + +void set_printer_config_index(int index) +{ + if (index < 0 || index >= PRINTER_CONFIG_COUNT) + return; + + PRINTER_CONFIG* old_config = &global_config.printer_config[global_config.printer_index]; + PRINTER_CONFIG* new_config = &global_config.printer_config[index]; + + global_config.printer_index = index; + + if (!new_config->ip_configured){ + new_config->raw = old_config->raw; + new_config->ip_configured = false; + new_config->auth_configured = false; + + new_config->printer_name[0] = 0; + new_config->klipper_host[0] = 0; + new_config->klipper_auth[0] = 0; + new_config->klipper_port = 0; + + new_config->color_scheme = old_config->color_scheme; + + for (int i = 0; i < 3; i++){ + new_config->hotend_presets[i] = old_config->hotend_presets[i]; + new_config->bed_presets[i] = old_config->bed_presets[i]; + } + + ESP.restart(); + } +} + +void load_global_config() +{ global_config.version = CONFIG_VERSION; global_config.brightness = 255; - global_config.screenTimeout = 5; - global_config.hotend_presets[0] = 0; - global_config.hotend_presets[1] = 200; - global_config.hotend_presets[2] = 240; - global_config.bed_presets[0] = 0; - global_config.bed_presets[1] = 60; - global_config.bed_presets[2] = 70; - VerifyVersion(); + global_config.screen_timeout = 5; + global_config.printer_config[0].hotend_presets[0] = 0; + global_config.printer_config[0].hotend_presets[1] = 200; + global_config.printer_config[0].hotend_presets[2] = 240; + global_config.printer_config[0].bed_presets[0] = 0; + global_config.printer_config[0].bed_presets[1] = 60; + global_config.printer_config[0].bed_presets[2] = 70; + verify_version(); Preferences preferences; preferences.begin("global_config", true); preferences.getBytes("global_config", &global_config, sizeof(global_config)); diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index 4ed198e..5a67a01 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -3,7 +3,8 @@ #include "lvgl.h" -#define CONFIG_VERSION 4 +#define CONFIG_VERSION 5 +#define PRINTER_CONFIG_COUNT 8 enum { REMAINING_TIME_CALC_PERCENTAGE = 0, @@ -11,47 +12,62 @@ enum { REMAINING_TIME_CALC_SLICER = 2, }; +typedef struct _PRINTER_CONFIG { + union { + unsigned int raw; + struct { + // Internal + bool ip_configured : 1; + bool auth_configured : 1; + + // External + bool light_mode : 1; + bool invert_colors : 1; + unsigned char remaining_time_calc_mode : 2; + }; + }; + + char printer_name[17]; + char klipper_host[65]; + char klipper_auth[33]; + unsigned short klipper_port; + + unsigned char color_scheme; + + unsigned short hotend_presets[3]; + unsigned short bed_presets[3]; +} PRINTER_CONFIG; + typedef struct _GLOBAL_CONFIG { unsigned char version; union { unsigned int raw; struct { // Internal - bool screenCalibrated : 1; - bool wifiConfigured : 1; - bool ipConfigured : 1; + bool screen_calibrated : 1; + bool wifi_configured : 1; // External - bool lightMode : 1; - bool invertColors : 1; - bool rotateScreen : 1; - bool onDuringPrint : 1; - bool autoOtaUpdate : 1; - unsigned char remaining_time_calc_mode : 2; - - // Internal - bool auth_configured : 1; + bool rotate_screen : 1; + bool auto_ota_update : 1; + bool multi_printer_mode : 1; + bool on_during_print : 1; }; }; - float screenCalXOffset; - float screenCalXMult; - float screenCalYOffset; - float screenCalYMult; - char wifiSSID[32]; - char wifiPassword[64]; + PRINTER_CONFIG printer_config[PRINTER_CONFIG_COUNT]; - char klipperHost[64]; - unsigned short klipperPort; + float screen_cal_x_offset; + float screen_cal_x_mult; + float screen_cal_y_offset; + float screen_cal_y_mult; + + char wifi_SSID[32]; + char wifi_password[64]; - unsigned char color_scheme; unsigned char brightness; - unsigned char screenTimeout; - - unsigned short hotend_presets[3]; - unsigned short bed_presets[3]; - - char klipper_auth[33]; + unsigned char screen_timeout; + unsigned char printer_index; } GLOBAL_CONFIG; typedef struct _COLOR_DEF { @@ -63,8 +79,12 @@ typedef struct _COLOR_DEF { extern GLOBAL_CONFIG global_config; extern COLOR_DEF color_defs[]; -void WriteGlobalConfig(); -void VerifyVersion(); -void LoadGlobalConfig(); +void write_global_config(); +void verify_version(); +void load_global_config(); + +PRINTER_CONFIG* get_current_printer_config(); +int get_printer_config_count(); +void set_printer_config_index(int index); #endif // !_GLOBAL_CONFIG_INIT \ No newline at end of file diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index d104ad3..c09743e 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -14,6 +14,7 @@ const char *printer_state_messages[] = { "Printing"}; Printer printer = {0}; +PrinterMinimal *printer_minimal; int klipper_request_consecutive_fail_count = 0; char filename_buff[512] = {0}; SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore; @@ -49,8 +50,7 @@ void send_gcode(bool wait, const char *gcode) SETUP_HTTP_CLIENT_FULL("/printer/gcode/script?script=" + urlEncode(gcode), false, wait ? 5000 : 750); try { - int result = client.GET(); - Serial.printf("Send gcode result: %d\n", result); + client.GET(); } catch (...) { @@ -111,6 +111,7 @@ int last_slicer_time_query = -15000; void fetch_printer_data() { freeze_request_thread(); + PRINTER_CONFIG *config = get_current_printer_config(); SETUP_HTTP_CLIENT("/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks&fan") int httpCode = client.GET(); @@ -247,15 +248,15 @@ void fetch_printer_data() remaining_time_s_slicer = printer.slicer_estimated_print_time_s - printer.elapsed_time_s; } - if (remaining_time_s_slicer <= 0 || global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_PERCENTAGE) + if (remaining_time_s_slicer <= 0 || config->remaining_time_calc_mode == REMAINING_TIME_CALC_PERCENTAGE) { printer.remaining_time_s = remaining_time_s_percentage; } - else if (global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_INTERPOLATED) + else if (config->remaining_time_calc_mode == REMAINING_TIME_CALC_INTERPOLATED) { printer.remaining_time_s = remaining_time_s_percentage * printer.print_progress + remaining_time_s_slicer * (1 - printer.print_progress); } - else if (global_config.remaining_time_calc_mode == REMAINING_TIME_CALC_SLICER) + else if (config->remaining_time_calc_mode == REMAINING_TIME_CALC_SLICER) { printer.remaining_time_s = remaining_time_s_slicer; } @@ -297,6 +298,94 @@ void fetch_printer_data() } } +void fetch_printer_data_minimal() +{ + PrinterMinimal data[PRINTER_CONFIG_COUNT] = {0}; + + for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){ + PRINTER_CONFIG *config = &global_config.printer_config[i]; + + if (!config->ip_configured) + { + data[i].online = false; + continue; + } + + delay(10); + HTTPClient client; + configure_http_client(client, "http://" + String(config->klipper_host) + ":" + String(config->klipper_port) + "/printer/objects/query?webhooks&print_stats&virtual_sdcard", true, 1000); + freeze_request_thread(); + + int httpCode = client.GET(); + delay(10); + if (httpCode == 200) + { + data[i].online = true; + JsonDocument doc; + deserializeJson(doc, client.getStream()); + auto status = doc["result"]["status"]; + + unfreeze_request_thread(); + + if (status.containsKey("webhooks")) + { + const char *state = status["webhooks"]["state"]; + + if (strcmp(state, "ready") == 0 && data[i].state == PRINTER_STATE_ERROR) + { + data[i].state = PRINTER_STATE_IDLE; + } + else if (strcmp(state, "shutdown") == 0 && data[i].state != PRINTER_STATE_ERROR) + { + data[i].state = PRINTER_STATE_ERROR; + } + } + + if (printer_minimal->state != PRINTER_STATE_ERROR) + { + if (status.containsKey("virtual_sdcard")) + { + data[i].print_progress = status["virtual_sdcard"]["progress"]; + } + + if (status.containsKey("print_stats")) + { + const char *state = status["print_stats"]["state"]; + + if (state == nullptr) + { + data[i].state = PRINTER_STATE_ERROR; + } + else if (strcmp(state, "printing") == 0) + { + data[i].state = PRINTER_STATE_PRINTING; + } + else if (strcmp(state, "paused") == 0) + { + data[i].state = PRINTER_STATE_PAUSED; + } + else if (strcmp(state, "complete") == 0 || strcmp(state, "cancelled") == 0 || strcmp(state, "standby") == 0) + { + data[i].state = PRINTER_STATE_IDLE; + } + } + } + + Serial.printf("Record: %d %f %d\n", data[i].online, data[i].print_progress, data[i].state); + } + else + { + printer_minimal->online = false; + unfreeze_request_thread(); + } + } + + freeze_render_thread(); + memcpy(printer_minimal, data, sizeof(PrinterMinimal) * PRINTER_CONFIG_COUNT); + lv_msg_send(DATA_PRINTER_MINIMAL, NULL); + unfreeze_render_thread(); +} + void data_loop() { // Causes other threads that are trying to lock the thread to actually lock it @@ -307,9 +396,16 @@ void data_loop() void data_loop_background(void * param){ esp_task_wdt_init(10, true); + int loop_iter = 20; while (true){ delay(data_update_interval); fetch_printer_data(); + if (global_config.multi_printer_mode) { + if (loop_iter++ > 20){ + fetch_printer_data_minimal(); + loop_iter = 0; + } + } } } @@ -317,9 +413,11 @@ TaskHandle_t background_loop; void data_setup() { + printer_minimal = (PrinterMinimal *)calloc(sizeof(PrinterMinimal), PRINTER_CONFIG_COUNT); semaphore_init(); printer.print_filename = filename_buff; fetch_printer_data(); + macros_query_setup(); freeze_render_thread(); xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 0, &background_loop, 0); diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index d1a4224..f7071cb 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -37,12 +37,20 @@ typedef struct _Printer { int slicer_estimated_print_time_s; } Printer; +typedef struct _PrinterMinimal { + bool online; + unsigned char state; + float print_progress; // 0 -> 1 +} PrinterMinimal; + extern Printer printer; +extern PrinterMinimal *printer_minimal; extern int klipper_request_consecutive_fail_count; #define DATA_PRINTER_STATE 1 #define DATA_PRINTER_DATA 2 #define DATA_PRINTER_TEMP_PRESET 3 +#define DATA_PRINTER_MINIMAL 4 void data_loop(); void data_setup(); diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index e8a3f70..e38edec 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -67,14 +67,14 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) } void set_invert_display(){ - tft.invertDisplay(global_config.invertColors); + tft.invertDisplay(get_current_printer_config()->invert_colors); } void screen_setup() { touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); touchscreen.begin(touchscreen_spi); - touchscreen.setRotation(global_config.rotateScreen ? 3 : 1); + touchscreen.setRotation(global_config.rotate_screen ? 3 : 1); lv_init(); @@ -83,7 +83,7 @@ void screen_setup() ledcSetup(0, 5000, 12); ledcAttachPin(21, 0); - tft.setRotation(global_config.rotateScreen ? 3 : 1); + tft.setRotation(global_config.rotate_screen ? 3 : 1); tft.fillScreen(TFT_BLACK); set_invert_display(); touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); diff --git a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp index fd39f00..22ea6d5 100644 --- a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp +++ b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp @@ -65,7 +65,7 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) { uint16_t magicX; // fix GT911 driver - orientation and handle rotation uint16_t magicY; - if (!global_config.rotateScreen) + if (!global_config.rotate_screen) { magicY = tp.points[i].x; magicX = TOUCH_HEIGHT - tp.points[i].y; @@ -84,7 +84,7 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) void set_invert_display() { - tft.invertDisplay(global_config.invertColors); + tft.invertDisplay(get_current_printer_config()->invert_colors); } void set_LED_color(uint8_t rgbVal[3]) @@ -114,7 +114,7 @@ void screen_setup() tft.init(); ledcSetup(0, 5000, 12); ledcAttachPin(TFT_BL, 0); - tft.setRotation(global_config.rotateScreen ? 3 : 1); + tft.setRotation(global_config.rotate_screen ? 3 : 1); tft.fillScreen(TFT_BLACK); set_invert_display(); LED_init(); diff --git a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp index 3ca7b3a..4f723cf 100644 --- a/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp +++ b/CYD-Klipper/src/core/device/ESP32-smartdisplay.cpp @@ -21,7 +21,7 @@ void set_invert_display() void lv_screen_intercept(_lv_disp_drv_t *disp_drv, const lv_area_t *area, lv_color_t *color_p) { - if (global_config.invertColors) { + if (get_current_printer_config()->invert_colors) { uint32_t w = (area->x2 - area->x1 + 1); uint32_t h = (area->y2 - area->y1 + 1); @@ -61,7 +61,7 @@ void screen_setup() } #endif // CYD_SCREEN_DISABLE_INVERT_COLORS - lv_disp_set_rotation(lv_disp_get_default(), (global_config.rotateScreen) ? ROTATION_INVERTED : ROTATION_NORMAL); + lv_disp_set_rotation(lv_disp_get_default(), (global_config.rotate_screen) ? ROTATION_INVERTED : ROTATION_NORMAL); } #endif // CYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY \ No newline at end of file diff --git a/CYD-Klipper/src/core/http_client.cpp b/CYD-Klipper/src/core/http_client.cpp index fb135bf..42edba3 100644 --- a/CYD-Klipper/src/core/http_client.cpp +++ b/CYD-Klipper/src/core/http_client.cpp @@ -3,12 +3,11 @@ String get_full_url(String url_part) { - return "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + url_part; + return "http://" + String(get_current_printer_config()->klipper_host) + ":" + String(get_current_printer_config()->klipper_port) + url_part; } void configure_http_client(HTTPClient &client, String url, bool stream, int timeout) { - Serial.println(url); if (stream){ client.useHTTP10(true); } @@ -20,7 +19,7 @@ void configure_http_client(HTTPClient &client, String url, bool stream, int time client.begin(url); - if (global_config.auth_configured) { - client.addHeader("X-Api-Key", global_config.klipper_auth); + if (get_current_printer_config()->auth_configured) { + client.addHeader("X-Api-Key", get_current_printer_config()->klipper_auth); } } \ No newline at end of file diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index 880af74..6f446ca 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -54,14 +54,14 @@ void lv_touch_intercept(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) 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); + data->point.x = round((data->point.x * global_config.screen_cal_x_mult) + global_config.screen_cal_x_offset); + data->point.y = round((data->point.y * global_config.screen_cal_y_mult) + global_config.screen_cal_y_offset); #endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION } } void lv_do_calibration(){ - if (global_config.screenCalibrated){ + if (global_config.screen_calibrated){ return; } @@ -149,22 +149,22 @@ void lv_do_calibration(){ int16_t yDist = CYD_SCREEN_HEIGHT_PX - 20; #endif - global_config.screenCalXMult = (float)xDist / (float)(x2 - x1); - global_config.screenCalXOffset = 10.0 - ((float)x1 * global_config.screenCalXMult); + global_config.screen_cal_x_mult = (float)xDist / (float)(x2 - x1); + global_config.screen_cal_x_offset = 10.0 - ((float)x1 * global_config.screen_cal_x_mult); - global_config.screenCalYMult = (float)yDist / (float)(y2 - y1); - global_config.screenCalYOffset = 10.0 - ((float)y1 * global_config.screenCalYMult); + global_config.screen_cal_y_mult = (float)yDist / (float)(y2 - y1); + global_config.screen_cal_y_offset = 10.0 - ((float)y1 * global_config.screen_cal_y_mult); - if (global_config.screenCalXMult == std::numeric_limits::infinity() || global_config.screenCalYMult == std::numeric_limits::infinity()){ + if (global_config.screen_cal_x_mult == std::numeric_limits::infinity() || global_config.screen_cal_y_mult == std::numeric_limits::infinity()){ Serial.println("Calibration failed, please try again"); ESP.restart(); } - global_config.screenCalibrated = true; - WriteGlobalConfig(); + global_config.screen_calibrated = true; + write_global_config(); lv_obj_clean(lv_scr_act()); - Serial.printf("Calibration done: X*%.2f + %.2f, Y*%.2f + %.2f\n", global_config.screenCalXMult, global_config.screenCalXOffset, global_config.screenCalYMult, global_config.screenCalYOffset); + Serial.printf("Calibration done: X*%.2f + %.2f, Y*%.2f + %.2f\n", global_config.screen_cal_x_mult, global_config.screen_cal_x_offset, global_config.screen_cal_y_mult, global_config.screen_cal_y_offset); } void set_screen_brightness() @@ -207,7 +207,7 @@ void screen_timer_sleep(lv_timer_t *timer) void screen_timer_setup() { - screen_sleep_timer = lv_timer_create(screen_timer_sleep, global_config.screenTimeout * 1000 * 60, NULL); + screen_sleep_timer = lv_timer_create(screen_timer_sleep, global_config.screen_timeout * 1000 * 60, NULL); lv_timer_pause(screen_sleep_timer); } @@ -228,26 +228,27 @@ void screen_timer_period(unsigned int period) void set_screen_timer_period() { - screen_timer_period(global_config.screenTimeout * 1000 * 60); + screen_timer_period(global_config.screen_timeout * 1000 * 60); } void set_color_scheme() { + PRINTER_CONFIG *config = get_current_printer_config(); lv_disp_t *dispp = lv_disp_get_default(); lv_color_t main_color = {0}; - COLOR_DEF color_def = color_defs[global_config.color_scheme]; + COLOR_DEF color_def = color_defs[config->color_scheme]; - if (color_defs[global_config.color_scheme].primary_color_light > 0){ + if (color_defs[config->color_scheme].primary_color_light > 0){ main_color = lv_palette_lighten(color_def.primary_color, color_def.primary_color_light); } - else if (color_defs[global_config.color_scheme].primary_color_light < 0) { + else if (color_defs[config->color_scheme].primary_color_light < 0) { main_color = lv_palette_darken(color_def.primary_color, color_def.primary_color_light * -1); } else { - main_color = lv_palette_main(color_defs[global_config.color_scheme].primary_color); + main_color = lv_palette_main(color_defs[config->color_scheme].primary_color); } - lv_theme_t *theme = lv_theme_default_init(dispp, main_color, lv_palette_main(color_def.secondary_color), !global_config.lightMode, &CYD_SCREEN_FONT); + lv_theme_t *theme = lv_theme_default_init(dispp, main_color, lv_palette_main(color_def.secondary_color), !config->light_mode, &CYD_SCREEN_FONT); lv_disp_set_theme(dispp, theme); } diff --git a/CYD-Klipper/src/main.cpp b/CYD-Klipper/src/main.cpp index e728bbe..776962f 100644 --- a/CYD-Klipper/src/main.cpp +++ b/CYD-Klipper/src/main.cpp @@ -13,7 +13,7 @@ void setup() { Serial.begin(115200); Serial.println("Hello World"); - LoadGlobalConfig(); + load_global_config(); screen_setup(); lv_setup(); Serial.println("Screen init done"); diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index fbea738..d741fd4 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -69,21 +69,21 @@ static void ta_event_cb(lv_event_t * e) { } else if (code == LV_EVENT_READY) { - strcpy(global_config.klipperHost, lv_textarea_get_text(hostEntry)); - global_config.klipperPort = atoi(lv_textarea_get_text(portEntry)); + strcpy(get_current_printer_config()->klipper_host, lv_textarea_get_text(hostEntry)); + get_current_printer_config()->klipper_port = atoi(lv_textarea_get_text(portEntry)); connection_status_t status = verify_ip(); if (status == CONNECT_OK) { - global_config.ipConfigured = true; - WriteGlobalConfig(); + get_current_printer_config()->ip_configured = true; + write_global_config(); connect_ok = true; } else if (status == CONNECT_AUTH_REQUIRED) { label = NULL; - global_config.ipConfigured = true; - WriteGlobalConfig(); + get_current_printer_config()->ip_configured = true; + write_global_config(); } else { @@ -109,7 +109,7 @@ static void reset_btn_event_handler(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); if(code == LV_EVENT_CLICKED) { - global_config.ipConfigured = false; + get_current_printer_config()->ip_configured = false; ip_init_inner(); } } @@ -176,9 +176,9 @@ static void keyboard_event_auth_entry(lv_event_t * e) { int len = strlen(txt); if (len > 0) { - global_config.auth_configured = true; - strcpy(global_config.klipper_auth, txt); - WriteGlobalConfig(); + get_current_printer_config()->auth_configured = true; + strcpy(get_current_printer_config()->klipper_auth, txt); + write_global_config(); auth_entry_done = true; } } @@ -190,7 +190,7 @@ static void keyboard_event_auth_entry(lv_event_t * e) { void handle_auth_entry(){ auth_entry_done = false; - global_config.klipper_auth[32] = 0; + get_current_printer_config()->klipper_auth[32] = 0; lv_obj_clean(lv_scr_act()); lv_obj_t * root = lv_create_empty_panel(lv_scr_act()); @@ -212,8 +212,8 @@ void handle_auth_entry(){ lv_textarea_set_max_length(passEntry, 32); lv_textarea_set_one_line(passEntry, true); - if (global_config.auth_configured) - lv_textarea_set_text(passEntry, global_config.klipper_auth); + if (get_current_printer_config()->auth_configured) + lv_textarea_set_text(passEntry, get_current_printer_config()->klipper_auth); else lv_textarea_set_text(passEntry, ""); @@ -235,7 +235,7 @@ void handle_auth_entry(){ } void ip_init_inner(){ - if (global_config.ipConfigured) { + if (get_current_printer_config()->ip_configured) { redraw_connect_screen(); return; } @@ -298,7 +298,7 @@ void ip_init(){ lv_timer_handler(); lv_task_handler(); - if (!connect_ok && global_config.ipConfigured && (millis() - last_data_update_ip) > data_update_interval_ip){ + if (!connect_ok && get_current_printer_config()->ip_configured && (millis() - last_data_update_ip) > data_update_interval_ip){ connection_status_t status = verify_ip(); connect_ok = status == CONNECT_OK; diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index a3194ee..8191d5c 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -93,7 +93,7 @@ void error_ui(){ } void check_if_screen_needs_to_be_disabled(){ - if (global_config.onDuringPrint && printer.state == PRINTER_STATE_PRINTING){ + if (global_config.on_during_print && printer.state == PRINTER_STATE_PRINTING){ screen_timer_wake(); screen_timer_stop(); } diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index 3a489ae..cf6a29f 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -4,6 +4,7 @@ #include "nav_buttons.h" #include "ui_utils.h" #include +#include "../conf/global_config.h" static lv_style_t nav_button_style; @@ -76,6 +77,10 @@ static void btn_click_macros(lv_event_t * e){ nav_buttons_setup(4); } +static void btn_click_printer(lv_event_t * e){ + nav_buttons_setup(6); +} + void create_button(const char* icon, const char* name, lv_event_cb_t button_click, lv_event_cb_t label_update, lv_obj_t * root){ lv_obj_t* btn = lv_btn_create(root); lv_obj_set_flex_grow(btn, 1); @@ -131,6 +136,11 @@ void nav_buttons_setup(unsigned char active_panel){ // Macros create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel); + if (global_config.multi_printer_mode) + { + create_button(LV_SYMBOL_HOME, "Printer", btn_click_printer, NULL, root_panel); + } + lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0); @@ -154,6 +164,9 @@ void nav_buttons_setup(unsigned char active_panel){ case 5: stats_panel_init(panel); break; + case 6: + printer_panel_init(panel); + break; } lv_msg_send(DATA_PRINTER_DATA, &printer); diff --git a/CYD-Klipper/src/ui/ota_setup.cpp b/CYD-Klipper/src/ui/ota_setup.cpp index 9d69d5b..40f9398 100644 --- a/CYD-Klipper/src/ui/ota_setup.cpp +++ b/CYD-Klipper/src/ui/ota_setup.cpp @@ -85,7 +85,7 @@ void ota_init() Serial.printf("OTA Update Result: %d\n", result); update_available = result == ESP32OTAPull::UPDATE_AVAILABLE; - if (global_config.autoOtaUpdate && update_available) + if (global_config.auto_ota_update && update_available) { ota_do_update(true); } diff --git a/CYD-Klipper/src/ui/panels/panel.h b/CYD-Klipper/src/ui/panels/panel.h index d69910a..a18095c 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -10,4 +10,5 @@ void move_panel_init(lv_obj_t* panel); void progress_panel_init(lv_obj_t* panel); void macros_panel_init(lv_obj_t* panel); void stats_panel_init(lv_obj_t* panel); +void printer_panel_init(lv_obj_t* panel); void macros_panel_add_power_devices_to_panel(lv_obj_t * panel, POWERQUERY query); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp new file mode 100644 index 0000000..c4ef1f8 --- /dev/null +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -0,0 +1,155 @@ +#include "panel.h" +#include "../../conf/global_config.h" +#include "../../core/data_setup.h" +#include "../ui_utils.h" + +const char * printer_status[] = { + "Error", + "Idle", + "Printing", + "Paused" +}; + +const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} }; + +static void update_printer_status_text(lv_event_t * e) +{ + lv_obj_t * label = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + PrinterMinimal * printer = &printer_minimal[index]; + + if (!printer->online){ + lv_label_set_text(label, "Offline"); + return; + } + + lv_label_set_text(label, printer_status[printer->state]); +} + +static void update_printer_percentage_bar(lv_event_t * e) +{ + lv_obj_t * percentage = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + PrinterMinimal * printer = &printer_minimal[index]; + + if (printer->online && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED)){ + lv_bar_set_value(percentage, printer->print_progress * 100, LV_ANIM_OFF); + } + else { + lv_bar_set_value(percentage, 0, LV_ANIM_OFF); + } +} + +static void update_printer_percentage_text(lv_event_t * e) +{ + lv_obj_t * label = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + PrinterMinimal * printer = &printer_minimal[index]; + + if (printer->online && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED)){ + lv_label_set_text_fmt(label, "%.2f%%", printer->print_progress * 100); + } + else { + lv_label_set_text(label, "-"); + } +} + +static void btn_printer_delete(lv_event_t * e) +{ + +} + +static void btn_printer_rename(lv_event_t * e) +{ + +} + +static void btn_printer_activate(lv_event_t * e) +{ + +} + +void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) +{ + int index = config - global_config.printer_config; + auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; + + lv_obj_t * data_row_name = lv_create_empty_panel(root); + lv_layout_flex_row(data_row_name, LV_FLEX_ALIGN_SPACE_BETWEEN); + lv_obj_set_size(data_row_name, width, LV_SIZE_CONTENT); + + lv_obj_t * label = lv_label_create(data_row_name); + lv_label_set_text(label, config->printer_name[0] == 0 ? config->klipper_host : config->printer_name); + + label = lv_label_create(data_row_name); + lv_obj_add_event_cb(label, update_printer_status_text, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + + lv_obj_t * progress_row = lv_create_empty_panel(root); + lv_layout_flex_row(progress_row); + lv_obj_set_size(progress_row, width, LV_SIZE_CONTENT); + + lv_obj_t * progress_bar = lv_bar_create(progress_row); + lv_obj_set_flex_grow(progress_bar, 1); + lv_obj_add_event_cb(progress_bar, update_printer_percentage_bar, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, progress_bar, config); + + label = lv_label_create(progress_row); + lv_obj_set_style_text_font(label, &CYD_SCREEN_FONT_SMALL, 0); + lv_obj_add_event_cb(label, update_printer_percentage_text, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + + lv_obj_t * button_row = lv_create_empty_panel(root); + lv_layout_flex_row(button_row); + lv_obj_set_size(button_row, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * btn = lv_btn_create(button_row); + lv_obj_set_flex_grow(btn, 1); + lv_obj_add_event_cb(btn, btn_printer_delete, LV_EVENT_CLICKED, config); + + label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_TRASH); + lv_obj_center(label); + + btn = lv_btn_create(button_row); + lv_obj_set_flex_grow(btn, 2); + lv_obj_add_event_cb(btn, btn_printer_rename, LV_EVENT_CLICKED, config); + + label = lv_label_create(btn); + lv_label_set_text(label, "Rename"); + lv_obj_center(label); + + btn = lv_btn_create(button_row); + lv_obj_set_flex_grow(btn, 2); + lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config); + + label = lv_label_create(btn); + lv_label_set_text(label, "Activate"); + lv_obj_center(label); + + lv_obj_t * line = lv_line_create(root); + lv_line_set_points(line, line_points, 2); + lv_obj_set_style_line_width(line, 1, 0); + lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); +} + +void printer_panel_init(lv_obj_t* panel) +{ + lv_obj_t * inner_panel = lv_create_empty_panel(panel); + lv_obj_align(inner_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + lv_obj_set_size(inner_panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); + lv_layout_flex_column(inner_panel); + lv_obj_set_scrollbar_mode(inner_panel, LV_SCROLLBAR_MODE_OFF); + + for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){ + PRINTER_CONFIG * config = &global_config.printer_config[i]; + if (config->ip_configured) { + create_printer_ui(&global_config.printer_config[i], inner_panel); + } + } + + lv_msg_send(DATA_PRINTER_MINIMAL, NULL); +} \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 165679a..94411b2 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -7,6 +7,7 @@ #include #include "../../core/lv_setup.h" #include "../ota_setup.h" +#include "../nav_buttons.h" #ifndef REPO_VERSION #define REPO_VERSION "Unknown" @@ -15,39 +16,44 @@ static void invert_color_switch(lv_event_t * e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - global_config.invertColors = checked; - WriteGlobalConfig(); + get_current_printer_config()->invert_colors = checked; + write_global_config(); set_invert_display(); } static void reset_calibration_click(lv_event_t * e){ - global_config.screenCalibrated = false; - WriteGlobalConfig(); + global_config.screen_calibrated = false; + write_global_config(); ESP.restart(); } static void reset_wifi_click(lv_event_t * e){ - global_config.wifiConfigured = false; - global_config.ipConfigured = false; - global_config.auth_configured = false; - WriteGlobalConfig(); + global_config.wifi_configured = false; + write_global_config(); + ESP.restart(); +} + +static void reset_ip_click(lv_event_t * e){ + get_current_printer_config()->ip_configured = false; + get_current_printer_config()->auth_configured = false; + write_global_config(); ESP.restart(); } static void light_mode_switch(lv_event_t * e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - global_config.lightMode = checked; - WriteGlobalConfig(); + get_current_printer_config()->light_mode = checked; + write_global_config(); set_color_scheme(); } static void theme_dropdown(lv_event_t * e){ lv_obj_t * dropdown = lv_event_get_target(e); auto selected = lv_dropdown_get_selected(dropdown); - global_config.color_scheme = selected; + get_current_printer_config()->color_scheme = selected; set_color_scheme(); - WriteGlobalConfig(); + write_global_config(); } const char* brightness_options = "100%\n75%\n50%\n25%"; @@ -58,7 +64,7 @@ static void brightness_dropdown(lv_event_t * e){ auto selected = lv_dropdown_get_selected(dropdown); global_config.brightness = brightness_options_values[selected]; set_screen_brightness(); - WriteGlobalConfig(); + write_global_config(); } const char* wake_timeout_options = "1m\n2m\n5m\n10m\n15m\n30m\n1h\n2h\n4h"; @@ -67,26 +73,26 @@ const char wake_timeout_options_values[] = { 1, 2, 5, 10, 15, 30, 60, 120, 240 static void wake_timeout_dropdown(lv_event_t * e){ lv_obj_t * dropdown = lv_event_get_target(e); auto selected = lv_dropdown_get_selected(dropdown); - global_config.screenTimeout = wake_timeout_options_values[selected]; + global_config.screen_timeout = wake_timeout_options_values[selected]; set_screen_timer_period(); - WriteGlobalConfig(); + write_global_config(); } static void rotate_screen_switch(lv_event_t* e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - global_config.rotateScreen = checked; - global_config.screenCalibrated = false; - WriteGlobalConfig(); + global_config.rotate_screen = checked; + global_config.screen_calibrated = false; + write_global_config(); ESP.restart(); } static void on_during_print_switch(lv_event_t* e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - global_config.onDuringPrint = checked; + global_config.on_during_print = checked; check_if_screen_needs_to_be_disabled(); - WriteGlobalConfig(); + write_global_config(); } static void btn_ota_do_update(lv_event_t * e){ @@ -96,16 +102,24 @@ static void btn_ota_do_update(lv_event_t * e){ static void auto_ota_update_switch(lv_event_t* e){ auto state = lv_obj_get_state(lv_event_get_target(e)); bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - global_config.autoOtaUpdate = checked; - WriteGlobalConfig(); + global_config.auto_ota_update = checked; + write_global_config(); +} + +static void multi_printer_switch(lv_event_t* e){ + auto state = lv_obj_get_state(lv_event_get_target(e)); + bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); + global_config.multi_printer_mode = checked; + write_global_config(); + nav_buttons_setup(3); } const char* estimated_time_options = "Percentage\nInterpolated\nSlicer"; static void estimated_time_dropdown(lv_event_t * e){ lv_obj_t * dropdown = lv_event_get_target(e); - global_config.remaining_time_calc_mode = lv_dropdown_get_selected(dropdown); - WriteGlobalConfig(); + get_current_printer_config()->remaining_time_calc_mode = lv_dropdown_get_selected(dropdown); + write_global_config(); } const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} }; @@ -152,6 +166,15 @@ void settings_panel_init(lv_obj_t* panel){ create_settings_widget("Configure WiFi", btn, panel); + btn = lv_btn_create(panel); + lv_obj_add_event_cb(btn, reset_ip_click, LV_EVENT_CLICKED, NULL); + + label = lv_label_create(btn); + lv_label_set_text(label, "Restart"); + lv_obj_center(label); + + create_settings_widget("Configure IP", btn, panel); + #ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, reset_calibration_click, LV_EVENT_CLICKED, NULL); @@ -168,7 +191,7 @@ void settings_panel_init(lv_obj_t* panel){ lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, invert_color_switch, LV_EVENT_VALUE_CHANGED, NULL); - if (global_config.invertColors) + if (get_current_printer_config()->invert_colors) lv_obj_add_state(toggle, LV_STATE_CHECKED); create_settings_widget("Invert Colors", toggle, panel); @@ -178,14 +201,14 @@ void settings_panel_init(lv_obj_t* panel){ lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, light_mode_switch, LV_EVENT_VALUE_CHANGED, NULL); - if (global_config.lightMode) + if (get_current_printer_config()->light_mode) lv_obj_add_state(toggle, LV_STATE_CHECKED); create_settings_widget("Light Mode", toggle, panel); dropdown = lv_dropdown_create(panel); lv_dropdown_set_options(dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple"); - lv_dropdown_set_selected(dropdown, global_config.color_scheme); + lv_dropdown_set_selected(dropdown, get_current_printer_config()->color_scheme); lv_obj_set_width(dropdown, DROPDOWN_WIDTH); lv_obj_add_event_cb(dropdown, theme_dropdown, LV_EVENT_VALUE_CHANGED, NULL); @@ -212,7 +235,7 @@ void settings_panel_init(lv_obj_t* panel){ lv_obj_add_event_cb(dropdown, wake_timeout_dropdown, LV_EVENT_VALUE_CHANGED, NULL); for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){ - if (wake_timeout_options_values[i] == global_config.screenTimeout){ + if (wake_timeout_options_values[i] == global_config.screen_timeout){ lv_dropdown_set_selected(dropdown, i); break; } @@ -226,14 +249,14 @@ void settings_panel_init(lv_obj_t* panel){ lv_obj_set_width(dropdown, DROPDOWN_WIDTH); lv_obj_add_event_cb(dropdown, estimated_time_dropdown, LV_EVENT_VALUE_CHANGED, NULL); - lv_dropdown_set_selected(dropdown, global_config.remaining_time_calc_mode); + lv_dropdown_set_selected(dropdown, get_current_printer_config()->remaining_time_calc_mode); create_settings_widget("Estimated Time", dropdown, panel); toggle = lv_switch_create(panel); lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, rotate_screen_switch, LV_EVENT_VALUE_CHANGED, NULL); - if (global_config.rotateScreen) + if (global_config.rotate_screen) lv_obj_add_state(toggle, LV_STATE_CHECKED); create_settings_widget("Rotate Screen", toggle, panel); @@ -243,17 +266,26 @@ void settings_panel_init(lv_obj_t* panel){ lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, on_during_print_switch, LV_EVENT_VALUE_CHANGED, NULL); - if (global_config.onDuringPrint) + if (global_config.on_during_print) lv_obj_add_state(toggle, LV_STATE_CHECKED); create_settings_widget("Screen On During Print", toggle, panel); #endif + toggle = lv_switch_create(panel); + lv_obj_set_width(toggle, TOGGLE_WIDTH); + lv_obj_add_event_cb(toggle, multi_printer_switch, LV_EVENT_VALUE_CHANGED, NULL); + + if (global_config.multi_printer_mode) + lv_obj_add_state(toggle, LV_STATE_CHECKED); + + create_settings_widget("Multi Printer Mode", toggle, panel); + toggle = lv_switch_create(panel); lv_obj_set_width(toggle, TOGGLE_WIDTH); lv_obj_add_event_cb(toggle, auto_ota_update_switch, LV_EVENT_VALUE_CHANGED, NULL); - if (global_config.autoOtaUpdate) + if (global_config.auto_ota_update) lv_obj_add_state(toggle, LV_STATE_CHECKED); create_settings_widget("Auto Update", toggle, panel); diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index 7a866f1..2716677 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -36,17 +36,17 @@ static void update_printer_data_bed_temp(lv_event_t * e){ static short get_temp_preset(int target){ switch (target){ case TARGET_HOTEND_CONFIG_1: - return global_config.hotend_presets[0]; + return get_current_printer_config()->hotend_presets[0]; case TARGET_HOTEND_CONFIG_2: - return global_config.hotend_presets[1]; + return get_current_printer_config()->hotend_presets[1]; case TARGET_HOTEND_CONFIG_3: - return global_config.hotend_presets[2]; + return get_current_printer_config()->hotend_presets[2]; case TARGET_BED_CONFIG_1: - return global_config.bed_presets[0]; + return get_current_printer_config()->bed_presets[0]; case TARGET_BED_CONFIG_2: - return global_config.bed_presets[1]; + return get_current_printer_config()->bed_presets[1]; case TARGET_BED_CONFIG_3: - return global_config.bed_presets[2]; + return get_current_printer_config()->bed_presets[2]; default: return -1; } @@ -62,7 +62,7 @@ static void update_temp_preset_label(lv_event_t * e){ } void UpdateConfig(){ - WriteGlobalConfig(); + write_global_config(); lv_msg_send(DATA_PRINTER_TEMP_PRESET, &printer); } @@ -91,27 +91,27 @@ static void keyboard_callback(lv_event_t * e){ send_gcode(true, gcode); break; case TARGET_HOTEND_CONFIG_1: - global_config.hotend_presets[0] = temp; + get_current_printer_config()->hotend_presets[0] = temp; UpdateConfig(); break; case TARGET_HOTEND_CONFIG_2: - global_config.hotend_presets[1] = temp; + get_current_printer_config()->hotend_presets[1] = temp; UpdateConfig(); break; case TARGET_HOTEND_CONFIG_3: - global_config.hotend_presets[2] = temp; + get_current_printer_config()->hotend_presets[2] = temp; UpdateConfig(); break; case TARGET_BED_CONFIG_1: - global_config.bed_presets[0] = temp; + get_current_printer_config()->bed_presets[0] = temp; UpdateConfig(); break; case TARGET_BED_CONFIG_2: - global_config.bed_presets[1] = temp; + get_current_printer_config()->bed_presets[1] = temp; UpdateConfig(); break; case TARGET_BED_CONFIG_3: - global_config.bed_presets[2] = temp; + get_current_printer_config()->bed_presets[2] = temp; UpdateConfig(); break; } diff --git a/CYD-Klipper/src/ui/wifi_setup.cpp b/CYD-Klipper/src/ui/wifi_setup.cpp index 6bb3556..fb2e366 100644 --- a/CYD-Klipper/src/ui/wifi_setup.cpp +++ b/CYD-Klipper/src/ui/wifi_setup.cpp @@ -10,7 +10,7 @@ static void reset_btn_event_handler(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); if(code == LV_EVENT_CLICKED) { - global_config.wifiConfigured = false; + global_config.wifi_configured = false; wifi_init_inner(); } } @@ -33,9 +33,9 @@ static void ta_event_cb(lv_event_t * e) { int len = strlen(txt); if (len > 0) { - global_config.wifiConfigured = true; - strcpy(global_config.wifiPassword, txt); - WriteGlobalConfig(); + global_config.wifi_configured = true; + strcpy(global_config.wifi_password, txt); + write_global_config(); wifi_init_inner(); } } @@ -79,7 +79,7 @@ static void wifi_btn_event_handler(lv_event_t * e){ if(code == LV_EVENT_CLICKED) { delay(100); char* ssid = (char*)e->user_data; - strcpy(global_config.wifiSSID, ssid); + strcpy(global_config.wifi_SSID, ssid); Serial.println(ssid); wifi_pass_entry(ssid); } @@ -89,8 +89,8 @@ void wifi_init_inner(){ WiFi.disconnect(); lv_obj_clean(lv_scr_act()); - if (global_config.wifiConfigured){ - WiFi.begin(global_config.wifiSSID, global_config.wifiPassword); + if (global_config.wifi_configured){ + WiFi.begin(global_config.wifi_SSID, global_config.wifi_password); lv_obj_t * label = lv_label_create(lv_scr_act()); lv_label_set_text(label, "Connecting to WiFi"); @@ -180,7 +180,7 @@ void wifi_init(){ WiFi.mode(WIFI_STA); wifi_init_inner(); - while (!global_config.wifiConfigured || WiFi.status() != WL_CONNECTED){ + while (!global_config.wifi_configured || WiFi.status() != WL_CONNECTED){ if (millis() - print_timer > print_freq){ print_timer = millis(); Serial.printf("WiFi Status: %s\n", errs[WiFi.status()]); From e9b58e0a6f75a58318a0cea13781efaa7643bf46 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 01:55:31 +0100 Subject: [PATCH 20/42] Implement printer panel fully --- .../boards/esp32-3248S035C-smartdisplay.json | 14 +- CYD-Klipper/src/conf/global_config.cpp | 3 + CYD-Klipper/src/conf/global_config.h | 1 + CYD-Klipper/src/core/data_setup.cpp | 2 +- CYD-Klipper/src/ui/panels/printer_panel.cpp | 146 +++++++++++++++++- 5 files changed, 152 insertions(+), 14 deletions(-) diff --git a/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json b/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json index 25e1f76..b873d3e 100644 --- a/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json @@ -9,6 +9,8 @@ "'-D ESP32_3248S035C'", "'-D LCD_WIDTH=320'", "'-D LCD_HEIGHT=480'", + "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", + "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", "'-D BCKL=27'", "'-D LCD_ST7796_SPI'", "'-D ST7796_SPI_HOST=SPI2_HOST'", @@ -18,10 +20,13 @@ "'-D ST7796_SPI_BUS_SCLK_IO_NUM=14'", "'-D ST7796_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", "'-D ST7796_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", + "'-D ST7796_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ST7796_SPI_BUS_FLAGS=0'", + "'-D ST7796_SPI_BUS_INTR_FLAGS=0'", "'-D ST7796_SPI_CONFIG_CS_GPIO_NUM=15'", "'-D ST7796_SPI_CONFIG_DC_GPIO_NUM=2'", "'-D ST7796_SPI_CONFIG_SPI_MODE=SPI_MODE0'", - "'-D ST7796_SPI_CONFIG_PCLK_HZ=80000000'", + "'-D ST7796_SPI_CONFIG_PCLK_HZ=24000000'", "'-D ST7796_SPI_CONFIG_TRANS_QUEUE_DEPTH=10'", "'-D ST7796_SPI_CONFIG_LCD_CMD_BITS=8'", "'-D ST7796_SPI_CONFIG_LCD_PARAM_BITS=8'", @@ -77,14 +82,13 @@ "'-D SPEAK=26'", "-DCYD_SCREEN_GAP_PX=10", - "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=40", - "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=40", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=45", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=45", "-DCYD_SCREEN_FONT=lv_font_montserrat_16", "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12", "-DCYD_SCREEN_SIDEBAR_SIZE_PX=50", "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1", - "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1", - "-DCYD_SCREEN_DISABLE_INVERT_COLORS=1" + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1" ], "f_cpu": "240000000L", "f_flash": "40000000L", diff --git a/CYD-Klipper/src/conf/global_config.cpp b/CYD-Klipper/src/conf/global_config.cpp index e717eee..cff6515 100644 --- a/CYD-Klipper/src/conf/global_config.cpp +++ b/CYD-Klipper/src/conf/global_config.cpp @@ -90,8 +90,11 @@ void set_printer_config_index(int index) new_config->bed_presets[i] = old_config->bed_presets[i]; } + write_global_config(); ESP.restart(); } + + write_global_config(); } void load_global_config() diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index 5a67a01..9b18e28 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -86,5 +86,6 @@ void load_global_config(); PRINTER_CONFIG* get_current_printer_config(); int get_printer_config_count(); void set_printer_config_index(int index); +int get_printer_config_free_index(); #endif // !_GLOBAL_CONFIG_INIT \ No newline at end of file diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index c09743e..e64a732 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -341,7 +341,7 @@ void fetch_printer_data_minimal() } } - if (printer_minimal->state != PRINTER_STATE_ERROR) + if (data[i].state != PRINTER_STATE_ERROR) { if (status.containsKey("virtual_sdcard")) { diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index c4ef1f8..6e09307 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -2,6 +2,9 @@ #include "../../conf/global_config.h" #include "../../core/data_setup.h" #include "../ui_utils.h" +#include "../../core/lv_setup.h" +#include +#include "../nav_buttons.h" const char * printer_status[] = { "Error", @@ -12,6 +15,16 @@ const char * printer_status[] = { const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} }; +static void update_printer_name_text(lv_event_t * e) +{ + lv_obj_t * label = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + PrinterMinimal * printer = &printer_minimal[index]; + + lv_label_set_text(label, config->printer_name[0] == 0 ? config->klipper_host : config->printer_name); +} + static void update_printer_status_text(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); @@ -49,27 +62,124 @@ static void update_printer_percentage_text(lv_event_t * e) int index = config - global_config.printer_config; PrinterMinimal * printer = &printer_minimal[index]; - if (printer->online && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED)){ - lv_label_set_text_fmt(label, "%.2f%%", printer->print_progress * 100); + if (printer->online && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED)) + { + char percentage_buffer[12]; + sprintf(percentage_buffer, "%.2f%%", printer->print_progress * 100); + lv_label_set_text(label, percentage_buffer); } - else { - lv_label_set_text(label, "-"); + else + { + lv_label_set_text(label, "-%"); + } +} + +static void btn_disable_if_controlled(lv_event_t * e) +{ + lv_obj_t * btn = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + + if (config == get_current_printer_config()) + { + lv_obj_add_state(btn, LV_STATE_DISABLED); + } + else + { + lv_obj_clear_state(btn, LV_STATE_DISABLED); + } +} + +static void btn_disable_if_controlled_or_offline(lv_event_t * e) +{ + lv_obj_t * btn = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + PrinterMinimal * printer = &printer_minimal[index]; + + if (config == get_current_printer_config() || !printer->online) + { + lv_obj_add_state(btn, LV_STATE_DISABLED); + } + else + { + lv_obj_clear_state(btn, LV_STATE_DISABLED); + } +} + +PRINTER_CONFIG * keyboard_config = NULL; + +static void keyboard_callback(lv_event_t * e){ + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * ta = lv_event_get_target(e); + lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e); + + if (code == LV_EVENT_READY) { + const char * text = lv_textarea_get_text(ta); + strcpy(keyboard_config->printer_name, text); + write_global_config(); + lv_msg_send(DATA_PRINTER_MINIMAL, NULL); + } + + if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY) { + lv_keyboard_set_textarea(kb, NULL); + lv_obj_del(lv_obj_get_parent(kb)); } } static void btn_printer_delete(lv_event_t * e) { + lv_obj_t * btn = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + if (config == get_current_printer_config()) + { + return; + } + + config->ip_configured = false; + write_global_config(); + + nav_buttons_setup(6); } +// TODO: Extract this from temp/print panel and combine static void btn_printer_rename(lv_event_t * e) { + keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + lv_obj_t * parent = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0); + lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN); + + lv_obj_t * empty_panel = lv_create_empty_panel(parent); + lv_obj_set_flex_grow(empty_panel, 1); + + lv_obj_t * ta = lv_textarea_create(parent); + lv_obj_t * keyboard = lv_keyboard_create(parent); + + lv_obj_set_width(ta, CYD_SCREEN_WIDTH_PX * 0.75); + lv_textarea_set_max_length(ta, 16); + lv_textarea_set_one_line(ta, true); + lv_textarea_set_text(ta, keyboard_config->printer_name); + lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_ALL, keyboard); + lv_keyboard_set_textarea(keyboard, ta); } static void btn_printer_activate(lv_event_t * e) { + lv_obj_t * label = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + set_printer_config_index(index); + set_color_scheme(); + lv_msg_send(DATA_PRINTER_MINIMAL, NULL); +} + +static void btn_printer_add(lv_event_t * e) +{ + set_printer_config_index(get_printer_config_free_index()); } void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) @@ -82,7 +192,8 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_set_size(data_row_name, width, LV_SIZE_CONTENT); lv_obj_t * label = lv_label_create(data_row_name); - lv_label_set_text(label, config->printer_name[0] == 0 ? config->klipper_host : config->printer_name); + lv_obj_add_event_cb(label, update_printer_name_text, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); label = lv_label_create(data_row_name); lv_obj_add_event_cb(label, update_printer_status_text, LV_EVENT_MSG_RECEIVED, config); @@ -109,6 +220,8 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_t * btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 1); lv_obj_add_event_cb(btn, btn_printer_delete, LV_EVENT_CLICKED, config); + lv_obj_add_event_cb(btn, btn_disable_if_controlled, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_TRASH); @@ -125,9 +238,11 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 2); lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config); + lv_obj_add_event_cb(btn, btn_disable_if_controlled_or_offline, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); label = lv_label_create(btn); - lv_label_set_text(label, "Activate"); + lv_label_set_text(label, "Control"); lv_obj_center(label); lv_obj_t * line = lv_line_create(root); @@ -139,11 +254,13 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) void printer_panel_init(lv_obj_t* panel) { lv_obj_t * inner_panel = lv_create_empty_panel(panel); - lv_obj_align(inner_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); - lv_obj_set_size(inner_panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); + lv_obj_align(inner_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, 0); + lv_obj_set_size(inner_panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_PANEL_HEIGHT_PX); lv_layout_flex_column(inner_panel); lv_obj_set_scrollbar_mode(inner_panel, LV_SCROLLBAR_MODE_OFF); + lv_obj_set_size(lv_create_empty_panel(inner_panel), 0, 0); + for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){ PRINTER_CONFIG * config = &global_config.printer_config[i]; if (config->ip_configured) { @@ -151,5 +268,18 @@ void printer_panel_init(lv_obj_t* panel) } } + // Add Printer Button + if (get_printer_config_free_index() != -1){ + lv_obj_t * btn = lv_btn_create(inner_panel); + lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, btn_printer_add, LV_EVENT_CLICKED, NULL); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, "Add Printer"); + lv_obj_center(label); + } + + lv_obj_set_size(lv_create_empty_panel(inner_panel), 0, 0); + lv_msg_send(DATA_PRINTER_MINIMAL, NULL); } \ No newline at end of file From 67b5ce1948c0cd76bd32af779cd0587acb0c0774 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 01:56:35 +0100 Subject: [PATCH 21/42] Set max printer name limit to 24 chars --- CYD-Klipper/src/conf/global_config.h | 2 +- CYD-Klipper/src/ui/panels/printer_panel.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index 9b18e28..c7e2c1b 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -27,7 +27,7 @@ typedef struct _PRINTER_CONFIG { }; }; - char printer_name[17]; + char printer_name[25]; char klipper_host[65]; char klipper_auth[33]; unsigned short klipper_port; diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index 6e09307..fada49e 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -159,7 +159,7 @@ static void btn_printer_rename(lv_event_t * e) lv_obj_t * keyboard = lv_keyboard_create(parent); lv_obj_set_width(ta, CYD_SCREEN_WIDTH_PX * 0.75); - lv_textarea_set_max_length(ta, 16); + lv_textarea_set_max_length(ta, 24); lv_textarea_set_one_line(ta, true); lv_textarea_set_text(ta, keyboard_config->printer_name); lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_ALL, keyboard); From f98c2eff78f1b1e53ff5d7432f29de13026f4bf6 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 19:22:24 +0100 Subject: [PATCH 22/42] Small refactor --- CYD-Klipper/src/core/macros_query.cpp | 9 +- CYD-Klipper/src/core/macros_query.h | 1 + CYD-Klipper/src/ui/panels/macros_panel.cpp | 44 +---- CYD-Klipper/src/ui/panels/printer_panel.cpp | 38 +---- CYD-Klipper/src/ui/panels/settings_panel.cpp | 165 +++---------------- CYD-Klipper/src/ui/panels/temp_panel.cpp | 114 +++++-------- CYD-Klipper/src/ui/ui_utils.cpp | 107 ++++++++++++ CYD-Klipper/src/ui/ui_utils.h | 7 +- 8 files changed, 196 insertions(+), 289 deletions(-) diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index fcbf900..f194c1e 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -13,7 +13,7 @@ static char* power_devices[16] = {0}; static bool power_device_states[16] = {0}; static int power_devices_count = 0; -static void _macros_query_internal(){ +void _macros_query_internal(){ SETUP_HTTP_CLIENT("/printer/gcode/help") int httpCode = client.GET(); @@ -52,13 +52,16 @@ void _power_devices_query_internal(){ SETUP_HTTP_CLIENT("/machine/device_power/devices") int httpCode = client.GET(); + + if (httpCode == 200 || httpCode == 404 || httpCode == 500){ + power_devices_clear(); + } + if (httpCode == 200){ JsonDocument doc; deserializeJson(doc, client.getStream()); auto result = doc["result"]["devices"].as(); - power_devices_clear(); - for (auto i : result){ const char * device_name = i["device"]; const char * device_state = i["status"]; diff --git a/CYD-Klipper/src/core/macros_query.h b/CYD-Klipper/src/core/macros_query.h index 1000dd3..40788b4 100644 --- a/CYD-Klipper/src/core/macros_query.h +++ b/CYD-Klipper/src/core/macros_query.h @@ -16,4 +16,5 @@ POWERQUERY power_devices_query(); void macros_query_setup(); bool set_power_state(const char* device_name, bool state); void _power_devices_query_internal(); +void _macros_query_internal(); void power_devices_clear(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 0481f6c..0928252 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -23,28 +23,7 @@ static void btn_goto_settings(lv_event_t * e){ void macros_panel_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query){ for (int i = 0; i < query.count; i++){ const char* macro = query.macros[i]; - - lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_layout_flex_row(panel, LV_FLEX_ALIGN_END); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, macro); - lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_obj_set_flex_grow(label, 1); - - lv_obj_t * btn = lv_btn_create(panel); - lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - - label = lv_label_create(btn); - lv_label_set_text(label, "Run"); - lv_obj_center(label); - - lv_obj_t * line = lv_line_create(root_panel); - lv_line_set_points(line, line_points, 2); - lv_obj_set_style_line_width(line, 1, 0); - lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); + lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro); } } @@ -61,26 +40,7 @@ void macros_panel_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY q for (int i = 0; i < query.count; i++){ const char* power_device_name = query.power_devices[i]; const bool power_device_state = query.power_states[i]; - - lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_layout_flex_row(panel, LV_FLEX_ALIGN_END); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, power_device_name); - lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_obj_set_flex_grow(label, 1); - - lv_obj_t * toggle = lv_switch_create(panel); - lv_obj_add_event_cb(toggle, power_device_toggle, LV_EVENT_VALUE_CHANGED, (void*)power_device_name); - lv_obj_set_size(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - if (power_device_state) - lv_obj_add_state(toggle, LV_STATE_CHECKED); - - lv_obj_t * line = lv_line_create(root_panel); - lv_line_set_points(line, line_points, 2); - lv_obj_set_style_line_width(line, 1, 0); - lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); + lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name); } } diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index fada49e..ca7c63c 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -5,6 +5,7 @@ #include "../../core/lv_setup.h" #include #include "../nav_buttons.h" +#include "../../core/macros_query.h" const char * printer_status[] = { "Error", @@ -109,21 +110,13 @@ static void btn_disable_if_controlled_or_offline(lv_event_t * e) PRINTER_CONFIG * keyboard_config = NULL; static void keyboard_callback(lv_event_t * e){ - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * ta = lv_event_get_target(e); lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_READY) { - const char * text = lv_textarea_get_text(ta); - strcpy(keyboard_config->printer_name, text); - write_global_config(); - lv_msg_send(DATA_PRINTER_MINIMAL, NULL); - } - - if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY) { - lv_keyboard_set_textarea(kb, NULL); - lv_obj_del(lv_obj_get_parent(kb)); - } + const char * text = lv_textarea_get_text(ta); + strcpy(keyboard_config->printer_name, text); + write_global_config(); + lv_msg_send(DATA_PRINTER_MINIMAL, NULL); } static void btn_printer_delete(lv_event_t * e) @@ -146,24 +139,7 @@ static void btn_printer_delete(lv_event_t * e) static void btn_printer_rename(lv_event_t * e) { keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - - lv_obj_t * parent = lv_create_empty_panel(lv_scr_act()); - lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0); - lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); - lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN); - - lv_obj_t * empty_panel = lv_create_empty_panel(parent); - lv_obj_set_flex_grow(empty_panel, 1); - - lv_obj_t * ta = lv_textarea_create(parent); - lv_obj_t * keyboard = lv_keyboard_create(parent); - - lv_obj_set_width(ta, CYD_SCREEN_WIDTH_PX * 0.75); - lv_textarea_set_max_length(ta, 24); - lv_textarea_set_one_line(ta, true); - lv_textarea_set_text(ta, keyboard_config->printer_name); - lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_ALL, keyboard); - lv_keyboard_set_textarea(keyboard, ta); + lv_create_keyboard_text_entry(keyboard_callback, LV_KEYBOARD_MODE_TEXT_LOWER, CYD_SCREEN_WIDTH_PX * 0.75, 24, keyboard_config->printer_name, false); } static void btn_printer_activate(lv_event_t * e) @@ -174,6 +150,8 @@ static void btn_printer_activate(lv_event_t * e) set_printer_config_index(index); set_color_scheme(); + _macros_query_internal(); + _power_devices_query_internal(); lv_msg_send(DATA_PRINTER_MINIMAL, NULL); } diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 94411b2..8db8ce3 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -57,7 +57,7 @@ static void theme_dropdown(lv_event_t * e){ } const char* brightness_options = "100%\n75%\n50%\n25%"; -const char brightness_options_values[] = { 255, 192, 128, 64 }; +const unsigned char brightness_options_values[] = { 255, 192, 128, 64 }; static void brightness_dropdown(lv_event_t * e){ lv_obj_t * dropdown = lv_event_get_target(e); @@ -122,193 +122,76 @@ static void estimated_time_dropdown(lv_event_t * e){ write_global_config(); } -const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} }; - -void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true){ - lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, label_text); - lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0); - - lv_obj_set_parent(object, panel); - lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0); - - if (set_height) - lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - - lv_obj_t * line = lv_line_create(root_panel); - lv_line_set_points(line, line_points, 2); - lv_obj_set_style_line_width(line, 1, 0); - lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); -} - -#define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75 -#define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2 - void settings_panel_init(lv_obj_t* panel){ - lv_obj_t * toggle = NULL; - lv_obj_t * btn = NULL; - lv_obj_t * label = NULL; - lv_obj_t * dropdown = NULL; - 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); - - label = lv_label_create(btn); - lv_label_set_text(label, "Restart"); - lv_obj_center(label); - - create_settings_widget("Configure WiFi", btn, panel); - - btn = lv_btn_create(panel); - lv_obj_add_event_cb(btn, reset_ip_click, LV_EVENT_CLICKED, NULL); - - label = lv_label_create(btn); - lv_label_set_text(label, "Restart"); - lv_obj_center(label); - - create_settings_widget("Configure IP", btn, panel); + lv_create_custom_menu_button("Configure WiFi", panel, reset_wifi_click, "Restart"); + lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart"); #ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION - btn = lv_btn_create(panel); - lv_obj_add_event_cb(btn, reset_calibration_click, LV_EVENT_CLICKED, NULL); - - label = lv_label_create(btn); - lv_label_set_text(label, "Restart"); - lv_obj_center(label); - - create_settings_widget("Calibrate Touch", btn, panel); + lv_create_custom_menu_button("Calibrate Touch", panel, reset_calibration_click, "Restart"); #endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION #ifndef CYD_SCREEN_DISABLE_INVERT_COLORS - toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, TOGGLE_WIDTH); - lv_obj_add_event_cb(toggle, invert_color_switch, LV_EVENT_VALUE_CHANGED, NULL); - - if (get_current_printer_config()->invert_colors) - lv_obj_add_state(toggle, LV_STATE_CHECKED); - - create_settings_widget("Invert Colors", toggle, panel); + lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors); #endif // CYD_SCREEN_DISABLE_INVERT_COLORS - toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, TOGGLE_WIDTH); - lv_obj_add_event_cb(toggle, light_mode_switch, LV_EVENT_VALUE_CHANGED, NULL); - - if (get_current_printer_config()->light_mode) - lv_obj_add_state(toggle, LV_STATE_CHECKED); - - create_settings_widget("Light Mode", toggle, panel); - - dropdown = lv_dropdown_create(panel); - lv_dropdown_set_options(dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple"); - lv_dropdown_set_selected(dropdown, get_current_printer_config()->color_scheme); - lv_obj_set_width(dropdown, DROPDOWN_WIDTH); - lv_obj_add_event_cb(dropdown, theme_dropdown, LV_EVENT_VALUE_CHANGED, NULL); - - create_settings_widget("Theme", dropdown, panel); - - dropdown = lv_dropdown_create(panel); - lv_dropdown_set_options(dropdown, brightness_options); - lv_obj_set_width(dropdown, DROPDOWN_WIDTH); - lv_obj_add_event_cb(dropdown, brightness_dropdown, LV_EVENT_VALUE_CHANGED, NULL); + lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode); + lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme); + int brightness_settings_index = 0; for (int i = 0; i < SIZEOF(brightness_options_values); i++){ if (brightness_options_values[i] == global_config.brightness){ - lv_dropdown_set_selected(dropdown, i); + brightness_settings_index = i; break; } } - create_settings_widget("Brightness", dropdown, panel); + lv_create_custom_menu_dropdown("Brightness", panel, brightness_dropdown, brightness_options, brightness_settings_index); + #ifndef CYD_SCREEN_DISABLE_TIMEOUT - dropdown = lv_dropdown_create(panel); - lv_dropdown_set_options(dropdown, wake_timeout_options); - lv_obj_set_width(dropdown, DROPDOWN_WIDTH); - lv_obj_add_event_cb(dropdown, wake_timeout_dropdown, LV_EVENT_VALUE_CHANGED, NULL); - + int wake_timeout_settings_index = 0; for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){ if (wake_timeout_options_values[i] == global_config.screen_timeout){ - lv_dropdown_set_selected(dropdown, i); + wake_timeout_settings_index = i; break; } } - create_settings_widget("Wake Timeout", dropdown, panel); + lv_create_custom_menu_dropdown("Wake Timeout", panel, wake_timeout_dropdown, wake_timeout_options, wake_timeout_settings_index); #endif - dropdown = lv_dropdown_create(panel); - lv_dropdown_set_options(dropdown, estimated_time_options); - lv_obj_set_width(dropdown, DROPDOWN_WIDTH); - lv_obj_add_event_cb(dropdown, estimated_time_dropdown, LV_EVENT_VALUE_CHANGED, NULL); - - lv_dropdown_set_selected(dropdown, get_current_printer_config()->remaining_time_calc_mode); - create_settings_widget("Estimated Time", dropdown, panel); - - toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, TOGGLE_WIDTH); - lv_obj_add_event_cb(toggle, rotate_screen_switch, LV_EVENT_VALUE_CHANGED, NULL); - - if (global_config.rotate_screen) - lv_obj_add_state(toggle, LV_STATE_CHECKED); - - create_settings_widget("Rotate Screen", toggle, panel); + lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode); + lv_create_custom_menu_switch("Rotate Screen", panel, rotate_screen_switch, global_config.rotate_screen); #ifndef CYD_SCREEN_DISABLE_TIMEOUT - toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, TOGGLE_WIDTH); - lv_obj_add_event_cb(toggle, on_during_print_switch, LV_EVENT_VALUE_CHANGED, NULL); - - if (global_config.on_during_print) - lv_obj_add_state(toggle, LV_STATE_CHECKED); - - create_settings_widget("Screen On During Print", toggle, panel); + lv_create_custom_menu_switch("Screen On During Print", panel, on_during_print_switch, global_config.on_during_print); #endif - toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, TOGGLE_WIDTH); - lv_obj_add_event_cb(toggle, multi_printer_switch, LV_EVENT_VALUE_CHANGED, NULL); + lv_create_custom_menu_switch("Multi Printer Mode", panel, multi_printer_switch, global_config.multi_printer_mode); + lv_create_custom_menu_switch("Auto Update", panel, auto_ota_update_switch, global_config.auto_ota_update); - if (global_config.multi_printer_mode) - lv_obj_add_state(toggle, LV_STATE_CHECKED); - - create_settings_widget("Multi Printer Mode", toggle, panel); - toggle = lv_switch_create(panel); - lv_obj_set_width(toggle, TOGGLE_WIDTH); - lv_obj_add_event_cb(toggle, auto_ota_update_switch, LV_EVENT_VALUE_CHANGED, NULL); - - if (global_config.auto_ota_update) - lv_obj_add_state(toggle, LV_STATE_CHECKED); - - create_settings_widget("Auto Update", toggle, panel); - - label = lv_label_create(panel); + lv_obj_t *label = lv_label_create(panel); lv_label_set_text(label, REPO_VERSION " "); - - create_settings_widget("Version", label, panel, false); + lv_create_custom_menu_entry("Version", label, panel, false); if (ota_has_update()){ - btn = lv_btn_create(panel); + lv_obj_t *btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, btn_ota_do_update, LV_EVENT_CLICKED, NULL); label = lv_label_create(btn); lv_label_set_text_fmt(label, "Update to %s", ota_new_version_name().c_str()); lv_obj_center(label); - create_settings_widget("Device", btn, panel); + lv_create_custom_menu_entry("Device", btn, panel); } else { label = lv_label_create(panel); lv_label_set_text(label, ARDUINO_BOARD " "); - - create_settings_widget("Device", label, panel, false); + lv_create_custom_menu_entry("Device", label, panel, false); } } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index 2716677..d9e7890 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -67,92 +67,62 @@ void UpdateConfig(){ } static void keyboard_callback(lv_event_t * e){ - lv_event_code_t code = lv_event_get_code(e); lv_obj_t * ta = lv_event_get_target(e); lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e); - if (code == LV_EVENT_READY) { - const char * text = lv_textarea_get_text(ta); + const char * text = lv_textarea_get_text(ta); - int temp = atoi(text); - if (temp < 0 || temp > 500){ - return; - } + int temp = atoi(text); + if (temp < 0 || temp > 500){ + return; + } - char gcode[64]; + char gcode[64]; - switch (keyboard_target){ - case TARGET_HOTEND: - sprintf(gcode, "M104 S%d", temp); - send_gcode(true, gcode); - break; - case TARGET_BED: - sprintf(gcode, "M140 S%d", temp); - send_gcode(true, gcode); - break; - case TARGET_HOTEND_CONFIG_1: - get_current_printer_config()->hotend_presets[0] = temp; - UpdateConfig(); - break; - case TARGET_HOTEND_CONFIG_2: - get_current_printer_config()->hotend_presets[1] = temp; - UpdateConfig(); - break; - case TARGET_HOTEND_CONFIG_3: - get_current_printer_config()->hotend_presets[2] = temp; - UpdateConfig(); - break; - case TARGET_BED_CONFIG_1: - get_current_printer_config()->bed_presets[0] = temp; - UpdateConfig(); - break; - case TARGET_BED_CONFIG_2: - get_current_printer_config()->bed_presets[1] = temp; - UpdateConfig(); - break; - case TARGET_BED_CONFIG_3: - get_current_printer_config()->bed_presets[2] = temp; - UpdateConfig(); - break; - } + switch (keyboard_target){ + case TARGET_HOTEND: + sprintf(gcode, "M104 S%d", temp); + send_gcode(true, gcode); + break; + case TARGET_BED: + sprintf(gcode, "M140 S%d", temp); + send_gcode(true, gcode); + break; + case TARGET_HOTEND_CONFIG_1: + get_current_printer_config()->hotend_presets[0] = temp; + UpdateConfig(); + break; + case TARGET_HOTEND_CONFIG_2: + get_current_printer_config()->hotend_presets[1] = temp; + UpdateConfig(); + break; + case TARGET_HOTEND_CONFIG_3: + get_current_printer_config()->hotend_presets[2] = temp; + UpdateConfig(); + break; + case TARGET_BED_CONFIG_1: + get_current_printer_config()->bed_presets[0] = temp; + UpdateConfig(); + break; + case TARGET_BED_CONFIG_2: + get_current_printer_config()->bed_presets[1] = temp; + UpdateConfig(); + break; + case TARGET_BED_CONFIG_3: + get_current_printer_config()->bed_presets[2] = temp; + UpdateConfig(); + break; } - - if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY) { - lv_keyboard_set_textarea(kb, NULL); - lv_obj_del(lv_obj_get_parent(kb)); - } -} - -static void show_keyboard(lv_event_t * e){ - lv_obj_t * parent = lv_create_empty_panel(root_panel); - lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0); - lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); - lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN); - - lv_obj_t * empty_panel = lv_create_empty_panel(parent); - lv_obj_set_flex_grow(empty_panel, 1); - - lv_obj_t * ta = lv_textarea_create(parent); - lv_obj_t * keyboard = lv_keyboard_create(parent); - - lv_obj_set_width(ta, CYD_SCREEN_PANEL_WIDTH_PX / 2); - lv_textarea_set_max_length(ta, 3); - lv_textarea_set_one_line(ta, true); - lv_textarea_set_text(ta, ""); - lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_ALL, keyboard); - - lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER); - lv_keyboard_set_textarea(keyboard, ta); } static void show_keyboard_with_hotend(lv_event_t * e){ keyboard_target = TARGET_HOTEND; - show_keyboard(e); + lv_create_keyboard_text_entry(keyboard_callback); } static void show_keyboard_with_bed(lv_event_t * e){ keyboard_target = TARGET_BED; - show_keyboard(e); + lv_create_keyboard_text_entry(keyboard_callback); } static void cooldown_temp(lv_event_t * e){ @@ -179,7 +149,7 @@ static void set_temp_via_preset(lv_event_t * e){ if (edit_mode) { keyboard_target = (temp_target)target; - show_keyboard(e); + lv_create_keyboard_text_entry(keyboard_callback); return; } diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index d42a210..98606b4 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -85,4 +85,111 @@ void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t tit lv_obj_center(label); } } +} + +void lv_keyboard_text_entry_close(lv_event_t * e){ + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * ta = lv_event_get_target(e); + lv_obj_t * kb = (lv_obj_t *)lv_event_get_user_data(e); + + if(code == LV_EVENT_DEFOCUSED || code == LV_EVENT_CANCEL || code == LV_EVENT_READY) + { + lv_keyboard_set_textarea(kb, NULL); + lv_obj_del(lv_obj_get_parent(kb)); + } +} + +void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode, lv_coord_t width, uint8_t max_length, const char* fill_text, bool contain_in_panel) +{ + lv_obj_t * parent = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_style_bg_opa(parent, LV_OPA_50, 0); + lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0); + lv_layout_flex_column(parent, LV_FLEX_ALIGN_SPACE_BETWEEN); + + if (contain_in_panel) + { + lv_obj_set_size(parent, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); + } + else + { + lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + } + + lv_obj_t * empty_panel = lv_create_empty_panel(parent); + lv_obj_set_flex_grow(empty_panel, 1); + + lv_obj_t * ta = lv_textarea_create(parent); + lv_obj_t * keyboard = lv_keyboard_create(parent); + + lv_obj_set_width(ta, width); + lv_textarea_set_max_length(ta, max_length); + lv_textarea_set_one_line(ta, true); + lv_textarea_set_text(ta, fill_text); + lv_obj_add_event_cb(ta, keyboard_callback, LV_EVENT_READY, keyboard); + lv_obj_add_event_cb(ta, lv_keyboard_text_entry_close, LV_EVENT_ALL, keyboard); + + lv_keyboard_set_mode(keyboard, keyboard_mode); + lv_keyboard_set_textarea(keyboard, ta); +} + +const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} }; + +void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height) +{ + lv_obj_t * panel = lv_create_empty_panel(root_panel); + lv_layout_flex_row(panel, LV_FLEX_ALIGN_END); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, label_text); + lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); + lv_obj_set_flex_grow(label, 1); + + lv_obj_set_parent(object, panel); + + if (set_height) + lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * line = lv_line_create(root_panel); + lv_line_set_points(line, line_points, 2); + lv_obj_set_style_line_width(line, 1, 0); + lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); +} + +#define DROPDOWN_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 3.75 +#define TOGGLE_WIDTH CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2 + +void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data) +{ + lv_obj_t * btn = lv_btn_create(lv_scr_act()); + lv_obj_add_event_cb(btn, on_click, LV_EVENT_CLICKED, user_data); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, btn_text); + lv_obj_center(label); + + lv_create_custom_menu_entry(label_text, btn, root_panel, true); +} + +void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data) +{ + lv_obj_t * toggle = lv_switch_create(lv_scr_act()); + lv_obj_add_event_cb(toggle, on_toggle, LV_EVENT_VALUE_CHANGED, user_data); + lv_obj_set_width(toggle, TOGGLE_WIDTH); + + if (state) + lv_obj_add_state(toggle, LV_STATE_CHECKED); + + lv_create_custom_menu_entry(label_text, toggle, root_panel, true); +} + +void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data) +{ + lv_obj_t * dropdown = lv_dropdown_create(lv_scr_act()); + lv_dropdown_set_options(dropdown, options); + lv_dropdown_set_selected(dropdown, index); + lv_obj_set_width(dropdown, DROPDOWN_WIDTH); + lv_obj_add_event_cb(dropdown, on_change, LV_EVENT_VALUE_CHANGED, user_data); + + lv_create_custom_menu_entry(label_text, dropdown, root_panel, true); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index d58ecc2..7bfcba1 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -37,4 +37,9 @@ lv_obj_t* lv_create_empty_panel(lv_obj_t* root); void lv_layout_flex_column(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_START, lv_coord_t pad_column = CYD_SCREEN_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_GAP_PX); void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_START, lv_coord_t pad_column = CYD_SCREEN_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_GAP_PX); void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count); -void destroy_event_user_data(lv_event_t * e); \ No newline at end of file +void destroy_event_user_data(lv_event_t * e); +void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_mode_t keyboard_mode = LV_KEYBOARD_MODE_NUMBER, lv_coord_t width = CYD_SCREEN_PANEL_WIDTH_PX / 2, uint8_t max_length = 3, const char* fill_text = "", bool contain_in_panel= true); +void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true); +void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL); +void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL); +void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL); \ No newline at end of file From 870d109c9284e3fc9ef64c2890d9a5f3ceb1425c Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 20:47:45 +0100 Subject: [PATCH 23/42] Implement printer switching in ip connect/error screen --- CYD-Klipper/src/core/data_setup.cpp | 4 +- CYD-Klipper/src/core/http_client.cpp | 6 +- CYD-Klipper/src/core/http_client.h | 2 + CYD-Klipper/src/ui/ip_setup.cpp | 3 + CYD-Klipper/src/ui/main_ui.cpp | 3 + CYD-Klipper/src/ui/panels/settings_panel.cpp | 12 +-- CYD-Klipper/src/ui/switch_printer.cpp | 88 ++++++++++++++++++++ CYD-Klipper/src/ui/switch_printer.h | 4 + CYD-Klipper/src/ui/ui_utils.cpp | 7 ++ CYD-Klipper/src/ui/ui_utils.h | 3 +- 10 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 CYD-Klipper/src/ui/switch_printer.cpp create mode 100644 CYD-Klipper/src/ui/switch_printer.h diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index e64a732..89e2f5a 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -313,7 +313,7 @@ void fetch_printer_data_minimal() delay(10); HTTPClient client; - configure_http_client(client, "http://" + String(config->klipper_host) + ":" + String(config->klipper_port) + "/printer/objects/query?webhooks&print_stats&virtual_sdcard", true, 1000); + configure_http_client(client, get_full_url("/printer/objects/query?webhooks&print_stats&virtual_sdcard", config), true, 1000); freeze_request_thread(); int httpCode = client.GET(); @@ -370,8 +370,6 @@ void fetch_printer_data_minimal() } } } - - Serial.printf("Record: %d %f %d\n", data[i].online, data[i].print_progress, data[i].state); } else { diff --git a/CYD-Klipper/src/core/http_client.cpp b/CYD-Klipper/src/core/http_client.cpp index 42edba3..4aeeb09 100644 --- a/CYD-Klipper/src/core/http_client.cpp +++ b/CYD-Klipper/src/core/http_client.cpp @@ -1,5 +1,9 @@ #include "http_client.h" -#include "../conf/global_config.h" + +String get_full_url(String url_part, PRINTER_CONFIG * config) +{ + return "http://" + String(config->klipper_host) + ":" + String(config->klipper_port) + url_part; +} String get_full_url(String url_part) { diff --git a/CYD-Klipper/src/core/http_client.h b/CYD-Klipper/src/core/http_client.h index d5c6d61..a3115ac 100644 --- a/CYD-Klipper/src/core/http_client.h +++ b/CYD-Klipper/src/core/http_client.h @@ -1,8 +1,10 @@ #pragma once #include +#include "../conf/global_config.h" String get_full_url(String url_part); +String get_full_url(String url_part, PRINTER_CONFIG * config); void configure_http_client(HTTPClient &client, String url, bool stream = true, int timeout = 1000); diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index d741fd4..ac1644b 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -7,6 +7,7 @@ #include "../core/macros_query.h" #include "panels/panel.h" #include "../core/http_client.h" +#include "switch_printer.h" bool connect_ok = false; lv_obj_t * hostEntry; @@ -161,6 +162,8 @@ void redraw_connect_screen(){ lv_label_set_text(btn_label, "Power Devices"); lv_obj_center(btn_label); } + + draw_switch_printer_button(); } static bool auth_entry_done = false; diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index 8191d5c..d02219d 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -8,6 +8,7 @@ #include "panels/panel.h" #include "../core/macros_query.h" #include "../core/lv_setup.h" +#include "switch_printer.h" char extruder_temp_buff[20]; char bed_temp_buff[20]; @@ -90,6 +91,8 @@ void error_ui(){ lv_label_set_text(label, "Devices"); lv_obj_center(label); } + + draw_switch_printer_button(); } void check_if_screen_needs_to_be_disabled(){ diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 8db8ce3..1072fc8 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -173,25 +173,19 @@ void settings_panel_init(lv_obj_t* panel){ lv_create_custom_menu_switch("Multi Printer Mode", panel, multi_printer_switch, global_config.multi_printer_mode); lv_create_custom_menu_switch("Auto Update", panel, auto_ota_update_switch, global_config.auto_ota_update); - - - lv_obj_t *label = lv_label_create(panel); - lv_label_set_text(label, REPO_VERSION " "); - lv_create_custom_menu_entry("Version", label, panel, false); + lv_create_custom_menu_label("Version", panel, REPO_VERSION " "); if (ota_has_update()){ lv_obj_t *btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, btn_ota_do_update, LV_EVENT_CLICKED, NULL); - label = lv_label_create(btn); + lv_obj_t *label = lv_label_create(btn); lv_label_set_text_fmt(label, "Update to %s", ota_new_version_name().c_str()); lv_obj_center(label); lv_create_custom_menu_entry("Device", btn, panel); } else { - label = lv_label_create(panel); - lv_label_set_text(label, ARDUINO_BOARD " "); - lv_create_custom_menu_entry("Device", label, panel, false); + lv_create_custom_menu_label("Device", panel, ARDUINO_BOARD " "); } } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/switch_printer.cpp b/CYD-Klipper/src/ui/switch_printer.cpp new file mode 100644 index 0000000..34c5684 --- /dev/null +++ b/CYD-Klipper/src/ui/switch_printer.cpp @@ -0,0 +1,88 @@ +#include "switch_printer.h" +#include "lvgl.h" +#include "../conf/global_config.h" +#include "ui_utils.h" +#include "../core/http_client.h" +#include "../core/lv_setup.h" +#include "../core/macros_query.h" + +static void btn_switch_printer(lv_event_t *e){ + lv_obj_t *btn = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + + set_printer_config_index(index); + set_color_scheme(); + _macros_query_internal(); + _power_devices_query_internal(); + + lv_obj_del(lv_obj_get_parent(lv_obj_get_parent(btn))); +} + +void switch_printer_init() { + lv_obj_t * parent = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_style_bg_opa(parent, LV_OPA_100, 0); + lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0); + lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_layout_flex_column(parent); + + lv_obj_set_size(lv_create_empty_panel(parent), 0, 0); + + auto width = CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; + + lv_obj_t * btn = lv_btn_create(parent); + lv_obj_set_size(btn, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, parent); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); + lv_obj_center(label); + + for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){ + PRINTER_CONFIG * config = &global_config.printer_config[i]; + const char* printer_name = (config->printer_name[0] == 0) ? config->klipper_host : config->printer_name; + + if (config == get_current_printer_config()) + { + lv_create_custom_menu_label(printer_name, parent, "Active"); + continue; + } + + if (config->ip_configured) { + HTTPClient client; + configure_http_client(client, get_full_url("/printer/objects/query?webhooks&print_stats&virtual_sdcard", config), true, 1000); + + + int httpCode = client.GET(); + if (httpCode == 200) + { + lv_create_custom_menu_button(printer_name, parent, btn_switch_printer, "Switch", config); + } + else + { + lv_create_custom_menu_label(printer_name, parent, "Offline"); + } + } + } +} + +static void show_switch_printer_screen(lv_event_t * e){ + switch_printer_init(); +} + +void draw_switch_printer_button() +{ + if (!global_config.multi_printer_mode) + { + return; + } + + lv_obj_t * btn = lv_btn_create(lv_scr_act()); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(btn, LV_ALIGN_TOP_RIGHT, -CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + lv_obj_add_event_cb(btn, show_switch_printer_screen, LV_EVENT_CLICKED, NULL); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_HOME); + lv_obj_center(label); +} \ No newline at end of file diff --git a/CYD-Klipper/src/ui/switch_printer.h b/CYD-Klipper/src/ui/switch_printer.h new file mode 100644 index 0000000..eb2d8a0 --- /dev/null +++ b/CYD-Klipper/src/ui/switch_printer.h @@ -0,0 +1,4 @@ +#pragma once + +void switch_printer_init(); +void draw_switch_printer_button(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index 98606b4..c43592b 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -192,4 +192,11 @@ void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel lv_obj_add_event_cb(dropdown, on_change, LV_EVENT_VALUE_CHANGED, user_data); lv_create_custom_menu_entry(label_text, dropdown, root_panel, true); +} + +void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text) +{ + lv_obj_t * label = lv_label_create(lv_scr_act()); + lv_label_set_text(label, text); + lv_create_custom_menu_entry(label_text, label, root_panel, false); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index 7bfcba1..295a2cf 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -42,4 +42,5 @@ void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, lv_keyboard_ void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true); void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL); void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL); -void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL); \ No newline at end of file +void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL); +void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text); \ No newline at end of file From 397c835129d74180ff649e68059986e569f9c39e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:08:45 +0100 Subject: [PATCH 24/42] Add build instructions --- Build.md | 37 +++++++++++++++++++++++++++++++++++++ readme/cmd.jpg | Bin 0 -> 18041 bytes 2 files changed, 37 insertions(+) create mode 100644 Build.md create mode 100644 readme/cmd.jpg diff --git a/Build.md b/Build.md new file mode 100644 index 0000000..4d2b2ba --- /dev/null +++ b/Build.md @@ -0,0 +1,37 @@ +# Building + +## Running a developer build + +On every change made in this repository, [Github Actions](https://github.com/suchmememanyskill/CYD-Klipper/actions) automatically builds the firmware images for various screens. You can run one of these images as follows: + +#### Getting a firmware image +0. Make sure you are logged into github +1. Go to a [Github Actions](https://github.com/suchmememanyskill/CYD-Klipper/actions) build summary, then download the `firmware` Artifact. +2. Open the firmware.zip archive you just downloaded, open the corresponding folder for your screen, then extract `merged_firmware.bin` + +This merged_firmware.bin file is a ready to flash image. Note that flashing this image does wipe your current configuration. + +#### Flashing merged_firmware.bin +1. Download and extract [esptool](https://github.com/espressif/esptool/releases) to a new folder + - For windows, download `esptool-v4.7.0-win64.zip` +2. Open a terminal window and navigate to this new folder containing esptool + - In windows, you can type cmd and press enter in the address bar in explorer to jump to the folder in cmd ![cmd](readme/cmd.jpg) +3. Move `merged-firmware.bin` into this new folder +4. Connect the display to your computer +5. Execute the command `esptool write_flash 0x0 merged-firmware.bin` + - Don't forget to hold down the boot button on the display + +## Building via PlatformIO + +0. Install [Visual Studio Code](https://code.visualstudio.com/) and install the PlatformIO IDE plugin. +1. Download the source code of CYD-Klipper + - This can be done via the `git clone https://github.com/suchmememanyskill/CYD-Klipper` command or via the green `<> Code` button on Github +2. Open the CYD-Klipper folder inside the CYD-Klipper folder in Visual Studio Code +3. Click on the Alien/Bug tab (PlatformIO) on the left +4. Expand the folder/tab for your specific screen + - Entries with the suffix '-SD' are using the smartdisplay driver. Entries without this suffix are using a custom driver + - Usually, a custom driver is preferred over the smartdisplay driver +5. Connect the display to your computer +6. Click 'Upload and Monitor' + - This will start compiling the code, and after upload it to the display + - Don't forget to hold the boot button while flashing. The screen will flash when the firmware is attempted to be flashed \ No newline at end of file diff --git a/readme/cmd.jpg b/readme/cmd.jpg new file mode 100644 index 0000000000000000000000000000000000000000..469deeda046a13011d7599fd12b3a7f58787f731 GIT binary patch literal 18041 zcmeHv2T&B-)9;W($r&XhAUTL+lob^gL?j1^q6jQV1_=U-AfQA6$q15j&N&AOl0k`* z1q4}8Skmqr^j_uO@2~fJuj;G!>eXF2RXuZ3cc0(s?$a|P`W^ZMKyp)7UKYT>zyR)o z{{Zv^a2>$H#6123f7sw3&S@MRY-}7nT-;Nq3GfIA@bU2R35m!^2#H9E@bO8gNJz;k zC@Cokh^fy~QJf{Cprkk+1Op4~gN<_r2j>h0AwD6+|Mm~v2#}rzLa|R{VVnmrNincU zG0?35BLHCFfZQH4{KpRi6Xfv}?&&jl_+W!F5&#ne3kwq)>zHe>wL4f3V3XpIF<+EE zMXq9md)}5p@JVRWX_jk6O_Ztwo2-}a*?FD8qoO{0j)v_5I|nD1kg$lTn7G9C8#1y` zIr*Dv>Kd9_+IMvB8$U2HHG`SkJ2*aaa&~d`e(K}v_w2cUSoq6`$f)R;*yNPdwDgS3 ztnA{F(z5c3%Bt$-me#iRj?On-gG0k3qhs&hkI&A{FDx!Ce_UBbY;Aw}y0eSi+dq~I z1Hk$&)(^@4CKo9v7bZ3~7B=p&To{;6V8J5A#$mpAicDGs*T|Oqyx^156xTwNiki-_ zTvFYnyk|FnN5v{M%Z4}>?VDu(J;A*Gk0kpc*iX5}0Rk)xaPhE60SIu|9xM{kd_MAi zKi;4rvA*C!^w|4oG$5^tv=SInVrCTd#GOyvEKo(NZD!~o+va@xOGV54S9r%)<*iwb zgIH9v<+*ZQtAlY}x7Nl|d{VfO&+VGI*6YHgVz(n?ZpYS`zC;7f;*Lj1_~#T91^fp| z`9-Uh_&xg^wWp<}l~fbsbC#Gc%FX>=I|QAvwGyv3Rv!~-2dlAZPp$Na1`?#=J$GyA z;V%zf&WQ~3EO?63U!6`7?)L5}6hmgsTFA=pz|&_n&-(L?oFD7_&@f9^jXH$v4xj-% z$O-!6#{#toI@Bms91Waa9NV2m1N9+Dm6I1*(3_m^uH**WqeyECKDVF&cgD?>6LfxL zB7vY@FP%X9U^ff4+q2&?!6=j;9BJz0us<%e6l5fc$2*rAW@&$Lri6s@ zH8c<(eStSuYo-qsvyFtl{i&amsu~y$!7l2c3!&w)!&HfpBlPz6o{4=#T^8B{>Q?lp zZvP}H2M2C9tsC1LZU#-kJs1x@q5&U9kS3n@L+wLm^?8Lei7i;-(7;o>wS!GGFatg0 zIC;UHk{n%^daQ%)6FT@o=Lh>gB8IWVpX~Bq`ahPZTRvooGMxD~CG;n$Pp=)@ygEHP zy`&3EuBeD=IARcv$Oa}DZhVF}El&&G2Cxq8Nw#S}=|bSkX0R{Cs+a_8CUCn2klG?O8T zV;s7Q0ebAT-rEb4cI&jNcQId3zv33IH@m%iVQZ` zk%JlRD9tQGp+*jNdg0~I@%jaLmjrA=0yY8uR~te%8#prEk6JvkF|tvLLn$3nq-p&fe* zOPnIBGrnxMj%>IWh>@HT{gp`iB%)O3VB#aT>Vgp3owvxhQ*Mq9@b%FNG!Qh#jKH7I z2u5+kc1ESR5tQu(rk4D#DER4Yv+GY!Jyi+!f?g4HxA-84I@e=UIj*sKn=aG|CW?HV z#SroE!I{CAs!s0fC{zAfOQ~*6gh=T9ECWKx+f}u`v~lh2OwZ$S!xJ~M*f$HZA!ds9 znn+0mx!&ez)F!lf-}=d+Fx+}aw|j;F>cl&htJZ!m)?!)HR5y_0VfpEo>6c>nh^o71 z0zAZrYq>68a+-&bOgUR>D4T7Ym()dTFlFzt?c601xY&;4k?PE=pJ?|{iU6sR=FxA6 zd&vA6siZXWrGQ}u60~8cH^dZ^_sNPk{eUlyVNvWkUT05TXGpmJmf~Y*z?|u)nF3@; zhr#L1nHECb+hY!Eyu__k63l}v_2eaa!>TO=#yz33^)Rz}Q(8G-i@5g@8X$2~v&e-> zluEIUGLJX}IFt@qr!+*E7W-hFq2Qx+FvAkSOU0<%A5IWJhR)4AQ`LPlS3t35aN)7d z4c=UHa{cJ-z;(fk?KTpw8l;^EiR!4%85|Ef=b9VHlvHGaPJgX*T8r)M*NU-EuM?O; z*oIR+Ar$Sg?V6SaJMb&73hceXtO@a>F)5onBQ(XWGGsVwl|OUtZm9(^;dR246={bm zbyhG+pQkKG@|*qD*qA>cbQG{y=cq5cIUTT*3aOjrq63F zW+4Q~dmYLnrHn)?Iym{y9aAS(i{liflT4-DUU+6j5~RQggS?ln1Yr(VZAb|mg`%jP z6g@K_{F{U3nxb^C{`kHz9i5EtaCj`aNgik z+~RP4&m!aARvqFxZ;ZV7!SXS5lOZn8d08v5`Hc0PY5%ANa{ZI{^_oRscGA=Wk25S*>L5qCboG_vZPBD>(-wM`rhf;s?`%p)%xtSk6 zN6+2?RYfocem>+0U5P3$zK}>^NgXa!jQ{8kt#RCYY2~hB0nWu2EpIi6Y`s~NF&8;j+&f^pM!i_NiXo8?jY zYt_6XX&V_XS?1-gJ)Qdn69m|~U6s70&66b}p9Q{rZvALTe)wSa(NJ*E+?2hXgo9m+ z@k2+>*9Say_WIa)g`OlA@2g3_A^3iWoBOy8;smYpdAy+DuX$m zNeMFAJeu;->$a(SqTNgG;;+CJNYTaF>tOez52@OMa3Pk6=H9L(za<$F^{UPCY9c2mxc7wP=({adz-KH;%BW zd$4(O$&NF3>F1SuauVdQ1LGfc?)&d!$qaZ<6MNQQynzS_i0wp1-4N`VCNCr7@fy>7 zmz_AS{eY=cfePnlCPoEW!<7-FWA}kO(P!D<#i&~~RlXaK-3SYWxVdgD2QF&5_#F}) zD2sFZRuRQm=je5$=uge8_|H^U)|cttiN9+%z!Sz5zwEjGbzPk!Ip)~kWBj_Pg07$Q zINUf6BLJ{m1zkJSvClu@&ZWUY)C2!$aNOuP*6?Zug96O&0mShLluUmF1qw9B-H&U3 zL=&uFAME2h$J|^!UaVgP5}07uCnsh;4k)Cd`WY)L8SP!U`q7Kg2+hpoYJv&NDIYN0 z@bc%B0k{SSWR$^nw?JlqB7h)#+>=)RwpjWI8AWnf`YJj`DzSF`@y33QkyL23xWK8knVqY;U817ieG~43fd< zTFG#a7!4HYR?T@1w~Q-Q`GCf+;phr{0fMSy+zdbiLu07xATUP1QnanJPc}(Wqk)XX zLq9Yy1_tr)eOENl2|se3GQSEV2D^jzPj~#M?z1UEdRI~pq763#6ZiJMcY@4hsF6u6~P_QWXC#CkL{8L+HJ(mBmhLVn-A~*=56`24FJHeS>T8`06=P|lJ?@E4#J(5N z0RJCr@M`6@+*`2~8E+6N-XKzbwb0tfNP%zuTzv4@`LnT=YCprE`|(l|A0GY*lz>Dq zzwjN3Iy#{T;3~prkD*%dU!Xdj{NgCJCK_@A+{eTJ33_W4kUfQO?EQJ`Z~NfRu@bS7 z_ZheT1X|(=R!7&_6#oe&5g-S@6HrA49AWo&IE>;VwvhTyX#Zn7zue$hlwLQTYzCob zh)QVqW(Go#GH76B?K}F{T>ZsW_&_#5Mf}*2N+-eSJY=?b?Vs>Wmuc{~ZM6agZOD&V z>|WYJx!8uI?D0>40&-$$@>V&%&GLI((PfG+PBxtsCj7*{oJm*ddb<4E-LKO1eEGN5 zV^O;A9|rJF_?`XWNQuC`T=N^$szAAjTz+d@g4OA^zF7|e`0^h%3RGs_pCGp!Tnbj_ zgPnzM2JBD%!2M4PJu8$t(B&N~3+`XW|7-&tRKR-up6jzeEZScd+|FNId2ivb=1a!v zJKvx?%N(vr`4}7WtYE%qFqf}P^1akzSv)UKP;jLNc5KlcBc6o^X^pPF6LeTeH(kG* zD9L~Yj;d7-q+Q#+1>$z#u0~1p?vKOY+@A*7Aee<*C z*|(zVCM(tDyP8qr2Iph5GpqPa;wp4m8euT*u|w$tiRl%?67Y0W&#AqNFt;&R;E9cV z$#k(hy_Nq$nXmptNE~e~4?a+HZeEq>g9TPvX~pGW{~f~nJGzK?4*`ThP?By_?zma? zBFYD6ayN2Ra8-4@hCAS~iwQCJI)=YYZBV1VURy^KBdsp1di3=;Mc5s)oqfltPyKxq z*`bC$A`ffy_7Y6Kw)ehc$Hk^8vgcbSlz}-%wN(3gAIfB#>6BuQX$87~HcCY>Yd< zb`qC}?L$GB&_I5`;VR8f`r|qMEKVhzo5|2r>+@ANOiqhlRC$%cWV}xhx;K>Mv&1SJ z_zB}4g((HwoZd)ehT3S##cgyxHF|kKsvFyu?R;-g;jv@XqvRYeMW&{M zix?4*X?9;UVDm`m^in1mZrxIY^(ulf)QE4_TY7AR$=t2p%f-@oZReAdWUk#Q&amkT zXzaM&duLR*_gc43ofrO_S+8@`Vzct6Wi;*q6GLYyb5+aU$EOad_zRfjjDLa=Rb@hH zp5CYo)qq~bqQgs(&k^wttV&Ls1miCmGTn)8C&BC3N*(~08tIkH-qS&Nwa_pVGbe%Ov z*HpvA(ki;gb>6i{A|nOtH11&BJxdqbgf*BY(|wOknEtJ-f5QGqu5~_djJJ@W&;!3~ z(kzfPY5A2DPN9)+*(TmQih^4TYIc#~Wrf%=ks_QO2DbhyLeYw~5;tsguQkt&E7W8e z3`#y1DDI3_UVS%vNN+SNQH2RmWT&OMLjC(he_^ zv4$?PPr72rf0SY}&|E`#D630FZMubmIvk2!@5a^26Wu<$rmShLNT^m_2?m?Kl=nU> zRTpldhAf3EqHDt62IkMM3W`&frJ1YVaW+}iW-h(dF*gr_C*35B5B;LEcxdvht|{GOxZ5TMm#qW3ze1M zK4pyK{?Pdq<&c|FQNAQ9>g0$pgXr4Vp%Iv zv7WIPIVQ^Xx?EJ0?6i@~E#<4{ZWY(}Wm)T${nPpT~zFQ=7BV;!jht3j`g*3H^a`7dRbh$ZS3MmIeln@gg)Mc z%!#DTO0LUxXhaU-Smp91MGJ;O-xhVE)D{@0s)$aV0R-43uOs#6_{m_A)d`6(x_#q% z>sRi}Oul{H=isFm#rzgq2$7SgCn^zge0lca;3-SbNQQFE?INlJ^vC{6>wQS5N5{^i zjziX&al;2Q5$#e<2kXeUm$v4`mnkqhhswwL&mtYsfI1wE1i9u=oZ!LZDBSeuI0A%> zgQ5O3yqWi?X4!Jw0}br>ZR{*F+AqD8GR^Y%Pe5zywUc&cT zXw9)gFmCPHd6-P0q;K=b5MS{<&$D|u`I~)>ANi!{JLVK`tkMK+Bqgs_*QH0Ly}{;% zS(+nSqbi6mxgmtw9kx>R7jE3FFvnbBkd$%F_UN7=TX?LUvUw;tr6(6kEA~}aq^crx z)@5Gd*^P{6uSwG z{5><4EI(dle)&Q?v_;h_&yWylsDg0(Qm&(};OO?EcEz0T3_E@|kGaReJS)?Jj~F&W ze$EhoRf@FUzgy$ErF8 zCsVTj3X1;l5<;mhkrZy^eEoX$*jH<|4Z^%+uWlNQsyD2FI9B)@CL%csj2^YM+yM_# zWOu6p1%mjw!)L-(YFBE%7&VPLx!c{E>}MZthmI5y4RqhNR~+@Aa;|8ZJ~iO>Aj^!p z+=F`5*!iKb{QcHT)yqr_Gmb^^rWW_bgnV=DN>yaedwoAbzs3yBQWOct0Il?&nf&7u zwkOpq#f)!V zOMN>0c%6$E$1s2fXgN?@#NCO zC-=RSCLXI)d+YmrI#fxKahl^*Gb}d5cdobO?mBo_Zy{}8OuiEVUDS55?6$*bQ$xZJ zV5dT(rOa-e&=4Xf3ge9yQ0ih zYKihBM|YP?lhgV)hZKeUcv*^gdX%zQV=oNnZ#-PjyHFjgt7|!ZgP56%y#DG%&wKy#KM`ZBiDmuH`UK2OhmVBnY@JuOP23U6m9aIVtEKIC-Xoscs^K zAM5PY=lJ=A=sd=Cqs#!$3+2(YD;FTv6R5nRuH|&wPP)yDda;8`SI4{RG-zi$#^E6Jf`snN5 zr=!pmKP5F^r;u$<^`a*XyKsarj+bYJZndU{F(!(2ckk-{7(~V_b+q*+o^F_)-j$Ko zlABKQEYv1nSr>*KR8$Sd!F|Djuw|WwSdkgJC^Ct{ z4SX^})ntFgsmaWa2#)+GG8C%k8mzP5>#aN*t z#3IFJgR~dRlesvhkSeh$GL)ylsg!YLQfHt?;nS@J z#NkSXro^k~ksN8SSe$EDsDyd)#U@)Zwjx&_Yfjo5bY!~Ms3hLjPOhw~M+4A0Us=J< z6wmC1&?;&=+g@7-0g2JoFCeGT0FCbp99M=igv6LS zf~;r%@sybsjZ{Rs!MnHDO3KonQnhQpGrjNk{5|bJp)}6Ry+uluxTi0ZO;zK~+uC*M z``Y-QQPm5MIkKd@7l}*Jo9WFwyVR86l4^3FHPs2jKik`fUQprEJtVtkf2qEW9?}n5 zJNgAdo>@^i?9n742kqukSnR~&T)=#4OyDJ!i^r8c`U+MZJ{8lSL~up;X6yi5H}M8C zU?+Rf?SVzMSuE(%gs&(x?^bKZWzbKbf17Vy9OiPqGVJSmjIsSrjK&i`+DAAOg<32K zmickyL9=Ux-|Xfm*DJ5y=42S?@Mr~bl$93^1wEx&wp)_jDko=VVN>efwp}Q7%nhni znL4yWhTccm&s|8Gn^2^&#B;yJQ&B!R9gr$|wx!nih7XBnrR=11UymIy&opecp1Wbm zTpi1;n^*5f+IdZ(bkT`J>>-1!tA?9e7G=4YWony*KOn8|)B>S{H#ZgCbu%s!0IIg=zfU|!5ChP8lf-;rtTFl zyzN^@iPdbeZ$Cn2v?Y#jhP(_+g_{K2x8E&x?(7g=dKs4$5W!;IB*ojX$rvc4LTKU-kr8CkgG5-W=@KTfq3;XcDO1os zv6LFvMRY;BqdGTrIHe>zLx$3}5v0x?OB}+gb}Q zZ&kUlg$7(I66cX$2zxxNuFAm$1}-7u@U>+4g-kBTj`zlTTl%-Z;Tm|#Yl&29uV>jL z${dgK6+TjHi4C}6WYK$JOW{tSv6ph~L!v>A+n0iI)9$ON+2uM&z+0`UU=n;eDesUe zcZvsvO-zS{4&1Mqt$#inNG@bl-YK_MNfV-i`24&qgy5aC9U5rWDckic-QDK-5*M&y zTv~1&w-kK7jpVSm6YDdhPIIznA-IbPKyM4?vg5+#aHbUh=6LZq(sTf2LS8U+E}a}& zB8_GCJvk284G!|()H!o(0KOFqwXD3W(J#S==Ev!1FbVzND2d}>eppHq4a6rN>NB3a zFyy8lJjreWQbnZAuWq464EGQfhYM(6?jvf{aBu57y|Puf-wGYLb>i0lM)k)< zqp#0Gl4Fi?8@3m%_uim^wt)%Rb_5Y9(q`^i1D`NR~vVX4m&8GD^icb#dXuyL1a8DOy2S+%-f0Ei)YN3`X zmZArD;LBYz+u>*+Ams#|4EC1tH$4d==*f$JM$|rM;&}JT?RMhg7*Sv1vKme{VBbmp z$^7x~k6^!q6%WJo`2qQ(%oE$?1buf0K?NT3z})cYjLfxUEQUE@b>)Jd^hb`Xp* zmrmR{sg$&?j^FRomNn8}_fCoM8$JI!okF>Zb8on_(3qZFM(9bkC>#$VX`A}1&A4I* znjx9w@B@_-i+X}S?*2E-{KX7@vvR-O>fg*%fXrVO>M!hl6F|oXG&KKNyZ;RhP**(L zw-)*va&msch%VP)n)&xE{Ki;;60FZ%aaA3Hlxdx?S5ZG`aqYU&Uz_pc?#chKf|jIT zhWc(QoiMK_O>M9yza=S*wK;x!}3fQc^O;I#Zl+wt!MHP;k0-p-zop69AgEqsTgK-9XYvRQ-vbw2wc)67=^ zGeaaT8hCg7P)_vd77aBDJVopX_Y_CmJKaP_0^`0%l!zj+-j5dIKO{s0pUl9Jofef& zh>r%a;0H8I9IyXJ>pKR%NUnRVecGYwvt`$uXjEBMk~Z+pIAkjs{6KBMJUs8q{3cig zui@HqK|kJHL12pCpxs#UNTOnd&9rHJh8n)Yu7ykYlouMPNVF=i5&x_9P6}qB&@P%l zjOr4p<}IOZbDWUy#lp&0po^W&(V^5gv#+e&->@->akHC*j?5cSI@Epm%&73*Joxv@ z$@lJ*fd6H|{xW5Bvgg0m-*Eh|T7XX$|H9!{)NL&FPBYI;76;lRlX|Wz8jN> z+)nJ72z1{Ndkep={ne@ii3W(*t`Zy&B;@Q3?3}xzwVgApjKf&?X0_p!6g|YvQ{I-c z+9^!24LW8XzOPa3yN0?lv59iPVBe9+I6CzS{y887B@8`zamTS@_A?eTq-~(@g3s)c znojV{kv(ij^)|~q7p#LeY+XM)g|lVsi%19Tncx!F&f0PYVi? zy{0=%)Aws`@K0buiqGT2Nu3|fvQ)~L@$p)b_mtOFc(7I^Txt!i{E)T7f{h7WVV@Ii zl+1$6o<}^GX$2qEi$)PHuad#WiE7Te&_-R3IpoBYp8>&$p884|N|R!QWl-m?{LZC4sE zx(cirupr2r<{PC%Mh>Nf@!i$66&LYq)LwdEG<`98m0LUOO%SiqfPE-ew@DP03r*E& zA}Yu{-x%8gF)Is5ym;?ZTCtSXYoaSqR_!9z`0(L=OwC=-^;&V4c|xw4wy~&jxbI># z+t=whnm3n8U&wxyoh`JHTfHi_OzABHxSyHtd+(%(l$<3rZI!x+2nrfWTeaNOF(XTB zSv&A5tYLvvRcMG=&WIdlu7qz-T}gAHqVZbbG|VJZ*uC(C|-Ep5GB0$l9KSn)%*Pmq@z{NTKqjW z+WsN*N@0YoWl9CcGuLm8kzOkkJ2KFUtYcga24B8UB&y1{aP^2m;5O}Uesp~po1T>g z<=xU5m!U&6uT?8(2o?(FV361}lK4btmo-qJy7y;%9fC|YAmm6>othyY-ZH--p_+gg zK9iw*23FsVEB#y)_b)?@Y`J`KQYfEi9$LaKATE7G5pK@-jJ4_*#~LJ2z2qmbDzK+) z3Z=4$!Ib)_4pd%E4SIE2Atc0rxiVZW{L{Fbb*8gPUvsgLZ6}`2gnMFlsD}p|g>b*!rZjiQ7@4V>Y>-HxHJK^{4G4wMW$0nYGxZ6xBZ4iyStvzN#&NOYH|J zaKjA;XZkELYpih&MJf>#7LQ$*`V`k{QaT~;`=mE40)0lsL*HZj=blmP5ByT_x|EUr zWA(!6@-f>9MNgbsq^#jx3C6~;keE5{{`9&)r>Pyttq*#MT)jnMsG;mA-m1G(Rnv72 z)%ub7M->ZS3uxXut9Bglw@^KP^C~_d;Dk4p`WuyO&eWE(YASY$5O> zv>kagrZ@c1VPZ;Ze1C4b`M`8M?|ww2_zqqAS6o8x&c2&KfNHsapK?`2MRoB0=``cu zRkjE6>SS1+jRM&AUKmT6Q}B)&55~9YnN|(+Qw_w+SI>Q2pP{RLknhYghg0$NOLtBH z{~09AvZ2_a^FbKx<7csAi`2JS9!&3IJPl$Jmu$r5%4A?Mc%FRtaQKshKIG=8kRoo| zPW3|%&G_-7I7Qxg7v9CxXCHeRIw@tYC+~oOouS+86low0}A!}QVM+6!Lw9fO|NS^}voHea8 z!f%3@gT?O2-L3FB^={Um6@w+{YNHH*mop3BJ69UAfBYWrbqb8AUw;Acg%9G% zewr`3g#`GREr;YXrF5U^ZME8$Y0rS8tAEJQ0*ZnkNo-f{MV%1{;3J@Zv&tR zRMo$F0MmN^>fw8O^ItvutB1dt(*GOwA$!IwC+X8v7HqfP3O@f9e#r__*Vt~qPXoRZ zAauBZ+DAFKygB-MxF+Zi3~h%WtnCdf9#!mKd_(eRW$9*St$p`Jz{4>{1~7*=OFE%} zD-YqDM%KsA$wBwHK6CiB2n{s(G=Pt~?>H!*0{{1b3i$RY_`2sQDl~AYZ_w`m%Ps4b nn6n6=@THAjcy!=~i+7gHhH Date: Sat, 9 Mar 2024 23:10:39 +0300 Subject: [PATCH 25/42] adds esp32-4827s043C-smartdisplay (#63) * +add esp32-4827s043C * DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX 40 to 35 --- .../boards/esp32-4827S043C-smartdisplay.json | 143 ++++++++++++++++++ CYD-Klipper/platformio.ini | 5 +- 2 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json diff --git a/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json b/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json new file mode 100644 index 0000000..06e18ed --- /dev/null +++ b/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json @@ -0,0 +1,143 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32s3_out.ld", + "partitions": "default_16MB.csv", + "memory_type": "qio_opi" + }, + "core": "esp32", + "extra_flags": [ + "'-D ARDUINO_ESP32S3_DEV'", + "'-D BOARD_HAS_PSRAM'", + "'-D ARDUINO_USB_MODE=1'", + "'-D ARDUINO_RUNNING_CORE=1'", + "'-D ARDUINO_EVENT_RUNNING_CORE=1'", + "'-D ARDUINO_USB_CDC_ON_BOOT=0'", + "'-D ESP32_4827S043C'", + "'-D LCD_WIDTH=480'", + "'-D LCD_HEIGHT=272'", + "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT)'", + "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT)'", + "'-D BCKL=2'", + "'-D LCD_ST7262_PAR'", + "'-D ST7262_PANEL_CONFIG_CLK_SRC=LCD_CLK_SRC_PLL160M'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_PCLK_HZ=(8*1000000)'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_H_RES=LCD_WIDTH'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_V_RES=LCD_HEIGHT'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_HSYNC_PULSE_WIDTH=4'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_HSYNC_BACK_PORCH=43'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_HSYNC_FRONT_PORCH=8'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_VSYNC_PULSE_WIDTH=4'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_VSYNC_BACK_PORCH=12'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_VSYNC_FRONT_PORCH=8'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_HSYNC_IDLE_LOW=true'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_VSYNC_IDLE_LOW=true'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_DE_IDLE_HIGH=false'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_PCLK_ACTIVE_NEG=true'", + "'-D ST7262_PANEL_CONFIG_TIMINGS_FLAGS_PCLK_IDLE_HIGH=false'", + "'-D ST7262_PANEL_CONFIG_DATA_WIDTH=16'", + "'-D ST7262_PANEL_CONFIG_SRAM_TRANS_ALIGN=4'", + "'-D ST7262_PANEL_CONFIG_PSRAM_TRANS_ALIGN=64'", + "'-D ST7262_PANEL_CONFIG_HSYNC_GPIO_NUM=39'", + "'-D ST7262_PANEL_CONFIG_VSYNC_GPIO_NUM=41'", + "'-D ST7262_PANEL_CONFIG_DE_GPIO_NUM=40'", + "'-D ST7262_PANEL_CONFIG_PCLK_GPIO_NUM=42'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R0=8'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R1=3'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R2=46'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R3=9'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_R4=1'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G0=5'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G1=6'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G2=7'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G3=15'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G4=16'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_G5=4'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B0=45'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B1=48'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B2=47'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B3=21'", + "'-D ST7262_PANEL_CONFIG_DATA_GPIO_B4=14'", + "'-D ST7262_PANEL_CONFIG_DISP_GPIO_NUM=GPIO_NUM_NC'", + "'-D ST7262_PANEL_CONFIG_FLAGS_DISP_ACTIVE_LOW=false'", + "'-D ST7262_PANEL_CONFIG_FLAGS_RELAX_ON_IDLE=false'", + "'-D ST7262_PANEL_CONFIG_FLAGS_FB_IN_PSRAM=true'", + "'-D BOARD_HAS_TOUCH'", + "'-D TOUCH_GT911_I2C'", + "'-D GT911_I2C_HOST=0'", + "'-D GT911_I2C_CONFIG_SDA_IO_NUM=19'", + "'-D GT911_I2C_CONFIG_SCL_IO_NUM=20'", + "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_MASTER_CLK_SPEED=400000'", + "'-D GT911_I2C_CONFIG_CLK_FLAGS=0'", + "'-D GT911_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS'", + "'-D GT911_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", + "'-D GT911_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", + "'-D GT911_IO_I2C_CONFIG_LCD_CMD_BITS=16'", + "'-D GT911_IO_I2C_CONFIG_LCD_PARAM_BITS=0'", + "'-D GT911_IO_I2C_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D GT911_IO_I2C_CONFIG_FLAGS_DISABLE_CONTROL_PHASE=true'", + "'-D GT911_TOUCH_CONFIG_X_MAX=LCD_WIDTH'", + "'-D GT911_TOUCH_CONFIG_Y_MAX=LCD_HEIGHT'", + "'-D GT911_TOUCH_CONFIG_RST_GPIO_NUM=38'", + "'-D GT911_TOUCH_CONFIG_INT_GPIO_NUM=18'", + "'-D GT911_TOUCH_CONFIG_LEVELS_RESET=0'", + "'-D GT911_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", + "'-D TOUCH_SWAP_XY=false'", + "'-D TOUCH_SWAP_X=false'", + "'-D TOUCH_SWAP_Y=false'", + "'-D BOARD_HAS_TF'", + "'-D TF_CS=10'", + "'-D TF_SPI_MOSI=11'", + "'-D TF_SPI_SCLK=12'", + "'-D TF_SPI_MISO=13'", + + "'-DCYD_SCREEN_HEIGHT_PX=272'", + "'-DCYD_SCREEN_WIDTH_PX=480'", + "-DROTATION_INVERTED=LV_DISP_ROT_180", + "-DROTATION_NORMAL=LV_DISP_ROT_NONE", + "'-DCYD_SCREEN_GAP_PX=10'", + "'-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35'", + "'-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=40'", + "'-DCYD_SCREEN_FONT=lv_font_montserrat_16'", + "'-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12'", + "'-DCYD_SCREEN_SIDEBAR_SIZE_PX=50'", + "'-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1'", + "'-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1'" + ], + "f_cpu": "240000000L", + "f_flash": "80000000L", + "flash_mode": "qio", + "hwids": [ + [ + "0x303A", + "0x1001" + ] + ], + "mcu": "esp32s3", + "variant": "esp32s3" + }, + "connectivity": [ + "wifi" + ], + "debug": { + "openocd_target": "esp32s3.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-4827S043C", + "upload": { + "flash_size": "16MB", + "maximum_ram_size": 327680, + "maximum_size": 16777216, + "use_1200bps_touch": true, + "wait_for_upload_port": true, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005004788147691.html", + "vendor": "Sunton" +} \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index b6dfe46..3782ed0 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -59,4 +59,7 @@ board = esp32-2432S032C-smartdisplay board = esp32-3248S035C-smartdisplay [env:esp32-8048S043C-SD] -board = esp32-8048S043C-smartdisplay \ No newline at end of file +board = esp32-8048S043C-smartdisplay + +[env:esp32-4827S043C-SD] +board = esp32-4827S043C-smartdisplay \ No newline at end of file From 68ff78eb4904371f08a44a282a97b2d22bf42817 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:16:40 +0100 Subject: [PATCH 26/42] Add 2432S024C-smartdisplay --- .../boards/esp32-2432S024C-smartdisplay.json | 122 ++++++++++++++++++ .../boards/esp32-4827S043C-smartdisplay.json | 2 +- CYD-Klipper/platformio.ini | 3 + 3 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json diff --git a/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json new file mode 100644 index 0000000..155f298 --- /dev/null +++ b/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json @@ -0,0 +1,122 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "'-D ARDUINO_ESP32_DEV'", + "'-D ESP32_2432S024C'", + "'-D LCD_WIDTH=240'", + "'-D LCD_HEIGHT=320'", + "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", + "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", + "'-D BCKL=27'", + "'-D LCD_ILI9341_SPI'", + "'-D ILI9341_SPI_HOST=SPI2_HOST'", + "'-D ILI9341_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", + "'-D ILI9341_SPI_BUS_MOSI_IO_NUM=13'", + "'-D ILI9341_SPI_BUS_MISO_IO_NUM=12'", + "'-D ILI9341_SPI_BUS_SCLK_IO_NUM=14'", + "'-D ILI9341_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ILI9341_SPI_BUS_FLAGS=0'", + "'-D ILI9341_SPI_BUS_INTR_FLAGS=0'", + "'-D ILI9341_SPI_CONFIG_CS_GPIO_NUM=15'", + "'-D ILI9341_SPI_CONFIG_DC_GPIO_NUM=2'", + "'-D ILI9341_SPI_CONFIG_SPI_MODE=SPI_MODE0'", + "'-D ILI9341_SPI_CONFIG_PCLK_HZ=24000000'", + "'-D ILI9341_SPI_CONFIG_TRANS_QUEUE_DEPTH=10'", + "'-D ILI9341_SPI_CONFIG_LCD_CMD_BITS=8'", + "'-D ILI9341_SPI_CONFIG_LCD_PARAM_BITS=8'", + "'-D ILI9341_SPI_CONFIG_FLAGS_DC_AS_CMD_PHASE=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_OCTAL_MODE=false'", + "'-D ILI9341_SPI_CONFIG_FLAGS_LSB_FIRST=false'", + "'-D ILI9341_DEV_CONFIG_RESET_GPIO_NUM=GPIO_NUM_NC'", + "'-D ILI9341_DEV_CONFIG_COLOR_SPACE=ESP_LCD_COLOR_SPACE_BGR'", + "'-D ILI9341_DEV_CONFIG_BITS_PER_PIXEL=16'", + "'-D ILI9341_DEV_CONFIG_FLAGS_RESET_ACTIVE_HIGH=false'", + "'-D ILI9341_DEV_CONFIG_VENDOR_CONFIG=NULL'", + "'-D LCD_SWAP_XY=false'", + "'-D LCD_MIRROR_X=true'", + "'-D LCD_MIRROR_Y=false'", + "'-D BOARD_HAS_TOUCH'", + "'-D TOUCH_CST816S_I2C'", + "'-D CST816S_I2C_HOST=0'", + "'-D CST816S_I2C_CONFIG_SDA_IO_NUM=33'", + "'-D CST816S_I2C_CONFIG_SCL_IO_NUM=32'", + "'-D CST816S_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D CST816S_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D CST816S_I2C_CONFIG_MASTER_CLK_SPEED=400000'", + "'-D CST816S_I2C_CONFIG_CLK_FLAGS=0'", + "'-D CST816S_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_CST816S_ADDRESS'", + "'-D CST816S_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", + "'-D CST816S_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", + "'-D CST816S_IO_I2C_CONFIG_LCD_CMD_BITS=8'", + "'-D CST816S_IO_I2C_CONFIG_LCD_PARAM_BITS=0'", + "'-D CST816S_IO_I2C_CONFIG_FLAGS_DC_LOW_ON_DATA=false'", + "'-D CST816S_IO_I2C_CONFIG_FLAGS_DISABLE_CONTROL_PHASE=true'", + "'-D CST816S_TOUCH_CONFIG_X_MAX=LCD_WIDTH'", + "'-D CST816S_TOUCH_CONFIG_Y_MAX=LCD_HEIGHT'", + "'-D CST816S_TOUCH_CONFIG_RST_GPIO_NUM=25'", + "'-D CST816S_TOUCH_CONFIG_INT_GPIO_NUM=21'", + "'-D CST816S_TOUCH_CONFIG_LEVELS_RESET=0'", + "'-D CST816S_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", + "'-D TOUCH_SWAP_XY=false'", + "'-D TOUCH_SWAP_X=false'", + "'-D TOUCH_SWAP_Y=false'", + "'-D BOARD_HAS_TF'", + "'-D TF_CS=5'", + "'-D TF_SPI_MOSI=23'", + "'-D TF_SPI_SCLK=18'", + "'-D TF_SPI_MISO=19'", + "'-D BOARD_HAS_RGB_LED'", + "'-D RGB_LED_R=4'", + "'-D RGB_LED_G=16'", + "'-D RGB_LED_B=17'", + "'-D BOARD_HAS_CDS'", + "'-D CDS=34'", + "'-D BOARD_HAS_SPEAK'", + "'-D SPEAK=26'", + + "-DCYD_SCREEN_GAP_PX=8", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35", + "-DCYD_SCREEN_FONT=lv_font_montserrat_14", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_10", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=40", + "-DCYD_SCREEN_DRIVER_ESP32_SMARTDISPLAY=1", + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-2432S024C-SD", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005005865107357.html", + "vendor": "Sunton" + } \ No newline at end of file diff --git a/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json b/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json index 06e18ed..231617b 100644 --- a/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json @@ -128,7 +128,7 @@ "arduino", "espidf" ], - "name": "esp32-4827S043C", + "name": "esp32-4827S043C-SD", "upload": { "flash_size": "16MB", "maximum_ram_size": 327680, diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 3782ed0..0773f71 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -43,6 +43,9 @@ lib_deps = bblanchon/ArduinoJson@^7.0.0 plageoj/UrlEncode@^1.0.1 +[env:esp32-2432S024C-SD] +board = esp32-2432S024C-smartdisplay + [env:esp32-2432S028Rv1-SD] board = esp32-2432S028RV1-smartdisplay From 451304b5dfd90596c8d2a9f57f8166eb48705040 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:16:55 +0100 Subject: [PATCH 27/42] Add 2432S024C and 4827S043C to CI --- ci.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ci.py b/ci.py index bd4abdd..cf9b893 100644 --- a/ci.py +++ b/ci.py @@ -1,6 +1,13 @@ import subprocess, os, shutil, json -CYD_PORTS = ["esp32-3248S035C", "esp32-2432S028R", "esp32-2432S032C-SD", "esp32-8048S043C-SD"] +CYD_PORTS = [ + "esp32-3248S035C", + "esp32-2432S028R", + "esp32-2432S032C-SD", + "esp32-8048S043C-SD", + "esp32-2432S024C-SD", + "esp32-4827S043C-SD" +] BASE_DIR = os.getcwd() def get_manifest(base_path : str, device_name : str): From 61f15ff6f3b4d67f538b90fb8708307062757f9e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 9 Mar 2024 21:43:46 +0100 Subject: [PATCH 28/42] Fix bugs --- CYD-Klipper/src/ui/panels/printer_panel.cpp | 6 ++-- CYD-Klipper/src/ui/panels/settings_panel.cpp | 37 +++++++++++++------- CYD-Klipper/src/ui/switch_printer.cpp | 15 +++++--- CYD-Klipper/src/ui/switch_printer.h | 1 + 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index ca7c63c..900c15a 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -6,6 +6,7 @@ #include #include "../nav_buttons.h" #include "../../core/macros_query.h" +#include "../switch_printer.h" const char * printer_status[] = { "Error", @@ -148,10 +149,7 @@ static void btn_printer_activate(lv_event_t * e) PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); int index = config - global_config.printer_config; - set_printer_config_index(index); - set_color_scheme(); - _macros_query_internal(); - _power_devices_query_internal(); + switch_printer(index); lv_msg_send(DATA_PRINTER_MINIMAL, NULL); } diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 1072fc8..12fdad9 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -127,19 +127,31 @@ void settings_panel_init(lv_obj_t* panel){ lv_layout_flex_column(panel); lv_obj_set_scrollbar_mode(panel, LV_SCROLLBAR_MODE_OFF); - lv_create_custom_menu_button("Configure WiFi", panel, reset_wifi_click, "Restart"); - lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart"); + if (global_config.multi_printer_mode) + { + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, "Printer Specific Settings"); + } -#ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION - lv_create_custom_menu_button("Calibrate Touch", panel, reset_calibration_click, "Restart"); -#endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION + lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode); + lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme); #ifndef CYD_SCREEN_DISABLE_INVERT_COLORS lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors); #endif // CYD_SCREEN_DISABLE_INVERT_COLORS lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode); - lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme); + lv_create_custom_menu_button("Configure IP", panel, reset_ip_click, "Restart"); + + if (global_config.multi_printer_mode) + { + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, "\nGlobal Settings"); + } + +#ifndef CYD_SCREEN_DISABLE_TIMEOUT + lv_create_custom_menu_switch("Screen On During Print", panel, on_during_print_switch, global_config.on_during_print); +#endif int brightness_settings_index = 0; for (int i = 0; i < SIZEOF(brightness_options_values); i++){ @@ -151,7 +163,6 @@ void settings_panel_init(lv_obj_t* panel){ lv_create_custom_menu_dropdown("Brightness", panel, brightness_dropdown, brightness_options, brightness_settings_index); - #ifndef CYD_SCREEN_DISABLE_TIMEOUT int wake_timeout_settings_index = 0; for (int i = 0; i < SIZEOF(wake_timeout_options_values); i++){ @@ -164,13 +175,7 @@ void settings_panel_init(lv_obj_t* panel){ lv_create_custom_menu_dropdown("Wake Timeout", panel, wake_timeout_dropdown, wake_timeout_options, wake_timeout_settings_index); #endif - lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode); lv_create_custom_menu_switch("Rotate Screen", panel, rotate_screen_switch, global_config.rotate_screen); - -#ifndef CYD_SCREEN_DISABLE_TIMEOUT - lv_create_custom_menu_switch("Screen On During Print", panel, on_during_print_switch, global_config.on_during_print); -#endif - lv_create_custom_menu_switch("Multi Printer Mode", panel, multi_printer_switch, global_config.multi_printer_mode); lv_create_custom_menu_switch("Auto Update", panel, auto_ota_update_switch, global_config.auto_ota_update); lv_create_custom_menu_label("Version", panel, REPO_VERSION " "); @@ -188,4 +193,10 @@ void settings_panel_init(lv_obj_t* panel){ else { lv_create_custom_menu_label("Device", panel, ARDUINO_BOARD " "); } + + #ifndef CYD_SCREEN_DISABLE_TOUCH_CALIBRATION + lv_create_custom_menu_button("Calibrate Touch", panel, reset_calibration_click, "Restart"); + #endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION + + lv_create_custom_menu_button("Configure WiFi", panel, reset_wifi_click, "Restart"); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/switch_printer.cpp b/CYD-Klipper/src/ui/switch_printer.cpp index 34c5684..f344334 100644 --- a/CYD-Klipper/src/ui/switch_printer.cpp +++ b/CYD-Klipper/src/ui/switch_printer.cpp @@ -5,16 +5,23 @@ #include "../core/http_client.h" #include "../core/lv_setup.h" #include "../core/macros_query.h" +#include "../core/screen_driver.h" + +void switch_printer(int index) +{ + set_printer_config_index(index); + set_color_scheme(); + set_invert_display(); + _macros_query_internal(); + _power_devices_query_internal(); +} static void btn_switch_printer(lv_event_t *e){ lv_obj_t *btn = lv_event_get_target(e); PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); int index = config - global_config.printer_config; - set_printer_config_index(index); - set_color_scheme(); - _macros_query_internal(); - _power_devices_query_internal(); + switch_printer(index); lv_obj_del(lv_obj_get_parent(lv_obj_get_parent(btn))); } diff --git a/CYD-Klipper/src/ui/switch_printer.h b/CYD-Klipper/src/ui/switch_printer.h index eb2d8a0..775303c 100644 --- a/CYD-Klipper/src/ui/switch_printer.h +++ b/CYD-Klipper/src/ui/switch_printer.h @@ -1,4 +1,5 @@ #pragma once +void switch_printer(int index); void switch_printer_init(); void draw_switch_printer_button(); \ No newline at end of file From e457114402f3ab2454029b24b58a97a7b5072e2a Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 10 Mar 2024 00:03:30 +0100 Subject: [PATCH 29/42] (Hopefully) fix touch on 2432S024C --- CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json | 2 +- CYD-Klipper/platformio.ini | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json index 155f298..dd03405 100644 --- a/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json @@ -64,7 +64,7 @@ "'-D CST816S_TOUCH_CONFIG_INT_GPIO_NUM=21'", "'-D CST816S_TOUCH_CONFIG_LEVELS_RESET=0'", "'-D CST816S_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", - "'-D TOUCH_SWAP_XY=false'", + "'-D TOUCH_SWAP_XY=true'", "'-D TOUCH_SWAP_X=false'", "'-D TOUCH_SWAP_Y=false'", "'-D BOARD_HAS_TF'", diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 0773f71..c77129c 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -61,8 +61,8 @@ board = esp32-2432S032C-smartdisplay [env:esp32-3248S035C-SD] board = esp32-3248S035C-smartdisplay -[env:esp32-8048S043C-SD] -board = esp32-8048S043C-smartdisplay - [env:esp32-4827S043C-SD] -board = esp32-4827S043C-smartdisplay \ No newline at end of file +board = esp32-4827S043C-smartdisplay + +[env:esp32-8048S043C-SD] +board = esp32-8048S043C-smartdisplay \ No newline at end of file From fb1e264df7fbd43feabd3ebb1e464a7c3cf8235a Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 10 Mar 2024 01:08:47 +0100 Subject: [PATCH 30/42] Display M117 message on screen --- CYD-Klipper/platformio.ini | 3 ++ CYD-Klipper/src/core/data_setup.cpp | 12 ++++--- CYD-Klipper/src/ui/ui_utils.cpp | 51 +++++++++++++++++++++++++++++ CYD-Klipper/src/ui/ui_utils.h | 3 +- 4 files changed, 64 insertions(+), 5 deletions(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index b6dfe46..1472295 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -17,6 +17,7 @@ lib_deps = https://github.com/suchmememanyskill/esp32-smartdisplay bblanchon/ArduinoJson@^7.0.0 plageoj/UrlEncode@^1.0.1 + erriez/ErriezCRC32 @ ^1.0.1 monitor_filters = esp32_exception_decoder build_flags = -DLV_CONF_PATH="../../../../src/conf/lv_conf.h" @@ -32,6 +33,7 @@ lib_deps = https://github.com/PaulStoffregen/XPT2046_Touchscreen.git bblanchon/ArduinoJson@^7.0.0 plageoj/UrlEncode@^1.0.1 + erriez/ErriezCRC32 @ ^1.0.1 [env:esp32-3248S035C] board = esp32-3248S035C @@ -42,6 +44,7 @@ lib_deps = https://github.com/OperatorB/gt911-arduino-fixed-reset.git bblanchon/ArduinoJson@^7.0.0 plageoj/UrlEncode@^1.0.1 + erriez/ErriezCRC32 @ ^1.0.1 [env:esp32-2432S028Rv1-SD] board = esp32-2432S028RV1-smartdisplay diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 89e2f5a..69ec09b 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -7,6 +7,7 @@ #include "macros_query.h" #include #include "http_client.h" +#include "../ui/ui_utils.h" const char *printer_state_messages[] = { "Error", @@ -112,7 +113,7 @@ void fetch_printer_data() { freeze_request_thread(); PRINTER_CONFIG *config = get_current_printer_config(); - SETUP_HTTP_CLIENT("/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks&fan") + SETUP_HTTP_CLIENT("/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks&fan&display_status") int httpCode = client.GET(); delay(10); @@ -235,8 +236,11 @@ void fetch_printer_data() } } - // TODO: make a call to /server/files/metadata to get more accurate time estimates - // https://moonraker.readthedocs.io/en/latest/web_api/#server-administration + if (status.containsKey("display_status")) + { + const char* message = status["display_status"]["message"]; + lv_create_popup_message(message, 10000); + } if (printer.state == PRINTER_STATE_PRINTING && printer.print_progress > 0) { @@ -418,5 +422,5 @@ void data_setup() macros_query_setup(); freeze_render_thread(); - xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 0, &background_loop, 0); + xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 2, &background_loop, 0); } diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index c43592b..a6d0e21 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -2,6 +2,7 @@ #include "ui_utils.h" #include "../core/data_setup.h" #include "../core/lv_setup.h" +#include lv_obj_t* lv_create_empty_panel(lv_obj_t* root) { lv_obj_t* panel = lv_obj_create(root); @@ -199,4 +200,54 @@ void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, c lv_obj_t * label = lv_label_create(lv_scr_act()); lv_label_set_text(label, text); lv_create_custom_menu_entry(label_text, label, root_panel, false); +} + +uint32_t message_hash = 0; +lv_timer_t* timer = NULL; + +void on_timer_destroy(lv_event_t * e) +{ + lv_timer_del(timer); + timer = NULL; + Serial.println("Timer destroy"); +} + +void timer_callback(lv_timer_t *timer) +{ + lv_obj_t * panel = (lv_obj_t *)timer->user_data; + lv_obj_del(panel); + Serial.println("Timer callback"); +} + +void lv_create_popup_message(const char* message, uint16_t timeout_ms) +{ + Serial.println("Hello"); + if (message == nullptr || timer != NULL) + { + return; + } + + uint32_t new_hash = crc32String(message); + + if (new_hash == message_hash) + { + return; + } + + message_hash = new_hash; + + lv_obj_t* panel = lv_obj_create(lv_scr_act()); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, LV_SIZE_CONTENT); + lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER); + lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, -CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + lv_obj_add_event_cb(panel, on_timer_destroy, LV_EVENT_DELETE, NULL); + lv_obj_set_style_border_color(panel, lv_color_hex(0xFF0000), 0); + + lv_obj_t* label = lv_label_create(panel); + lv_label_set_text_fmt(label, "%s", message); + lv_obj_set_size(label, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 6, LV_SIZE_CONTENT); + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + + timer = lv_timer_create(timer_callback, timeout_ms, panel); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index 295a2cf..8c4239c 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -43,4 +43,5 @@ void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_ob void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL); void lv_create_custom_menu_switch(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_toggle, bool state, void * user_data = NULL); void lv_create_custom_menu_dropdown(const char *label_text, lv_obj_t *root_panel, lv_event_cb_t on_change, const char *options, int index, void * user_data = NULL); -void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text); \ No newline at end of file +void lv_create_custom_menu_label(const char *label_text, lv_obj_t* root_panel, const char *text); +void lv_create_popup_message(const char* message, uint16_t timeout_ms); \ No newline at end of file From 8d6d22c38af439cdad522c7b7355b5efdc85bec1 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 11 Mar 2024 21:55:33 +0100 Subject: [PATCH 31/42] Change status to 'In Control' when in control --- CYD-Klipper/src/ui/panels/printer_panel.cpp | 9 ++++++++- CYD-Klipper/src/ui/ui_utils.cpp | 3 --- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index 900c15a..68148f5 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -34,7 +34,14 @@ static void update_printer_status_text(lv_event_t * e) int index = config - global_config.printer_config; PrinterMinimal * printer = &printer_minimal[index]; - if (!printer->online){ + if (config == get_current_printer_config()) + { + lv_label_set_text(label, "In Control"); + return; + } + + if (!printer->online) + { lv_label_set_text(label, "Offline"); return; } diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index a6d0e21..b1e6b4a 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -209,19 +209,16 @@ void on_timer_destroy(lv_event_t * e) { lv_timer_del(timer); timer = NULL; - Serial.println("Timer destroy"); } void timer_callback(lv_timer_t *timer) { lv_obj_t * panel = (lv_obj_t *)timer->user_data; lv_obj_del(panel); - Serial.println("Timer callback"); } void lv_create_popup_message(const char* message, uint16_t timeout_ms) { - Serial.println("Hello"); if (message == nullptr || timer != NULL) { return; From a265301d9713a09a7a5b3dc326d141d53fcb9245 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 11 Mar 2024 22:20:56 +0100 Subject: [PATCH 32/42] Update smartdisplay driver to v2.0.7 --- CYD-Klipper/boards/esp32-2432S022C-smartdisplay.json | 10 +++++----- CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json | 6 +++--- .../boards/esp32-2432S028RV1-smartdisplay.json | 4 ++-- .../boards/esp32-2432S028RV2-smartdisplay.json | 4 ++-- .../boards/esp32-2432S028RV3-smartdisplay.json | 6 +++--- CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json | 12 ++++++------ CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json | 12 ++++++------ CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json | 12 ++++++------ CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json | 10 +++++----- CYD-Klipper/platformio.ini | 2 +- 10 files changed, 39 insertions(+), 39 deletions(-) diff --git a/CYD-Klipper/boards/esp32-2432S022C-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S022C-smartdisplay.json index 6359d76..a0bd504 100644 --- a/CYD-Klipper/boards/esp32-2432S022C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S022C-smartdisplay.json @@ -11,7 +11,7 @@ "'-D LCD_HEIGHT=320'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/8)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", - "'-D BCKL=0'", + "'-D GPIO_BCKL=0'", "'-D LCD_ST7789_I80'", "'-D ST7789_I80_BUS_CONFIG_CLK_SRC=LCD_CLK_SRC_PLL160M'", "'-D ST7789_I80_BUS_CONFIG_DC=16'", @@ -29,7 +29,7 @@ "'-D ST7789_I80_BUS_CONFIG_PSRAM_TRANS_ALIGN=64'", "'-D ST7789_I80_BUS_CONFIG_SRAM_TRANS_ALIGN=4'", "'-D ST7789_IO_I80_CONFIG_CS_GPIO_NUM=17'", - "'-D ST7789_IO_I80_CONFIG_PCLK_HZ=55000000'", + "'-D ST7789_IO_I80_CONFIG_PCLK_HZ=12000000'", "'-D ST7789_IO_I80_CONFIG_TRANS_QUEUE_DEPTH=10'", "'-D ST7789_IO_I80_CONFIG_LCD_CMD_BITS=8'", "'-D ST7789_IO_I80_CONFIG_LCD_PARAM_BITS=8'", @@ -43,7 +43,7 @@ "'-D ST7789_IO_I80_CONFIG_FLAGS_PCLK_ACTIVE_NEG=0'", "'-D ST7789_IO_I80_CONFIG_FLAGS_PCLK_IDLE_LOW=0'", "'-D ST7789_DEV_CONFIG_RESET_GPIO_NUM=GPIO_NUM_NC'", - "'-D ST7789_DEV_CONFIG_COLOR_SPACE=ESP_LCD_COLOR_SPACE_BGR'", + "'-D ST7789_DEV_CONFIG_COLOR_SPACE=ESP_LCD_COLOR_SPACE_RGB'", "'-D ST7789_DEV_CONFIG_BITS_PER_PIXEL=16'", "'-D ST7789_DEV_CONFIG_FLAGS_RESET_ACTIVE_HIGH=false'", "'-D ST7789_DEV_CONFIG_VENDOR_CONFIG=NULL'", @@ -53,7 +53,7 @@ "'-D LCD_MIRROR_Y=false'", "'-D BOARD_HAS_TOUCH'", "'-D TOUCH_CST816S_I2C'", - "'-D CST816S_I2C_HOST=0'", + "'-D CST816S_I2C_HOST=I2C_NUM_0'", "'-D CST816S_I2C_CONFIG_SDA_IO_NUM=21'", "'-D CST816S_I2C_CONFIG_SCL_IO_NUM=22'", "'-D CST816S_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", @@ -73,7 +73,7 @@ "'-D CST816S_TOUCH_CONFIG_INT_GPIO_NUM=GPIO_NUM_NC'", "'-D CST816S_TOUCH_CONFIG_LEVELS_RESET=0'", "'-D CST816S_TOUCH_CONFIG_LEVELS_INTERRUPT=0'", - "'-D TOUCH_SWAP_XY=false'", + "'-D TOUCH_SWAP_XY=true'", "'-D TOUCH_SWAP_X=false'", "'-D TOUCH_SWAP_Y=false'", "'-D BOARD_HAS_TF'", diff --git a/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json index dd03405..1d9a6f9 100644 --- a/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S024C-smartdisplay.json @@ -11,7 +11,7 @@ "'-D LCD_HEIGHT=320'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", - "'-D BCKL=27'", + "'-D GPIO_BCKL=27'", "'-D LCD_ILI9341_SPI'", "'-D ILI9341_SPI_HOST=SPI2_HOST'", "'-D ILI9341_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", @@ -20,7 +20,7 @@ "'-D ILI9341_SPI_BUS_SCLK_IO_NUM=14'", "'-D ILI9341_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", "'-D ILI9341_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", - "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=(LVGL_BUFFER_PIXELS*sizeof(lv_color16_t))'", "'-D ILI9341_SPI_BUS_FLAGS=0'", "'-D ILI9341_SPI_BUS_INTR_FLAGS=0'", "'-D ILI9341_SPI_CONFIG_CS_GPIO_NUM=15'", @@ -44,7 +44,7 @@ "'-D LCD_MIRROR_Y=false'", "'-D BOARD_HAS_TOUCH'", "'-D TOUCH_CST816S_I2C'", - "'-D CST816S_I2C_HOST=0'", + "'-D CST816S_I2C_HOST=I2C_NUM_0'", "'-D CST816S_I2C_CONFIG_SDA_IO_NUM=33'", "'-D CST816S_I2C_CONFIG_SCL_IO_NUM=32'", "'-D CST816S_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", diff --git a/CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json index 9db9ad3..e095218 100644 --- a/CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S028RV1-smartdisplay.json @@ -11,7 +11,7 @@ "'-D LCD_HEIGHT=320'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", - "'-D BCKL=21'", + "'-D GPIO_BCKL=21'", "'-D LCD_ILI9341_SPI'", "'-D ILI9341_SPI_HOST=SPI2_HOST'", "'-D ILI9341_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", @@ -20,7 +20,7 @@ "'-D ILI9341_SPI_BUS_SCLK_IO_NUM=14'", "'-D ILI9341_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", "'-D ILI9341_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", - "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=(LVGL_BUFFER_PIXELS*sizeof(lv_color16_t))'", "'-D ILI9341_SPI_BUS_FLAGS=0'", "'-D ILI9341_SPI_BUS_INTR_FLAGS=0'", "'-D ILI9341_SPI_CONFIG_CS_GPIO_NUM=15'", diff --git a/CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json index b99744c..d1cbbea 100644 --- a/CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S028RV2-smartdisplay.json @@ -11,7 +11,7 @@ "'-D LCD_HEIGHT=320'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", - "'-D BCKL=21'", + "'-D GPIO_BCKL=21'", "'-D LCD_ILI9341_SPI'", "'-D ILI9341_SPI_HOST=SPI2_HOST'", "'-D ILI9341_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", @@ -20,7 +20,7 @@ "'-D ILI9341_SPI_BUS_SCLK_IO_NUM=14'", "'-D ILI9341_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", "'-D ILI9341_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", - "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ILI9341_SPI_BUS_MAX_TRANSFER_SZ=(LVGL_BUFFER_PIXELS*sizeof(lv_color16_t))'", "'-D ILI9341_SPI_BUS_FLAGS=0'", "'-D ILI9341_SPI_BUS_INTR_FLAGS=0'", "'-D ILI9341_SPI_CONFIG_CS_GPIO_NUM=15'", diff --git a/CYD-Klipper/boards/esp32-2432S028RV3-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S028RV3-smartdisplay.json index 088d369..8c12ed9 100644 --- a/CYD-Klipper/boards/esp32-2432S028RV3-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S028RV3-smartdisplay.json @@ -11,7 +11,7 @@ "'-D LCD_HEIGHT=320'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", - "'-D BCKL=21'", + "'-D GPIO_BCKL=21'", "'-D LCD_ST7789_SPI'", "'-D ST7789_SPI_HOST=SPI2_HOST'", "'-D ST7789_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", @@ -20,13 +20,13 @@ "'-D ST7789_SPI_BUS_SCLK_IO_NUM=14'", "'-D ST7789_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", "'-D ST7789_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", - "'-D ST7789_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ST7789_SPI_BUS_MAX_TRANSFER_SZ=(LVGL_BUFFER_PIXELS*sizeof(lv_color16_t))'", "'-D ST7789_SPI_BUS_FLAGS=0'", "'-D ST7789_SPI_BUS_INTR_FLAGS=0'", "'-D ST7789_SPI_CONFIG_CS_GPIO_NUM=15'", "'-D ST7789_SPI_CONFIG_DC_GPIO_NUM=2'", "'-D ST7789_SPI_CONFIG_SPI_MODE=SPI_MODE3'", - "'-D ST7789_SPI_CONFIG_PCLK_HZ=55000000'", + "'-D ST7789_SPI_CONFIG_PCLK_HZ=24000000'", "'-D ST7789_SPI_CONFIG_TRANS_QUEUE_DEPTH=10'", "'-D ST7789_SPI_CONFIG_LCD_CMD_BITS=8'", "'-D ST7789_SPI_CONFIG_LCD_PARAM_BITS=8'", diff --git a/CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json b/CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json index f377ad4..8702f43 100644 --- a/CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-2432S032C-smartdisplay.json @@ -11,7 +11,7 @@ "'-D LCD_HEIGHT=320'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", - "'-D BCKL=27'", + "'-D GPIO_BCKL=27'", "'-D LCD_IPS'", "'-D LCD_ST7789_SPI'", "'-D ST7789_SPI_HOST=SPI2_HOST'", @@ -21,7 +21,7 @@ "'-D ST7789_SPI_BUS_SCLK_IO_NUM=14'", "'-D ST7789_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", "'-D ST7789_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", - "'-D ST7789_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ST7789_SPI_BUS_MAX_TRANSFER_SZ=(LVGL_BUFFER_PIXELS*sizeof(lv_color16_t))'", "'-D ST7789_SPI_BUS_FLAGS=0'", "'-D ST7789_SPI_BUS_INTR_FLAGS=0'", "'-D ST7789_SPI_CONFIG_CS_GPIO_NUM=15'", @@ -45,13 +45,13 @@ "'-D LCD_MIRROR_Y=false'", "'-D BOARD_HAS_TOUCH'", "'-D TOUCH_GT911_I2C'", - "'-D GT911_I2C_HOST=0'", + "'-D GT911_I2C_HOST=I2C_NUM_0'", "'-D GT911_I2C_CONFIG_SDA_IO_NUM=33'", "'-D GT911_I2C_CONFIG_SCL_IO_NUM=32'", - "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", - "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_DISABLE'", + "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_DISABLE'", "'-D GT911_I2C_CONFIG_MASTER_CLK_SPEED=400000'", - "'-D GT911_I2C_CONFIG_CLK_FLAGS=0'", + "'-D GT911_I2C_CONFIG_CLK_FLAGS=I2C_SCLK_SRC_FLAG_FOR_NOMAL'", "'-D GT911_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS'", "'-D GT911_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", "'-D GT911_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", diff --git a/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json b/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json index b873d3e..2932d90 100644 --- a/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-3248S035C-smartdisplay.json @@ -11,7 +11,7 @@ "'-D LCD_HEIGHT=480'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT/4)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT)'", - "'-D BCKL=27'", + "'-D GPIO_BCKL=27'", "'-D LCD_ST7796_SPI'", "'-D ST7796_SPI_HOST=SPI2_HOST'", "'-D ST7796_SPI_DMA_CHANNEL=SPI_DMA_CH_AUTO'", @@ -20,7 +20,7 @@ "'-D ST7796_SPI_BUS_SCLK_IO_NUM=14'", "'-D ST7796_SPI_BUS_QUADWP_IO_NUM=GPIO_NUM_NC'", "'-D ST7796_SPI_BUS_QUADHD_IO_NUM=GPIO_NUM_NC'", - "'-D ST7796_SPI_BUS_MAX_TRANSFER_SZ=0'", + "'-D ST7796_SPI_BUS_MAX_TRANSFER_SZ=(LVGL_BUFFER_PIXELS*sizeof(lv_color16_t))'", "'-D ST7796_SPI_BUS_FLAGS=0'", "'-D ST7796_SPI_BUS_INTR_FLAGS=0'", "'-D ST7796_SPI_CONFIG_CS_GPIO_NUM=15'", @@ -44,13 +44,13 @@ "'-D LCD_MIRROR_Y=false'", "'-D BOARD_HAS_TOUCH'", "'-D TOUCH_GT911_I2C'", - "'-D GT911_I2C_HOST=0'", + "'-D GT911_I2C_HOST=I2C_NUM_0'", "'-D GT911_I2C_CONFIG_SDA_IO_NUM=33'", "'-D GT911_I2C_CONFIG_SCL_IO_NUM=32'", - "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", - "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_DISABLE'", + "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_DISABLE'", "'-D GT911_I2C_CONFIG_MASTER_CLK_SPEED=400000'", - "'-D GT911_I2C_CONFIG_CLK_FLAGS=0'", + "'-D GT911_I2C_CONFIG_CLK_FLAGS=I2C_SCLK_SRC_FLAG_FOR_NOMAL'", "'-D GT911_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS'", "'-D GT911_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", "'-D GT911_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", diff --git a/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json b/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json index 231617b..9793e12 100644 --- a/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-4827S043C-smartdisplay.json @@ -18,7 +18,7 @@ "'-D LCD_HEIGHT=272'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT)'", - "'-D BCKL=2'", + "'-D GPIO_BCKL=2'", "'-D LCD_ST7262_PAR'", "'-D ST7262_PANEL_CONFIG_CLK_SRC=LCD_CLK_SRC_PLL160M'", "'-D ST7262_PANEL_CONFIG_TIMINGS_PCLK_HZ=(8*1000000)'", @@ -64,13 +64,13 @@ "'-D ST7262_PANEL_CONFIG_FLAGS_FB_IN_PSRAM=true'", "'-D BOARD_HAS_TOUCH'", "'-D TOUCH_GT911_I2C'", - "'-D GT911_I2C_HOST=0'", + "'-D GT911_I2C_HOST=I2C_NUM_0'", "'-D GT911_I2C_CONFIG_SDA_IO_NUM=19'", "'-D GT911_I2C_CONFIG_SCL_IO_NUM=20'", - "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", - "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_DISABLE'", + "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_DISABLE'", "'-D GT911_I2C_CONFIG_MASTER_CLK_SPEED=400000'", - "'-D GT911_I2C_CONFIG_CLK_FLAGS=0'", + "'-D GT911_I2C_CONFIG_CLK_FLAGS=I2C_SCLK_SRC_FLAG_FOR_NOMAL'", "'-D GT911_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS'", "'-D GT911_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", "'-D GT911_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", @@ -91,7 +91,7 @@ "'-D TF_CS=10'", "'-D TF_SPI_MOSI=11'", "'-D TF_SPI_SCLK=12'", - "'-D TF_SPI_MISO=13'", + "'-D TF_SPI_MISO=13'", "'-DCYD_SCREEN_HEIGHT_PX=272'", "'-DCYD_SCREEN_WIDTH_PX=480'", diff --git a/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json index d98466a..4978087 100644 --- a/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json +++ b/CYD-Klipper/boards/esp32-8048S043C-smartdisplay.json @@ -18,7 +18,7 @@ "'-D LCD_HEIGHT=480'", "'-D LVGL_BUFFER_PIXELS=(LCD_WIDTH*LCD_HEIGHT)'", "'-D LVGL_BUFFER_MALLOC_FLAGS=(MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT)'", - "'-D BCKL=2'", + "'-D GPIO_BCKL=2'", "'-D LCD_ST7262_PAR'", "'-D ST7262_PANEL_CONFIG_CLK_SRC=LCD_CLK_SRC_PLL160M'", "'-D ST7262_PANEL_CONFIG_TIMINGS_PCLK_HZ=(12.5*1000000)'", @@ -64,13 +64,13 @@ "'-D ST7262_PANEL_CONFIG_FLAGS_FB_IN_PSRAM=true'", "'-D BOARD_HAS_TOUCH'", "'-D TOUCH_GT911_I2C'", - "'-D GT911_I2C_HOST=0'", + "'-D GT911_I2C_HOST=I2C_NUM_0'", "'-D GT911_I2C_CONFIG_SDA_IO_NUM=19'", "'-D GT911_I2C_CONFIG_SCL_IO_NUM=20'", - "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_ENABLE'", - "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_ENABLE'", + "'-D GT911_I2C_CONFIG_SDA_PULLUP_EN=GPIO_PULLUP_DISABLE'", + "'-D GT911_I2C_CONFIG_SCL_PULLUP_EN=GPIO_PULLUP_DISABLE'", "'-D GT911_I2C_CONFIG_MASTER_CLK_SPEED=400000'", - "'-D GT911_I2C_CONFIG_CLK_FLAGS=0'", + "'-D GT911_I2C_CONFIG_CLK_FLAGS=I2C_SCLK_SRC_FLAG_FOR_NOMAL'", "'-D GT911_IO_I2C_CONFIG_DEV_ADDR=ESP_LCD_TOUCH_IO_I2C_GT911_ADDRESS'", "'-D GT911_IO_I2C_CONFIG_CONTROL_PHASE_BYTES=1'", "'-D GT911_IO_I2C_CONFIG_DC_BIT_OFFSET=0'", diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 9d1405a..e1771b0 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -14,7 +14,7 @@ board = esp32dev framework = arduino monitor_speed = 115200 lib_deps = - https://github.com/suchmememanyskill/esp32-smartdisplay + https://github.com/suchmememanyskill/esp32-smartdisplay#9c1d737 bblanchon/ArduinoJson@^7.0.0 plageoj/UrlEncode@^1.0.1 erriez/ErriezCRC32 @ ^1.0.1 From a8c94fe207f2f581d26b7d8e12fef7127b9de423 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:08:48 +0100 Subject: [PATCH 33/42] Refactor + Power menu in printer menu --- CYD-Klipper/src/core/data_setup.cpp | 6 +- CYD-Klipper/src/core/data_setup.h | 1 + CYD-Klipper/src/core/macros_query.cpp | 142 ++++++++++++++------ CYD-Klipper/src/core/macros_query.h | 15 ++- CYD-Klipper/src/ui/ip_setup.cpp | 32 ++--- CYD-Klipper/src/ui/macros.cpp | 75 +++++++++++ CYD-Klipper/src/ui/macros.h | 9 ++ CYD-Klipper/src/ui/main_ui.cpp | 5 +- CYD-Klipper/src/ui/panels/macros_panel.cpp | 40 +----- CYD-Klipper/src/ui/panels/panel.h | 3 +- CYD-Klipper/src/ui/panels/printer_panel.cpp | 45 ++++++- CYD-Klipper/src/ui/switch_printer.cpp | 2 - 12 files changed, 253 insertions(+), 122 deletions(-) create mode 100644 CYD-Klipper/src/ui/macros.cpp create mode 100644 CYD-Klipper/src/ui/macros.h diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 69ec09b..73c3efc 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -8,6 +8,7 @@ #include #include "http_client.h" #include "../ui/ui_utils.h" +#include "macros_query.h" const char *printer_state_messages[] = { "Error", @@ -325,6 +326,7 @@ void fetch_printer_data_minimal() if (httpCode == 200) { data[i].online = true; + data[i].power_devices = 0; JsonDocument doc; deserializeJson(doc, client.getStream()); auto status = doc["result"]["status"]; @@ -377,7 +379,8 @@ void fetch_printer_data_minimal() } else { - printer_minimal->online = false; + data[i].online = false; + data[i].power_devices = power_devices_count(config); unfreeze_request_thread(); } } @@ -420,7 +423,6 @@ void data_setup() printer.print_filename = filename_buff; fetch_printer_data(); - macros_query_setup(); freeze_render_thread(); xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 2, &background_loop, 0); } diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index f7071cb..f6c5bde 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -41,6 +41,7 @@ typedef struct _PrinterMinimal { bool online; unsigned char state; float print_progress; // 0 -> 1 + unsigned int power_devices; } PrinterMinimal; extern Printer printer; diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index f194c1e..f3998b3 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -1,7 +1,6 @@ #include "lvgl.h" #include "macros_query.h" #include "./data_setup.h" -#include "../conf/global_config.h" #include #include #include "http_client.h" @@ -11,12 +10,15 @@ static int macros_count = 0; static char* power_devices[16] = {0}; static bool power_device_states[16] = {0}; -static int power_devices_count = 0; +static unsigned int stored_power_devices_count = 0; -void _macros_query_internal(){ - SETUP_HTTP_CLIENT("/printer/gcode/help") +MACROSQUERY macros_query(PRINTER_CONFIG * config) +{ + HTTPClient client; + configure_http_client(client, get_full_url("/printer/gcode/help", config), true, 1000); int httpCode = client.GET(); + if (httpCode == 200){ JsonDocument doc; deserializeJson(doc, client.getStream()); @@ -37,76 +39,132 @@ void _macros_query_internal(){ macros[macros_count++] = macro; } } + + return {(const char**)macros, (unsigned int)macros_count}; + } + else { + return {NULL, 0}; } } -void power_devices_clear(){ - for (int i = 0; i < power_devices_count; i++){ - free(power_devices[i]); - } - - power_devices_count = 0; +MACROSQUERY macros_query() +{ + return macros_query(get_current_printer_config()); } -void _power_devices_query_internal(){ - SETUP_HTTP_CLIENT("/machine/device_power/devices") +unsigned int macro_count(PRINTER_CONFIG * config) +{ + HTTPClient client; + configure_http_client(client, get_full_url("/printer/gcode/help", config), true, 1000); int httpCode = client.GET(); - if (httpCode == 200 || httpCode == 404 || httpCode == 500){ - power_devices_clear(); + if (httpCode == 200){ + JsonDocument doc; + deserializeJson(doc, client.getStream()); + auto result = doc["result"].as(); + + unsigned int count = 0; + + for (JsonPair i : result){ + const char *value = i.value().as().c_str(); + if (strcmp(value, "CYD_SCREEN_MACRO") == 0) { + count++; + } + } + + return count; } + else { + return 0; + } +} + +unsigned int macro_count() +{ + return macro_count(get_current_printer_config()); +} + +POWERQUERY power_devices_query(PRINTER_CONFIG * config) +{ + HTTPClient client; + configure_http_client(client, get_full_url("/machine/device_power/devices", config), true, 1000); + + int httpCode = client.GET(); if (httpCode == 200){ JsonDocument doc; deserializeJson(doc, client.getStream()); auto result = doc["result"]["devices"].as(); + for (int i = 0; i < stored_power_devices_count; i++){ + free(power_devices[i]); + } + + stored_power_devices_count = 0; + for (auto i : result){ const char * device_name = i["device"]; const char * device_state = i["status"]; - power_devices[power_devices_count] = (char*)malloc(strlen(device_name) + 1); - strcpy(power_devices[power_devices_count], device_name); - power_device_states[power_devices_count] = strcmp(device_state, "on") == 0; - power_devices_count++; + power_devices[stored_power_devices_count] = (char*)malloc(strlen(device_name) + 1); + strcpy(power_devices[stored_power_devices_count], device_name); + power_device_states[stored_power_devices_count] = strcmp(device_state, "on") == 0; + stored_power_devices_count++; } + + return {(const char**)power_devices, (const bool*)power_device_states, (unsigned int)stored_power_devices_count}; + } + else { + return {NULL, NULL, 0}; } } -static void on_state_change(void * s, lv_msg_t * m) { - if (printer.state == PRINTER_STATE_ERROR || printer.state == PRINTER_STATE_PAUSED){ - return; - } - - _macros_query_internal(); - _power_devices_query_internal(); +POWERQUERY power_devices_query() +{ + return power_devices_query(get_current_printer_config()); } -bool set_power_state(const char* device_name, bool state) { - SETUP_HTTP_CLIENT("/machine/device_power/device?device=" + urlEncode(device_name) + "&action=" + (state ? "on" : "off")); +unsigned int power_devices_count(PRINTER_CONFIG * config) +{ + HTTPClient client; + configure_http_client(client, get_full_url("/machine/device_power/devices", config), true, 1000); - if (client.POST("") != 200) - return false; + int httpCode = client.GET(); - for (int i = 0; i < power_devices_count; i++){ - if (strcmp(power_devices[i], device_name) == 0){ - power_device_states[i] = state; - return true; + if (httpCode == 200){ + JsonDocument doc; + deserializeJson(doc, client.getStream()); + auto result = doc["result"]["devices"].as(); + + unsigned int count = 0; + + for (auto i : result){ + count++; } + + return count; + } + else { + return 0; } - - return true; } -MACROSQUERY macros_query() { - return {(const char**)macros, (unsigned int)macros_count}; +unsigned int power_devices_count() +{ + return power_devices_count(get_current_printer_config()); } -POWERQUERY power_devices_query() { - return {(const char**)power_devices, (const bool*)power_device_states, (unsigned int)power_devices_count}; + + +bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config) +{ + HTTPClient client; + configure_http_client(client, get_full_url("/machine/device_power/device?device=" + urlEncode(device_name) + "&action=" + (state ? "on" : "off"), config), true, 1000); + + return client.POST("") == 200; } -void macros_query_setup(){ - lv_msg_subscribe(DATA_PRINTER_STATE, on_state_change, NULL); - on_state_change(NULL, NULL); +bool set_power_state(const char* device_name, bool state) +{ + return set_power_state(device_name, state, get_current_printer_config()); } \ No newline at end of file diff --git a/CYD-Klipper/src/core/macros_query.h b/CYD-Klipper/src/core/macros_query.h index 40788b4..13ae98a 100644 --- a/CYD-Klipper/src/core/macros_query.h +++ b/CYD-Klipper/src/core/macros_query.h @@ -1,5 +1,7 @@ #pragma once +#include "../conf/global_config.h" + typedef struct { const char** macros; uint32_t count; @@ -11,10 +13,13 @@ typedef struct { uint32_t count; } POWERQUERY; +MACROSQUERY macros_query(PRINTER_CONFIG * config); MACROSQUERY macros_query(); +unsigned int macro_count(PRINTER_CONFIG * config); +unsigned int macro_count(); +POWERQUERY power_devices_query(PRINTER_CONFIG * config); POWERQUERY power_devices_query(); -void macros_query_setup(); -bool set_power_state(const char* device_name, bool state); -void _power_devices_query_internal(); -void _macros_query_internal(); -void power_devices_clear(); \ No newline at end of file +unsigned int power_devices_count(PRINTER_CONFIG * config); +unsigned int power_devices_count(); +bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config); +bool set_power_state(const char* device_name, bool state); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index ac1644b..8c0ce2a 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -8,8 +8,10 @@ #include "panels/panel.h" #include "../core/http_client.h" #include "switch_printer.h" +#include "macros.h" bool connect_ok = false; +int prev_power_device_count = 0; lv_obj_t * hostEntry; lv_obj_t * portEntry; lv_obj_t * label = NULL; @@ -116,21 +118,7 @@ static void reset_btn_event_handler(lv_event_t * e){ } static void power_devices_button(lv_event_t * e) { - lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); - lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, 0); - lv_layout_flex_column(panel); - lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX); - lv_obj_align(panel, LV_ALIGN_TOP_LEFT, 0, CYD_SCREEN_GAP_PX); - - lv_obj_t * button = lv_btn_create(panel); - lv_obj_set_size(button, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(button, destroy_event_user_data, LV_EVENT_CLICKED, panel); - - lv_obj_t * label = lv_label_create(button); - lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); - lv_obj_center(label); - - macros_panel_add_power_devices_to_panel(panel, power_devices_query()); + macros_draw_power_fullscreen(); } void redraw_connect_screen(){ @@ -153,7 +141,7 @@ void redraw_connect_screen(){ lv_label_set_text(btn_label, "Reset"); lv_obj_center(btn_label); - if (power_devices_query().count >= 1){ + if (prev_power_device_count >= 1){ lv_obj_t * power_devices_btn = lv_btn_create(button_row); lv_obj_add_event_cb(power_devices_btn, power_devices_button, LV_EVENT_CLICKED, NULL); lv_obj_set_height(power_devices_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); @@ -292,7 +280,7 @@ int retry_count = 0; void ip_init(){ connect_ok = false; retry_count = 0; - int prev_power_device_count = 0; + prev_power_device_count = 0; ip_init_inner(); @@ -312,13 +300,12 @@ void ip_init(){ lv_label_set_text(label, retry_count_text.c_str()); } - if (status != CONNECT_AUTH_REQUIRED) - _power_devices_query_internal(); - else + if (status == CONNECT_AUTH_REQUIRED) handle_auth_entry(); - if (power_devices_query().count != prev_power_device_count) { - prev_power_device_count = power_devices_query().count; + unsigned int power_device_count = power_devices_count(); + if (power_device_count != prev_power_device_count) { + prev_power_device_count = power_device_count; redraw_connect_screen(); } } @@ -328,7 +315,6 @@ void ip_init(){ void ip_ok(){ if (klipper_request_consecutive_fail_count > 5){ freeze_request_thread(); - power_devices_clear(); ip_init(); unfreeze_request_thread(); klipper_request_consecutive_fail_count = 0; diff --git a/CYD-Klipper/src/ui/macros.cpp b/CYD-Klipper/src/ui/macros.cpp new file mode 100644 index 0000000..b5e9987 --- /dev/null +++ b/CYD-Klipper/src/ui/macros.cpp @@ -0,0 +1,75 @@ +#include "macros.h" +#include "ui_utils.h" +#include +#include "../core/data_setup.h" + +PRINTER_CONFIG * curernt_config = NULL; + +static void btn_press(lv_event_t * e){ + lv_obj_t * btn = lv_event_get_target(e); + const char* macro = (const char*)lv_event_get_user_data(e); + Serial.printf("Macro: %s\n", macro); + send_gcode(false, macro); +} + +void macros_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query) +{ + for (int i = 0; i < query.count; i++){ + const char* macro = query.macros[i]; + lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro); + } +} + +static void power_device_toggle(lv_event_t * e) +{ + auto state = lv_obj_get_state(lv_event_get_target(e)); + bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); + const char* power_device_name = (const char*)lv_event_get_user_data(e); + Serial.printf("Power Device: %s, State: %d -> %d\n", power_device_name, !checked, checked); + + if (curernt_config != NULL) + set_power_state(power_device_name, checked, curernt_config); +} + +void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query) +{ + for (int i = 0; i < query.count; i++){ + const char* power_device_name = query.power_devices[i]; + const bool power_device_state = query.power_states[i]; + lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name); + } +} + +void macros_draw_power_fullscreen(PRINTER_CONFIG * config) +{ + curernt_config = config; + + lv_obj_t * parent = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_style_bg_opa(parent, LV_OPA_100, 0); + lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0); + lv_obj_set_size(parent, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_layout_flex_column(parent); + + lv_obj_set_size(lv_create_empty_panel(parent), 0, 0); + + auto width = CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; + + lv_obj_t * btn = lv_btn_create(parent); + lv_obj_set_size(btn, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, parent); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); + lv_obj_center(label); + + MACROSQUERY query = macros_query(config); + POWERQUERY power = power_devices_query(config); + + macros_add_macros_to_panel(parent, query); + macros_add_power_devices_to_panel(parent, power); +} + +void macros_draw_power_fullscreen() +{ + macros_draw_power_fullscreen(get_current_printer_config()); +} \ No newline at end of file diff --git a/CYD-Klipper/src/ui/macros.h b/CYD-Klipper/src/ui/macros.h new file mode 100644 index 0000000..c5040be --- /dev/null +++ b/CYD-Klipper/src/ui/macros.h @@ -0,0 +1,9 @@ +#pragma once + +#include "lvgl.h" +#include "../core/macros_query.h" + +void macros_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query); +void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query); +void macros_draw_power_fullscreen(PRINTER_CONFIG * config); +void macros_draw_power_fullscreen(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index d02219d..3f3a77f 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -9,6 +9,7 @@ #include "../core/macros_query.h" #include "../core/lv_setup.h" #include "switch_printer.h" +#include "macros.h" char extruder_temp_buff[20]; char bed_temp_buff[20]; @@ -37,7 +38,7 @@ void error_ui_macros_open(lv_event_t * e){ lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); lv_obj_center(label); - macros_panel_add_power_devices_to_panel(panel, power_devices_query()); + macros_add_power_devices_to_panel(panel, power_devices_query()); } void error_ui(){ @@ -81,7 +82,7 @@ void error_ui(){ lv_label_set_text(label, "FW Restart"); lv_obj_center(label); - if (power_devices_query().count >= 1){ + if (power_devices_count() >= 1){ btn = lv_btn_create(button_row); lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_add_event_cb(btn, error_ui_macros_open, LV_EVENT_CLICKED, NULL); diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 0928252..ec4784c 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -1,49 +1,15 @@ -#include "lvgl.h" +#include "../macros.h" #include "panel.h" #include "../nav_buttons.h" #include "../../core/data_setup.h" -#include "../../core/macros_query.h" #include "../../conf/global_config.h" #include "../ui_utils.h" #include -const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2) * 0.85f), 0} }; - -static void btn_press(lv_event_t * e){ - lv_obj_t * btn = lv_event_get_target(e); - const char* macro = (const char*)lv_event_get_user_data(e); - Serial.printf("Macro: %s\n", macro); - send_gcode(false, macro); -} - static void btn_goto_settings(lv_event_t * e){ nav_buttons_setup(3); } -void macros_panel_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query){ - for (int i = 0; i < query.count; i++){ - const char* macro = query.macros[i]; - lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro); - } -} - -static void power_device_toggle(lv_event_t * e){ - auto state = lv_obj_get_state(lv_event_get_target(e)); - bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); - const char* power_device_name = (const char*)lv_event_get_user_data(e); - Serial.printf("Power Device: %s, State: %d -> %d\n", power_device_name, !checked, checked); - - set_power_state(power_device_name, checked); -} - -void macros_panel_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query){ - for (int i = 0; i < query.count; i++){ - const char* power_device_name = query.power_devices[i]; - const bool power_device_state = query.power_states[i]; - lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name); - } -} - void macros_panel_init(lv_obj_t* panel) { lv_obj_t * btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, btn_goto_settings, LV_EVENT_CLICKED, NULL); @@ -69,6 +35,6 @@ void macros_panel_init(lv_obj_t* panel) { 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); - macros_panel_add_power_devices_to_panel(root_panel, power); - macros_panel_add_macros_to_panel(root_panel, query); + macros_add_power_devices_to_panel(root_panel, power); + macros_add_macros_to_panel(root_panel, query); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/panel.h b/CYD-Klipper/src/ui/panels/panel.h index a18095c..a6c1aa8 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -10,5 +10,4 @@ void move_panel_init(lv_obj_t* panel); void progress_panel_init(lv_obj_t* panel); void macros_panel_init(lv_obj_t* panel); void stats_panel_init(lv_obj_t* panel); -void printer_panel_init(lv_obj_t* panel); -void macros_panel_add_power_devices_to_panel(lv_obj_t * panel, POWERQUERY query); \ No newline at end of file +void printer_panel_init(lv_obj_t* panel); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index 68148f5..427be34 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -7,6 +7,7 @@ #include "../nav_buttons.h" #include "../../core/macros_query.h" #include "../switch_printer.h" +#include "../macros.h" const char * printer_status[] = { "Error", @@ -83,34 +84,56 @@ static void update_printer_percentage_text(lv_event_t * e) } } -static void btn_disable_if_controlled(lv_event_t * e) +static void update_printer_control_button_text(lv_event_t * e) +{ + lv_obj_t * label = lv_event_get_target(e); + PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int index = config - global_config.printer_config; + PrinterMinimal * printer = &printer_minimal[index]; + + if (!printer->online && printer->power_devices > 0) + { + lv_label_set_text(label, "Power"); + } + else + { + lv_label_set_text(label, "Control"); + } +} + +static void btn_enable_delete(lv_event_t * e) { lv_obj_t * btn = lv_event_get_target(e); PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); if (config == get_current_printer_config()) { + // Disable lv_obj_add_state(btn, LV_STATE_DISABLED); } else { + // Enable lv_obj_clear_state(btn, LV_STATE_DISABLED); } } -static void btn_disable_if_controlled_or_offline(lv_event_t * e) +static void btn_enable_control(lv_event_t * e) { lv_obj_t * btn = lv_event_get_target(e); PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); int index = config - global_config.printer_config; PrinterMinimal * printer = &printer_minimal[index]; - if (config == get_current_printer_config() || !printer->online) + if (config == get_current_printer_config() || (!printer->online && printer->power_devices < 0)) { + // Disable lv_obj_add_state(btn, LV_STATE_DISABLED); + } - else + else { + // Enable lv_obj_clear_state(btn, LV_STATE_DISABLED); } } @@ -155,6 +178,13 @@ static void btn_printer_activate(lv_event_t * e) lv_obj_t * label = lv_event_get_target(e); PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); int index = config - global_config.printer_config; + PrinterMinimal * printer = &printer_minimal[index]; + + if (!printer->online) + { + macros_draw_power_fullscreen(config); + return; + } switch_printer(index); lv_msg_send(DATA_PRINTER_MINIMAL, NULL); @@ -203,7 +233,7 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_t * btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 1); lv_obj_add_event_cb(btn, btn_printer_delete, LV_EVENT_CLICKED, config); - lv_obj_add_event_cb(btn, btn_disable_if_controlled, LV_EVENT_MSG_RECEIVED, config); + lv_obj_add_event_cb(btn, btn_enable_delete, LV_EVENT_MSG_RECEIVED, config); lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); label = lv_label_create(btn); @@ -221,12 +251,13 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 2); lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config); - lv_obj_add_event_cb(btn, btn_disable_if_controlled_or_offline, LV_EVENT_MSG_RECEIVED, config); + lv_obj_add_event_cb(btn, btn_enable_control, LV_EVENT_MSG_RECEIVED, config); lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); label = lv_label_create(btn); - lv_label_set_text(label, "Control"); lv_obj_center(label); + lv_obj_add_event_cb(label, update_printer_control_button_text, LV_EVENT_MSG_RECEIVED, config); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); lv_obj_t * line = lv_line_create(root); lv_line_set_points(line, line_points, 2); diff --git a/CYD-Klipper/src/ui/switch_printer.cpp b/CYD-Klipper/src/ui/switch_printer.cpp index f344334..20a8982 100644 --- a/CYD-Klipper/src/ui/switch_printer.cpp +++ b/CYD-Klipper/src/ui/switch_printer.cpp @@ -12,8 +12,6 @@ void switch_printer(int index) set_printer_config_index(index); set_color_scheme(); set_invert_display(); - _macros_query_internal(); - _power_devices_query_internal(); } static void btn_switch_printer(lv_event_t *e){ From 65abe295c967e2c05e1ec1c27911892a3a932bed Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 12 Mar 2024 21:30:23 +0100 Subject: [PATCH 34/42] Fix button disable conditions --- CYD-Klipper/src/ui/panels/printer_panel.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index 427be34..bc2ef52 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -125,7 +125,7 @@ static void btn_enable_control(lv_event_t * e) int index = config - global_config.printer_config; PrinterMinimal * printer = &printer_minimal[index]; - if (config == get_current_printer_config() || (!printer->online && printer->power_devices < 0)) + if (config == get_current_printer_config() || (!printer->online && printer->power_devices <= 0)) { // Disable lv_obj_add_state(btn, LV_STATE_DISABLED); From d0d80e89806dd0f790238fd09843e5f1098ca93b Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:06:52 +0100 Subject: [PATCH 35/42] Imrpove site --- _site/index.html | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-) diff --git a/_site/index.html b/_site/index.html index 8ab571c..e262944 100644 --- a/_site/index.html +++ b/_site/index.html @@ -24,7 +24,11 @@ } .main a { - color: #F00; + color: #F44; + } + + .install { + margin-bottom: 300px; } .install .iconify { @@ -46,13 +50,22 @@ document.getElementById("changelog-header-version").innerText += data.tag_name; } + function setInstallButton(esp){ + document.getElementById("install-btn").innerHTML = ``; + } + + function setInstallButtonDefault(){ + setInstallButton("esp32-2432S028R") + } + fetchChangelog(); + window.onload = setInstallButtonDefault;
-

CYD-Klipper

+

CYD-Klipper

An implementation of a Klipper status display on an ESP32 + screen.
Uses Moonraker to fetch data.
Source code is available on GitHub.

@@ -64,18 +77,24 @@

Donate

If you found this project helpful, please consider a donation to my Ko-Fi.
It would help out a lot in the development of this project, due to the need to buy the screens.
Thank you!

- -
-

Install on ESP32-2432S028 (2.8" Resistive)

-

Note: You may need to hold the 'BOOT' button on the device while pressing install.

- + +
+

Report Issues

+

If you experience any issues with this project, or any feature requests for the project, please report them on the issues tab on Github.

+
-

Install on ESP32-3248S035 (3.5" Capacitive)

-

Note: You may need to hold the 'BOOT' button on the device while pressing install.

- +

Install

+

Select your device from the list below and click 'Connect'.
Note: You may need to hold the 'BOOT' button on the device while pressing install.
The 2.8" Resistive and 3.5" Capacitive models are best suited (in my opinion) for CYD-Klipper.

+ +
\ No newline at end of file From 36b37176d6d1cec9a52f8fc08dd1ebfebd0d7a9e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 13 Mar 2024 18:46:13 +0100 Subject: [PATCH 36/42] Fix macros tab controlling other printers --- CYD-Klipper/src/ui/macros.cpp | 7 ++++++- CYD-Klipper/src/ui/macros.h | 1 + CYD-Klipper/src/ui/panels/macros_panel.cpp | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CYD-Klipper/src/ui/macros.cpp b/CYD-Klipper/src/ui/macros.cpp index b5e9987..9e3ea34 100644 --- a/CYD-Klipper/src/ui/macros.cpp +++ b/CYD-Klipper/src/ui/macros.cpp @@ -40,9 +40,14 @@ void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query) } } -void macros_draw_power_fullscreen(PRINTER_CONFIG * config) +void macros_set_current_config(PRINTER_CONFIG * config) { curernt_config = config; +} + +void macros_draw_power_fullscreen(PRINTER_CONFIG * config) +{ + macros_set_current_config(config); lv_obj_t * parent = lv_create_empty_panel(lv_scr_act()); lv_obj_set_style_bg_opa(parent, LV_OPA_100, 0); diff --git a/CYD-Klipper/src/ui/macros.h b/CYD-Klipper/src/ui/macros.h index c5040be..0e6b690 100644 --- a/CYD-Klipper/src/ui/macros.h +++ b/CYD-Klipper/src/ui/macros.h @@ -5,5 +5,6 @@ void macros_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query); void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query); +void macros_set_current_config(PRINTER_CONFIG * config); void macros_draw_power_fullscreen(PRINTER_CONFIG * config); void macros_draw_power_fullscreen(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index ec4784c..6245f97 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -11,6 +11,8 @@ static void btn_goto_settings(lv_event_t * e){ } void macros_panel_init(lv_obj_t* panel) { + macros_set_current_config(get_current_printer_config()); + lv_obj_t * btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, btn_goto_settings, LV_EVENT_CLICKED, NULL); lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); From be3b2ddb2422718e0a4ec5c272a442ee95a0d4a0 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 13 Mar 2024 19:50:20 +0100 Subject: [PATCH 37/42] 3248S035C Vertical --- .../boards/esp32-3248S035C-vertical.json | 66 +++++++++++++++++++ CYD-Klipper/platformio.ini | 11 ++++ .../src/core/device/ESP32-3248S035C.cpp | 25 ++++--- CYD-Klipper/src/core/lv_setup.cpp | 2 +- CYD-Klipper/src/ui/panels/stats_panel.cpp | 3 +- CYD-Klipper/src/ui/panels/temp_panel.cpp | 61 +++++++++++------ _site/index.html | 1 + ci.py | 3 +- 8 files changed, 141 insertions(+), 31 deletions(-) create mode 100644 CYD-Klipper/boards/esp32-3248S035C-vertical.json diff --git a/CYD-Klipper/boards/esp32-3248S035C-vertical.json b/CYD-Klipper/boards/esp32-3248S035C-vertical.json new file mode 100644 index 0000000..bfa0cb2 --- /dev/null +++ b/CYD-Klipper/boards/esp32-3248S035C-vertical.json @@ -0,0 +1,66 @@ +{ + "build": { + "arduino": { + "ldscript": "esp32_out.ld" + }, + "core": "esp32", + "extra_flags": [ + "-DUSER_SETUP_LOADED=1", + "-DST7796_DRIVER=1", + "-DTFT_BL=27", + "-DTFT_BACKLIGHT_ON=HIGH", + "-DTFT_MISO=12", + "-DTFT_MOSI=13", + "-DTFT_SCLK=14", + "-DTFT_CS=15", + "-DTFT_DC=2", + "-DTFT_RST=-1", + "-DLOAD_GCLD=1", + "-DSPI_FREQUENCY=80000000", + "-DSPI_READ_FREQUENCY=20000000", + "-DSPI_TOUCH_FREQUENCY=2500000", + "-DTOUCH_CS=-1", + + "-DCYD_SCREEN_HEIGHT_PX=480", + "-DCYD_SCREEN_WIDTH_PX=320", + "-DCYD_SCREEN_GAP_PX=10", + "-DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=45", + "-DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=45", + "-DCYD_SCREEN_FONT=lv_font_montserrat_16", + "-DCYD_SCREEN_FONT_SMALL=lv_font_montserrat_12", + "-DCYD_SCREEN_SIDEBAR_SIZE_PX=50", + "-DCYD_SCREEN_DRIVER_ESP32_3248S035C=1", + "-DCYD_SCREEN_DISABLE_TOUCH_CALIBRATION=1", + "-DCYD_SCREEN_VERTICAL=1", + "-DCYD_SCREEN_NO_TEMP_SCROLL=1" + ], + "f_cpu": "240000000L", + "f_flash": "40000000L", + "flash_mode": "dio", + "mcu": "esp32", + "variant": "esp32" + }, + "connectivity": [ + "wifi", + "bluetooth", + "ethernet", + "can" + ], + "debug": { + "openocd_board": "esp-wroom-32.cfg" + }, + "frameworks": [ + "arduino", + "espidf" + ], + "name": "esp32-3248S035C-V", + "upload": { + "flash_size": "4MB", + "maximum_ram_size": 327680, + "maximum_size": 4194304, + "require_upload_port": true, + "speed": 460800 + }, + "url": "https://www.aliexpress.com/item/1005004632953455.html", + "vendor": "Sunton" + } \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index e1771b0..fbfd7f4 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -46,6 +46,17 @@ lib_deps = plageoj/UrlEncode@^1.0.1 erriez/ErriezCRC32 @ ^1.0.1 +[env:esp32-3248S035C-V] +board = esp32-3248S035C-vertical +lib_deps = + SPI + https://github.com/suchmememanyskill/lvgl + https://github.com/Bodmer/TFT_eSPI.git + https://github.com/OperatorB/gt911-arduino-fixed-reset.git + bblanchon/ArduinoJson@^7.0.0 + plageoj/UrlEncode@^1.0.1 + erriez/ErriezCRC32 @ ^1.0.1 + [env:esp32-2432S024C-SD] board = esp32-2432S024C-smartdisplay diff --git a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp index 22ea6d5..715b38f 100644 --- a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp +++ b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp @@ -1,10 +1,6 @@ #ifdef CYD_SCREEN_DRIVER_ESP32_3248S035C #include "../screen_driver.h" -#ifdef CYD_SCREEN_VERTICAL - #error "Vertical screen not supported with the ESP32_3248S035C driver" -#endif - #include "lvgl.h" #include #include @@ -107,14 +103,13 @@ void screen_setup() { // Initialize the touchscreen tp.begin(); - tp.setRotation(ROTATION_NORMAL); + // Initialize LVGL lv_init(); // Initialize the display tft.init(); ledcSetup(0, 5000, 12); ledcAttachPin(TFT_BL, 0); - tft.setRotation(global_config.rotate_screen ? 3 : 1); tft.fillScreen(TFT_BLACK); set_invert_display(); LED_init(); @@ -122,8 +117,22 @@ void screen_setup() lv_disp_draw_buf_init(&draw_buf, buf, NULL, TFT_WIDTH * TFT_HEIGHT / 10); static lv_disp_drv_t disp_drv; lv_disp_drv_init(&disp_drv); - disp_drv.hor_res = TFT_HEIGHT; - disp_drv.ver_res = TFT_WIDTH; + + + #ifdef CYD_SCREEN_VERTICAL + disp_drv.hor_res = TFT_WIDTH; + disp_drv.ver_res = TFT_HEIGHT; + tp.setRotation(2); + tft.setRotation(global_config.rotate_screen ? 2 : 0); + #else + disp_drv.hor_res = TFT_HEIGHT; + disp_drv.ver_res = TFT_WIDTH; + + tft.setRotation(global_config.rotate_screen ? 3 : 1); + tp.setRotation(ROTATION_NORMAL); + #endif + + disp_drv.flush_cb = screen_lv_flush; disp_drv.draw_buf = &draw_buf; lv_disp_drv_register(&disp_drv); diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index 6f446ca..0cbb26b 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -270,7 +270,7 @@ void lv_setup() #endif // CYD_SCREEN_DISABLE_TOUCH_CALIBRATION display_driver->driver->read_cb = lv_touch_intercept; - + screen_timer_setup(); screen_timer_start(); lv_png_init(); diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp index b55793b..e9d361b 100644 --- a/CYD-Klipper/src/ui/panels/stats_panel.cpp +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -225,13 +225,14 @@ void create_stat_text_block(lv_obj_t * root, const char* label, lv_event_cb_t va } void stats_panel_init(lv_obj_t* panel) { - auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 3; + auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 2; lv_obj_t * left_panel = lv_create_empty_panel(panel); lv_obj_set_size(left_panel, panel_width, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_layout_flex_column(left_panel); lv_obj_set_flex_align(left_panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); lv_obj_align(left_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + lv_obj_clear_flag(left_panel, LV_OBJ_FLAG_SCROLLABLE); create_stat_text_block(left_panel, "Position:", label_pos); diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index d9e7890..6b5d70c 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -225,20 +225,10 @@ static void set_bed_target_temp_chart(lv_event_t * e){ lv_chart_set_next_value(chart, series, printer.bed_target_temp); } -void temp_panel_init(lv_obj_t * panel){ +void create_charts(lv_obj_t * root) +{ const auto element_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; - root_panel = panel; - edit_mode = false; - - lv_obj_t * root_temp_panel = lv_create_empty_panel(panel); - lv_obj_set_size(root_temp_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); - lv_obj_align(root_temp_panel, LV_ALIGN_TOP_RIGHT, 0, 0); - lv_obj_set_style_pad_all(root_temp_panel, CYD_SCREEN_GAP_PX, 0); - lv_layout_flex_column(root_temp_panel); - lv_obj_set_flex_align(root_temp_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER); - lv_obj_set_scrollbar_mode(root_temp_panel, LV_SCROLLBAR_MODE_OFF); - - lv_obj_t * chart = lv_chart_create(root_temp_panel); + lv_obj_t * chart = lv_chart_create(root); lv_obj_set_size(chart, element_width - CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * 3); lv_chart_set_type(chart, LV_CHART_TYPE_LINE); lv_chart_set_point_count(chart, 120); @@ -261,16 +251,16 @@ void temp_panel_init(lv_obj_t * panel){ lv_obj_add_event_cb(chart, set_bed_temp_chart, LV_EVENT_MSG_RECEIVED, ser4); lv_obj_add_event_cb(chart, set_chart_range, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subscribe_obj(DATA_PRINTER_DATA, chart, NULL); +} - lv_obj_t * single_screen_panel = lv_create_empty_panel(root_temp_panel); - lv_obj_set_size(single_screen_panel, element_width, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2 - CYD_SCREEN_GAP_PX / 2); - lv_layout_flex_column(single_screen_panel); - +void create_temp_buttons(lv_obj_t * root, lv_obj_t * panel) +{ + const auto element_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; lv_obj_t * temp_rows[2] = {0}; lv_obj_t * button_temp_rows[2] = {0}; for (int tempIter = 0; tempIter < 2; tempIter++){ - temp_rows[tempIter] = lv_create_empty_panel(single_screen_panel); + temp_rows[tempIter] = lv_create_empty_panel(root); lv_layout_flex_column(temp_rows[tempIter]); lv_obj_set_size(temp_rows[tempIter], element_width, LV_SIZE_CONTENT); @@ -306,9 +296,40 @@ void temp_panel_init(lv_obj_t * panel){ lv_label_set_text(label, "Set"); lv_obj_center(label); } +} - lv_obj_t * gap = lv_create_empty_panel(single_screen_panel); - lv_obj_set_flex_grow(gap, 1); +void temp_panel_init(lv_obj_t * panel){ + const auto element_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; + root_panel = panel; + edit_mode = false; + + lv_obj_t * root_temp_panel = lv_create_empty_panel(panel); + lv_obj_set_size(root_temp_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); + lv_obj_align(root_temp_panel, LV_ALIGN_TOP_RIGHT, 0, 0); + lv_obj_set_style_pad_all(root_temp_panel, CYD_SCREEN_GAP_PX, 0); + lv_layout_flex_column(root_temp_panel); + lv_obj_set_flex_align(root_temp_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_CENTER); + lv_obj_set_scrollbar_mode(root_temp_panel, LV_SCROLLBAR_MODE_OFF); + + #ifndef CYD_SCREEN_NO_TEMP_SCROLL + create_charts(root_temp_panel); + + lv_obj_t * single_screen_panel = lv_create_empty_panel(root_temp_panel); + lv_obj_set_size(single_screen_panel, element_width, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2 - CYD_SCREEN_GAP_PX / 2); + lv_layout_flex_column(single_screen_panel); + #else + lv_obj_clear_flag(root_temp_panel, LV_OBJ_FLAG_SCROLLABLE); + lv_obj_t * single_screen_panel = root_temp_panel; + #endif + + create_temp_buttons(single_screen_panel, panel); + + #ifdef CYD_SCREEN_NO_TEMP_SCROLL + create_charts(single_screen_panel); + #else + lv_obj_t * gap = lv_create_empty_panel(single_screen_panel); + lv_obj_set_flex_grow(gap, 1); + #endif lv_obj_t * one_above_bottom_panel = lv_create_empty_panel(single_screen_panel); lv_obj_set_size(one_above_bottom_panel, element_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); diff --git a/_site/index.html b/_site/index.html index e262944..a82f39c 100644 --- a/_site/index.html +++ b/_site/index.html @@ -91,6 +91,7 @@ + diff --git a/ci.py b/ci.py index cf9b893..8ed1366 100644 --- a/ci.py +++ b/ci.py @@ -6,7 +6,8 @@ CYD_PORTS = [ "esp32-2432S032C-SD", "esp32-8048S043C-SD", "esp32-2432S024C-SD", - "esp32-4827S043C-SD" + "esp32-4827S043C-SD", + "esp32-3248S035C-V" ] BASE_DIR = os.getcwd() From a7bde994423be76173400f60ea0cb3828af35888 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 13 Mar 2024 20:20:57 +0100 Subject: [PATCH 38/42] Fix inverted vertical --- CYD-Klipper/src/core/device/ESP32-3248S035C.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp index 715b38f..75c39b7 100644 --- a/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp +++ b/CYD-Klipper/src/core/device/ESP32-3248S035C.cpp @@ -68,8 +68,14 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) } else { - magicY = TOUCH_WIDTH - tp.points[i].x; - magicX = tp.points[i].y; + #ifdef CYD_SCREEN_VERTICAL + // I don't even want to know why this works... + magicY = TOUCH_HEIGHT - tp.points[i].x; + magicX = tp.points[i].y - 160; + #else + magicY = TOUCH_WIDTH - tp.points[i].x; + magicX = tp.points[i].y; + #endif } data->point.x = magicX; From 1a31ef0758b43378d752d980c54df21bfd1a91f7 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:26:10 +0100 Subject: [PATCH 39/42] map error text in moonraker as error state --- CYD-Klipper/src/core/data_setup.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 73c3efc..36e0825 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -139,7 +139,7 @@ void fetch_printer_data() { printer_state = PRINTER_STATE_IDLE; } - else if (strcmp(state, "shutdown") == 0 && printer.state != PRINTER_STATE_ERROR) + else if ((strcmp(state, "shutdown") == 0 || strcmp(state, "error") == 0) && printer.state != PRINTER_STATE_ERROR) { printer_state = PRINTER_STATE_ERROR; } From 92d47d8c079dbb1e1050c63a1a67f3e28cfd22cd Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Wed, 13 Mar 2024 22:42:06 +0100 Subject: [PATCH 40/42] Move print preview image to the top left --- CYD-Klipper/src/ui/panels/print_panel.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index d869c53..5bf267d 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -33,11 +33,11 @@ static void btn_print_file_verify(lv_event_t * e){ lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 4, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 3); lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0); - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, "Print File"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 0, 0); + lv_obj_t * label_print_file = lv_label_create(panel); + lv_label_set_text(label_print_file, "Print File"); + lv_obj_align(label_print_file, LV_ALIGN_TOP_LEFT, 0, 0); - label = lv_label_create(panel); + lv_obj_t * label = lv_label_create(panel); lv_label_set_text(label, selected_file->name); lv_obj_align(label, LV_ALIGN_CENTER, 0, -20); lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 10); @@ -65,7 +65,14 @@ static void btn_print_file_verify(lv_event_t * e){ if (img != NULL){ lv_obj_set_parent(img, panel); - lv_obj_align(img, LV_ALIGN_BOTTOM_MID, 0, 0); + lv_obj_align(img, LV_ALIGN_TOP_LEFT, 0, 0); + + lv_obj_t * text_center_panel = lv_create_empty_panel(panel); + lv_obj_set_size(text_center_panel, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2, 32); + lv_obj_align(text_center_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX + 32, 0); + + lv_obj_set_parent(label_print_file, text_center_panel); + lv_obj_align(label_print_file, LV_ALIGN_LEFT_MID, 0, 0); } } From 9c958b42b337012b94d0d186ac9b02e1b07f42a1 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 14 Mar 2024 18:28:22 +0100 Subject: [PATCH 41/42] Fix macro panel in error screen --- CYD-Klipper/src/ui/macros.cpp | 3 --- CYD-Klipper/src/ui/main_ui.cpp | 16 +--------------- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/CYD-Klipper/src/ui/macros.cpp b/CYD-Klipper/src/ui/macros.cpp index 9e3ea34..4d70de2 100644 --- a/CYD-Klipper/src/ui/macros.cpp +++ b/CYD-Klipper/src/ui/macros.cpp @@ -67,10 +67,7 @@ void macros_draw_power_fullscreen(PRINTER_CONFIG * config) lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); lv_obj_center(label); - MACROSQUERY query = macros_query(config); POWERQUERY power = power_devices_query(config); - - macros_add_macros_to_panel(parent, query); macros_add_power_devices_to_panel(parent, power); } diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index 3f3a77f..8b33ae9 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -24,21 +24,7 @@ static void btn_click_firmware_restart(lv_event_t * e){ } void error_ui_macros_open(lv_event_t * e){ - lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); - lv_obj_set_style_bg_opa(panel, LV_OPA_COVER, 0); - lv_layout_flex_column(panel); - lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX); - lv_obj_align(panel, LV_ALIGN_TOP_LEFT, 0, CYD_SCREEN_GAP_PX); - - lv_obj_t * button = lv_btn_create(panel); - lv_obj_set_size(button, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(button, destroy_event_user_data, LV_EVENT_CLICKED, panel); - - lv_obj_t * label = lv_label_create(button); - lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); - lv_obj_center(label); - - macros_add_power_devices_to_panel(panel, power_devices_query()); + macros_draw_power_fullscreen(); } void error_ui(){ From 7aceb856210b4858eb51b7c5514d64ecab15be2e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 14 Mar 2024 19:00:57 +0100 Subject: [PATCH 42/42] Move error ui to panel --- CYD-Klipper/src/ui/main_ui.cpp | 75 +------------------- CYD-Klipper/src/ui/nav_buttons.cpp | 52 +++++++++----- CYD-Klipper/src/ui/nav_buttons.h | 11 +++ CYD-Klipper/src/ui/panels/error_panel.cpp | 53 ++++++++++++++ CYD-Klipper/src/ui/panels/macros_panel.cpp | 2 +- CYD-Klipper/src/ui/panels/move_panel.cpp | 2 +- CYD-Klipper/src/ui/panels/panel.h | 3 +- CYD-Klipper/src/ui/panels/printer_panel.cpp | 2 +- CYD-Klipper/src/ui/panels/settings_panel.cpp | 2 +- 9 files changed, 105 insertions(+), 97 deletions(-) create mode 100644 CYD-Klipper/src/ui/panels/error_panel.cpp diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index 8b33ae9..4ac8492 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -11,77 +11,6 @@ #include "switch_printer.h" #include "macros.h" -char extruder_temp_buff[20]; -char bed_temp_buff[20]; -char position_buff[20]; - -static void btn_click_restart(lv_event_t * e){ - send_gcode(false, "RESTART"); -} - -static void btn_click_firmware_restart(lv_event_t * e){ - send_gcode(false, "FIRMWARE_RESTART"); -} - -void error_ui_macros_open(lv_event_t * e){ - macros_draw_power_fullscreen(); -} - -void error_ui(){ - lv_obj_clean(lv_scr_act()); - - lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); - lv_layout_flex_column(panel); - lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); - lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); - lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); - - lv_obj_t * label; - label = lv_label_create(panel); - lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready"); - - label = lv_label_create(panel); - lv_label_set_text(label, printer.state_message); - lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); - lv_obj_clear_flag(label, LV_OBJ_FLAG_SCROLLABLE); - lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); - - lv_obj_t * button_row = lv_create_empty_panel(panel); - lv_obj_set_size(button_row, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_layout_flex_row(button_row); - - lv_obj_t * btn = lv_btn_create(button_row); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL); - lv_obj_set_flex_grow(btn, 1); - - label = lv_label_create(btn); - lv_label_set_text(label, "Restart"); - lv_obj_center(label); - - btn = lv_btn_create(button_row); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL); - lv_obj_set_flex_grow(btn, 1); - - label = lv_label_create(btn); - lv_label_set_text(label, "FW Restart"); - lv_obj_center(label); - - if (power_devices_count() >= 1){ - btn = lv_btn_create(button_row); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_add_event_cb(btn, error_ui_macros_open, LV_EVENT_CLICKED, NULL); - lv_obj_set_flex_grow(btn, 1); - - label = lv_label_create(btn); - lv_label_set_text(label, "Devices"); - lv_obj_center(label); - } - - draw_switch_printer_button(); -} - void check_if_screen_needs_to_be_disabled(){ if (global_config.on_during_print && printer.state == PRINTER_STATE_PRINTING){ screen_timer_wake(); @@ -96,10 +25,10 @@ static void on_state_change(void * s, lv_msg_t * m){ check_if_screen_needs_to_be_disabled(); if (printer.state == PRINTER_STATE_ERROR){ - error_ui(); + nav_buttons_setup(PANEL_ERROR); } else { - nav_buttons_setup(0); + nav_buttons_setup(PANEL_PRINT); } } diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index cf6a29f..aa2d0d2 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -58,27 +58,31 @@ static void update_printer_data_time(lv_event_t * e){ } static void btn_click_files(lv_event_t * e){ - nav_buttons_setup(0); + nav_buttons_setup(PANEL_PRINT); } static void btn_click_move(lv_event_t * e){ - nav_buttons_setup(1); + nav_buttons_setup(PANEL_MOVE); } static void btn_click_extrude(lv_event_t * e){ - nav_buttons_setup(2); + nav_buttons_setup(PANEL_TEMP); } static void btn_click_settings(lv_event_t * e){ - nav_buttons_setup(3); + nav_buttons_setup(PANEL_SETTINGS); } static void btn_click_macros(lv_event_t * e){ - nav_buttons_setup(4); + nav_buttons_setup(PANEL_MACROS); } static void btn_click_printer(lv_event_t * e){ - nav_buttons_setup(6); + nav_buttons_setup(PANEL_PRINTER); +} + +static void btn_click_err(lv_event_t * e){ + nav_buttons_setup(PANEL_ERROR); } void create_button(const char* icon, const char* name, lv_event_cb_t button_click, lv_event_cb_t label_update, lv_obj_t * root){ @@ -124,20 +128,27 @@ void nav_buttons_setup(unsigned char active_panel){ #endif - // Files/Print - create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); + if (printer.state != PRINTER_STATE_ERROR){ + // Files/Print + create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); - // Move - create_button(printer.state == PRINTER_STATE_PRINTING ? LV_SYMBOL_EDIT : LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel); + // Move + create_button(printer.state == PRINTER_STATE_PRINTING ? LV_SYMBOL_EDIT : LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel); - // Extrude/Temp - create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel); + // Extrude/Temp + create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel); + } + else { + // Error UI + create_button(LV_SYMBOL_WARNING, "Error", btn_click_err, NULL, root_panel); + } // Macros create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel); if (global_config.multi_printer_mode) { + // Printers create_button(LV_SYMBOL_HOME, "Printer", btn_click_printer, NULL, root_panel); } @@ -146,27 +157,30 @@ void nav_buttons_setup(unsigned char active_panel){ lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0); switch (active_panel){ - case 0: + case PANEL_PRINT: print_panel_init(panel); break; - case 1: + case PANEL_MOVE: move_panel_init(panel); break; - case 2: + case PANEL_TEMP: temp_panel_init(panel); break; - case 3: + case PANEL_SETTINGS: settings_panel_init(panel); break; - case 4: + case PANEL_MACROS: macros_panel_init(panel); break; - case 5: + case PANEL_STATS: stats_panel_init(panel); break; - case 6: + case PANEL_PRINTER: printer_panel_init(panel); break; + case PANEL_ERROR: + error_panel_init(panel); + break; } lv_msg_send(DATA_PRINTER_DATA, &printer); diff --git a/CYD-Klipper/src/ui/nav_buttons.h b/CYD-Klipper/src/ui/nav_buttons.h index 5ba07de..b1c6c10 100644 --- a/CYD-Klipper/src/ui/nav_buttons.h +++ b/CYD-Klipper/src/ui/nav_buttons.h @@ -1,2 +1,13 @@ +#pragma once + +#define PANEL_PRINT 0 +#define PANEL_MOVE 1 +#define PANEL_TEMP 2 +#define PANEL_SETTINGS 3 +#define PANEL_MACROS 4 +#define PANEL_STATS 5 +#define PANEL_PRINTER 6 +#define PANEL_ERROR 7 + void nav_buttons_setup(unsigned char active_panel); void nav_style_setup(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/error_panel.cpp b/CYD-Klipper/src/ui/panels/error_panel.cpp new file mode 100644 index 0000000..10a28ba --- /dev/null +++ b/CYD-Klipper/src/ui/panels/error_panel.cpp @@ -0,0 +1,53 @@ +#include "panel.h" +#include "../../core/data_setup.h" +#include "../ui_utils.h" + +static void btn_click_restart(lv_event_t * e){ + send_gcode(false, "RESTART"); +} + +static void btn_click_firmware_restart(lv_event_t * e){ + send_gcode(false, "FIRMWARE_RESTART"); +} + +void error_panel_init(lv_obj_t* panel) +{ + lv_layout_flex_column(panel, LV_FLEX_ALIGN_SPACE_BETWEEN); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); + + lv_obj_t * label; + label = lv_label_create(panel); + lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready"); + + lv_obj_t * panel_with_text = lv_create_empty_panel(panel); + lv_layout_flex_column(panel_with_text, LV_FLEX_ALIGN_START); + lv_obj_set_flex_grow(panel_with_text, 1); + lv_obj_set_width(panel_with_text, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); + + label = lv_label_create(panel_with_text); + lv_label_set_text(label, printer.state_message); + lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + + lv_obj_t * button_row = lv_create_empty_panel(panel); + lv_obj_set_size(button_row, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_layout_flex_row(button_row); + + lv_obj_t * btn = lv_btn_create(button_row); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL); + lv_obj_set_flex_grow(btn, 1); + + label = lv_label_create(btn); + lv_label_set_text(label, "Restart"); + lv_obj_center(label); + + btn = lv_btn_create(button_row); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL); + lv_obj_set_flex_grow(btn, 1); + + label = lv_label_create(btn); + lv_label_set_text(label, "FW Restart"); + lv_obj_center(label); +} \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 6245f97..295eaca 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -7,7 +7,7 @@ #include static void btn_goto_settings(lv_event_t * e){ - nav_buttons_setup(3); + nav_buttons_setup(PANEL_SETTINGS); } void macros_panel_init(lv_obj_t* panel) { diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 2ffc264..913339d 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -85,7 +85,7 @@ static void disable_steppers_click(lv_event_t * e) { static void switch_to_stat_panel(lv_event_t * e) { lv_obj_t * panel = lv_event_get_target(e); - nav_buttons_setup(5); + nav_buttons_setup(PANEL_STATS); } inline void root_panel_steppers_locked(lv_obj_t * root_panel){ diff --git a/CYD-Klipper/src/ui/panels/panel.h b/CYD-Klipper/src/ui/panels/panel.h index a6c1aa8..70223ad 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -10,4 +10,5 @@ void move_panel_init(lv_obj_t* panel); void progress_panel_init(lv_obj_t* panel); void macros_panel_init(lv_obj_t* panel); void stats_panel_init(lv_obj_t* panel); -void printer_panel_init(lv_obj_t* panel); \ No newline at end of file +void printer_panel_init(lv_obj_t* panel); +void error_panel_init(lv_obj_t* panel); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index bc2ef52..6e8dfd6 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -163,7 +163,7 @@ static void btn_printer_delete(lv_event_t * e) config->ip_configured = false; write_global_config(); - nav_buttons_setup(6); + nav_buttons_setup(PANEL_PRINTER); } // TODO: Extract this from temp/print panel and combine diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 12fdad9..ecc124d 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -111,7 +111,7 @@ static void multi_printer_switch(lv_event_t* e){ bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); global_config.multi_printer_mode = checked; write_global_config(); - nav_buttons_setup(3); + nav_buttons_setup(PANEL_SETTINGS); } const char* estimated_time_options = "Percentage\nInterpolated\nSlicer";