Skip to content

Commit

Permalink
Finish all panels
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Oct 26, 2024
1 parent 309a686 commit e55c287
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 270 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -696,7 +696,7 @@ bool KlipperPrinter::start_file(const char *filename)
return http_code == 200;
}

bool KlipperPrinter::set_target_temperature(PrinterTemperatureDevice device, float temperature)
bool KlipperPrinter::set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature)
{
char gcode[64] = {0};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class KlipperPrinter : public BasePrinter
Files get_files();
bool start_file(const char* filename);
unsigned char* get_32_32_png_image_thumbnail(const char* gcode_filename);
bool set_target_temperature(PrinterTemperatureDevice device, float temperature);
bool set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature);
bool send_gcode(const char* gcode, bool wait = true);
int get_slicer_time_estimate_s();
void configure_http_client(HTTPClient &client, String url_part, bool stream, int timeout);
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 @@ -159,7 +159,7 @@ class BasePrinter
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);
virtual bool set_target_temperature(PrinterTemperatureDevice device, float temperature) = 0;
virtual bool set_target_temperature(PrinterTemperatureDevice device, unsigned int temperature) = 0;

BasePrinter(unsigned char index);
PrinterData* AnnouncePrinterData();
Expand Down
2 changes: 2 additions & 0 deletions CYD-Klipper/src/ui/panels/files_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ static void btn_print_file_verify(lv_event_t * e){
}

void files_panel_init(lv_obj_t* panel){
freeze_request_thread();
Files files = get_current_printer()->get_files();
unfreeze_request_thread();

if (!files.success || files.count <= 0){
lv_obj_t * label = lv_label_create(panel);
Expand Down
35 changes: 17 additions & 18 deletions CYD-Klipper/src/ui/panels/progress_panel.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "panel.h"
#include "../../core/data_setup.h"
#include <stdio.h>
#include "../ui_utils.h"
#include "../../core/printer_integration.hpp"

char time_buffer[12];

Expand All @@ -15,35 +15,35 @@ char* time_display(unsigned long time){

static void progress_bar_update(lv_event_t* e){
lv_obj_t * bar = lv_event_get_target(e);
lv_bar_set_value(bar, printer.print_progress * 100, LV_ANIM_ON);
lv_bar_set_value(bar, get_current_printer_data()->print_progress * 100, LV_ANIM_ON);
}

static void update_printer_data_elapsed_time(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
lv_label_set_text(label, time_display(printer.elapsed_time_s));
lv_label_set_text(label, time_display(get_current_printer_data()->elapsed_time_s));
}

static void update_printer_data_remaining_time(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
lv_label_set_text(label, time_display(printer.remaining_time_s));
lv_label_set_text(label, time_display(get_current_printer_data()->remaining_time_s));
}

static void update_printer_data_stats(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char buff[256] = {0};

switch (get_current_printer_config()->show_stats_on_progress_panel)
switch (get_current_printer()->printer_config->show_stats_on_progress_panel)
{
case SHOW_STATS_ON_PROGRESS_PANEL_LAYER:
sprintf(buff, "Layer %d of %d", printer.current_layer, printer.total_layers);
sprintf(buff, "Layer %d of %d", get_current_printer_data()->current_layer, get_current_printer_data()->total_layers);
break;
case SHOW_STATS_ON_PROGRESS_PANEL_PARTIAL:
sprintf(buff, "Position: X%.2f Y%.2f\nFeedrate: %d mm/s\nFilament Used: %.2f m\nLayer %d of %d",
printer.position[0], printer.position[1], printer.feedrate_mm_per_s, printer.filament_used_mm / 1000, printer.current_layer, printer.total_layers);
get_current_printer_data()->position[0], get_current_printer_data()->position[1], get_current_printer_data()->feedrate_mm_per_s, get_current_printer_data()->filament_used_mm / 1000, get_current_printer_data()->current_layer, get_current_printer_data()->total_layers);
break;
case SHOW_STATS_ON_PROGRESS_PANEL_ALL:
sprintf(buff, "Pressure Advance: %.3f (%.2fs)\nPosition: X%.2f Y%.2f Z%.2f\nFeedrate: %d mm/s\nFilament Used: %.2f m\nFan: %.0f%%\nSpeed: %.0f%%\nFlow: %.0f%%\nLayer %d of %d",
printer.pressure_advance, printer.smooth_time, printer.position[0], printer.position[1], printer.position[2], printer.feedrate_mm_per_s, printer.filament_used_mm / 1000, printer.fan_speed * 100, printer.speed_mult * 100, printer.extrude_mult * 100, printer.current_layer, printer.total_layers);
get_current_printer_data()->pressure_advance, get_current_printer_data()->smooth_time, get_current_printer_data()->position[0], get_current_printer_data()->position[1], get_current_printer_data()->position[2], get_current_printer_data()->feedrate_mm_per_s, get_current_printer_data()->filament_used_mm / 1000, get_current_printer_data()->fan_speed * 100, get_current_printer_data()->speed_mult * 100, get_current_printer_data()->extrude_mult * 100, get_current_printer_data()->current_layer, get_current_printer_data()->total_layers);
break;
}

Expand All @@ -53,25 +53,24 @@ static void update_printer_data_stats(lv_event_t * e){
static void update_printer_data_percentage(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char percentage_buffer[12];
sprintf(percentage_buffer, "%.2f%%", printer.print_progress * 100);
sprintf(percentage_buffer, "%.2f%%", get_current_printer_data()->print_progress * 100);
lv_label_set_text(label, percentage_buffer);
}

static void btn_click_stop(lv_event_t * e){
send_gcode(true, "CANCEL_PRINT");
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureStop);
}

static void btn_click_pause(lv_event_t * e){
send_gcode(true, "PAUSE");
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeaturePause);
}

static void btn_click_resume(lv_event_t * e){
send_gcode(true, "RESUME");
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureResume);
}

static void btn_click_estop(lv_event_t * e){
send_estop();
send_gcode(false, "M112");
get_current_printer()->execute_feature(PrinterFeatures::PrinterFeatureEmergencyStop);
}

void progress_panel_init(lv_obj_t* panel){
Expand All @@ -97,7 +96,7 @@ void progress_panel_init(lv_obj_t* panel){
lv_layout_flex_column(center_panel);

// Only align progress bar to top mid if necessary to make room for all extras
if (get_current_printer_config()->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_ALL && CYD_SCREEN_HEIGHT_PX <= 320)
if (get_current_printer()->printer_config->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_ALL && CYD_SCREEN_HEIGHT_PX <= 320)
{
lv_obj_align(center_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX+(3 * CYD_SCREEN_GAP_PX));
}
Expand All @@ -108,7 +107,7 @@ void progress_panel_init(lv_obj_t* panel){

// Filename
lv_obj_t * label = lv_label_create(center_panel);
lv_label_set_text(label, printer.print_filename);
lv_label_set_text(label, get_current_printer_data()->print_filename);
if (global_config.full_filenames) lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);
else lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
lv_obj_set_width(label, panel_width);
Expand Down Expand Up @@ -155,7 +154,7 @@ void progress_panel_init(lv_obj_t* panel){
lv_obj_center(label);

// Resume Button
if (printer.state == PRINTER_STATE_PAUSED){
if (get_current_printer_data()->state == PrinterState::PrinterStatePaused){
btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, btn_click_resume, LV_EVENT_CLICKED, NULL);

Expand All @@ -176,7 +175,7 @@ void progress_panel_init(lv_obj_t* panel){
lv_obj_align(btn, LV_ALIGN_BOTTOM_RIGHT, -2 * CYD_SCREEN_GAP_PX - CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, -1 * CYD_SCREEN_GAP_PX);
lv_obj_set_size(btn, CYD_SCREEN_MIN_BUTTON_WIDTH_PX * button_size_mult, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX * button_size_mult);

if (get_current_printer_config()->show_stats_on_progress_panel > SHOW_STATS_ON_PROGRESS_PANEL_NONE)
if (get_current_printer()->printer_config->show_stats_on_progress_panel > SHOW_STATS_ON_PROGRESS_PANEL_NONE)
{
label = lv_label_create(panel);
lv_obj_align(label, LV_ALIGN_BOTTOM_LEFT, CYD_SCREEN_GAP_PX, -1 * CYD_SCREEN_GAP_PX);
Expand Down
29 changes: 15 additions & 14 deletions CYD-Klipper/src/ui/panels/settings_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "../../core/lv_setup.h"
#include "../ota_setup.h"
#include "../nav_buttons.h"
#include "../../core/printer_integration.hpp"

#ifndef REPO_VERSION
#define REPO_VERSION "Unknown"
Expand All @@ -16,7 +17,7 @@
static void invert_color_switch(lv_event_t * e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
get_current_printer_config()->invert_colors = checked;
get_current_printer()->printer_config->invert_colors = checked;
write_global_config();
set_invert_display();
}
Expand All @@ -38,37 +39,37 @@ static void reset_wifi_click(lv_event_t * e){
}

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

static void light_mode_switch(lv_event_t * e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
get_current_printer_config()->light_mode = checked;
get_current_printer()->printer_config->light_mode = checked;
write_global_config();
set_color_scheme();
}

static void filament_move_mode_switch(lv_event_t * e){
auto state = lv_obj_get_state(lv_event_get_target(e));
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
get_current_printer_config()->custom_filament_move_macros = checked;
get_current_printer()->printer_config->custom_filament_move_macros = checked;
write_global_config();
}

static void show_stats_on_progress_panel_dropdown(lv_event_t * e){
auto selected = lv_dropdown_get_selected(lv_event_get_target(e));
get_current_printer_config()->show_stats_on_progress_panel = selected;
get_current_printer()->printer_config->show_stats_on_progress_panel = selected;
write_global_config();
}

static void theme_dropdown(lv_event_t * e){
lv_obj_t * dropdown = lv_event_get_target(e);
auto selected = lv_dropdown_get_selected(dropdown);
get_current_printer_config()->color_scheme = selected;
get_current_printer()->printer_config->color_scheme = selected;
set_color_scheme();
write_global_config();
}
Expand Down Expand Up @@ -171,7 +172,7 @@ const char* estimated_time_options = "Percentage\nInterpolated\nSlicer";

static void estimated_time_dropdown(lv_event_t * e){
lv_obj_t * dropdown = lv_event_get_target(e);
get_current_printer_config()->remaining_time_calc_mode = lv_dropdown_get_selected(dropdown);
get_current_printer()->printer_config->remaining_time_calc_mode = lv_dropdown_get_selected(dropdown);
write_global_config();
}

Expand All @@ -182,10 +183,10 @@ void settings_section_theming(lv_obj_t* panel)
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, "Theming");

lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nLime\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer_config()->color_scheme, NULL, PRINTER_SPECIFIC_SETTING);
lv_create_custom_menu_dropdown("Theme", panel, theme_dropdown, "Blue\nGreen\nLime\nGrey\nYellow\nOrange\nRed\nPurple", get_current_printer()->printer_config->color_scheme, NULL, PRINTER_SPECIFIC_SETTING);

#ifndef CYD_SCREEN_DISABLE_INVERT_COLORS
lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer_config()->invert_colors, NULL, (global_config.multi_printer_mode) ? "Stored per printer"
lv_create_custom_menu_switch("Invert Colors", panel, invert_color_switch, get_current_printer()->printer_config->invert_colors, NULL, (global_config.multi_printer_mode) ? "Stored per printer"
#ifdef CYD_SCREEN_DRIVER_ESP32_2432S028R
"\nIntended for the 2.8\" dual USB model screen" : "Intended for the 2.8\" dual USB model screen"
#else
Expand All @@ -194,16 +195,16 @@ void settings_section_theming(lv_obj_t* panel)
);
#endif // CYD_SCREEN_DISABLE_INVERT_COLORS

lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer_config()->light_mode, NULL, PRINTER_SPECIFIC_SETTING);
lv_create_custom_menu_switch("Light Mode", panel, light_mode_switch, get_current_printer()->printer_config->light_mode, NULL, PRINTER_SPECIFIC_SETTING);
}

void settings_section_behaviour(lv_obj_t* panel)
{
lv_obj_t * label = lv_label_create(panel);
lv_label_set_text(label, "\nBehaviour");

lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer_config()->remaining_time_calc_mode, NULL, PRINTER_SPECIFIC_SETTING);
lv_create_custom_menu_dropdown("Stats in Progress Screen", panel, show_stats_on_progress_panel_dropdown, "None\nLayers\nPartial\nAll", get_current_printer_config()->show_stats_on_progress_panel, NULL, PRINTER_SPECIFIC_SETTING);
lv_create_custom_menu_dropdown("Estimated Time", panel, estimated_time_dropdown, estimated_time_options, get_current_printer()->printer_config->remaining_time_calc_mode, NULL, PRINTER_SPECIFIC_SETTING);
lv_create_custom_menu_dropdown("Stats in Progress Screen", panel, show_stats_on_progress_panel_dropdown, "None\nLayers\nPartial\nAll", get_current_printer()->printer_config->show_stats_on_progress_panel, NULL, PRINTER_SPECIFIC_SETTING);

#ifndef CYD_SCREEN_DISABLE_TIMEOUT
int wake_timeout_settings_index = 0;
Expand All @@ -225,7 +226,7 @@ void settings_section_behaviour(lv_obj_t* panel)
lv_create_custom_menu_switch("Disable M117 Messaging", panel, disable_m117_messaging_switch, global_config.disable_m117_messaging);
lv_create_custom_menu_button("Configure Printer IP", panel, reset_ip_click, "Restart");

lv_create_custom_menu_switch("Custom Filament Move Macros", panel, filament_move_mode_switch, get_current_printer_config()->custom_filament_move_macros, NULL,
lv_create_custom_menu_switch("Custom Filament Move Macros", panel, filament_move_mode_switch, get_current_printer()->printer_config->custom_filament_move_macros, NULL,
global_config.multi_printer_mode
? "Calls FILAMENT_RETRACT and\nFILAMENT_EXTRUDE in temperature menu\nwhen enabled. Stored per printer."
: "Calls FILAMENT_RETRACT and\nFILAMENT_EXTRUDE in temperature menu\nwhen enabled");
Expand Down
Loading

0 comments on commit e55c287

Please sign in to comment.