Skip to content

Commit

Permalink
Move error ui to panel
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Mar 14, 2024
1 parent 9c958b4 commit 7aceb85
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 97 deletions.
75 changes: 2 additions & 73 deletions CYD-Klipper/src/ui/main_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,77 +11,6 @@
#include "switch_printer.h"
#include "macros.h"

char extruder_temp_buff[20];
char bed_temp_buff[20];
char position_buff[20];

static void btn_click_restart(lv_event_t * e){
send_gcode(false, "RESTART");
}

static void btn_click_firmware_restart(lv_event_t * e){
send_gcode(false, "FIRMWARE_RESTART");
}

void error_ui_macros_open(lv_event_t * e){
macros_draw_power_fullscreen();
}

void error_ui(){
lv_obj_clean(lv_scr_act());

lv_obj_t * panel = lv_create_empty_panel(lv_scr_act());
lv_layout_flex_column(panel);
lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX, CYD_SCREEN_HEIGHT_PX);
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0);
lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);

lv_obj_t * label;
label = lv_label_create(panel);
lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready");

label = lv_label_create(panel);
lv_label_set_text(label, printer.state_message);
lv_obj_set_width(label, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2);
lv_obj_clear_flag(label, LV_OBJ_FLAG_SCROLLABLE);
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);

lv_obj_t * button_row = lv_create_empty_panel(panel);
lv_obj_set_size(button_row, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_layout_flex_row(button_row);

lv_obj_t * btn = lv_btn_create(button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create(btn);
lv_label_set_text(label, "Restart");
lv_obj_center(label);

btn = lv_btn_create(button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create(btn);
lv_label_set_text(label, "FW Restart");
lv_obj_center(label);

if (power_devices_count() >= 1){
btn = lv_btn_create(button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, error_ui_macros_open, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create(btn);
lv_label_set_text(label, "Devices");
lv_obj_center(label);
}

draw_switch_printer_button();
}

void check_if_screen_needs_to_be_disabled(){
if (global_config.on_during_print && printer.state == PRINTER_STATE_PRINTING){
screen_timer_wake();
Expand All @@ -96,10 +25,10 @@ static void on_state_change(void * s, lv_msg_t * m){
check_if_screen_needs_to_be_disabled();

if (printer.state == PRINTER_STATE_ERROR){
error_ui();
nav_buttons_setup(PANEL_ERROR);
}
else {
nav_buttons_setup(0);
nav_buttons_setup(PANEL_PRINT);
}
}

Expand Down
52 changes: 33 additions & 19 deletions CYD-Klipper/src/ui/nav_buttons.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,27 +58,31 @@ static void update_printer_data_time(lv_event_t * e){
}

static void btn_click_files(lv_event_t * e){
nav_buttons_setup(0);
nav_buttons_setup(PANEL_PRINT);
}

static void btn_click_move(lv_event_t * e){
nav_buttons_setup(1);
nav_buttons_setup(PANEL_MOVE);
}

static void btn_click_extrude(lv_event_t * e){
nav_buttons_setup(2);
nav_buttons_setup(PANEL_TEMP);
}

static void btn_click_settings(lv_event_t * e){
nav_buttons_setup(3);
nav_buttons_setup(PANEL_SETTINGS);
}

static void btn_click_macros(lv_event_t * e){
nav_buttons_setup(4);
nav_buttons_setup(PANEL_MACROS);
}

static void btn_click_printer(lv_event_t * e){
nav_buttons_setup(6);
nav_buttons_setup(PANEL_PRINTER);
}

static void btn_click_err(lv_event_t * e){
nav_buttons_setup(PANEL_ERROR);
}

void create_button(const char* icon, const char* name, lv_event_cb_t button_click, lv_event_cb_t label_update, lv_obj_t * root){
Expand Down Expand Up @@ -124,20 +128,27 @@ void nav_buttons_setup(unsigned char active_panel){

#endif

// Files/Print
create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel);
if (printer.state != PRINTER_STATE_ERROR){
// Files/Print
create_button(LV_SYMBOL_COPY, "Idle", btn_click_files, update_printer_data_time, root_panel);

// Move
create_button(printer.state == PRINTER_STATE_PRINTING ? LV_SYMBOL_EDIT : LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel);
// Move
create_button(printer.state == PRINTER_STATE_PRINTING ? LV_SYMBOL_EDIT : LV_SYMBOL_CHARGE, "Z?", btn_click_move, update_printer_data_z_pos, root_panel);

// Extrude/Temp
create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel);
// Extrude/Temp
create_button(LV_SYMBOL_WARNING, "?/?", btn_click_extrude, update_printer_data_temp, root_panel);
}
else {
// Error UI
create_button(LV_SYMBOL_WARNING, "Error", btn_click_err, NULL, root_panel);
}

// Macros
create_button(LV_SYMBOL_GPS, "Macro", btn_click_macros, NULL, root_panel);

if (global_config.multi_printer_mode)
{
// Printers
create_button(LV_SYMBOL_HOME, "Printer", btn_click_printer, NULL, root_panel);
}

Expand All @@ -146,27 +157,30 @@ void nav_buttons_setup(unsigned char active_panel){
lv_obj_align(panel, LV_ALIGN_TOP_RIGHT, 0, 0);

switch (active_panel){
case 0:
case PANEL_PRINT:
print_panel_init(panel);
break;
case 1:
case PANEL_MOVE:
move_panel_init(panel);
break;
case 2:
case PANEL_TEMP:
temp_panel_init(panel);
break;
case 3:
case PANEL_SETTINGS:
settings_panel_init(panel);
break;
case 4:
case PANEL_MACROS:
macros_panel_init(panel);
break;
case 5:
case PANEL_STATS:
stats_panel_init(panel);
break;
case 6:
case PANEL_PRINTER:
printer_panel_init(panel);
break;
case PANEL_ERROR:
error_panel_init(panel);
break;
}

lv_msg_send(DATA_PRINTER_DATA, &printer);
Expand Down
11 changes: 11 additions & 0 deletions CYD-Klipper/src/ui/nav_buttons.h
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
#pragma once

#define PANEL_PRINT 0
#define PANEL_MOVE 1
#define PANEL_TEMP 2
#define PANEL_SETTINGS 3
#define PANEL_MACROS 4
#define PANEL_STATS 5
#define PANEL_PRINTER 6
#define PANEL_ERROR 7

void nav_buttons_setup(unsigned char active_panel);
void nav_style_setup();
53 changes: 53 additions & 0 deletions CYD-Klipper/src/ui/panels/error_panel.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include "panel.h"
#include "../../core/data_setup.h"
#include "../ui_utils.h"

static void btn_click_restart(lv_event_t * e){
send_gcode(false, "RESTART");
}

static void btn_click_firmware_restart(lv_event_t * e){
send_gcode(false, "FIRMWARE_RESTART");
}

void error_panel_init(lv_obj_t* panel)
{
lv_layout_flex_column(panel, LV_FLEX_ALIGN_SPACE_BETWEEN);
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX, 0);

lv_obj_t * label;
label = lv_label_create(panel);
lv_label_set_text(label, LV_SYMBOL_WARNING " Printer is not ready");

lv_obj_t * panel_with_text = lv_create_empty_panel(panel);
lv_layout_flex_column(panel_with_text, LV_FLEX_ALIGN_START);
lv_obj_set_flex_grow(panel_with_text, 1);
lv_obj_set_width(panel_with_text, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2);

label = lv_label_create(panel_with_text);
lv_label_set_text(label, printer.state_message);
lv_obj_set_width(label, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2);
lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP);

lv_obj_t * button_row = lv_create_empty_panel(panel);
lv_obj_set_size(button_row, CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_layout_flex_row(button_row);

lv_obj_t * btn = lv_btn_create(button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, btn_click_restart, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create(btn);
lv_label_set_text(label, "Restart");
lv_obj_center(label);

btn = lv_btn_create(button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, btn_click_firmware_restart, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);

label = lv_label_create(btn);
lv_label_set_text(label, "FW Restart");
lv_obj_center(label);
}
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/panels/macros_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <HardwareSerial.h>

static void btn_goto_settings(lv_event_t * e){
nav_buttons_setup(3);
nav_buttons_setup(PANEL_SETTINGS);
}

void macros_panel_init(lv_obj_t* panel) {
Expand Down
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/panels/move_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static void disable_steppers_click(lv_event_t * e) {

static void switch_to_stat_panel(lv_event_t * e) {
lv_obj_t * panel = lv_event_get_target(e);
nav_buttons_setup(5);
nav_buttons_setup(PANEL_STATS);
}

inline void root_panel_steppers_locked(lv_obj_t * root_panel){
Expand Down
3 changes: 2 additions & 1 deletion CYD-Klipper/src/ui/panels/panel.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ void move_panel_init(lv_obj_t* panel);
void progress_panel_init(lv_obj_t* panel);
void macros_panel_init(lv_obj_t* panel);
void stats_panel_init(lv_obj_t* panel);
void printer_panel_init(lv_obj_t* panel);
void printer_panel_init(lv_obj_t* panel);
void error_panel_init(lv_obj_t* panel);
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/panels/printer_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ static void btn_printer_delete(lv_event_t * e)
config->ip_configured = false;
write_global_config();

nav_buttons_setup(6);
nav_buttons_setup(PANEL_PRINTER);
}

// TODO: Extract this from temp/print panel and combine
Expand Down
2 changes: 1 addition & 1 deletion CYD-Klipper/src/ui/panels/settings_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ static void multi_printer_switch(lv_event_t* e){
bool checked = (state & LV_STATE_CHECKED == LV_STATE_CHECKED);
global_config.multi_printer_mode = checked;
write_global_config();
nav_buttons_setup(3);
nav_buttons_setup(PANEL_SETTINGS);
}

const char* estimated_time_options = "Percentage\nInterpolated\nSlicer";
Expand Down

0 comments on commit 7aceb85

Please sign in to comment.