♻️ Common Bed Leveling object name, accessors (#24214)
This commit is contained in:
@@ -63,11 +63,9 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
|
||||
struct linear_fit_data lsf_results;
|
||||
incremental_LSF_reset(&lsf_results);
|
||||
GRID_LOOP(x, y) {
|
||||
if (!isnan(Z_VALUES_ARR[x][y])) {
|
||||
xy_pos_t rpos;
|
||||
rpos.x = ubl.mesh_index_to_xpos(x);
|
||||
rpos.y = ubl.mesh_index_to_ypos(y);
|
||||
incremental_LSF(&lsf_results, rpos, Z_VALUES_ARR[x][y]);
|
||||
if (!isnan(bedlevel.z_values[x][y])) {
|
||||
xy_pos_t rpos = { bedlevel.get_mesh_x(x), bedlevel.get_mesh_y(y) };
|
||||
incremental_LSF(&lsf_results, rpos, bedlevel.z_values[x][y]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,13 +74,13 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
|
||||
return true;
|
||||
}
|
||||
|
||||
ubl.set_all_mesh_points_to_value(0);
|
||||
bedlevel.set_all_mesh_points_to_value(0);
|
||||
|
||||
matrix_3x3 rotation = matrix_3x3::create_look_at(vector_3(lsf_results.A, lsf_results.B, 1));
|
||||
GRID_LOOP(i, j) {
|
||||
float mx = ubl.mesh_index_to_xpos(i),
|
||||
my = ubl.mesh_index_to_ypos(j),
|
||||
mz = Z_VALUES_ARR[i][j];
|
||||
float mx = bedlevel.get_mesh_x(i),
|
||||
my = bedlevel.get_mesh_y(j),
|
||||
mz = bedlevel.z_values[i][j];
|
||||
|
||||
if (DEBUGGING(LEVELING)) {
|
||||
DEBUG_ECHOPAIR_F("before rotation = [", mx, 7);
|
||||
@@ -106,7 +104,7 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
|
||||
DEBUG_DELAY(20);
|
||||
}
|
||||
|
||||
Z_VALUES_ARR[i][j] = mz - lsf_results.D;
|
||||
bedlevel.z_values[i][j] = mz - lsf_results.D;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -124,7 +122,7 @@ char cmd[MAX_CMD_SIZE+16], str_1[16], str_2[16], str_3[16];
|
||||
void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y, bool zmove/*=false*/) {
|
||||
if (zmove) {
|
||||
planner.synchronize();
|
||||
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
|
||||
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
|
||||
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
|
||||
planner.synchronize();
|
||||
}
|
||||
@@ -136,7 +134,7 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
|
||||
sprintf_P(cmd, PSTR("G42 F4000 I%i J%i"), mesh_x, mesh_y);
|
||||
gcode.process_subcommands_now(cmd);
|
||||
planner.synchronize();
|
||||
current_position.z = goto_mesh_value ? Z_VALUES_ARR[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
|
||||
current_position.z = goto_mesh_value ? bedlevel.z_values[mesh_x][mesh_y] : Z_CLEARANCE_BETWEEN_PROBES;
|
||||
planner.buffer_line(current_position, homing_feedrate(Z_AXIS), active_extruder);
|
||||
planner.synchronize();
|
||||
HMI_ReturnScreen();
|
||||
@@ -146,8 +144,8 @@ void UBLMeshToolsClass::manual_move(const uint8_t mesh_x, const uint8_t mesh_y,
|
||||
float UBLMeshToolsClass::get_max_value() {
|
||||
float max = __FLT_MIN__;
|
||||
GRID_LOOP(x, y) {
|
||||
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] > max)
|
||||
max = Z_VALUES_ARR[x][y];
|
||||
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] > max)
|
||||
max = bedlevel.z_values[x][y];
|
||||
}
|
||||
return max;
|
||||
}
|
||||
@@ -155,20 +153,19 @@ float UBLMeshToolsClass::get_max_value() {
|
||||
float UBLMeshToolsClass::get_min_value() {
|
||||
float min = __FLT_MAX__;
|
||||
GRID_LOOP(x, y) {
|
||||
if (!isnan(Z_VALUES_ARR[x][y]) && Z_VALUES_ARR[x][y] < min)
|
||||
min = Z_VALUES_ARR[x][y];
|
||||
if (!isnan(bedlevel.z_values[x][y]) && bedlevel.z_values[x][y] < min)
|
||||
min = bedlevel.z_values[x][y];
|
||||
}
|
||||
return min;
|
||||
}
|
||||
|
||||
bool UBLMeshToolsClass::validate() {
|
||||
float min = __FLT_MAX__;
|
||||
float max = __FLT_MIN__;
|
||||
float min = __FLT_MAX__, max = __FLT_MIN__;
|
||||
|
||||
GRID_LOOP(x, y) {
|
||||
if (isnan(Z_VALUES_ARR[x][y])) return false;
|
||||
if (Z_VALUES_ARR[x][y] < min) min = Z_VALUES_ARR[x][y];
|
||||
if (Z_VALUES_ARR[x][y] > max) max = Z_VALUES_ARR[x][y];
|
||||
if (isnan(bedlevel.z_values[x][y])) return false;
|
||||
if (bedlevel.z_values[x][y] < min) min = bedlevel.z_values[x][y];
|
||||
if (bedlevel.z_values[x][y] > max) max = bedlevel.z_values[x][y];
|
||||
}
|
||||
return max <= UBL_Z_OFFSET_MAX && min >= UBL_Z_OFFSET_MIN;
|
||||
}
|
||||
@@ -177,15 +174,15 @@ bool UBLMeshToolsClass::validate() {
|
||||
void UBLMeshToolsClass::Draw_Bed_Mesh(int16_t selected /*= -1*/, uint8_t gridline_width /*= 1*/, uint16_t padding_x /*= 8*/, uint16_t padding_y_top /*= 40 + 53 - 7*/) {
|
||||
drawing_mesh = true;
|
||||
const uint16_t total_width_px = DWIN_WIDTH - padding_x - padding_x;
|
||||
const uint16_t cell_width_px = total_width_px / GRID_MAX_POINTS_X;
|
||||
const uint16_t cell_height_px = total_width_px / GRID_MAX_POINTS_Y;
|
||||
const uint16_t cell_width_px = total_width_px / (GRID_MAX_POINTS_X);
|
||||
const uint16_t cell_height_px = total_width_px / (GRID_MAX_POINTS_Y);
|
||||
const float v_max = abs(get_max_value()), v_min = abs(get_min_value()), range = _MAX(v_min, v_max);
|
||||
|
||||
// Clear background from previous selection and select new square
|
||||
DWIN_Draw_Rectangle(1, Color_Bg_Black, _MAX(0, padding_x - gridline_width), _MAX(0, padding_y_top - gridline_width), padding_x + total_width_px, padding_y_top + total_width_px);
|
||||
if (selected >= 0) {
|
||||
const auto selected_y = selected / GRID_MAX_POINTS_X;
|
||||
const auto selected_x = selected - (GRID_MAX_POINTS_X * selected_y);
|
||||
const auto selected_y = selected / (GRID_MAX_POINTS_X);
|
||||
const auto selected_x = selected - (GRID_MAX_POINTS_X) * selected_y;
|
||||
const auto start_y_px = padding_y_top + selected_y * cell_height_px;
|
||||
const auto start_x_px = padding_x + selected_x * cell_width_px;
|
||||
DWIN_Draw_Rectangle(1, Color_White, _MAX(0, start_x_px - gridline_width), _MAX(0, start_y_px - gridline_width), start_x_px + cell_width_px, start_y_px + cell_height_px);
|
||||
@@ -196,14 +193,14 @@ bool UBLMeshToolsClass::validate() {
|
||||
GRID_LOOP(x, y) {
|
||||
const auto start_x_px = padding_x + x * cell_width_px;
|
||||
const auto end_x_px = start_x_px + cell_width_px - 1 - gridline_width;
|
||||
const auto start_y_px = padding_y_top + (GRID_MAX_POINTS_Y - y - 1) * cell_height_px;
|
||||
const auto start_y_px = padding_y_top + ((GRID_MAX_POINTS_Y) - y - 1) * cell_height_px;
|
||||
const auto end_y_px = start_y_px + cell_height_px - 1 - gridline_width;
|
||||
DWIN_Draw_Rectangle(1, // RGB565 colors: http://www.barth-dev.de/online/rgb565-color-picker/
|
||||
isnan(Z_VALUES_ARR[x][y]) ? Color_Grey : ( // gray if undefined
|
||||
(Z_VALUES_ARR[x][y] < 0 ?
|
||||
(uint16_t)round(0x1F * -Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
|
||||
(uint16_t)round(0x3F * Z_VALUES_ARR[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
|
||||
_MIN(0x1F, (((uint8_t)abs(Z_VALUES_ARR[x][y]) / 10) * 4))), // + blue stepping for every mm
|
||||
isnan(bedlevel.z_values[x][y]) ? Color_Grey : ( // gray if undefined
|
||||
(bedlevel.z_values[x][y] < 0 ?
|
||||
(uint16_t)round(0x1F * -bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_min)) << 11 : // red if mesh point value is negative
|
||||
(uint16_t)round(0x3F * bedlevel.z_values[x][y] / (!viewer_asymmetric_range ? range : v_max)) << 5) | // green if mesh point value is positive
|
||||
_MIN(0x1F, (((uint8_t)abs(bedlevel.z_values[x][y]) / 10) * 4))), // + blue stepping for every mm
|
||||
start_x_px, start_y_px, end_x_px, end_y_px
|
||||
);
|
||||
|
||||
@@ -213,14 +210,14 @@ bool UBLMeshToolsClass::validate() {
|
||||
// Draw value text on
|
||||
if (viewer_print_value) {
|
||||
int8_t offset_x, offset_y = cell_height_px / 2 - 6;
|
||||
if (isnan(Z_VALUES_ARR[x][y])) { // undefined
|
||||
if (isnan(bedlevel.z_values[x][y])) { // undefined
|
||||
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px + cell_width_px / 2 - 5, start_y_px + offset_y, F("X"));
|
||||
}
|
||||
else { // has value
|
||||
if (GRID_MAX_POINTS_X < 10)
|
||||
sprintf_P(buf, PSTR("%s"), dtostrf(abs(Z_VALUES_ARR[x][y]), 1, 2, str_1));
|
||||
sprintf_P(buf, PSTR("%s"), dtostrf(abs(bedlevel.z_values[x][y]), 1, 2, str_1));
|
||||
else
|
||||
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(Z_VALUES_ARR[x][y] - (int16_t)Z_VALUES_ARR[x][y]) * 100));
|
||||
sprintf_P(buf, PSTR("%02i"), (uint16_t)(abs(bedlevel.z_values[x][y] - (int16_t)bedlevel.z_values[x][y]) * 100));
|
||||
offset_x = cell_width_px / 2 - 3 * (strlen(buf)) - 2;
|
||||
if (!(GRID_MAX_POINTS_X < 10))
|
||||
DWIN_Draw_String(false, font6x12, Color_White, Color_Bg_Blue, start_x_px - 2 + offset_x, start_y_px + offset_y /*+ square / 2 - 6*/, F("."));
|
||||
|
||||
Reference in New Issue
Block a user