1
0
mirror of https://github.com/MarlinFirmware/Marlin.git synced 2024-11-28 06:21:31 +00:00

Outdent UBL code

This commit is contained in:
Scott Lahteine 2021-02-23 16:09:54 -06:00 committed by Scott Lahteine
parent 8fca59f63b
commit dc0247c57e
3 changed files with 2044 additions and 2044 deletions

View File

@ -24,27 +24,27 @@
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "../bedlevel.h"
#include "../bedlevel.h"
unified_bed_leveling ubl;
unified_bed_leveling ubl;
#include "../../../MarlinCore.h"
#include "../../../gcode/gcode.h"
#include "../../../MarlinCore.h"
#include "../../../gcode/gcode.h"
#include "../../../module/settings.h"
#include "../../../module/planner.h"
#include "../../../module/motion.h"
#include "../../../module/probe.h"
#include "../../../module/settings.h"
#include "../../../module/planner.h"
#include "../../../module/motion.h"
#include "../../../module/probe.h"
#if ENABLED(EXTENSIBLE_UI)
#if ENABLED(EXTENSIBLE_UI)
#include "../../../lcd/extui/ui_api.h"
#endif
#endif
#include "math.h"
#include "math.h"
void unified_bed_leveling::echo_name() { SERIAL_ECHOPGM("Unified Bed Leveling"); }
void unified_bed_leveling::echo_name() { SERIAL_ECHOPGM("Unified Bed Leveling"); }
void unified_bed_leveling::report_current_mesh() {
void unified_bed_leveling::report_current_mesh() {
if (!leveling_is_valid()) return;
SERIAL_ECHO_MSG(" G29 I999");
GRID_LOOP(x, y)
@ -54,39 +54,39 @@
SERIAL_ECHOLNPAIR_F_P(SP_Z_STR, z_values[x][y], 4);
serial_delay(75); // Prevent Printrun from exploding
}
}
}
void unified_bed_leveling::report_state() {
void unified_bed_leveling::report_state() {
echo_name();
SERIAL_ECHO_TERNARY(planner.leveling_active, " System v" UBL_VERSION " ", "", "in", "active\n");
serial_delay(50);
}
}
int8_t unified_bed_leveling::storage_slot;
int8_t unified_bed_leveling::storage_slot;
float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y];
#define _GRIDPOS(A,N) (MESH_MIN_##A + N * (MESH_##A##_DIST))
#define _GRIDPOS(A,N) (MESH_MIN_##A + N * (MESH_##A##_DIST))
const float
unified_bed_leveling::_mesh_index_to_xpos[GRID_MAX_POINTS_X] PROGMEM = ARRAY_N(GRID_MAX_POINTS_X,
const float
unified_bed_leveling::_mesh_index_to_xpos[GRID_MAX_POINTS_X] PROGMEM = ARRAY_N(GRID_MAX_POINTS_X,
_GRIDPOS(X, 0), _GRIDPOS(X, 1), _GRIDPOS(X, 2), _GRIDPOS(X, 3),
_GRIDPOS(X, 4), _GRIDPOS(X, 5), _GRIDPOS(X, 6), _GRIDPOS(X, 7),
_GRIDPOS(X, 8), _GRIDPOS(X, 9), _GRIDPOS(X, 10), _GRIDPOS(X, 11),
_GRIDPOS(X, 12), _GRIDPOS(X, 13), _GRIDPOS(X, 14), _GRIDPOS(X, 15)
),
unified_bed_leveling::_mesh_index_to_ypos[GRID_MAX_POINTS_Y] PROGMEM = ARRAY_N(GRID_MAX_POINTS_Y,
),
unified_bed_leveling::_mesh_index_to_ypos[GRID_MAX_POINTS_Y] PROGMEM = ARRAY_N(GRID_MAX_POINTS_Y,
_GRIDPOS(Y, 0), _GRIDPOS(Y, 1), _GRIDPOS(Y, 2), _GRIDPOS(Y, 3),
_GRIDPOS(Y, 4), _GRIDPOS(Y, 5), _GRIDPOS(Y, 6), _GRIDPOS(Y, 7),
_GRIDPOS(Y, 8), _GRIDPOS(Y, 9), _GRIDPOS(Y, 10), _GRIDPOS(Y, 11),
_GRIDPOS(Y, 12), _GRIDPOS(Y, 13), _GRIDPOS(Y, 14), _GRIDPOS(Y, 15)
);
);
volatile int16_t unified_bed_leveling::encoder_diff;
volatile int16_t unified_bed_leveling::encoder_diff;
unified_bed_leveling::unified_bed_leveling() { reset(); }
unified_bed_leveling::unified_bed_leveling() { reset(); }
void unified_bed_leveling::reset() {
void unified_bed_leveling::reset() {
const bool was_enabled = planner.leveling_active;
set_bed_leveling_enabled(false);
storage_slot = -1;
@ -95,21 +95,21 @@
GRID_LOOP(x, y) ExtUI::onMeshUpdate(x, y, 0);
#endif
if (was_enabled) report_current_position();
}
}
void unified_bed_leveling::invalidate() {
void unified_bed_leveling::invalidate() {
set_bed_leveling_enabled(false);
set_all_mesh_points_to_value(NAN);
}
}
void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
void unified_bed_leveling::set_all_mesh_points_to_value(const float value) {
GRID_LOOP(x, y) {
z_values[x][y] = value;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, value));
}
}
}
#if ENABLED(OPTIMIZED_MESH_STORAGE)
#if ENABLED(OPTIMIZED_MESH_STORAGE)
constexpr float mesh_store_scaling = 1000;
constexpr int16_t Z_STEPS_NAN = INT16_MAX;
@ -132,9 +132,9 @@
GRID_LOOP(x, y) out_values[x][y] = store_to_z(stored_values[x][y]);
}
#endif // OPTIMIZED_MESH_STORAGE
#endif // OPTIMIZED_MESH_STORAGE
static void serial_echo_xy(const uint8_t sp, const int16_t x, const int16_t y) {
static void serial_echo_xy(const uint8_t sp, const int16_t x, const int16_t y) {
SERIAL_ECHO_SP(sp);
SERIAL_CHAR('(');
if (x < 100) { SERIAL_CHAR(' '); if (x < 10) SERIAL_CHAR(' '); }
@ -144,9 +144,9 @@
SERIAL_ECHO(y);
SERIAL_CHAR(')');
serial_delay(5);
}
}
static void serial_echo_column_labels(const uint8_t sp) {
static void serial_echo_column_labels(const uint8_t sp) {
SERIAL_ECHO_SP(7);
LOOP_L_N(i, GRID_MAX_POINTS_X) {
if (i < 10) SERIAL_CHAR(' ');
@ -154,16 +154,16 @@
SERIAL_ECHO_SP(sp);
}
serial_delay(10);
}
}
/**
/**
* Produce one of these mesh maps:
* 0: Human-readable
* 1: CSV format for spreadsheet import
* 2: TODO: Display on Graphical LCD
* 4: Compact Human-Readable
*/
void unified_bed_leveling::display_map(const int map_type) {
void unified_bed_leveling::display_map(const int map_type) {
const bool was = gcode.set_autoreport_paused(true);
constexpr uint8_t eachsp = 1 + 6 + 1, // [-3.567]
@ -241,9 +241,9 @@
}
gcode.set_autoreport_paused(was);
}
}
bool unified_bed_leveling::sanity_check() {
bool unified_bed_leveling::sanity_check() {
uint8_t error_flag = 0;
if (settings.calc_num_meshes() < 1) {
@ -252,6 +252,6 @@
}
return !!error_flag;
}
}
#endif // AUTO_BED_LEVELING_UBL

View File

@ -46,7 +46,7 @@ struct mesh_index_pair;
#endif
class unified_bed_leveling {
private:
private:
static int g29_verbose_level,
g29_phase_value,
@ -88,7 +88,7 @@ class unified_bed_leveling {
static void g29_compare_current_mesh_to_stored_mesh();
#endif
public:
public:
static void echo_name();
static void report_current_mesh();

View File

@ -24,36 +24,36 @@
#if ENABLED(AUTO_BED_LEVELING_UBL)
#include "../bedlevel.h"
#include "../bedlevel.h"
#include "../../../MarlinCore.h"
#include "../../../HAL/shared/eeprom_api.h"
#include "../../../libs/hex_print.h"
#include "../../../module/settings.h"
#include "../../../lcd/marlinui.h"
#include "../../../module/stepper.h"
#include "../../../module/planner.h"
#include "../../../module/motion.h"
#include "../../../module/probe.h"
#include "../../../gcode/gcode.h"
#include "../../../libs/least_squares_fit.h"
#include "../../../MarlinCore.h"
#include "../../../HAL/shared/eeprom_api.h"
#include "../../../libs/hex_print.h"
#include "../../../module/settings.h"
#include "../../../lcd/marlinui.h"
#include "../../../module/stepper.h"
#include "../../../module/planner.h"
#include "../../../module/motion.h"
#include "../../../module/probe.h"
#include "../../../gcode/gcode.h"
#include "../../../libs/least_squares_fit.h"
#if HAS_MULTI_HOTEND
#if HAS_MULTI_HOTEND
#include "../../../module/tool_change.h"
#endif
#endif
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
#define DEBUG_OUT ENABLED(DEBUG_LEVELING_FEATURE)
#include "../../../core/debug_out.h"
#if ENABLED(EXTENSIBLE_UI)
#if ENABLED(EXTENSIBLE_UI)
#include "../../../lcd/extui/ui_api.h"
#endif
#endif
#include <math.h>
#include <math.h>
#define UBL_G29_P31
#define UBL_G29_P31
#if HAS_LCD_MENU
#if HAS_LCD_MENU
bool unified_bed_leveling::lcd_map_control = false;
@ -66,27 +66,27 @@
void ubl_map_screen();
#endif
#endif
#define SIZE_OF_LITTLE_RAISE 1
#define BIG_RAISE_NOT_NEEDED 0
#define SIZE_OF_LITTLE_RAISE 1
#define BIG_RAISE_NOT_NEEDED 0
int unified_bed_leveling::g29_verbose_level,
int unified_bed_leveling::g29_verbose_level,
unified_bed_leveling::g29_phase_value,
unified_bed_leveling::g29_repetition_cnt,
unified_bed_leveling::g29_storage_slot = 0,
unified_bed_leveling::g29_map_type;
bool unified_bed_leveling::g29_c_flag;
float unified_bed_leveling::g29_card_thickness = 0,
bool unified_bed_leveling::g29_c_flag;
float unified_bed_leveling::g29_card_thickness = 0,
unified_bed_leveling::g29_constant = 0;
xy_bool_t unified_bed_leveling::xy_seen;
xy_pos_t unified_bed_leveling::g29_pos;
xy_bool_t unified_bed_leveling::xy_seen;
xy_pos_t unified_bed_leveling::g29_pos;
#if HAS_BED_PROBE
#if HAS_BED_PROBE
int unified_bed_leveling::g29_grid_size;
#endif
#endif
/**
/**
* G29: Unified Bed Leveling by Roxy
*
* Parameters understood by this leveling system:
@ -309,7 +309,7 @@
* features of all three systems combined.
*/
void unified_bed_leveling::G29() {
void unified_bed_leveling::G29() {
bool probe_deployed = false;
if (g29_parameter_parsing()) return; // Abort on parameter error
@ -680,9 +680,9 @@
TERN_(HAS_MULTI_HOTEND, tool_change(old_tool_index));
return;
}
}
void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
void unified_bed_leveling::adjust_mesh_to_mean(const bool cflag, const float value) {
float sum = 0;
int n = 0;
GRID_LOOP(x, y)
@ -713,17 +713,17 @@
z_values[x][y] -= mean + value;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
}
}
}
void unified_bed_leveling::shift_mesh_height() {
void unified_bed_leveling::shift_mesh_height() {
GRID_LOOP(x, y)
if (!isnan(z_values[x][y])) {
z_values[x][y] += g29_constant;
TERN_(EXTENSIBLE_UI, ExtUI::onMeshUpdate(x, y, z_values[x][y]));
}
}
}
#if HAS_BED_PROBE
#if HAS_BED_PROBE
/**
* Probe all invalidated locations of the mesh that can be reached by the probe.
* This attempts to fill in locations closest to the nozzle's start location first.
@ -794,9 +794,9 @@
);
}
#endif // HAS_BED_PROBE
#endif // HAS_BED_PROBE
#if HAS_LCD_MENU
#if HAS_LCD_MENU
typedef void (*clickFunc_t)();
@ -1051,9 +1051,9 @@
ui.return_to_status();
}
#endif // HAS_LCD_MENU
#endif // HAS_LCD_MENU
bool unified_bed_leveling::g29_parameter_parsing() {
bool unified_bed_leveling::g29_parameter_parsing() {
bool err_flag = false;
TERN_(HAS_LCD_MENU, set_message_with_feedback(GET_TEXT(MSG_UBL_DOING_G29)));
@ -1165,15 +1165,15 @@
return UBL_ERR;
}
return UBL_OK;
}
}
static uint8_t ubl_state_at_invocation = 0;
static uint8_t ubl_state_at_invocation = 0;
#if ENABLED(UBL_DEVEL_DEBUGGING)
#if ENABLED(UBL_DEVEL_DEBUGGING)
static uint8_t ubl_state_recursion_chk = 0;
#endif
#endif
void unified_bed_leveling::save_ubl_active_state_and_disable() {
void unified_bed_leveling::save_ubl_active_state_and_disable() {
#if ENABLED(UBL_DEVEL_DEBUGGING)
ubl_state_recursion_chk++;
if (ubl_state_recursion_chk != 1) {
@ -1184,9 +1184,9 @@
#endif
ubl_state_at_invocation = planner.leveling_active;
set_bed_leveling_enabled(false);
}
}
void unified_bed_leveling::restore_ubl_active_state_and_leave() {
void unified_bed_leveling::restore_ubl_active_state_and_leave() {
TERN_(HAS_LCD_MENU, ui.release());
#if ENABLED(UBL_DEVEL_DEBUGGING)
if (--ubl_state_recursion_chk) {
@ -1196,9 +1196,9 @@
}
#endif
set_bed_leveling_enabled(ubl_state_at_invocation);
}
}
mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
mesh_index_pair unified_bed_leveling::find_furthest_invalid_mesh_point() {
bool found_a_NAN = false, found_a_real = false;
@ -1247,9 +1247,9 @@
farthest.distance = 1;
}
return farthest;
}
}
mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const xy_pos_t &pos, const bool probe_relative/*=false*/, MeshFlags *done_flags/*=nullptr*/) {
mesh_index_pair unified_bed_leveling::find_closest_mesh_point_of_type(const MeshPointType type, const xy_pos_t &pos, const bool probe_relative/*=false*/, MeshFlags *done_flags/*=nullptr*/) {
mesh_index_pair closest;
closest.invalidate();
closest.distance = -99999.9f;
@ -1289,15 +1289,15 @@
} // GRID_LOOP
return closest;
}
}
/**
/**
* 'Smart Fill': Scan from the outward edges of the mesh towards the center.
* If an invalid location is found, use the next two points (if valid) to
* calculate a 'reasonable' value for the unprobed mesh point.
*/
bool unified_bed_leveling::smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
bool unified_bed_leveling::smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir) {
const float v = z_values[x][y];
if (isnan(v)) { // A NAN...
const int8_t dx = x + xdir, dy = y + ydir;
@ -1312,11 +1312,11 @@
}
}
return false;
}
}
typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
typedef struct { uint8_t sx, ex, sy, ey; bool yfirst; } smart_fill_info;
void unified_bed_leveling::smart_fill_mesh() {
void unified_bed_leveling::smart_fill_mesh() {
static const smart_fill_info
info0 PROGMEM = { 0, GRID_MAX_POINTS_X, 0, GRID_MAX_POINTS_Y - 2, false }, // Bottom of the mesh looking up
info1 PROGMEM = { 0, GRID_MAX_POINTS_X, GRID_MAX_POINTS_Y - 1, 0, false }, // Top of the mesh looking down
@ -1341,9 +1341,9 @@
if (smart_fill_one(x, y, 0, dir)) break;
}
}
}
}
#if HAS_BED_PROBE
#if HAS_BED_PROBE
//#define VALIDATE_MESH_TILT
@ -1587,9 +1587,9 @@
}
#endif // HAS_BED_PROBE
#endif // HAS_BED_PROBE
#if ENABLED(UBL_G29_P31)
#if ENABLED(UBL_G29_P31)
void unified_bed_leveling::smart_fill_wlsf(const float &weight_factor) {
// For each undefined mesh point, compute a distance-weighted least squares fit
@ -1641,9 +1641,9 @@
SERIAL_ECHOLNPGM("done");
}
#endif // UBL_G29_P31
#endif // UBL_G29_P31
#if ENABLED(UBL_DEVEL_DEBUGGING)
#if ENABLED(UBL_DEVEL_DEBUGGING)
/**
* Much of the 'What?' command can be eliminated. But until we are fully debugged, it is
* good to have the extra information. Soon... we prune this to just a few items
@ -1778,6 +1778,6 @@
}
}
#endif // UBL_DEVEL_DEBUGGING
#endif // UBL_DEVEL_DEBUGGING
#endif // AUTO_BED_LEVELING_UBL