|
@@ -2644,8 +2644,16 @@ inline void gcode_G28() {
|
2644
|
2644
|
* on again when homing all axis
|
2645
|
2645
|
*/
|
2646
|
2646
|
#if ENABLED(MESH_BED_LEVELING)
|
2647
|
|
- uint8_t mbl_was_active = mbl.active;
|
2648
|
|
- mbl.active = false;
|
|
2647
|
+ float pre_home_z = MESH_HOME_SEARCH_Z;
|
|
2648
|
+ if (mbl.is_active()) {
|
|
2649
|
+ // Save known Z position if already homed
|
|
2650
|
+ if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
|
|
2651
|
+ pre_home_z = current_position[Z_AXIS];
|
|
2652
|
+ pre_home_z += mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
|
|
2653
|
+ current_position[Y_AXIS] - home_offset[Y_AXIS]);
|
|
2654
|
+ }
|
|
2655
|
+ mbl.is_active(false);
|
|
2656
|
+ }
|
2649
|
2657
|
#endif
|
2650
|
2658
|
|
2651
|
2659
|
setup_for_endstop_move();
|
|
@@ -2945,20 +2953,31 @@ inline void gcode_G28() {
|
2945
|
2953
|
|
2946
|
2954
|
// Enable mesh leveling again
|
2947
|
2955
|
#if ENABLED(MESH_BED_LEVELING)
|
2948
|
|
- if (mbl_was_active && home_all_axis) {
|
2949
|
|
- current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
|
2950
|
|
- sync_plan_position();
|
2951
|
|
- mbl.active = 1;
|
2952
|
|
- #if ENABLED(MESH_G28_REST_ORIGIN)
|
2953
|
|
- current_position[Z_AXIS] = 0.0;
|
2954
|
|
- set_destination_to_current();
|
2955
|
|
- feedrate = homing_feedrate[Z_AXIS];
|
2956
|
|
- line_to_destination();
|
2957
|
|
- stepper.synchronize();
|
2958
|
|
- #endif
|
2959
|
|
- #if ENABLED(DEBUG_LEVELING_FEATURE)
|
2960
|
|
- if (DEBUGGING(LEVELING)) DEBUG_POS("mbl_was_active", current_position);
|
2961
|
|
- #endif
|
|
2956
|
+ if (mbl.has_mesh()) {
|
|
2957
|
+ if (home_all_axis || (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && homeZ)) {
|
|
2958
|
+ current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
|
|
2959
|
+ sync_plan_position();
|
|
2960
|
+ mbl.is_active(true);
|
|
2961
|
+ #if ENABLED(MESH_G28_REST_ORIGIN)
|
|
2962
|
+ current_position[Z_AXIS] = 0.0;
|
|
2963
|
+ set_destination_to_current();
|
|
2964
|
+ feedrate = homing_feedrate[Z_AXIS];
|
|
2965
|
+ line_to_destination();
|
|
2966
|
+ stepper.synchronize();
|
|
2967
|
+ #else
|
|
2968
|
+ current_position[Z_AXIS] = MESH_HOME_SEARCH_Z -
|
|
2969
|
+ mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
|
|
2970
|
+ current_position[Y_AXIS] - home_offset[Y_AXIS]);
|
|
2971
|
+ #endif
|
|
2972
|
+ }
|
|
2973
|
+ else if ((axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) && (homeX || homeY)) {
|
|
2974
|
+ current_position[Z_AXIS] = pre_home_z;
|
|
2975
|
+ sync_plan_position();
|
|
2976
|
+ mbl.is_active(true);
|
|
2977
|
+ current_position[Z_AXIS] = pre_home_z -
|
|
2978
|
+ mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
|
|
2979
|
+ current_position[Y_AXIS] - home_offset[Y_AXIS]);
|
|
2980
|
+ }
|
2962
|
2981
|
}
|
2963
|
2982
|
#endif
|
2964
|
2983
|
|
|
@@ -2978,7 +2997,7 @@ inline void gcode_G28() {
|
2978
|
2997
|
|
2979
|
2998
|
#if ENABLED(MESH_BED_LEVELING)
|
2980
|
2999
|
|
2981
|
|
- enum MeshLevelingState { MeshReport, MeshStart, MeshNext, MeshSet, MeshSetZOffset };
|
|
3000
|
+ enum MeshLevelingState { MeshReport, MeshStart, MeshNext, MeshSet, MeshSetZOffset, MeshReset };
|
2982
|
3001
|
|
2983
|
3002
|
inline void _mbl_goto_xy(float x, float y) {
|
2984
|
3003
|
saved_feedrate = feedrate;
|
|
@@ -3015,6 +3034,7 @@ inline void gcode_G28() {
|
3015
|
3034
|
* S2 Probe the next mesh point
|
3016
|
3035
|
* S3 Xn Yn Zn.nn Manually modify a single point
|
3017
|
3036
|
* S4 Zn.nn Set z offset. Positive away from bed, negative closer to bed.
|
|
3037
|
+ * S5 Reset and disable mesh
|
3018
|
3038
|
*
|
3019
|
3039
|
* The S0 report the points as below
|
3020
|
3040
|
*
|
|
@@ -3028,8 +3048,8 @@ inline void gcode_G28() {
|
3028
|
3048
|
|
3029
|
3049
|
static int probe_point = -1;
|
3030
|
3050
|
MeshLevelingState state = code_seen('S') ? (MeshLevelingState)code_value_short() : MeshReport;
|
3031
|
|
- if (state < 0 || state > 4) {
|
3032
|
|
- SERIAL_PROTOCOLLNPGM("S out of range (0-4).");
|
|
3051
|
+ if (state < 0 || state > 5) {
|
|
3052
|
+ SERIAL_PROTOCOLLNPGM("S out of range (0-5).");
|
3033
|
3053
|
return;
|
3034
|
3054
|
}
|
3035
|
3055
|
|
|
@@ -3038,8 +3058,13 @@ inline void gcode_G28() {
|
3038
|
3058
|
|
3039
|
3059
|
switch (state) {
|
3040
|
3060
|
case MeshReport:
|
3041
|
|
- if (mbl.active) {
|
3042
|
|
- SERIAL_PROTOCOLPGM("Num X,Y: ");
|
|
3061
|
+ if (mbl.has_mesh()) {
|
|
3062
|
+ SERIAL_PROTOCOLPGM("State: ");
|
|
3063
|
+ if (mbl.is_active())
|
|
3064
|
+ SERIAL_PROTOCOLPGM("On");
|
|
3065
|
+ else
|
|
3066
|
+ SERIAL_PROTOCOLPGM("Off");
|
|
3067
|
+ SERIAL_PROTOCOLPGM("\nNum X,Y: ");
|
3043
|
3068
|
SERIAL_PROTOCOL(MESH_NUM_X_POINTS);
|
3044
|
3069
|
SERIAL_PROTOCOLCHAR(',');
|
3045
|
3070
|
SERIAL_PROTOCOL(MESH_NUM_Y_POINTS);
|
|
@@ -3100,7 +3125,7 @@ inline void gcode_G28() {
|
3100
|
3125
|
// After recording the last point, activate the mbl and home
|
3101
|
3126
|
SERIAL_PROTOCOLLNPGM("Mesh probing done.");
|
3102
|
3127
|
probe_point = -1;
|
3103
|
|
- mbl.active = true;
|
|
3128
|
+ mbl.has_mesh(true);
|
3104
|
3129
|
enqueue_and_echo_commands_P(PSTR("G28"));
|
3105
|
3130
|
}
|
3106
|
3131
|
break;
|
|
@@ -3147,6 +3172,19 @@ inline void gcode_G28() {
|
3147
|
3172
|
return;
|
3148
|
3173
|
}
|
3149
|
3174
|
mbl.z_offset = z;
|
|
3175
|
+ break;
|
|
3176
|
+
|
|
3177
|
+ case MeshReset:
|
|
3178
|
+ if (mbl.is_active()) {
|
|
3179
|
+ current_position[Z_AXIS] +=
|
|
3180
|
+ mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
|
|
3181
|
+ current_position[Y_AXIS] - home_offset[Y_AXIS]) - MESH_HOME_SEARCH_Z;
|
|
3182
|
+ mbl.reset();
|
|
3183
|
+ sync_plan_position();
|
|
3184
|
+ }
|
|
3185
|
+ else
|
|
3186
|
+ mbl.reset();
|
|
3187
|
+
|
3150
|
3188
|
} // switch(state)
|
3151
|
3189
|
|
3152
|
3190
|
report_current_position();
|
|
@@ -5944,7 +5982,7 @@ inline void gcode_M410() {
|
5944
|
5982
|
/**
|
5945
|
5983
|
* M420: Enable/Disable Mesh Bed Leveling
|
5946
|
5984
|
*/
|
5947
|
|
- inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.active = !!code_value_short(); }
|
|
5985
|
+ inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.has_mesh(!!code_value_short()); }
|
5948
|
5986
|
|
5949
|
5987
|
/**
|
5950
|
5988
|
* M421: Set a single Mesh Bed Leveling Z coordinate
|
|
@@ -7335,7 +7373,7 @@ void clamp_to_software_endstops(float target[3]) {
|
7335
|
7373
|
|
7336
|
7374
|
// This function is used to split lines on mesh borders so each segment is only part of one mesh area
|
7337
|
7375
|
void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
|
7338
|
|
- if (!mbl.active) {
|
|
7376
|
+ if (!mbl.is_active()) {
|
7339
|
7377
|
planner.buffer_line(x, y, z, e, feed_rate, extruder);
|
7340
|
7378
|
set_current_to_destination();
|
7341
|
7379
|
return;
|