123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
-
-
- #include "Marlin.h"
- #include "math.h"
-
- #if ENABLED(AUTO_BED_LEVELING_UBL)
-
- #include "ubl.h"
- #include "hex_print_routines.h"
- #include "temperature.h"
-
- extern Planner planner;
-
-
-
- void bit_clear(uint16_t bits[16], uint8_t x, uint8_t y) { CBI(bits[y], x); }
- void bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { SBI(bits[y], x); }
- bool is_bit_set(uint16_t bits[16], uint8_t x, uint8_t y) { return TEST(bits[y], x); }
-
- uint8_t ubl_cnt = 0;
-
- void unified_bed_leveling::echo_name() { SERIAL_PROTOCOLPGM("Unified Bed Leveling"); }
-
- void unified_bed_leveling::report_state() {
- echo_name();
- SERIAL_PROTOCOLPGM(" System v" UBL_VERSION " ");
- if (!state.active) SERIAL_PROTOCOLPGM("in");
- SERIAL_PROTOCOLLNPGM("active.");
- safe_delay(50);
- }
-
- static void serial_echo_xy(const int16_t x, const int16_t y) {
- SERIAL_CHAR('(');
- SERIAL_ECHO(x);
- SERIAL_CHAR(',');
- SERIAL_ECHO(y);
- SERIAL_CHAR(')');
- safe_delay(10);
- }
-
- ubl_state unified_bed_leveling::state;
-
- float unified_bed_leveling::z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y],
- unified_bed_leveling::last_specified_z;
-
-
-
- constexpr float unified_bed_leveling::_mesh_index_to_xpos[16],
- unified_bed_leveling::_mesh_index_to_ypos[16];
-
- bool unified_bed_leveling::g26_debug_flag = false,
- unified_bed_leveling::has_control_of_lcd_panel = false;
-
- volatile int unified_bed_leveling::encoder_diff;
-
- unified_bed_leveling::unified_bed_leveling() {
- ubl_cnt++;
- reset();
- }
-
- void unified_bed_leveling::reset() {
- state.active = false;
- state.z_offset = 0;
- state.storage_slot = -1;
- #if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
- planner.z_fade_height = 10.0;
- #endif
- ZERO(z_values);
- last_specified_z = -999.9;
- }
-
- void unified_bed_leveling::invalidate() {
- state.active = false;
- state.z_offset = 0;
- for (int x = 0; x < GRID_MAX_POINTS_X; x++)
- for (int y = 0; y < GRID_MAX_POINTS_Y; y++)
- z_values[x][y] = NAN;
- }
-
- void unified_bed_leveling::display_map(const int map_type) {
- const bool map0 = map_type == 0;
- constexpr uint8_t spaces = 8 * (GRID_MAX_POINTS_X - 2);
-
- if (map0) {
- SERIAL_PROTOCOLLNPGM("\nBed Topography Report:\n");
- serial_echo_xy(0, GRID_MAX_POINTS_Y - 1);
- SERIAL_ECHO_SP(spaces + 3);
- serial_echo_xy(GRID_MAX_POINTS_X - 1, GRID_MAX_POINTS_Y - 1);
- SERIAL_EOL;
- serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MAX_Y);
- SERIAL_ECHO_SP(spaces);
- serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MAX_Y);
- SERIAL_EOL;
- }
-
- const float current_xi = get_cell_index_x(current_position[X_AXIS] + (MESH_X_DIST) / 2.0),
- current_yi = get_cell_index_y(current_position[Y_AXIS] + (MESH_Y_DIST) / 2.0);
-
- for (int8_t j = GRID_MAX_POINTS_Y - 1; j >= 0; j--) {
- for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) {
- const bool is_current = i == current_xi && j == current_yi;
-
-
- if (map0) SERIAL_CHAR(is_current ? '[' : ' ');
-
- const float f = z_values[i][j];
- if (isnan(f)) {
- serialprintPGM(map0 ? PSTR(" . ") : PSTR("NAN"));
- }
- else {
-
- if (map0 && f >= 0.0) SERIAL_CHAR(' ');
- SERIAL_PROTOCOL_F(f, 3);
- idle();
- }
- if (!map0 && i < GRID_MAX_POINTS_X - 1) SERIAL_CHAR(',');
-
- #if TX_BUFFER_SIZE > 0
- MYSERIAL.flushTX();
- #endif
- safe_delay(15);
- if (map0) {
- SERIAL_CHAR(is_current ? ']' : ' ');
- SERIAL_CHAR(' ');
- }
- }
- SERIAL_EOL;
- if (j && map0) {
- SERIAL_CHAR(' ');
- SERIAL_EOL;
- }
- }
-
- if (map0) {
- serial_echo_xy(UBL_MESH_MIN_X, UBL_MESH_MIN_Y);
- SERIAL_ECHO_SP(spaces + 4);
- serial_echo_xy(UBL_MESH_MAX_X, UBL_MESH_MIN_Y);
- SERIAL_EOL;
- serial_echo_xy(0, 0);
- SERIAL_ECHO_SP(spaces + 5);
- serial_echo_xy(GRID_MAX_POINTS_X - 1, 0);
- SERIAL_EOL;
- }
- }
-
- bool unified_bed_leveling::sanity_check() {
- uint8_t error_flag = 0;
-
- const int a = settings.calc_num_meshes();
- if (a < 1) {
- SERIAL_PROTOCOLLNPGM("?Insufficient EEPROM storage for a mesh of this size.");
- error_flag++;
- }
-
- return !!error_flag;
- }
-
- #endif
|