Skip to content

Commit

Permalink
Add info to stat panel
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Feb 3, 2024
1 parent 41be4b1 commit 77db365
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CYD-Klipper/src/core/data_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ void fetch_printer_data()
printer.extruder_temp = status["extruder"]["temperature"];
printer.extruder_target_temp = status["extruder"]["target"];
bool can_extrude = status["extruder"]["can_extrude"];
printer.pressure_advance = status["extruder"]["pressure_advance"];
printer.can_extrude = can_extrude == true;
}

Expand Down Expand Up @@ -148,6 +149,8 @@ void fetch_printer_data()
printer.absolute_coords = absolute_coords == true;
printer.speed_mult = status["gcode_move"]["speed_factor"];
printer.extrude_mult = status["gcode_move"]["extrude_factor"];
printer.feedrate_mm_per_s = status["gcode_move"]["speed"];
printer.feedrate_mm_per_s /= 60; // convert mm/m to mm/s
}

if (status.containsKey("fan"))
Expand All @@ -167,6 +170,8 @@ void fetch_printer_data()
printer.print_filename = filename_buff;
printer.elapsed_time_s = status["print_stats"]["print_duration"];
printer.filament_used_mm = status["print_stats"]["filament_used"];
printer.total_layers = status["print_stats"]["info"]["total_layer"];
printer.current_layer = status["print_stats"]["info"]["current_layer"];

const char *state = status["print_stats"]["state"];

Expand Down
4 changes: 4 additions & 0 deletions CYD-Klipper/src/core/data_setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ typedef struct _Printer {
float gcode_offset[3];
float speed_mult;
float extrude_mult;
int total_layers;
int current_layer;
float pressure_advance;
int feedrate_mm_per_s;
} Printer;

extern Printer printer;
Expand Down
62 changes: 62 additions & 0 deletions CYD-Klipper/src/ui/panels/stats_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,71 @@ void create_state_button(lv_obj_t * root, lv_event_cb_t label, lv_event_cb_t but
lv_obj_align(label_obj, LV_ALIGN_CENTER, 0, 0);
}

static void label_pos(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char x_pos_buff[32];
sprintf(x_pos_buff, "X%.2f Y%.2f", printer.position[0], printer.position[1]);
lv_label_set_text(label, x_pos_buff);
}

static void label_filament_used_m(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char filament_buff[32];
sprintf(filament_buff, "%.2f m", printer.filament_used_mm / 1000);
lv_label_set_text(label, filament_buff);
}

static void label_total_layers(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char layers_buff[32];
sprintf(layers_buff, "%d of %d", printer.current_layer, printer.total_layers);
lv_label_set_text(label, layers_buff);
}

static void label_pressure_advance(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char pressure_buff[32];
sprintf(pressure_buff, "%.3f", printer.pressure_advance);
lv_label_set_text(label, pressure_buff);
}

static void label_feedrate(lv_event_t * e){
lv_obj_t * label = lv_event_get_target(e);
char feedrate_buff[32];
sprintf(feedrate_buff, "%d mm/s", printer.feedrate_mm_per_s);
lv_label_set_text(label, feedrate_buff);
}

void create_stat_text_block(lv_obj_t * root, const char* label, lv_event_cb_t value){
lv_obj_t * panel = lv_create_empty_panel(root);
lv_obj_set_size(panel, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
lv_layout_flex_column(panel , LV_FLEX_ALIGN_START, CYD_SCREEN_GAP_PX / 2, CYD_SCREEN_GAP_PX / 2);
lv_obj_set_flex_align(panel, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);

lv_obj_t * label_obj = lv_label_create(panel);
lv_label_set_text(label_obj, label);
lv_obj_set_style_text_font(label_obj, CYD_SCREEN_FONT_SMALL, 0);

lv_obj_t * value_obj = lv_label_create(panel);
lv_obj_add_event_cb(value_obj, value, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subscribe_obj(DATA_PRINTER_DATA, value_obj, NULL);
}

void stats_panel_init(lv_obj_t* panel) {
auto panel_width = CYD_SCREEN_PANEL_WIDTH_PX / 2 - CYD_SCREEN_GAP_PX * 3;

lv_obj_t * left_panel = lv_create_empty_panel(panel);
lv_obj_set_size(left_panel, panel_width, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2);
lv_layout_flex_column(left_panel);
lv_obj_set_flex_align(left_panel, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_START);
lv_obj_align(left_panel, LV_ALIGN_TOP_LEFT, CYD_SCREEN_GAP_PX, CYD_SCREEN_GAP_PX);

create_stat_text_block(left_panel, "Position:", label_pos);
create_stat_text_block(left_panel, "Filament Used:", label_filament_used_m);
create_stat_text_block(left_panel, "Layer:", label_total_layers);
create_stat_text_block(left_panel, "Pressure Advance:", label_pressure_advance);
create_stat_text_block(left_panel, "Feedrate:", label_feedrate);

lv_obj_t * right_panel = lv_create_empty_panel(panel);
lv_obj_set_size(right_panel, panel_width, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2);
lv_layout_flex_column(right_panel, LV_FLEX_ALIGN_CENTER);
Expand Down

0 comments on commit 77db365

Please sign in to comment.