Additional cleanup of UBL code
This commit is contained in:
parent
cc3204509c
commit
e244399766
35 changed files with 2201 additions and 2070 deletions
|
|
@ -28,52 +28,59 @@
|
|||
#include "hex_print_routines.h"
|
||||
|
||||
/**
|
||||
* These variables used to be declared inside the bed_leveling class. We are going to still declare
|
||||
* them within the .cpp file for bed leveling. But there is only one instance of the bed leveling
|
||||
* object and we can get rid of a level of inderection by not making them 'member data'. So, in the
|
||||
* interest of speed, we do it this way. When we move to a 32-Bit processor, they can be moved
|
||||
* back inside the bed leveling class.
|
||||
* These variables used to be declared inside the unified_bed_leveling class. We are going to
|
||||
* still declare them within the .cpp file for bed leveling. But there is only one instance of
|
||||
* the bed leveling object and we can get rid of a level of inderection by not making them
|
||||
* '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
|
||||
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_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
|
||||
|
||||
bed_leveling::bed_leveling() {
|
||||
unified_bed_leveling::unified_bed_leveling() {
|
||||
for (uint8_t i = 0; i <= UBL_MESH_NUM_X_POINTS; i++) // We go one past what we expect to ever need for safety
|
||||
mesh_index_to_X_location[i] = double(UBL_MESH_MIN_X) + double(MESH_X_DIST) * double(i);
|
||||
mesh_index_to_x_location[i] = double(UBL_MESH_MIN_X) + double(MESH_X_DIST) * double(i);
|
||||
|
||||
for (uint8_t i = 0; i <= UBL_MESH_NUM_Y_POINTS; i++) // We go one past what we expect to ever need for safety
|
||||
mesh_index_to_Y_location[i] = double(UBL_MESH_MIN_Y) + double(MESH_Y_DIST) * double(i);
|
||||
mesh_index_to_y_location[i] = double(UBL_MESH_MIN_Y) + double(MESH_Y_DIST) * double(i);
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
void bed_leveling::store_state() {
|
||||
int k = E2END - sizeof(blm.state);
|
||||
eeprom_write_block((void *)&blm.state, (void *)k, sizeof(blm.state));
|
||||
void unified_bed_leveling::store_state() {
|
||||
int k = E2END - sizeof(ubl.state);
|
||||
eeprom_write_block((void *)&ubl.state, (void *)k, sizeof(ubl.state));
|
||||
}
|
||||
|
||||
void bed_leveling::load_state() {
|
||||
int k = E2END - sizeof(blm.state);
|
||||
eeprom_read_block((void *)&blm.state, (void *)k, sizeof(blm.state));
|
||||
void unified_bed_leveling::load_state() {
|
||||
int k = E2END - sizeof(ubl.state);
|
||||
eeprom_read_block((void *)&ubl.state, (void *)k, sizeof(ubl.state));
|
||||
|
||||
if (sanity_check())
|
||||
SERIAL_PROTOCOLLNPGM("?In load_state() sanity_check() failed.\n");
|
||||
|
||||
// These lines can go away in a few weeks. They are just
|
||||
// to make sure people updating thier firmware won't be using
|
||||
if (blm.state.G29_Fade_Height_Multiplier != 1.0 / blm.state.G29_Correction_Fade_Height) { // an incomplete Bed_Leveling.state structure. For speed
|
||||
blm.state.G29_Fade_Height_Multiplier = 1.0 / blm.state.G29_Correction_Fade_Height; // we now multiply by the inverse of the Fade Height instead of
|
||||
store_state(); // dividing by it. Soon... all of the old structures will be
|
||||
} // updated, but until then, we try to ease the transition
|
||||
// for our Beta testers.
|
||||
/**
|
||||
* These lines can go away in a few weeks. They are just
|
||||
* to make sure people updating thier 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
|
||||
* updated, but until then, we try to ease the transition
|
||||
* for our Beta testers.
|
||||
*/
|
||||
if (ubl.state.g29_fade_height_multiplier != 1.0 / ubl.state.g29_correction_fade_height) {
|
||||
ubl.state.g29_fade_height_multiplier = 1.0 / ubl.state.g29_correction_fade_height;
|
||||
store_state();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void bed_leveling::load_mesh(int m) {
|
||||
int k = E2END - sizeof(blm.state),
|
||||
j = (k - Unified_Bed_Leveling_EEPROM_start) / sizeof(z_values);
|
||||
void unified_bed_leveling::load_mesh(int m) {
|
||||
int k = E2END - sizeof(ubl.state),
|
||||
j = (k - ubl_eeprom_start) / sizeof(z_values);
|
||||
|
||||
if (m == -1) {
|
||||
SERIAL_PROTOCOLLNPGM("?No mesh saved in EEPROM. Zeroing mesh in memory.\n");
|
||||
|
|
@ -81,7 +88,7 @@
|
|||
return;
|
||||
}
|
||||
|
||||
if (m < 0 || m >= j || Unified_Bed_Leveling_EEPROM_start <= 0) {
|
||||
if (m < 0 || m >= j || ubl_eeprom_start <= 0) {
|
||||
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
|
||||
return;
|
||||
}
|
||||
|
|
@ -96,11 +103,11 @@
|
|||
SERIAL_EOL;
|
||||
}
|
||||
|
||||
void bed_leveling:: store_mesh(int m) {
|
||||
void unified_bed_leveling:: store_mesh(int m) {
|
||||
int k = E2END - sizeof(state),
|
||||
j = (k - Unified_Bed_Leveling_EEPROM_start) / sizeof(z_values);
|
||||
j = (k - ubl_eeprom_start) / sizeof(z_values);
|
||||
|
||||
if (m < 0 || m >= j || Unified_Bed_Leveling_EEPROM_start <= 0) {
|
||||
if (m < 0 || m >= j || ubl_eeprom_start <= 0) {
|
||||
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
|
||||
SERIAL_PROTOCOL(m);
|
||||
SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");
|
||||
|
|
@ -122,18 +129,18 @@
|
|||
SERIAL_EOL;
|
||||
}
|
||||
|
||||
void bed_leveling::reset() {
|
||||
void unified_bed_leveling::reset() {
|
||||
state.active = false;
|
||||
state.z_offset = 0;
|
||||
state.EEPROM_storage_slot = -1;
|
||||
state.eeprom_storage_slot = -1;
|
||||
|
||||
ZERO(z_values);
|
||||
|
||||
last_specified_z = -999.9; // We can't pre-initialize these values in the declaration
|
||||
fade_scaling_factor_for_current_height = 0.0; // due to C++11 constraints
|
||||
last_specified_z = -999.9;
|
||||
fade_scaling_factor_for_current_height = 0.0;
|
||||
}
|
||||
|
||||
void bed_leveling::invalidate() {
|
||||
void unified_bed_leveling::invalidate() {
|
||||
prt_hex_word((unsigned int)this);
|
||||
SERIAL_EOL;
|
||||
|
||||
|
|
@ -144,7 +151,7 @@
|
|||
z_values[x][y] = NAN;
|
||||
}
|
||||
|
||||
void bed_leveling::display_map(int map_type) {
|
||||
void unified_bed_leveling::display_map(int map_type) {
|
||||
float f, current_xi, current_yi;
|
||||
int8_t i, j;
|
||||
UNUSED(map_type);
|
||||
|
|
@ -155,8 +162,8 @@
|
|||
SERIAL_ECHOPAIR(", ", UBL_MESH_NUM_Y_POINTS - 1);
|
||||
SERIAL_ECHOPGM(") ");
|
||||
|
||||
current_xi = blm.get_cell_index_x(current_position[X_AXIS] + (MESH_X_DIST) / 2.0);
|
||||
current_yi = blm.get_cell_index_y(current_position[Y_AXIS] + (MESH_Y_DIST) / 2.0);
|
||||
current_xi = ubl.get_cell_index_x(current_position[X_AXIS] + (MESH_X_DIST) / 2.0);
|
||||
current_yi = ubl.get_cell_index_y(current_position[Y_AXIS] + (MESH_Y_DIST) / 2.0);
|
||||
|
||||
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++)
|
||||
SERIAL_ECHOPGM(" ");
|
||||
|
|
@ -166,16 +173,18 @@
|
|||
SERIAL_ECHOLNPGM(")");
|
||||
|
||||
// if (map_type || 1) {
|
||||
SERIAL_ECHOPAIR("(", UBL_MESH_MIN_X);
|
||||
SERIAL_ECHOPAIR(",", UBL_MESH_MAX_Y);
|
||||
SERIAL_CHAR(')');
|
||||
|
||||
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++)
|
||||
SERIAL_ECHOPGM(" ");
|
||||
SERIAL_ECHOPAIR("(", UBL_MESH_MIN_X);
|
||||
SERIAL_ECHOPAIR(",", UBL_MESH_MAX_Y);
|
||||
SERIAL_CHAR(')');
|
||||
|
||||
for (i = 0; i < UBL_MESH_NUM_X_POINTS - 1; i++)
|
||||
SERIAL_ECHOPGM(" ");
|
||||
|
||||
SERIAL_ECHOPAIR("(", UBL_MESH_MAX_X);
|
||||
SERIAL_ECHOPAIR(",", UBL_MESH_MAX_Y);
|
||||
SERIAL_ECHOLNPGM(")");
|
||||
|
||||
SERIAL_ECHOPAIR("(", UBL_MESH_MAX_X);
|
||||
SERIAL_ECHOPAIR(",", UBL_MESH_MAX_Y);
|
||||
SERIAL_ECHOLNPGM(")");
|
||||
// }
|
||||
|
||||
for (j = UBL_MESH_NUM_Y_POINTS - 1; j >= 0; j--) {
|
||||
|
|
@ -235,51 +244,51 @@
|
|||
SERIAL_EOL;
|
||||
}
|
||||
|
||||
bool bed_leveling::sanity_check() {
|
||||
bool unified_bed_leveling::sanity_check() {
|
||||
uint8_t error_flag = 0;
|
||||
|
||||
if (state.n_x != UBL_MESH_NUM_X_POINTS) {
|
||||
if (state.n_x != UBL_MESH_NUM_X_POINTS) {
|
||||
SERIAL_PROTOCOLLNPGM("?UBL_MESH_NUM_X_POINTS set wrong\n");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
error_flag++;
|
||||
}
|
||||
|
||||
int k = E2END - sizeof(blm.state),
|
||||
j = (k - Unified_Bed_Leveling_EEPROM_start) / sizeof(z_values);
|
||||
const int k = E2END - sizeof(ubl.state),
|
||||
j = (k - ubl_eeprom_start) / sizeof(z_values);
|
||||
|
||||
if (j < 1) {
|
||||
SERIAL_PROTOCOLLNPGM("?No EEPROM storage available for a mesh of this size.\n");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue