From 48520f652a2106f190da3dec3772d8072a4dd15e Mon Sep 17 00:00:00 2001 From: Sims <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 20 Nov 2023 15:57:40 +0100 Subject: [PATCH 01/45] Print wifi connect status while connecting, retry ip more times (#3) --- CYD-Klipper/src/ui/ip_setup.cpp | 4 ++-- CYD-Klipper/src/ui/wifi_setup.cpp | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index 33cc7c6..2acb3db 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -26,11 +26,11 @@ bool verify_ip(){ } bool retry_ip_verify(){ - for (int i = 0; i < 3; i++){ + for (int i = 0; i < 5; i++){ if (verify_ip()){ return true; } - delay(500); + delay(1000); } return false; diff --git a/CYD-Klipper/src/ui/wifi_setup.cpp b/CYD-Klipper/src/ui/wifi_setup.cpp index 49e19c7..a64f65d 100644 --- a/CYD-Klipper/src/ui/wifi_setup.cpp +++ b/CYD-Klipper/src/ui/wifi_setup.cpp @@ -147,11 +147,29 @@ void wifi_init_inner(){ } } +const char* errs[] = { + "Idle", + "No SSID Available", + "Scan Completed", + "Connected", + "Connection Failed", + "Connection Lost", + "Disconnected" +}; + +const int print_freq = 1000; +int print_timer = 0; + void wifi_init(){ WiFi.mode(WIFI_STA); wifi_init_inner(); while (!global_config.wifiConfigured || WiFi.status() != WL_CONNECTED){ + if (millis() - print_timer > print_freq){ + print_timer = millis(); + Serial.printf("WiFi Status: %s\n", errs[WiFi.status()]); + } + lv_timer_handler(); lv_task_handler(); } From e15c7e37ffa7def6d436e80daba7bde9b652fb5c Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 23 Nov 2023 12:31:32 +0100 Subject: [PATCH 02/45] update readme --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1dbe63d..d8a2d77 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Donations](https://img.shields.io/badge/Support%20on-Ko--Fi-red)](https://ko-fi.com/suchmememanyskill) # CYD-Klipper -An implementation of a Klipper status display on an ESP32 + screen. Uses Moonraker to fetch data. +An implementation of a wireless Klipper status display on an ESP32 + screen. Uses Moonraker to fetch data. A simple and cheap solution to use a dedicated screen with Klipper, a 3d printing Firmware. @@ -19,6 +19,7 @@ A ESP32-2432S028R is required to run this project. You can find out where to buy - Move the printer - Manage temperature - Extrude/Retract filament +- Execute predefined gcode macros ### Install From 1e3f0ab637b4d8c80b52bc442ba2368cc7273627 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Dec 2023 01:13:40 +0100 Subject: [PATCH 03/45] Lower CPU speed if screen is off --- CYD-Klipper/src/core/screen_driver.cpp | 8 ++++++++ CYD-Klipper/src/core/screen_driver.h | 3 +++ CYD-Klipper/src/main.cpp | 2 +- CYD-Klipper/src/ui/ip_setup.cpp | 2 +- CYD-Klipper/src/ui/ip_setup.h | 2 +- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/CYD-Klipper/src/core/screen_driver.cpp b/CYD-Klipper/src/core/screen_driver.cpp index 8b6adb7..ce6bfa8 100644 --- a/CYD-Klipper/src/core/screen_driver.cpp +++ b/CYD-Klipper/src/core/screen_driver.cpp @@ -100,12 +100,20 @@ void screen_timer_wake() lv_timer_reset(screenSleepTimer); isScreenInSleep = false; set_screen_brightness(); + + // Reset cpu freq + setCpuFrequencyMhz(CPU_FREQ_HIGH); + Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz()); } void screen_timer_sleep(lv_timer_t *timer) { screen_setBrightness(0); isScreenInSleep = true; + + // Screen is off, no need to make the cpu run fast, the user won't notice ;) + setCpuFrequencyMhz(CPU_FREQ_LOW); + Serial.printf("CPU Speed: %d MHz\n", ESP.getCpuFreqMHz()); } void screen_timer_setup() diff --git a/CYD-Klipper/src/core/screen_driver.h b/CYD-Klipper/src/core/screen_driver.h index 6b68fcd..90f808e 100644 --- a/CYD-Klipper/src/core/screen_driver.h +++ b/CYD-Klipper/src/core/screen_driver.h @@ -4,6 +4,9 @@ #ifndef _SCREEN_DRIVER_INIT #define _SCREEN_DRIVER_INIT +#define CPU_FREQ_HIGH 240 +#define CPU_FREQ_LOW 80 + #include #include diff --git a/CYD-Klipper/src/main.cpp b/CYD-Klipper/src/main.cpp index 89851ff..1e03eb6 100644 --- a/CYD-Klipper/src/main.cpp +++ b/CYD-Klipper/src/main.cpp @@ -25,7 +25,7 @@ void setup() { Serial.println("Screen init done"); wifi_init(); - ip_setup(); + ip_init(); data_setup(); nav_style_setup(); diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index 2acb3db..f57c259 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -95,7 +95,7 @@ void ip_setup_inner(){ lv_keyboard_set_textarea(keyboard, ipEntry); } -void ip_setup(){ +void ip_init(){ connect_ok = false; if (global_config.ipConfigured && retry_ip_verify()){ diff --git a/CYD-Klipper/src/ui/ip_setup.h b/CYD-Klipper/src/ui/ip_setup.h index 25ce25a..aa41ec1 100644 --- a/CYD-Klipper/src/ui/ip_setup.h +++ b/CYD-Klipper/src/ui/ip_setup.h @@ -1 +1 @@ -void ip_setup(); \ No newline at end of file +void ip_init(); \ No newline at end of file From f2d232d9eb29c18bb25543c76b7b54a9f7bae47c Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 2 Dec 2023 02:01:26 +0100 Subject: [PATCH 04/45] Add visual Klipper connect retry --- CYD-Klipper/src/ui/ip_setup.cpp | 62 +++++++++++++++++++++---------- CYD-Klipper/src/ui/wifi_setup.cpp | 5 +-- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index f57c259..65c8a9e 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -9,12 +9,15 @@ lv_obj_t * ipEntry; lv_obj_t * portEntry; lv_obj_t * label = NULL; +void ip_init_inner(); + bool verify_ip(){ HTTPClient client; String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/printer/info"; int httpCode; try { Serial.println(url); + client.setTimeout(500); client.begin(url.c_str()); httpCode = client.GET(); return httpCode == 200; @@ -25,17 +28,6 @@ bool verify_ip(){ } } -bool retry_ip_verify(){ - for (int i = 0; i < 5; i++){ - if (verify_ip()){ - return true; - } - delay(1000); - } - - return false; -} - static void ta_event_cb(lv_event_t * e) { lv_event_code_t code = lv_event_get_code(e); lv_obj_t * ta = lv_event_get_target(e); @@ -53,8 +45,8 @@ static void ta_event_cb(lv_event_t * e) { { strcpy(global_config.klipperHost, lv_textarea_get_text(ipEntry)); global_config.klipperPort = atoi(lv_textarea_get_text(portEntry)); - bool result = verify_ip(); - if (result) + + if (verify_ip()) { global_config.ipConfigured = true; WriteGlobalConfig(); @@ -67,9 +59,33 @@ static void ta_event_cb(lv_event_t * e) { } } -void ip_setup_inner(){ +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; + ip_init_inner(); + } +} + +void ip_init_inner(){ lv_obj_clean(lv_scr_act()); + if (global_config.ipConfigured) { + label = lv_label_create(lv_scr_act()); + lv_label_set_text(label, "Connecting to Klipper"); + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t * resetBtn = lv_btn_create(lv_scr_act()); + lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); + lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, 40); + + lv_obj_t * btnLabel = lv_label_create(resetBtn); + lv_label_set_text(btnLabel, "Reset"); + lv_obj_center(btnLabel); + return; + } + lv_obj_t * keyboard = lv_keyboard_create(lv_scr_act()); label = lv_label_create(lv_scr_act()); lv_label_set_text(label, "Enter Klipper IP and Port"); @@ -95,18 +111,26 @@ void ip_setup_inner(){ lv_keyboard_set_textarea(keyboard, ipEntry); } +long last_data_update_ip = -10000; +const long data_update_interval_ip = 10000; +int retry_count = 0; + void ip_init(){ connect_ok = false; - if (global_config.ipConfigured && retry_ip_verify()){ - return; - } - - ip_setup_inner(); + ip_init_inner(); while (!connect_ok) { lv_timer_handler(); lv_task_handler(); + + if (!connect_ok && global_config.ipConfigured && (millis() - last_data_update_ip) > data_update_interval_ip){ + connect_ok = verify_ip(); + last_data_update_ip = millis(); + retry_count++; + String retry_count_text = "Connecting to Klipper (Try " + String(retry_count + 1) + ")"; + lv_label_set_text(label, retry_count_text.c_str()); + } } } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/wifi_setup.cpp b/CYD-Klipper/src/ui/wifi_setup.cpp index a64f65d..c86c5fd 100644 --- a/CYD-Klipper/src/ui/wifi_setup.cpp +++ b/CYD-Klipper/src/ui/wifi_setup.cpp @@ -77,12 +77,11 @@ static void wifi_btn_event_handler(lv_event_t * e){ void wifi_init_inner(){ WiFi.disconnect(); + lv_obj_clean(lv_scr_act()); if (global_config.wifiConfigured){ WiFi.begin(global_config.wifiSSID, global_config.wifiPassword); - lv_obj_clean(lv_scr_act()); - lv_obj_t * label = lv_label_create(lv_scr_act()); lv_label_set_text(label, "Connecting to WiFi"); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); @@ -98,8 +97,6 @@ void wifi_init_inner(){ return; } - lv_obj_clean(lv_scr_act()); - lv_obj_t * label = lv_label_create(lv_scr_act()); lv_label_set_text(label, "Scanning for networks..."); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); From 7a430f81c58ae410356fa603def1aaee059ba873 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 11 Dec 2023 22:23:18 +0100 Subject: [PATCH 05/45] Change back to klipper connect screen when connection to klipper gets severed --- CYD-Klipper/src/core/data_setup.cpp | 6 ++++-- CYD-Klipper/src/core/data_setup.h | 1 + CYD-Klipper/src/main.cpp | 1 + CYD-Klipper/src/ui/ip_setup.cpp | 10 ++++++++++ CYD-Klipper/src/ui/ip_setup.h | 3 ++- 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 4d8927e..39ee59b 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -12,6 +12,7 @@ const char *printer_state_messages[] = { "Printing"}; Printer printer = {0}; +int klipper_request_consecutive_fail_count = 0; void send_gcode(bool wait, const char *gcode) { @@ -46,6 +47,7 @@ void fetch_printer_data() int httpCode = client.GET(); if (httpCode == 200) { + klipper_request_consecutive_fail_count = 0; String payload = client.getString(); DynamicJsonDocument doc(4096); deserializeJson(doc, payload); @@ -159,6 +161,7 @@ void fetch_printer_data() } else { + klipper_request_consecutive_fail_count++; Serial.printf("Failed to fetch printer data: %d\n", httpCode); } } @@ -171,9 +174,8 @@ void data_loop() if (millis() - last_data_update < data_update_interval) return; - last_data_update = millis(); - fetch_printer_data(); + last_data_update = millis(); } void data_setup() diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index 4e08ab5..3b2a151 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -28,6 +28,7 @@ typedef struct _Printer { } Printer; extern Printer printer; +extern int klipper_request_consecutive_fail_count; #define DATA_PRINTER_STATE 1 #define DATA_PRINTER_DATA 2 diff --git a/CYD-Klipper/src/main.cpp b/CYD-Klipper/src/main.cpp index 1e03eb6..a517416 100644 --- a/CYD-Klipper/src/main.cpp +++ b/CYD-Klipper/src/main.cpp @@ -34,6 +34,7 @@ void setup() { void loop(){ wifi_ok(); + ip_ok(); data_loop(); lv_timer_handler(); lv_task_handler(); diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index 65c8a9e..04f6d9d 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -3,6 +3,7 @@ #include "lvgl.h" #include #include +#include "core/data_setup.h" bool connect_ok = false; lv_obj_t * ipEntry; @@ -117,6 +118,7 @@ int retry_count = 0; void ip_init(){ connect_ok = false; + retry_count = 0; ip_init_inner(); @@ -133,4 +135,12 @@ void ip_init(){ lv_label_set_text(label, retry_count_text.c_str()); } } +} + +void ip_ok(){ + if (klipper_request_consecutive_fail_count > 5){ + ip_init(); + klipper_request_consecutive_fail_count = 0; + lv_msg_send(DATA_PRINTER_STATE, &printer); + } } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/ip_setup.h b/CYD-Klipper/src/ui/ip_setup.h index aa41ec1..a9d7ece 100644 --- a/CYD-Klipper/src/ui/ip_setup.h +++ b/CYD-Klipper/src/ui/ip_setup.h @@ -1 +1,2 @@ -void ip_init(); \ No newline at end of file +void ip_init(); +void ip_ok(); \ No newline at end of file From 34c6a5e03143b92d9d445f363b741b24bbd3d96b Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 15 Dec 2023 19:22:48 +0100 Subject: [PATCH 06/45] Offload API request loop to core 0 --- CYD-Klipper/src/core/data_setup.cpp | 68 ++++++++++++++++++++++++---- CYD-Klipper/src/core/data_setup.h | 5 +- CYD-Klipper/src/core/files_query.cpp | 4 ++ CYD-Klipper/src/ui/ip_setup.cpp | 2 + 4 files changed, 68 insertions(+), 11 deletions(-) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 39ee59b..f89e29c 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -13,6 +13,33 @@ const char *printer_state_messages[] = { Printer printer = {0}; int klipper_request_consecutive_fail_count = 0; +char filename_buff[512] = {0}; +SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore; +long last_data_update = 0; +const long data_update_interval = 800; + +void semaphore_init(){ + freezeRenderThreadSemaphore = xSemaphoreCreateMutex(); + freezeRequestThreadSemaphore = xSemaphoreCreateMutex(); + xSemaphoreGive(freezeRenderThreadSemaphore); + xSemaphoreGive(freezeRequestThreadSemaphore); +} + +void freeze_request_thread(){ + xSemaphoreTake(freezeRequestThreadSemaphore, portMAX_DELAY); +} + +void unfreeze_request_thread(){ + xSemaphoreGive(freezeRequestThreadSemaphore); +} + +void freeze_render_thread(){ + xSemaphoreTake(freezeRenderThreadSemaphore, portMAX_DELAY); +} + +void unfreeze_render_thread(){ + xSemaphoreGive(freezeRenderThreadSemaphore); +} void send_gcode(bool wait, const char *gcode) { @@ -36,10 +63,10 @@ void send_gcode(bool wait, const char *gcode) } } -char filename_buff[512] = {0}; - void fetch_printer_data() { + bool frozen = true; + 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", global_config.klipperHost, global_config.klipperPort); HTTPClient client; @@ -55,6 +82,10 @@ void fetch_printer_data() bool emit_state_update = false; int printer_state = printer.state; + unfreeze_request_thread(); + frozen = false; + freeze_render_thread(); + if (status.containsKey("webhooks")) { const char *state = status["webhooks"]["state"]; @@ -164,23 +195,40 @@ void fetch_printer_data() klipper_request_consecutive_fail_count++; Serial.printf("Failed to fetch printer data: %d\n", httpCode); } -} -long last_data_update = 0; -const long data_update_interval = 1500; + if (frozen) + unfreeze_request_thread(); + + unfreeze_render_thread(); +} void data_loop() { - if (millis() - last_data_update < data_update_interval) - return; + // Causes other threads that are trying to lock the thread to actually lock it + unfreeze_render_thread(); + delay(1); + freeze_render_thread(); +} - fetch_printer_data(); - last_data_update = millis(); +void data_loop_background(void * param){ + while (true){ + delay(100); + if (millis() - last_data_update < data_update_interval) + continue; + + fetch_printer_data(); + last_data_update = millis(); + } } +TaskHandle_t background_loop; + void data_setup() { + semaphore_init(); printer.print_filename = filename_buff; fetch_printer_data(); macros_query_setup(); -} \ No newline at end of file + freeze_render_thread(); + xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 1, &background_loop, 0); +} diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index 3b2a151..fc0a44f 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -36,4 +36,7 @@ extern int klipper_request_consecutive_fail_count; void data_loop(); void data_setup(); -void send_gcode(bool wait, const char* gcode); \ No newline at end of file +void send_gcode(bool wait, const char* gcode); + +void freeze_request_thread(); +void unfreeze_request_thread(); \ No newline at end of file diff --git a/CYD-Klipper/src/core/files_query.cpp b/CYD-Klipper/src/core/files_query.cpp index 28abbb5..d6ebb42 100644 --- a/CYD-Klipper/src/core/files_query.cpp +++ b/CYD-Klipper/src/core/files_query.cpp @@ -1,6 +1,7 @@ #include #include "files_query.h" #include "../conf/global_config.h" +#include "data_setup.h" #include #include #include @@ -9,6 +10,8 @@ FILESYSTEM_FILE* last_query = NULL; FILESYSTEM_FILE* get_files(){ + freeze_request_thread(); + if (last_query != NULL){ FILESYSTEM_FILE* current = last_query; @@ -59,5 +62,6 @@ FILESYSTEM_FILE* get_files(){ result += 1; } + unfreeze_request_thread(); return last_query; } \ 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 04f6d9d..deb6fda 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -139,7 +139,9 @@ void ip_init(){ void ip_ok(){ if (klipper_request_consecutive_fail_count > 5){ + freeze_request_thread(); ip_init(); + unfreeze_request_thread(); klipper_request_consecutive_fail_count = 0; lv_msg_send(DATA_PRINTER_STATE, &printer); } From 7c786d1e6b76cc6cb8a1b200b8e52c2af428654a Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 15 Dec 2023 19:24:55 +0100 Subject: [PATCH 07/45] Don't continously call unfreeze_render_thread() --- CYD-Klipper/src/core/data_setup.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index f89e29c..82d32f8 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -189,6 +189,8 @@ void fetch_printer_data() printer.state = printer_state; lv_msg_send(DATA_PRINTER_STATE, &printer); } + + unfreeze_render_thread(); } else { @@ -198,8 +200,6 @@ void fetch_printer_data() if (frozen) unfreeze_request_thread(); - - unfreeze_render_thread(); } void data_loop() From 53441c86c42edfd10b0734b6a2113263bf61f9cb Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 5 Jan 2024 23:20:47 +0100 Subject: [PATCH 08/45] Add kofi to site --- _site/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/_site/index.html b/_site/index.html index 67118a8..aeecc14 100644 --- a/_site/index.html +++ b/_site/index.html @@ -22,6 +22,7 @@

CYD-Klipper

An implementation of a Klipper status display on an ESP32 + screen.
Uses Moonraker to fetch data.

GitHub release (with filter) GitHub repo + Donate KoFi

Install

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

From 91920a679ad7d04541f7b9e1ac12cb3327a1cb09 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 6 Jan 2024 19:59:13 +0100 Subject: [PATCH 09/45] Fix #10 --- CYD-Klipper/platformio.ini | 3 ++- CYD-Klipper/src/core/data_setup.cpp | 6 +++--- CYD-Klipper/src/core/files_query.cpp | 15 ++++++++++----- CYD-Klipper/src/core/macros_query.cpp | 6 +++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index e756d90..c04f71d 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -18,7 +18,8 @@ lib_deps = lvgl/lvgl@^8.3.9 https://github.com/Bodmer/TFT_eSPI.git https://github.com/PaulStoffregen/XPT2046_Touchscreen.git - bblanchon/ArduinoJson@^6.21.3 + bblanchon/ArduinoJson@^7.0.0 +monitor_filters = esp32_exception_decoder build_flags = -DLV_CONF_PATH="../../../../src/conf/lv_conf.h" -DUSER_SETUP_LOADED=1 diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 82d32f8..28ba10c 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -70,14 +70,14 @@ void fetch_printer_data() char buff[256] = {}; sprintf(buff, "http://%s:%d/printer/objects/query?extruder&heater_bed&toolhead&gcode_move&virtual_sdcard&print_stats&webhooks", global_config.klipperHost, global_config.klipperPort); HTTPClient client; + client.useHTTP10(true); client.begin(buff); int httpCode = client.GET(); if (httpCode == 200) { klipper_request_consecutive_fail_count = 0; - String payload = client.getString(); - DynamicJsonDocument doc(4096); - deserializeJson(doc, payload); + JsonDocument doc; + deserializeJson(doc, client.getStream()); auto status = doc["result"]["status"]; bool emit_state_update = false; int printer_state = printer.state; diff --git a/CYD-Klipper/src/core/files_query.cpp b/CYD-Klipper/src/core/files_query.cpp index d6ebb42..fec496c 100644 --- a/CYD-Klipper/src/core/files_query.cpp +++ b/CYD-Klipper/src/core/files_query.cpp @@ -22,24 +22,28 @@ FILESYSTEM_FILE* get_files(){ free(last_query); } - + Serial.printf("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size()); std::list files; char buff[256] = {}; sprintf(buff, "http://%s:%d/server/files/list", global_config.klipperHost, global_config.klipperPort); HTTPClient client; + client.useHTTP10(true); client.begin(buff); int httpCode = client.GET(); int count = 0; if (httpCode == 200){ - String payload = client.getString(); - DynamicJsonDocument doc(60000); - auto a = deserializeJson(doc, payload); - Serial.printf("JSON PARSE: %s\n", a.c_str()); + JsonDocument doc; + auto parseResult = deserializeJson(doc, client.getStream()); + Serial.printf("Json parse: %s\n", parseResult.c_str()); auto result = doc["result"].as(); for (auto file : result){ FILESYSTEM_FILE f = {0}; const char* path = file["path"]; f.name = (char*)malloc(strlen(path) + 1); + if (f.name == NULL){ + Serial.println("Failed to allocate memory"); + continue; + } strcpy(f.name, path); f.modified = file["modified"]; files.push_back(f); @@ -62,6 +66,7 @@ FILESYSTEM_FILE* get_files(){ result += 1; } + Serial.printf("Heap space post-file-parse: %d bytes\n", esp_get_free_heap_size()); unfreeze_request_thread(); return last_query; } \ 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 11ddef3..909f4fc 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -15,12 +15,12 @@ static void on_state_change(void * s, lv_msg_t * m) { String url = "http://" + String(global_config.klipperHost) + ":" + String(global_config.klipperPort) + "/printer/gcode/help"; HTTPClient client; + client.useHTTP10(true); client.begin(url.c_str()); int httpCode = client.GET(); if (httpCode == 200){ - String payload = client.getString(); - DynamicJsonDocument doc(16384); - deserializeJson(doc, payload); + JsonDocument doc; + deserializeJson(doc, client.getStream()); auto result = doc["result"].as(); for (int i = 0; i < macros_count; i++){ From a7acd49d603ecdf0f9ba7adea259edec8e04f371 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 6 Jan 2024 20:40:37 +0100 Subject: [PATCH 10/45] Make all colors somewhat worth using --- CYD-Klipper/src/conf/global_config.cpp | 14 +++++++------- CYD-Klipper/src/conf/global_config.h | 4 ++++ CYD-Klipper/src/core/screen_driver.cpp | 15 ++++++++++++++- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/CYD-Klipper/src/conf/global_config.cpp b/CYD-Klipper/src/conf/global_config.cpp index 978e1b9..7e86626 100644 --- a/CYD-Klipper/src/conf/global_config.cpp +++ b/CYD-Klipper/src/conf/global_config.cpp @@ -5,13 +5,13 @@ GLOBAL_CONFIG global_config = {0}; COLOR_DEF color_defs[] = { - {LV_PALETTE_BLUE, LV_PALETTE_RED}, - {LV_PALETTE_GREEN, LV_PALETTE_PURPLE}, - {LV_PALETTE_GREY, LV_PALETTE_CYAN}, - {LV_PALETTE_YELLOW, LV_PALETTE_PINK}, - {LV_PALETTE_ORANGE, LV_PALETTE_BLUE}, - {LV_PALETTE_RED, LV_PALETTE_GREEN}, - {LV_PALETTE_PURPLE, LV_PALETTE_GREY}, + {LV_PALETTE_BLUE, 0, LV_PALETTE_RED}, + {LV_PALETTE_LIME, -2, LV_PALETTE_PURPLE}, + {LV_PALETTE_GREY, 0, LV_PALETTE_CYAN}, + {LV_PALETTE_YELLOW, -2, LV_PALETTE_PINK}, + {LV_PALETTE_ORANGE, -2, LV_PALETTE_BLUE}, + {LV_PALETTE_RED, 0, LV_PALETTE_GREEN}, + {LV_PALETTE_PURPLE, 0, LV_PALETTE_GREY}, }; void WriteGlobalConfig() { diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index 975315a..922b14e 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -10,9 +10,12 @@ typedef struct _GLOBAL_CONFIG { union { unsigned char raw; struct { + // Internal bool screenCalibrated : 1; bool wifiConfigured : 1; bool ipConfigured : 1; + + // External bool lightMode : 1; bool invertColors : 1; bool rotateScreen : 1; @@ -40,6 +43,7 @@ typedef struct _GLOBAL_CONFIG { typedef struct _COLOR_DEF { lv_palette_t primary_color; + short primary_color_light; lv_palette_t secondary_color; } COLOR_DEF; diff --git a/CYD-Klipper/src/core/screen_driver.cpp b/CYD-Klipper/src/core/screen_driver.cpp index ce6bfa8..e419ab5 100644 --- a/CYD-Klipper/src/core/screen_driver.cpp +++ b/CYD-Klipper/src/core/screen_driver.cpp @@ -183,7 +183,20 @@ void screen_lv_touchRead(lv_indev_drv_t *indev_driver, lv_indev_data_t *data) void set_color_scheme(){ lv_disp_t *dispp = lv_disp_get_default(); - lv_theme_t *theme = lv_theme_default_init(dispp, lv_palette_main(color_defs[global_config.color_scheme].primary_color), lv_palette_main(color_defs[global_config.color_scheme].secondary_color), !global_config.lightMode, LV_FONT_DEFAULT); + lv_color_t main_color = {0}; + COLOR_DEF color_def = color_defs[global_config.color_scheme]; + + if (color_defs[global_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) { + 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); + } + + lv_theme_t *theme = lv_theme_default_init(dispp, main_color, lv_palette_main(color_def.secondary_color), !global_config.lightMode, LV_FONT_DEFAULT); lv_disp_set_theme(dispp, theme); } From 48466cfb4401c268ae58afb09f5853b3d1dbf2bf Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:07:19 +0100 Subject: [PATCH 11/45] Lower data fetch task priority --- CYD-Klipper/src/core/data_setup.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 28ba10c..6241f60 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -15,7 +15,6 @@ Printer printer = {0}; int klipper_request_consecutive_fail_count = 0; char filename_buff[512] = {0}; SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore; -long last_data_update = 0; const long data_update_interval = 800; void semaphore_init(){ @@ -212,12 +211,8 @@ void data_loop() void data_loop_background(void * param){ while (true){ - delay(100); - if (millis() - last_data_update < data_update_interval) - continue; - + delay(data_update_interval); fetch_printer_data(); - last_data_update = millis(); } } @@ -230,5 +225,5 @@ void data_setup() fetch_printer_data(); macros_query_setup(); freeze_render_thread(); - xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 1, &background_loop, 0); + xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 0, &background_loop, 0); } From 50f4984231eba200feaf2279fc5cc7613b5a6e79 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 7 Jan 2024 21:07:35 +0100 Subject: [PATCH 12/45] Insert sort the fetched files, discard any extras --- CYD-Klipper/src/core/files_query.cpp | 56 +++++++++++++++++++---- CYD-Klipper/src/core/files_query.h | 2 +- CYD-Klipper/src/ui/panels/print_panel.cpp | 11 ++++- 3 files changed, 56 insertions(+), 13 deletions(-) diff --git a/CYD-Klipper/src/core/files_query.cpp b/CYD-Klipper/src/core/files_query.cpp index fec496c..85acfa1 100644 --- a/CYD-Klipper/src/core/files_query.cpp +++ b/CYD-Klipper/src/core/files_query.cpp @@ -9,7 +9,7 @@ // Always has +1 entry with a null'd name FILESYSTEM_FILE* last_query = NULL; -FILESYSTEM_FILE* get_files(){ +FILESYSTEM_FILE* get_files(int limit){ freeze_request_thread(); if (last_query != NULL){ @@ -22,42 +22,77 @@ FILESYSTEM_FILE* get_files(){ free(last_query); } + Serial.printf("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size()); 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.begin(buff); int httpCode = client.GET(); - int count = 0; + auto timer_parse = millis(); + if (httpCode == 200){ JsonDocument doc; auto parseResult = deserializeJson(doc, client.getStream()); Serial.printf("Json parse: %s\n", parseResult.c_str()); auto result = doc["result"].as(); + for (auto file : result){ FILESYSTEM_FILE f = {0}; const char* path = file["path"]; + float modified = file["modified"]; + auto file_iter = files.begin(); + + while (file_iter != files.end()){ + if ((*file_iter).modified < modified) + break; + + file_iter++; + } + + // Little inefficient as it always allocates a string, even if it doesn't have to f.name = (char*)malloc(strlen(path) + 1); if (f.name == NULL){ Serial.println("Failed to allocate memory"); continue; } strcpy(f.name, path); - f.modified = file["modified"]; - files.push_back(f); - count++; + f.modified = modified; + + if (file_iter != files.end()) + files.insert(file_iter, f); + else + files.push_back(f); + + if (files.size() > limit){ + auto last_entry = files.back(); + + if (last_entry.name != NULL) + free(last_entry.name); + + files.pop_back(); + } } } - //Serial.printf("Found %d files\n", count); - files.sort([](FILESYSTEM_FILE a, FILESYSTEM_FILE b){return a.modified < b.modified;}); - files.reverse(); // TODO: Reverse is unneeded here, we can iterate backwards - size_t size = sizeof(FILESYSTEM_FILE) * (files.size() + 1); FILESYSTEM_FILE* result = (FILESYSTEM_FILE*)malloc(size); - //Serial.printf("Allocated %d bytes\n", size); + + if (result == NULL){ + Serial.println("Failed to allocate memory"); + + for (auto file : files){ + free(file.name); + } + + unfreeze_request_thread(); + return NULL; + } + last_query = result; result[files.size()].name = NULL; @@ -67,6 +102,7 @@ FILESYSTEM_FILE* get_files(){ } Serial.printf("Heap space post-file-parse: %d bytes\n", esp_get_free_heap_size()); + Serial.printf("Got %d files. Request took %dms, parsing took %dms\n", files.size(), timer_parse - timer_request, millis() - timer_parse); unfreeze_request_thread(); return last_query; } \ No newline at end of file diff --git a/CYD-Klipper/src/core/files_query.h b/CYD-Klipper/src/core/files_query.h index a5c6cbc..efb8b12 100644 --- a/CYD-Klipper/src/core/files_query.h +++ b/CYD-Klipper/src/core/files_query.h @@ -19,4 +19,4 @@ typedef struct _FILESYSTEM_FILE { float modified; } FILESYSTEM_FILE; -FILESYSTEM_FILE* get_files(); \ No newline at end of file +FILESYSTEM_FILE* get_files(int limit); \ 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 a44d9b6..e0a1cd6 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -95,13 +95,20 @@ void print_panel_init(lv_obj_t* panel){ lv_obj_set_size(list, panel_width_margin, panel_height_margin); lv_obj_align(list, LV_ALIGN_CENTER, 0, 0); - FILESYSTEM_FILE* files = get_files(); + FILESYSTEM_FILE* files = get_files(25); int count = 0; - while (files->name != NULL && count <= 20){ + while (files != NULL && files->name != NULL && count <= 20){ lv_obj_t * btn = lv_list_add_btn(list, LV_SYMBOL_FILE, files->name); lv_obj_add_event_cb(btn, btn_print_file_verify, LV_EVENT_CLICKED, (void*)files); files += 1; count++; } + + if (count <= 0){ + lv_obj_del(list); + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, "Failed to read files."); + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); + } } \ No newline at end of file From 9136f4c94bdb0f8fdb9f164a160f5d9f85c51c81 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:33:01 +0100 Subject: [PATCH 13/45] Add some delay within data loop to give other processes on the core time to process --- CYD-Klipper/src/core/data_setup.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 6241f60..49713aa 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -15,7 +15,7 @@ Printer printer = {0}; int klipper_request_consecutive_fail_count = 0; char filename_buff[512] = {0}; SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore; -const long data_update_interval = 800; +const long data_update_interval = 780; void semaphore_init(){ freezeRenderThreadSemaphore = xSemaphoreCreateMutex(); @@ -72,6 +72,7 @@ void fetch_printer_data() client.useHTTP10(true); client.begin(buff); int httpCode = client.GET(); + delay(10); if (httpCode == 200) { klipper_request_consecutive_fail_count = 0; @@ -80,7 +81,7 @@ void fetch_printer_data() auto status = doc["result"]["status"]; bool emit_state_update = false; int printer_state = printer.state; - + delay(10); unfreeze_request_thread(); frozen = false; freeze_render_thread(); From 082d66ca109fd76fcc0ace481b335778bc0b8199 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 19 Jan 2024 21:05:57 +0100 Subject: [PATCH 14/45] Longer watchdog timeout, refactor, use duty cycle for backlight --- CYD-Klipper/src/core/data_setup.cpp | 8 +++----- CYD-Klipper/src/core/screen_driver.cpp | 10 +++++++++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 49713aa..b02b986 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -4,6 +4,7 @@ #include "../conf/global_config.h" #include #include +#include #include "macros_query.h" const char *printer_state_messages[] = { @@ -64,7 +65,6 @@ void send_gcode(bool wait, const char *gcode) void fetch_printer_data() { - bool frozen = true; 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", global_config.klipperHost, global_config.klipperPort); @@ -83,7 +83,6 @@ void fetch_printer_data() int printer_state = printer.state; delay(10); unfreeze_request_thread(); - frozen = false; freeze_render_thread(); if (status.containsKey("webhooks")) @@ -196,10 +195,8 @@ void fetch_printer_data() { klipper_request_consecutive_fail_count++; Serial.printf("Failed to fetch printer data: %d\n", httpCode); - } - - if (frozen) unfreeze_request_thread(); + } } void data_loop() @@ -211,6 +208,7 @@ void data_loop() } void data_loop_background(void * param){ + esp_task_wdt_init(10, true); while (true){ delay(data_update_interval); fetch_printer_data(); diff --git a/CYD-Klipper/src/core/screen_driver.cpp b/CYD-Klipper/src/core/screen_driver.cpp index e419ab5..ae06f78 100644 --- a/CYD-Klipper/src/core/screen_driver.cpp +++ b/CYD-Klipper/src/core/screen_driver.cpp @@ -84,7 +84,11 @@ void touchscreen_calibrate(bool force) void screen_setBrightness(byte brightness) { - analogWrite(TFT_BL, brightness); + // calculate duty, 4095 from 2 ^ 12 - 1 + uint32_t duty = (4095 / 255) * brightness; + + // write duty to LEDC + ledcWrite(0, duty); } void set_screen_brightness() @@ -213,6 +217,10 @@ void screen_setup() lv_init(); tft.init(); + + ledcSetup(0, 5000, 12); + ledcAttachPin(21, 0); + tft.setRotation(global_config.rotateScreen ? 3 : 1); tft.fillScreen(TFT_BLACK); set_screen_brightness(); From dd20c11d8beaff5235ff1d8d68d66666c559abe5 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 23 Jan 2024 20:07:06 +0100 Subject: [PATCH 15/45] Slightly optimise file reader --- CYD-Klipper/src/core/files_query.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CYD-Klipper/src/core/files_query.cpp b/CYD-Klipper/src/core/files_query.cpp index 85acfa1..ff493b5 100644 --- a/CYD-Klipper/src/core/files_query.cpp +++ b/CYD-Klipper/src/core/files_query.cpp @@ -53,8 +53,10 @@ FILESYSTEM_FILE* get_files(int limit){ file_iter++; } + + if (file_iter == files.end() && files.size() >= limit) + continue; - // Little inefficient as it always allocates a string, even if it doesn't have to f.name = (char*)malloc(strlen(path) + 1); if (f.name == NULL){ Serial.println("Failed to allocate memory"); From 2e252c1d18b6f9323a404e46b5d18538eb620fd5 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Fri, 26 Jan 2024 17:26:41 +0100 Subject: [PATCH 16/45] Upgrade lvgl --- CYD-Klipper/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index c04f71d..a4b28d5 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -15,7 +15,7 @@ framework = arduino monitor_speed = 115200 lib_deps = SPI - lvgl/lvgl@^8.3.9 + https://github.com/lvgl/lvgl#74d0a81 https://github.com/Bodmer/TFT_eSPI.git https://github.com/PaulStoffregen/XPT2046_Touchscreen.git bblanchon/ArduinoJson@^7.0.0 From ec75a3e289572a6e44ece5957df1bfbac6c3c998 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 00:18:52 +0100 Subject: [PATCH 17/45] Start of porting process --- CYD-Klipper/.vscode/settings.json | 3 +- CYD-Klipper/platformio.ini | 22 +++++ .../ESP32-2432S028R.cpp} | 17 +++- CYD-Klipper/src/core/device/ESP32-2432S028R.h | 1 + CYD-Klipper/src/core/screen_driver.h | 30 ++----- CYD-Klipper/src/main.cpp | 1 + CYD-Klipper/src/ui/panels/macros_panel.cpp | 83 +++++++++---------- CYD-Klipper/src/ui/panels/settings_panel.cpp | 25 +++--- CYD-Klipper/src/ui/ui_utils.cpp | 10 +++ CYD-Klipper/src/ui/ui_utils.h | 6 ++ 10 files changed, 117 insertions(+), 81 deletions(-) rename CYD-Klipper/src/core/{screen_driver.cpp => device/ESP32-2432S028R.cpp} (95%) create mode 100644 CYD-Klipper/src/core/device/ESP32-2432S028R.h create mode 100644 CYD-Klipper/src/ui/ui_utils.cpp create mode 100644 CYD-Klipper/src/ui/ui_utils.h diff --git a/CYD-Klipper/.vscode/settings.json b/CYD-Klipper/.vscode/settings.json index 75d2259..4d652ee 100644 --- a/CYD-Klipper/.vscode/settings.json +++ b/CYD-Klipper/.vscode/settings.json @@ -9,6 +9,7 @@ "vector": "cpp", "string_view": "cpp", "initializer_list": "cpp", - "algorithm": "cpp" + "algorithm": "cpp", + "cstddef": "cpp" } } \ No newline at end of file diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index a4b28d5..81b35c9 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -41,3 +41,25 @@ build_flags = -DSPI_FREQUENCY=55000000 -DSPI_READ_FREQUENCY=20000000 -DSPI_TOUCH_FREQUENCY=2500000 + + ### Porting options ### + # Defines the screen height + -DCYD_SCREEN_HEIGHT=240 + # Defines the screen width + -DCYD_SCREEN_WIDTH=320 + # Defines the pixel gap used for large gaps (like between buttons) + -DCYD_SCREEN_BIG_GAP_PX=8 + # Defines the pixel gap used for small gaps (like between text and buttons) + -DCYD_SCREEN_SMALL_GAP_PX=4 + # Defines the minimum pixel height of a button + -DCYD_SCREEN_MIN_BUTTON_HEIGHT=35 + # Defines the minimum pixel width of a button + -DCYD_SCREEN_MIN_BUTTON_WIDTH=35 + # Defines the size of font used + -DCYD_SCREEN_FONT=&lv_font_montserrat_14 + # Defines the size of font used for small text + -DCYD_SCREEN_FONT_SMALL=&lv_font_montserrat_10 + # Defines the size of the sizebar + -DCYD_SCREEN_SIDEBAR_SIZE_PX=40 + # Defines the screen driver + -DCYD_SCREEN_DRIVER_ESP32_2432S028R=1 \ No newline at end of file diff --git a/CYD-Klipper/src/core/screen_driver.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp similarity index 95% rename from CYD-Klipper/src/core/screen_driver.cpp rename to CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index ae06f78..99347b8 100644 --- a/CYD-Klipper/src/core/screen_driver.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -1,8 +1,19 @@ -#include "screen_driver.h" +#include "ESP32-2432S028R.h" + #include #include -#include "../conf/global_config.h" +#include "../../conf/global_config.h" #include "lvgl.h" +#include +#include + +#define XPT2046_IRQ 36 +#define XPT2046_MOSI 32 +#define XPT2046_MISO 39 +#define XPT2046_CLK 25 +#define XPT2046_CS 33 +#define CPU_FREQ_HIGH 240 +#define CPU_FREQ_LOW 80 SPIClass touchscreen_spi = SPIClass(HSPI); XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ); @@ -229,7 +240,7 @@ void screen_setup() touchscreen_spi.begin(XPT2046_CLK, XPT2046_MISO, XPT2046_MOSI, XPT2046_CS); touchscreen.begin(touchscreen_spi); - touchscreen_calibrate(); + touchscreen_calibrate(false); lv_disp_draw_buf_init(&draw_buf, buf, NULL, TFT_WIDTH * TFT_HEIGHT / 10); diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.h b/CYD-Klipper/src/core/device/ESP32-2432S028R.h new file mode 100644 index 0000000..7b9637e --- /dev/null +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.h @@ -0,0 +1 @@ +#pragma once \ No newline at end of file diff --git a/CYD-Klipper/src/core/screen_driver.h b/CYD-Klipper/src/core/screen_driver.h index 90f808e..1e6380c 100644 --- a/CYD-Klipper/src/core/screen_driver.h +++ b/CYD-Klipper/src/core/screen_driver.h @@ -1,35 +1,21 @@ #pragma once // Adapted from https://github.com/xperiments-in/xtouch/blob/main/src/devices/2.8/screen.h -#ifndef _SCREEN_DRIVER_INIT -#define _SCREEN_DRIVER_INIT +#ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R + #include "device/ESP32-2432S028R.h" +#else + #error "No screen driver defined" +#endif -#define CPU_FREQ_HIGH 240 -#define CPU_FREQ_LOW 80 - -#include -#include - -#define XPT2046_IRQ 36 -#define XPT2046_MOSI 32 -#define XPT2046_MISO 39 -#define XPT2046_CLK 25 -#define XPT2046_CS 33 - -TS_Point touchscreen_point(); void touchscreen_calibrate(bool force = false); -void screen_setBrightness(byte brightness); +void screen_setBrightness(unsigned char brightness); void screen_timer_setup(); void screen_timer_start(); void screen_timer_stop(); -void screen_timer_period(uint32_t period); +void screen_timer_period(unsigned int period); void set_color_scheme(); void screen_setup(); void set_invert_display(); void screen_timer_wake(); void set_screen_timer_period(); -void set_screen_brightness(); - -extern TFT_eSPI tft; - -#endif // _SCREEN_DRIVER_INIT \ No newline at end of file +void set_screen_brightness(); \ No newline at end of file diff --git a/CYD-Klipper/src/main.cpp b/CYD-Klipper/src/main.cpp index a517416..4b6b0af 100644 --- a/CYD-Klipper/src/main.cpp +++ b/CYD-Klipper/src/main.cpp @@ -6,6 +6,7 @@ #include "core/data_setup.h" #include "ui/main_ui.h" #include "ui/nav_buttons.h" +#include static void event_handler(lv_event_t * e){ lv_event_code_t code = lv_event_get_code(e); diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 16348fb..ebb2c07 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -3,15 +3,10 @@ #include "../nav_buttons.h" #include "../../core/data_setup.h" #include "../../core/macros_query.h" +#include "../ui_utils.h" #include -int y_offset_macros = 40; -const int y_element_size = 50; -const int y_seperator_size = 1; -const int y_seperator_x_padding = 50; -const int panel_width = TFT_HEIGHT - 40; -const int y_element_x_padding = 30; -const static lv_point_t line_points[] = { {0, 0}, {panel_width - y_seperator_x_padding, 0} }; +const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; static void btn_press(lv_event_t * e){ lv_obj_t * btn = lv_event_get_target(e); @@ -24,44 +19,11 @@ static void btn_goto_settings(lv_event_t * e){ nav_buttons_setup(3); } -void create_macro_widget(const char* macro, lv_obj_t* root_panel){ - lv_obj_t * panel = lv_obj_create(root_panel); - lv_obj_set_style_border_width(panel, 0, 0); - lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0); - lv_obj_set_style_pad_all(panel, 0, 0); - lv_obj_align(panel, LV_ALIGN_TOP_MID, 0, y_offset_macros); - lv_obj_set_size(panel, panel_width - y_element_x_padding, y_element_size); - - lv_obj_t * line = lv_line_create(panel); - lv_line_set_points(line, line_points, 2); - lv_obj_set_style_line_width(line, y_seperator_size, 0); - lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); - lv_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0); - - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, macro); - lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0); - lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_obj_set_width(label, (TFT_HEIGHT - 40) * 0.75f); - - lv_obj_t * btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0); - lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro); - - label = lv_label_create(btn); - lv_label_set_text(label, "Run"); - lv_obj_center(label); - - y_offset_macros += y_element_size; -} - void macros_panel_init(lv_obj_t* panel) { - y_offset_macros = 40; - 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, TFT_HEIGHT - 40 - 20, 30); - lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, 5); + lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT); + lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_BIG_GAP_PX); lv_obj_t * label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_SETTINGS " Screen Settings"); @@ -75,7 +37,42 @@ void macros_panel_init(lv_obj_t* panel) { return; } + lv_obj_t * root_panel = lv_create_empty_panel(panel); + lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT - CYD_SCREEN_MIN_BUTTON_HEIGHT - CYD_SCREEN_BIG_GAP_PX); + lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX); + lv_obj_set_layout(root_panel, LV_LAYOUT_FLEX); + lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_align(root_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + lv_obj_set_style_pad_column(root_panel, 0, 0); + lv_obj_set_style_pad_row(root_panel, 0, 0); + + for (int j = 0; j < 2; j++) for (int i = 0; i < query.count; i++){ - create_macro_widget(query.macros[i], panel); + const char* macro = query.macros[i]; + + lv_obj_t * panel = lv_create_empty_panel(root_panel); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX * 2); + + lv_obj_t * line = lv_line_create(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_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0); + + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, macro); + lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0); + lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); + // TODO: Hack. Needs to be fixed for proper porting + lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH * 0.75f); + + lv_obj_t * btn = lv_btn_create(panel); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT); + lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0); + lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro); + + label = lv_label_create(btn); + lv_label_set_text(label, "Run"); + lv_obj_center(label); } } \ 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 c7404f3..53b2797 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -3,6 +3,8 @@ #include "../../core/screen_driver.h" #include "../../conf/global_config.h" #include "../main_ui.h" +#include "../ui_utils.h" +#include static void invert_color_switch(lv_event_t * e){ auto state = lv_obj_get_state(lv_event_get_target(e)); @@ -80,25 +82,20 @@ static void on_during_print_switch(lv_event_t* e){ WriteGlobalConfig(); } -int y_offset = 0; -const int y_element_size = 50; -const int y_seperator_size = 1; -const int y_seperator_x_padding = 50; -const int panel_width = TFT_HEIGHT - 40; -const int y_element_x_padding = 30; -const static lv_point_t line_points[] = { {0, 0}, {panel_width - y_seperator_x_padding, 0} }; +const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel){ + lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT); + lv_obj_t * panel = lv_obj_create(root_panel); lv_obj_set_style_border_width(panel, 0, 0); lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0); lv_obj_set_style_pad_all(panel, 0, 0); - lv_obj_align(panel, LV_ALIGN_TOP_MID, 0, y_offset); - lv_obj_set_size(panel, panel_width - y_element_x_padding, y_element_size); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX * 2); lv_obj_t * line = lv_line_create(panel); lv_line_set_points(line, line_points, 2); - lv_obj_set_style_line_width(line, y_seperator_size, 0); + lv_obj_set_style_line_width(line, 1, 0); lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); lv_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0); @@ -108,11 +105,15 @@ void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* lv_obj_set_parent(object, panel); lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0); - y_offset += y_element_size; } void settings_panel_init(lv_obj_t* panel){ - y_offset = 0; + + lv_obj_set_layout(panel, LV_LAYOUT_FLEX); + lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + lv_obj_set_style_pad_column(panel, 0, 0); + lv_obj_set_style_pad_row(panel, 0, 0); lv_obj_t * btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, reset_wifi_click, LV_EVENT_CLICKED, NULL); diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp new file mode 100644 index 0000000..8c1075d --- /dev/null +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -0,0 +1,10 @@ +#include "lvgl.h" +#include "ui_utils.h" + +lv_obj_t* lv_create_empty_panel(lv_obj_t* root) { + lv_obj_t* panel = lv_obj_create(root); + lv_obj_set_style_border_width(panel, 0, 0); + lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0); + lv_obj_set_style_pad_all(panel, 0, 0); + return 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 new file mode 100644 index 0000000..381b8a5 --- /dev/null +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -0,0 +1,6 @@ +#pragma once + +#define CYD_SCREEN_PANEL_WIDTH \ + (CYD_SCREEN_WIDTH - CYD_SCREEN_SIDEBAR_SIZE_PX) + +lv_obj_t* lv_create_empty_panel(lv_obj_t* root); \ No newline at end of file From 1c50efa500f88bd64c60a37c87d45384af25abb8 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 00:24:33 +0100 Subject: [PATCH 18/45] Make fonts ajustable --- CYD-Klipper/src/conf/lv_conf.h | 2 +- CYD-Klipper/src/core/device/ESP32-2432S028R.cpp | 2 +- CYD-Klipper/src/ui/nav_buttons.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 d5979b6..e086ff1 100644 --- a/CYD-Klipper/src/conf/lv_conf.h +++ b/CYD-Klipper/src/conf/lv_conf.h @@ -335,7 +335,7 @@ #define LV_FONT_MONTSERRAT_22 0 #define LV_FONT_MONTSERRAT_24 0 #define LV_FONT_MONTSERRAT_26 0 -#define LV_FONT_MONTSERRAT_28 1 +#define LV_FONT_MONTSERRAT_28 0 #define LV_FONT_MONTSERRAT_30 0 #define LV_FONT_MONTSERRAT_32 0 #define LV_FONT_MONTSERRAT_34 0 diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index 99347b8..489bea3 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -211,7 +211,7 @@ void set_color_scheme(){ main_color = lv_palette_main(color_defs[global_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, LV_FONT_DEFAULT); + 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_disp_set_theme(dispp, theme); } diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index e056316..09d010b 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -186,5 +186,5 @@ void nav_style_setup(){ lv_style_set_radius(&nav_button_style, 0); lv_style_init(&nav_button_text_style); - lv_style_set_text_font(&nav_button_text_style, &lv_font_montserrat_10); + lv_style_set_text_font(&nav_button_text_style, CYD_SCREEN_FONT_SMALL); } \ No newline at end of file From 939a9f6547b7b101bcf31b0463a91ced9df7b354 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 00:48:06 +0100 Subject: [PATCH 19/45] Make sidebar ajustable --- CYD-Klipper/src/ui/nav_buttons.cpp | 109 +++++++------------ CYD-Klipper/src/ui/panels/move_panel.cpp | 2 - CYD-Klipper/src/ui/panels/progress_panel.cpp | 2 - CYD-Klipper/src/ui/panels/temp_panel.cpp | 1 - 4 files changed, 37 insertions(+), 77 deletions(-) diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index 09d010b..5339ca3 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -3,6 +3,7 @@ #include "../core/data_setup.h" #include "nav_buttons.h" #include +#include "ui_utils.h" static lv_style_t nav_button_style; @@ -75,92 +76,54 @@ static void btn_click_macros(lv_event_t * e){ nav_buttons_setup(4); } -void nav_buttons_setup(unsigned char active_panel){ - lv_obj_clean(lv_scr_act()); - lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE); - sprintf(temp_buffer, "%.0f/%.0f", printer.extruder_temp, printer.bed_temp); - sprintf(z_pos_buffer, "Z%.2f", printer.position[2]); - - const int button_width = 40; - const int button_height = 60; - const int icon_text_spacing = 10; - - // Files/Print - lv_obj_t * btn = lv_btn_create(lv_scr_act()); - lv_obj_set_size(btn, button_width, button_height); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, 0); +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); + lv_obj_set_width(btn, CYD_SCREEN_SIDEBAR_SIZE_PX); lv_obj_add_style(btn, &nav_button_style, 0); - lv_obj_add_event_cb(btn, btn_click_files, LV_EVENT_CLICKED, NULL); + if (button_click != NULL) + lv_obj_add_event_cb(btn, button_click, LV_EVENT_CLICKED, NULL); - lv_obj_t * label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_COPY); - lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing); - - label = lv_label_create(btn); - lv_label_set_text(label, "Idle"); - lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing); - lv_obj_add_style(label, &nav_button_text_style, 0); - lv_obj_add_event_cb(label, update_printer_data_time, LV_EVENT_MSG_RECEIVED, NULL); - lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); - - // Move - btn = lv_btn_create(lv_scr_act()); - lv_obj_set_size(btn, button_width, button_height); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height); - lv_obj_add_style(btn, &nav_button_style, 0); - lv_obj_add_event_cb(btn, btn_click_move, LV_EVENT_CLICKED, NULL); - - label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_CHARGE); - lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing); + lv_obj_t* label = lv_label_create(btn); + lv_label_set_text(label, icon); + lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * CYD_SCREEN_BIG_GAP_PX); label = lv_label_create(btn); - lv_label_set_text(label, z_pos_buffer); - lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing); - lv_obj_add_event_cb(label, update_printer_data_z_pos, LV_EVENT_MSG_RECEIVED, NULL); + lv_label_set_text(label, name); + lv_obj_align(label, LV_ALIGN_CENTER, 0, CYD_SCREEN_BIG_GAP_PX); + lv_obj_add_event_cb(label, label_update, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); lv_obj_add_style(label, &nav_button_text_style, 0); +} - // Extrude/Temp - btn = lv_btn_create(lv_scr_act()); - lv_obj_set_size(btn, button_width, button_height); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height * 2); - lv_obj_add_style(btn, &nav_button_style, 0); - lv_obj_add_event_cb(btn, btn_click_extrude, LV_EVENT_CLICKED, NULL); +void nav_buttons_setup(unsigned char active_panel){ + lv_obj_clean(lv_scr_act()); + lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE); - label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_WARNING); - lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing); + lv_obj_t * root_panel = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_size(root_panel, CYD_SCREEN_SIDEBAR_SIZE_PX, CYD_SCREEN_HEIGHT); + lv_obj_align(root_panel, LV_ALIGN_TOP_LEFT, 0, 0); + lv_obj_set_layout(root_panel, LV_LAYOUT_FLEX); + lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_align(root_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + lv_obj_set_style_pad_column(root_panel, 0, 0); + lv_obj_set_style_pad_row(root_panel, 0, 0); - label = lv_label_create(btn); - lv_label_set_text(label, temp_buffer); - lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing); - lv_obj_add_event_cb(label, update_printer_data_temp, LV_EVENT_MSG_RECEIVED, NULL); - lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); - lv_obj_add_style(label, &nav_button_text_style, 0); + // Files/Print + create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); - // Settings - btn = lv_btn_create(lv_scr_act()); - lv_obj_set_size(btn, button_width, button_height); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, 0, button_height * 3); - lv_obj_add_style(btn, &nav_button_style, 0); - lv_obj_add_event_cb(btn, btn_click_macros, LV_EVENT_CLICKED, NULL); + // Move + create_button(LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel); - label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_GPS); - lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * icon_text_spacing); + // Extrude/Temp + create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel); - label = lv_label_create(btn); - lv_label_set_text(label, "Macro"); - lv_obj_align(label, LV_ALIGN_CENTER, 0, icon_text_spacing); - lv_obj_add_style(label, &nav_button_text_style, 0); + // Macros + create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel); - lv_obj_t * panel = lv_obj_create(lv_scr_act()); - lv_obj_set_size(panel, TFT_HEIGHT - button_width, TFT_WIDTH); + lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT); lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0); - lv_obj_set_style_border_width(panel, 0, 0); - lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0); - lv_obj_set_style_pad_all(panel, 0, 0); switch (active_panel){ case 0: @@ -179,6 +142,8 @@ void nav_buttons_setup(unsigned char active_panel){ macros_panel_init(panel); break; } + + lv_msg_send(DATA_PRINTER_DATA, &printer); } void nav_style_setup(){ diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index fcde141..8ba8e49 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -204,6 +204,4 @@ void move_panel_init(lv_obj_t* panel){ y_pos += 60; } - - lv_msg_send(DATA_PRINTER_DATA, &printer); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/progress_panel.cpp b/CYD-Klipper/src/ui/panels/progress_panel.cpp index adfe229..dd72e13 100644 --- a/CYD-Klipper/src/ui/panels/progress_panel.cpp +++ b/CYD-Klipper/src/ui/panels/progress_panel.cpp @@ -117,6 +117,4 @@ void progress_panel_init(lv_obj_t* panel){ lv_label_set_text(label, LV_SYMBOL_PAUSE); lv_obj_center(label); } - - lv_msg_send(DATA_PRINTER_DATA, &printer); } \ 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 f055869..3348482 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -302,6 +302,5 @@ void temp_panel_init(lv_obj_t* panel){ lv_label_set_text(label, LV_SYMBOL_UP " Retract"); lv_obj_center(label); - lv_msg_send(DATA_PRINTER_DATA, &printer); lv_msg_send(DATA_PRINTER_TEMP_PRESET, &printer); } \ No newline at end of file From 8198729ad3aa4bffcb53c523ac9aa4c7cdbcbf26 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 00:49:25 +0100 Subject: [PATCH 20/45] Rename defines --- CYD-Klipper/platformio.ini | 8 ++++---- CYD-Klipper/src/ui/nav_buttons.cpp | 4 ++-- CYD-Klipper/src/ui/panels/macros_panel.cpp | 10 +++++----- CYD-Klipper/src/ui/panels/settings_panel.cpp | 4 ++-- CYD-Klipper/src/ui/ui_utils.h | 2 +- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 81b35c9..45b41d6 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -44,17 +44,17 @@ build_flags = ### Porting options ### # Defines the screen height - -DCYD_SCREEN_HEIGHT=240 + -DCYD_SCREEN_HEIGHT_PX=240 # Defines the screen width - -DCYD_SCREEN_WIDTH=320 + -DCYD_SCREEN_WIDTH_PX=320 # Defines the pixel gap used for large gaps (like between buttons) -DCYD_SCREEN_BIG_GAP_PX=8 # Defines the pixel gap used for small gaps (like between text and buttons) -DCYD_SCREEN_SMALL_GAP_PX=4 # Defines the minimum pixel height of a button - -DCYD_SCREEN_MIN_BUTTON_HEIGHT=35 + -DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35 # Defines the minimum pixel width of a button - -DCYD_SCREEN_MIN_BUTTON_WIDTH=35 + -DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35 # Defines the size of font used -DCYD_SCREEN_FONT=&lv_font_montserrat_14 # Defines the size of font used for small text diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index 5339ca3..2000911 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -101,7 +101,7 @@ 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()); - lv_obj_set_size(root_panel, CYD_SCREEN_SIDEBAR_SIZE_PX, CYD_SCREEN_HEIGHT); + 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_obj_set_layout(root_panel, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN); @@ -122,7 +122,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, CYD_SCREEN_HEIGHT); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_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 ebb2c07..95034bf 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -22,7 +22,7 @@ static void btn_goto_settings(lv_event_t * e){ 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); - lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT); + lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_BIG_GAP_PX); lv_obj_t * label = lv_label_create(btn); @@ -38,8 +38,8 @@ void macros_panel_init(lv_obj_t* panel) { } lv_obj_t * root_panel = lv_create_empty_panel(panel); - lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT - CYD_SCREEN_MIN_BUTTON_HEIGHT - CYD_SCREEN_BIG_GAP_PX); - lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX); + lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX); + lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX); lv_obj_set_layout(root_panel, LV_LAYOUT_FLEX); lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_align(root_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); @@ -51,7 +51,7 @@ void macros_panel_init(lv_obj_t* panel) { const char* macro = query.macros[i]; lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX * 2); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX * 2); lv_obj_t * line = lv_line_create(panel); lv_line_set_points(line, line_points, 2); @@ -67,7 +67,7 @@ void macros_panel_init(lv_obj_t* panel) { lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH * 0.75f); lv_obj_t * btn = lv_btn_create(panel); - lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0); lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro); diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 53b2797..9759597 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -85,13 +85,13 @@ static void on_during_print_switch(lv_event_t* e){ const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel){ - lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT); + lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * panel = lv_obj_create(root_panel); lv_obj_set_style_border_width(panel, 0, 0); lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0); lv_obj_set_style_pad_all(panel, 0, 0); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT + CYD_SCREEN_BIG_GAP_PX * 2); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX * 2); lv_obj_t * line = lv_line_create(panel); lv_line_set_points(line, line_points, 2); diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index 381b8a5..39effe1 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -1,6 +1,6 @@ #pragma once #define CYD_SCREEN_PANEL_WIDTH \ - (CYD_SCREEN_WIDTH - CYD_SCREEN_SIDEBAR_SIZE_PX) + (CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) lv_obj_t* lv_create_empty_panel(lv_obj_t* root); \ No newline at end of file From db0c335049736bf00c5ba77fff0c0320810ea0e9 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 00:55:33 +0100 Subject: [PATCH 21/45] Don't show each macro twice --- CYD-Klipper/src/ui/panels/macros_panel.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 95034bf..5b79b93 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -46,7 +46,6 @@ void macros_panel_init(lv_obj_t* panel) { lv_obj_set_style_pad_column(root_panel, 0, 0); lv_obj_set_style_pad_row(root_panel, 0, 0); - for (int j = 0; j < 2; j++) for (int i = 0; i < query.count; i++){ const char* macro = query.macros[i]; From 66bb1137aaca2c4e98ea45d0279fb92e825784de Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 11:40:25 +0100 Subject: [PATCH 22/45] Make generic functions for creating flex parents --- CYD-Klipper/src/ui/nav_buttons.cpp | 6 +--- CYD-Klipper/src/ui/panels/macros_panel.cpp | 31 ++++++++------------ CYD-Klipper/src/ui/panels/settings_panel.cpp | 26 ++++++---------- CYD-Klipper/src/ui/ui_utils.cpp | 16 ++++++++++ CYD-Klipper/src/ui/ui_utils.h | 4 ++- 5 files changed, 41 insertions(+), 42 deletions(-) diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index 2000911..f305a68 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -103,11 +103,7 @@ void nav_buttons_setup(unsigned char active_panel){ lv_obj_t * root_panel = lv_create_empty_panel(lv_scr_act()); 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_obj_set_layout(root_panel, LV_LAYOUT_FLEX); - lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN); - lv_obj_set_flex_align(root_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); - lv_obj_set_style_pad_column(root_panel, 0, 0); - lv_obj_set_style_pad_row(root_panel, 0, 0); + lv_layout_flex_column(root_panel, LV_FLEX_ALIGN_START, 0, 0); // Files/Print create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 5b79b93..1f2b731 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -38,40 +38,33 @@ void macros_panel_init(lv_obj_t* panel) { } lv_obj_t * root_panel = lv_create_empty_panel(panel); - lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX); - lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX); - lv_obj_set_layout(root_panel, LV_LAYOUT_FLEX); - lv_obj_set_flex_flow(root_panel, LV_FLEX_FLOW_COLUMN); - lv_obj_set_flex_align(root_panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); - lv_obj_set_style_pad_column(root_panel, 0, 0); - lv_obj_set_style_pad_row(root_panel, 0, 0); + lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); + lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX * 2); + lv_layout_flex_column(root_panel); + for (int j = 0; j < 2; j++) 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_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX * 2); - - lv_obj_t * line = lv_line_create(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_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0); + lv_layout_flex_row(panel, LV_FLEX_ALIGN_END); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * label = lv_label_create(panel); lv_label_set_text(label, macro); - lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0); lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); - // TODO: Hack. Needs to be fixed for proper porting - lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH * 0.75f); + lv_obj_set_flex_grow(label, 1); lv_obj_t * btn = lv_btn_create(panel); lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0); - lv_obj_add_event_cb(btn, btn_press, LV_EVENT_CLICKED, (void*)macro); 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); } } \ 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 9759597..8609833 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -87,17 +87,8 @@ const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel){ lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_t * panel = lv_obj_create(root_panel); - lv_obj_set_style_border_width(panel, 0, 0); - lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0); - lv_obj_set_style_pad_all(panel, 0, 0); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX * 2); - - lv_obj_t * line = lv_line_create(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_obj_align(line, LV_ALIGN_BOTTOM_MID, 0, 0); + lv_obj_t * panel = lv_create_empty_panel(root_panel); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * label = lv_label_create(panel); lv_label_set_text(label, label_text); @@ -105,15 +96,16 @@ void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* lv_obj_set_parent(object, panel); lv_obj_align(object, LV_ALIGN_RIGHT_MID, 0, 0); + + 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); } void settings_panel_init(lv_obj_t* panel){ - - lv_obj_set_layout(panel, LV_LAYOUT_FLEX); - lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_COLUMN); - lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); - lv_obj_set_style_pad_column(panel, 0, 0); - lv_obj_set_style_pad_row(panel, 0, 0); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_layout_flex_column(panel); lv_obj_t * btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, reset_wifi_click, LV_EVENT_CLICKED, NULL); diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index 8c1075d..a489d4a 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -7,4 +7,20 @@ lv_obj_t* lv_create_empty_panel(lv_obj_t* root) { lv_obj_set_style_bg_opa(panel, LV_OPA_TRANSP, 0); lv_obj_set_style_pad_all(panel, 0, 0); return panel; +} + +void lv_layout_flex_column(lv_obj_t* obj, lv_flex_align_t allign, lv_coord_t pad_column, lv_coord_t pad_row){ + lv_obj_set_layout(obj, LV_LAYOUT_FLEX); + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); + lv_obj_set_flex_align(obj, allign, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + lv_obj_set_style_pad_column(obj, pad_column, 0); + lv_obj_set_style_pad_row(obj, pad_row, 0); +} + +void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign, lv_coord_t pad_column, lv_coord_t pad_row){ + lv_obj_set_layout(obj, LV_LAYOUT_FLEX); + lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_ROW); + lv_obj_set_flex_align(obj, allign, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); + lv_obj_set_style_pad_column(obj, pad_column, 0); + lv_obj_set_style_pad_row(obj, pad_row, 0); } \ 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 39effe1..df9a77a 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -3,4 +3,6 @@ #define CYD_SCREEN_PANEL_WIDTH \ (CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) -lv_obj_t* lv_create_empty_panel(lv_obj_t* root); \ No newline at end of file +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_BIG_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_BIG_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_BIG_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_BIG_GAP_PX); \ No newline at end of file From 2d6fdb8e84e63a6a403dd440f9ed6751fa461f69 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:06:20 +0100 Subject: [PATCH 23/45] Set timeout for getting files --- CYD-Klipper/.vscode/settings.json | 3 ++- CYD-Klipper/src/core/files_query.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/CYD-Klipper/.vscode/settings.json b/CYD-Klipper/.vscode/settings.json index 4d652ee..378bfd4 100644 --- a/CYD-Klipper/.vscode/settings.json +++ b/CYD-Klipper/.vscode/settings.json @@ -10,6 +10,7 @@ "string_view": "cpp", "initializer_list": "cpp", "algorithm": "cpp", - "cstddef": "cpp" + "cstddef": "cpp", + "functional": "cpp" } } \ No newline at end of file diff --git a/CYD-Klipper/src/core/files_query.cpp b/CYD-Klipper/src/core/files_query.cpp index ff493b5..0fce127 100644 --- a/CYD-Klipper/src/core/files_query.cpp +++ b/CYD-Klipper/src/core/files_query.cpp @@ -31,6 +31,7 @@ FILESYSTEM_FILE* get_files(int limit){ 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); int httpCode = client.GET(); auto timer_parse = millis(); From 4ff96e0278669461c6700a9c7d26b6ae1d2efec5 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:06:35 +0100 Subject: [PATCH 24/45] Make file select responsive --- CYD-Klipper/src/ui/nav_buttons.cpp | 2 +- CYD-Klipper/src/ui/panels/macros_panel.cpp | 9 ++++----- CYD-Klipper/src/ui/panels/print_panel.cpp | 20 +++++++++----------- CYD-Klipper/src/ui/panels/settings_panel.cpp | 4 ++-- CYD-Klipper/src/ui/ui_utils.h | 2 +- 5 files changed, 17 insertions(+), 20 deletions(-) diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index f305a68..ad55fab 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -118,7 +118,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, CYD_SCREEN_HEIGHT_PX); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_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 1f2b731..920a47a 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -6,7 +6,7 @@ #include "../ui_utils.h" #include -const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; +const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; static void btn_press(lv_event_t * e){ lv_obj_t * btn = lv_event_get_target(e); @@ -22,7 +22,7 @@ static void btn_goto_settings(lv_event_t * e){ 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); - lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_BIG_GAP_PX); lv_obj_t * label = lv_label_create(btn); @@ -38,17 +38,16 @@ void macros_panel_init(lv_obj_t* panel) { } lv_obj_t * root_panel = lv_create_empty_panel(panel); - lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); + lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX * 2); lv_layout_flex_column(root_panel); - for (int j = 0; j < 2; j++) 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 - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * label = lv_label_create(panel); lv_label_set_text(label, macro); diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index e0a1cd6..ee5f32a 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -5,6 +5,7 @@ #include "../../conf/global_config.h" #include #include +#include "../ui_utils.h" FILESYSTEM_FILE* selected_file = NULL; @@ -49,7 +50,8 @@ static void btn_print_file_verify(lv_event_t * e){ selected_file = (FILESYSTEM_FILE*)lv_event_get_user_data(e); lv_obj_t * panel = lv_obj_create(lv_scr_act()); - lv_obj_set_size(panel, TFT_HEIGHT - 40, TFT_WIDTH - 30); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX * 2, 0); + lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 4, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 3); lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0); lv_obj_t * label = lv_label_create(panel); @@ -59,12 +61,12 @@ static void btn_print_file_verify(lv_event_t * e){ 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, TFT_HEIGHT - 90); + lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 10); lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 10, -10); - lv_obj_set_size(btn, 40, 40); + lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 0, 0); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_add_event_cb(btn, btn_print_back, LV_EVENT_CLICKED, panel); label = lv_label_create(btn); @@ -72,8 +74,8 @@ static void btn_print_file_verify(lv_event_t * e){ lv_obj_center(label); btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10); - lv_obj_set_size(btn, 40, 40); + lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, 0, 0); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_add_event_cb(btn, btn_print_file, LV_EVENT_CLICKED, panel); label = lv_label_create(btn); @@ -87,12 +89,8 @@ void print_panel_init(lv_obj_t* panel){ return; } - auto panel_width = TFT_HEIGHT - 40; - auto panel_height_margin = TFT_WIDTH - 10; - auto panel_width_margin = panel_width - 10; - lv_obj_t * list = lv_list_create(panel); - lv_obj_set_size(list, panel_width_margin, panel_height_margin); + lv_obj_set_size(list, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); lv_obj_align(list, LV_ALIGN_CENTER, 0, 0); FILESYSTEM_FILE* files = get_files(25); diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 8609833..caf5c9f 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -82,13 +82,13 @@ static void on_during_print_switch(lv_event_t* e){ WriteGlobalConfig(); } -const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; +const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel){ lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * label = lv_label_create(panel); lv_label_set_text(label, label_text); diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index df9a77a..f5074a5 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -1,6 +1,6 @@ #pragma once -#define CYD_SCREEN_PANEL_WIDTH \ +#define CYD_SCREEN_PANEL_WIDTH_PX \ (CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) lv_obj_t* lv_create_empty_panel(lv_obj_t* root); From b3c60e4442a7b8f15d14e2c72dca34f488f5b576 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:14:12 +0100 Subject: [PATCH 25/45] Change styling of print panel --- CYD-Klipper/src/ui/panels/print_panel.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index ee5f32a..847c842 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -90,13 +90,17 @@ void print_panel_init(lv_obj_t* panel){ } lv_obj_t * list = lv_list_create(panel); - lv_obj_set_size(list, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); + 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_align(list, LV_ALIGN_CENTER, 0, 0); FILESYSTEM_FILE* files = get_files(25); int count = 0; while (files != NULL && files->name != NULL && count <= 20){ lv_obj_t * btn = lv_list_add_btn(list, LV_SYMBOL_FILE, files->name); + lv_obj_set_style_bg_opa(btn, LV_OPA_TRANSP, 0); lv_obj_add_event_cb(btn, btn_print_file_verify, LV_EVENT_CLICKED, (void*)files); files += 1; From 6750c8f5727444c0bcf510c346d19c7c3d022dbd Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 12:54:18 +0100 Subject: [PATCH 26/45] Make progress panel responsive --- CYD-Klipper/src/ui/panels/print_panel.cpp | 6 ++- CYD-Klipper/src/ui/panels/progress_panel.cpp | 47 +++++++++++--------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index 847c842..2229e92 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -46,6 +46,8 @@ static void btn_print_back(lv_event_t * e){ } static void btn_print_file_verify(lv_event_t * e){ + const auto button_size_mult = 1.3f; + lv_obj_t * btn = lv_event_get_target(e); selected_file = (FILESYSTEM_FILE*)lv_event_get_user_data(e); @@ -66,7 +68,7 @@ static void btn_print_file_verify(lv_event_t * e){ btn = lv_btn_create(panel); lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 0, 0); - lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); lv_obj_add_event_cb(btn, btn_print_back, LV_EVENT_CLICKED, panel); label = lv_label_create(btn); @@ -75,7 +77,7 @@ static void btn_print_file_verify(lv_event_t * e){ btn = lv_btn_create(panel); lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, 0, 0); - lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); lv_obj_add_event_cb(btn, btn_print_file, LV_EVENT_CLICKED, panel); label = lv_label_create(btn); diff --git a/CYD-Klipper/src/ui/panels/progress_panel.cpp b/CYD-Klipper/src/ui/panels/progress_panel.cpp index dd72e13..0950161 100644 --- a/CYD-Klipper/src/ui/panels/progress_panel.cpp +++ b/CYD-Klipper/src/ui/panels/progress_panel.cpp @@ -1,6 +1,7 @@ #include "panel.h" #include "../../core/data_setup.h" #include +#include "../ui_utils.h" char time_buffer[12]; @@ -47,48 +48,55 @@ static void btn_click_resume(lv_event_t * e){ } void progress_panel_init(lv_obj_t* panel){ - auto panel_width = TFT_HEIGHT - 40; - auto panel_width_margin = panel_width - 30; + auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 3; + const auto button_size_mult = 1.3f; + + lv_obj_t * center_panel = lv_create_empty_panel(panel); + lv_obj_align(center_panel, LV_ALIGN_CENTER, 0, 0); + lv_obj_set_size(center_panel, panel_width, LV_SIZE_CONTENT); + lv_layout_flex_column(center_panel); // Filename - lv_obj_t * label = lv_label_create(panel); + lv_obj_t * label = lv_label_create(center_panel); lv_label_set_text(label, printer.print_filename); - lv_obj_align(label, LV_ALIGN_CENTER, 0, -40); lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR); - lv_obj_set_width(label, panel_width_margin); + lv_obj_set_width(label, panel_width); // Progress Bar - lv_obj_t * bar = lv_bar_create(panel); - lv_obj_align(bar, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_size(bar, panel_width_margin, 20); + lv_obj_t * bar = lv_bar_create(center_panel); + lv_obj_set_size(bar, panel_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * 0.75f); lv_obj_add_event_cb(bar, progress_bar_update, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subsribe_obj(DATA_PRINTER_DATA, bar, NULL); + // Time + lv_obj_t * time_est_panel = lv_create_empty_panel(center_panel); + lv_obj_set_size(time_est_panel, panel_width, LV_SIZE_CONTENT); + // Elapsed Time - label = lv_label_create(panel); + label = lv_label_create(time_est_panel); lv_label_set_text(label, "???"); - lv_obj_align(label, LV_ALIGN_LEFT_MID, 10, 20); + lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0); lv_obj_add_event_cb(label, update_printer_data_elapsed_time, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); // Remaining Time - label = lv_label_create(panel); + label = lv_label_create(time_est_panel); lv_label_set_text(label, "???"); - lv_obj_align(label, LV_ALIGN_RIGHT_MID, -10, 20); + lv_obj_align(label, LV_ALIGN_RIGHT_MID, 0, 0); lv_obj_add_event_cb(label, update_printer_data_remaining_time, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); // Percentage - label = lv_label_create(panel); + label = lv_label_create(time_est_panel); lv_label_set_text(label, "???"); - lv_obj_align(label, LV_ALIGN_CENTER, 0, 20); + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); lv_obj_add_event_cb(label, update_printer_data_percentage, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); // Stop Button lv_obj_t * btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10); - lv_obj_set_size(btn, 40, 40); + lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -1 * CYD_SCREEN_BIG_GAP_PX, -1 * CYD_SCREEN_BIG_GAP_PX); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); lv_obj_add_event_cb(btn, btn_click_stop, LV_EVENT_CLICKED, NULL); label = lv_label_create(btn); @@ -98,8 +106,6 @@ void progress_panel_init(lv_obj_t* panel){ // Resume Button if (printer.state == PRINTER_STATE_PAUSED){ btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -60, -10); - lv_obj_set_size(btn, 40, 40); lv_obj_add_event_cb(btn, btn_click_resume, LV_EVENT_CLICKED, NULL); label = lv_label_create(btn); @@ -109,12 +115,13 @@ void progress_panel_init(lv_obj_t* panel){ // Pause Button else { btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -60, -10); - lv_obj_set_size(btn, 40, 40); lv_obj_add_event_cb(btn, btn_click_pause, LV_EVENT_CLICKED, NULL); label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_PAUSE); lv_obj_center(label); } + + lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -2 * CYD_SCREEN_BIG_GAP_PX - CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, -1 * CYD_SCREEN_BIG_GAP_PX); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); } \ No newline at end of file From 8f2997808266795a060b2e8fec17481a1ade6def Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:54:47 +0100 Subject: [PATCH 27/45] Make temp panel responsive --- CYD-Klipper/src/ui/panels/temp_panel.cpp | 147 ++++++++++++----------- 1 file changed, 74 insertions(+), 73 deletions(-) diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index 3348482..4c7f2b3 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -2,6 +2,7 @@ #include "../../core/data_setup.h" #include "../../conf/global_config.h" #include +#include "../ui_utils.h" enum temp_target{ TARGET_HOTEND, @@ -127,7 +128,8 @@ static void keyboard_callback(lv_event_t * e){ static void show_keyboard(lv_event_t * e){ lv_obj_t * keyboard = lv_keyboard_create(root_panel); lv_obj_t * ta = lv_textarea_create(root_panel); - lv_obj_set_size(ta, TFT_HEIGHT - 40, 120); + // TODO: Hack, should be fixed before finishing porting + lv_obj_set_size(ta, CYD_SCREEN_PANEL_WIDTH_PX, 120); lv_obj_align(ta, LV_ALIGN_TOP_MID, 0, 0); lv_textarea_set_max_length(ta, 3); //lv_textarea_set_one_line(ta, true); @@ -202,104 +204,103 @@ static void btn_retract(lv_event_t * e){ send_gcode(true, "G1%20E-25%20F300"); } -void temp_panel_init(lv_obj_t* panel){ +void temp_panel_init(lv_obj_t * panel){ + const auto element_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2; root_panel = panel; edit_mode = false; - const int btn_row_y_one = 30; - const int btn_row_y_two = 100; - auto panel_width = TFT_HEIGHT - 40; - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, "???"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 10); - lv_obj_add_event_cb(label, update_printer_data_hotend_temp, LV_EVENT_MSG_RECEIVED, NULL); - lv_msg_subscribe_obj(DATA_PRINTER_DATA, label, NULL); - - label = lv_label_create(panel); - lv_label_set_text(label, "???"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 80); - lv_obj_add_event_cb(label, update_printer_data_bed_temp, LV_EVENT_MSG_RECEIVED, NULL); - lv_msg_subscribe_obj(DATA_PRINTER_DATA, label, NULL); - - lv_obj_t * btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_TOP_RIGHT, -10, btn_row_y_one); - lv_obj_add_event_cb(btn, show_keyboard_with_hotend, LV_EVENT_CLICKED, panel); - lv_obj_set_width(btn, panel_width / 4 - 10); - label = lv_label_create(btn); - lv_label_set_text(label, "Set"); - lv_obj_center(label); - - btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_TOP_RIGHT, -10, btn_row_y_two); - lv_obj_add_event_cb(btn, show_keyboard_with_bed, LV_EVENT_CLICKED, panel); - lv_obj_set_width(btn, panel_width / 4 - 10); - - label = lv_label_create(btn); - lv_label_set_text(label, "Set"); - lv_obj_center(label); + lv_obj_t * root_temp_panel = lv_create_empty_panel(panel); + lv_obj_set_size(root_temp_panel, CYD_SCREEN_PANEL_WIDTH_PX, LV_SIZE_CONTENT); + lv_obj_align(root_temp_panel, LV_ALIGN_TOP_RIGHT, 0, 0); + lv_obj_set_style_pad_all(root_temp_panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_layout_flex_column(root_temp_panel); - // Presets - for (int i = 0; i < 3; i++){ - int x_pos = 10 + (panel_width / 4) * i - (3 * i); + lv_obj_t * temp_rows[2] = {0}; + lv_obj_t * button_temp_rows[2] = {0}; - btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_pos, btn_row_y_one); - lv_obj_add_event_cb(btn, set_temp_via_preset, LV_EVENT_CLICKED, reinterpret_cast(TARGET_HOTEND_CONFIG_1 + i)); - lv_obj_set_width(btn, panel_width / 4 - 10); + for (int tempIter = 0; tempIter < 2; tempIter++){ + temp_rows[tempIter] = lv_create_empty_panel(root_temp_panel); + lv_layout_flex_column(temp_rows[tempIter]); + lv_obj_set_size(temp_rows[tempIter], element_width, LV_SIZE_CONTENT); - label = lv_label_create(btn); + lv_obj_t * label = lv_label_create(temp_rows[tempIter]); lv_label_set_text(label, "???"); - lv_obj_center(label); - lv_obj_add_event_cb(label, update_temp_preset_label, LV_EVENT_MSG_RECEIVED, reinterpret_cast(TARGET_HOTEND_CONFIG_1 + i)); - lv_msg_subscribe_obj(DATA_PRINTER_TEMP_PRESET, label, NULL); + lv_obj_add_event_cb(label, (tempIter == 0) ? update_printer_data_hotend_temp : update_printer_data_bed_temp, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subscribe_obj(DATA_PRINTER_DATA, label, NULL); + lv_obj_set_width(label, element_width); + + button_temp_rows[tempIter] = lv_create_empty_panel(temp_rows[tempIter]); + lv_layout_flex_row(button_temp_rows[tempIter], LV_FLEX_ALIGN_SPACE_EVENLY); + lv_obj_set_size(button_temp_rows[tempIter], element_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + for (int buttonIter = 0; buttonIter < 3; buttonIter++){ + lv_obj_t * btn = lv_btn_create(button_temp_rows[tempIter]); + lv_obj_add_event_cb(btn, set_temp_via_preset, LV_EVENT_CLICKED, reinterpret_cast(TARGET_HOTEND_CONFIG_1 + buttonIter + tempIter * 3)); + lv_obj_set_flex_grow(btn, 1); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + label = lv_label_create(btn); + lv_label_set_text(label, "???"); + lv_obj_center(label); + lv_obj_add_event_cb(label, update_temp_preset_label, LV_EVENT_MSG_RECEIVED, reinterpret_cast(TARGET_HOTEND_CONFIG_1 + buttonIter + tempIter * 3)); + lv_msg_subscribe_obj(DATA_PRINTER_TEMP_PRESET, label, NULL); + } - btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_pos, btn_row_y_two); - lv_obj_add_event_cb(btn, set_temp_via_preset, LV_EVENT_CLICKED, reinterpret_cast(TARGET_BED_CONFIG_1 + i)); - lv_obj_set_width(btn, panel_width / 4 - 10); + lv_obj_t * btn = lv_btn_create(button_temp_rows[tempIter]); + lv_obj_add_event_cb(btn, (tempIter == 0) ? show_keyboard_with_hotend : show_keyboard_with_bed, LV_EVENT_CLICKED, panel); + lv_obj_set_flex_grow(btn, 1); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); label = lv_label_create(btn); - lv_label_set_text(label, "???"); + lv_label_set_text(label, "Set"); lv_obj_center(label); - lv_obj_add_event_cb(label, update_temp_preset_label, LV_EVENT_MSG_RECEIVED, reinterpret_cast(TARGET_BED_CONFIG_1 + i)); - lv_msg_subscribe_obj(DATA_PRINTER_TEMP_PRESET, label, NULL); } - btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 10, -50); - lv_obj_set_size(btn, panel_width / 2 - 15, 40); - lv_obj_add_event_cb(btn, cooldown_temp, LV_EVENT_CLICKED, panel); + lv_obj_t * bottom_panel = lv_create_empty_panel(panel); + lv_obj_set_size(bottom_panel, element_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(bottom_panel, LV_ALIGN_BOTTOM_MID, 0, -1 * CYD_SCREEN_BIG_GAP_PX); + lv_layout_flex_row(bottom_panel, LV_FLEX_ALIGN_SPACE_EVENLY); - label = lv_label_create(btn); - lv_label_set_text(label, "Cooldown"); + lv_obj_t * one_above_bottom_panel = lv_create_empty_panel(panel); + lv_obj_set_size(one_above_bottom_panel, element_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(one_above_bottom_panel, LV_ALIGN_BOTTOM_MID, 0, -1 * CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); + lv_layout_flex_row(one_above_bottom_panel, LV_FLEX_ALIGN_SPACE_EVENLY); + + lv_obj_t * btn = lv_btn_create(bottom_panel); + lv_obj_set_flex_grow(btn, 1); + lv_obj_add_event_cb(btn, btn_extrude, LV_EVENT_CLICKED, NULL); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_DOWN " Extrude"); lv_obj_center(label); - btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -10, -50); - lv_obj_add_event_cb(btn, btn_toggleable_edit, LV_EVENT_CLICKED, NULL); - lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE); - lv_obj_set_size(btn, panel_width / 2 - 15, 40); + btn = lv_btn_create(one_above_bottom_panel); + lv_obj_set_flex_grow(btn, 1); + lv_obj_add_event_cb(btn, btn_retract, LV_EVENT_CLICKED, NULL); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); label = lv_label_create(btn); - lv_label_set_text(label, "Edit Presets"); + lv_label_set_text(label, LV_SYMBOL_UP " Retract"); lv_obj_center(label); - btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 10, -5); - lv_obj_add_event_cb(btn, btn_extrude, LV_EVENT_CLICKED, NULL); - lv_obj_set_size(btn, panel_width / 2 - 15, 40); + btn = lv_btn_create(bottom_panel); + lv_obj_set_flex_grow(btn, 1); + lv_obj_add_event_cb(btn, cooldown_temp, LV_EVENT_CLICKED, NULL); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_DOWN " Extrude"); + lv_label_set_text(label, "Cooldown"); lv_obj_center(label); - btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -10, -5); - lv_obj_add_event_cb(btn, btn_retract, LV_EVENT_CLICKED, NULL); - lv_obj_set_size(btn, panel_width / 2 - 15, 40); + btn = lv_btn_create(one_above_bottom_panel); + lv_obj_set_flex_grow(btn, 1); + lv_obj_add_event_cb(btn, btn_toggleable_edit, LV_EVENT_CLICKED, NULL); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_flag(btn, LV_OBJ_FLAG_CHECKABLE); label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_UP " Retract"); + lv_label_set_text(label, "Edit Presets"); lv_obj_center(label); lv_msg_send(DATA_PRINTER_TEMP_PRESET, &printer); From c65cc08eb374b9ceed29ad09bafffeb9e75d2736 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sun, 28 Jan 2024 19:23:35 +0100 Subject: [PATCH 28/45] Don't break macros --- CYD-Klipper/src/ui/panels/macros_panel.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 920a47a..649de2f 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -55,6 +55,7 @@ void macros_panel_init(lv_obj_t* panel) { 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); From 292f879780fdc6928ad551efc38a742de4125e7b Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:32:38 +0100 Subject: [PATCH 29/45] Make move panel responsive --- CYD-Klipper/src/core/macros_query.cpp | 2 +- CYD-Klipper/src/ui/main_ui.cpp | 1 - CYD-Klipper/src/ui/panels/move_panel.cpp | 103 ++++++++++++++++++++++- 3 files changed, 102 insertions(+), 4 deletions(-) diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index 909f4fc..0b6e9b0 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -42,7 +42,7 @@ static void on_state_change(void * s, lv_msg_t * m) { } MACROSQUERY macros_query() { - return {(const char**)macros, macros_count}; + return {(const char**)macros, (unsigned int)macros_count}; } void macros_query_setup(){ diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index cc37bc1..9366141 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -72,7 +72,6 @@ static void on_state_change(void * s, lv_msg_t * m){ } } - void main_ui_setup(){ lv_msg_subscribe(DATA_PRINTER_STATE, on_state_change, NULL); on_state_change(NULL, NULL); diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 8ba8e49..0fef115 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -2,6 +2,9 @@ #include "panel.h" #include "../../core/data_setup.h" #include +#include "../ui_utils.h" + +static bool last_homing_state = false; static void move_printer(const char* axis, float amount) { if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING) @@ -72,7 +75,7 @@ lv_event_cb_t button_callbacks[] = {x_line_button_press, y_line_button_press, z_ lv_event_cb_t position_callbacks[] = {x_pos_update, y_pos_update, z_pos_update}; const float xy_offsets[] = {-100, -10, -1, 1, 10, 100}; -const float z_offsets[] = {-25, -1, -0.1, 0.1, 1, 25}; +const float z_offsets[] = {-10, -1, -0.1, 0.1, 1, 10}; const float* offsets[] = { xy_offsets, xy_offsets, @@ -80,7 +83,7 @@ const float* offsets[] = { }; const char* xy_offset_labels[] = {"-100", "-10", "-1", "+1", "+10", "+100"}; -const char* z_offset_labels[] = {"-25", "-1", "-0.1", "+0.1", "+1", "+25"}; +const char* z_offset_labels[] = {"-10", "-1", "-0.1", "+0.1", "+1", "+10"}; const char** offset_labels[] = { xy_offset_labels, @@ -107,7 +110,103 @@ static void stepper_state_update(lv_event_t * e){ lv_label_set_text(label, printer.homed_axis ? LV_SYMBOL_HOME " Steppers locked" : LV_SYMBOL_EYE_CLOSE " Steppers unlocked"); } +inline void root_panel_steppers_locked(lv_obj_t * root_panel){ + const auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_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_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_layout_flex_column(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, 0, 0); + + lv_obj_t * home_button_row = lv_create_empty_panel(panel); + lv_obj_set_size(home_button_row, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_layout_flex_row(home_button_row); + + lv_obj_t * btn = lv_btn_create(home_button_row); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, home_button_click, LV_EVENT_CLICKED, NULL); + lv_obj_set_flex_grow(btn, 1); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_HOME "Home Axis"); + lv_obj_center(label); + + btn = lv_btn_create(home_button_row); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, disable_steppers_click, LV_EVENT_CLICKED, NULL); + lv_obj_set_flex_grow(btn, 1); + + label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Disable Step"); + lv_obj_center(label); + + for (int row = 0; row < 3; row++) { + label = lv_label_create(panel); + lv_label_set_text(label, "???"); + lv_obj_set_width(label, width); + lv_obj_add_event_cb(label, position_callbacks[row], LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); + + lv_obj_t * row_panel = lv_create_empty_panel(panel); + lv_obj_set_size(row_panel, width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_layout_flex_row(row_panel); + + for (int col = 0; col < 6; col++) + { + btn = lv_btn_create(row_panel); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, button_callbacks[row], LV_EVENT_CLICKED, (void*)(offsets[row] + col)); + lv_obj_set_flex_grow(btn, 1); + + label = lv_label_create(btn); + lv_label_set_text(label, offset_labels[row][col]); + lv_obj_center(label); + } + } + +} + +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_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER); + + lv_obj_t * label = lv_label_create(panel); + lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Steppers unlocked"); + + lv_obj_t * btn = lv_btn_create(panel); + lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, home_button_click, LV_EVENT_CLICKED, NULL); + + label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_HOME "Home Axis"); + lv_obj_center(label); +} + +static void root_panel_state_update(lv_event_t * e){ + if (last_homing_state == printer.homed_axis) + return; + + lv_obj_t * panel = lv_event_get_target(e); + last_homing_state = printer.homed_axis; + + lv_obj_clean(panel); + + if (printer.homed_axis) + root_panel_steppers_locked(panel); + else + root_panel_steppers_unlocked(panel); +} + void move_panel_init(lv_obj_t* panel){ + last_homing_state = !printer.homed_axis; + + lv_obj_add_event_cb(panel, root_panel_state_update, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subsribe_obj(DATA_PRINTER_DATA, panel, NULL); + + return; + lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE); const int button_size = 40; const int button_size_vertical = 40; From c5b6401c605df02f384f7fc0c4dc80838175223c Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:34:25 +0100 Subject: [PATCH 30/45] Remove unneeded code --- CYD-Klipper/src/ui/panels/move_panel.cpp | 104 ----------------------- 1 file changed, 104 deletions(-) diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 0fef115..36825db 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -105,11 +105,6 @@ static void disable_steppers_click(lv_event_t * e) { send_gcode(true, "M18"); } -static void stepper_state_update(lv_event_t * e){ - lv_obj_t * label = lv_event_get_target(e); - lv_label_set_text(label, printer.homed_axis ? LV_SYMBOL_HOME " Steppers locked" : LV_SYMBOL_EYE_CLOSE " Steppers unlocked"); -} - inline void root_panel_steppers_locked(lv_obj_t * root_panel){ const auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2; @@ -204,103 +199,4 @@ void move_panel_init(lv_obj_t* panel){ lv_obj_add_event_cb(panel, root_panel_state_update, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subsribe_obj(DATA_PRINTER_DATA, panel, NULL); - - return; - - lv_obj_clear_flag(panel, LV_OBJ_FLAG_SCROLLABLE); - const int button_size = 40; - const int button_size_vertical = 40; - const int button_padding = 2; - const int x_offset = 15; - int y_pos = 75; - - auto panel_width = TFT_HEIGHT - 40; - - lv_obj_t * home_button = lv_btn_create(panel); - lv_obj_align(home_button, LV_ALIGN_TOP_LEFT, 10, 5); - lv_obj_add_event_cb(home_button, home_button_click, LV_EVENT_CLICKED, NULL); - lv_obj_set_size(home_button, panel_width / 2 - 15, 30); - - lv_obj_t * home_label = lv_label_create(home_button); - lv_label_set_text(home_label, LV_SYMBOL_HOME "Home Axis"); - lv_obj_center(home_label); - - lv_obj_t * disable_steppers_button = lv_btn_create(panel); - lv_obj_align(disable_steppers_button, LV_ALIGN_TOP_RIGHT, -10, 5); - lv_obj_add_event_cb(disable_steppers_button, disable_steppers_click, LV_EVENT_CLICKED, NULL); - lv_obj_set_size(disable_steppers_button, panel_width / 2 - 15, 30); - - lv_obj_t * disable_steppers_label = lv_label_create(disable_steppers_button); - lv_label_set_text(disable_steppers_label, LV_SYMBOL_EYE_CLOSE "Disable Step"); - lv_obj_center(disable_steppers_label); - - lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, "???"); - lv_obj_align(label, LV_ALIGN_TOP_MID, 0, 40); - lv_obj_add_event_cb(label, stepper_state_update, LV_EVENT_MSG_RECEIVED, NULL); - lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); - - for (int i = 0; i < 3; i++) { - lv_obj_t * btn = lv_btn_create(panel); - lv_obj_set_size(btn, button_size, button_size_vertical); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset, y_pos); - lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i])); - - lv_obj_t * label = lv_label_create(btn); - lv_label_set_text(label, offset_labels[i][0]); - lv_obj_center(label); - - btn = lv_btn_create(panel); - lv_obj_set_size(btn, button_size, button_size_vertical); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 1, y_pos); - lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 1)); - - label = lv_label_create(btn); - lv_label_set_text(label, offset_labels[i][1]); - lv_obj_center(label); - - btn = lv_btn_create(panel); - lv_obj_set_size(btn, button_size, button_size_vertical); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 2, y_pos); - lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 2)); - - label = lv_label_create(btn); - lv_label_set_text(label, offset_labels[i][2]); - lv_obj_center(label); - - btn = lv_btn_create(panel); - lv_obj_set_size(btn, button_size, button_size_vertical); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 3, y_pos); - lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 3)); - - label = lv_label_create(btn); - lv_label_set_text(label, offset_labels[i][3]); - lv_obj_center(label); - - btn = lv_btn_create(panel); - lv_obj_set_size(btn, button_size, button_size_vertical); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 4, y_pos); - lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 4)); - - label = lv_label_create(btn); - lv_label_set_text(label, offset_labels[i][4]); - lv_obj_center(label); - - btn = lv_btn_create(panel); - lv_obj_set_size(btn, button_size, button_size_vertical); - lv_obj_align(btn, LV_ALIGN_TOP_LEFT, x_offset + (button_size + button_padding) * 5, y_pos); - lv_obj_add_event_cb(btn, button_callbacks[i], LV_EVENT_CLICKED, (void*)(offsets[i] + 5)); - - label = lv_label_create(btn); - lv_label_set_text(label, offset_labels[i][5]); - lv_obj_center(label); - - label = lv_label_create(panel); - lv_label_set_text(label, "???"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, x_offset, y_pos - 15);\ - lv_obj_add_event_cb(label, position_callbacks[i], LV_EVENT_MSG_RECEIVED, NULL); - lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); - - y_pos += 60; - } } \ No newline at end of file From de1833e2190396d242f402860986863fbef2ca28 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:51:25 +0100 Subject: [PATCH 31/45] Make klipper error screen responsive --- .../src/core/device/ESP32-2432S028R.cpp | 8 ++--- CYD-Klipper/src/ui/main_ui.cpp | 31 ++++++++++++------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index 489bea3..59dfad1 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -21,7 +21,7 @@ XPT2046_Touchscreen touchscreen(XPT2046_CS, XPT2046_IRQ); uint32_t LV_EVENT_GET_COMP_CHILD; static lv_disp_draw_buf_t draw_buf; -static lv_color_t buf[TFT_WIDTH * TFT_HEIGHT / 10]; +static lv_color_t buf[CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10]; TFT_eSPI tft = TFT_eSPI(); @@ -242,13 +242,13 @@ void screen_setup() touchscreen_calibrate(false); - lv_disp_draw_buf_init(&draw_buf, buf, NULL, TFT_WIDTH * TFT_HEIGHT / 10); + lv_disp_draw_buf_init(&draw_buf, buf, NULL, CYD_SCREEN_HEIGHT_PX * CYD_SCREEN_WIDTH_PX / 10); /*Initialize the display*/ 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; + disp_drv.hor_res = CYD_SCREEN_WIDTH_PX; + disp_drv.ver_res = CYD_SCREEN_HEIGHT_PX; 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/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index 9366141..47134b7 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -4,6 +4,7 @@ #include "../core/screen_driver.h" #include "lvgl.h" #include "nav_buttons.h" +#include "ui_utils.h" char extruder_temp_buff[20]; char bed_temp_buff[20]; @@ -19,32 +20,40 @@ static void btn_click_firmware_restart(lv_event_t * e){ 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_BIG_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(lv_scr_act()); + label = lv_label_create(panel); lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 10); - label = lv_label_create(lv_scr_act()); + label = lv_label_create(panel); lv_label_set_text(label, printer.state_message); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 30); - lv_obj_set_size(label, TFT_HEIGHT - 20, TFT_WIDTH - 30); + lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_BIG_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 * btn = lv_btn_create(lv_scr_act()); - lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 10, -10); - lv_obj_set_size(btn, TFT_HEIGHT / 2 - 15, 30); + lv_obj_t * button_row = lv_create_empty_panel(panel); + lv_obj_set_size(button_row, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_BIG_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(lv_scr_act()); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -10, -10); - lv_obj_set_size(btn, TFT_HEIGHT / 2 - 15, 30); + 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, "Firmware Restart"); From 0ba2abd6b1444b9399982a66e2aae446b995ec6a Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:56:03 +0100 Subject: [PATCH 32/45] Rename BIG_GAP to GAP --- CYD-Klipper/platformio.ini | 4 +--- CYD-Klipper/src/main.cpp | 10 ---------- CYD-Klipper/src/ui/main_ui.cpp | 6 +++--- CYD-Klipper/src/ui/nav_buttons.cpp | 4 ++-- CYD-Klipper/src/ui/panels/macros_panel.cpp | 12 ++++++------ CYD-Klipper/src/ui/panels/move_panel.cpp | 6 +++--- CYD-Klipper/src/ui/panels/print_panel.cpp | 6 +++--- CYD-Klipper/src/ui/panels/progress_panel.cpp | 6 +++--- CYD-Klipper/src/ui/panels/settings_panel.cpp | 6 +++--- CYD-Klipper/src/ui/panels/temp_panel.cpp | 8 ++++---- CYD-Klipper/src/ui/ui_utils.h | 4 ++-- 11 files changed, 30 insertions(+), 42 deletions(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 45b41d6..ce76e7e 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -48,9 +48,7 @@ build_flags = # Defines the screen width -DCYD_SCREEN_WIDTH_PX=320 # Defines the pixel gap used for large gaps (like between buttons) - -DCYD_SCREEN_BIG_GAP_PX=8 - # Defines the pixel gap used for small gaps (like between text and buttons) - -DCYD_SCREEN_SMALL_GAP_PX=4 + -DCYD_SCREEN_GAP_PX=8 # Defines the minimum pixel height of a button -DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35 # Defines the minimum pixel width of a button diff --git a/CYD-Klipper/src/main.cpp b/CYD-Klipper/src/main.cpp index 4b6b0af..2218658 100644 --- a/CYD-Klipper/src/main.cpp +++ b/CYD-Klipper/src/main.cpp @@ -8,16 +8,6 @@ #include "ui/nav_buttons.h" #include -static void event_handler(lv_event_t * e){ - lv_event_code_t code = lv_event_get_code(e); - - if(code == LV_EVENT_CLICKED) { - global_config.version = 0; - WriteGlobalConfig(); - ESP.restart(); - } -} - void setup() { Serial.begin(115200); Serial.println("Hello World"); diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index 47134b7..eedb049 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -24,7 +24,7 @@ void error_ui(){ 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_BIG_GAP_PX, 0); + 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; @@ -33,12 +33,12 @@ void error_ui(){ label = lv_label_create(panel); lv_label_set_text(label, printer.state_message); - lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2); + 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_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + 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); diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index ad55fab..4bc7cb2 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -86,11 +86,11 @@ void create_button(const char* icon, const char* name, lv_event_cb_t button_clic lv_obj_t* label = lv_label_create(btn); lv_label_set_text(label, icon); - lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * CYD_SCREEN_BIG_GAP_PX); + lv_obj_align(label, LV_ALIGN_CENTER, 0, -1 * CYD_SCREEN_GAP_PX); label = lv_label_create(btn); lv_label_set_text(label, name); - lv_obj_align(label, LV_ALIGN_CENTER, 0, CYD_SCREEN_BIG_GAP_PX); + lv_obj_align(label, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX); lv_obj_add_event_cb(label, label_update, LV_EVENT_MSG_RECEIVED, NULL); lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); lv_obj_add_style(label, &nav_button_text_style, 0); diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 649de2f..2bf6bc3 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -6,7 +6,7 @@ #include "../ui_utils.h" #include -const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; +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); @@ -22,8 +22,8 @@ static void btn_goto_settings(lv_event_t * e){ 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); - lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_BIG_GAP_PX); + lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX); lv_obj_t * label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_SETTINGS " Screen Settings"); @@ -38,8 +38,8 @@ void macros_panel_init(lv_obj_t* panel) { } lv_obj_t * root_panel = lv_create_empty_panel(panel); - lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); - lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_BIG_GAP_PX * 2); + lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); + lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2); lv_layout_flex_column(root_panel); for (int i = 0; i < query.count; i++){ @@ -47,7 +47,7 @@ void macros_panel_init(lv_obj_t* panel) { 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_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + 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); diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 36825db..4da42b0 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -106,11 +106,11 @@ static void disable_steppers_click(lv_event_t * e) { } inline void root_panel_steppers_locked(lv_obj_t * root_panel){ - const auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2; + 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_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, 0, 0); lv_obj_t * home_button_row = lv_create_empty_panel(panel); @@ -164,7 +164,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_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(panel, LV_FLEX_ALIGN_CENTER); lv_obj_t * label = lv_label_create(panel); diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index 2229e92..32837ab 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -52,8 +52,8 @@ static void btn_print_file_verify(lv_event_t * e){ selected_file = (FILESYSTEM_FILE*)lv_event_get_user_data(e); lv_obj_t * panel = lv_obj_create(lv_scr_act()); - lv_obj_set_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX * 2, 0); - lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 4, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 3); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX * 2, 0); + 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); @@ -63,7 +63,7 @@ static void btn_print_file_verify(lv_event_t * e){ 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_BIG_GAP_PX * 10); + lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 10); lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); btn = lv_btn_create(panel); diff --git a/CYD-Klipper/src/ui/panels/progress_panel.cpp b/CYD-Klipper/src/ui/panels/progress_panel.cpp index 0950161..7aa84ef 100644 --- a/CYD-Klipper/src/ui/panels/progress_panel.cpp +++ b/CYD-Klipper/src/ui/panels/progress_panel.cpp @@ -48,7 +48,7 @@ static void btn_click_resume(lv_event_t * e){ } void progress_panel_init(lv_obj_t* panel){ - auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 3; + auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3; const auto button_size_mult = 1.3f; lv_obj_t * center_panel = lv_create_empty_panel(panel); @@ -95,7 +95,7 @@ void progress_panel_init(lv_obj_t* panel){ // Stop Button lv_obj_t * btn = lv_btn_create(panel); - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -1 * CYD_SCREEN_BIG_GAP_PX, -1 * CYD_SCREEN_BIG_GAP_PX); + lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -1 * CYD_SCREEN_GAP_PX, -1 * CYD_SCREEN_GAP_PX); lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); lv_obj_add_event_cb(btn, btn_click_stop, LV_EVENT_CLICKED, NULL); @@ -122,6 +122,6 @@ void progress_panel_init(lv_obj_t* panel){ lv_obj_center(label); } - lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -2 * CYD_SCREEN_BIG_GAP_PX - CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, -1 * CYD_SCREEN_BIG_GAP_PX); + lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -2 * CYD_SCREEN_GAP_PX - CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, -1 * CYD_SCREEN_GAP_PX); lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); } \ 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 caf5c9f..8b6972c 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -82,13 +82,13 @@ static void on_during_print_switch(lv_event_t* e){ WriteGlobalConfig(); } -const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2) * 0.85f), 0} }; +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){ lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * panel = lv_create_empty_panel(root_panel); - lv_obj_set_size(panel, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + 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); @@ -104,7 +104,7 @@ void create_settings_widget(const char* label_text, lv_obj_t* object, lv_obj_t* } void settings_panel_init(lv_obj_t* panel){ - lv_obj_set_style_pad_all(panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(panel); lv_obj_t * btn = lv_btn_create(panel); diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index 4c7f2b3..34a7350 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -205,14 +205,14 @@ static void btn_retract(lv_event_t * e){ } void temp_panel_init(lv_obj_t * panel){ - const auto element_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_BIG_GAP_PX * 2; + 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, LV_SIZE_CONTENT); lv_obj_align(root_temp_panel, LV_ALIGN_TOP_RIGHT, 0, 0); - lv_obj_set_style_pad_all(root_temp_panel, CYD_SCREEN_BIG_GAP_PX, 0); + lv_obj_set_style_pad_all(root_temp_panel, CYD_SCREEN_GAP_PX, 0); lv_layout_flex_column(root_temp_panel); lv_obj_t * temp_rows[2] = {0}; @@ -258,12 +258,12 @@ void temp_panel_init(lv_obj_t * panel){ lv_obj_t * bottom_panel = lv_create_empty_panel(panel); lv_obj_set_size(bottom_panel, element_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_align(bottom_panel, LV_ALIGN_BOTTOM_MID, 0, -1 * CYD_SCREEN_BIG_GAP_PX); + lv_obj_align(bottom_panel, LV_ALIGN_BOTTOM_MID, 0, -1 * CYD_SCREEN_GAP_PX); lv_layout_flex_row(bottom_panel, LV_FLEX_ALIGN_SPACE_EVENLY); lv_obj_t * one_above_bottom_panel = lv_create_empty_panel(panel); lv_obj_set_size(one_above_bottom_panel, element_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_align(one_above_bottom_panel, LV_ALIGN_BOTTOM_MID, 0, -1 * CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_BIG_GAP_PX * 2); + lv_obj_align(one_above_bottom_panel, LV_ALIGN_BOTTOM_MID, 0, -1 * CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_layout_flex_row(one_above_bottom_panel, LV_FLEX_ALIGN_SPACE_EVENLY); lv_obj_t * btn = lv_btn_create(bottom_panel); diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index f5074a5..96dd2e2 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -4,5 +4,5 @@ (CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) 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_BIG_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_BIG_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_BIG_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_BIG_GAP_PX); \ No newline at end of file +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); \ No newline at end of file From 982c03b0f6e16c678a386257d2d4fab72e951f37 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 30 Jan 2024 19:02:59 +0100 Subject: [PATCH 33/45] Make wifi-setup responsive --- CYD-Klipper/src/ui/wifi_setup.cpp | 55 +++++++++++++++++++++---------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/CYD-Klipper/src/ui/wifi_setup.cpp b/CYD-Klipper/src/ui/wifi_setup.cpp index c86c5fd..d221933 100644 --- a/CYD-Klipper/src/ui/wifi_setup.cpp +++ b/CYD-Klipper/src/ui/wifi_setup.cpp @@ -1,8 +1,9 @@ #include "lvgl.h" #include "wifi_setup.h" #include "../conf/global_config.h" - +#include "ui_utils.h" #include "WiFi.h" + void wifi_init_inner(); static void reset_btn_event_handler(lv_event_t * e) { @@ -47,18 +48,28 @@ static void ta_event_cb(lv_event_t * e) { void wifi_pass_entry(const char* ssid){ lv_obj_clean(lv_scr_act()); - lv_obj_t * label = lv_label_create(lv_scr_act()); + lv_obj_t * root = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_size(root, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_layout_flex_column(root); + + lv_obj_t * top_root = lv_create_empty_panel(root); + lv_obj_set_width(top_root, CYD_SCREEN_WIDTH_PX); + lv_layout_flex_column(top_root); + lv_obj_set_flex_grow(top_root, 1); + lv_obj_set_style_pad_all(top_root, CYD_SCREEN_GAP_PX, 0); + + lv_obj_t * label = lv_label_create(top_root); lv_label_set_text(label, "Enter WiFi Password"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 10 + 2); + lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); - lv_obj_t * passEntry = lv_textarea_create(lv_scr_act()); + lv_obj_t * passEntry = lv_textarea_create(top_root); lv_textarea_set_one_line(passEntry, true); lv_textarea_set_text(passEntry, ""); - lv_obj_align(passEntry, LV_ALIGN_TOP_LEFT, 10, 40); + lv_obj_set_width(passEntry, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); lv_obj_add_event_cb(passEntry, ta_event_cb, LV_EVENT_ALL, NULL); - lv_obj_set_size(passEntry, TFT_HEIGHT - 20, 60); + lv_obj_set_flex_grow(passEntry, 1); - lv_obj_t * keyboard = lv_keyboard_create(lv_scr_act()); + lv_obj_t * keyboard = lv_keyboard_create(root); lv_keyboard_set_textarea(keyboard, passEntry); } @@ -74,7 +85,6 @@ static void wifi_btn_event_handler(lv_event_t * e){ } } - void wifi_init_inner(){ WiFi.disconnect(); lv_obj_clean(lv_scr_act()); @@ -88,7 +98,8 @@ void wifi_init_inner(){ lv_obj_t * resetBtn = lv_btn_create(lv_scr_act()); lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); - lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, 40); + lv_obj_set_height(resetBtn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); label = lv_label_create(resetBtn); lv_label_set_text(label, "Reset"); @@ -107,21 +118,29 @@ void wifi_init_inner(){ lv_obj_clean(lv_scr_act()); - lv_obj_t * refreshBtn = lv_btn_create(lv_scr_act()); + lv_obj_t * root = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_size(root, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_layout_flex_column(root); + lv_obj_set_style_pad_all(root, CYD_SCREEN_GAP_PX, 0); + + lv_obj_t * top_row = lv_create_empty_panel(root); + lv_obj_set_size(top_row, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, LV_SIZE_CONTENT); + lv_layout_flex_row(top_row, LV_FLEX_ALIGN_SPACE_BETWEEN); + + label = lv_label_create(top_row); + lv_label_set_text(label, "Select a network"); + + lv_obj_t * refreshBtn = lv_btn_create(top_row); lv_obj_add_event_cb(refreshBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); - lv_obj_align(refreshBtn, LV_ALIGN_TOP_RIGHT, -5, 5 - 1); + lv_obj_set_size(refreshBtn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); label = lv_label_create(refreshBtn); lv_label_set_text(label, LV_SYMBOL_REFRESH); lv_obj_center(label); - label = lv_label_create(lv_scr_act()); - lv_label_set_text(label, "Select a network"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 10 + 2); - - lv_obj_t * list = lv_list_create(lv_scr_act()); - lv_obj_align(list, LV_ALIGN_TOP_LEFT, 10, 40); - lv_obj_set_size(list, TFT_HEIGHT - 20, TFT_WIDTH - 40 - 5); + lv_obj_t * list = lv_list_create(root); + lv_obj_set_width(list, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); + lv_obj_set_flex_grow(list, 1); int n = WiFi.scanNetworks(); From 899f89b57d651126217f64c78fd69393d05451c7 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 30 Jan 2024 20:12:42 +0100 Subject: [PATCH 34/45] Make ip setup responsive --- CYD-Klipper/src/ui/ip_setup.cpp | 36 +++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index deb6fda..c6a3930 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -4,6 +4,7 @@ #include #include #include "core/data_setup.h" +#include "ui_utils.h" bool connect_ok = false; lv_obj_t * ipEntry; @@ -87,29 +88,42 @@ void ip_init_inner(){ return; } - lv_obj_t * keyboard = lv_keyboard_create(lv_scr_act()); - label = lv_label_create(lv_scr_act()); + lv_obj_t * root = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_size(root, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); + lv_layout_flex_column(root); + + lv_obj_t * top_root = lv_create_empty_panel(root); + lv_obj_set_width(top_root, CYD_SCREEN_WIDTH_PX); + lv_layout_flex_column(top_root); + lv_obj_set_flex_grow(top_root, 1); + lv_obj_set_style_pad_all(top_root, CYD_SCREEN_GAP_PX, 0); + + label = lv_label_create(top_root); lv_label_set_text(label, "Enter Klipper IP and Port"); - lv_obj_align(label, LV_ALIGN_TOP_LEFT, 10, 10 + 2); + lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); - ipEntry = lv_textarea_create(lv_scr_act()); + lv_obj_t * textbow_row = lv_create_empty_panel(top_root); + lv_obj_set_width(textbow_row, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); + lv_obj_set_flex_grow(textbow_row, 1); + lv_layout_flex_row(textbow_row); + + ipEntry = lv_textarea_create(textbow_row); lv_textarea_set_one_line(ipEntry, true); lv_textarea_set_max_length(ipEntry, 63); lv_textarea_set_text(ipEntry, ""); - lv_obj_align(ipEntry, LV_ALIGN_TOP_LEFT, 10, 40); - lv_obj_add_event_cb(ipEntry, ta_event_cb, LV_EVENT_ALL, keyboard); - lv_obj_set_size(ipEntry, TFT_HEIGHT - 20 - 100, 60); + lv_obj_set_flex_grow(ipEntry, 3); - portEntry = lv_textarea_create(lv_scr_act()); + portEntry = lv_textarea_create(textbow_row); lv_textarea_set_one_line(portEntry, true); lv_textarea_set_max_length(portEntry, 5); lv_textarea_set_text(portEntry, "80"); - lv_obj_align(portEntry, LV_ALIGN_TOP_LEFT, TFT_HEIGHT - 20 - 80, 40); - lv_obj_add_event_cb(portEntry, ta_event_cb, LV_EVENT_ALL, keyboard); - lv_obj_set_size(portEntry, 90, 60); + lv_obj_set_flex_grow(portEntry, 1); + lv_obj_t * keyboard = lv_keyboard_create(root); lv_keyboard_set_mode(keyboard, LV_KEYBOARD_MODE_NUMBER); lv_keyboard_set_textarea(keyboard, ipEntry); + lv_obj_add_event_cb(ipEntry, ta_event_cb, LV_EVENT_ALL, keyboard); + lv_obj_add_event_cb(portEntry, ta_event_cb, LV_EVENT_ALL, keyboard); } long last_data_update_ip = -10000; From c077b6e6176ff3ddca2f7521f86426d90cdd6f32 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 30 Jan 2024 20:32:45 +0100 Subject: [PATCH 35/45] Remove leftover defines --- CYD-Klipper/platformio.ini | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index ce76e7e..6b257d7 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -24,10 +24,8 @@ build_flags = -DLV_CONF_PATH="../../../../src/conf/lv_conf.h" -DUSER_SETUP_LOADED=1 -DILI9341_2_DRIVER=1 - -DTFT_WIDTH=240 - -DTFT_HEIGHT=320 - -DTFT_BL=21 -DTFT_BACKLIGHT_ON=HIGH + -DTFT_BL=21 -DTFT_MISO=12 -DTFT_MOSI=13 -DTFT_SCLK=14 From a84c695a9f1e485bcc09d7ad96a57832da3fef8e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 30 Jan 2024 20:39:00 +0100 Subject: [PATCH 36/45] Kickstart workflow --- .github/workflows/compile.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 179f9e4..9b232d4 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -17,7 +17,7 @@ jobs: path: | ~/.cache/pip ~/.platformio/.cache - key: ${{ runner.os }}-pio + key: ${{ runner.os }}-pio-cyd-klipper - uses: actions/setup-python@v4 with: From 9c12588187274f6f2a22c352090f8e9c70f5ebba Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 30 Jan 2024 20:47:56 +0100 Subject: [PATCH 37/45] CI pls --- CYD-Klipper/src/conf/lv_conf.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CYD-Klipper/src/conf/lv_conf.h b/CYD-Klipper/src/conf/lv_conf.h index e086ff1..d5979b6 100644 --- a/CYD-Klipper/src/conf/lv_conf.h +++ b/CYD-Klipper/src/conf/lv_conf.h @@ -335,7 +335,7 @@ #define LV_FONT_MONTSERRAT_22 0 #define LV_FONT_MONTSERRAT_24 0 #define LV_FONT_MONTSERRAT_26 0 -#define LV_FONT_MONTSERRAT_28 0 +#define LV_FONT_MONTSERRAT_28 1 #define LV_FONT_MONTSERRAT_30 0 #define LV_FONT_MONTSERRAT_32 0 #define LV_FONT_MONTSERRAT_34 0 From 4e7bff92c9721fb9b0fc23ad4759a7c31b3fd0a9 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Tue, 30 Jan 2024 20:50:35 +0100 Subject: [PATCH 38/45] Test CI 2 --- .github/workflows/compile.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/compile.yaml b/.github/workflows/compile.yaml index 9b232d4..f3a1a85 100644 --- a/.github/workflows/compile.yaml +++ b/.github/workflows/compile.yaml @@ -8,7 +8,7 @@ on: [push, pull_request] jobs: build: - runs-on: ubuntu-latest + runs-on: windows-latest steps: - uses: actions/checkout@v3 From 1ff75d2aa593aa2f2d7d662af5b796d986797918 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:10:40 +0100 Subject: [PATCH 39/45] Process feedback partially --- CYD-Klipper/src/core/device/ESP32-2432S028R.cpp | 7 +++++-- CYD-Klipper/src/core/device/ESP32-2432S028R.h | 1 - CYD-Klipper/src/core/screen_driver.h | 6 ------ CYD-Klipper/src/ui/panels/settings_panel.cpp | 4 ++++ 4 files changed, 9 insertions(+), 9 deletions(-) delete mode 100644 CYD-Klipper/src/core/device/ESP32-2432S028R.h diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp index 59dfad1..851e401 100644 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp +++ b/CYD-Klipper/src/core/device/ESP32-2432S028R.cpp @@ -1,4 +1,5 @@ -#include "ESP32-2432S028R.h" +#ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R +#include "../screen_driver.h" #include #include @@ -267,4 +268,6 @@ void screen_setup() /*Initialize the graphics library */ LV_EVENT_GET_COMP_CHILD = lv_event_register_id(); set_color_scheme(); -} \ No newline at end of file +} + +#endif // CYD_SCREEN_DRIVER_ESP32_2432S028R \ No newline at end of file diff --git a/CYD-Klipper/src/core/device/ESP32-2432S028R.h b/CYD-Klipper/src/core/device/ESP32-2432S028R.h deleted file mode 100644 index 7b9637e..0000000 --- a/CYD-Klipper/src/core/device/ESP32-2432S028R.h +++ /dev/null @@ -1 +0,0 @@ -#pragma once \ No newline at end of file diff --git a/CYD-Klipper/src/core/screen_driver.h b/CYD-Klipper/src/core/screen_driver.h index 1e6380c..d1ca104 100644 --- a/CYD-Klipper/src/core/screen_driver.h +++ b/CYD-Klipper/src/core/screen_driver.h @@ -1,12 +1,6 @@ #pragma once // Adapted from https://github.com/xperiments-in/xtouch/blob/main/src/devices/2.8/screen.h -#ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R - #include "device/ESP32-2432S028R.h" -#else - #error "No screen driver defined" -#endif - void touchscreen_calibrate(bool force = false); void screen_setBrightness(unsigned char brightness); void screen_timer_setup(); diff --git a/CYD-Klipper/src/ui/panels/settings_panel.cpp b/CYD-Klipper/src/ui/panels/settings_panel.cpp index 8b6972c..8568128 100644 --- a/CYD-Klipper/src/ui/panels/settings_panel.cpp +++ b/CYD-Klipper/src/ui/panels/settings_panel.cpp @@ -126,6 +126,7 @@ void settings_panel_init(lv_obj_t* panel){ create_settings_widget("Calibrate Touch", btn, panel); lv_obj_t * toggle = lv_switch_create(panel); + lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); lv_obj_add_event_cb(toggle, invert_color_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.invertColors) @@ -135,6 +136,7 @@ void settings_panel_init(lv_obj_t* panel){ toggle = lv_switch_create(panel); + lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); lv_obj_add_event_cb(toggle, light_mode_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.lightMode) @@ -176,6 +178,7 @@ void settings_panel_init(lv_obj_t* panel){ create_settings_widget("Wake Timeout", dropdown, panel); toggle = lv_switch_create(panel); + lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); lv_obj_add_event_cb(toggle, rotate_screen_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.rotateScreen) @@ -184,6 +187,7 @@ void settings_panel_init(lv_obj_t* panel){ create_settings_widget("Rotate Screen", toggle, panel); toggle = lv_switch_create(panel); + lv_obj_set_width(toggle, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * 2); lv_obj_add_event_cb(toggle, on_during_print_switch, LV_EVENT_VALUE_CHANGED, NULL); if (global_config.onDuringPrint) From ba015bb2e87000615d76f5dc2b70ccc358f17f9a Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Thu, 1 Feb 2024 18:18:36 +0100 Subject: [PATCH 40/45] Switch to fork of lvgl for keyboard mods --- CYD-Klipper/platformio.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index 6b257d7..cc99151 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -15,7 +15,7 @@ framework = arduino monitor_speed = 115200 lib_deps = SPI - https://github.com/lvgl/lvgl#74d0a81 + https://github.com/suchmememanyskill/lvgl https://github.com/Bodmer/TFT_eSPI.git https://github.com/PaulStoffregen/XPT2046_Touchscreen.git bblanchon/ArduinoJson@^7.0.0 From 41be4b1a31429829366f43a70fbd2983a4715d24 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 3 Feb 2024 15:16:25 +0100 Subject: [PATCH 41/45] Add stats panel --- CYD-Klipper/platformio.ini | 15 +- CYD-Klipper/src/core/data_setup.cpp | 16 ++- CYD-Klipper/src/core/data_setup.h | 4 + CYD-Klipper/src/ui/ip_setup.cpp | 3 +- CYD-Klipper/src/ui/panels/move_panel.cpp | 9 +- CYD-Klipper/src/ui/panels/panel.h | 3 +- CYD-Klipper/src/ui/panels/stats_panel.cpp | 166 ++++++++++++++++++++++ CYD-Klipper/src/ui/panels/temp_panel.cpp | 18 ++- CYD-Klipper/src/ui/ui_utils.cpp | 61 ++++++++ CYD-Klipper/src/ui/ui_utils.h | 10 +- 10 files changed, 275 insertions(+), 30 deletions(-) create mode 100644 CYD-Klipper/src/ui/panels/stats_panel.cpp diff --git a/CYD-Klipper/platformio.ini b/CYD-Klipper/platformio.ini index cc99151..efe33db 100644 --- a/CYD-Klipper/platformio.ini +++ b/CYD-Klipper/platformio.ini @@ -19,6 +19,7 @@ lib_deps = https://github.com/Bodmer/TFT_eSPI.git https://github.com/PaulStoffregen/XPT2046_Touchscreen.git bblanchon/ArduinoJson@^7.0.0 + plageoj/UrlEncode@^1.0.1 monitor_filters = esp32_exception_decoder build_flags = -DLV_CONF_PATH="../../../../src/conf/lv_conf.h" @@ -39,23 +40,13 @@ build_flags = -DSPI_FREQUENCY=55000000 -DSPI_READ_FREQUENCY=20000000 -DSPI_TOUCH_FREQUENCY=2500000 - - ### Porting options ### - # Defines the screen height + -DCYD_SCREEN_HEIGHT_PX=240 - # Defines the screen width -DCYD_SCREEN_WIDTH_PX=320 - # Defines the pixel gap used for large gaps (like between buttons) -DCYD_SCREEN_GAP_PX=8 - # Defines the minimum pixel height of a button -DCYD_SCREEN_MIN_BUTTON_HEIGHT_PX=35 - # Defines the minimum pixel width of a button -DCYD_SCREEN_MIN_BUTTON_WIDTH_PX=35 - # Defines the size of font used -DCYD_SCREEN_FONT=&lv_font_montserrat_14 - # Defines the size of font used for small text -DCYD_SCREEN_FONT_SMALL=&lv_font_montserrat_10 - # Defines the size of the sizebar -DCYD_SCREEN_SIDEBAR_SIZE_PX=40 - # Defines the screen driver - -DCYD_SCREEN_DRIVER_ESP32_2432S028R=1 \ No newline at end of file + -DCYD_SCREEN_DRIVER_ESP32_2432S028R=1 diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index b02b986..8686c30 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -6,6 +6,7 @@ #include #include #include "macros_query.h" +#include const char *printer_state_messages[] = { "Error", @@ -43,8 +44,9 @@ 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, gcode); + 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); @@ -67,7 +69,7 @@ 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", global_config.klipperHost, global_config.klipperPort); + 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); @@ -139,8 +141,18 @@ void fetch_printer_data() printer.position[0] = status["gcode_move"]["gcode_position"][0]; printer.position[1] = status["gcode_move"]["gcode_position"][1]; printer.position[2] = status["gcode_move"]["gcode_position"][2]; + printer.gcode_offset[0] = status["gcode_move"]["homing_origin"][0]; + printer.gcode_offset[1] = status["gcode_move"]["homing_origin"][1]; + printer.gcode_offset[2] = status["gcode_move"]["homing_origin"][2]; bool absolute_coords = status["gcode_move"]["absolute_coordinates"]; printer.absolute_coords = absolute_coords == true; + printer.speed_mult = status["gcode_move"]["speed_factor"]; + printer.extrude_mult = status["gcode_move"]["extrude_factor"]; + } + + if (status.containsKey("fan")) + { + printer.fan_speed = status["fan"]["speed"]; } if (status.containsKey("virtual_sdcard")) diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index fc0a44f..109f108 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -25,6 +25,10 @@ typedef struct _Printer { float filament_used_mm; char* print_filename; // 0 -> 1 float print_progress; + float fan_speed; // 0 -> 1 + float gcode_offset[3]; + float speed_mult; + float extrude_mult; } Printer; extern Printer printer; diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index c6a3930..ffa236e 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -80,7 +80,8 @@ void ip_init_inner(){ lv_obj_t * resetBtn = lv_btn_create(lv_scr_act()); lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); - lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, 40); + lv_obj_set_height(resetBtn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_t * btnLabel = lv_label_create(resetBtn); lv_label_set_text(btnLabel, "Reset"); diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 4da42b0..d28ecba 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -19,9 +19,7 @@ static void move_printer(const char* axis, float amount) { send_gcode(true, "G91"); } - const char * space = "%20"; - - sprintf(gcode, "G1%s%s%s%.1f%sF6000", space, axis, extra, amount, space); + sprintf(gcode, "G1 %s%s%.1f F6000", axis, extra, amount); send_gcode(true, gcode); if (absolute_coords) { @@ -195,6 +193,11 @@ static void root_panel_state_update(lv_event_t * e){ } void move_panel_init(lv_obj_t* panel){ + if (printer.state == PRINTER_STATE_PRINTING){ + stats_panel_init(panel); + return; + } + last_homing_state = !printer.homed_axis; lv_obj_add_event_cb(panel, root_panel_state_update, LV_EVENT_MSG_RECEIVED, NULL); diff --git a/CYD-Klipper/src/ui/panels/panel.h b/CYD-Klipper/src/ui/panels/panel.h index ac65776..0656035 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -7,4 +7,5 @@ void temp_panel_init(lv_obj_t* panel); void print_panel_init(lv_obj_t* panel); void move_panel_init(lv_obj_t* panel); void progress_panel_init(lv_obj_t* panel); -void macros_panel_init(lv_obj_t* panel); \ No newline at end of file +void macros_panel_init(lv_obj_t* panel); +void stats_panel_init(lv_obj_t* panel); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp new file mode 100644 index 0000000..417bfad --- /dev/null +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -0,0 +1,166 @@ +#include "panel.h" +#include "../ui_utils.h" +#include "../../core/data_setup.h" +#include +#include + +static void set_fan_speed_text(lv_event_t * e) { + lv_obj_t * label = lv_event_get_target(e); + char data[64]; + sprintf(data, "Fan: %.0f%%", printer.fan_speed * 100); + lv_label_set_text(label, data); +} + +static void set_fan_speed(lv_event_t * e){ + int speed = (int)lv_event_get_user_data(e); + char gcode[64]; + sprintf(gcode, "M106 S%d", speed); + send_gcode(true, gcode); +} + +const char* fan_speeds[] = { "0%", "15%", "25%", "35%" }; +const int fan_speeds_values[] = { 0, 38, 64, 90 }; + +const char* fan_speeds_2[] = { "50%", "75%", "100%"}; +const int fan_speeds_values_2[] = { 128, 192, 255 }; + +lv_button_column_t fan_speed_columns[] = { + { set_fan_speed, fan_speeds, (const void**)fan_speeds_values, 4}, + { set_fan_speed, fan_speeds_2, (const void**)fan_speeds_values_2, 3} +}; + +static void set_zoffset_text(lv_event_t * e) { + lv_obj_t * label = lv_event_get_target(e); + char data[64]; + sprintf(data, "Z Offset: %.03f", printer.gcode_offset[2]); + lv_label_set_text(label, data); +} + +static void set_zoffset(lv_event_t * e){ + char* offset = (char*)lv_event_get_user_data(e); + char gcode[64]; + sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s", offset); + send_gcode(true, gcode); +} + +const char* zoffsets[] = { "-0.005", "-0.01", "-0.025", "-0.05" }; +const char* zoffsets_2[] = { "+0.005", "+0.01", "+0.025", "+0.05" }; + +lv_button_column_t zoffset_columns[] = { + { set_zoffset, zoffsets, (const void**)zoffsets, 4}, + { set_zoffset, zoffsets_2, (const void**)zoffsets_2, 4} +}; + +static void set_speed_mult_text(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char data[64]; + sprintf(data, "Speed: %.0f%%", printer.speed_mult * 100); + lv_label_set_text(label, data); +} + +static void set_speed_mult(lv_event_t * e){ + int speed = (int)lv_event_get_user_data(e); + char gcode[64]; + sprintf(gcode, "M220 S%d", speed); + send_gcode(true, gcode); +} + +static void set_speed_mult_offset(lv_event_t * e){ + int speed = (int)lv_event_get_user_data(e); + float result = printer.speed_mult * 100 + speed; + printer.speed_mult = result / 100; + char gcode[64]; + sprintf(gcode, "M220 S%.0f", result); + send_gcode(true, gcode); +} + +const char* speed_presets[] = { "50%", "100%", "150%", "200%" }; +const int speed_presets_values[] = { 50, 100, 150, 200 }; +const char* speed_presets_minus[] = { "-1%", "-5%", "-10%", "-25%" }; +const int speed_presets_minus_values[] = { -1, -5, -10, -25 }; +const char* speed_presets_plus[] = { "+1%", "+5%", "+10%", "+25%" }; +const int speed_presets_plus_values[] = { 1, 5, 10, 25 }; + +lv_button_column_t speed_mult_columns[] = { + { set_speed_mult, speed_presets, (const void**)speed_presets_values, 4}, + { set_speed_mult_offset, speed_presets_minus, (const void**)speed_presets_minus_values, 4}, + { set_speed_mult_offset, speed_presets_plus, (const void**)speed_presets_plus_values, 4} +}; + +static void set_extrude_mult_text(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char data[64]; + sprintf(data, "Flow: %.0f%%", printer.extrude_mult * 100); + lv_label_set_text(label, data); +} + +static void set_extrude_mult(lv_event_t * e){ + int speed = (int)lv_event_get_user_data(e); + char gcode[64]; + sprintf(gcode, "M221 S%d", speed); + send_gcode(true, gcode); +} + +static void set_extrude_mult_offset(lv_event_t * e){ + int speed = (int)lv_event_get_user_data(e); + float result = printer.extrude_mult * 100 + speed; + printer.extrude_mult = result / 100; + char gcode[64]; + sprintf(gcode, "M221 S%.0f", result); + send_gcode(true, gcode); +} + +const char* extrude_presets[] = { "95%", "100%", "105%", "110%" }; +const int extrude_presets_values[] = { 95, 100, 105, 110 }; +const char* extrude_offset[] = { "+5%", "+1%", "-1%", "-5%" }; +const int extrude_offset_values[] = { 5, 1, -1, -5 }; + +lv_button_column_t extrude_mult_columns[] = { + { set_extrude_mult, extrude_presets, (const void**)extrude_presets_values, 4}, + { set_extrude_mult_offset, extrude_offset, (const void**)extrude_offset_values, 4} +}; + +static void open_fan_speed_panel(lv_event_t * e){ + lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_fan_speed_text, fan_speed_columns, 2); + lv_msg_send(DATA_PRINTER_DATA, &printer); +} + +static void open_zoffset_panel(lv_event_t * e){ + lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_zoffset_text, zoffset_columns, 2); + lv_msg_send(DATA_PRINTER_DATA, &printer); +} + +static void open_speed_mult_panel(lv_event_t * e){ + lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_speed_mult_text, speed_mult_columns, 3); + lv_msg_send(DATA_PRINTER_DATA, &printer); +} + +static void open_extrude_mult_panel(lv_event_t * e){ + lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_extrude_mult_text, extrude_mult_columns, 2); + lv_msg_send(DATA_PRINTER_DATA, &printer); +} + +void create_state_button(lv_obj_t * root, lv_event_cb_t label, lv_event_cb_t button){ + lv_obj_t * btn = lv_btn_create(root); + lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, button, LV_EVENT_CLICKED, NULL); + + lv_obj_t * label_obj = lv_label_create(btn); + lv_obj_add_event_cb(label_obj, label, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subscribe_obj(DATA_PRINTER_DATA, label_obj, NULL); + lv_obj_align(label_obj, LV_ALIGN_CENTER, 0, 0); +} + +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 * 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_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); + + create_state_button(right_panel, set_fan_speed_text, open_fan_speed_panel); + create_state_button(right_panel, set_zoffset_text, open_zoffset_panel); + create_state_button(right_panel, set_speed_mult_text, open_speed_mult_panel); + create_state_button(right_panel, set_extrude_mult_text, open_extrude_mult_panel); +} \ 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 34a7350..3ee3633 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -80,15 +80,14 @@ static void keyboard_callback(lv_event_t * e){ } char gcode[64]; - const char* space = "%20"; switch (keyboard_target){ case TARGET_HOTEND: - sprintf(gcode, "M104%sS%d", space, temp); + sprintf(gcode, "M104 S%d", temp); send_gcode(true, gcode); break; case TARGET_BED: - sprintf(gcode, "M140%sS%d", space, temp); + sprintf(gcode, "M140 S%d", temp); send_gcode(true, gcode); break; case TARGET_HOTEND_CONFIG_1: @@ -156,8 +155,8 @@ static void cooldown_temp(lv_event_t * e){ return; } - send_gcode(true, "M104%20S0"); - send_gcode(true, "M140%20S0"); + send_gcode(true, "M104 S0"); + send_gcode(true, "M140 S0"); } static void btn_extrude(lv_event_t * e){ @@ -166,7 +165,7 @@ static void btn_extrude(lv_event_t * e){ } send_gcode(true, "M83"); - send_gcode(true, "G1%20E25%20F300"); + send_gcode(true, "G1 E25 F300"); } static void set_temp_via_preset(lv_event_t * e){ @@ -180,11 +179,10 @@ static void set_temp_via_preset(lv_event_t * e){ } char gcode[64]; - const char* space = "%20"; if (target <= TARGET_HOTEND_CONFIG_3) - sprintf(gcode, "M104%sS%d", space, value); + sprintf(gcode, "M104 S%d", value); else - sprintf(gcode, "M140%sS%d", space, value); + sprintf(gcode, "M140 S%d", value); send_gcode(true, gcode); } @@ -201,7 +199,7 @@ static void btn_retract(lv_event_t * e){ } send_gcode(true, "M83"); - send_gcode(true, "G1%20E-25%20F300"); + send_gcode(true, "G1 E-25 F300"); } void temp_panel_init(lv_obj_t * panel){ diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index a489d4a..26ce3c5 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -1,5 +1,6 @@ #include "lvgl.h" #include "ui_utils.h" +#include "../core/data_setup.h" lv_obj_t* lv_create_empty_panel(lv_obj_t* root) { lv_obj_t* panel = lv_obj_create(root); @@ -23,4 +24,64 @@ void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign, lv_coord_t pad_co lv_obj_set_flex_align(obj, allign, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER); lv_obj_set_style_pad_column(obj, pad_column, 0); lv_obj_set_style_pad_row(obj, pad_row, 0); +} + +static void lv_fullscreen_menu_close(lv_event_t * e){ + lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e); + lv_obj_del(panel); +} + +void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count){ + const auto full_panel_width = CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 3; + const auto full_panel_inner_width = full_panel_width - CYD_SCREEN_GAP_PX * 2 - 4; + const auto full_panel_height = CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX; + const auto full_panel_inner_height = full_panel_height - CYD_SCREEN_GAP_PX * 2 - 4; + auto column_width = full_panel_inner_width / column_count - CYD_SCREEN_GAP_PX; + auto column_height = full_panel_inner_height - CYD_SCREEN_GAP_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX; + + lv_obj_t * panel = lv_obj_create(root); + lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0); + lv_obj_set_size(panel, full_panel_width, full_panel_height); + lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t * top_menu_row = lv_create_empty_panel(panel); + lv_obj_set_size(top_menu_row, full_panel_inner_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(top_menu_row, LV_ALIGN_TOP_LEFT, 0, 0); + + lv_obj_t * btn = lv_btn_create(top_menu_row); + lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0); + lv_obj_add_event_cb(btn, lv_fullscreen_menu_close, LV_EVENT_CLICKED, panel); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_CLOSE); + lv_obj_center(label); + + label = lv_label_create(top_menu_row); + lv_label_set_text(label, "-"); + lv_obj_align(label, LV_ALIGN_LEFT_MID, 0, 0); + lv_obj_add_event_cb(label, title, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL); + + lv_obj_t * rows = lv_create_empty_panel(panel); + lv_obj_set_size(rows, full_panel_inner_width, column_height); + lv_obj_align(rows, LV_ALIGN_BOTTOM_LEFT, 0, 0); + lv_layout_flex_row(rows, LV_FLEX_ALIGN_SPACE_BETWEEN, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + + for (int i = 0; i < column_count; i++){ + lv_obj_t * column = lv_create_empty_panel(rows); + lv_obj_clear_flag(column, LV_OBJ_FLAG_SCROLLABLE); + lv_obj_set_size(column, column_width, column_height); + lv_layout_flex_column(column, LV_FLEX_ALIGN_CENTER, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX); + + for (int j = 0; j < columns[i].length; j++){ + lv_obj_t * btn = lv_btn_create(column); + lv_obj_set_size(btn, column_width, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_add_event_cb(btn, columns[i].event, LV_EVENT_CLICKED, (void*)columns[i].data[j]); + + label = lv_label_create(btn); + lv_label_set_text(label, columns[i].labels[j]); + lv_obj_center(label); + } + } } \ 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 96dd2e2..0245c9e 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -3,6 +3,14 @@ #define CYD_SCREEN_PANEL_WIDTH_PX \ (CYD_SCREEN_WIDTH_PX - CYD_SCREEN_SIDEBAR_SIZE_PX) +typedef struct { + lv_event_cb_t event; + const char** labels; + const void** data; + int length; +} lv_button_column_t; + 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); \ No newline at end of file +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); \ No newline at end of file From 77db3652f217015968c81091e6415d8545f84c7e Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 3 Feb 2024 16:39:49 +0100 Subject: [PATCH 42/45] Add info to stat panel --- CYD-Klipper/src/core/data_setup.cpp | 5 ++ CYD-Klipper/src/core/data_setup.h | 4 ++ CYD-Klipper/src/ui/panels/stats_panel.cpp | 62 +++++++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 8686c30..d240d6d 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -121,6 +121,7 @@ void fetch_printer_data() printer.extruder_temp = status["extruder"]["temperature"]; printer.extruder_target_temp = status["extruder"]["target"]; bool can_extrude = status["extruder"]["can_extrude"]; + printer.pressure_advance = status["extruder"]["pressure_advance"]; printer.can_extrude = can_extrude == true; } @@ -148,6 +149,8 @@ void fetch_printer_data() printer.absolute_coords = absolute_coords == true; printer.speed_mult = status["gcode_move"]["speed_factor"]; printer.extrude_mult = status["gcode_move"]["extrude_factor"]; + printer.feedrate_mm_per_s = status["gcode_move"]["speed"]; + printer.feedrate_mm_per_s /= 60; // convert mm/m to mm/s } if (status.containsKey("fan")) @@ -167,6 +170,8 @@ void fetch_printer_data() printer.print_filename = filename_buff; printer.elapsed_time_s = status["print_stats"]["print_duration"]; printer.filament_used_mm = status["print_stats"]["filament_used"]; + printer.total_layers = status["print_stats"]["info"]["total_layer"]; + printer.current_layer = status["print_stats"]["info"]["current_layer"]; const char *state = status["print_stats"]["state"]; diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index 109f108..57e4e74 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -29,6 +29,10 @@ typedef struct _Printer { float gcode_offset[3]; float speed_mult; float extrude_mult; + int total_layers; + int current_layer; + float pressure_advance; + int feedrate_mm_per_s; } Printer; extern Printer printer; diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp index 417bfad..37249e0 100644 --- a/CYD-Klipper/src/ui/panels/stats_panel.cpp +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -151,9 +151,71 @@ void create_state_button(lv_obj_t * root, lv_event_cb_t label, lv_event_cb_t but lv_obj_align(label_obj, LV_ALIGN_CENTER, 0, 0); } +static void label_pos(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char x_pos_buff[32]; + sprintf(x_pos_buff, "X%.2f Y%.2f", printer.position[0], printer.position[1]); + lv_label_set_text(label, x_pos_buff); +} + +static void label_filament_used_m(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char filament_buff[32]; + sprintf(filament_buff, "%.2f m", printer.filament_used_mm / 1000); + lv_label_set_text(label, filament_buff); +} + +static void label_total_layers(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char layers_buff[32]; + sprintf(layers_buff, "%d of %d", printer.current_layer, printer.total_layers); + lv_label_set_text(label, layers_buff); +} + +static void label_pressure_advance(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char pressure_buff[32]; + sprintf(pressure_buff, "%.3f", printer.pressure_advance); + lv_label_set_text(label, pressure_buff); +} + +static void label_feedrate(lv_event_t * e){ + lv_obj_t * label = lv_event_get_target(e); + char feedrate_buff[32]; + sprintf(feedrate_buff, "%d mm/s", printer.feedrate_mm_per_s); + lv_label_set_text(label, feedrate_buff); +} + +void create_stat_text_block(lv_obj_t * root, const char* label, lv_event_cb_t value){ + lv_obj_t * panel = lv_create_empty_panel(root); + lv_obj_set_size(panel, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_layout_flex_column(panel , LV_FLEX_ALIGN_START, CYD_SCREEN_GAP_PX / 2, CYD_SCREEN_GAP_PX / 2); + lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START); + + lv_obj_t * label_obj = lv_label_create(panel); + lv_label_set_text(label_obj, label); + lv_obj_set_style_text_font(label_obj, CYD_SCREEN_FONT_SMALL, 0); + + lv_obj_t * value_obj = lv_label_create(panel); + lv_obj_add_event_cb(value_obj, value, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subscribe_obj(DATA_PRINTER_DATA, value_obj, NULL); +} + 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_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); + + create_stat_text_block(left_panel, "Position:", label_pos); + create_stat_text_block(left_panel, "Filament Used:", label_filament_used_m); + create_stat_text_block(left_panel, "Layer:", label_total_layers); + create_stat_text_block(left_panel, "Pressure Advance:", label_pressure_advance); + 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_layout_flex_column(right_panel, LV_FLEX_ALIGN_CENTER); From e152868e0fdef77f7ef789d2991847586ca551e2 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 3 Feb 2024 17:22:09 +0100 Subject: [PATCH 43/45] Add macros to not ready screen --- CYD-Klipper/src/ui/main_ui.cpp | 38 +++++++++++++++++++- CYD-Klipper/src/ui/panels/macros_panel.cpp | 40 ++++++++++++---------- CYD-Klipper/src/ui/panels/panel.h | 4 ++- 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index eedb049..373e54c 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -5,6 +5,8 @@ #include "lvgl.h" #include "nav_buttons.h" #include "ui_utils.h" +#include "panels/panel.h" +#include "../core/macros_query.h" char extruder_temp_buff[20]; char bed_temp_buff[20]; @@ -18,6 +20,29 @@ static void btn_click_firmware_restart(lv_event_t * e){ send_gcode(false, "FIRMWARE_RESTART"); } +void error_ui_macros_close(lv_event_t * e){ + lv_obj_t * obj = (lv_obj_t *)lv_event_get_user_data(e); + lv_obj_del(obj); +} + +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, error_ui_macros_close, 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_macros_to_panel(panel, macros_query()); +} + void error_ui(){ lv_obj_clean(lv_scr_act()); @@ -56,8 +81,19 @@ void error_ui(){ lv_obj_set_flex_grow(btn, 1); label = lv_label_create(btn); - lv_label_set_text(label, "Firmware Restart"); + lv_label_set_text(label, "FW Restart"); lv_obj_center(label); + + if (macros_query().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, "Macros"); + lv_obj_center(label); + } } void check_if_screen_needs_to_be_disabled(){ diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 2bf6bc3..68f2ea0 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -19,24 +19,7 @@ static void btn_goto_settings(lv_event_t * e){ nav_buttons_setup(3); } -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); - lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX); - - lv_obj_t * label = lv_label_create(btn); - lv_label_set_text(label, LV_SYMBOL_SETTINGS " Screen Settings"); - lv_obj_center(label); - - MACROSQUERY query = macros_query(); - if (query.count == 0){ - label = lv_label_create(panel); - lv_label_set_text(label, "No macros found.\nMacros with the description\n\"CYD_SCREEN_MACRO\"\nwill show up here."); - lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); - return; - } - +void macros_panel_add_macros_to_panel(lv_obj_t * panel, MACROSQUERY query){ lv_obj_t * root_panel = lv_create_empty_panel(panel); lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2); @@ -67,4 +50,25 @@ void macros_panel_init(lv_obj_t* panel) { lv_obj_set_style_line_width(line, 1, 0); lv_obj_set_style_line_color(line, lv_color_hex(0xAAAAAA), 0); } +} + +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); + lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX); + + lv_obj_t * label = lv_label_create(btn); + lv_label_set_text(label, LV_SYMBOL_SETTINGS " Screen Settings"); + lv_obj_center(label); + + MACROSQUERY query = macros_query(); + if (query.count == 0){ + label = lv_label_create(panel); + lv_label_set_text(label, "No macros found.\nMacros with the description\n\"CYD_SCREEN_MACRO\"\nwill show up here."); + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); + return; + } + + macros_panel_add_macros_to_panel(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 0656035..1457f9f 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -1,4 +1,5 @@ #include "lvgl.h" +#include "../../core/macros_query.h" #define SIZEOF(arr) (sizeof(arr) / sizeof(*arr)) @@ -8,4 +9,5 @@ void print_panel_init(lv_obj_t* panel); 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); \ No newline at end of file +void stats_panel_init(lv_obj_t* panel); +void macros_panel_add_macros_to_panel(lv_obj_t * panel, MACROSQUERY query); \ No newline at end of file From a07d28293ceceaebae254e53e5514aaa834c781b Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 3 Feb 2024 22:41:31 +0100 Subject: [PATCH 44/45] Add power devices to macro menu --- CYD-Klipper/src/core/macros_query.cpp | 68 ++++++++++++++++++++-- CYD-Klipper/src/core/macros_query.h | 10 +++- CYD-Klipper/src/ui/main_ui.cpp | 6 +- CYD-Klipper/src/ui/nav_buttons.cpp | 2 +- CYD-Klipper/src/ui/panels/macros_panel.cpp | 55 ++++++++++++++--- CYD-Klipper/src/ui/panels/panel.h | 2 +- 6 files changed, 125 insertions(+), 18 deletions(-) diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index 0b6e9b0..9acb12e 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -4,15 +4,16 @@ #include #include "../conf/global_config.h" #include +#include static char* macros[64] = {0}; static int macros_count = 0; -static void on_state_change(void * s, lv_msg_t * m) { - if (printer.state == PRINTER_STATE_ERROR || printer.state == PRINTER_STATE_PAUSED){ - return; - } +static char* power_devices[16] = {0}; +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); @@ -41,10 +42,69 @@ static void on_state_change(void * s, lv_msg_t * m) { } } +static 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.begin(url.c_str()); + int httpCode = client.GET(); + if (httpCode == 200){ + JsonDocument doc; + deserializeJson(doc, client.getStream()); + auto result = doc["result"]["devices"].as(); + + for (int i = 0; i < power_devices_count; i++){ + free(power_devices[i]); + } + + 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++; + } + } +} + +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(); +} + +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 (client.POST("") != 200) + return false; + + for (int i = 0; i < power_devices_count; i++){ + if (strcmp(power_devices[i], device_name) == 0){ + power_device_states[i] = state; + return true; + } + } + + return true; +} + MACROSQUERY macros_query() { return {(const char**)macros, (unsigned int)macros_count}; } +POWERQUERY power_devices_query() { + return {(const char**)power_devices, (const bool*)power_device_states, (unsigned int)power_devices_count}; +} + void macros_query_setup(){ lv_msg_subscribe(DATA_PRINTER_STATE, on_state_change, NULL); on_state_change(NULL, NULL); diff --git a/CYD-Klipper/src/core/macros_query.h b/CYD-Klipper/src/core/macros_query.h index 5fdee3f..954350e 100644 --- a/CYD-Klipper/src/core/macros_query.h +++ b/CYD-Klipper/src/core/macros_query.h @@ -5,5 +5,13 @@ typedef struct { uint32_t count; } MACROSQUERY; +typedef struct { + const char** power_devices; + const bool* power_states; + uint32_t count; +} POWERQUERY; + MACROSQUERY macros_query(); -void macros_query_setup(); \ No newline at end of file +POWERQUERY power_devices_query(); +void macros_query_setup(); +bool set_power_state(const char* device_name, bool state); \ 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 373e54c..a6f1184 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -40,7 +40,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_macros_to_panel(panel, macros_query()); + macros_panel_add_power_devices_to_panel(panel, power_devices_query()); } void error_ui(){ @@ -84,14 +84,14 @@ void error_ui(){ lv_label_set_text(label, "FW Restart"); lv_obj_center(label); - if (macros_query().count >= 1){ + if (power_devices_query().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, "Macros"); + lv_label_set_text(label, "Devices"); lv_obj_center(label); } } diff --git a/CYD-Klipper/src/ui/nav_buttons.cpp b/CYD-Klipper/src/ui/nav_buttons.cpp index 4bc7cb2..fbdd5e6 100644 --- a/CYD-Klipper/src/ui/nav_buttons.cpp +++ b/CYD-Klipper/src/ui/nav_buttons.cpp @@ -109,7 +109,7 @@ void nav_buttons_setup(unsigned char active_panel){ create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel); // Move - create_button(LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel); + 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); diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index 68f2ea0..160cd17 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -3,6 +3,7 @@ #include "../nav_buttons.h" #include "../../core/data_setup.h" #include "../../core/macros_query.h" +#include "../../conf/global_config.h" #include "../ui_utils.h" #include @@ -19,12 +20,7 @@ static void btn_goto_settings(lv_event_t * e){ nav_buttons_setup(3); } -void macros_panel_add_macros_to_panel(lv_obj_t * panel, MACROSQUERY query){ - lv_obj_t * root_panel = lv_create_empty_panel(panel); - lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); - lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2); - lv_layout_flex_column(root_panel); - +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]; @@ -52,6 +48,42 @@ void macros_panel_add_macros_to_panel(lv_obj_t * panel, MACROSQUERY query){ } } +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_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); + } +} + 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); @@ -63,12 +95,19 @@ void macros_panel_init(lv_obj_t* panel) { lv_obj_center(label); MACROSQUERY query = macros_query(); - if (query.count == 0){ + POWERQUERY power = power_devices_query(); + if (query.count == 0 && power.count == 0){ label = lv_label_create(panel); lv_label_set_text(label, "No macros found.\nMacros with the description\n\"CYD_SCREEN_MACRO\"\nwill show up here."); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); return; } - macros_panel_add_macros_to_panel(panel, query); + lv_obj_t * root_panel = lv_create_empty_panel(panel); + lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); + lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2); + lv_layout_flex_column(root_panel); + + macros_panel_add_power_devices_to_panel(root_panel, power); + macros_panel_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 1457f9f..d69910a 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -10,4 +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 macros_panel_add_macros_to_panel(lv_obj_t * panel, MACROSQUERY query); \ No newline at end of file +void macros_panel_add_power_devices_to_panel(lv_obj_t * panel, POWERQUERY query); \ No newline at end of file From 1f76012423b5a4970c0c3ad591b64d33dffcbab5 Mon Sep 17 00:00:00 2001 From: suchmememanyskill <38142618+suchmememanyskill@users.noreply.github.com> Date: Sat, 3 Feb 2024 23:45:28 +0100 Subject: [PATCH 45/45] Make power devices also show on klipper connect screen if available --- CYD-Klipper/src/core/macros_query.cpp | 3 +- CYD-Klipper/src/core/macros_query.h | 3 +- CYD-Klipper/src/ui/ip_setup.cpp | 70 ++++++++++++++++++----- CYD-Klipper/src/ui/main_ui.cpp | 7 +-- CYD-Klipper/src/ui/panels/print_panel.cpp | 7 +-- CYD-Klipper/src/ui/ui_utils.cpp | 8 +-- CYD-Klipper/src/ui/ui_utils.h | 3 +- CYD-Klipper/src/ui/wifi_setup.cpp | 2 +- README.md | 4 +- 9 files changed, 74 insertions(+), 33 deletions(-) diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp index 9acb12e..2ed0c0c 100644 --- a/CYD-Klipper/src/core/macros_query.cpp +++ b/CYD-Klipper/src/core/macros_query.cpp @@ -42,10 +42,11 @@ static void _macros_query_internal(){ } } -static void _power_devices_query_internal(){ +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.begin(url.c_str()); int httpCode = client.GET(); if (httpCode == 200){ diff --git a/CYD-Klipper/src/core/macros_query.h b/CYD-Klipper/src/core/macros_query.h index 954350e..6d58c25 100644 --- a/CYD-Klipper/src/core/macros_query.h +++ b/CYD-Klipper/src/core/macros_query.h @@ -14,4 +14,5 @@ typedef struct { MACROSQUERY macros_query(); POWERQUERY power_devices_query(); void macros_query_setup(); -bool set_power_state(const char* device_name, bool state); \ No newline at end of file +bool set_power_state(const char* device_name, bool state); +void _power_devices_query_internal(); \ 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 ffa236e..8763cef 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -5,6 +5,8 @@ #include #include "core/data_setup.h" #include "ui_utils.h" +#include "../core/macros_query.h" +#include "panels/panel.h" bool connect_ok = false; lv_obj_t * ipEntry; @@ -70,25 +72,63 @@ static void reset_btn_event_handler(lv_event_t * e){ } } -void ip_init_inner(){ +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()); +} + +void redraw_connect_screen(){ lv_obj_clean(lv_scr_act()); + label = lv_label_create(lv_scr_act()); + lv_label_set_text(label, "Connecting to Klipper"); + lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t * button_row = lv_create_empty_panel(lv_scr_act()); + lv_obj_set_size(button_row, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + lv_layout_flex_row(button_row, LV_FLEX_ALIGN_CENTER); + lv_obj_align(button_row, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * reset_btn = lv_btn_create(button_row); + lv_obj_add_event_cb(reset_btn, reset_btn_event_handler, LV_EVENT_CLICKED, NULL); + lv_obj_set_height(reset_btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); + + lv_obj_t * btn_label = lv_label_create(reset_btn); + lv_label_set_text(btn_label, "Reset"); + lv_obj_center(btn_label); + + if (power_devices_query().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); + + btn_label = lv_label_create(power_devices_btn); + lv_label_set_text(btn_label, "Power Devices"); + lv_obj_center(btn_label); + } +} + +void ip_init_inner(){ if (global_config.ipConfigured) { - label = lv_label_create(lv_scr_act()); - lv_label_set_text(label, "Connecting to Klipper"); - lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); - - lv_obj_t * resetBtn = lv_btn_create(lv_scr_act()); - lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); - lv_obj_set_height(resetBtn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); - - lv_obj_t * btnLabel = lv_label_create(resetBtn); - lv_label_set_text(btnLabel, "Reset"); - lv_obj_center(btnLabel); + redraw_connect_screen(); return; } + lv_obj_clean(lv_scr_act()); + lv_obj_t * root = lv_create_empty_panel(lv_scr_act()); lv_obj_set_size(root, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX); lv_layout_flex_column(root); @@ -148,6 +188,10 @@ void ip_init(){ retry_count++; String retry_count_text = "Connecting to Klipper (Try " + String(retry_count + 1) + ")"; lv_label_set_text(label, retry_count_text.c_str()); + + _power_devices_query_internal(); + if (power_devices_query().count >= 1) + redraw_connect_screen(); } } } diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index a6f1184..19ebeff 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -20,10 +20,7 @@ static void btn_click_firmware_restart(lv_event_t * e){ send_gcode(false, "FIRMWARE_RESTART"); } -void error_ui_macros_close(lv_event_t * e){ - lv_obj_t * obj = (lv_obj_t *)lv_event_get_user_data(e); - lv_obj_del(obj); -} + void error_ui_macros_open(lv_event_t * e){ lv_obj_t * panel = lv_create_empty_panel(lv_scr_act()); @@ -34,7 +31,7 @@ void error_ui_macros_open(lv_event_t * e){ 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, error_ui_macros_close, LV_EVENT_CLICKED, panel); + 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"); diff --git a/CYD-Klipper/src/ui/panels/print_panel.cpp b/CYD-Klipper/src/ui/panels/print_panel.cpp index 32837ab..9f8549f 100644 --- a/CYD-Klipper/src/ui/panels/print_panel.cpp +++ b/CYD-Klipper/src/ui/panels/print_panel.cpp @@ -40,11 +40,6 @@ static void btn_print_file(lv_event_t * e){ Serial.printf("Print start: HTTP %d\n", httpCode); } -static void btn_print_back(lv_event_t * e){ - lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e); - lv_obj_del(panel); -} - static void btn_print_file_verify(lv_event_t * e){ const auto button_size_mult = 1.3f; @@ -69,7 +64,7 @@ static void btn_print_file_verify(lv_event_t * e){ btn = lv_btn_create(panel); lv_obj_align(btn, LV_ALIGN_BOTTOM_LEFT, 0, 0); lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult); - lv_obj_add_event_cb(btn, btn_print_back, LV_EVENT_CLICKED, panel); + lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel); label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_CLOSE); diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index 26ce3c5..541dfe5 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -26,9 +26,9 @@ void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign, lv_coord_t pad_co lv_obj_set_style_pad_row(obj, pad_row, 0); } -static void lv_fullscreen_menu_close(lv_event_t * e){ - lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e); - lv_obj_del(panel); +void destroy_event_user_data(lv_event_t * e){ + lv_obj_t * obj = (lv_obj_t *)lv_event_get_user_data(e); + lv_obj_del(obj); } void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count){ @@ -51,7 +51,7 @@ void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t tit lv_obj_t * btn = lv_btn_create(top_menu_row); lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_align(btn, LV_ALIGN_RIGHT_MID, 0, 0); - lv_obj_add_event_cb(btn, lv_fullscreen_menu_close, LV_EVENT_CLICKED, panel); + lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel); lv_obj_t * label = lv_label_create(btn); lv_label_set_text(label, LV_SYMBOL_CLOSE); diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index 0245c9e..f5e5fe5 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -13,4 +13,5 @@ typedef struct { 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); \ No newline at end of file +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 diff --git a/CYD-Klipper/src/ui/wifi_setup.cpp b/CYD-Klipper/src/ui/wifi_setup.cpp index d221933..6bb3556 100644 --- a/CYD-Klipper/src/ui/wifi_setup.cpp +++ b/CYD-Klipper/src/ui/wifi_setup.cpp @@ -97,7 +97,7 @@ void wifi_init_inner(){ lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); lv_obj_t * resetBtn = lv_btn_create(lv_scr_act()); - lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_ALL, NULL); + lv_obj_add_event_cb(resetBtn, reset_btn_event_handler, LV_EVENT_CLICKED, NULL); lv_obj_set_height(resetBtn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_align(resetBtn, LV_ALIGN_CENTER, 0, CYD_SCREEN_GAP_PX + CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); diff --git a/README.md b/README.md index d8a2d77..fae3287 100644 --- a/README.md +++ b/README.md @@ -16,10 +16,12 @@ A ESP32-2432S028R is required to run this project. You can find out where to buy - View printer status - View print progress - Start a print -- Move the printer +- (When the printer is idle) move the printer +- (During a print) set fan speed, flow rate, speed and z offset - Manage temperature - Extrude/Retract filament - Execute predefined gcode macros +- Toggle Moonraker power devices ### Install