Skip to content

Commit

Permalink
Add emergency stop and full filename options (#124)
Browse files Browse the repository at this point in the history
* init estop button

* style estop and add full filename option

* finalize estop style and adjust layout to accommodate extras

---------

Co-authored-by: Sims <[email protected]>
  • Loading branch information
rorosaurus and suchmememanyskill authored Aug 31, 2024
1 parent db01993 commit 0b1db1d
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CYD-Klipper/src/conf/global_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ typedef struct _GLOBAL_CONFIG {
bool display_mode : 1; // Driver specifc usage. Currently only used on ESP32-2432S028R to fix the screen on the usb-c model
bool disable_m117_messaging : 1;
bool sort_macros : 1;
bool show_estop : 1;
bool full_filenames : 1;
};
};

Expand Down
15 changes: 15 additions & 0 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ void send_gcode(bool wait, const char *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)
Expand Down
1 change: 1 addition & 0 deletions CYD-Klipper/src/core/data_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ extern int klipper_request_consecutive_fail_count;

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);

Expand Down
6 changes: 5 additions & 1 deletion CYD-Klipper/src/ui/panels/files_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,11 @@ void files_panel_init(lv_obj_t* panel){
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);
lv_obj_set_style_bg_opa(btn, LV_OPA_TRANSP, 0);
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;
Expand Down
39 changes: 25 additions & 14 deletions CYD-Klipper/src/ui/panels/progress_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,37 +69,48 @@ static void btn_click_resume(lv_event_t * e){
send_gcode(true, "RESUME");
}

static void btn_click_estop(lv_event_t * e){
send_estop();
send_gcode(false, "M112");
}

void progress_panel_init(lv_obj_t* panel){
auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 3;
const auto button_size_mult = 1.3f;

// Emergency Stop
if (global_config.show_estop){
lv_obj_t * btn = lv_btn_create(panel);
lv_obj_add_event_cb(btn, btn_click_estop, LV_EVENT_CLICKED, NULL);

lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_align(btn, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX);
lv_obj_set_style_bg_color(btn, lv_color_hex(0xFF0000), LV_PART_MAIN);

lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_POWER " EMERGENCY STOP");
lv_obj_center(label);
}

lv_obj_t * center_panel = lv_create_empty_panel(panel);
lv_obj_set_size(center_panel, panel_width, LV_SIZE_CONTENT);
lv_layout_flex_column(center_panel);

if (get_current_printer_config()->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_ALL)
// 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)
{
lv_obj_align(center_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX);
lv_obj_align(center_panel, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX+(3 * CYD_SCREEN_GAP_PX));
}
else
{
lv_obj_align(center_panel, LV_ALIGN_CENTER, 0, 0);
}


if (get_current_printer_config()->show_stats_on_progress_panel == SHOW_STATS_ON_PROGRESS_PANEL_LAYER)
{
lv_obj_t * label = lv_label_create(panel);
lv_obj_align(label, LV_ALIGN_TOP_MID, 0, CYD_SCREEN_GAP_PX);
lv_obj_set_style_text_font(label, &CYD_SCREEN_FONT_SMALL, 0);
lv_obj_add_event_cb(label, update_printer_data_stats, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subsribe_obj(DATA_PRINTER_DATA, label, NULL);
}

// Filename
lv_obj_t * label = lv_label_create(center_panel);
lv_label_set_text(label, printer.print_filename);
lv_label_set_long_mode(label, LV_LABEL_LONG_SCROLL_CIRCULAR);
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);

// Progress Bar
Expand Down Expand Up @@ -165,7 +176,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_PARTIAL)
if (get_current_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
16 changes: 16 additions & 0 deletions CYD-Klipper/src/ui/panels/settings_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,20 @@ static void sort_macros_switch(lv_event_t* e){
write_global_config();
}

static void show_estop_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);
global_config.show_estop = checked;
write_global_config();
}

static void full_filenames_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);
global_config.full_filenames = checked;
write_global_config();
}

static void rotate_screen_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);
Expand Down Expand Up @@ -217,6 +231,8 @@ void settings_section_behaviour(lv_obj_t* panel)
: "Calls FILAMENT_RETRACT and\nFILAMENT_EXTRUDE in temperature menu\nwhen enabled");

lv_create_custom_menu_switch("Sort Macros A->Z", panel, sort_macros_switch, global_config.sort_macros);
lv_create_custom_menu_switch("Show Emergency Stop", panel, show_estop_switch, global_config.show_estop);
lv_create_custom_menu_switch("Show Full Filenames", panel, full_filenames_switch, global_config.full_filenames);
}

void settings_section_device(lv_obj_t* panel)
Expand Down

0 comments on commit 0b1db1d

Please sign in to comment.