Further repairs to UBL, comments, spacing

master
Scott Lahteine 8 years ago
parent f3618c3337
commit 9e4bd6b3b5

@ -38,7 +38,7 @@
#define EXTRUSION_MULTIPLIER 1.0 // This is too much clutter for the main Configuration.h file But
#define RETRACTION_MULTIPLIER 1.0 // some user have expressed an interest in being able to customize
#define NOZZLE 0.3 // these numbers for thier printer so they don't need to type all
#define NOZZLE 0.3 // these numbers for their printer so they don't need to type all
#define FILAMENT 1.75 // the options every time they do a Mesh Validation Print.
#define LAYER_HEIGHT 0.2
#define PRIME_LENGTH 10.0 // So, we put these number in an easy to find and change place.
@ -113,10 +113,7 @@
* Y # Y coordinate Specify the starting location of the drawing activity.
*/
extern bool g26_debug_flag;
extern bool ubl_has_control_of_lcd_panel;
extern float feedrate;
//extern bool relative_mode;
extern Planner planner;
//#if ENABLED(ULTRA_LCD)
extern char lcd_status_message[];
@ -197,12 +194,10 @@
set_current_to_destination();
}
ubl_has_control_of_lcd_panel = true; // Take control of the LCD Panel!
ubl.has_control_of_lcd_panel = true; // Take control of the LCD Panel!
if (turn_on_heaters()) // Turn on the heaters, leave the command if anything
goto LEAVE; // has gone wrong.
axis_relative_modes[E_AXIS] = false; // Get things setup so we can take control of the
//relative_mode = false; // planner and stepper motors!
current_position[E_AXIS] = 0.0;
sync_plan_position_e();
@ -232,7 +227,7 @@
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0.0);
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], ooze_amount);
ubl_has_control_of_lcd_panel = true; // Take control of the LCD Panel!
ubl.has_control_of_lcd_panel = true; // Take control of the LCD Panel!
//debug_current_and_destination((char*)"Starting G26 Mesh Validation Pattern.");
/**
@ -292,7 +287,7 @@
xi = location.x_index; // Just to shrink the next few lines and make them easier to understand
yi = location.y_index;
if (g26_debug_flag) {
if (ubl.g26_debug_flag) {
SERIAL_ECHOPAIR(" Doing circle at: (xi=", xi);
SERIAL_ECHOPAIR(", yi=", yi);
SERIAL_CHAR(')');
@ -346,7 +341,7 @@
ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1);
#endif
//if (g26_debug_flag) {
//if (ubl.g26_debug_flag) {
// char ccc, *cptr, seg_msg[50], seg_num[10];
// strcpy(seg_msg, " segment: ");
// strcpy(seg_num, " \n");
@ -364,7 +359,7 @@
//if (lcd_init_counter > 10) {
// lcd_init_counter = 0;
// lcd_init(); // Some people's LCD Displays are locking up. This might help them
// ubl_has_control_of_lcd_panel = true; // Make sure UBL still is controlling the LCD Panel
// ubl.has_control_of_lcd_panel = true; // Make sure UBL still is controlling the LCD Panel
//}
//debug_current_and_destination((char*)"Looking for lines to connect.");
@ -394,7 +389,7 @@
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 0); // Move back to the starting position
//debug_current_and_destination((char*)"done doing X/Y move.");
ubl_has_control_of_lcd_panel = false; // Give back control of the LCD Panel!
ubl.has_control_of_lcd_panel = false; // Give back control of the LCD Panel!
if (!keep_heaters_on) {
#if HAS_TEMP_BED
@ -479,7 +474,7 @@
ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
if (g26_debug_flag) {
if (ubl.g26_debug_flag) {
SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx);
SERIAL_ECHOPAIR(", sy=", sy);
SERIAL_ECHOPAIR(") -> (ex=", ex);
@ -516,7 +511,7 @@
ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1);
if (g26_debug_flag) {
if (ubl.g26_debug_flag) {
SERIAL_ECHOPAIR(" Connecting with vertical line (sx=", sx);
SERIAL_ECHOPAIR(", sy=", sy);
SERIAL_ECHOPAIR(") -> (ex=", ex);
@ -541,10 +536,10 @@
bool has_xy_component = (x != current_position[X_AXIS] || y != current_position[Y_AXIS]); // Check if X or Y is involved in the movement.
//if (g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() has_xy_component:", (int)has_xy_component);
//if (ubl.g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() has_xy_component:", (int)has_xy_component);
if (z != last_z) {
//if (g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() changing Z to ", (int)z);
//if (ubl.g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() changing Z to ", (int)z);
last_z = z;
feed_value = planner.max_feedrate_mm_s[Z_AXIS]/(3.0); // Base the feed rate off of the configured Z_AXIS feed rate
@ -559,24 +554,24 @@
stepper.synchronize();
set_destination_to_current();
//if (g26_debug_flag) debug_current_and_destination((char*)" in move_to() done with Z move");
//if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() done with Z move");
}
// Check if X or Y is involved in the movement.
// Yes: a 'normal' movement. No: a retract() or un_retract()
feed_value = has_xy_component ? PLANNER_XY_FEEDRATE() / 10.0 : planner.max_feedrate_mm_s[E_AXIS] / 1.5;
if (g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() feed_value for XY:", feed_value);
if (ubl.g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() feed_value for XY:", feed_value);
destination[X_AXIS] = x;
destination[Y_AXIS] = y;
destination[E_AXIS] += e_delta;
//if (g26_debug_flag) debug_current_and_destination((char*)" in move_to() doing last move");
//if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() doing last move");
ubl_line_to_destination(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], feed_value, 0);
//if (g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
//if (ubl.g26_debug_flag) debug_current_and_destination((char*)" in move_to() after last move");
stepper.synchronize();
set_destination_to_current();
@ -586,9 +581,9 @@
void retract_filament() {
if (!g26_retracted) { // Only retract if we are not already retracted!
g26_retracted = true;
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
//if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Decided to do retract.");
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], -1.0 * retraction_multiplier);
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
//if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Retraction done.");
}
}
@ -596,7 +591,7 @@
if (g26_retracted) { // Only un-retract if we are retracted.
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 1.2 * retraction_multiplier);
g26_retracted = false;
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
//if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" unretract done.");
}
}
@ -633,7 +628,7 @@
// On very small lines we don't do the optimization because it just isn't worth it.
//
if (dist_end < dist_start && (SIZE_OF_INTERSECTION_CIRCLES) < abs(line_length)) {
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" Reversing start and end of print_line_from_here_to_there()");
//if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" Reversing start and end of print_line_from_here_to_there()");
print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
return;
}
@ -642,7 +637,7 @@
if (dist_start > 2.0) {
retract_filament();
//if (g26_debug_flag) SERIAL_ECHOLNPGM(" filament retracted.");
//if (ubl.g26_debug_flag) SERIAL_ECHOLNPGM(" filament retracted.");
}
move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
@ -650,7 +645,7 @@
un_retract_filament();
//if (g26_debug_flag) {
//if (ubl.g26_debug_flag) {
// SERIAL_ECHOLNPGM(" doing printing move.");
// debug_current_and_destination((char*)"doing final move_to() inside print_line_from_here_to_there()");
//}
@ -810,7 +805,7 @@
lcd_setstatuspgm(PSTR("G26 Heating Bed."), 99);
lcd_quick_feedback();
#endif
ubl_has_control_of_lcd_panel = true;
ubl.has_control_of_lcd_panel = true;
thermalManager.setTargetBed(bed_temp);
while (abs(thermalManager.degBed() - bed_temp) > 3) {
if (ubl_lcd_clicked()) return exit_from_g26();

@ -76,10 +76,10 @@ void gcode_M100() {
// We want to start and end the dump on a nice 16 byte boundry even though
// the values we are using are not 16 byte aligned.
//
SERIAL_ECHOPAIR("\nbss_end : ", hex_word((uint16_t)ptr));
SERIAL_ECHOPAIR("\nbss_end : 0x", hex_word((uint16_t)ptr));
ptr = (char*)((uint32_t)ptr & 0xfff0);
sp = top_of_stack();
SERIAL_ECHOLNPAIR("\nStack Pointer : ", hex_word((uint16_t)sp));
SERIAL_ECHOLNPAIR("\nStack Pointer : 0x", hex_word((uint16_t)sp));
sp = (char*)((uint32_t)sp | 0x000f);
n = sp - ptr;
//

@ -299,13 +299,11 @@
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "UBL.h"
unified_bed_leveling ubl;
#define UBL_MESH_VALID !( ( z_values[0][0] == z_values[0][1] && z_values[0][1] == z_values[0][2] \
&& z_values[1][0] == z_values[1][1] && z_values[1][1] == z_values[1][2] \
&& z_values[2][0] == z_values[2][1] && z_values[2][1] == z_values[2][2] \
&& z_values[0][0] == 0 && z_values[1][0] == 0 && z_values[2][0] == 0 ) \
|| isnan(z_values[0][0]))
extern bool g26_debug_flag;
extern int ubl_eeprom_start;
#define UBL_MESH_VALID !( ( ubl.z_values[0][0] == ubl.z_values[0][1] && ubl.z_values[0][1] == ubl.z_values[0][2] \
&& ubl.z_values[1][0] == ubl.z_values[1][1] && ubl.z_values[1][1] == ubl.z_values[1][2] \
&& ubl.z_values[2][0] == ubl.z_values[2][1] && ubl.z_values[2][1] == ubl.z_values[2][2] \
&& ubl.z_values[0][0] == 0 && ubl.z_values[1][0] == 0 && ubl.z_values[2][0] == 0 ) \
|| isnan(ubl.z_values[0][0]))
#endif
bool Running = true;
@ -5349,11 +5347,9 @@ inline void gcode_M42() {
#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_MESH_EDIT_ENABLED)
inline void gcode_M49() {
ubl.g26_debug_flag = !ubl.g26_debug_flag;
SERIAL_PROTOCOLPGM("UBL Debug Flag turned ");
if ((g26_debug_flag = !g26_debug_flag))
SERIAL_PROTOCOLLNPGM("on.");
else
SERIAL_PROTOCOLLNPGM("off.");
serialprintPGM(ubl.g26_debug_flag ? PSTR("on.") : PSTR("off."));
}
#endif // AUTO_BED_LEVELING_UBL && UBL_MESH_EDIT_ENABLED
@ -7216,6 +7212,8 @@ void quickstop_stepper() {
* Z[height] Sets the Z fade height (0 or none to disable)
* V[bool] Verbose - Print the leveling grid
*
* With AUTO_BED_LEVELING_UBL only:
*
* L[index] Load UBL mesh from index (0 is default)
*/
inline void gcode_M420() {
@ -7224,15 +7222,15 @@ void quickstop_stepper() {
// L to load a mesh from the EEPROM
if (code_seen('L')) {
const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(z_values);
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return;
}
ubl.load_mesh(Storage_Slot);
ubl.state.eeprom_storage_slot = Storage_Slot;
if (Storage_Slot != ubl.state.eeprom_storage_slot)
ubl.store_state();
ubl.load_mesh(storage_slot);
if (storage_slot != ubl.state.eeprom_storage_slot) ubl.store_state();
ubl.state.eeprom_storage_slot = storage_slot;
ubl.display_map(0); // Right now, we only support one type of map
SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID);
SERIAL_ECHOLNPAIR("eeprom_storage_slot = ", ubl.state.eeprom_storage_slot);
@ -8736,7 +8734,7 @@ void process_next_command() {
#endif // Z_MIN_PROBE_REPEATABILITY_TEST
#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_MESH_EDIT_ENABLED)
case 49: // M49: Turn on or off g26_debug_flag for verbose output
case 49: // M49: Turn on or off G26 debug flag for verbose output
gcode_M49();
break;
#endif // AUTO_BED_LEVELING_UBL && UBL_MESH_EDIT_ENABLED

@ -81,20 +81,33 @@
#define MESH_X_DIST ((float(UBL_MESH_MAX_X) - float(UBL_MESH_MIN_X)) / (float(UBL_MESH_NUM_X_POINTS) - 1.0))
#define MESH_Y_DIST ((float(UBL_MESH_MAX_Y) - float(UBL_MESH_MIN_Y)) / (float(UBL_MESH_NUM_Y_POINTS) - 1.0))
extern float last_specified_z;
extern float fade_scaling_factor_for_current_height;
extern float z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS];
extern float mesh_index_to_x_location[UBL_MESH_NUM_X_POINTS + 1]; // +1 just because of paranoia that we might end up on the
extern float mesh_index_to_y_location[UBL_MESH_NUM_Y_POINTS + 1]; // the last Mesh Line and that is the start of a whole new cell
class unified_bed_leveling {
private:
float last_specified_z,
fade_scaling_factor_for_current_height;
public:
float z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS];
bool g26_debug_flag = false,
has_control_of_lcd_panel = false;
int8_t eeprom_start = -1;
volatile int encoder_diff; // Volatile because it's changed at interrupt time.
struct ubl_state {
bool active = false;
float z_offset = 0.0;
int eeprom_storage_slot = -1,
int8_t eeprom_storage_slot = -1,
n_x = UBL_MESH_NUM_X_POINTS,
n_y = UBL_MESH_NUM_Y_POINTS;
float mesh_x_min = UBL_MESH_MIN_X,
mesh_y_min = UBL_MESH_MIN_Y,
mesh_x_max = UBL_MESH_MAX_X,
@ -104,23 +117,26 @@
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
float g29_correction_fade_height = 10.0,
g29_fade_height_multiplier = 1.0 / 10.0; // It is cheaper to do a floating point multiply than a floating
// point divide. So, we keep this number in both forms. The first
// is for the user. The second one is the one that is actually used
// again and again and again during the correction calculations.
g29_fade_height_multiplier = 1.0 / 10.0; // It's cheaper to do a floating point multiply than divide,
// so keep this value and its reciprocal.
#else
const float g29_correction_fade_height = 10.0,
g29_fade_height_multiplier = 1.0 / 10.0;
#endif
unsigned char padding[24]; // This is just to allow room to add state variables without
// If you change this struct, adjust TOTAL_STRUCT_SIZE
#define TOTAL_STRUCT_SIZE 43 // Total size of the above fields
// padding provides space to add state variables without
// changing the location of data structures in the EEPROM.
// This is for compatability with future versions to keep
// people from having to regenerate thier mesh data.
//
// If you change the contents of this struct, please adjust
// the padding[] to keep the size the same!
// This is for compatibility with future versions to keep
// users from having to regenerate their mesh data.
unsigned char padding[64 - TOTAL_STRUCT_SIZE];
} state, pre_initialized;
unified_bed_leveling();
// ~unified_bed_leveling(); // No destructor because this object never goes away!
void display_map(const int);
@ -269,7 +285,8 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPAIR(" raw get_z_correction(", x0);
SERIAL_ECHOPAIR(",", y0);
SERIAL_CHAR(',')
SERIAL_ECHO(y0);
SERIAL_ECHOPGM(") = ");
SERIAL_ECHO_F(z0, 6);
}
@ -291,11 +308,11 @@
#if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPGM("??? Yikes! NAN in get_z_correction( ");
SERIAL_ECHO(x0);
SERIAL_ECHOPGM(", ");
SERIAL_ECHOPAIR("??? Yikes! NAN in get_z_correction(", x0);
SERIAL_CHAR(',');
SERIAL_ECHO(y0);
SERIAL_ECHOLNPGM(" )");
SERIAL_CHAR(')');
SERIAL_EOL;
}
#endif
}
@ -313,7 +330,7 @@
*/
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) const {
FORCE_INLINE float fade_scaling_factor_for_z(const float &lz) {
const float rz = RAW_Z_POSITION(lz);
if (last_specified_z != rz) {
last_specified_z = rz;

@ -27,7 +27,6 @@
#include "UBL.h"
#include "hex_print_routines.h"
extern int ubl_eeprom_start;
/**
* These support functions allow the use of large bit arrays of flags that take very
@ -65,10 +64,7 @@
* 'member data'. So, in the interest of speed, we do it this way. On a 32-bit CPU they can be
* moved back inside the bed leveling class.
*/
float last_specified_z,
fade_scaling_factor_for_current_height,
z_values[UBL_MESH_NUM_X_POINTS][UBL_MESH_NUM_Y_POINTS],
mesh_index_to_x_location[UBL_MESH_NUM_X_POINTS + 1], // +1 just because of paranoia that we might end up on the
float mesh_index_to_x_location[UBL_MESH_NUM_X_POINTS + 1], // +1 just because of paranoia that we might end up on the
mesh_index_to_y_location[UBL_MESH_NUM_Y_POINTS + 1]; // the last Mesh Line and that is the start of a whole new cell
unified_bed_leveling::unified_bed_leveling() {
@ -96,7 +92,7 @@
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
/**
* These lines can go away in a few weeks. They are just
* to make sure people updating thier firmware won't be using
* to make sure people updating their firmware won't be using
* an incomplete Bed_Leveling.state structure. For speed
* we now multiply by the inverse of the Fade Height instead of
* dividing by it. Soon... all of the old structures will be
@ -111,7 +107,7 @@
}
void unified_bed_leveling::load_mesh(const int16_t m) {
int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values);
int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
if (m == -1) {
SERIAL_PROTOCOLLNPGM("?No mesh saved in EEPROM. Zeroing mesh in memory.\n");
@ -119,7 +115,7 @@
return;
}
if (m < 0 || m >= j || ubl_eeprom_start <= 0) {
if (m < 0 || m >= j || eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
return;
}
@ -132,9 +128,9 @@
}
void unified_bed_leveling::store_mesh(const int16_t m) {
int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values);
int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
if (m < 0 || m >= j || ubl_eeprom_start <= 0) {
if (m < 0 || m >= j || eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
SERIAL_PROTOCOL(m);
SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
@ -202,9 +198,8 @@
for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
const bool is_current = i == current_xi && j == current_yi;
// is the nozzle here? if so, mark the number
if (map0)
SERIAL_CHAR(is_current ? '[' : ' ');
// is the nozzle here? then mark the number
if (map0) SERIAL_CHAR(is_current ? '[' : ' ');
const float f = z_values[i][j];
if (isnan(f)) {
@ -212,12 +207,11 @@
}
else {
// if we don't do this, the columns won't line up nicely
if (f >= 0.0 && map0) SERIAL_CHAR(' ');
if (map0 && f >= 0.0) SERIAL_CHAR(' ');
SERIAL_PROTOCOL_F(f, 3);
idle();
}
if (!map0 && i < UBL_MESH_NUM_X_POINTS - 1)
SERIAL_CHAR(',');
if (!map0 && i < UBL_MESH_NUM_X_POINTS - 1) SERIAL_CHAR(',');
#if TX_BUFFER_SIZE > 0
MYSERIAL.flushTX();
@ -256,43 +250,36 @@
SERIAL_PROTOCOLLNPGM("?UBL_MESH_NUM_X_POINTS set wrong\n");
error_flag++;
}
if (state.n_y != UBL_MESH_NUM_Y_POINTS) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_NUM_Y_POINTS set wrong\n");
error_flag++;
}
if (state.mesh_x_min != UBL_MESH_MIN_X) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_X set wrong\n");
error_flag++;
}
if (state.mesh_y_min != UBL_MESH_MIN_Y) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_Y set wrong\n");
error_flag++;
}
if (state.mesh_x_max != UBL_MESH_MAX_X) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_X set wrong\n");
error_flag++;
}
if (state.mesh_y_max != UBL_MESH_MAX_Y) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_Y set wrong\n");
error_flag++;
}
if (state.mesh_x_dist != MESH_X_DIST) {
SERIAL_PROTOCOLLNPGM("?MESH_X_DIST set wrong\n");
error_flag++;
}
if (state.mesh_y_dist != MESH_Y_DIST) {
SERIAL_PROTOCOLLNPGM("?MESH_Y_DIST set wrong\n");
error_flag++;
}
const int j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values);
const int j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
if (j < 1) {
SERIAL_PROTOCOLLNPGM("?No EEPROM storage available for a mesh of this size.\n");
error_flag++;

@ -65,8 +65,6 @@
#define SIZE_OF_LITTLE_RAISE 0
#define BIG_RAISE_NOT_NEEDED 0
extern void lcd_quick_feedback();
extern int ubl_eeprom_start;
extern volatile int ubl_encoderDiff; // This is volatile because it is getting changed at interrupt time.
/**
* G29: Unified Bed Leveling by Roxy
@ -146,7 +144,7 @@
* P0 Phase 0 Zero Mesh Data and turn off the Mesh Compensation System. This reverts the
* 3D Printer to the same state it was in before the Unified Bed Leveling Compensation
* was turned on. Setting the entire Mesh to Zero is a special case that allows
* a subsequent G or T leveling operation for backward compatability.
* a subsequent G or T leveling operation for backward compatibility.
*
* P1 Phase 1 Invalidate entire Mesh and continue with automatic generation of the Mesh data using
* the Z-Probe. Depending upon the values of DELTA_PROBEABLE_RADIUS and
@ -299,14 +297,10 @@
* this is going to be helpful to the users!)
*
* The foundation of this Bed Leveling System is built on Epatel's Mesh Bed Leveling code. A big
* 'Thanks!' to him and the creators of 3-Point and Grid Based leveling. Combining thier contributions
* 'Thanks!' to him and the creators of 3-Point and Grid Based leveling. Combining their contributions
* we now have the functionality and features of all three systems combined.
*/
int ubl_eeprom_start = -1;
bool ubl_has_control_of_lcd_panel = false;
volatile int8_t ubl_encoderDiff = 0; // Volatile because it's changed by Temperature ISR button update
// The simple parameter flags and values are 'static' so parameter parsing can be in a support routine.
static int g29_verbose_level, phase_value = -1, repetition_cnt,
storage_slot = 0, map_type; //unlevel_value = -1;
@ -318,8 +312,8 @@
#endif
void gcode_G29() {
SERIAL_PROTOCOLLNPAIR("ubl_eeprom_start=", ubl_eeprom_start);
if (ubl_eeprom_start < 0) {
SERIAL_PROTOCOLLNPAIR("ubl.eeprom_start=", ubl.eeprom_start);
if (ubl.eeprom_start < 0) {
SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
return;
@ -340,7 +334,7 @@
SERIAL_PROTOCOLLNPGM("Entire Mesh invalidated.\n");
break; // No more invalid Mesh Points to populate
}
z_values[location.x_index][location.y_index] = NAN;
ubl.z_values[location.x_index][location.y_index] = NAN;
}
SERIAL_PROTOCOLLNPGM("Locations invalidated.\n");
}
@ -359,21 +353,21 @@
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) { // a poorly calibrated Delta.
const float p1 = 0.5 * (UBL_MESH_NUM_X_POINTS) - x,
p2 = 0.5 * (UBL_MESH_NUM_Y_POINTS) - y;
z_values[x][y] += 2.0 * HYPOT(p1, p2);
ubl.z_values[x][y] += 2.0 * HYPOT(p1, p2);
}
}
break;
case 1:
for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) { // Create a diagonal line several Mesh cells thick that is raised
z_values[x][x] += 9.999;
z_values[x][x + (x < UBL_MESH_NUM_Y_POINTS - 1) ? 1 : -1] += 9.999; // We want the altered line several mesh points thick
ubl.z_values[x][x] += 9.999;
ubl.z_values[x][x + (x < UBL_MESH_NUM_Y_POINTS - 1) ? 1 : -1] += 9.999; // We want the altered line several mesh points thick
}
break;
case 2:
// Allow the user to specify the height because 10mm is a little extreme in some cases.
for (uint8_t x = (UBL_MESH_NUM_X_POINTS) / 3; x < 2 * (UBL_MESH_NUM_X_POINTS) / 3; x++) // Create a rectangular raised area in
for (uint8_t y = (UBL_MESH_NUM_Y_POINTS) / 3; y < 2 * (UBL_MESH_NUM_Y_POINTS) / 3; y++) // the center of the bed
z_values[x][y] += code_seen('C') ? ubl_constant : 9.99;
ubl.z_values[x][y] += code_seen('C') ? ubl_constant : 9.99;
break;
}
}
@ -395,17 +389,18 @@
return;
}
switch (phase_value) {
case 0:
//
// Zero Mesh Data
//
case 0:
ubl.reset();
SERIAL_PROTOCOLLNPGM("Mesh zeroed.\n");
break;
case 1:
//
// Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
//
case 1:
if (!code_seen('C') ) {
ubl.invalidate();
SERIAL_PROTOCOLLNPGM("Mesh invalidated. Probing mesh.\n");
@ -419,10 +414,11 @@
probe_entire_mesh(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER,
code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U'));
break;
case 2: {
//
// Manually Probe Mesh in areas that can't be reached by the probe
//
case 2: {
SERIAL_PROTOCOLLNPGM("Manually probing unreachable mesh locations.\n");
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
if (!x_flag && !y_flag) { // use a good default location for the path
@ -455,24 +451,24 @@
} break;
case 3: {
//
// Populate invalid Mesh areas with a constant
//
case 3: {
const float height = code_seen('C') ? ubl_constant : 0.0;
// If no repetition is specified, do the whole Mesh
if (!repeat_flag) repetition_cnt = 9999;
while (repetition_cnt--) {
const mesh_index_pair location = find_closest_mesh_point_of_type(INVALID, x_pos, y_pos, 0, NULL, false); // The '0' says we want to use the nozzle's position
if (location.x_index < 0) break; // No more invalid Mesh Points to populate
z_values[location.x_index][location.y_index] = height;
ubl.z_values[location.x_index][location.y_index] = height;
}
} break;
case 4:
//
// Fine Tune (Or Edit) the Mesh
// Fine Tune (i.e., Edit) the Mesh
//
case 4:
fine_tune_mesh(x_pos, y_pos, code_seen('O') || code_seen('M'));
break;
case 5:
@ -487,16 +483,16 @@
SERIAL_ECHO_START;
SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:");
KEEPALIVE_STATE(PAUSED_FOR_USER);
ubl_has_control_of_lcd_panel++;
ubl.has_control_of_lcd_panel++;
while (!ubl_lcd_clicked()) {
safe_delay(250);
if (ubl_encoderDiff) {
SERIAL_ECHOLN((int)ubl_encoderDiff);
ubl_encoderDiff = 0;
if (ubl.encoder_diff) {
SERIAL_ECHOLN((int)ubl.encoder_diff);
ubl.encoder_diff = 0;
}
}
SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel.");
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
KEEPALIVE_STATE(IN_HANDLER);
break;
@ -508,9 +504,9 @@
wait_for_user = true;
while (wait_for_user) {
safe_delay(250);
if (ubl_encoderDiff) {
SERIAL_ECHOLN((int)ubl_encoderDiff);
ubl_encoderDiff = 0;
if (ubl.encoder_diff) {
SERIAL_ECHOLN((int)ubl.encoder_diff);
ubl.encoder_diff = 0;
}
}
SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel.");
@ -562,9 +558,9 @@
if (code_seen('L')) { // Load Current Mesh Data
storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot;
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values);
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
if (storage_slot < 0 || storage_slot >= j || ubl_eeprom_start <= 0) {
if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return;
}
@ -586,19 +582,19 @@
SERIAL_ECHOLNPGM("G29 I 999"); // host in a form it can be reconstructed on a different machine
for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y])) {
if (!isnan(ubl.z_values[x][y])) {
SERIAL_ECHOPAIR("M421 I ", x);
SERIAL_ECHOPAIR(" J ", y);
SERIAL_ECHOPGM(" Z ");
SERIAL_ECHO_F(z_values[x][y], 6);
SERIAL_ECHO_F(ubl.z_values[x][y], 6);
SERIAL_EOL;
}
return;
}
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values);
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
if (storage_slot < 0 || storage_slot >= j || ubl_eeprom_start <= 0) {
if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
goto LEAVE;
@ -622,7 +618,7 @@
save_ubl_active_state_and_disable();
//measured_z = probe_pt(x_pos + X_PROBE_OFFSET_FROM_EXTRUDER, y_pos + Y_PROBE_OFFSET_FROM_EXTRUDER, ProbeDeployAndStow, g29_verbose_level);
ubl_has_control_of_lcd_panel++; // Grab the LCD Hardware
ubl.has_control_of_lcd_panel++; // Grab the LCD Hardware
measured_z = 1.5;
do_blocking_move_to_z(measured_z); // Get close to the bed, but leave some space so we don't damage anything
// The user is not going to be locking in a new Z-Offset very often so
@ -638,7 +634,7 @@
do_blocking_move_to_z(measured_z);
} while (!ubl_lcd_clicked());
ubl_has_control_of_lcd_panel++; // There is a race condition for the Encoder Wheel getting clicked.
ubl.has_control_of_lcd_panel++; // There is a race condition for the Encoder Wheel getting clicked.
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
// or here. So, until we are done looking for a long Encoder Wheel Press,
// we need to take control of the panel
@ -658,7 +654,7 @@
goto LEAVE;
}
}
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
safe_delay(20); // We don't want any switch noise.
ubl.state.z_offset = measured_z;
@ -675,7 +671,7 @@
lcd_quick_feedback();
#endif
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
}
void find_mean_mesh_height() {
@ -687,8 +683,8 @@
n = 0;
for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y])) {
sum += z_values[x][y];
if (!isnan(ubl.z_values[x][y])) {
sum += ubl.z_values[x][y];
n++;
}
@ -699,8 +695,8 @@
//
for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y])) {
difference = (z_values[x][y] - mean);
if (!isnan(ubl.z_values[x][y])) {
difference = (ubl.z_values[x][y] - mean);
sum_of_diff_squared += difference * difference;
}
@ -717,15 +713,15 @@
if (c_flag)
for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y]))
z_values[x][y] -= mean + ubl_constant;
if (!isnan(ubl.z_values[x][y]))
ubl.z_values[x][y] -= mean + ubl_constant;
}
void shift_mesh_height() {
for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y]))
z_values[x][y] += ubl_constant;
if (!isnan(ubl.z_values[x][y]))
ubl.z_values[x][y] += ubl_constant;
}
/**
@ -735,7 +731,7 @@
void probe_entire_mesh(const float &lx, const float &ly, const bool do_ubl_mesh_map, const bool stow_probe, bool do_furthest) {
mesh_index_pair location;
ubl_has_control_of_lcd_panel++;
ubl.has_control_of_lcd_panel++;
save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
DEPLOY_PROBE();
@ -745,7 +741,7 @@
lcd_quick_feedback();
STOW_PROBE();
while (ubl_lcd_clicked()) idle();
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
restore_ubl_active_state_and_leave();
safe_delay(50); // Debounce the Encoder wheel
return;
@ -761,11 +757,11 @@
if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
goto LEAVE;
}
const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level);
z_values[location.x_index][location.y_index] = measured_z + zprobe_zoffset;
ubl.z_values[location.x_index][location.y_index] = measured_z + zprobe_zoffset;
}
if (do_ubl_mesh_map) ubl.display_map(map_type);
@ -842,7 +838,7 @@
for (i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
for (j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
c = -((normal.x * (UBL_MESH_MIN_X + i * (MESH_X_DIST)) + normal.y * (UBL_MESH_MIN_Y + j * (MESH_Y_DIST))) - d);
z_values[i][j] += c;
ubl.z_values[i][j] += c;
}
}
return normal;
@ -852,9 +848,9 @@
KEEPALIVE_STATE(PAUSED_FOR_USER);
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
idle();
if (ubl_encoderDiff) {
do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(ubl_encoderDiff));
ubl_encoderDiff = 0;
if (ubl.encoder_diff) {
do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(ubl.encoder_diff));
ubl.encoder_diff = 0;
}
}
KEEPALIVE_STATE(IN_HANDLER);
@ -863,7 +859,7 @@
float measure_business_card_thickness(const float &in_height) {
ubl_has_control_of_lcd_panel++;
ubl.has_control_of_lcd_panel++;
save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
SERIAL_PROTOCOLLNPGM("Place Shim Under Nozzle and Perform Measurement.");
@ -873,7 +869,7 @@
const float z1 = use_encoder_wheel_to_measure_point();
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE);
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
SERIAL_PROTOCOLLNPGM("Remove Shim and Measure Bed Height.");
const float z2 = use_encoder_wheel_to_measure_point();
@ -890,7 +886,7 @@
void manually_probe_remaining_mesh(const float &lx, const float &ly, const float &z_clearance, const float &card_thickness, const bool do_ubl_mesh_map) {
ubl_has_control_of_lcd_panel++;
ubl.has_control_of_lcd_panel++;
save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
do_blocking_move_to_z(z_clearance);
do_blocking_move_to_xy(lx, ly);
@ -911,7 +907,7 @@
if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
goto LEAVE;
}
@ -931,13 +927,13 @@
last_y = yProbe;
KEEPALIVE_STATE(PAUSED_FOR_USER);
ubl_has_control_of_lcd_panel = true;
ubl.has_control_of_lcd_panel = true;
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
idle();
if (ubl_encoderDiff) {
do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl_encoderDiff) / 100.0);
ubl_encoderDiff = 0;
if (ubl.encoder_diff) {
do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl.encoder_diff) / 100.0);
ubl.encoder_diff = 0;
}
}
@ -949,17 +945,17 @@
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
lcd_quick_feedback();
while (ubl_lcd_clicked()) idle();
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
KEEPALIVE_STATE(IN_HANDLER);
restore_ubl_active_state_and_leave();
return;
}
}
z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - card_thickness;
ubl.z_values[location.x_index][location.y_index] = current_position[Z_AXIS] - card_thickness;
if (g29_verbose_level > 2) {
SERIAL_PROTOCOLPGM("Mesh Point Measured at: ");
SERIAL_PROTOCOL_F(z_values[location.x_index][location.y_index], 6);
SERIAL_PROTOCOL_F(ubl.z_values[location.x_index][location.y_index], 6);
SERIAL_EOL;
}
} while (location.x_index >= 0 && location.y_index >= 0);
@ -1110,7 +1106,7 @@
* good to have the extra information. Soon... we prune this to just a few items
*/
void g29_what_command() {
const uint16_t k = E2END - ubl_eeprom_start;
const uint16_t k = E2END - ubl.eeprom_start;
SERIAL_PROTOCOLPGM("Unified Bed Leveling System Version 1.00 ");
if (ubl.state.active)
@ -1167,21 +1163,21 @@
SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
SERIAL_EOL;
safe_delay(50);
SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: 0x", hex_word(ubl_eeprom_start));
SERIAL_PROTOCOLLNPAIR("Free EEPROM space starts at: 0x", hex_word(ubl.eeprom_start));
SERIAL_PROTOCOLLNPAIR("end of EEPROM : ", hex_word(E2END));
SERIAL_PROTOCOLLNPAIR("end of EEPROM : 0x", hex_word(E2END));
safe_delay(50);
SERIAL_PROTOCOLLNPAIR("sizeof(ubl) : ", (int)sizeof(ubl));
SERIAL_EOL;
SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(z_values));
SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(ubl.z_values));
SERIAL_EOL;
safe_delay(50);
SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: 0x", hex_word(k));
safe_delay(50);
SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(z_values));
SERIAL_PROTOCOLPAIR("EEPROM can hold ", k / sizeof(ubl.z_values));
SERIAL_PROTOCOLLNPGM(" meshes.\n");
safe_delay(50);
@ -1245,9 +1241,9 @@
}
storage_slot = code_value_int();
int16_t j = (UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(tmp_z_values);
int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(tmp_z_values);
if (storage_slot < 0 || storage_slot > j || ubl_eeprom_start <= 0) {
if (storage_slot < 0 || storage_slot > j || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return;
}
@ -1256,12 +1252,12 @@
eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
SERIAL_ECHOPAIR("Subtracting Mesh ", storage_slot);
SERIAL_PROTOCOLLNPAIR(" loaded from EEPROM address ", hex_word(j)); // Soon, we can remove the extra clutter of printing
SERIAL_PROTOCOLLNPAIR(" loaded from EEPROM address 0x", hex_word(j)); // Soon, we can remove the extra clutter of printing
// the address in the EEPROM where the Mesh is stored.
for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
z_values[x][y] = z_values[x][y] - tmp_z_values[x][y];
ubl.z_values[x][y] -= tmp_z_values[x][y];
}
mesh_index_pair find_closest_mesh_point_of_type(const MeshPointType type, const float &lx, const float &ly, const bool probe_as_reference, unsigned int bits[16], bool far_flag) {
@ -1280,8 +1276,8 @@
for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
for (uint8_t j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) {
if ( (type == INVALID && isnan(z_values[i][j])) // Check to see if this location holds the right thing
|| (type == REAL && !isnan(z_values[i][j]))
if ( (type == INVALID && isnan(ubl.z_values[i][j])) // Check to see if this location holds the right thing
|| (type == REAL && !isnan(ubl.z_values[i][j]))
|| (type == SET_IN_BITMAP && is_bit_set(bits, i, j))
) {
@ -1308,7 +1304,7 @@
if (far_flag) { // If doing the far_flag action, we want to be as far as possible
for (uint8_t k = 0; k < UBL_MESH_NUM_X_POINTS; k++) { // from the starting point and from any other probed points. We
for (uint8_t l = 0; l < UBL_MESH_NUM_Y_POINTS; l++) { // want the next point spread out and filling in any blank spaces
if (!isnan(z_values[k][l])) { // in the mesh. So we add in some of the distance to every probed
if (!isnan(ubl.z_values[k][l])) { // in the mesh. So we add in some of the distance to every probed
distance += sq(i - k) * (MESH_X_DIST) * .05 // point we can find.
+ sq(j - l) * (MESH_Y_DIST) * .05;
}
@ -1361,19 +1357,19 @@
if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) { // In theory, we don't need this check.
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
goto FINE_TUNE_EXIT;
}
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); // Move the nozzle to where we are going to edit
do_blocking_move_to_xy(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy));
float new_z = z_values[location.x_index][location.y_index];
float new_z = ubl.z_values[location.x_index][location.y_index];
round_off = (int32_t)(new_z * 1000.0); // we chop off the last digits just to be clean. We are rounding to the
new_z = float(round_off) / 1000.0;
KEEPALIVE_STATE(PAUSED_FOR_USER);
ubl_has_control_of_lcd_panel = true;
ubl.has_control_of_lcd_panel = true;
lcd_implementation_clear();
lcd_mesh_edit_setup(new_z);
@ -1385,7 +1381,7 @@
lcd_return_to_status();
ubl_has_control_of_lcd_panel = true; // There is a race condition for the Encoder Wheel getting clicked.
ubl.has_control_of_lcd_panel = true; // There is a race condition for the Encoder Wheel getting clicked.
// It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
// or here.
@ -1406,7 +1402,7 @@
safe_delay(20); // We don't want any switch noise.
z_values[location.x_index][location.y_index] = new_z;
ubl.z_values[location.x_index][location.y_index] = new_z;
lcd_implementation_clear();
@ -1414,7 +1410,7 @@
FINE_TUNE_EXIT:
ubl_has_control_of_lcd_panel = false;
ubl.has_control_of_lcd_panel = false;
KEEPALIVE_STATE(IN_HANDLER);
if (do_ubl_mesh_map) ubl.display_map(map_type);

@ -32,12 +32,11 @@
extern float destination[XYZE];
extern void set_current_to_destination();
extern float destination[];
bool g26_debug_flag = false;
void debug_current_and_destination(char *title) {
// if the title message starts with a '!' it is so important, we are going to
// ignore the status of the g26_debug_flag
if (*title != '!' && !g26_debug_flag) return;
if (*title != '!' && !ubl.g26_debug_flag) return;
const float de = destination[E_AXIS] - current_position[E_AXIS];
@ -122,7 +121,7 @@
cell_dest_xi = ubl.get_cell_index_x(RAW_X_POSITION(x_end)),
cell_dest_yi = ubl.get_cell_index_y(RAW_Y_POSITION(y_end));
if (g26_debug_flag) {
if (ubl.g26_debug_flag) {
SERIAL_ECHOPGM(" ubl_line_to_destination(xe=");
SERIAL_ECHO(x_end);
SERIAL_ECHOPGM(", ye=");
@ -151,7 +150,7 @@
planner.buffer_line(x_end, y_end, z_end + ubl.state.z_offset, e_end, feed_rate, extruder);
set_current_to_destination();
if (g26_debug_flag)
if (ubl.g26_debug_flag)
debug_current_and_destination((char*)"out of bounds in ubl_line_to_destination()");
return;
@ -213,7 +212,7 @@
planner.buffer_line(x_end, y_end, z_end + z0 + ubl.state.z_offset, e_end, feed_rate, extruder);
if (g26_debug_flag)
if (ubl.g26_debug_flag)
debug_current_and_destination((char*)"FINAL_MOVE in ubl_line_to_destination()");
set_current_to_destination();
@ -340,7 +339,7 @@
} //else printf("FIRST MOVE PRUNED ");
}
if (g26_debug_flag)
if (ubl.g26_debug_flag)
debug_current_and_destination((char*)"vertical move done in ubl_line_to_destination()");
//
@ -425,7 +424,7 @@
} //else printf("FIRST MOVE PRUNED ");
}
if (g26_debug_flag)
if (ubl.g26_debug_flag)
debug_current_and_destination((char*)"horizontal move done in ubl_line_to_destination()");
if (current_position[X_AXIS] != x_end || current_position[Y_AXIS] != y_end)
@ -564,7 +563,7 @@
}
}
if (g26_debug_flag)
if (ubl.g26_debug_flag)
debug_current_and_destination((char*)"generic move done in ubl_line_to_destination()");
if (current_position[0] != x_end || current_position[1] != y_end)

@ -166,7 +166,6 @@
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "UBL.h"
int ubl_eeprom_start = -1;
#endif
#if ENABLED(ABL_BILINEAR_SUBDIVISION)
@ -847,7 +846,7 @@ void Config_Postprocess() {
}
#if ENABLED(AUTO_BED_LEVELING_UBL)
ubl_eeprom_start = (eeprom_index + 32) & 0xFFF8; // Pad the end of configuration data so it
ubl.eeprom_start = (eeprom_index + 32) & 0xFFF8; // Pad the end of configuration data so it
// can float up or down a little bit without
// disrupting the Unified Bed Leveling data
ubl.load_state();
@ -1233,7 +1232,7 @@ void Config_ResetDefault() {
SERIAL_ECHO_F(ubl.state.z_offset, 6);
SERIAL_EOL;
SERIAL_ECHOPAIR("EEPROM can hold ", (int)((UBL_LAST_EEPROM_INDEX - ubl_eeprom_start) / sizeof(z_values)));
SERIAL_ECHOPAIR("EEPROM can hold ", (int)((UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values)));
SERIAL_ECHOLNPGM(" meshes.\n");
SERIAL_ECHOLNPGM("UBL_MESH_NUM_X_POINTS " STRINGIFY(UBL_MESH_NUM_X_POINTS));

@ -124,8 +124,7 @@ uint16_t max_display_update_time = 0;
int32_t lastEncoderMovementMillis;
#if ENABLED(AUTO_BED_LEVELING_UBL)
extern bool ubl_has_control_of_lcd_panel;
extern int8_t ubl_encoderDiff;
#include "UBL.h"
#endif
#if HAS_POWER_SWITCH
@ -860,9 +859,9 @@ void kill_screen(const char* lcd_msg) {
static void _lcd_mesh_fine_tune(const char* msg) {
defer_return_to_status = true;
if (ubl_encoderDiff) {
ubl_encoderPosition = (ubl_encoderDiff > 0) ? 1 : -1;
ubl_encoderDiff = 0;
if (ubl.encoder_diff) {
ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
ubl.encoder_diff = 0;
mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
mesh_edit_value = mesh_edit_accumulator;
@ -3206,7 +3205,7 @@ void lcd_update() {
lcd_buttons_update();
#if ENABLED(AUTO_BED_LEVELING_UBL)
const bool UBL_CONDITION = !ubl_has_control_of_lcd_panel;
const bool UBL_CONDITION = !ubl.has_control_of_lcd_panel;
#else
constexpr bool UBL_CONDITION = true;
#endif
@ -3622,8 +3621,8 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
}
#if ENABLED(AUTO_BED_LEVELING_UBL)
if (ubl_has_control_of_lcd_panel) {
ubl_encoderDiff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
if (ubl.has_control_of_lcd_panel) {
ubl.encoder_diff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor
encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
// wheel has not turned.
}

Loading…
Cancel
Save