Skip to content

Commit 68f47ab

Browse files
Vertabreakthinkyhead
authored andcommitted
UBL Mesh Wizard (MarlinFirmware#21556)
Co-authored-by: Scott Lahteine <[email protected]>
1 parent 3d0f7b5 commit 68f47ab

File tree

7 files changed

+105
-2
lines changed

7 files changed

+105
-2
lines changed

Marlin/Configuration.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1491,6 +1491,8 @@
14911491
//#define UBL_Z_RAISE_WHEN_OFF_MESH 2.5 // When the nozzle is off the mesh, this value is used
14921492
// as the Z-Height correction value.
14931493

1494+
//#define UBL_MESH_WIZARD // Run several commands in a row to get a complete mesh
1495+
14941496
#elif ENABLED(MESH_BED_LEVELING)
14951497

14961498
//===========================================================================

Marlin/src/feature/bedlevel/ubl/ubl.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ unified_bed_leveling ubl;
3535
#include "../../../module/planner.h"
3636
#include "../../../module/motion.h"
3737
#include "../../../module/probe.h"
38+
#include "../../../module/temperature.h"
3839

3940
#if ENABLED(EXTENSIBLE_UI)
4041
#include "../../../lcd/extui/ui_api.h"
@@ -254,4 +255,48 @@ bool unified_bed_leveling::sanity_check() {
254255
return !!error_flag;
255256
}
256257

258+
#if ENABLED(UBL_MESH_WIZARD)
259+
260+
/**
261+
* M1004: UBL Mesh Wizard - One-click mesh creation with or without a probe
262+
*/
263+
void GcodeSuite::M1004() {
264+
265+
#define ALIGN_GCODE TERN(Z_STEPPER_AUTO_ALIGN, "G34", "")
266+
#define PROBE_GCODE TERN(HAS_BED_PROBE, "G29P1\nG29P3", "G29P4R255")
267+
268+
#if HAS_HOTEND
269+
if (parser.seenval('H')) { // Handle H# parameter to set Hotend temp
270+
const celsius_t hotend_temp = parser.value_int(); // Marlin never sends itself F or K, always C
271+
thermalManager.setTargetHotend(hotend_temp, 0);
272+
thermalManager.wait_for_hotend(false);
273+
}
274+
#endif
275+
276+
#if HAS_HEATED_BED
277+
if (parser.seenval('B')) { // Handle B# parameter to set Bed temp
278+
const celsius_t bed_temp = parser.value_int(); // Marlin never sends itself F or K, always C
279+
thermalManager.setTargetBed(bed_temp);
280+
thermalManager.wait_for_bed(false);
281+
}
282+
#endif
283+
284+
process_subcommands_now_P(G28_STR); // Home
285+
process_subcommands_now_P(PSTR(ALIGN_GCODE "\n" // Align multi z axis if available
286+
PROBE_GCODE "\n" // Build mesh with available hardware
287+
"G29P3\nG29P3")); // Ensure mesh is complete by running smart fill twice
288+
289+
if (parser.seenval('S')) {
290+
char umw_gcode[32];
291+
sprintf_P(umw_gcode, PSTR("G29S%i"), parser.value_int());
292+
queue.inject(umw_gcode);
293+
}
294+
295+
process_subcommands_now_P(PSTR("G29A\nG29F10\n" // Set UBL Active & Fade 10
296+
"M140S0\nM104S0\n" // Turn off heaters
297+
"M500")); // Store settings
298+
}
299+
300+
#endif // UBL_MESH_WIZARD
301+
257302
#endif // AUTO_BED_LEVELING_UBL

Marlin/src/gcode/gcode.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -987,6 +987,10 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
987987
case 1002: M1002(); break; // M1002: [INTERNAL] Tool-change and Relative E Move
988988
#endif
989989

990+
#if ENABLED(UBL_MESH_WIZARD)
991+
case 1004: M1004(); break; // M1004: UBL Mesh Wizard
992+
#endif
993+
990994
#if ENABLED(MAX7219_GCODE)
991995
case 7219: M7219(); break; // M7219: Set LEDs, columns, and rows
992996
#endif

Marlin/src/gcode/gcode.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,6 +1079,10 @@ class GcodeSuite {
10791079
static void M1002();
10801080
#endif
10811081

1082+
#if ENABLED(UBL_MESH_WIZARD)
1083+
static void M1004();
1084+
#endif
1085+
10821086
#if ENABLED(MAX7219_GCODE)
10831087
static void M7219();
10841088
#endif

Marlin/src/lcd/language/language_en.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ namespace Language_en {
166166
PROGMEM Language_Str MSG_UBL_LEVEL_BED = _UxGT("Unified Bed Leveling");
167167
PROGMEM Language_Str MSG_LCD_TILTING_MESH = _UxGT("Tilting Point");
168168
PROGMEM Language_Str MSG_UBL_MANUAL_MESH = _UxGT("Manually Build Mesh");
169+
PROGMEM Language_Str MSG_UBL_MESH_WIZARD = _UxGT("UBL Mesh Wizard");
169170
PROGMEM Language_Str MSG_UBL_BC_INSERT = _UxGT("Place Shim & Measure");
170171
PROGMEM Language_Str MSG_UBL_BC_INSERT2 = _UxGT("Measure");
171172
PROGMEM Language_Str MSG_UBL_BC_REMOVE = _UxGT("Remove & Measure Bed");

Marlin/src/lcd/menu/menu_ubl.cpp

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
#include "../../feature/bedlevel/bedlevel.h"
3838

3939
static int16_t ubl_storage_slot = 0,
40-
custom_hotend_temp = 190,
40+
custom_hotend_temp = 150,
4141
side_points = 3,
4242
ubl_fillin_amount = 5,
4343
ubl_height_amount = 1;
@@ -603,6 +603,50 @@ void _menu_ubl_tools() {
603603

604604
#endif
605605

606+
#if ENABLED(UBL_MESH_WIZARD)
607+
608+
/**
609+
* UBL Mesh Wizard - One-click mesh creation with or without a probe
610+
*/
611+
void _lcd_ubl_mesh_wizard() {
612+
char ubl_lcd_gcode[30];
613+
#if HAS_HEATED_BED && HAS_HOTEND
614+
sprintf_P(ubl_lcd_gcode, PSTR("M1004B%iH%iS%i"), custom_bed_temp, custom_hotend_temp, ubl_storage_slot);
615+
#elif HAS_HOTEND
616+
sprintf_P(ubl_lcd_gcode, PSTR("M1004H%iS%i"), custom_hotend_temp, ubl_storage_slot);
617+
#else
618+
sprintf_P(ubl_lcd_gcode, PSTR("M1004S%i"), ubl_storage_slot);
619+
#endif
620+
queue.inject(ubl_lcd_gcode);
621+
}
622+
623+
void _menu_ubl_mesh_wizard() {
624+
const int16_t total_slots = settings.calc_num_meshes();
625+
START_MENU();
626+
BACK_ITEM(MSG_UBL_LEVEL_BED);
627+
628+
#if HAS_HOTEND
629+
EDIT_ITEM(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, thermalManager.hotend_max_target(0));
630+
#endif
631+
632+
#if HAS_HEATED_BED
633+
EDIT_ITEM(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP, BED_MAX_TARGET);
634+
#endif
635+
636+
EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, total_slots);
637+
638+
ACTION_ITEM(MSG_UBL_MESH_WIZARD, _lcd_ubl_mesh_wizard);
639+
640+
#if ENABLED(G26_MESH_VALIDATION)
641+
SUBMENU(MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
642+
#endif
643+
644+
ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
645+
END_MENU();
646+
}
647+
648+
#endif
649+
606650
/**
607651
* UBL System submenu
608652
*
@@ -626,6 +670,9 @@ void _lcd_ubl_level_bed() {
626670
#if ENABLED(G26_MESH_VALIDATION)
627671
SUBMENU(MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
628672
#endif
673+
#if ENABLED(UBL_MESH_WIZARD)
674+
SUBMENU(MSG_UBL_MESH_WIZARD, _menu_ubl_mesh_wizard);
675+
#endif
629676
ACTION_ITEM(MSG_UBL_MESH_EDIT, _ubl_goto_map_screen);
630677
SUBMENU(MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
631678
SUBMENU(MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);

buildroot/tests/FYSETC_F6

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ opt_set MOTHERBOARD BOARD_FYSETC_F6_13 \
2424
L6470_CHAIN_SCK_PIN 53 L6470_CHAIN_MISO_PIN 49 L6470_CHAIN_MOSI_PIN 40 L6470_CHAIN_SS_PIN 42 \
2525
'ENABLE_RESET_L64XX_CHIPS(V)' NOOP
2626
opt_enable RESTORE_LEVELING_AFTER_G28 EEPROM_SETTINGS EEPROM_CHITCHAT \
27-
Z_PROBE_ALLEN_KEY AUTO_BED_LEVELING_UBL \
27+
Z_PROBE_ALLEN_KEY AUTO_BED_LEVELING_UBL UBL_MESH_WIZARD \
2828
OLED_PANEL_TINYBOY2 MESH_EDIT_GFX_OVERLAY DELTA_CALIBRATION_MENU
2929
exec_test $1 $2 "DELTA, RAMPS, L6470, UBL, Allen Key, EEPROM, OLED_PANEL_TINYBOY2..." "$3"
3030

0 commit comments

Comments
 (0)