mirror of
https://github.com/suchmememanyskill/CYD-Klipper.git
synced 2026-03-20 21:23:25 +00:00
Start print in bambu integration
This commit is contained in:
@@ -42,6 +42,7 @@ bool BambuPrinter::publish_mqtt_command(const char* command)
|
|||||||
char auth[48] = {0};
|
char auth[48] = {0};
|
||||||
sprintf(auth, "device/%s/request", printer_config->printer_auth);
|
sprintf(auth, "device/%s/request", printer_config->printer_auth);
|
||||||
|
|
||||||
|
LOG_F(("Publishing MQTT Command: %s", command));
|
||||||
return client.publish(auth, command);
|
return client.publish(auth, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,11 +299,6 @@ Files BambuPrinter::get_files()
|
|||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BambuPrinter::start_file(const char* filename)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
Thumbnail BambuPrinter::get_32_32_png_image_thumbnail(const char* gcode_filename)
|
Thumbnail BambuPrinter::get_32_32_png_image_thumbnail(const char* gcode_filename)
|
||||||
{
|
{
|
||||||
Thumbnail thumbnail = {0};
|
Thumbnail thumbnail = {0};
|
||||||
|
|||||||
@@ -19,16 +19,6 @@ class BambuPrinter : public BasePrinter
|
|||||||
unsigned int ignore_error = 0;
|
unsigned int ignore_error = 0;
|
||||||
unsigned long print_start;
|
unsigned long print_start;
|
||||||
|
|
||||||
union {
|
|
||||||
struct {
|
|
||||||
bool chamber_light_available : 1;
|
|
||||||
bool chamber_light_on : 1;
|
|
||||||
bool work_light_available : 1;
|
|
||||||
bool work_light_on : 1;
|
|
||||||
};
|
|
||||||
unsigned char bambu_misc;
|
|
||||||
};
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void parse_state(JsonDocument& in);
|
void parse_state(JsonDocument& in);
|
||||||
void init_ui_panels();
|
void init_ui_panels();
|
||||||
@@ -39,6 +29,17 @@ class BambuPrinter : public BasePrinter
|
|||||||
float chamber_fan_speed;
|
float chamber_fan_speed;
|
||||||
BambuSpeedProfile speed_profile = BambuSpeedProfileNormal;
|
BambuSpeedProfile speed_profile = BambuSpeedProfileNormal;
|
||||||
|
|
||||||
|
union {
|
||||||
|
struct {
|
||||||
|
bool chamber_light_available : 1;
|
||||||
|
bool chamber_light_on : 1;
|
||||||
|
bool work_light_available : 1;
|
||||||
|
bool work_light_on : 1;
|
||||||
|
bool has_ams : 1;
|
||||||
|
};
|
||||||
|
unsigned char bambu_misc;
|
||||||
|
};
|
||||||
|
|
||||||
BambuPrinter(int index) : BasePrinter(index)
|
BambuPrinter(int index) : BasePrinter(index)
|
||||||
{
|
{
|
||||||
supported_features = PrinterFeatureHome
|
supported_features = PrinterFeatureHome
|
||||||
@@ -63,6 +64,7 @@ class BambuPrinter : public BasePrinter
|
|||||||
print_start = millis();
|
print_start = millis();
|
||||||
|
|
||||||
init_ui_panels();
|
init_ui_panels();
|
||||||
|
no_confirm_print_file = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool move_printer(const char* axis, float amount, bool relative);
|
bool move_printer(const char* axis, float amount, bool relative);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
const char* speed_profiles[] = { "Silent (50%)", "Normal (100%)", "Sport (124%)", "Ludicrous (166%)" };
|
const char* speed_profiles[] = { "Silent (50%)", "Normal (100%)", "Sport (124%)", "Ludicrous (166%)" };
|
||||||
const BambuSpeedProfile speed_profile_values[] = { BambuSpeedProfileSilent, BambuSpeedProfileNormal, BambuSpeedProfileSport, BambuSpeedProfileLudicrous };
|
const BambuSpeedProfile speed_profile_values[] = { BambuSpeedProfileSilent, BambuSpeedProfileNormal, BambuSpeedProfileSport, BambuSpeedProfileLudicrous };
|
||||||
const char* COMMAND_SET_PRINT_SPEED = "{\"print\":{\"command\":\"print_speed\",\"param\":\"%d\"}}";
|
const char* COMMAND_SET_PRINT_SPEED = "{\"print\":{\"command\":\"print_speed\",\"param\":\"%d\"}}";
|
||||||
|
const char* COMMAND_START_PRINT_3MF = "{\"print\":{\"command\":\"project_file\",\"param\":\"Metadata/plate_1.gcode\",\"project_id\":\"0\",\"profile_id\":\"0\",\"task_id\":\"0\",\"subtask_id\":\"0\",\"subtask_name\":\"CYD-Klipper Print Job\",\"url\":\"file:///sdcard/%s\",\"timelapse\":%s,\"bed_type\":\"auto\",\"bed_leveling\":%s,\"flow_cali\":%s,\"vibration_cali\":%s,\"layer_inspect\":%s,\"ams_mapping\":[],\"use_ams\":%s}}";
|
||||||
|
|
||||||
enum FanIndex
|
enum FanIndex
|
||||||
{
|
{
|
||||||
@@ -139,4 +140,118 @@ void BambuPrinter::init_ui_panels()
|
|||||||
{
|
{
|
||||||
custom_menus_count = 4;
|
custom_menus_count = 4;
|
||||||
custom_menus = bambu_ui_panels;
|
custom_menus = bambu_ui_panels;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
const char* bambu_current_file;
|
||||||
|
|
||||||
|
union
|
||||||
|
{
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
bool bambu_option_use_ams : 1;
|
||||||
|
bool bambu_option_timelapse : 1;
|
||||||
|
bool bambu_option_bed_leveling : 1;
|
||||||
|
bool bambu_option_flow_calibration : 1;
|
||||||
|
bool bambu_option_vibration_compensation : 1;
|
||||||
|
bool bambu_option_layer_inspect : 1;
|
||||||
|
};
|
||||||
|
unsigned char bambu_options_raw;
|
||||||
|
};
|
||||||
|
} __internal_bambu_file_state = {};
|
||||||
|
|
||||||
|
#define SET_BOOL_STATE(bool_name, func_name) static void func_name (lv_event_t * e) { auto state = lv_obj_get_state(lv_event_get_target(e)); bool_name = (state & LV_STATE_CHECKED == LV_STATE_CHECKED); }
|
||||||
|
|
||||||
|
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_use_ams, set_bambu_option_use_ams)
|
||||||
|
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_timelapse, set_bambu_option_timelapse)
|
||||||
|
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_bed_leveling, set_bambu_option_bed_leveling)
|
||||||
|
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_flow_calibration, set_bambu_option_flow_calibration)
|
||||||
|
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_vibration_compensation, set_bambu_option_vibration_compensation)
|
||||||
|
SET_BOOL_STATE(__internal_bambu_file_state.bambu_option_layer_inspect, set_bambu_option_layer_inspect)
|
||||||
|
|
||||||
|
#define BOOLEAN_TO_STRING(b) b ? "true" : "false"
|
||||||
|
|
||||||
|
static void print_file_start(lv_event_t * e)
|
||||||
|
{
|
||||||
|
BambuPrinter* printer = (BambuPrinter*)get_current_printer();
|
||||||
|
char buff[713];
|
||||||
|
|
||||||
|
if (snprintf(buff, 713, COMMAND_START_PRINT_3MF,
|
||||||
|
__internal_bambu_file_state.bambu_current_file,
|
||||||
|
BOOLEAN_TO_STRING(__internal_bambu_file_state.bambu_option_timelapse),
|
||||||
|
BOOLEAN_TO_STRING(__internal_bambu_file_state.bambu_option_bed_leveling),
|
||||||
|
BOOLEAN_TO_STRING(__internal_bambu_file_state.bambu_option_flow_calibration),
|
||||||
|
BOOLEAN_TO_STRING(__internal_bambu_file_state.bambu_option_vibration_compensation),
|
||||||
|
BOOLEAN_TO_STRING(__internal_bambu_file_state.bambu_option_layer_inspect),
|
||||||
|
BOOLEAN_TO_STRING(__internal_bambu_file_state.bambu_option_use_ams)) >= 712)
|
||||||
|
{
|
||||||
|
LOG_LN("Failed to prepare message to start print");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printer->publish_mqtt_command(buff);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool BambuPrinter::start_file(const char* filename){
|
||||||
|
if (get_current_printer_data()->state != PrinterState::PrinterStateIdle)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
__internal_bambu_file_state.bambu_current_file = filename;
|
||||||
|
|
||||||
|
lv_obj_t * panel = lv_obj_create(lv_scr_act());
|
||||||
|
lv_obj_set_style_pad_all(panel, CYD_SCREEN_GAP_PX * 2, 0);
|
||||||
|
lv_layout_flex_column(panel);
|
||||||
|
lv_obj_set_size(panel, CYD_SCREEN_WIDTH_PX - CYD_SCREEN_GAP_PX * 3, CYD_SCREEN_HEIGHT_PX - CYD_SCREEN_GAP_PX * 2);
|
||||||
|
lv_obj_align(panel, LV_ALIGN_CENTER, 0, 0);
|
||||||
|
|
||||||
|
lv_obj_t * label_print_file = lv_label_create(panel);
|
||||||
|
lv_obj_set_width(label_print_file, LV_PCT(100));
|
||||||
|
lv_label_set_long_mode(label_print_file, LV_LABEL_LONG_SCROLL_CIRCULAR);
|
||||||
|
lv_label_set_text_fmt(label_print_file, "Settings for %s", __internal_bambu_file_state.bambu_current_file);
|
||||||
|
|
||||||
|
__internal_bambu_file_state.bambu_option_use_ams = ((BambuPrinter*)get_current_printer())->has_ams;
|
||||||
|
__internal_bambu_file_state.bambu_option_timelapse = false;
|
||||||
|
__internal_bambu_file_state.bambu_option_bed_leveling = true;
|
||||||
|
__internal_bambu_file_state.bambu_option_flow_calibration = true;
|
||||||
|
__internal_bambu_file_state.bambu_option_vibration_compensation = true;
|
||||||
|
__internal_bambu_file_state.bambu_option_layer_inspect = true;
|
||||||
|
|
||||||
|
if (__internal_bambu_file_state.bambu_option_use_ams)
|
||||||
|
{
|
||||||
|
lv_create_custom_menu_switch("Use AMS", panel, set_bambu_option_use_ams, __internal_bambu_file_state.bambu_option_use_ams);
|
||||||
|
}
|
||||||
|
|
||||||
|
lv_create_custom_menu_switch("Timelapse", panel, set_bambu_option_timelapse, __internal_bambu_file_state.bambu_option_timelapse);
|
||||||
|
lv_create_custom_menu_switch("Bed Leveling", panel, set_bambu_option_bed_leveling, __internal_bambu_file_state.bambu_option_bed_leveling);
|
||||||
|
lv_create_custom_menu_switch("Flow Calibration", panel, set_bambu_option_flow_calibration, __internal_bambu_file_state.bambu_option_flow_calibration);
|
||||||
|
lv_create_custom_menu_switch("Vibration Compensation", panel, set_bambu_option_vibration_compensation, __internal_bambu_file_state.bambu_option_vibration_compensation);
|
||||||
|
lv_create_custom_menu_switch("Inspect First Layer", panel, set_bambu_option_layer_inspect, __internal_bambu_file_state.bambu_option_layer_inspect);
|
||||||
|
|
||||||
|
lv_obj_t* buttons_panel = lv_create_empty_panel(panel);
|
||||||
|
lv_layout_flex_row(buttons_panel);
|
||||||
|
lv_obj_set_size(buttons_panel, LV_PCT(100), CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||||
|
|
||||||
|
lv_obj_t* btn = lv_btn_create(buttons_panel);
|
||||||
|
lv_obj_set_flex_grow(btn, 1);
|
||||||
|
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||||
|
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel);
|
||||||
|
|
||||||
|
lv_obj_t* label = lv_label_create(btn);
|
||||||
|
lv_label_set_text(label, LV_SYMBOL_CLOSE " Cancel");
|
||||||
|
lv_obj_center(label);
|
||||||
|
|
||||||
|
btn = lv_btn_create(buttons_panel);
|
||||||
|
lv_obj_set_flex_grow(btn, 1);
|
||||||
|
lv_obj_set_height(btn, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||||
|
lv_obj_add_event_cb(btn, print_file_start, LV_EVENT_CLICKED, panel);
|
||||||
|
lv_obj_add_event_cb(btn, destroy_event_user_data, LV_EVENT_CLICKED, panel);
|
||||||
|
|
||||||
|
label = lv_label_create(btn);
|
||||||
|
lv_label_set_text(label, LV_SYMBOL_OK " Print");
|
||||||
|
lv_obj_center(label);
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
@@ -228,6 +228,15 @@ void BambuPrinter::parse_state(JsonDocument& in)
|
|||||||
chamber_fan_speed = convert_fan_speed(print["big_fan2_speed"]);
|
chamber_fan_speed = convert_fan_speed(print["big_fan2_speed"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (print.containsKey("ams_exist_bits"))
|
||||||
|
{
|
||||||
|
const char* ams_exists = print["ams_exist_bits"];
|
||||||
|
if (!strcmp(ams_exists, "0"))
|
||||||
|
{
|
||||||
|
has_ams = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
printer_data.extrude_mult = 1;
|
printer_data.extrude_mult = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ class BasePrinter
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
short popup_message_timeout_s = 10;
|
short popup_message_timeout_s = 10;
|
||||||
|
bool no_confirm_print_file = false;
|
||||||
|
|
||||||
PrinterConfiguration* printer_config{};
|
PrinterConfiguration* printer_config{};
|
||||||
PrinterFeatures supported_features{};
|
PrinterFeatures supported_features{};
|
||||||
|
|||||||
@@ -11,14 +11,23 @@
|
|||||||
|
|
||||||
const char* selected_file = NULL;
|
const char* selected_file = NULL;
|
||||||
|
|
||||||
static void btn_print_file(lv_event_t * e){
|
static void btn_print_file(lv_event_t * e)
|
||||||
|
{
|
||||||
lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e);
|
lv_obj_t * panel = (lv_obj_t*)lv_event_get_user_data(e);
|
||||||
lv_obj_del(panel);
|
lv_obj_del(panel);
|
||||||
|
|
||||||
current_printer_start_file(selected_file);
|
current_printer_start_file(selected_file);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void btn_print_file_verify(lv_event_t * e){
|
static void btn_print_file_verify_instant(lv_event_t * e)
|
||||||
|
{
|
||||||
|
lv_obj_t * btn = lv_event_get_target(e);
|
||||||
|
selected_file = (char*)lv_event_get_user_data(e);
|
||||||
|
current_printer_start_file(selected_file);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void btn_print_file_verify(lv_event_t * e)
|
||||||
|
{
|
||||||
if (get_current_printer_data()->state != PrinterState::PrinterStateIdle){
|
if (get_current_printer_data()->state != PrinterState::PrinterStateIdle){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -111,10 +120,12 @@ void files_panel_init(lv_obj_t* panel){
|
|||||||
lv_obj_t * btn = lv_list_add_btn(list, LV_SYMBOL_FILE, files.available_files[i]);
|
lv_obj_t * btn = lv_list_add_btn(list, LV_SYMBOL_FILE, files.available_files[i]);
|
||||||
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){
|
if (global_config.full_filenames)
|
||||||
|
{
|
||||||
lv_label_set_long_mode(lv_obj_get_child(btn, 1), LV_LABEL_LONG_WRAP);
|
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.available_files[i]));
|
|
||||||
|
lv_obj_add_event_cb(btn, (get_current_printer()->no_confirm_print_file) ? btn_print_file_verify_instant : btn_print_file_verify, LV_EVENT_CLICKED, (void*)(files.available_files[i]));
|
||||||
lv_obj_on_destroy_free_data(btn, files.available_files[i]);
|
lv_obj_on_destroy_free_data(btn, files.available_files[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -181,8 +181,10 @@ void lv_create_custom_menu_entry(const char* label_text, lv_obj_t* object, lv_ob
|
|||||||
|
|
||||||
lv_obj_set_parent(object, panel);
|
lv_obj_set_parent(object, panel);
|
||||||
|
|
||||||
if (set_height)
|
if (set_height)
|
||||||
|
{
|
||||||
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
lv_obj_set_height(object, CYD_SCREEN_MIN_BUTTON_HEIGHT_PX);
|
||||||
|
}
|
||||||
|
|
||||||
if (comment != NULL)
|
if (comment != NULL)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user