diff --git a/CYD-Klipper/.vscode/settings.json b/CYD-Klipper/.vscode/settings.json index 0ddaeec..425aa19 100644 --- a/CYD-Klipper/.vscode/settings.json +++ b/CYD-Klipper/.vscode/settings.json @@ -15,7 +15,12 @@ "*.tcc": "cpp", "cmath": "cpp", "system_error": "cpp", - "random": "cpp" + "random": "cpp", + "optional": "cpp", + "limits": "cpp", + "memory": "cpp", + "new": "cpp", + "type_traits": "cpp" }, "cmake.configureOnOpen": false } \ No newline at end of file diff --git a/CYD-Klipper/src/conf/global_config.cpp b/CYD-Klipper/src/conf/global_config.cpp index 42cbf3c..613e635 100644 --- a/CYD-Klipper/src/conf/global_config.cpp +++ b/CYD-Klipper/src/conf/global_config.cpp @@ -2,10 +2,10 @@ #include "global_config.h" #include "lvgl.h" -GLOBAL_CONFIG global_config = {0}; -TEMPORARY_CONFIG temporary_config = {0}; +GlobalConfig global_config = {0}; +TemporaryConfig temporary_config = {0}; -COLOR_DEF color_defs[] = { +ColorDefinition color_defs[] = { {LV_PALETTE_BLUE, 0, LV_PALETTE_RED}, {LV_PALETTE_GREEN, 0, LV_PALETTE_PURPLE}, {LV_PALETTE_LIME, -2, LV_PALETTE_PURPLE}, @@ -30,7 +30,7 @@ void verify_version() if (!preferences.begin("global_config", false)) return; - GLOBAL_CONFIG config = {0}; + GlobalConfig config = {0}; preferences.getBytes("global_config", &config, sizeof(config)); LOG_F(("Config version: %d\n", config.version)) if (config.version != CONFIG_VERSION) { @@ -41,7 +41,7 @@ void verify_version() preferences.end(); } -PRINTER_CONFIG* get_current_printer_config() +PrinterConfiguration* get_current_printer_config() { return &global_config.printer_config[global_config.printer_index]; } @@ -70,8 +70,8 @@ void set_printer_config_index(int index) if (index < 0 || index >= PRINTER_CONFIG_COUNT) return; - PRINTER_CONFIG* old_config = &global_config.printer_config[global_config.printer_index]; - PRINTER_CONFIG* new_config = &global_config.printer_config[index]; + PrinterConfiguration* old_config = &global_config.printer_config[global_config.printer_index]; + PrinterConfiguration* new_config = &global_config.printer_config[index]; global_config.printer_index = index; diff --git a/CYD-Klipper/src/conf/global_config.h b/CYD-Klipper/src/conf/global_config.h index 8e6ac3b..c9a7c06 100644 --- a/CYD-Klipper/src/conf/global_config.h +++ b/CYD-Klipper/src/conf/global_config.h @@ -20,7 +20,14 @@ enum { SHOW_STATS_ON_PROGRESS_PANEL_ALL = 3, }; -typedef struct _PRINTER_CONFIG { +enum PrinterType { + PrinterTypeKlipper = 0, + PrinterTypeKlipperSerial = 1, + PrinterTypeBambu = 2, + PrinterTypeOctoprint = 3, +}; + +typedef struct { union { unsigned int raw; struct { @@ -35,6 +42,7 @@ typedef struct _PRINTER_CONFIG { unsigned char show_stats_on_progress_panel : 2; bool custom_filament_move_macros : 1; + PrinterType printer_type : 3; }; }; @@ -51,9 +59,9 @@ typedef struct _PRINTER_CONFIG { unsigned short printer_move_x_steps[3]; unsigned short printer_move_y_steps[3]; unsigned short printer_move_z_steps[3]; -} PRINTER_CONFIG; +} PrinterConfiguration; -typedef struct _GLOBAL_CONFIG { +typedef struct { unsigned char version; union { unsigned int raw; @@ -75,7 +83,7 @@ typedef struct _GLOBAL_CONFIG { }; }; - PRINTER_CONFIG printer_config[PRINTER_CONFIG_COUNT]; + PrinterConfiguration printer_config[PRINTER_CONFIG_COUNT]; float screen_cal_x_offset; float screen_cal_x_mult; @@ -88,24 +96,23 @@ typedef struct _GLOBAL_CONFIG { unsigned char brightness; unsigned char screen_timeout; unsigned char printer_index; -} GLOBAL_CONFIG; +} GlobalConfig; // Volatile/temporary config that doesn't survive a reset -typedef struct _TEMPORARY_CONFIG { +typedef struct { bool debug : 1; bool remote_echo : 1; -} TEMPORARY_CONFIG; +} TemporaryConfig; - -typedef struct _COLOR_DEF { +typedef struct { lv_palette_t primary_color; short primary_color_light; lv_palette_t secondary_color; -} COLOR_DEF; +} ColorDefinition; -extern GLOBAL_CONFIG global_config; -extern TEMPORARY_CONFIG temporary_config; -extern COLOR_DEF color_defs[]; +extern GlobalConfig global_config; +extern TemporaryConfig temporary_config; +extern ColorDefinition color_defs[]; #define LOG(x) if(temporary_config.debug){ Serial.print(x);} #define LOG_LN(x) if(temporary_config.debug){ Serial.println(x);} @@ -115,9 +122,9 @@ void write_global_config(); void verify_version(); void load_global_config(); -PRINTER_CONFIG* get_current_printer_config(); -int get_printer_config_count(); -void set_printer_config_index(int index); -int get_printer_config_free_index(); +//PRINTER_CONFIG* get_current_printer_config(); +//int get_printer_config_count(); +//void set_printer_config_index(int index); +//int get_printer_config_free_index(); #endif // !_GLOBAL_CONFIG_INIT \ No newline at end of file diff --git a/CYD-Klipper/src/core/data_setup.cpp b/CYD-Klipper/src/core/data_setup.cpp index 38fd60f..89053b5 100644 --- a/CYD-Klipper/src/core/data_setup.cpp +++ b/CYD-Klipper/src/core/data_setup.cpp @@ -1,23 +1,11 @@ #include "data_setup.h" -#include "lvgl.h" -#include "../conf/global_config.h" -#include #include -#include "macros_query.h" #include -#include "http_client.h" -#include "../ui/ui_utils.h" -#include "macros_query.h" #include "printer_integration.hpp" -Printer printer = {0}; -PrinterMinimal *printer_minimal; -int klipper_request_consecutive_fail_count = 999; -char filename_buff[512] = {0}; SemaphoreHandle_t freezeRenderThreadSemaphore, freezeRequestThreadSemaphore; const long data_update_interval = 780; -unsigned char lock_absolute_relative_mode_swap = 0; void semaphore_init(){ freezeRenderThreadSemaphore = xSemaphoreCreateMutex(); @@ -42,90 +30,6 @@ void unfreeze_render_thread(){ xSemaphoreGive(freezeRenderThreadSemaphore); } -void send_gcode(bool wait, const char *gcode) -{ - LOG_F(("Sending gcode: %s\n", gcode)) - - SETUP_HTTP_CLIENT_FULL("/printer/gcode/script?script=" + urlEncode(gcode), false, wait ? 5000 : 750); - try - { - client.GET(); - } - catch (...) - { - LOG_LN("Failed to send gcode"); - } -} - -void send_estop() -{ - LOG_LN("Sending estop"); - - SETUP_HTTP_CLIENT_FULL("/printer/emergency_stop", false, 5000); - try - { - client.GET(); - } - catch (...) - { - LOG_LN("Failed to send estop"); - } -} - -int get_slicer_time_estimate_s() -{ - if (printer.state == PRINTER_STATE_IDLE) - return 0; - - delay(10); - - SETUP_HTTP_CLIENT("/server/files/metadata?filename=" + urlEncode(printer.print_filename)); - - int httpCode = client.GET(); - - if (httpCode != 200) - return 0; - - JsonDocument doc; - deserializeJson(doc, client.getStream()); - int time_estimate_s = doc["result"]["estimated_time"]; - LOG_F(("Got slicer time estimate: %ds\n", time_estimate_s)) - return time_estimate_s; -} - -void move_printer(const char* axis, float amount, bool relative) { - if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING) - return; - - char gcode[64]; - const char* extra = (amount > 0) ? "+" : ""; - const char* start = ""; - const char* end = ""; - - bool absolute_coords = printer.absolute_coords; - - if (absolute_coords && relative) { - start = "G91\n"; - } - else if (!absolute_coords && !relative) { - start = "G90\n"; - } - - if (absolute_coords && relative) { - end = "\nG90"; - } - else if (!absolute_coords && !relative) { - end = "\nG91"; - } - - sprintf(gcode, "%sG1 %s%s%.3f F6000%s", start, axis, extra, amount, end); - send_gcode(true, gcode); - - lock_absolute_relative_mode_swap = 2; -} - -int last_slicer_time_query = -15000; - void fetch_printer_data() { freeze_request_thread(); @@ -159,10 +63,14 @@ void fetch_printer_data_minimal() PrinterDataMinimal* data = (PrinterDataMinimal*)malloc(sizeof(PrinterDataMinimal) * get_printer_count()); for (int i = 0; i < get_printer_count(); i++) { + freeze_request_thread(); BasePrinter* printer = get_printer(i); + unfreeze_request_thread(); *(data + i) = printer->fetch_min(); } + freeze_render_thread(); announce_printer_data_minimal(data); + unfreeze_render_thread(); free(data); } @@ -193,11 +101,8 @@ TaskHandle_t background_loop; void data_setup() { - printer_minimal = (PrinterMinimal*)calloc(sizeof(PrinterMinimal), PRINTER_CONFIG_COUNT); semaphore_init(); - printer.print_filename = filename_buff; fetch_printer_data(); - freeze_render_thread(); xTaskCreatePinnedToCore(data_loop_background, "data_loop_background", 5000, NULL, 2, &background_loop, 0); } diff --git a/CYD-Klipper/src/core/data_setup.h b/CYD-Klipper/src/core/data_setup.h index d1fad06..6aebf01 100644 --- a/CYD-Klipper/src/core/data_setup.h +++ b/CYD-Klipper/src/core/data_setup.h @@ -1,62 +1,7 @@ #pragma once -enum { - PRINTER_STATE_OFFLINE = 0, - PRINTER_STATE_ERROR = 1, - PRINTER_STATE_IDLE = 2, - PRINTER_STATE_PRINTING = 3, - PRINTER_STATE_PAUSED = 4, -}; - -typedef struct _Printer { - unsigned char state; - char* state_message; - float extruder_temp; - float extruder_target_temp; - float bed_temp; - float bed_target_temp; - float position[3]; - unsigned char can_extrude; - unsigned char homed_axis; - unsigned char absolute_coords; - float elapsed_time_s; - float printed_time_s; - float remaining_time_s; - float filament_used_mm; - char* print_filename; - float print_progress; // 0 -> 1 - float fan_speed; // 0 -> 1 - float gcode_offset[3]; - float speed_mult; - float extrude_mult; - int total_layers; - int current_layer; - float pressure_advance; - float smooth_time; - int feedrate_mm_per_s; - int slicer_estimated_print_time_s; -} Printer; - -typedef struct _PrinterMinimal { - unsigned char state; - float print_progress; // 0 -> 1 - unsigned int power_devices; -} PrinterMinimal; - -extern Printer printer; -extern PrinterMinimal *printer_minimal; -extern int klipper_request_consecutive_fail_count; - -#define DATA_PRINTER_STATE 1 -#define DATA_PRINTER_DATA 2 -#define DATA_PRINTER_TEMP_PRESET 3 -#define DATA_PRINTER_MINIMAL 4 - void data_loop(); void data_setup(); -void send_estop(); -void send_gcode(bool wait, const char* gcode); -void move_printer(const char* axis, float amount, bool relative); 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 deleted file mode 100644 index e154ea9..0000000 --- a/CYD-Klipper/src/core/files_query.cpp +++ /dev/null @@ -1,113 +0,0 @@ -#include -#include "files_query.h" -#include "../conf/global_config.h" -#include "data_setup.h" -#include -#include -#include "http_client.h" - -// Always has +1 entry with a null'd name -FILESYSTEM_FILE* last_query = NULL; - -void clear_files() -{ - if (last_query != NULL){ - FILESYSTEM_FILE* current = last_query; - - while (current->name != NULL){ - free(current->name); - current += 1; - } - - free(last_query); - last_query = NULL; - } -} - -FILESYSTEM_FILE* get_files(int limit) -{ - freeze_request_thread(); - clear_files(); - - LOG_F(("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size())) - std::list files; - - auto timer_request = millis(); - SETUP_HTTP_CLIENT_FULL("/server/files/list", true, 5000); - - int httpCode = client.GET(); - auto timer_parse = millis(); - - if (httpCode == 200){ - JsonDocument doc; - auto parseResult = deserializeJson(doc, client.getStream()); - LOG_F(("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++; - } - - if (file_iter == files.end() && files.size() >= limit) - continue; - - f.name = (char*)malloc(strlen(path) + 1); - if (f.name == NULL){ - LOG_LN("Failed to allocate memory"); - continue; - } - strcpy(f.name, path); - 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(); - } - } - } - - size_t size = sizeof(FILESYSTEM_FILE) * (files.size() + 1); - FILESYSTEM_FILE* result = (FILESYSTEM_FILE*)malloc(size); - - if (result == NULL){ - LOG_LN("Failed to allocate memory"); - - for (auto file : files){ - free(file.name); - } - - unfreeze_request_thread(); - return NULL; - } - - last_query = result; - result[files.size()].name = NULL; - - for (auto file : files){ - *result = file; - result += 1; - } - - LOG_F(("Heap space post-file-parse: %d bytes\n", esp_get_free_heap_size())) - LOG_F(("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 deleted file mode 100644 index 822cad8..0000000 --- a/CYD-Klipper/src/core/files_query.h +++ /dev/null @@ -1,23 +0,0 @@ -/* -At some point it may be a fun challenge to try to implement a virtual folder structure, but not today. - -typedef struct _FILESYSTEM_FILE { - char* name; - char* parent_folder_name; - long level; -} FILESYSTEM_FILE; - -typedef struct _FILESYSTEM_FOLDER { - char** files; - char* folder_path; - FILESYSTEM_FOLDER* folders; -} FILESYSTEM_FOLDER; -*/ - -typedef struct _FILESYSTEM_FILE { - char* name; - float modified; -} FILESYSTEM_FILE; - -FILESYSTEM_FILE* get_files(int limit); -void clear_files(); \ No newline at end of file diff --git a/CYD-Klipper/src/core/http_client.cpp b/CYD-Klipper/src/core/http_client.cpp deleted file mode 100644 index a27945b..0000000 --- a/CYD-Klipper/src/core/http_client.cpp +++ /dev/null @@ -1,32 +0,0 @@ -#include "http_client.h" - -String get_full_url(String url_part, PRINTER_CONFIG * config) -{ - if (config == NULL){ - config = get_current_printer_config(); - } - - return "http://" + String(config->klipper_host) + ":" + String(config->klipper_port) + url_part; -} - -void configure_http_client(HTTPClient &client, String url, bool stream, int timeout, PRINTER_CONFIG * config) -{ - if (config == NULL){ - config = get_current_printer_config(); - } - - if (stream){ - client.useHTTP10(true); - } - - if (timeout > 0){ - client.setTimeout(timeout); - client.setConnectTimeout(timeout); - } - - client.begin(url); - - if (config->auth_configured) { - client.addHeader("X-Api-Key", config->klipper_auth); - } -} \ No newline at end of file diff --git a/CYD-Klipper/src/core/http_client.h b/CYD-Klipper/src/core/http_client.h deleted file mode 100644 index 87ca30f..0000000 --- a/CYD-Klipper/src/core/http_client.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include -#include "../conf/global_config.h" - -String get_full_url(String url_part, PRINTER_CONFIG * config = NULL); -void configure_http_client(HTTPClient &client, String url, bool stream = true, int timeout = 1000, PRINTER_CONFIG * config = NULL); - -#define SETUP_HTTP_CLIENT(url_part) HTTPClient client; configure_http_client(client, get_full_url(url_part)); -#define SETUP_HTTP_CLIENT_FULL(url_part, stream, timeout) HTTPClient client; configure_http_client(client, get_full_url(url_part), stream, timeout); \ No newline at end of file diff --git a/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp b/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp index 657e27d..017aed1 100644 --- a/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp +++ b/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp @@ -144,7 +144,7 @@ bool KlipperPrinter::execute_feature(PrinterFeatures feature) return false; } - if (get_current_printer_config()->custom_filament_move_macros) + if (get_current_printer()->printer_config->custom_filament_move_macros) { return send_gcode("FILAMENT_RETRACT"); } @@ -491,7 +491,7 @@ Macros KlipperPrinter::get_macros() } } - if (global_config->sort_macros) + if (global_config.sort_macros) { std::sort(macros.macros, macros.macros + macros.count, [](const char* a, const char* b) { return strcmp(a, b) < 0; diff --git a/CYD-Klipper/src/core/lv_setup.cpp b/CYD-Klipper/src/core/lv_setup.cpp index b3c7d55..c408dc8 100644 --- a/CYD-Klipper/src/core/lv_setup.cpp +++ b/CYD-Klipper/src/core/lv_setup.cpp @@ -5,6 +5,7 @@ #include "../ui/ui_utils.h" #include #include "../ui/serial/serial_console.h" +#include "printer_integration.hpp" #ifndef CPU_FREQ_HIGH #define CPU_FREQ_HIGH 240 @@ -254,10 +255,10 @@ void set_screen_timer_period() void set_color_scheme() { - PRINTER_CONFIG *config = get_current_printer_config(); + PrinterConfiguration *config = get_current_printer()->printer_config; lv_disp_t *dispp = lv_disp_get_default(); lv_color_t main_color = {0}; - COLOR_DEF color_def = color_defs[config->color_scheme]; + ColorDefinition color_def = color_defs[config->color_scheme]; if (color_defs[config->color_scheme].primary_color_light > 0){ main_color = lv_palette_lighten(color_def.primary_color, color_def.primary_color_light); diff --git a/CYD-Klipper/src/core/macros_query.cpp b/CYD-Klipper/src/core/macros_query.cpp deleted file mode 100644 index 958b3e7..0000000 --- a/CYD-Klipper/src/core/macros_query.cpp +++ /dev/null @@ -1,185 +0,0 @@ -#include "lvgl.h" -#include "macros_query.h" -#include "./data_setup.h" -#include -#include -#include "http_client.h" - -static char* macros[64] = {0}; -static int macros_count = 0; - -static char* power_devices[16] = {0}; -static bool power_device_states[16] = {0}; -static unsigned int stored_power_devices_count = 0; - -void macros_clear() -{ - for (int i = 0; i < macros_count; i++){ - free(macros[i]); - } - - macros_count = 0; -} - -MACROSQUERY macros_query(PRINTER_CONFIG * config) -{ - HTTPClient client; - configure_http_client(client, get_full_url("/printer/gcode/help", config), true, 1000); - - int httpCode = client.GET(); - - if (httpCode == 200){ - JsonDocument doc; - deserializeJson(doc, client.getStream()); - auto result = doc["result"].as(); - - macros_clear(); - - for (JsonPair i : result){ - const char *key = i.key().c_str(); - const char *value = i.value().as().c_str(); - if (strcmp(value, "CYD_SCREEN_MACRO") == 0) { - char* macro = (char*)malloc(strlen(key) + 1); - strcpy(macro, key); - macros[macros_count++] = macro; - } - } - - if (global_config.sort_macros) - { - std::sort(macros, macros + macros_count, [](const char* a, const char* b) { - return strcmp(a, b) < 0; - }); - } - - return {(const char**)macros, (unsigned int)macros_count}; - } - else { - return {NULL, 0}; - } -} - -MACROSQUERY macros_query() -{ - return macros_query(get_current_printer_config()); -} - -unsigned int macro_count(PRINTER_CONFIG * config) -{ - HTTPClient client; - configure_http_client(client, get_full_url("/printer/gcode/help", config), true, 1000); - - int httpCode = client.GET(); - - if (httpCode == 200){ - JsonDocument doc; - deserializeJson(doc, client.getStream()); - auto result = doc["result"].as(); - - unsigned int count = 0; - - for (JsonPair i : result){ - const char *value = i.value().as().c_str(); - if (strcmp(value, "CYD_SCREEN_MACRO") == 0) { - count++; - } - } - - return count; - } - else { - return 0; - } -} - -unsigned int macro_count() -{ - return macro_count(get_current_printer_config()); -} - -void power_devices_clear() -{ - for (int i = 0; i < stored_power_devices_count; i++){ - free(power_devices[i]); - } - - stored_power_devices_count = 0; -} - -POWERQUERY power_devices_query(PRINTER_CONFIG * config) -{ - HTTPClient client; - configure_http_client(client, get_full_url("/machine/device_power/devices", config), true, 1000); - - int httpCode = client.GET(); - - if (httpCode == 200){ - JsonDocument doc; - deserializeJson(doc, client.getStream()); - auto result = doc["result"]["devices"].as(); - - power_devices_clear(); - - for (auto i : result){ - const char * device_name = i["device"]; - const char * device_state = i["status"]; - power_devices[stored_power_devices_count] = (char*)malloc(strlen(device_name) + 1); - strcpy(power_devices[stored_power_devices_count], device_name); - power_device_states[stored_power_devices_count] = strcmp(device_state, "on") == 0; - stored_power_devices_count++; - } - - return {(const char**)power_devices, (const bool*)power_device_states, (unsigned int)stored_power_devices_count}; - } - else { - return {NULL, NULL, 0}; - } -} - -POWERQUERY power_devices_query() -{ - return power_devices_query(get_current_printer_config()); -} - -unsigned int power_devices_count(PRINTER_CONFIG * config) -{ - HTTPClient client; - configure_http_client(client, get_full_url("/machine/device_power/devices", config), true, 1000); - - int httpCode = client.GET(); - - if (httpCode == 200){ - JsonDocument doc; - deserializeJson(doc, client.getStream()); - auto result = doc["result"]["devices"].as(); - - unsigned int count = 0; - - for (auto i : result){ - count++; - } - - return count; - } - else { - return 0; - } -} - -unsigned int power_devices_count() -{ - return power_devices_count(get_current_printer_config()); -} - -bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config) -{ - HTTPClient client; - configure_http_client(client, get_full_url("/machine/device_power/device?device=" + urlEncode(device_name) + "&action=" + (state ? "on" : "off"), config), true, 1000); - - return client.POST("") == 200; -} - -bool set_power_state(const char* device_name, bool state) -{ - return set_power_state(device_name, state, get_current_printer_config()); -} \ No newline at end of file diff --git a/CYD-Klipper/src/core/macros_query.h b/CYD-Klipper/src/core/macros_query.h deleted file mode 100644 index 9022cc5..0000000 --- a/CYD-Klipper/src/core/macros_query.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include "../conf/global_config.h" - -typedef struct { - const char** macros; - uint32_t count; -} MACROSQUERY; - -typedef struct { - const char** power_devices; - const bool* power_states; - uint32_t count; -} POWERQUERY; - -MACROSQUERY macros_query(PRINTER_CONFIG * config); -MACROSQUERY macros_query(); -unsigned int macro_count(PRINTER_CONFIG * config); -unsigned int macro_count(); -POWERQUERY power_devices_query(PRINTER_CONFIG * config); -POWERQUERY power_devices_query(); -unsigned int power_devices_count(PRINTER_CONFIG * config); -unsigned int power_devices_count(); -bool set_power_state(const char* device_name, bool state, PRINTER_CONFIG * config); -bool set_power_state(const char* device_name, bool state); -void macros_clear(); -void power_devices_clear(); \ No newline at end of file diff --git a/CYD-Klipper/src/core/printer_integration.cpp b/CYD-Klipper/src/core/printer_integration.cpp index 4f78e28..725369c 100644 --- a/CYD-Klipper/src/core/printer_integration.cpp +++ b/CYD-Klipper/src/core/printer_integration.cpp @@ -1,4 +1,6 @@ #include "printer_integration.hpp" +#include "lv_setup.h" +#include "screen_driver.h" unsigned char current_printer_index = 0; unsigned char total_printers; @@ -20,12 +22,6 @@ BasePrinter::BasePrinter(unsigned char index) // TODO: Fetch printer config and global config } -#define DATA_PRINTER_STATE 1 -#define DATA_PRINTER_DATA 2 -#define DATA_PRINTER_TEMP_PRESET 3 -#define DATA_PRINTER_MINIMAL 4 -#define DATA_PRINTER_POPUP 5 - PrinterData* BasePrinter::AnnouncePrinterData() { char* old_state_message = printer_data_copy->state_message; @@ -37,11 +33,6 @@ PrinterData* BasePrinter::AnnouncePrinterData() if (old_state_message != printer_data_copy->state_message) { free(old_state_message); - lv_msg_send(DATA_PRINTER_STATE, get_current_printer()); - } - else if (printer_data.state != printer_data_copy->state) - { - lv_msg_send(DATA_PRINTER_STATE, get_current_printer()); } if (old_print_filename != printer_data_copy->print_filename) @@ -49,6 +40,11 @@ PrinterData* BasePrinter::AnnouncePrinterData() free(old_print_filename); } + if (printer_data.state != printer_data_copy->state) + { + lv_msg_send(DATA_PRINTER_STATE, get_current_printer()); + } + if (old_popup_message != printer_data_copy->popup_message) { free(old_popup_message); @@ -73,6 +69,11 @@ BasePrinter* get_printer(int idx) return registered_printers + idx; } +int get_current_printer_index() +{ + return current_printer_index; +} + PrinterData* get_current_printer_data() { return printer_data_copy; @@ -87,4 +88,27 @@ void announce_printer_data_minimal(PrinterDataMinimal* printer_data) { memcpy(printer_data_copy, printer_data, sizeof(PrinterDataMinimal) * total_printers); lv_msg_send(DATA_PRINTER_MINIMAL, get_current_printer()); +} + +PrinterDataMinimal* get_printer_data_minimal(int idx) +{ + return &(minimal_data_copy[idx]); +} + +void BasePrinter::save_printer_config() +{ + // TODO +} + + +void add_printer() +{ + +} + +void set_current_printer(int idx) +{ + //set_printer_config_index(index); + set_color_scheme(); + set_invert_display(); } \ No newline at end of file diff --git a/CYD-Klipper/src/core/printer_integration.hpp b/CYD-Klipper/src/core/printer_integration.hpp index b2623d4..06298d8 100644 --- a/CYD-Klipper/src/core/printer_integration.hpp +++ b/CYD-Klipper/src/core/printer_integration.hpp @@ -97,7 +97,7 @@ typedef struct _PrinterData { int feedrate_mm_per_s; } PrinterData; -typedef struct { +typedef struct { unsigned char state; float print_progress; // 0 -> 1 unsigned int power_devices; @@ -118,7 +118,7 @@ typedef struct { } PowerDevices; typedef struct { - const char** available_files; + char** available_files; unsigned int count; bool success; } Files; @@ -132,11 +132,10 @@ class BasePrinter { protected: unsigned char config_index{}; - GLOBAL_CONFIG* global_config{}; PrinterData printer_data{}; - PRINTER_CONFIG* printer_config{}; - + public: + PrinterConfiguration* printer_config{}; PrinterFeatures supported_features{}; PrinterTemperatureDevice supported_temperature_devices{}; PrinterUiPanel* custom_menus{}; @@ -148,12 +147,15 @@ class BasePrinter virtual bool fetch() = 0; virtual PrinterDataMinimal fetch_min() = 0; virtual void disconnect() = 0; + // Free macros externally when done virtual Macros get_macros() = 0; virtual int get_macros_count() = 0; virtual bool execute_macro(const char* macro) = 0; + // Free power devices externally when done virtual PowerDevices get_power_devices() = 0; virtual int get_power_devices_count() = 0; virtual bool set_power_device_state(const char* device_name, bool state) = 0; + // Free files externally when done virtual Files get_files() = 0; virtual bool start_file(const char* filename) = 0; virtual unsigned char* get_32_32_png_image_thumbnail(const char* gcode_filename); @@ -161,11 +163,22 @@ class BasePrinter BasePrinter(unsigned char index); PrinterData* AnnouncePrinterData(); + void save_printer_config(); }; +#define DATA_PRINTER_STATE 1 +#define DATA_PRINTER_DATA 2 +#define DATA_PRINTER_TEMP_PRESET 3 +#define DATA_PRINTER_MINIMAL 4 +#define DATA_PRINTER_POPUP 5 + BasePrinter* get_current_printer(); BasePrinter* get_printer(int idx); void initialize_printers(); PrinterData* get_current_printer_data(); unsigned int get_printer_count(); -void announce_printer_data_minimal(PrinterDataMinimal* printer_data); \ No newline at end of file +void announce_printer_data_minimal(PrinterDataMinimal* printer_data); +PrinterDataMinimal* get_printer_data_minimal(int idx); +int get_current_printer_index(); +void add_printer(); +void set_current_printer(int idx); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/macros.cpp b/CYD-Klipper/src/ui/macros.cpp index 9338e8a..f0f90a9 100644 --- a/CYD-Klipper/src/ui/macros.cpp +++ b/CYD-Klipper/src/ui/macros.cpp @@ -3,52 +3,80 @@ #include #include "../core/data_setup.h" -PRINTER_CONFIG * curernt_config = NULL; +typedef struct { + const char* power_device_name; + BasePrinter* printer; +} DoubleStorage; -static void btn_press(lv_event_t * e){ +static void macro_run(lv_event_t * e){ lv_obj_t * btn = lv_event_get_target(e); const char* macro = (const char*)lv_event_get_user_data(e); LOG_F(("Macro: %s\n", macro)) - send_gcode(false, macro); + get_current_printer()->execute_macro(macro); } -void macros_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query) +int macros_add_macros_to_panel(lv_obj_t * root_panel, BasePrinter* printer) { - for (int i = 0; i < query.count; i++){ - const char* macro = query.macros[i]; - lv_create_custom_menu_button(macro, root_panel, btn_press, "Run", (void*)macro); + freeze_request_thread(); + Macros macros = printer->get_macros(); + unfreeze_request_thread(); + + if (!macros.success) + { + return 0; } + + for (int i = 0; i < macros.count; i++) + { + const char* macro = macros.macros[i]; + lv_obj_on_destroy_free_data(root_panel, macro); + lv_create_custom_menu_button(macro, root_panel, macro_run, "Run", (void*)macro); + } + + free(macros.macros); + return macros.count; } 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); - LOG_F(("Power Device: %s, State: %d -> %d\n", power_device_name, !checked, checked)) + DoubleStorage* device = (DoubleStorage*)lv_event_get_user_data(e); + LOG_F(("Power Device: %s, State: %d -> %d\n", device->power_device_name, !checked, checked)) - if (curernt_config != NULL) - set_power_state(power_device_name, checked, curernt_config); + device->printer->set_power_device_state(device->power_device_name, checked); } -void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query) +int macros_add_power_devices_to_panel(lv_obj_t * root_panel, BasePrinter* printer) { - for (int i = 0; i < query.count; i++){ - const char* power_device_name = query.power_devices[i]; - const bool power_device_state = query.power_states[i]; - lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)power_device_name); + freeze_request_thread(); + PowerDevices devices = printer->get_power_devices(); + unfreeze_request_thread(); + + if (!devices.success) + { + return 0; } + + for (int i = 0; i < devices.count; i++) + { + const char* power_device_name = devices.power_devices[i]; + const bool power_device_state = devices.power_states[i]; + DoubleStorage* storage = (DoubleStorage*)malloc(sizeof(DoubleStorage)); + storage->printer = printer; + storage->power_device_name = power_device_name; + lv_obj_on_destroy_free_data(root_panel, storage); + lv_obj_on_destroy_free_data(root_panel, power_device_name); + lv_create_custom_menu_switch(power_device_name, root_panel, power_device_toggle, power_device_state, (void*)storage); + } + + free(devices.power_devices); + free(devices.power_states); + return devices.count; } -void macros_set_current_config(PRINTER_CONFIG * config) +void macros_draw_power_fullscreen(BasePrinter* printer) { - curernt_config = config; -} - -void macros_draw_power_fullscreen(PRINTER_CONFIG * config) -{ - macros_set_current_config(config); - lv_obj_t * parent = lv_create_empty_panel(lv_scr_act()); lv_obj_set_style_bg_opa(parent, LV_OPA_100, 0); lv_obj_align(parent, LV_ALIGN_TOP_RIGHT, 0, 0); @@ -67,11 +95,10 @@ void macros_draw_power_fullscreen(PRINTER_CONFIG * config) lv_label_set_text(label, LV_SYMBOL_CLOSE " Close"); lv_obj_center(label); - POWERQUERY power = power_devices_query(config); - macros_add_power_devices_to_panel(parent, power); + macros_add_power_devices_to_panel(parent, printer); } void macros_draw_power_fullscreen() { - macros_draw_power_fullscreen(get_current_printer_config()); + macros_draw_power_fullscreen(get_current_printer()); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/macros.h b/CYD-Klipper/src/ui/macros.h index 0e6b690..a41d90e 100644 --- a/CYD-Klipper/src/ui/macros.h +++ b/CYD-Klipper/src/ui/macros.h @@ -1,10 +1,10 @@ #pragma once #include "lvgl.h" -#include "../core/macros_query.h" +#include "../conf/global_config.h" +#include "../core/printer_integration.hpp" -void macros_add_macros_to_panel(lv_obj_t * root_panel, MACROSQUERY query); -void macros_add_power_devices_to_panel(lv_obj_t * root_panel, POWERQUERY query); -void macros_set_current_config(PRINTER_CONFIG * config); -void macros_draw_power_fullscreen(PRINTER_CONFIG * config); +int macros_add_macros_to_panel(lv_obj_t * root_panel, BasePrinter* printer); +int macros_add_power_devices_to_panel(lv_obj_t * root_panel, BasePrinter* printer); +void macros_draw_power_fullscreen(BasePrinter* printer); void macros_draw_power_fullscreen(); \ No newline at end of file diff --git a/CYD-Klipper/src/ui/main_ui.cpp b/CYD-Klipper/src/ui/main_ui.cpp index 3a081dc..9df1686 100644 --- a/CYD-Klipper/src/ui/main_ui.cpp +++ b/CYD-Klipper/src/ui/main_ui.cpp @@ -2,17 +2,17 @@ #include "../core/data_setup.h" #include "../conf/global_config.h" #include "../core/screen_driver.h" +#include "../core/printer_integration.hpp" #include "lvgl.h" #include "nav_buttons.h" #include "ui_utils.h" #include "panels/panel.h" -#include "../core/macros_query.h" #include "../core/lv_setup.h" #include "switch_printer.h" #include "macros.h" void check_if_screen_needs_to_be_disabled(){ - if (global_config.on_during_print && printer.state == PRINTER_STATE_PRINTING){ + if (global_config.on_during_print && get_current_printer_data()->state == PrinterState::PrinterStatePrinting){ screen_timer_wake(); screen_timer_stop(); } @@ -24,18 +24,22 @@ void check_if_screen_needs_to_be_disabled(){ static void on_state_change(void * s, lv_msg_t * m){ check_if_screen_needs_to_be_disabled(); - if (printer.state == PRINTER_STATE_OFFLINE){ + PrinterData* printer = get_current_printer_data(); + + if (printer->state == PrinterState::PrinterStateOffline){ nav_buttons_setup(PANEL_CONNECTING); } - else if (printer.state == PRINTER_STATE_ERROR){ + else if (printer->state == PrinterState::PrinterStateError){ nav_buttons_setup(PANEL_ERROR); } - else if (printer.state == PRINTER_STATE_IDLE) { + else if (printer->state == PrinterState::PrinterStateIdle) { nav_buttons_setup(PANEL_FILES); } else { nav_buttons_setup(PANEL_PROGRESS); } + + lv_msg_send(DATA_PRINTER_DATA, get_current_printer()); } void main_ui_setup(){ diff --git a/CYD-Klipper/src/ui/panels/connecting_panel.cpp b/CYD-Klipper/src/ui/panels/connecting_panel.cpp index d39b9d6..a182548 100644 --- a/CYD-Klipper/src/ui/panels/connecting_panel.cpp +++ b/CYD-Klipper/src/ui/panels/connecting_panel.cpp @@ -1,9 +1,11 @@ #include "panel.h" -#include "../../conf/global_config.h" +#include "../../core/printer_integration.hpp" void connecting_panel_init(lv_obj_t* panel) { lv_obj_t* label = lv_label_create(panel); - lv_label_set_text_fmt(label, "Connecting to %s...", (get_current_printer_config()->printer_name[0] == 0) ? get_current_printer_config()->klipper_host : get_current_printer_config()->printer_name); + lv_label_set_text_fmt(label, "Connecting to %s...", (get_current_printer()->printer_config->printer_name[0] == 0) + ? get_current_printer()->printer_config->klipper_host + : get_current_printer()->printer_config->printer_name); lv_obj_align(label, LV_ALIGN_CENTER, 0, 0); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/error_panel.cpp b/CYD-Klipper/src/ui/panels/error_panel.cpp index d24e0c5..3641c4d 100644 --- a/CYD-Klipper/src/ui/panels/error_panel.cpp +++ b/CYD-Klipper/src/ui/panels/error_panel.cpp @@ -1,13 +1,19 @@ #include "panel.h" #include "../../core/data_setup.h" #include "../ui_utils.h" +#include "../../core/printer_integration.hpp" static void btn_click_restart(lv_event_t * e){ - send_gcode(false, "RESTART"); + get_current_printer()->execute_feature(PrinterFeatureRestart); } static void btn_click_firmware_restart(lv_event_t * e){ - send_gcode(false, "FIRMWARE_RESTART"); + get_current_printer()->execute_feature(PrinterFeatureFirmwareRestart); +} + +static void set_state_message_text(lv_event_t * e) { + lv_obj_t * label = lv_event_get_target(e); + lv_label_set_text(label, get_current_printer_data()->state_message); } void error_panel_init(lv_obj_t* panel) @@ -25,9 +31,10 @@ void error_panel_init(lv_obj_t* panel) lv_obj_set_width(panel_with_text, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); label = lv_label_create(panel_with_text); - lv_label_set_text(label, printer.state_message); lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2); lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + lv_obj_add_event_cb(label, set_state_message_text, LV_EVENT_MSG_RECEIVED, NULL); + lv_msg_subscribe_obj(DATA_PRINTER_DATA, label, NULL); lv_obj_t * button_row = lv_create_empty_panel(panel); lv_obj_set_size(button_row, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); diff --git a/CYD-Klipper/src/ui/panels/files_panel.cpp b/CYD-Klipper/src/ui/panels/files_panel.cpp index fe22a56..b6c29a5 100644 --- a/CYD-Klipper/src/ui/panels/files_panel.cpp +++ b/CYD-Klipper/src/ui/panels/files_panel.cpp @@ -1,36 +1,33 @@ #include "lvgl.h" #include "panel.h" + #include "../../core/data_setup.h" -#include "../../core/files_query.h" #include "../../conf/global_config.h" #include #include "../ui_utils.h" #include "../../core/lv_setup.h" #include "../gcode_img.h" -#include "../../core/http_client.h" #include +#include "../../core/printer_integration.hpp" -FILESYSTEM_FILE* selected_file = NULL; +const char* selected_file = NULL; static void btn_print_file(lv_event_t * e){ lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e); lv_obj_del(panel); - SETUP_HTTP_CLIENT("/printer/print/start?filename=" + urlEncode(selected_file->name)); - - int httpCode = client.POST(""); - LOG_F(("Print start: HTTP %d\n", httpCode)) + get_current_printer()->start_file(selected_file); } static void btn_print_file_verify(lv_event_t * e){ - if (printer.state != PRINTER_STATE_IDLE){ + if (get_current_printer_data()->state != PrinterState::PrinterStateIdle){ return; } 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); + selected_file = (char*)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_GAP_PX * 2, 0); @@ -42,7 +39,7 @@ static void btn_print_file_verify(lv_event_t * e){ lv_obj_align(label_print_file, LV_ALIGN_TOP_LEFT, 0, 0); lv_obj_t * label = lv_label_create(panel); - lv_label_set_text(label, selected_file->name); + lv_label_set_text(label, selected_file); lv_obj_align(label, LV_ALIGN_CENTER, 0, -20); lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 10); lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); @@ -65,7 +62,7 @@ static void btn_print_file_verify(lv_event_t * e){ lv_label_set_text(label, LV_SYMBOL_OK); lv_obj_center(label); - lv_obj_t* img = show_gcode_img(selected_file->name); + lv_obj_t* img = show_gcode_img(selected_file); if (img != NULL){ lv_obj_set_parent(img, panel); @@ -81,7 +78,14 @@ static void btn_print_file_verify(lv_event_t * e){ } void files_panel_init(lv_obj_t* panel){ - clear_img_mem(); + Files files = get_current_printer()->get_files(); + + if (!files.success || files.count <= 0){ + 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); + return; + } lv_obj_t * list = lv_list_create(panel); lv_obj_set_style_radius(list, 0, 0); @@ -90,25 +94,19 @@ void files_panel_init(lv_obj_t* panel){ lv_obj_set_size(list, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX); lv_obj_align(list, LV_ALIGN_CENTER, 0, 0); - FILESYSTEM_FILE* files = get_files(25); - 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); + for (int i = 0; i < files.count; i++) + { + lv_obj_t * btn = lv_list_add_btn(list, LV_SYMBOL_FILE, files.available_files[i]); lv_obj_set_style_bg_opa(btn, LV_OPA_TRANSP, 0); if (global_config.full_filenames){ lv_label_set_long_mode(lv_obj_get_child(btn, 1), LV_LABEL_LONG_WRAP); } - lv_obj_add_event_cb(btn, btn_print_file_verify, LV_EVENT_CLICKED, (void*)files); - - files += 1; - count++; + lv_obj_add_event_cb(btn, btn_print_file_verify, LV_EVENT_CLICKED, (void*)(files.available_files[i])); + lv_obj_on_destroy_free_data(btn, files.available_files[i]); } - 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); - } + // Not deallocating filenames in this scope will cause double allocation, oh well. + // TODO: read label text + free(files.available_files); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/macros_panel.cpp b/CYD-Klipper/src/ui/panels/macros_panel.cpp index f48d935..ef7b762 100644 --- a/CYD-Klipper/src/ui/panels/macros_panel.cpp +++ b/CYD-Klipper/src/ui/panels/macros_panel.cpp @@ -11,8 +11,6 @@ static void btn_goto_settings(lv_event_t * e){ } void macros_panel_init(lv_obj_t* panel) { - macros_set_current_config(get_current_printer_config()); - lv_obj_t * btn = lv_btn_create(panel); lv_obj_add_event_cb(btn, btn_goto_settings, LV_EVENT_CLICKED, NULL); lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); @@ -22,27 +20,23 @@ void macros_panel_init(lv_obj_t* panel) { lv_label_set_text(label, LV_SYMBOL_SETTINGS " Screen Settings"); lv_obj_center(label); - MACROSQUERY macros = macros_query(); - POWERQUERY power = power_devices_query(); - lv_obj_t * root_panel = lv_create_empty_panel(panel); lv_obj_set_scrollbar_mode(root_panel, LV_SCROLLBAR_MODE_OFF); lv_obj_set_size(root_panel, CYD_SCREEN_PANEL_WIDTH_PX, CYD_SCREEN_PANEL_HEIGHT_PX - CYD_SCREEN_MIN_BUTTON_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2); lv_obj_align(root_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX + CYD_SCREEN_GAP_PX * 2); lv_layout_flex_column(root_panel); - macros_add_power_devices_to_panel(root_panel, power); + int power_count = macros_add_power_devices_to_panel(root_panel, get_current_printer()); + int macros_count = macros_add_macros_to_panel(root_panel, get_current_printer()); - if (macros.count == 0){ + if (macros_count <= 0){ label = lv_label_create(root_panel); lv_label_set_text(label, "No macros found.\nMacros with the description\n\"CYD_SCREEN_MACRO\"\nwill show up here."); - if (power.count == 0){ + if (power_count <= 0){ lv_layout_flex_column(root_panel, LV_FLEX_ALIGN_CENTER); } return; } - - macros_add_macros_to_panel(root_panel, macros); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/panels/move_panel.cpp b/CYD-Klipper/src/ui/panels/move_panel.cpp index 0c24c05..55ffe6e 100644 --- a/CYD-Klipper/src/ui/panels/move_panel.cpp +++ b/CYD-Klipper/src/ui/panels/move_panel.cpp @@ -5,6 +5,7 @@ #include "../ui_utils.h" #include #include +#include "../../core/printer_integration.hpp" static bool last_homing_state = false; static bool move_edit_mode = false; @@ -21,7 +22,7 @@ char z_offset_labels[6 * OFFSET_LABEL_SIZE] = {0}; static void calculate_offsets_from_current_printer() { - unsigned short* items[] = {get_current_printer_config()->printer_move_x_steps, get_current_printer_config()->printer_move_y_steps, get_current_printer_config()->printer_move_z_steps}; + unsigned short* items[] = {get_current_printer()->printer_config->printer_move_x_steps, get_current_printer()->printer_config->printer_move_y_steps, get_current_printer()->printer_config->printer_move_z_steps}; float* offsets[] = {(float*)x_offsets, (float*)y_offsets, (float*)z_offsets}; char * labels[] = {(char*)x_offset_labels, (char*)y_offset_labels, (char*)z_offset_labels}; @@ -74,7 +75,7 @@ static void keyboard_cb_edit_move_increment(lv_event_t * e) return; } - unsigned short* items[] = {get_current_printer_config()->printer_move_x_steps, get_current_printer_config()->printer_move_y_steps, get_current_printer_config()->printer_move_z_steps}; + unsigned short* items[] = {get_current_printer()->printer_config->printer_move_x_steps, get_current_printer()->printer_config->printer_move_y_steps, get_current_printer()->printer_config->printer_move_z_steps}; LOG_F(("Setting increment %d %d %f\n", selected_column, selected_row, increment)) items[selected_column][selected_row] = increment * 10; write_global_config(); @@ -109,7 +110,7 @@ static void x_line_button_press(lv_event_t * e) { } float data = *data_pointer; - move_printer("X", data, true); + get_current_printer()->move_printer("X", data, true); } static void y_line_button_press(lv_event_t * e) { @@ -122,7 +123,7 @@ static void y_line_button_press(lv_event_t * e) { } float data = *data_pointer; - move_printer("Y", data, true); + get_current_printer()->move_printer("Y", data, true); } static void z_line_button_press(lv_event_t * e) { @@ -135,27 +136,27 @@ static void z_line_button_press(lv_event_t * e) { } float data = *data_pointer; - move_printer("Z", data, true); + get_current_printer()->move_printer("Z", data, true); } static void x_pos_update(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); char x_pos_buff[12]; - sprintf(x_pos_buff, "X: %.1f", printer.position[0]); + sprintf(x_pos_buff, "X: %.1f", get_current_printer_data()->position[0]); lv_label_set_text(label, x_pos_buff); } static void y_pos_update(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); char y_pos_buff[12]; - sprintf(y_pos_buff, "Y: %.1f", printer.position[1]); + sprintf(y_pos_buff, "Y: %.1f", get_current_printer_data()->position[1]); lv_label_set_text(label, y_pos_buff); } static void z_pos_update(lv_event_t * e){ lv_obj_t * label = lv_event_get_target(e); char z_pos_buff[12]; - sprintf(z_pos_buff, "Z: %.2f", printer.position[2]); + sprintf(z_pos_buff, "Z: %.2f", get_current_printer_data()->position[2]); lv_label_set_text(label, z_pos_buff); } @@ -163,17 +164,17 @@ 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}; static void home_button_click(lv_event_t * e) { - if (printer.state == PRINTER_STATE_PRINTING) + if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting) return; - send_gcode(false, "G28"); + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureHome); } static void disable_steppers_click(lv_event_t * e) { - if (printer.state == PRINTER_STATE_PRINTING) + if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting) return; - send_gcode(true, "M18"); + get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureDisableSteppers); } static void switch_to_stat_panel(lv_event_t * e) { @@ -194,7 +195,7 @@ static void line_custom_set(const char * axis, const char *text) if (pos < 0 || pos > 500) return; - move_printer(axis, pos, false); + get_current_printer()->move_printer(axis, pos, false); } static void x_line_custom_callback(lv_event_t * e) { @@ -339,28 +340,28 @@ inline void root_panel_steppers_unlocked(lv_obj_t * root_panel){ } static void root_panel_state_update(lv_event_t * e){ - if (last_homing_state == printer.homed_axis) + if (last_homing_state == get_current_printer_data()->homed_axis) return; lv_obj_t * panel = lv_event_get_target(e); - last_homing_state = printer.homed_axis; + last_homing_state = get_current_printer_data()->homed_axis; lv_obj_clean(panel); - if (printer.homed_axis) + if (get_current_printer_data()->homed_axis) root_panel_steppers_locked(panel); else root_panel_steppers_unlocked(panel); } void move_panel_init(lv_obj_t* panel){ - if (printer.state == PRINTER_STATE_PRINTING){ + if (get_current_printer_data()->state == PrinterState::PrinterStatePrinting){ stats_panel_init(panel); return; } calculate_offsets_from_current_printer(); - last_homing_state = !printer.homed_axis; + last_homing_state = !get_current_printer_data()->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); diff --git a/CYD-Klipper/src/ui/panels/panel.h b/CYD-Klipper/src/ui/panels/panel.h index 7c3c283..ef8b27e 100644 --- a/CYD-Klipper/src/ui/panels/panel.h +++ b/CYD-Klipper/src/ui/panels/panel.h @@ -1,5 +1,4 @@ #include "lvgl.h" -#include "../../core/macros_query.h" #define SIZEOF(arr) (sizeof(arr) / sizeof(*arr)) diff --git a/CYD-Klipper/src/ui/panels/printer_panel.cpp b/CYD-Klipper/src/ui/panels/printer_panel.cpp index 19a29d2..b048437 100644 --- a/CYD-Klipper/src/ui/panels/printer_panel.cpp +++ b/CYD-Klipper/src/ui/panels/printer_panel.cpp @@ -5,7 +5,6 @@ #include "../../core/lv_setup.h" #include #include "../nav_buttons.h" -#include "../../core/macros_query.h" #include "../switch_printer.h" #include "../macros.h" @@ -22,41 +21,32 @@ const static lv_point_t line_points[] = { {0, 0}, {(short int)((CYD_SCREEN_PANEL static void update_printer_name_text(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - int index = config - global_config.printer_config; - PrinterMinimal * printer = &printer_minimal[index]; - - lv_label_set_text(label, config->printer_name[0] == 0 ? config->klipper_host : config->printer_name); + int config_index = (int)lv_event_get_user_data(e); + BasePrinter* printer = get_printer(config_index); + lv_label_set_text(label, printer->printer_config->printer_name[0] == 0 ? printer->printer_config->klipper_host : printer->printer_config->printer_name); } static void update_printer_status_text(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - int index = config - global_config.printer_config; - PrinterMinimal * printer = &printer_minimal[index]; + int config_index = (int)lv_event_get_user_data(e); + PrinterDataMinimal* printer = get_printer_data_minimal(config_index); - if (config == get_current_printer_config()) + if (config_index == get_current_printer_index()) { lv_label_set_text(label, "In Control"); return; } - if (printer->state == PRINTER_STATE_OFFLINE) - { - lv_label_set_text(label, "Offline"); - return; - } - lv_label_set_text(label, printer_status[printer->state]); } static void update_printer_label_visible_active_printer(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int config_index = (int)lv_event_get_user_data(e); - if (config == get_current_printer_config()) + if (config_index == get_current_printer_index()) { lv_label_set_text(label, LV_SYMBOL_WIFI); } @@ -69,14 +59,15 @@ static void update_printer_label_visible_active_printer(lv_event_t * e) static void update_printer_percentage_bar(lv_event_t * e) { lv_obj_t * percentage = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - int index = config - global_config.printer_config; - PrinterMinimal * printer = &printer_minimal[index]; + int config_index = (int)lv_event_get_user_data(e); + PrinterDataMinimal* printer = get_printer_data_minimal(config_index); - if (printer->state != PRINTER_STATE_OFFLINE && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED)){ + if (printer->state == PrinterState::PrinterStatePrinting || printer->state == PrinterState::PrinterStatePaused) + { lv_bar_set_value(percentage, printer->print_progress * 100, LV_ANIM_OFF); } - else { + else + { lv_bar_set_value(percentage, 0, LV_ANIM_OFF); } } @@ -84,11 +75,10 @@ static void update_printer_percentage_bar(lv_event_t * e) static void update_printer_percentage_text(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - int index = config - global_config.printer_config; - PrinterMinimal * printer = &printer_minimal[index]; + int config_index = (int)lv_event_get_user_data(e); + PrinterDataMinimal* printer = get_printer_data_minimal(config_index); - if (printer->state != PRINTER_STATE_OFFLINE && (printer->state == PRINTER_STATE_PRINTING || printer->state == PRINTER_STATE_PAUSED)) + if (printer->state == PrinterState::PrinterStatePrinting || printer->state == PrinterState::PrinterStatePaused) { char percentage_buffer[12]; sprintf(percentage_buffer, "%.2f%%", printer->print_progress * 100); @@ -103,11 +93,10 @@ static void update_printer_percentage_text(lv_event_t * e) static void update_printer_control_button_text(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - int index = config - global_config.printer_config; - PrinterMinimal * printer = &printer_minimal[index]; + int config_index = (int)lv_event_get_user_data(e); + PrinterDataMinimal* printer = get_printer_data_minimal(config_index); - if (printer->power_devices > 0 && (config == get_current_printer_config() || printer->state == PRINTER_STATE_OFFLINE)) + if (printer->power_devices > 0 && (config_index == get_current_printer_index() || printer->state == PrinterState::PrinterStateOffline)) { lv_label_set_text(label, "Power"); } @@ -120,9 +109,10 @@ static void update_printer_control_button_text(lv_event_t * e) static void btn_set_secondary_button_text(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + int config_index = (int)lv_event_get_user_data(e); + PrinterDataMinimal* printer = get_printer_data_minimal(config_index); - if (config == get_current_printer_config()) + if (config_index == get_current_printer_index()) { lv_label_set_text(label, LV_SYMBOL_SETTINGS); } @@ -135,11 +125,10 @@ static void btn_set_secondary_button_text(lv_event_t * e) static void btn_enable_control(lv_event_t * e) { lv_obj_t * btn = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - int index = config - global_config.printer_config; - PrinterMinimal * printer = &printer_minimal[index]; + int config_index = (int)lv_event_get_user_data(e); + PrinterDataMinimal* printer = get_printer_data_minimal(config_index); - if ((config == get_current_printer_config() || printer->state == PRINTER_STATE_OFFLINE) && printer->power_devices <= 0) + if ((config_index == get_current_printer_index() || printer->state == PrinterState::PrinterStateOffline) && printer->power_devices <= 0) { // Disable lv_obj_add_state(btn, LV_STATE_DISABLED); @@ -152,7 +141,7 @@ static void btn_enable_control(lv_event_t * e) } } -PRINTER_CONFIG * keyboard_config = NULL; +PrinterConfiguration * keyboard_config = NULL; static void keyboard_callback(lv_event_t * e){ lv_obj_t * ta = lv_event_get_target(e); @@ -167,15 +156,16 @@ static void keyboard_callback(lv_event_t * e){ static void btn_printer_secondary(lv_event_t * e) { lv_obj_t * btn = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - - if (config == get_current_printer_config()) + int config_index = (int)lv_event_get_user_data(e); + BasePrinter* printer = get_printer(config_index); + + if (config_index == get_current_printer_index()) { nav_buttons_setup(PANEL_SETTINGS); return; } - config->ip_configured = false; + printer->printer_config->ip_configured = false; write_global_config(); nav_buttons_setup(PANEL_PRINTER); @@ -183,33 +173,33 @@ static void btn_printer_secondary(lv_event_t * e) static void btn_printer_rename(lv_event_t * e) { - keyboard_config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + keyboard_config = (PrinterConfiguration*)lv_event_get_user_data(e); lv_create_keyboard_text_entry(keyboard_callback, "Rename Printer", LV_KEYBOARD_MODE_TEXT_LOWER, CYD_SCREEN_WIDTH_PX * 0.75, 24, keyboard_config->printer_name, false); } static void btn_printer_activate(lv_event_t * e) { lv_obj_t * label = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); - int index = config - global_config.printer_config; - PrinterMinimal * printer = &printer_minimal[index]; + int config_index = (int)lv_event_get_user_data(e); + PrinterDataMinimal* printer = get_printer_data_minimal(config_index); + BasePrinter* printer_full = get_printer(config_index); - if (printer->power_devices > 0 && (config == get_current_printer_config() || printer->state == PRINTER_STATE_OFFLINE)) + if (printer->power_devices > 0 && (config_index == get_current_printer_index() || printer->state == PrinterState::PrinterStateOffline)) { - macros_draw_power_fullscreen(config); + macros_draw_power_fullscreen(printer_full); return; } - switch_printer(index); + set_current_printer(config_index); lv_msg_send(DATA_PRINTER_MINIMAL, NULL); } static void btn_printer_add(lv_event_t * e) { - set_printer_config_index(get_printer_config_free_index()); + add_printer(); } -void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) +void create_printer_ui(PrinterConfiguration * config, lv_obj_t * root) { int index = config - global_config.printer_config; auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2; @@ -219,16 +209,16 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_set_size(data_row_name, width, LV_SIZE_CONTENT); lv_obj_t * label = lv_label_create(data_row_name); - lv_obj_add_event_cb(label, update_printer_name_text, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + lv_obj_add_event_cb(label, update_printer_name_text, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, (void*)index); label = lv_label_create(data_row_name); - lv_obj_add_event_cb(label, update_printer_label_visible_active_printer, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + lv_obj_add_event_cb(label, update_printer_label_visible_active_printer, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, (void*)index); label = lv_label_create(data_row_name); - lv_obj_add_event_cb(label, update_printer_status_text, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + lv_obj_add_event_cb(label, update_printer_status_text, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, (void*)index); lv_obj_t * progress_row = lv_create_empty_panel(root); lv_layout_flex_row(progress_row); @@ -236,13 +226,13 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_t * progress_bar = lv_bar_create(progress_row); lv_obj_set_flex_grow(progress_bar, 1); - lv_obj_add_event_cb(progress_bar, update_printer_percentage_bar, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, progress_bar, config); + lv_obj_add_event_cb(progress_bar, update_printer_percentage_bar, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, progress_bar, (void*)index); label = lv_label_create(progress_row); lv_obj_set_style_text_font(label, &CYD_SCREEN_FONT_SMALL, 0); - lv_obj_add_event_cb(label, update_printer_percentage_text, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + lv_obj_add_event_cb(label, update_printer_percentage_text, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, (void*)index); lv_obj_t * button_row = lv_create_empty_panel(root); lv_layout_flex_row(button_row); @@ -250,16 +240,16 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) lv_obj_t * btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 1); - lv_obj_add_event_cb(btn, btn_printer_secondary, LV_EVENT_CLICKED, config); + lv_obj_add_event_cb(btn, btn_printer_secondary, LV_EVENT_CLICKED, (void*)index); label = lv_label_create(btn); lv_obj_center(label); - lv_obj_add_event_cb(label, btn_set_secondary_button_text, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + lv_obj_add_event_cb(label, btn_set_secondary_button_text, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, (void*)index); btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 2); - lv_obj_add_event_cb(btn, btn_printer_rename, LV_EVENT_CLICKED, config); + lv_obj_add_event_cb(btn, btn_printer_rename, LV_EVENT_CLICKED, (void*)index); label = lv_label_create(btn); lv_label_set_text(label, "Rename"); @@ -267,14 +257,14 @@ void create_printer_ui(PRINTER_CONFIG * config, lv_obj_t * root) btn = lv_btn_create(button_row); lv_obj_set_flex_grow(btn, 2); - lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, config); - lv_obj_add_event_cb(btn, btn_enable_control, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, config); + lv_obj_add_event_cb(btn, btn_printer_activate, LV_EVENT_CLICKED, (void*)index); + lv_obj_add_event_cb(btn, btn_enable_control, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, btn, (void*)index); label = lv_label_create(btn); lv_obj_center(label); - lv_obj_add_event_cb(label, update_printer_control_button_text, LV_EVENT_MSG_RECEIVED, config); - lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, config); + lv_obj_add_event_cb(label, update_printer_control_button_text, LV_EVENT_MSG_RECEIVED, (void*)index); + lv_msg_subsribe_obj(DATA_PRINTER_MINIMAL, label, (void*)index); lv_obj_t * line = lv_line_create(root); lv_line_set_points(line, line_points, 2); @@ -293,14 +283,14 @@ void printer_panel_init(lv_obj_t* panel) lv_obj_set_size(lv_create_empty_panel(inner_panel), 0, 0); for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){ - PRINTER_CONFIG * config = &global_config.printer_config[i]; + PrinterConfiguration * config = &global_config.printer_config[i]; if (config->ip_configured) { create_printer_ui(&global_config.printer_config[i], inner_panel); } } // Add Printer Button - if (get_printer_config_free_index() != -1){ + if (get_printer_count() == PRINTER_CONFIG_COUNT){ lv_obj_t * btn = lv_btn_create(inner_panel); lv_obj_set_size(btn, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX); lv_obj_add_event_cb(btn, btn_printer_add, LV_EVENT_CLICKED, NULL); @@ -311,6 +301,4 @@ void printer_panel_init(lv_obj_t* panel) } lv_obj_set_size(lv_create_empty_panel(inner_panel), 0, 0); - - lv_msg_send(DATA_PRINTER_MINIMAL, NULL); } \ No newline at end of file diff --git a/CYD-Klipper/src/ui/switch_printer.cpp b/CYD-Klipper/src/ui/switch_printer.cpp index 708de3a..a703178 100644 --- a/CYD-Klipper/src/ui/switch_printer.cpp +++ b/CYD-Klipper/src/ui/switch_printer.cpp @@ -17,7 +17,7 @@ void switch_printer(int index) static void btn_switch_printer(lv_event_t *e){ lv_obj_t *btn = lv_event_get_target(e); - PRINTER_CONFIG * config = (PRINTER_CONFIG*)lv_event_get_user_data(e); + PrinterConfiguration * config = (PrinterConfiguration*)lv_event_get_user_data(e); int index = config - global_config.printer_config; switch_printer(index); @@ -45,7 +45,7 @@ void switch_printer_init() { lv_obj_center(label); for (int i = 0; i < PRINTER_CONFIG_COUNT; i++){ - PRINTER_CONFIG * config = &global_config.printer_config[i]; + PrinterConfiguration * config = &global_config.printer_config[i]; const char* printer_name = (config->printer_name[0] == 0) ? config->klipper_host : config->printer_name; if (config == get_current_printer_config() && config->ip_configured) diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index 12c9053..391c0d1 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -40,9 +40,9 @@ void destroy_event_free_data(lv_event_t * e) free(data); } -void lv_on_destroy_free_data(lv_obj_t * element, void* ptr) +void lv_obj_on_destroy_free_data(lv_obj_t * element, const void* ptr) { - lv_obj_add_event_cb(element, destroy_event_free_data, LV_EVENT_DELETE, ptr); + lv_obj_add_event_cb(element, destroy_event_free_data, LV_EVENT_DELETE, (void*)ptr); } void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count){ diff --git a/CYD-Klipper/src/ui/ui_utils.h b/CYD-Klipper/src/ui/ui_utils.h index 32790b3..020ba71 100644 --- a/CYD-Klipper/src/ui/ui_utils.h +++ b/CYD-Klipper/src/ui/ui_utils.h @@ -38,7 +38,7 @@ void lv_layout_flex_column(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN void lv_layout_flex_row(lv_obj_t* obj, lv_flex_align_t allign = LV_FLEX_ALIGN_START, lv_coord_t pad_column = CYD_SCREEN_GAP_PX, lv_coord_t pad_row = CYD_SCREEN_GAP_PX); void lv_create_fullscreen_button_matrix_popup(lv_obj_t * root, lv_event_cb_t title, lv_button_column_t* columns, int column_count); void destroy_event_user_data(lv_event_t * e); -void lv_on_destroy_free_data(lv_obj_t * element, void* ptr); +void lv_obj_on_destroy_free_data(lv_obj_t * element, const void* ptr); void lv_create_keyboard_text_entry(lv_event_cb_t keyboard_callback, const char* title = NULL, lv_keyboard_mode_t keyboard_mode = LV_KEYBOARD_MODE_NUMBER, lv_coord_t width = CYD_SCREEN_PANEL_WIDTH_PX / 2, uint8_t max_length = 3, const char* fill_text = "", bool contain_in_panel= true); void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_obj_t* root_panel, bool set_height = true, const char * comment = NULL); void lv_create_custom_menu_button(const char *label_text, lv_obj_t* root_panel, lv_event_cb_t on_click, const char *btn_text, void * user_data = NULL, const char * comment = NULL);