Skip to content

Commit

Permalink
Fix temp chart crashing
Browse files Browse the repository at this point in the history
  • Loading branch information
suchmememanyskill committed Feb 16, 2024
1 parent 12c4319 commit dcf32d6
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion CYD-Klipper/src/ui/panels/temp_panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,31 @@ static void btn_retract(lv_event_t * e){
send_gcode(true, "G1 E-25 F300");
}

static void set_chart_range(lv_event_t * e) {
lv_obj_t * chart = lv_event_get_target(e);

int max_temp = 0;

if (printer.extruder_target_temp > max_temp)
max_temp = printer.extruder_target_temp;

if (printer.bed_target_temp > max_temp)
max_temp = printer.bed_target_temp;

if (printer.extruder_temp > max_temp)
max_temp = printer.extruder_temp;

if (printer.bed_temp > max_temp)
max_temp = printer.bed_temp;

int range = ((max_temp + 49) / 50) * 50;

if (range < 100)
range = 100;

lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, range);
}

static void set_hotend_temp_chart(lv_event_t * e){
lv_obj_t * chart = lv_event_get_target(e);
lv_chart_series_t * series = (lv_chart_series_t *)lv_event_get_user_data(e);
Expand Down Expand Up @@ -251,7 +276,7 @@ void temp_panel_init(lv_obj_t * panel){
lv_chart_set_point_count(chart, 120);
lv_obj_set_style_size(chart, 0, LV_PART_INDICATOR);
lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, CYD_SCREEN_GAP_PX / 2, CYD_SCREEN_GAP_PX / 4, 4, 3, true, CYD_SCREEN_MIN_BUTTON_WIDTH_PX);
lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 300);
lv_chart_set_update_mode(chart, LV_CHART_UPDATE_MODE_SHIFT);

lv_chart_series_t * ser1 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_ORANGE), LV_CHART_AXIS_PRIMARY_Y);
lv_chart_series_t * ser2 = lv_chart_add_series(chart, lv_palette_main(LV_PALETTE_RED), LV_CHART_AXIS_PRIMARY_Y);
Expand All @@ -262,6 +287,7 @@ void temp_panel_init(lv_obj_t * panel){
lv_obj_add_event_cb(chart, set_hotend_temp_chart, LV_EVENT_MSG_RECEIVED, ser2);
lv_obj_add_event_cb(chart, set_bed_target_temp_chart, LV_EVENT_MSG_RECEIVED, ser3);
lv_obj_add_event_cb(chart, set_bed_temp_chart, LV_EVENT_MSG_RECEIVED, ser4);
lv_obj_add_event_cb(chart, set_chart_range, LV_EVENT_MSG_RECEIVED, NULL);
lv_msg_subscribe_obj(DATA_PRINTER_DATA, chart, NULL);

lv_obj_t * single_screen_panel = lv_create_empty_panel(root_temp_panel);
Expand Down

0 comments on commit dcf32d6

Please sign in to comment.