diff --git a/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp b/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp index d919747..29844ae 100644 --- a/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp +++ b/CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp @@ -187,8 +187,8 @@ bool KlipperPrinter::fetch() if (status.containsKey("webhooks")) { - const char *state = status["webhooks"]["state"]; - const char *message = status["webhooks"]["state_message"]; + const char* state = status["webhooks"]["state"]; + const char* message = status["webhooks"]["state_message"]; if (strcmp(state, "ready") == 0 && printer_data.state == PrinterStateError) { @@ -199,7 +199,7 @@ bool KlipperPrinter::fetch() printer_data.state = PrinterStateError; } - if (printer_data.state_message == NULL || strcmp(printer_data.state_message, message)) + if (message != NULL && (printer_data.state_message == NULL || strcmp(printer_data.state_message, message))) { printer_data.state_message = (char *)malloc(strlen(message) + 1); strcpy(printer_data.state_message, message); @@ -452,7 +452,7 @@ void KlipperPrinter::disconnect() Macros KlipperPrinter::get_macros() { HTTPClient client; - Macros macros; + Macros macros = {0}; configure_http_client(client, "/printer/gcode/help", true, 1000); int http_code = client.GET(); @@ -522,7 +522,7 @@ bool KlipperPrinter::execute_macro(const char* macro) PowerDevices KlipperPrinter::get_power_devices() { HTTPClient client; - PowerDevices power_devices; + PowerDevices power_devices = {0}; configure_http_client(client, "/machine/device_power/devices", true, 1000); int http_code = client.GET(); @@ -590,7 +590,7 @@ typedef struct { Files KlipperPrinter::get_files() { - Files files_result; + Files files_result = {0}; HTTPClient client; LOG_F(("Heap space pre-file-parse: %d bytes\n", esp_get_free_heap_size())) std::list files; @@ -704,7 +704,7 @@ Thumbnail KlipperPrinter::get_32_32_png_image_thumbnail(const char* gcode_filena { Thumbnail thumbnail = {0}; HTTPClient client; - configure_http_client(client, "/server/files/thumbnails?filename=", true, 1000); + configure_http_client(client, "/server/files/thumbnails?filename=" + urlEncode(gcode_filename), true, 1000); char* img_filename_path = NULL; unsigned char* data_png = NULL; @@ -725,7 +725,6 @@ Thumbnail KlipperPrinter::get_32_32_png_image_thumbnail(const char* gcode_filena deserializeJson(doc, client.getStream()); auto result = doc["result"].as(); const char* chosen_thumb = NULL; - for (auto file : result){ int width = file["width"]; int height = file["height"]; @@ -735,9 +734,10 @@ Thumbnail KlipperPrinter::get_32_32_png_image_thumbnail(const char* gcode_filena if (width != height || width != 32) continue; + if (strcmp(thumbnail + strlen(thumbnail) - 4, ".png")) continue; - + chosen_thumb = thumbnail; break; } @@ -755,6 +755,7 @@ Thumbnail KlipperPrinter::get_32_32_png_image_thumbnail(const char* gcode_filena if (img_filename_path == NULL) { + LOG_LN("No compatible thumbnail found"); return thumbnail; } diff --git a/CYD-Klipper/src/core/printer_integration.cpp b/CYD-Klipper/src/core/printer_integration.cpp index 3f754f6..9168da4 100644 --- a/CYD-Klipper/src/core/printer_integration.cpp +++ b/CYD-Klipper/src/core/printer_integration.cpp @@ -1,25 +1,20 @@ #include "printer_integration.hpp" #include "lv_setup.h" #include "screen_driver.h" +#include -unsigned char current_printer_index = 0; -unsigned char total_printers; -BasePrinter** registered_printers; -PrinterDataMinimal* minimal_data_copy; -PrinterData* printer_data_copy; +static char blank[] = { '\0' }; +static unsigned char current_printer_index = 0; +static unsigned char total_printers; +static BasePrinter** registered_printers; +static PrinterDataMinimal* minimal_data_copy; +static PrinterData* printer_data_copy; BasePrinter::BasePrinter(unsigned char index) { config_index = index; printer_config = &global_config.printer_config[index]; - - printer_data.state_message = (char*)malloc(1); - printer_data.print_filename = (char*)malloc(1); - printer_data.popup_message = (char*)malloc(1); - *printer_data.state_message = '\0'; - *printer_data.print_filename = '\0'; - *printer_data.popup_message = '\0'; - + memset(&printer_data, 0, sizeof(PrinterData)); // TODO: Fetch printer config and global config } @@ -27,27 +22,46 @@ PrinterData* BasePrinter::AnnouncePrinterData() { char* old_state_message = printer_data_copy->state_message; char* old_print_filename = printer_data_copy->print_filename; - char* old_popup_message = printer_data_copy->print_filename; + char* old_popup_message = printer_data_copy->popup_message; + PrinterState old_state = printer_data_copy->state; memcpy(printer_data_copy, &printer_data, sizeof(PrinterData)); - if (old_state_message != printer_data_copy->state_message) + if (printer_data_copy->state_message == NULL) + { + printer_data_copy->state_message = blank; + } + + if (printer_data_copy->print_filename == NULL) + { + printer_data_copy->print_filename = blank; + } + + if (printer_data_copy->popup_message == NULL) + { + printer_data_copy->popup_message = blank; + } + + if (old_state_message != printer_data_copy->state_message && old_state_message != NULL && old_state_message != blank) { + LOG_F(("Freeing state message '%s' (%x)\n", old_state_message, old_state_message)); free(old_state_message); } - if (old_print_filename != printer_data_copy->print_filename) + if (old_print_filename != printer_data_copy->print_filename && old_print_filename != NULL && old_print_filename != blank) { + LOG_F(("Freeing print filename '%s' (%x)\n", old_print_filename, old_print_filename)); free(old_print_filename); } - if (printer_data.state != printer_data_copy->state) + if (old_state != printer_data_copy->state) { lv_msg_send(DATA_PRINTER_STATE, get_current_printer()); } - if (old_popup_message != printer_data_copy->popup_message) + if (old_popup_message != printer_data_copy->popup_message && old_popup_message != NULL && old_popup_message != blank) { + LOG_F(("Freeing popup message '%s' (%x)\n", old_popup_message, old_popup_message)); free(old_popup_message); lv_msg_send(DATA_PRINTER_POPUP, get_current_printer()); } @@ -60,6 +74,7 @@ void initialize_printers(BasePrinter** printers, unsigned char total) { printer_data_copy = (PrinterData*)malloc(sizeof(PrinterData)); minimal_data_copy = (PrinterDataMinimal*)malloc(sizeof(PrinterDataMinimal) * total_printers); + memset(printer_data_copy, 0, sizeof(PrinterData)); memset(minimal_data_copy, 0, sizeof(PrinterDataMinimal) * total_printers); registered_printers = printers; total_printers = total; diff --git a/CYD-Klipper/src/ui/ip_setup.cpp b/CYD-Klipper/src/ui/ip_setup.cpp index 859c15e..f7e22f2 100644 --- a/CYD-Klipper/src/ui/ip_setup.cpp +++ b/CYD-Klipper/src/ui/ip_setup.cpp @@ -83,6 +83,7 @@ static void keyboard_event_ip_entry(lv_event_t * e) { if (status == ConnectionStatus::ConnectOk) { global_config.printer_config[global_config.printer_index].ip_configured = true; + global_config.printer_config[global_config.printer_index].setup_complete = true; write_global_config(); } else if (status == ConnectionStatus::ConnectAuthRequired) diff --git a/CYD-Klipper/src/ui/panels/stats_panel.cpp b/CYD-Klipper/src/ui/panels/stats_panel.cpp index 22a34b5..c964b62 100644 --- a/CYD-Klipper/src/ui/panels/stats_panel.cpp +++ b/CYD-Klipper/src/ui/panels/stats_panel.cpp @@ -9,10 +9,15 @@ static void swap_to_files_menu(lv_event_t * e) { nav_buttons_setup(PANEL_FILES); } +static void update_data(lv_event_t * e) { + lv_msg_send(DATA_PRINTER_DATA, get_current_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_add_event_cb(btn, update_data, 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); diff --git a/CYD-Klipper/src/ui/panels/temp_panel.cpp b/CYD-Klipper/src/ui/panels/temp_panel.cpp index c360946..c0c1507 100644 --- a/CYD-Klipper/src/ui/panels/temp_panel.cpp +++ b/CYD-Klipper/src/ui/panels/temp_panel.cpp @@ -237,9 +237,9 @@ void create_charts(lv_obj_t * root) lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y); lv_chart_set_all_value(chart, ser2, get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1]); lv_chart_series_t * ser3 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_TEAL), LV_CHART_AXIS_PRIMARY_Y); - lv_chart_set_all_value(chart, ser3, get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); + lv_chart_set_all_value(chart, ser3, get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); lv_chart_series_t * ser4 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_BLUE), LV_CHART_AXIS_PRIMARY_Y); - lv_chart_set_all_value(chart, ser4, get_current_printer_data()->target_temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); + lv_chart_set_all_value(chart, ser4, get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]); lv_obj_add_event_cb(chart, set_hotend_target_temp_chart, LV_EVENT_MSG_RECEIVED, ser1); lv_obj_add_event_cb(chart, set_hotend_temp_chart, LV_EVENT_MSG_RECEIVED, ser2); diff --git a/CYD-Klipper/src/ui/ui_utils.cpp b/CYD-Klipper/src/ui/ui_utils.cpp index 4d645f0..3fcf4fc 100644 --- a/CYD-Klipper/src/ui/ui_utils.cpp +++ b/CYD-Klipper/src/ui/ui_utils.cpp @@ -268,6 +268,8 @@ void lv_create_popup_message(const char* message, uint16_t timeout_ms) lv_label_set_text_fmt(label, "%s", message); lv_obj_set_size(label, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 6, LV_SIZE_CONTENT); lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); + + timer = lv_timer_create(timer_callback, timeout_ms, panel); } lv_obj_t * lv_label_btn_create(lv_obj_t * parent, lv_event_cb_t btn_callback, void* user_data)