Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Oct 28, 2024
1 parent b99e00d commit ccc5817
Show file tree
Hide file tree
Showing 10 changed files with 70 additions and 35 deletions.
4 changes: 3 additions & 1 deletion CYD-Klipper/src/conf/global_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ void global_config_add_new_printer()
int free_index = get_printer_config_free_index();
if (free_index <= -1)
{
LOG_LN("No available slot for new printer");
return;
}

PrinterConfiguration* old_config = &global_config.printer_config[global_config.printer_index];
PrinterConfiguration* new_config = &global_config.printer_config[free_index];

new_config->raw = old_config->raw;
new_config->setup_complete = false;
new_config->ip_configured = false;
new_config->auth_configured = false;

Expand All @@ -99,7 +101,7 @@ void global_config_add_new_printer()
new_config->printer_move_z_steps[i] = old_config->printer_move_z_steps[i];
}

write_global_config();
global_config_set_printer(free_index);
ESP.restart();
}

Expand Down
5 changes: 2 additions & 3 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,18 +61,17 @@ void fetch_printer_data()

void fetch_printer_data_minimal()
{
PrinterDataMinimal* data = (PrinterDataMinimal*)malloc(sizeof(PrinterDataMinimal) * get_printer_count());
PrinterDataMinimal data[PRINTER_CONFIG_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();
data[i] = printer->fetch_min();
}
freeze_render_thread();
announce_printer_data_minimal(data);
unfreeze_render_thread();
free(data);
}

void data_loop()
Expand Down
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 @@ -371,9 +371,10 @@ bool KlipperPrinter::fetch()

PrinterDataMinimal KlipperPrinter::fetch_min()
{
PrinterDataMinimal data = {0};
PrinterDataMinimal data = {};
data.success = false;

if (!printer_config->ip_configured)
if (!printer_config->setup_complete)
{
data.state = PrinterStateOffline;
return data;
Expand All @@ -387,7 +388,7 @@ PrinterDataMinimal KlipperPrinter::fetch_min()
int http_code = client.GET();
if (http_code == 200)
{
data.state = PrinterStateIdle;
data.state = PrinterState::PrinterStateIdle;
data.power_devices = get_power_devices_count();

JsonDocument doc;
Expand All @@ -400,7 +401,7 @@ PrinterDataMinimal KlipperPrinter::fetch_min()

if (strcmp(state, "shutdown") == 0)
{
data.state = PrinterStateError;
data.state = PrinterState::PrinterStateError;
}
}

Expand All @@ -417,26 +418,26 @@ PrinterDataMinimal KlipperPrinter::fetch_min()

if (state == nullptr)
{
data.state = PrinterStateError;
data.state = PrinterState::PrinterStateError;
}
else if (strcmp(state, "printing") == 0)
{
data.state = PrinterStatePrinting;
data.state = PrinterState::PrinterStatePrinting;
}
else if (strcmp(state, "paused") == 0)
{
data.state = PrinterStatePaused;
data.state = PrinterState::PrinterStatePaused;
}
else if (strcmp(state, "complete") == 0 || strcmp(state, "cancelled") == 0 || strcmp(state, "standby") == 0)
{
data.state = PrinterStateIdle;
data.state = PrinterState::PrinterStateIdle;
}
}
}
}
else
{
data.state = PrinterStateOffline;
data.state = PrinterState::PrinterStateOffline;
data.power_devices = get_power_devices_count();
}

Expand Down
1 change: 1 addition & 0 deletions CYD-Klipper/src/core/lv_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ void lv_touch_intercept(lv_indev_drv_t *indev_driver, lv_indev_data_t *data)
}

data->state = LV_INDEV_STATE_REL;
delay(300); // Some screens don't debounce their signal properly
}

screen_timer_wake();
Expand Down
5 changes: 3 additions & 2 deletions CYD-Klipper/src/core/printer_integration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,11 @@ PrinterData* BasePrinter::AnnouncePrinterData()

void initialize_printers(BasePrinter** printers, unsigned char total)
{
LOG_F(("Initializing %d printers\n", total))
printer_data_copy = (PrinterData*)malloc(sizeof(PrinterData));
minimal_data_copy = (PrinterDataMinimal*)malloc(sizeof(PrinterDataMinimal) * total_printers);
minimal_data_copy = (PrinterDataMinimal*)malloc(sizeof(PrinterDataMinimal) * total);
memset(printer_data_copy, 0, sizeof(PrinterData));
memset(minimal_data_copy, 0, sizeof(PrinterDataMinimal) * total_printers);
memset(minimal_data_copy, 0, sizeof(PrinterDataMinimal) * total);
registered_printers = printers;
total_printers = total;
}
Expand Down
2 changes: 1 addition & 1 deletion CYD-Klipper/src/core/printer_integration.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ typedef struct _PrinterData {
} PrinterData;

typedef struct {
unsigned char state;
PrinterState state;
float print_progress; // 0 -> 1
unsigned int power_devices;
bool success;
Expand Down
16 changes: 14 additions & 2 deletions CYD-Klipper/src/ui/ip_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,27 @@ void show_ip_entry()
lv_textarea_set_one_line(hostEntry, true);
lv_obj_add_flag(hostEntry, LV_OBJ_FLAG_USER_1);
lv_textarea_set_max_length(hostEntry, 63);
lv_textarea_set_text(hostEntry, "");
lv_obj_set_flex_grow(hostEntry, 3);

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_set_flex_grow(portEntry, 1);

if (global_config.printer_config[global_config.printer_index].ip_configured)
{
char buff[7] = {0};
sprintf(buff, "%d", global_config.printer_config[global_config.printer_index].klipper_port);
lv_textarea_set_text(hostEntry, global_config.printer_config[global_config.printer_index].klipper_host);
lv_textarea_set_text(portEntry, buff);
}
else
{
lv_textarea_set_text(hostEntry, "");
lv_textarea_set_text(portEntry, "80");
}

lv_obj_t * keyboard = lv_keyboard_create(root);
lv_keyboard_set_map(keyboard, LV_KEYBOARD_MODE_USER_1, kb_map, kb_ctrl);
lv_obj_add_event_cb(hostEntry, keyboard_event_ip_entry, LV_EVENT_ALL, keyboard);
Expand Down
33 changes: 27 additions & 6 deletions CYD-Klipper/src/ui/nav_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,27 @@
#include "../core/printer_integration.hpp"

static lv_style_t nav_button_style;

static char temp_buffer[10];
static char z_pos_buffer[10];
static char time_buffer[10];

static lv_style_t nav_button_text_style;

static void update_printer_data_z_pos(lv_event_t * e) {
lv_obj_t * label = lv_event_get_target(e);
char z_pos_buffer[10];

sprintf(z_pos_buffer, "Z%.2f", get_current_printer_data()->position[2]);
lv_label_set_text(label, z_pos_buffer);
}

static void update_printer_data_temp(lv_event_t * e) {
lv_obj_t * label = lv_event_get_target(e);
char temp_buffer[10];

sprintf(temp_buffer, "%.0f/%.0f", get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexNozzle1], get_current_printer_data()->temperatures[PrinterTemperatureDeviceIndex::PrinterTemperatureDeviceIndexBed]);
lv_label_set_text(label, temp_buffer);
}

static void update_printer_data_time(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char time_buffer[10];

if (get_current_printer_data()->state == PrinterState::PrinterStateIdle){
lv_label_set_text(label, "Idle");
Expand Down Expand Up @@ -57,6 +55,29 @@ static void update_printer_data_time(lv_event_t * e){
lv_label_set_text(label, time_buffer);
}

static void update_multi_printer_label(lv_event_t * e) {
lv_obj_t * label = lv_event_get_target(e);

int idle_count = 0;
for (int i = 0; i < get_printer_count(); i++)
{
PrinterDataMinimal* data = get_printer_data_minimal(i);
if (data->state == PrinterState::PrinterStateIdle)
{
idle_count++;
}
}

if (idle_count > 0)
{
lv_label_set_text_fmt(label, "%d idle", idle_count);
}
else
{
lv_label_set_text(label, "Printer");
}
}

static void btn_click_files(lv_event_t * e){
nav_buttons_setup(PANEL_FILES);
}
Expand Down Expand Up @@ -168,7 +189,7 @@ void nav_buttons_setup(PANEL_TYPE active_panel){
if (global_config.multi_printer_mode)
{
// Printers
create_button(LV_SYMBOL_HOME, "Printer", btn_click_printer, NULL, root_panel);
create_button(LV_SYMBOL_HOME, "Printer", btn_click_printer, update_multi_printer_label, root_panel);
}

lv_obj_t * panel = lv_create_empty_panel(lv_scr_act());
Expand Down
17 changes: 8 additions & 9 deletions CYD-Klipper/src/ui/panels/printer_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,9 @@ static void btn_printer_secondary(lv_event_t * e)

static void btn_printer_rename(lv_event_t * e)
{
keyboard_config = (PrinterConfiguration*)lv_event_get_user_data(e);
int config_index = (int)lv_event_get_user_data(e);
BasePrinter* printer = get_printer(config_index);
keyboard_config = printer->printer_config;
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);
}

Expand All @@ -196,9 +198,8 @@ static void btn_printer_add(lv_event_t * e)
global_config_add_new_printer();
}

void create_printer_ui(PrinterConfiguration * config, lv_obj_t * root)
void create_printer_ui(int index, lv_obj_t * root)
{
int index = config - global_config.printer_config;
auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2;

lv_obj_t * data_row_name = lv_create_empty_panel(root);
Expand Down Expand Up @@ -279,15 +280,12 @@ 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++){
PrinterConfiguration * config = &global_config.printer_config[i];
if (config->ip_configured) {
create_printer_ui(&global_config.printer_config[i], inner_panel);
}
for (int i = 0; i < get_printer_count(); i++){
create_printer_ui(i, inner_panel);
}

// Add Printer Button
if (get_printer_count() == PRINTER_CONFIG_COUNT){
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);
Expand All @@ -298,4 +296,5 @@ 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);
}
3 changes: 1 addition & 2 deletions CYD-Klipper/src/ui/panels/settings_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ static void reset_wifi_click(lv_event_t * e){
}

static void reset_ip_click(lv_event_t * e){
get_current_printer()->printer_config->ip_configured = false;
get_current_printer()->printer_config->auth_configured = false;
get_current_printer()->printer_config->setup_complete = false;
write_global_config();
ESP.restart();
}
Expand Down

0 comments on commit ccc5817

Please sign in to comment.