2018-10-28 01:10:44 +02:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 15:00:57 +01:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2018-10-28 01:10:44 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2018-10-28 01:10:44 +02:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2020-07-23 05:20:14 +02:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2018-10-28 01:10:44 +02:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
//
|
|
|
|
// Unified Bed Leveling Menus
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "../../inc/MarlinConfigPre.h"
|
|
|
|
|
2020-04-24 04:42:38 +02:00
|
|
|
#if BOTH(HAS_LCD_MENU, AUTO_BED_LEVELING_UBL)
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-08-21 12:21:34 +02:00
|
|
|
#include "menu_item.h"
|
2020-04-10 03:05:58 +02:00
|
|
|
#include "../../gcode/gcode.h"
|
|
|
|
#include "../../gcode/queue.h"
|
2020-06-25 23:39:22 +02:00
|
|
|
#include "../../module/motion.h"
|
2018-10-28 01:10:44 +02:00
|
|
|
#include "../../module/planner.h"
|
2020-08-08 03:51:40 +02:00
|
|
|
#include "../../module/settings.h"
|
2018-10-28 01:10:44 +02:00
|
|
|
#include "../../feature/bedlevel/bedlevel.h"
|
|
|
|
|
|
|
|
static int16_t ubl_storage_slot = 0,
|
|
|
|
custom_hotend_temp = 190,
|
|
|
|
side_points = 3,
|
|
|
|
ubl_fillin_amount = 5,
|
2019-08-18 02:58:38 +02:00
|
|
|
ubl_height_amount = 1;
|
|
|
|
|
2020-04-25 23:49:53 +02:00
|
|
|
static uint8_t n_edit_pts = 1;
|
|
|
|
static int8_t x_plot = 0, y_plot = 0; // May be negative during move
|
2018-10-28 01:10:44 +02:00
|
|
|
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
static int16_t custom_bed_temp = 50;
|
|
|
|
#endif
|
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
float mesh_edit_accumulator; // Rounded to 2.5 decimal places on use
|
|
|
|
|
|
|
|
inline float rounded_mesh_value() {
|
|
|
|
const int32_t rounded = int32_t(mesh_edit_accumulator * 1000);
|
|
|
|
return float(rounded - (rounded % 5L)) / 1000;
|
|
|
|
}
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2021-03-24 09:28:48 +01:00
|
|
|
/**
|
|
|
|
* This screen displays the temporary mesh value and updates it based on encoder
|
|
|
|
* movement. While this screen is active ubl.fine_tune_mesh sits in a loop getting
|
|
|
|
* the current value via ubl_mesh_value, moves the Z axis, and updates the mesh
|
|
|
|
* value until the encoder button is pressed.
|
|
|
|
*
|
|
|
|
* - Update the 'mesh_edit_accumulator' from encoder rotation
|
|
|
|
* - Draw the mesh value (with draw_edit_screen)
|
|
|
|
* - Draw the graphical overlay, if enabled.
|
|
|
|
* - Update the 'refresh' state according to the display type
|
|
|
|
*/
|
|
|
|
void _lcd_mesh_fine_tune(PGM_P const msg) {
|
|
|
|
constexpr float mesh_edit_step = 1.0f / 200.0f;
|
2019-03-23 22:30:43 +01:00
|
|
|
ui.defer_status_screen();
|
2018-10-28 01:10:44 +02:00
|
|
|
if (ubl.encoder_diff) {
|
2020-09-28 08:52:38 +02:00
|
|
|
mesh_edit_accumulator += TERN(IS_TFTGLCD_PANEL,
|
2021-03-24 09:28:48 +01:00
|
|
|
ubl.encoder_diff * mesh_edit_step / ENCODER_PULSES_PER_STEP,
|
|
|
|
ubl.encoder_diff > 0 ? mesh_edit_step : -mesh_edit_step
|
2020-09-28 08:52:38 +02:00
|
|
|
);
|
2018-10-28 01:10:44 +02:00
|
|
|
ubl.encoder_diff = 0;
|
2020-11-08 01:28:29 +01:00
|
|
|
IF_DISABLED(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
2020-09-28 08:52:38 +02:00
|
|
|
TERN_(IS_TFTGLCD_PANEL, ui.refresh(LCDVIEW_CALL_REDRAW_NEXT));
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
if (ui.should_draw()) {
|
2020-07-03 16:53:22 +02:00
|
|
|
const float rounded_f = rounded_mesh_value();
|
|
|
|
MenuEditItemBase::draw_edit_screen(msg, ftostr43sign(rounded_f));
|
|
|
|
TERN_(MESH_EDIT_GFX_OVERLAY, _lcd_zoffset_overlay_gfx(rounded_f));
|
2020-07-30 08:43:19 +02:00
|
|
|
TERN_(HAS_GRAPHICAL_TFT, ui.refresh(LCDVIEW_NONE));
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
//
|
2021-03-24 09:28:48 +01:00
|
|
|
// Init mesh editing and go to the fine tuning screen (ubl.fine_tune_mesh)
|
|
|
|
// To capture encoder events UBL will also call ui.capture and ui.release.
|
2020-07-03 16:53:22 +02:00
|
|
|
//
|
2021-03-24 09:28:48 +01:00
|
|
|
void MarlinUI::ubl_mesh_edit_start(const float &initial) {
|
|
|
|
TERN_(HAS_GRAPHICAL_TFT, clear_lcd());
|
2020-07-03 16:53:22 +02:00
|
|
|
mesh_edit_accumulator = initial;
|
2021-03-24 09:28:48 +01:00
|
|
|
goto_screen([]{ _lcd_mesh_fine_tune(GET_TEXT(MSG_MESH_EDIT_Z)); });
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
2021-03-24 09:28:48 +01:00
|
|
|
//
|
|
|
|
// Get the mesh value within a Z adjustment loop (ubl.fine_tune_mesh)
|
|
|
|
//
|
|
|
|
float MarlinUI::ubl_mesh_value() { return rounded_mesh_value(); }
|
2018-10-28 01:10:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Build Custom Mesh Command
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_build_custom_mesh() {
|
2020-04-10 03:05:58 +02:00
|
|
|
char ubl_lcd_gcode[64];
|
2018-10-28 01:10:44 +02:00
|
|
|
#if HAS_HEATED_BED
|
2020-04-10 03:05:58 +02:00
|
|
|
sprintf_P(ubl_lcd_gcode, PSTR("G28\nM190 S%i\nM109 S%i\nG29 P1"), custom_bed_temp, custom_hotend_temp);
|
|
|
|
#else
|
|
|
|
sprintf_P(ubl_lcd_gcode, PSTR("G28\nM109 S%i\nG29 P1"), custom_hotend_temp);
|
2018-10-28 01:10:44 +02:00
|
|
|
#endif
|
2020-04-10 03:05:58 +02:00
|
|
|
queue.inject(ubl_lcd_gcode);
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Custom Mesh submenu
|
|
|
|
*
|
|
|
|
* << Build Mesh
|
|
|
|
* Hotend Temp: ---
|
|
|
|
* Bed Temp: ---
|
|
|
|
* Build Custom Mesh
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_custom_mesh() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_BUILD_MESH_MENU);
|
2020-06-25 02:44:50 +02:00
|
|
|
#if HAS_HOTEND
|
2021-03-19 22:34:10 +01:00
|
|
|
EDIT_ITEM(int3, MSG_UBL_HOTEND_TEMP_CUSTOM, &custom_hotend_temp, EXTRUDE_MINTEMP, thermalManager.hotend_max_target(0));
|
2020-06-25 02:44:50 +02:00
|
|
|
#endif
|
2018-10-28 01:10:44 +02:00
|
|
|
#if HAS_HEATED_BED
|
2020-04-27 11:41:18 +02:00
|
|
|
EDIT_ITEM(int3, MSG_UBL_BED_TEMP_CUSTOM, &custom_bed_temp, BED_MINTEMP, BED_MAX_TARGET);
|
2018-10-28 01:10:44 +02:00
|
|
|
#endif
|
2019-10-03 12:38:30 +02:00
|
|
|
ACTION_ITEM(MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_build_custom_mesh);
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Adjust Mesh Height Command
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_adjust_height_cmd() {
|
2021-01-17 06:15:43 +01:00
|
|
|
char ubl_lcd_gcode[13];
|
|
|
|
const int ind = ubl_height_amount > 0 ? 6 : 7;
|
|
|
|
strcpy_P(ubl_lcd_gcode, PSTR("G29P6C-"));
|
2019-06-19 07:00:19 +02:00
|
|
|
sprintf_P(&ubl_lcd_gcode[ind], PSTR(".%i"), ABS(ubl_height_amount));
|
2020-04-10 03:05:58 +02:00
|
|
|
queue.inject(ubl_lcd_gcode);
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Adjust Mesh Height submenu
|
|
|
|
*
|
|
|
|
* << Edit Mesh
|
|
|
|
* Height Amount: ---
|
|
|
|
* Adjust Mesh Height
|
|
|
|
* << Info Screen
|
|
|
|
*/
|
|
|
|
void _menu_ubl_height_adjust() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_EDIT_MESH);
|
|
|
|
EDIT_ITEM(int3, MSG_UBL_MESH_HEIGHT_AMOUNT, &ubl_height_amount, -9, 9, _lcd_ubl_adjust_height_cmd);
|
2020-01-04 02:46:05 +01:00
|
|
|
ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Edit Mesh submenu
|
|
|
|
*
|
|
|
|
* << UBL Tools
|
|
|
|
* Fine Tune All
|
|
|
|
* Fine Tune Closest
|
|
|
|
* - Adjust Mesh Height >>
|
|
|
|
* << Info Screen
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_edit_mesh() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_TOOLS);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_FINE_TUNE_ALL, PSTR("G29P4R999T"));
|
|
|
|
GCODES_ITEM(MSG_UBL_FINE_TUNE_CLOSEST, PSTR("G29P4T"));
|
2019-10-03 12:38:30 +02:00
|
|
|
SUBMENU(MSG_UBL_MESH_HEIGHT_ADJUST, _menu_ubl_height_adjust);
|
2020-01-04 02:46:05 +01:00
|
|
|
ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
2020-06-25 02:44:50 +02:00
|
|
|
#if ENABLED(G26_MESH_VALIDATION)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Validate Custom Mesh Command
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_validate_custom_mesh() {
|
2021-01-17 06:15:43 +01:00
|
|
|
char ubl_lcd_gcode[20];
|
|
|
|
sprintf_P(ubl_lcd_gcode, PSTR("G28\nG26CPH%" PRIi16 TERN_(HAS_HEATED_BED, "B%" PRIi16))
|
2020-06-25 02:44:50 +02:00
|
|
|
, custom_hotend_temp
|
|
|
|
#if HAS_HEATED_BED
|
2020-10-12 02:06:57 +02:00
|
|
|
, custom_bed_temp
|
2020-06-25 02:44:50 +02:00
|
|
|
#endif
|
|
|
|
);
|
|
|
|
queue.inject(ubl_lcd_gcode);
|
|
|
|
}
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-06-25 02:44:50 +02:00
|
|
|
/**
|
|
|
|
* UBL Validate Mesh submenu
|
|
|
|
*
|
|
|
|
* << UBL Tools
|
2020-07-09 10:11:57 +02:00
|
|
|
* Mesh Validation with Material 1 up to 5
|
2020-06-25 02:44:50 +02:00
|
|
|
* Validate Custom Mesh
|
|
|
|
* << Info Screen
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_validate_mesh() {
|
|
|
|
START_MENU();
|
|
|
|
BACK_ITEM(MSG_UBL_TOOLS);
|
2020-07-09 10:11:57 +02:00
|
|
|
#if PREHEAT_COUNT
|
|
|
|
#if HAS_HEATED_BED
|
|
|
|
#define VALIDATE_MESH_GCODE_ITEM(M) \
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM_N_S(M, ui.get_preheat_label(M), MSG_UBL_VALIDATE_MESH_M, PSTR("G28\nG26CPI" STRINGIFY(M)))
|
2020-07-09 10:11:57 +02:00
|
|
|
#else
|
|
|
|
#define VALIDATE_MESH_GCODE_ITEM(M) \
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM_N_S(M, ui.get_preheat_label(M), MSG_UBL_VALIDATE_MESH_M, PSTR("G28\nG26CPB0I" STRINGIFY(M)))
|
2020-07-09 10:11:57 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
VALIDATE_MESH_GCODE_ITEM(0);
|
|
|
|
#if PREHEAT_COUNT > 1
|
|
|
|
VALIDATE_MESH_GCODE_ITEM(1);
|
|
|
|
#if PREHEAT_COUNT > 2
|
|
|
|
VALIDATE_MESH_GCODE_ITEM(2);
|
|
|
|
#if PREHEAT_COUNT > 3
|
|
|
|
VALIDATE_MESH_GCODE_ITEM(3);
|
|
|
|
#if PREHEAT_COUNT > 4
|
|
|
|
VALIDATE_MESH_GCODE_ITEM(4);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif // PREHEAT_COUNT
|
2020-06-25 02:44:50 +02:00
|
|
|
ACTION_ITEM(MSG_UBL_VALIDATE_CUSTOM_MESH, _lcd_ubl_validate_custom_mesh);
|
|
|
|
ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
|
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2018-10-28 01:10:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Grid Leveling submenu
|
|
|
|
*
|
|
|
|
* << UBL Tools
|
|
|
|
* Side points: ---
|
|
|
|
* Level Mesh
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_grid_level() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_TOOLS);
|
|
|
|
EDIT_ITEM(int3, MSG_UBL_SIDE_POINTS, &side_points, 2, 6);
|
2019-11-02 06:05:05 +01:00
|
|
|
ACTION_ITEM(MSG_UBL_MESH_LEVEL, []{
|
2019-10-08 02:44:33 +02:00
|
|
|
char ubl_lcd_gcode[12];
|
2021-01-17 06:15:43 +01:00
|
|
|
sprintf_P(ubl_lcd_gcode, PSTR("G29J%i"), side_points);
|
2020-04-10 03:05:58 +02:00
|
|
|
queue.inject(ubl_lcd_gcode);
|
2019-10-08 02:44:33 +02:00
|
|
|
});
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Mesh Leveling submenu
|
|
|
|
*
|
|
|
|
* << UBL Tools
|
|
|
|
* 3-Point Mesh Leveling
|
|
|
|
* - Grid Mesh Leveling >>
|
|
|
|
* << Info Screen
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_mesh_leveling() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_TOOLS);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_3POINT_MESH_LEVELING, PSTR("G29J0"));
|
2019-10-03 12:38:30 +02:00
|
|
|
SUBMENU(MSG_UBL_GRID_MESH_LEVELING, _lcd_ubl_grid_level);
|
2020-01-04 02:46:05 +01:00
|
|
|
ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Fill-in Amount Mesh Command
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_fillin_amount_cmd() {
|
2019-06-19 07:00:19 +02:00
|
|
|
char ubl_lcd_gcode[18];
|
2021-01-17 06:15:43 +01:00
|
|
|
sprintf_P(ubl_lcd_gcode, PSTR("G29P3RC.%i"), ubl_fillin_amount);
|
2020-04-10 03:05:58 +02:00
|
|
|
gcode.process_subcommands_now(ubl_lcd_gcode);
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Fill-in Mesh submenu
|
|
|
|
*
|
|
|
|
* << Build Mesh
|
|
|
|
* Fill-in Amount: ---
|
|
|
|
* Fill-in Mesh
|
|
|
|
* Smart Fill-in
|
|
|
|
* Manual Fill-in
|
|
|
|
* << Info Screen
|
|
|
|
*/
|
|
|
|
void _menu_ubl_fillin() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_BUILD_MESH_MENU);
|
|
|
|
EDIT_ITEM(int3, MSG_UBL_FILLIN_AMOUNT, &ubl_fillin_amount, 0, 9, _lcd_ubl_fillin_amount_cmd);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_SMART_FILLIN, PSTR("G29P3T0"));
|
|
|
|
GCODES_ITEM(MSG_UBL_MANUAL_FILLIN, PSTR("G29P2BT0"));
|
2020-01-04 02:46:05 +01:00
|
|
|
ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
void _lcd_ubl_invalidate() {
|
|
|
|
ubl.invalidate();
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("Mesh invalidated.");
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Build Mesh submenu
|
|
|
|
*
|
|
|
|
* << UBL Tools
|
2020-07-09 10:11:57 +02:00
|
|
|
* Build Mesh with Material 1 up to 5
|
2018-10-28 01:10:44 +02:00
|
|
|
* - Build Custom Mesh >>
|
|
|
|
* Build Cold Mesh
|
|
|
|
* - Fill-in Mesh >>
|
|
|
|
* Continue Bed Mesh
|
|
|
|
* Invalidate All
|
|
|
|
* Invalidate Closest
|
|
|
|
* << Info Screen
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_build_mesh() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_TOOLS);
|
2020-07-09 10:11:57 +02:00
|
|
|
#if PREHEAT_COUNT
|
|
|
|
#if HAS_HEATED_BED
|
2021-01-17 06:15:43 +01:00
|
|
|
#define PREHEAT_BED_GCODE(M) "M190I" STRINGIFY(M) "\n"
|
2020-07-09 10:11:57 +02:00
|
|
|
#else
|
|
|
|
#define PREHEAT_BED_GCODE(M) ""
|
|
|
|
#endif
|
|
|
|
#define BUILD_MESH_GCODE_ITEM(M) GCODES_ITEM_S(ui.get_preheat_label(M), MSG_UBL_BUILD_MESH_M, \
|
|
|
|
PSTR( \
|
|
|
|
"G28\n" \
|
|
|
|
PREHEAT_BED_GCODE(M) \
|
2021-01-17 06:15:43 +01:00
|
|
|
"M109I" STRINGIFY(M) "\n" \
|
|
|
|
"G29P1\n" \
|
|
|
|
"M104S0\n" \
|
|
|
|
"M140S0" \
|
2020-07-09 10:11:57 +02:00
|
|
|
) )
|
|
|
|
BUILD_MESH_GCODE_ITEM(0);
|
|
|
|
#if PREHEAT_COUNT > 1
|
|
|
|
BUILD_MESH_GCODE_ITEM(1);
|
|
|
|
#if PREHEAT_COUNT > 2
|
|
|
|
BUILD_MESH_GCODE_ITEM(2);
|
|
|
|
#if PREHEAT_COUNT > 3
|
|
|
|
BUILD_MESH_GCODE_ITEM(3);
|
|
|
|
#if PREHEAT_COUNT > 4
|
|
|
|
BUILD_MESH_GCODE_ITEM(4);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif // PREHEAT_COUNT
|
|
|
|
|
2019-10-03 12:38:30 +02:00
|
|
|
SUBMENU(MSG_UBL_BUILD_CUSTOM_MESH, _lcd_ubl_custom_mesh);
|
2021-01-17 19:08:40 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_BUILD_COLD_MESH, PSTR("G29NP1"));
|
2019-10-03 12:38:30 +02:00
|
|
|
SUBMENU(MSG_UBL_FILLIN_MESH, _menu_ubl_fillin);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_CONTINUE_MESH, PSTR("G29P1C"));
|
2019-10-03 12:38:30 +02:00
|
|
|
ACTION_ITEM(MSG_UBL_INVALIDATE_ALL, _lcd_ubl_invalidate);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_INVALIDATE_CLOSEST, PSTR("G29I"));
|
2020-01-04 02:46:05 +01:00
|
|
|
ACTION_ITEM(MSG_INFO_SCREEN, ui.return_to_status);
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-06-25 23:39:22 +02:00
|
|
|
* UBL Load / Save Mesh Commands
|
2018-10-28 01:10:44 +02:00
|
|
|
*/
|
2020-06-25 23:39:22 +02:00
|
|
|
inline void _lcd_ubl_load_save_cmd(const char loadsave, PGM_P const msg) {
|
2020-04-10 03:05:58 +02:00
|
|
|
char ubl_lcd_gcode[40];
|
2021-01-17 06:15:43 +01:00
|
|
|
sprintf_P(ubl_lcd_gcode, PSTR("G29%c%i\nM117 "), loadsave, ubl_storage_slot);
|
2020-06-25 23:39:22 +02:00
|
|
|
sprintf_P(&ubl_lcd_gcode[strlen(ubl_lcd_gcode)], msg, ubl_storage_slot);
|
2020-04-10 03:05:58 +02:00
|
|
|
gcode.process_subcommands_now(ubl_lcd_gcode);
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
2020-06-25 23:39:22 +02:00
|
|
|
void _lcd_ubl_load_mesh_cmd() { _lcd_ubl_load_save_cmd('L', GET_TEXT(MSG_MESH_LOADED)); }
|
|
|
|
void _lcd_ubl_save_mesh_cmd() { _lcd_ubl_load_save_cmd('S', GET_TEXT(MSG_MESH_SAVED)); }
|
2018-10-28 01:10:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Mesh Storage submenu
|
|
|
|
*
|
|
|
|
* << Unified Bed Leveling
|
|
|
|
* Memory Slot: ---
|
|
|
|
* Load Bed Mesh
|
|
|
|
* Save Bed Mesh
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_storage_mesh() {
|
|
|
|
int16_t a = settings.calc_num_meshes();
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_LEVEL_BED);
|
2020-04-28 06:52:11 +02:00
|
|
|
if (!WITHIN(ubl_storage_slot, 0, a - 1))
|
2019-08-06 02:09:40 +02:00
|
|
|
STATIC_ITEM(MSG_UBL_NO_STORAGE);
|
2018-10-28 01:10:44 +02:00
|
|
|
else {
|
2019-10-03 12:38:30 +02:00
|
|
|
EDIT_ITEM(int3, MSG_UBL_STORAGE_SLOT, &ubl_storage_slot, 0, a - 1);
|
|
|
|
ACTION_ITEM(MSG_UBL_LOAD_MESH, _lcd_ubl_load_mesh_cmd);
|
|
|
|
ACTION_ITEM(MSG_UBL_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL LCD "radar" map point editing
|
|
|
|
*/
|
2020-07-03 16:53:22 +02:00
|
|
|
void _lcd_ubl_map_edit_cmd() {
|
2019-06-19 07:00:19 +02:00
|
|
|
char ubl_lcd_gcode[50], str[10], str2[10];
|
2019-09-18 01:16:28 +02:00
|
|
|
dtostrf(ubl.mesh_index_to_xpos(x_plot), 0, 2, str);
|
|
|
|
dtostrf(ubl.mesh_index_to_ypos(y_plot), 0, 2, str2);
|
2021-01-17 06:15:43 +01:00
|
|
|
snprintf_P(ubl_lcd_gcode, sizeof(ubl_lcd_gcode), PSTR("G29P4X%sY%sR%i"), str, str2, int(n_edit_pts));
|
2020-04-10 03:05:58 +02:00
|
|
|
queue.inject(ubl_lcd_gcode);
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL LCD Map Movement
|
|
|
|
*/
|
|
|
|
void ubl_map_move_to_xy() {
|
2021-01-02 03:08:10 +01:00
|
|
|
const xy_pos_t xy = { ubl.mesh_index_to_xpos(x_plot), ubl.mesh_index_to_ypos(y_plot) };
|
|
|
|
|
|
|
|
// Some printers have unreachable areas in the mesh. Skip the move if unreachable.
|
|
|
|
if (!position_is_reachable(xy)) return;
|
2019-03-26 04:04:57 +01:00
|
|
|
|
|
|
|
#if ENABLED(DELTA)
|
2020-07-03 16:53:22 +02:00
|
|
|
if (current_position.z > delta_clip_start_height) { // Make sure the delta has fully free motion
|
|
|
|
destination = current_position;
|
2019-09-29 11:25:39 +02:00
|
|
|
destination.z = delta_clip_start_height;
|
2020-07-03 16:53:22 +02:00
|
|
|
prepare_internal_fast_move_to_destination(homing_feedrate(Z_AXIS)); // Set current_position from destination
|
2019-03-26 04:04:57 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-03 02:01:09 +01:00
|
|
|
// Use the built-in manual move handler to move to the mesh point.
|
|
|
|
ui.manual_move.set_destination(xy);
|
|
|
|
ui.manual_move.soon(ALL_AXES);
|
2020-07-03 16:53:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int32_t grid_index(const uint8_t x, const uint8_t y) {
|
|
|
|
return (GRID_MAX_POINTS_X) * y + x;
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL LCD "radar" map
|
|
|
|
*/
|
2020-07-03 16:53:22 +02:00
|
|
|
void ubl_map_screen() {
|
|
|
|
// static millis_t next_move = 0;
|
|
|
|
// const millis_t ms = millis();
|
2020-04-28 06:35:10 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
uint8_t x, y;
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
if (ui.first_page) {
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
// On click send "G29 P4 ..." to edit the Z value
|
|
|
|
if (ui.use_click()) {
|
|
|
|
_lcd_ubl_map_edit_cmd();
|
|
|
|
return;
|
|
|
|
}
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
ui.defer_status_screen();
|
|
|
|
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
// Index of the mesh point upon entry
|
2020-08-06 11:19:56 +02:00
|
|
|
const int32_t old_pos_index = grid_index(x_plot, y_plot);
|
2020-07-03 16:53:22 +02:00
|
|
|
// Direction from new (unconstrained) encoder value
|
|
|
|
const int8_t step_dir = int32_t(ui.encoderPosition) < old_pos_index ? -1 : 1;
|
|
|
|
#endif
|
2019-03-26 04:04:57 +01:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
do {
|
|
|
|
// Now, keep the encoder position within range
|
2020-07-30 08:43:19 +02:00
|
|
|
if (int32_t(ui.encoderPosition) < 0) ui.encoderPosition = GRID_MAX_POINTS + TERN(TOUCH_SCREEN, ui.encoderPosition, -1);
|
|
|
|
if (int32_t(ui.encoderPosition) > GRID_MAX_POINTS - 1) ui.encoderPosition = TERN(TOUCH_SCREEN, ui.encoderPosition - GRID_MAX_POINTS, 0);
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
// Draw the grid point based on the encoder
|
|
|
|
x = ui.encoderPosition % (GRID_MAX_POINTS_X);
|
|
|
|
y = ui.encoderPosition / (GRID_MAX_POINTS_X);
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
// Validate if needed
|
|
|
|
#if IS_KINEMATIC
|
|
|
|
const xy_pos_t xy = { ubl.mesh_index_to_xpos(x), ubl.mesh_index_to_ypos(y) };
|
|
|
|
if (position_is_reachable(xy)) break; // Found a valid point
|
|
|
|
ui.encoderPosition += step_dir; // Test the next point
|
|
|
|
#endif
|
2021-03-03 07:11:50 +01:00
|
|
|
} while (ENABLED(IS_KINEMATIC));
|
2020-07-03 16:53:22 +02:00
|
|
|
|
|
|
|
// Determine number of points to edit
|
2019-03-26 04:04:57 +01:00
|
|
|
#if IS_KINEMATIC
|
2020-07-03 16:53:22 +02:00
|
|
|
n_edit_pts = 9; // TODO: Delta accessible edit points
|
|
|
|
#else
|
|
|
|
const bool xc = WITHIN(x, 1, GRID_MAX_POINTS_X - 2),
|
|
|
|
yc = WITHIN(y, 1, GRID_MAX_POINTS_Y - 2);
|
|
|
|
n_edit_pts = yc ? (xc ? 9 : 6) : (xc ? 6 : 4); // Corners
|
2019-03-26 04:04:57 +01:00
|
|
|
#endif
|
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
// Refresh is also set by encoder movement
|
|
|
|
//if (int32_t(ui.encoderPosition) != grid_index(x, y))
|
|
|
|
// ui.refresh(LCDVIEW_CALL_REDRAW_NEXT);
|
|
|
|
}
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
// Draw the grid point based on the encoder
|
|
|
|
x = ui.encoderPosition % (GRID_MAX_POINTS_X);
|
|
|
|
y = ui.encoderPosition / (GRID_MAX_POINTS_X);
|
2018-10-28 01:10:44 +02:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
if (ui.should_draw()) ui.ubl_plot(x, y);
|
2019-03-26 04:04:57 +01:00
|
|
|
|
2020-07-03 16:53:22 +02:00
|
|
|
// Add a move if needed to match the grid point
|
|
|
|
if (x != x_plot || y != y_plot) {
|
|
|
|
x_plot = x; y_plot = y; // The move is always posted, so update the grid point now
|
|
|
|
ubl_map_move_to_xy(); // Sets up a "manual move"
|
|
|
|
ui.refresh(LCDVIEW_CALL_REDRAW_NEXT); // Clean up a half drawn box
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL LCD "radar" map homing
|
|
|
|
*/
|
|
|
|
void _ubl_map_screen_homing() {
|
|
|
|
ui.defer_status_screen();
|
|
|
|
_lcd_draw_homing();
|
|
|
|
if (all_axes_homed()) {
|
|
|
|
ubl.lcd_map_control = true; // Return to the map screen after editing Z
|
|
|
|
ui.goto_screen(ubl_map_screen, grid_index(x_plot, y_plot)); // Pre-set the encoder value
|
|
|
|
ui.manual_move.menu_scale = 0; // Immediate move
|
|
|
|
ubl_map_move_to_xy(); // Move to current mesh point
|
|
|
|
ui.manual_move.menu_scale = 1; // Delayed moves
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Homing before LCD map
|
|
|
|
*/
|
2020-07-03 16:53:22 +02:00
|
|
|
void _ubl_goto_map_screen() {
|
|
|
|
if (planner.movesplanned()) return; // The ACTION_ITEM will do nothing
|
2020-11-30 02:06:40 +01:00
|
|
|
if (!all_axes_trusted()) {
|
2018-10-31 23:07:52 +01:00
|
|
|
set_all_unhomed();
|
2019-11-02 05:51:25 +01:00
|
|
|
queue.inject_P(G28_STR);
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
2020-07-03 16:53:22 +02:00
|
|
|
ui.goto_screen(_ubl_map_screen_homing); // Go to the "Homing" screen
|
2018-10-28 01:10:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Output map submenu
|
|
|
|
*
|
|
|
|
* << Unified Bed Leveling
|
|
|
|
* Output for Host
|
|
|
|
* Output for CSV
|
|
|
|
* Off Printer Backup
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_output_map() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_LEVEL_BED);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_OUTPUT_MAP_HOST, PSTR("G29T0"));
|
|
|
|
GCODES_ITEM(MSG_UBL_OUTPUT_MAP_CSV, PSTR("G29T1"));
|
|
|
|
GCODES_ITEM(MSG_UBL_OUTPUT_MAP_BACKUP, PSTR("G29S-1"));
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Tools submenu
|
|
|
|
*
|
|
|
|
* << Unified Bed Leveling
|
|
|
|
* - Build Mesh >>
|
|
|
|
* - Validate Mesh >>
|
|
|
|
* - Edit Mesh >>
|
|
|
|
* - Mesh Leveling >>
|
|
|
|
*/
|
|
|
|
void _menu_ubl_tools() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_UBL_LEVEL_BED);
|
|
|
|
SUBMENU(MSG_UBL_BUILD_MESH_MENU, _lcd_ubl_build_mesh);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_MANUAL_MESH, PSTR("G29I999\nG29P2BT0"));
|
2020-06-25 02:44:50 +02:00
|
|
|
#if ENABLED(G26_MESH_VALIDATION)
|
|
|
|
SUBMENU(MSG_UBL_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
|
|
|
|
#endif
|
2019-10-03 12:38:30 +02:00
|
|
|
SUBMENU(MSG_EDIT_MESH, _lcd_ubl_edit_mesh);
|
|
|
|
SUBMENU(MSG_UBL_MESH_LEVELING, _lcd_ubl_mesh_leveling);
|
2018-10-28 01:10:44 +02:00
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
2020-06-25 02:44:50 +02:00
|
|
|
#if ENABLED(G26_MESH_VALIDATION)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL Step-By-Step submenu
|
|
|
|
*
|
|
|
|
* << Unified Bed Leveling
|
|
|
|
* 1 Build Cold Mesh
|
|
|
|
* 2 Smart Fill-in
|
|
|
|
* - 3 Validate Mesh >>
|
|
|
|
* 4 Fine Tune All
|
|
|
|
* - 5 Validate Mesh >>
|
|
|
|
* 6 Fine Tune All
|
|
|
|
* 7 Save Bed Mesh
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_step_by_step() {
|
|
|
|
START_MENU();
|
|
|
|
BACK_ITEM(MSG_UBL_LEVEL_BED);
|
2021-01-17 19:08:40 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_1_BUILD_COLD_MESH, PSTR("G29NP1"));
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_2_SMART_FILLIN, PSTR("G29P3T0"));
|
2020-06-25 02:44:50 +02:00
|
|
|
SUBMENU(MSG_UBL_3_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_4_FINE_TUNE_ALL, PSTR("G29P4R999T"));
|
2020-06-25 02:44:50 +02:00
|
|
|
SUBMENU(MSG_UBL_5_VALIDATE_MESH_MENU, _lcd_ubl_validate_mesh);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_6_FINE_TUNE_ALL, PSTR("G29P4R999T"));
|
2020-06-25 02:44:50 +02:00
|
|
|
ACTION_ITEM(MSG_UBL_7_SAVE_MESH, _lcd_ubl_save_mesh_cmd);
|
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2018-10-28 01:10:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* UBL System submenu
|
|
|
|
*
|
|
|
|
* << Motion
|
|
|
|
* - Manually Build Mesh >>
|
|
|
|
* - Activate UBL >>
|
|
|
|
* - Deactivate UBL >>
|
|
|
|
* - Step-By-Step UBL >>
|
|
|
|
* - Mesh Storage >>
|
|
|
|
* - Output Map >>
|
|
|
|
* - UBL Tools >>
|
|
|
|
* - Output UBL Info >>
|
|
|
|
*/
|
|
|
|
void _lcd_ubl_level_bed() {
|
|
|
|
START_MENU();
|
2019-10-03 12:38:30 +02:00
|
|
|
BACK_ITEM(MSG_MOTION);
|
2020-04-29 21:52:42 +02:00
|
|
|
if (planner.leveling_active)
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_DEACTIVATE_MESH, PSTR("G29D"));
|
2020-04-29 21:52:42 +02:00
|
|
|
else
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_ACTIVATE_MESH, PSTR("G29A"));
|
2020-06-25 02:44:50 +02:00
|
|
|
#if ENABLED(G26_MESH_VALIDATION)
|
|
|
|
SUBMENU(MSG_UBL_STEP_BY_STEP_MENU, _lcd_ubl_step_by_step);
|
|
|
|
#endif
|
2020-07-03 16:53:22 +02:00
|
|
|
ACTION_ITEM(MSG_UBL_MESH_EDIT, _ubl_goto_map_screen);
|
2019-10-03 12:38:30 +02:00
|
|
|
SUBMENU(MSG_UBL_STORAGE_MESH_MENU, _lcd_ubl_storage_mesh);
|
|
|
|
SUBMENU(MSG_UBL_OUTPUT_MAP, _lcd_ubl_output_map);
|
|
|
|
SUBMENU(MSG_UBL_TOOLS, _menu_ubl_tools);
|
2021-01-17 06:15:43 +01:00
|
|
|
GCODES_ITEM(MSG_UBL_INFO_UBL, PSTR("G29W"));
|
2018-10-28 01:10:44 +02:00
|
|
|
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
|
2019-10-08 02:44:33 +02:00
|
|
|
editable.decimal = planner.z_fade_height;
|
2019-11-02 06:05:05 +01:00
|
|
|
EDIT_ITEM_FAST(float3, MSG_Z_FADE_HEIGHT, &editable.decimal, 0, 100, []{ set_z_fade_height(editable.decimal); });
|
2018-10-28 01:10:44 +02:00
|
|
|
#endif
|
|
|
|
END_MENU();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // HAS_LCD_MENU && AUTO_BED_LEVELING_UBL
|