Make stats panel accessible from move panel, improve Z offset menu

This commit is contained in:
suchmememanyskill
2024-02-15 18:29:13 +01:00
parent cd58fcae4f
commit 3dc241dbec
9 changed files with 93 additions and 44 deletions

View File

@@ -12,6 +12,8 @@
"algorithm": "cpp",
"cstddef": "cpp",
"functional": "cpp",
"*.tcc": "cpp"
}
"*.tcc": "cpp",
"cmath": "cpp"
},
"cmake.configureOnOpen": false
}

View File

@@ -21,7 +21,7 @@ monitor_filters = esp32_exception_decoder
build_flags =
-DLV_CONF_PATH="../../../../src/conf/lv_conf.h"
extra_scripts =
pre:extract_commit.py
pre:extract_commit.py
[env:esp32-2432S028R]
board = esp32-2432S028R
@@ -43,12 +43,8 @@ lib_deps =
bblanchon/ArduinoJson@^7.0.0
plageoj/UrlEncode@^1.0.1
# Terribly slow. Only use for development
[env:esp32-3248S035C-smartdisplay]
board = esp32-3248S035C-smartdisplay
[env:esp32-2432S028R-smartdisplay]
board = esp32-2432S028R-smartdisplay
[env:esp32-2432S022C]
board = esp32-2432S022C-smartdisplay

View File

@@ -65,6 +65,33 @@ void send_gcode(bool wait, const char *gcode)
}
}
void move_printer(const char* axis, float amount, bool relative) {
if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING)
return;
char gcode[64];
const char* extra = (amount > 0) ? "+" : "";
bool absolute_coords = printer.absolute_coords;
if (absolute_coords && relative) {
send_gcode(true, "G91");
}
else if (!absolute_coords && !relative) {
send_gcode(true, "G90");
}
sprintf(gcode, "G1 %s%s%.3f F6000", axis, extra, amount);
send_gcode(true, gcode);
if (absolute_coords && relative) {
send_gcode(true, "G90");
}
else if (!absolute_coords && !relative) {
send_gcode(true, "G91");
}
}
void fetch_printer_data()
{
freeze_request_thread();
@@ -122,6 +149,7 @@ void fetch_printer_data()
printer.extruder_target_temp = status["extruder"]["target"];
bool can_extrude = status["extruder"]["can_extrude"];
printer.pressure_advance = status["extruder"]["pressure_advance"];
printer.smooth_time = status["extruder"]["smooth_time"];
printer.can_extrude = can_extrude == true;
}

View File

@@ -32,6 +32,7 @@ typedef struct _Printer {
int total_layers;
int current_layer;
float pressure_advance;
float smooth_time;
int feedrate_mm_per_s;
} Printer;
@@ -45,6 +46,7 @@ extern int klipper_request_consecutive_fail_count;
void data_loop();
void data_setup();
void send_gcode(bool wait, const char* gcode);
void move_printer(const char* axis, float amount, bool relative);
void freeze_request_thread();
void unfreeze_request_thread();

View File

@@ -26,14 +26,15 @@ void lv_do_calibration(){
is_in_calibration_mode = true;
lv_obj_clean(lv_scr_act());
lv_obj_clear_flag(lv_scr_act(), LV_OBJ_FLAG_SCROLLABLE);
lv_obj_t * label = lv_label_create(lv_scr_act());
lv_label_set_text(label, "Calibrate Screen");
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
lv_obj_t * line = lv_line_create(lv_scr_act());
static lv_point_t line_points_x[] = { {0, 10}, {20, 10} };
static lv_point_t line_points_y[] = { {10, 0}, {10, 20} };
static lv_point_t line_points_x[] = { {0, 10}, {21, 10} };
static lv_point_t line_points_y[] = { {10, 0}, {10, 21} };
lv_line_set_points(line, line_points_x, 2);
lv_obj_align(line, LV_ALIGN_TOP_LEFT, 0, 0);
@@ -63,12 +64,12 @@ void lv_do_calibration(){
line = lv_line_create(lv_scr_act());
lv_line_set_points(line, line_points_x, 2);
lv_obj_align(line, LV_ALIGN_BOTTOM_RIGHT, 0, -10);
lv_obj_align(line, LV_ALIGN_BOTTOM_RIGHT, 1, -10);
lv_obj_set_style_line_width(line, 1, 0);
line = lv_line_create(lv_scr_act());
lv_line_set_points(line, line_points_y, 2);
lv_obj_align(line, LV_ALIGN_BOTTOM_RIGHT, -10, 0);
lv_obj_align(line, LV_ALIGN_BOTTOM_RIGHT, -10, 1);
while (true){
lv_timer_handler();

View File

@@ -137,6 +137,9 @@ void nav_buttons_setup(unsigned char active_panel){
case 4:
macros_panel_init(panel);
break;
case 5:
stats_panel_init(panel);
break;
}
lv_msg_send(DATA_PRINTER_DATA, &printer);

View File

@@ -1,48 +1,28 @@
#include "lvgl.h"
#include "panel.h"
#include "../../core/data_setup.h"
#include "../nav_buttons.h"
#include "../ui_utils.h"
#include <stdio.h>
static bool last_homing_state = false;
static void move_printer(const char* axis, float amount) {
if (!printer.homed_axis || printer.state == PRINTER_STATE_PRINTING)
return;
char gcode[64];
const char* extra = (amount > 0) ? "+" : "";
bool absolute_coords = printer.absolute_coords;
if (absolute_coords) {
send_gcode(true, "G91");
}
sprintf(gcode, "G1 %s%s%.1f F6000", axis, extra, amount);
send_gcode(true, gcode);
if (absolute_coords) {
send_gcode(true, "G90");
}
}
static void x_line_button_press(lv_event_t * e) {
float* data_pointer = (float*)lv_event_get_user_data(e);
float data = *data_pointer;
move_printer("X", data);
move_printer("X", data, true);
}
static void y_line_button_press(lv_event_t * e) {
float* data_pointer = (float*)lv_event_get_user_data(e);
float data = *data_pointer;
move_printer("Y", data);
move_printer("Y", data, true);
}
static void z_line_button_press(lv_event_t * e) {
float* data_pointer = (float*)lv_event_get_user_data(e);
float data = *data_pointer;
move_printer("Z", data);
move_printer("Z", data, true);
}
char x_pos_buff[12];
@@ -103,6 +83,11 @@ static void disable_steppers_click(lv_event_t * e) {
send_gcode(true, "M18");
}
static void switch_to_stat_panel(lv_event_t * e) {
lv_obj_t * panel = lv_event_get_target(e);
nav_buttons_setup(5);
}
inline void root_panel_steppers_locked(lv_obj_t * root_panel){
const auto width = CYD_SCREEN_PANEL_WIDTH_PX - CYD_SCREEN_GAP_PX * 2;
@@ -121,7 +106,7 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){
lv_obj_set_flex_grow(btn, 1);
lv_obj_t * label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_HOME "Home Axis");
lv_label_set_text(label, LV_SYMBOL_HOME "Home");
lv_obj_center(label);
btn = lv_btn_create(home_button_row);
@@ -130,7 +115,16 @@ inline void root_panel_steppers_locked(lv_obj_t * root_panel){
lv_obj_set_flex_grow(btn, 1);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Disable Step");
lv_label_set_text(label, LV_SYMBOL_EYE_CLOSE " Unlock");
lv_obj_center(label);
btn = lv_btn_create(home_button_row);
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
lv_obj_add_event_cb(btn, switch_to_stat_panel, LV_EVENT_CLICKED, NULL);
lv_obj_set_flex_grow(btn, 1);
label = lv_label_create(btn);
lv_label_set_text(label, LV_SYMBOL_EDIT " Params");
lv_obj_center(label);
for (int row = 0; row < 3; row++) {

View File

@@ -36,19 +36,38 @@ static void set_zoffset_text(lv_event_t * e) {
lv_label_set_text(label, data);
}
static void set_zoffset_text_ex(lv_event_t * e) {
lv_obj_t * label = lv_event_get_target(e);
char data[64];
sprintf(data, "Z Offset: %.03f, Z: %.03f", printer.gcode_offset[2], printer.position[2]);
lv_label_set_text(label, data);
}
static void set_zoffset(lv_event_t * e){
char* offset = (char*)lv_event_get_user_data(e);
const char* extra = printer.state == PRINTER_STATE_IDLE ? " MOVE=1" : "";
char gcode[64];
sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s", offset);
sprintf(gcode, "SET_GCODE_OFFSET Z_ADJUST=%s%s", offset, extra);
send_gcode(true, gcode);
}
static void set_z(lv_event_t * e){
bool is_zero = !strcmp((char*)lv_event_get_user_data(e), "Z=0");
char gcode[64];
move_printer("Z", is_zero ? 0 : 1, false);
}
const char* zoffsets[] = { "-0.005", "-0.01", "-0.025", "-0.05" };
const char* zoffsets_2[] = { "+0.005", "+0.01", "+0.025", "+0.05" };
const char* z_set[] = { "Z=0", "Z=1" };
lv_button_column_t zoffset_columns[] = {
{ set_zoffset, zoffsets, (const void**)zoffsets, 4},
{ set_zoffset, zoffsets_2, (const void**)zoffsets_2, 4}
{ set_zoffset, zoffsets_2, (const void**)zoffsets_2, 4},
{ set_z, z_set, (const void**)z_set, 2}
};
static void set_speed_mult_text(lv_event_t * e){
@@ -126,7 +145,7 @@ static void open_fan_speed_panel(lv_event_t * e){
}
static void open_zoffset_panel(lv_event_t * e){
lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_zoffset_text, zoffset_columns, 2);
lv_create_fullscreen_button_matrix_popup(lv_scr_act(), set_zoffset_text_ex, zoffset_columns, (printer.state == PRINTER_STATE_IDLE) ? 3 : 2);
lv_msg_send(DATA_PRINTER_DATA, &printer);
}
@@ -175,7 +194,7 @@ static void label_total_layers(lv_event_t * e){
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);
sprintf(pressure_buff, "%.3f (%.2fs)", printer.pressure_advance, printer.smooth_time);
lv_label_set_text(label, pressure_buff);
}
@@ -211,8 +230,12 @@ void stats_panel_init(lv_obj_t* panel) {
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);
if (printer.state != PRINTER_STATE_IDLE){
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);

2
ci.py
View File

@@ -1,6 +1,6 @@
import subprocess, os, shutil, json
CYD_PORTS = ["esp32-3248S035C", "esp32-2432S028R", "esp32-2432S022C"]
CYD_PORTS = ["esp32-3248S035C", "esp32-2432S028R"]
BASE_DIR = os.getcwd()
def get_manifest(base_path : str, device_name : str):