Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Oct 28, 2024
1 parent d6e788f commit b99e00d
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 29 deletions.
19 changes: 10 additions & 9 deletions CYD-Klipper/src/core/klipper/klipper_printer_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<FileSystemFile> files;
Expand Down Expand Up @@ -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;

Expand All @@ -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<JsonArray>();
const char* chosen_thumb = NULL;

for (auto file : result){
int width = file["width"];
int height = file["height"];
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down
51 changes: 33 additions & 18 deletions CYD-Klipper/src/core/printer_integration.cpp
Original file line number Diff line number Diff line change
@@ -1,53 +1,67 @@
#include "printer_integration.hpp"
#include "lv_setup.h"
#include "screen_driver.h"
#include <HardwareSerial.h>

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
}

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());
}
Expand All @@ -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;
Expand Down
1 change: 1 addition & 0 deletions CYD-Klipper/src/ui/ip_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions CYD-Klipper/src/ui/panels/stats_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions CYD-Klipper/src/ui/panels/temp_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions CYD-Klipper/src/ui/ui_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit b99e00d

Please sign in to comment.