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 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 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 FILAMENT 1.75 // the options every time they do a Mesh Validation Print.
#define LAYER_HEIGHT 0.2 #define LAYER_HEIGHT 0.2
#define PRIME_LENGTH 10.0 // So, we put these number in an easy to find and change place. #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. * 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 float feedrate;
//extern bool relative_mode;
extern Planner planner; extern Planner planner;
//#if ENABLED(ULTRA_LCD) //#if ENABLED(ULTRA_LCD)
extern char lcd_status_message[]; extern char lcd_status_message[];
@ -197,12 +194,10 @@
set_current_to_destination(); 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 if (turn_on_heaters()) // Turn on the heaters, leave the command if anything
goto LEAVE; // has gone wrong. 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; current_position[E_AXIS] = 0.0;
sync_plan_position_e(); 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], 0.0);
move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], ooze_amount); 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."); //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 xi = location.x_index; // Just to shrink the next few lines and make them easier to understand
yi = location.y_index; yi = location.y_index;
if (g26_debug_flag) { if (ubl.g26_debug_flag) {
SERIAL_ECHOPAIR(" Doing circle at: (xi=", xi); SERIAL_ECHOPAIR(" Doing circle at: (xi=", xi);
SERIAL_ECHOPAIR(", yi=", yi); SERIAL_ECHOPAIR(", yi=", yi);
SERIAL_CHAR(')'); SERIAL_CHAR(')');
@ -346,7 +341,7 @@
ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1); ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1);
#endif #endif
//if (g26_debug_flag) { //if (ubl.g26_debug_flag) {
// char ccc, *cptr, seg_msg[50], seg_num[10]; // char ccc, *cptr, seg_msg[50], seg_num[10];
// strcpy(seg_msg, " segment: "); // strcpy(seg_msg, " segment: ");
// strcpy(seg_num, " \n"); // strcpy(seg_num, " \n");
@ -364,7 +359,7 @@
//if (lcd_init_counter > 10) { //if (lcd_init_counter > 10) {
// lcd_init_counter = 0; // lcd_init_counter = 0;
// lcd_init(); // Some people's LCD Displays are locking up. This might help them // 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."); //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 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."); //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 (!keep_heaters_on) {
#if HAS_TEMP_BED #if HAS_TEMP_BED
@ -479,7 +474,7 @@
ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1); ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
ey = constrain(ey, Y_MIN_POS + 1, Y_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(" Connecting with horizontal line (sx=", sx);
SERIAL_ECHOPAIR(", sy=", sy); SERIAL_ECHOPAIR(", sy=", sy);
SERIAL_ECHOPAIR(") -> (ex=", ex); SERIAL_ECHOPAIR(") -> (ex=", ex);
@ -516,7 +511,7 @@
ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1); ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1);
ey = constrain(ey, Y_MIN_POS + 1, Y_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(" Connecting with vertical line (sx=", sx);
SERIAL_ECHOPAIR(", sy=", sy); SERIAL_ECHOPAIR(", sy=", sy);
SERIAL_ECHOPAIR(") -> (ex=", ex); 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. 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 (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; 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 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(); stepper.synchronize();
set_destination_to_current(); 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. // Check if X or Y is involved in the movement.
// Yes: a 'normal' movement. No: a retract() or un_retract() // 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; 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[X_AXIS] = x;
destination[Y_AXIS] = y; destination[Y_AXIS] = y;
destination[E_AXIS] += e_delta; 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); 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(); stepper.synchronize();
set_destination_to_current(); set_destination_to_current();
@ -586,9 +581,9 @@
void retract_filament() { void retract_filament() {
if (!g26_retracted) { // Only retract if we are not already retracted! if (!g26_retracted) { // Only retract if we are not already retracted!
g26_retracted = true; 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); 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. 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); move_to(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], 1.2 * retraction_multiplier);
g26_retracted = false; 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. // 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 (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); print_line_from_here_to_there(ex, ey, ez, sx, sy, sz);
return; return;
} }
@ -642,7 +637,7 @@
if (dist_start > 2.0) { if (dist_start > 2.0) {
retract_filament(); 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 move_to(sx, sy, sz, 0.0); // Get to the starting point with no extrusion
@ -650,7 +645,7 @@
un_retract_filament(); un_retract_filament();
//if (g26_debug_flag) { //if (ubl.g26_debug_flag) {
// SERIAL_ECHOLNPGM(" doing printing move."); // SERIAL_ECHOLNPGM(" doing printing move.");
// debug_current_and_destination((char*)"doing final move_to() inside print_line_from_here_to_there()"); // 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_setstatuspgm(PSTR("G26 Heating Bed."), 99);
lcd_quick_feedback(); lcd_quick_feedback();
#endif #endif
ubl_has_control_of_lcd_panel = true; ubl.has_control_of_lcd_panel = true;
thermalManager.setTargetBed(bed_temp); thermalManager.setTargetBed(bed_temp);
while (abs(thermalManager.degBed() - bed_temp) > 3) { while (abs(thermalManager.degBed() - bed_temp) > 3) {
if (ubl_lcd_clicked()) return exit_from_g26(); 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 // 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. // 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); ptr = (char*)((uint32_t)ptr & 0xfff0);
sp = top_of_stack(); 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); sp = (char*)((uint32_t)sp | 0x000f);
n = sp - ptr; n = sp - ptr;
// //

@ -299,13 +299,11 @@
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
#include "UBL.h" #include "UBL.h"
unified_bed_leveling ubl; unified_bed_leveling ubl;
#define UBL_MESH_VALID !( ( z_values[0][0] == z_values[0][1] && z_values[0][1] == z_values[0][2] \ #define UBL_MESH_VALID !( ( ubl.z_values[0][0] == ubl.z_values[0][1] && ubl.z_values[0][1] == ubl.z_values[0][2] \
&& z_values[1][0] == z_values[1][1] && z_values[1][1] == z_values[1][2] \ && ubl.z_values[1][0] == ubl.z_values[1][1] && ubl.z_values[1][1] == ubl.z_values[1][2] \
&& z_values[2][0] == z_values[2][1] && z_values[2][1] == z_values[2][2] \ && ubl.z_values[2][0] == ubl.z_values[2][1] && ubl.z_values[2][1] == ubl.z_values[2][2] \
&& z_values[0][0] == 0 && z_values[1][0] == 0 && z_values[2][0] == 0 ) \ && ubl.z_values[0][0] == 0 && ubl.z_values[1][0] == 0 && ubl.z_values[2][0] == 0 ) \
|| isnan(z_values[0][0])) || isnan(ubl.z_values[0][0]))
extern bool g26_debug_flag;
extern int ubl_eeprom_start;
#endif #endif
bool Running = true; bool Running = true;
@ -5349,11 +5347,9 @@ inline void gcode_M42() {
#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_MESH_EDIT_ENABLED) #if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_MESH_EDIT_ENABLED)
inline void gcode_M49() { inline void gcode_M49() {
ubl.g26_debug_flag = !ubl.g26_debug_flag;
SERIAL_PROTOCOLPGM("UBL Debug Flag turned "); SERIAL_PROTOCOLPGM("UBL Debug Flag turned ");
if ((g26_debug_flag = !g26_debug_flag)) serialprintPGM(ubl.g26_debug_flag ? PSTR("on.") : PSTR("off."));
SERIAL_PROTOCOLLNPGM("on.");
else
SERIAL_PROTOCOLLNPGM("off.");
} }
#endif // AUTO_BED_LEVELING_UBL && UBL_MESH_EDIT_ENABLED #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) * Z[height] Sets the Z fade height (0 or none to disable)
* V[bool] Verbose - Print the leveling grid * V[bool] Verbose - Print the leveling grid
* *
* With AUTO_BED_LEVELING_UBL only:
*
* L[index] Load UBL mesh from index (0 is default) * L[index] Load UBL mesh from index (0 is default)
*/ */
inline void gcode_M420() { inline void gcode_M420() {
@ -7224,15 +7222,15 @@ void quickstop_stepper() {
// L to load a mesh from the EEPROM // L to load a mesh from the EEPROM
if (code_seen('L')) { if (code_seen('L')) {
const int8_t storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot; 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) { if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n"); SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return; return;
} }
ubl.load_mesh(Storage_Slot);
ubl.state.eeprom_storage_slot = Storage_Slot; ubl.load_mesh(storage_slot);
if (Storage_Slot != ubl.state.eeprom_storage_slot) if (storage_slot != ubl.state.eeprom_storage_slot) ubl.store_state();
ubl.store_state(); ubl.state.eeprom_storage_slot = storage_slot;
ubl.display_map(0); // Right now, we only support one type of map ubl.display_map(0); // Right now, we only support one type of map
SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID); SERIAL_ECHOLNPAIR("UBL_MESH_VALID = ", UBL_MESH_VALID);
SERIAL_ECHOLNPAIR("eeprom_storage_slot = ", ubl.state.eeprom_storage_slot); SERIAL_ECHOLNPAIR("eeprom_storage_slot = ", ubl.state.eeprom_storage_slot);
@ -8736,7 +8734,7 @@ void process_next_command() {
#endif // Z_MIN_PROBE_REPEATABILITY_TEST #endif // Z_MIN_PROBE_REPEATABILITY_TEST
#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(UBL_MESH_EDIT_ENABLED) #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(); gcode_M49();
break; break;
#endif // AUTO_BED_LEVELING_UBL && UBL_MESH_EDIT_ENABLED #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_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)) #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_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 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 { class unified_bed_leveling {
private:
float last_specified_z,
fade_scaling_factor_for_current_height;
public: 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 { struct ubl_state {
bool active = false; bool active = false;
float z_offset = 0.0; float z_offset = 0.0;
int eeprom_storage_slot = -1, int8_t eeprom_storage_slot = -1,
n_x = UBL_MESH_NUM_X_POINTS, n_x = UBL_MESH_NUM_X_POINTS,
n_y = UBL_MESH_NUM_Y_POINTS; n_y = UBL_MESH_NUM_Y_POINTS;
float mesh_x_min = UBL_MESH_MIN_X, float mesh_x_min = UBL_MESH_MIN_X,
mesh_y_min = UBL_MESH_MIN_Y, mesh_y_min = UBL_MESH_MIN_Y,
mesh_x_max = UBL_MESH_MAX_X, mesh_x_max = UBL_MESH_MAX_X,
@ -104,23 +117,26 @@
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
float g29_correction_fade_height = 10.0, 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 g29_fade_height_multiplier = 1.0 / 10.0; // It's cheaper to do a floating point multiply than divide,
// point divide. So, we keep this number in both forms. The first // so keep this value and its reciprocal.
// is for the user. The second one is the one that is actually used #else
// again and again and again during the correction calculations. const float g29_correction_fade_height = 10.0,
g29_fade_height_multiplier = 1.0 / 10.0;
#endif #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. // changing the location of data structures in the EEPROM.
// This is for compatability with future versions to keep // This is for compatibility with future versions to keep
// people from having to regenerate thier mesh data. // users from having to regenerate their mesh data.
// unsigned char padding[64 - TOTAL_STRUCT_SIZE];
// If you change the contents of this struct, please adjust
// the padding[] to keep the size the same!
} state, pre_initialized; } state, pre_initialized;
unified_bed_leveling(); unified_bed_leveling();
// ~unified_bed_leveling(); // No destructor because this object never goes away!
void display_map(const int); void display_map(const int);
@ -269,7 +285,8 @@
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) { if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPAIR(" raw get_z_correction(", x0); SERIAL_ECHOPAIR(" raw get_z_correction(", x0);
SERIAL_ECHOPAIR(",", y0); SERIAL_CHAR(',')
SERIAL_ECHO(y0);
SERIAL_ECHOPGM(") = "); SERIAL_ECHOPGM(") = ");
SERIAL_ECHO_F(z0, 6); SERIAL_ECHO_F(z0, 6);
} }
@ -291,11 +308,11 @@
#if ENABLED(DEBUG_LEVELING_FEATURE) #if ENABLED(DEBUG_LEVELING_FEATURE)
if (DEBUGGING(MESH_ADJUST)) { if (DEBUGGING(MESH_ADJUST)) {
SERIAL_ECHOPGM("??? Yikes! NAN in get_z_correction( "); SERIAL_ECHOPAIR("??? Yikes! NAN in get_z_correction(", x0);
SERIAL_ECHO(x0); SERIAL_CHAR(',');
SERIAL_ECHOPGM(", ");
SERIAL_ECHO(y0); SERIAL_ECHO(y0);
SERIAL_ECHOLNPGM(" )"); SERIAL_CHAR(')');
SERIAL_EOL;
} }
#endif #endif
} }
@ -313,7 +330,7 @@
*/ */
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #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); const float rz = RAW_Z_POSITION(lz);
if (last_specified_z != rz) { if (last_specified_z != rz) {
last_specified_z = rz; last_specified_z = rz;

@ -27,7 +27,6 @@
#include "UBL.h" #include "UBL.h"
#include "hex_print_routines.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 * 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 * '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. * moved back inside the bed leveling class.
*/ */
float last_specified_z, float mesh_index_to_x_location[UBL_MESH_NUM_X_POINTS + 1], // +1 just because of paranoia that we might end up on the
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
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 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() { unified_bed_leveling::unified_bed_leveling() {
@ -96,7 +92,7 @@
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT) #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
/** /**
* These lines can go away in a few weeks. They are just * 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 * an incomplete Bed_Leveling.state structure. For speed
* we now multiply by the inverse of the Fade Height instead of * we now multiply by the inverse of the Fade Height instead of
* dividing by it. Soon... all of the old structures will be * 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) { 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) { if (m == -1) {
SERIAL_PROTOCOLLNPGM("?No mesh saved in EEPROM. Zeroing mesh in memory.\n"); SERIAL_PROTOCOLLNPGM("?No mesh saved in EEPROM. Zeroing mesh in memory.\n");
@ -119,7 +115,7 @@
return; 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"); SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
return; return;
} }
@ -132,9 +128,9 @@
} }
void unified_bed_leveling::store_mesh(const int16_t m) { 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_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
SERIAL_PROTOCOL(m); SERIAL_PROTOCOL(m);
SERIAL_PROTOCOLLNPGM(" mesh slots available.\n"); SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
@ -202,9 +198,8 @@
for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) { for (uint8_t i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
const bool is_current = i == current_xi && j == current_yi; const bool is_current = i == current_xi && j == current_yi;
// is the nozzle here? if so, mark the number // is the nozzle here? then mark the number
if (map0) if (map0) SERIAL_CHAR(is_current ? '[' : ' ');
SERIAL_CHAR(is_current ? '[' : ' ');
const float f = z_values[i][j]; const float f = z_values[i][j];
if (isnan(f)) { if (isnan(f)) {
@ -212,12 +207,11 @@
} }
else { else {
// if we don't do this, the columns won't line up nicely // 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); SERIAL_PROTOCOL_F(f, 3);
idle(); idle();
} }
if (!map0 && i < UBL_MESH_NUM_X_POINTS - 1) if (!map0 && i < UBL_MESH_NUM_X_POINTS - 1) SERIAL_CHAR(',');
SERIAL_CHAR(',');
#if TX_BUFFER_SIZE > 0 #if TX_BUFFER_SIZE > 0
MYSERIAL.flushTX(); MYSERIAL.flushTX();
@ -256,43 +250,36 @@
SERIAL_PROTOCOLLNPGM("?UBL_MESH_NUM_X_POINTS set wrong\n"); SERIAL_PROTOCOLLNPGM("?UBL_MESH_NUM_X_POINTS set wrong\n");
error_flag++; error_flag++;
} }
if (state.n_y != UBL_MESH_NUM_Y_POINTS) { if (state.n_y != UBL_MESH_NUM_Y_POINTS) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_NUM_Y_POINTS set wrong\n"); SERIAL_PROTOCOLLNPGM("?UBL_MESH_NUM_Y_POINTS set wrong\n");
error_flag++; error_flag++;
} }
if (state.mesh_x_min != UBL_MESH_MIN_X) { if (state.mesh_x_min != UBL_MESH_MIN_X) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_X set wrong\n"); SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_X set wrong\n");
error_flag++; error_flag++;
} }
if (state.mesh_y_min != UBL_MESH_MIN_Y) { if (state.mesh_y_min != UBL_MESH_MIN_Y) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_Y set wrong\n"); SERIAL_PROTOCOLLNPGM("?UBL_MESH_MIN_Y set wrong\n");
error_flag++; error_flag++;
} }
if (state.mesh_x_max != UBL_MESH_MAX_X) { if (state.mesh_x_max != UBL_MESH_MAX_X) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_X set wrong\n"); SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_X set wrong\n");
error_flag++; error_flag++;
} }
if (state.mesh_y_max != UBL_MESH_MAX_Y) { if (state.mesh_y_max != UBL_MESH_MAX_Y) {
SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_Y set wrong\n"); SERIAL_PROTOCOLLNPGM("?UBL_MESH_MAX_Y set wrong\n");
error_flag++; error_flag++;
} }
if (state.mesh_x_dist != MESH_X_DIST) { if (state.mesh_x_dist != MESH_X_DIST) {
SERIAL_PROTOCOLLNPGM("?MESH_X_DIST set wrong\n"); SERIAL_PROTOCOLLNPGM("?MESH_X_DIST set wrong\n");
error_flag++; error_flag++;
} }
if (state.mesh_y_dist != MESH_Y_DIST) { if (state.mesh_y_dist != MESH_Y_DIST) {
SERIAL_PROTOCOLLNPGM("?MESH_Y_DIST set wrong\n"); SERIAL_PROTOCOLLNPGM("?MESH_Y_DIST set wrong\n");
error_flag++; 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) { if (j < 1) {
SERIAL_PROTOCOLLNPGM("?No EEPROM storage available for a mesh of this size.\n"); SERIAL_PROTOCOLLNPGM("?No EEPROM storage available for a mesh of this size.\n");
error_flag++; error_flag++;

@ -65,8 +65,6 @@
#define SIZE_OF_LITTLE_RAISE 0 #define SIZE_OF_LITTLE_RAISE 0
#define BIG_RAISE_NOT_NEEDED 0 #define BIG_RAISE_NOT_NEEDED 0
extern void lcd_quick_feedback(); 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 * 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 * 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 * 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 * 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 * 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 * 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!) * 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 * 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. * 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. // 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, static int g29_verbose_level, phase_value = -1, repetition_cnt,
storage_slot = 0, map_type; //unlevel_value = -1; storage_slot = 0, map_type; //unlevel_value = -1;
@ -318,8 +312,8 @@
#endif #endif
void gcode_G29() { void gcode_G29() {
SERIAL_PROTOCOLLNPAIR("ubl_eeprom_start=", ubl_eeprom_start); SERIAL_PROTOCOLLNPAIR("ubl.eeprom_start=", ubl.eeprom_start);
if (ubl_eeprom_start < 0) { if (ubl.eeprom_start < 0) {
SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it"); SERIAL_PROTOCOLLNPGM("?You need to enable your EEPROM and initialize it");
SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n"); SERIAL_PROTOCOLLNPGM("with M502, M500, M501 in that order.\n");
return; return;
@ -340,7 +334,7 @@
SERIAL_PROTOCOLLNPGM("Entire Mesh invalidated.\n"); SERIAL_PROTOCOLLNPGM("Entire Mesh invalidated.\n");
break; // No more invalid Mesh Points to populate 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"); 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. 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, const float p1 = 0.5 * (UBL_MESH_NUM_X_POINTS) - x,
p2 = 0.5 * (UBL_MESH_NUM_Y_POINTS) - y; 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; break;
case 1: 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 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; ubl.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 + (x < UBL_MESH_NUM_Y_POINTS - 1) ? 1 : -1] += 9.999; // We want the altered line several mesh points thick
} }
break; break;
case 2: case 2:
// Allow the user to specify the height because 10mm is a little extreme in some cases. // 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 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 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; break;
} }
} }
@ -395,17 +389,18 @@
return; return;
} }
switch (phase_value) { switch (phase_value) {
case 0:
// //
// Zero Mesh Data // Zero Mesh Data
// //
case 0:
ubl.reset(); ubl.reset();
SERIAL_PROTOCOLLNPGM("Mesh zeroed.\n"); SERIAL_PROTOCOLLNPGM("Mesh zeroed.\n");
break; break;
case 1:
// //
// Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe // Invalidate Entire Mesh and Automatically Probe Mesh in areas that can be reached by the probe
// //
case 1:
if (!code_seen('C') ) { if (!code_seen('C') ) {
ubl.invalidate(); ubl.invalidate();
SERIAL_PROTOCOLLNPGM("Mesh invalidated. Probing mesh.\n"); 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, 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')); code_seen('O') || code_seen('M'), code_seen('E'), code_seen('U'));
break; break;
case 2: {
// //
// Manually Probe Mesh in areas that can't be reached by the probe // Manually Probe Mesh in areas that can't be reached by the probe
// //
case 2: {
SERIAL_PROTOCOLLNPGM("Manually probing unreachable mesh locations.\n"); SERIAL_PROTOCOLLNPGM("Manually probing unreachable mesh locations.\n");
do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES);
if (!x_flag && !y_flag) { // use a good default location for the path if (!x_flag && !y_flag) { // use a good default location for the path
@ -455,24 +451,24 @@
} break; } break;
case 3: {
// //
// Populate invalid Mesh areas with a constant // Populate invalid Mesh areas with a constant
// //
case 3: {
const float height = code_seen('C') ? ubl_constant : 0.0; const float height = code_seen('C') ? ubl_constant : 0.0;
// If no repetition is specified, do the whole Mesh // If no repetition is specified, do the whole Mesh
if (!repeat_flag) repetition_cnt = 9999; if (!repeat_flag) repetition_cnt = 9999;
while (repetition_cnt--) { 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 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 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; } 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')); fine_tune_mesh(x_pos, y_pos, code_seen('O') || code_seen('M'));
break; break;
case 5: case 5:
@ -487,16 +483,16 @@
SERIAL_ECHO_START; SERIAL_ECHO_START;
SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:"); SERIAL_ECHOLNPGM("Checking G29 has control of LCD Panel:");
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
ubl_has_control_of_lcd_panel++; ubl.has_control_of_lcd_panel++;
while (!ubl_lcd_clicked()) { while (!ubl_lcd_clicked()) {
safe_delay(250); safe_delay(250);
if (ubl_encoderDiff) { if (ubl.encoder_diff) {
SERIAL_ECHOLN((int)ubl_encoderDiff); SERIAL_ECHOLN((int)ubl.encoder_diff);
ubl_encoderDiff = 0; ubl.encoder_diff = 0;
} }
} }
SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel."); 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); KEEPALIVE_STATE(IN_HANDLER);
break; break;
@ -508,9 +504,9 @@
wait_for_user = true; wait_for_user = true;
while (wait_for_user) { while (wait_for_user) {
safe_delay(250); safe_delay(250);
if (ubl_encoderDiff) { if (ubl.encoder_diff) {
SERIAL_ECHOLN((int)ubl_encoderDiff); SERIAL_ECHOLN((int)ubl.encoder_diff);
ubl_encoderDiff = 0; ubl.encoder_diff = 0;
} }
} }
SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel."); SERIAL_ECHOLNPGM("G29 giving back control of LCD Panel.");
@ -562,9 +558,9 @@
if (code_seen('L')) { // Load Current Mesh Data if (code_seen('L')) { // Load Current Mesh Data
storage_slot = code_has_value() ? code_value_int() : ubl.state.eeprom_storage_slot; 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"); SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return; return;
} }
@ -586,19 +582,19 @@
SERIAL_ECHOLNPGM("G29 I 999"); // host in a form it can be reconstructed on a different machine 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 x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) 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("M421 I ", x);
SERIAL_ECHOPAIR(" J ", y); SERIAL_ECHOPAIR(" J ", y);
SERIAL_ECHOPGM(" Z "); SERIAL_ECHOPGM(" Z ");
SERIAL_ECHO_F(z_values[x][y], 6); SERIAL_ECHO_F(ubl.z_values[x][y], 6);
SERIAL_EOL; SERIAL_EOL;
} }
return; 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_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1); SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
goto LEAVE; goto LEAVE;
@ -622,7 +618,7 @@
save_ubl_active_state_and_disable(); 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); //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; 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 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 // 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); do_blocking_move_to_z(measured_z);
} while (!ubl_lcd_clicked()); } 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) // 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, // or here. So, until we are done looking for a long Encoder Wheel Press,
// we need to take control of the panel // we need to take control of the panel
@ -658,7 +654,7 @@
goto LEAVE; 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. safe_delay(20); // We don't want any switch noise.
ubl.state.z_offset = measured_z; ubl.state.z_offset = measured_z;
@ -675,7 +671,7 @@
lcd_quick_feedback(); lcd_quick_feedback();
#endif #endif
ubl_has_control_of_lcd_panel = false; ubl.has_control_of_lcd_panel = false;
} }
void find_mean_mesh_height() { void find_mean_mesh_height() {
@ -687,8 +683,8 @@
n = 0; n = 0;
for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++) for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y])) { if (!isnan(ubl.z_values[x][y])) {
sum += z_values[x][y]; sum += ubl.z_values[x][y];
n++; n++;
} }
@ -699,8 +695,8 @@
// //
for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++) for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y])) { if (!isnan(ubl.z_values[x][y])) {
difference = (z_values[x][y] - mean); difference = (ubl.z_values[x][y] - mean);
sum_of_diff_squared += difference * difference; sum_of_diff_squared += difference * difference;
} }
@ -717,15 +713,15 @@
if (c_flag) if (c_flag)
for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++) for (x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) for (y = 0; y < UBL_MESH_NUM_Y_POINTS; y++)
if (!isnan(z_values[x][y])) if (!isnan(ubl.z_values[x][y]))
z_values[x][y] -= mean + ubl_constant; ubl.z_values[x][y] -= mean + ubl_constant;
} }
void shift_mesh_height() { void shift_mesh_height() {
for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++) for (uint8_t x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) 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]))
z_values[x][y] += ubl_constant; 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) { 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; 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 save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe
DEPLOY_PROBE(); DEPLOY_PROBE();
@ -745,7 +741,7 @@
lcd_quick_feedback(); lcd_quick_feedback();
STOW_PROBE(); STOW_PROBE();
while (ubl_lcd_clicked()) idle(); 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(); restore_ubl_active_state_and_leave();
safe_delay(50); // Debounce the Encoder wheel safe_delay(50); // Debounce the Encoder wheel
return; return;
@ -761,11 +757,11 @@
if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) { if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to probe off the bed."); SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
ubl_has_control_of_lcd_panel = false; ubl.has_control_of_lcd_panel = false;
goto LEAVE; goto LEAVE;
} }
const float measured_z = probe_pt(LOGICAL_X_POSITION(rawx), LOGICAL_Y_POSITION(rawy), stow_probe, g29_verbose_level); 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); 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 (i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
for (j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) { 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); 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; return normal;
@ -852,9 +848,9 @@
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here! while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
idle(); idle();
if (ubl_encoderDiff) { if (ubl.encoder_diff) {
do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(ubl_encoderDiff)); do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(ubl.encoder_diff));
ubl_encoderDiff = 0; ubl.encoder_diff = 0;
} }
} }
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
@ -863,7 +859,7 @@
float measure_business_card_thickness(const float &in_height) { 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 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."); SERIAL_PROTOCOLLNPGM("Place Shim Under Nozzle and Perform Measurement.");
@ -873,7 +869,7 @@
const float z1 = use_encoder_wheel_to_measure_point(); const float z1 = use_encoder_wheel_to_measure_point();
do_blocking_move_to_z(current_position[Z_AXIS] + SIZE_OF_LITTLE_RAISE); 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."); SERIAL_PROTOCOLLNPGM("Remove Shim and Measure Bed Height.");
const float z2 = use_encoder_wheel_to_measure_point(); 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) { 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 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_z(z_clearance);
do_blocking_move_to_xy(lx, ly); 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)) { if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to probe off the bed."); SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
ubl_has_control_of_lcd_panel = false; ubl.has_control_of_lcd_panel = false;
goto LEAVE; goto LEAVE;
} }
@ -931,13 +927,13 @@
last_y = yProbe; last_y = yProbe;
KEEPALIVE_STATE(PAUSED_FOR_USER); 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! while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here!
idle(); idle();
if (ubl_encoderDiff) { if (ubl.encoder_diff) {
do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl_encoderDiff) / 100.0); do_blocking_move_to_z(current_position[Z_AXIS] + float(ubl.encoder_diff) / 100.0);
ubl_encoderDiff = 0; ubl.encoder_diff = 0;
} }
} }
@ -949,17 +945,17 @@
do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE); do_blocking_move_to_z(Z_CLEARANCE_DEPLOY_PROBE);
lcd_quick_feedback(); lcd_quick_feedback();
while (ubl_lcd_clicked()) idle(); while (ubl_lcd_clicked()) idle();
ubl_has_control_of_lcd_panel = false; ubl.has_control_of_lcd_panel = false;
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
restore_ubl_active_state_and_leave(); restore_ubl_active_state_and_leave();
return; 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) { if (g29_verbose_level > 2) {
SERIAL_PROTOCOLPGM("Mesh Point Measured at: "); 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; SERIAL_EOL;
} }
} while (location.x_index >= 0 && location.y_index >= 0); } 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 * good to have the extra information. Soon... we prune this to just a few items
*/ */
void g29_what_command() { 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 "); SERIAL_PROTOCOLPGM("Unified Bed Leveling System Version 1.00 ");
if (ubl.state.active) if (ubl.state.active)
@ -1167,21 +1163,21 @@
SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk); SERIAL_PROTOCOLLNPAIR("ubl_state_recursion_chk :", ubl_state_recursion_chk);
SERIAL_EOL; SERIAL_EOL;
safe_delay(50); 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); safe_delay(50);
SERIAL_PROTOCOLLNPAIR("sizeof(ubl) : ", (int)sizeof(ubl)); SERIAL_PROTOCOLLNPAIR("sizeof(ubl) : ", (int)sizeof(ubl));
SERIAL_EOL; SERIAL_EOL;
SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(z_values)); SERIAL_PROTOCOLLNPAIR("z_value[][] size: ", (int)sizeof(ubl.z_values));
SERIAL_EOL; SERIAL_EOL;
safe_delay(50); safe_delay(50);
SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: 0x", hex_word(k)); SERIAL_PROTOCOLLNPAIR("EEPROM free for UBL: 0x", hex_word(k));
safe_delay(50); 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"); SERIAL_PROTOCOLLNPGM(" meshes.\n");
safe_delay(50); safe_delay(50);
@ -1245,9 +1241,9 @@
} }
storage_slot = code_value_int(); 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"); SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return; return;
} }
@ -1256,12 +1252,12 @@
eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values)); eeprom_read_block((void *)&tmp_z_values, (void *)j, sizeof(tmp_z_values));
SERIAL_ECHOPAIR("Subtracting Mesh ", storage_slot); 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. // 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 x = 0; x < UBL_MESH_NUM_X_POINTS; x++)
for (uint8_t y = 0; y < UBL_MESH_NUM_Y_POINTS; y++) 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) { 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 i = 0; i < UBL_MESH_NUM_X_POINTS; i++) {
for (uint8_t j = 0; j < UBL_MESH_NUM_Y_POINTS; j++) { 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 if ( (type == INVALID && isnan(ubl.z_values[i][j])) // Check to see if this location holds the right thing
|| (type == REAL && !isnan(z_values[i][j])) || (type == REAL && !isnan(ubl.z_values[i][j]))
|| (type == SET_IN_BITMAP && is_bit_set(bits, 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 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 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 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. distance += sq(i - k) * (MESH_X_DIST) * .05 // point we can find.
+ sq(j - l) * (MESH_Y_DIST) * .05; + 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. 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_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now 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; 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_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)); 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 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; new_z = float(round_off) / 1000.0;
KEEPALIVE_STATE(PAUSED_FOR_USER); KEEPALIVE_STATE(PAUSED_FOR_USER);
ubl_has_control_of_lcd_panel = true; ubl.has_control_of_lcd_panel = true;
lcd_implementation_clear(); lcd_implementation_clear();
lcd_mesh_edit_setup(new_z); lcd_mesh_edit_setup(new_z);
@ -1385,7 +1381,7 @@
lcd_return_to_status(); 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) // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune)
// or here. // or here.
@ -1406,7 +1402,7 @@
safe_delay(20); // We don't want any switch noise. 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(); lcd_implementation_clear();
@ -1414,7 +1410,7 @@
FINE_TUNE_EXIT: FINE_TUNE_EXIT:
ubl_has_control_of_lcd_panel = false; ubl.has_control_of_lcd_panel = false;
KEEPALIVE_STATE(IN_HANDLER); KEEPALIVE_STATE(IN_HANDLER);
if (do_ubl_mesh_map) ubl.display_map(map_type); if (do_ubl_mesh_map) ubl.display_map(map_type);

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

@ -166,7 +166,6 @@
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
#include "UBL.h" #include "UBL.h"
int ubl_eeprom_start = -1;
#endif #endif
#if ENABLED(ABL_BILINEAR_SUBDIVISION) #if ENABLED(ABL_BILINEAR_SUBDIVISION)
@ -847,7 +846,7 @@ void Config_Postprocess() {
} }
#if ENABLED(AUTO_BED_LEVELING_UBL) #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 // can float up or down a little bit without
// disrupting the Unified Bed Leveling data // disrupting the Unified Bed Leveling data
ubl.load_state(); ubl.load_state();
@ -1233,7 +1232,7 @@ void Config_ResetDefault() {
SERIAL_ECHO_F(ubl.state.z_offset, 6); SERIAL_ECHO_F(ubl.state.z_offset, 6);
SERIAL_EOL; 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(" meshes.\n");
SERIAL_ECHOLNPGM("UBL_MESH_NUM_X_POINTS " STRINGIFY(UBL_MESH_NUM_X_POINTS)); 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; int32_t lastEncoderMovementMillis;
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
extern bool ubl_has_control_of_lcd_panel; #include "UBL.h"
extern int8_t ubl_encoderDiff;
#endif #endif
#if HAS_POWER_SWITCH #if HAS_POWER_SWITCH
@ -860,9 +859,9 @@ void kill_screen(const char* lcd_msg) {
static void _lcd_mesh_fine_tune(const char* msg) { static void _lcd_mesh_fine_tune(const char* msg) {
defer_return_to_status = true; defer_return_to_status = true;
if (ubl_encoderDiff) { if (ubl.encoder_diff) {
ubl_encoderPosition = (ubl_encoderDiff > 0) ? 1 : -1; ubl_encoderPosition = (ubl.encoder_diff > 0) ? 1 : -1;
ubl_encoderDiff = 0; ubl.encoder_diff = 0;
mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0; mesh_edit_accumulator += float(ubl_encoderPosition) * 0.005 / 2.0;
mesh_edit_value = mesh_edit_accumulator; mesh_edit_value = mesh_edit_accumulator;
@ -3206,7 +3205,7 @@ void lcd_update() {
lcd_buttons_update(); lcd_buttons_update();
#if ENABLED(AUTO_BED_LEVELING_UBL) #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 #else
constexpr bool UBL_CONDITION = true; constexpr bool UBL_CONDITION = true;
#endif #endif
@ -3622,8 +3621,8 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; }
case encrot3: ENCODER_SPIN(encrot2, encrot0); break; case encrot3: ENCODER_SPIN(encrot2, encrot0); break;
} }
#if ENABLED(AUTO_BED_LEVELING_UBL) #if ENABLED(AUTO_BED_LEVELING_UBL)
if (ubl_has_control_of_lcd_panel) { if (ubl.has_control_of_lcd_panel) {
ubl_encoderDiff = encoderDiff; // Make the encoder's rotation available to G29's Mesh Editor 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 encoderDiff = 0; // We are going to lie to the LCD Panel and claim the encoder
// wheel has not turned. // wheel has not turned.
} }

Loading…
Cancel
Save