diff --git a/.travis.yml b/.travis.yml index 22578e6a77..79962ba073 100644 --- a/.travis.yml +++ b/.travis.yml @@ -72,7 +72,7 @@ script: # Test a probeless build of AUTO_BED_LEVELING_UBL # - restore_configs - - opt_enable AUTO_BED_LEVELING_UBL UBL_G26_MESH_EDITING ENABLE_LEVELING_FADE_HEIGHT EEPROM_SETTINGS G3D_PANEL + - opt_enable AUTO_BED_LEVELING_UBL G26_MESH_EDITING ENABLE_LEVELING_FADE_HEIGHT EEPROM_SETTINGS G3D_PANEL - opt_enable_adv CUSTOM_USER_MENUS I2C_POSITION_ENCODERS BABYSTEPPING - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM} # @@ -101,7 +101,7 @@ script: # Test MESH_BED_LEVELING feature, with LCD # - restore_configs - - opt_enable MESH_BED_LEVELING MESH_G28_REST_ORIGIN LCD_BED_LEVELING ULTIMAKERCONTROLLER + - opt_enable MESH_BED_LEVELING G26_MESH_EDITING MESH_G28_REST_ORIGIN LCD_BED_LEVELING ULTIMAKERCONTROLLER - build_marlin_pio ${TRAVIS_BUILD_DIR} ${TEST_PLATFORM} # # Test MINIRAMBO for PWM_MOTOR_CURRENT @@ -115,7 +115,7 @@ script: # - restore_configs - opt_set MOTHERBOARD BOARD_MINIRAMBO - - opt_enable PROBE_MANUALLY AUTO_BED_LEVELING_BILINEAR LCD_BED_LEVELING ULTIMAKERCONTROLLER + - opt_enable PROBE_MANUALLY AUTO_BED_LEVELING_BILINEAR G26_MESH_EDITING LCD_BED_LEVELING ULTIMAKERCONTROLLER - opt_enable EEPROM_SETTINGS EEPROM_CHITCHAT M100_FREE_MEMORY_WATCHER M100_FREE_MEMORY_DUMPER M100_FREE_MEMORY_CORRUPTOR INCH_MODE_SUPPORT TEMPERATURE_UNITS_SUPPORT - opt_enable ULTIMAKERCONTROLLER SDSUPPORT - opt_enable PRINTCOUNTER NOZZLE_PARK_FEATURE NOZZLE_CLEAN_FEATURE PCA9632 USE_XMAX_PLUG diff --git a/Marlin/src/core/macros.h b/Marlin/src/core/macros.h index 6342c16439..a925362b1e 100644 --- a/Marlin/src/core/macros.h +++ b/Marlin/src/core/macros.h @@ -95,6 +95,9 @@ #define STRINGIFY(M) STRINGIFY_(M) // Macros for bit masks +#ifndef _BV + #define _BV(B) (1UL<<(B)) +#endif #define TEST(n,b) (((n)&_BV(b))!=0) #define SBI(n,b) (n |= _BV(b)) #define CBI(n,b) (n &= ~_BV(b)) diff --git a/Marlin/src/core/utility.h b/Marlin/src/core/utility.h index 5ad9f11d9b..7717478085 100644 --- a/Marlin/src/core/utility.h +++ b/Marlin/src/core/utility.h @@ -23,7 +23,7 @@ #ifndef __UTILITY_H__ #define __UTILITY_H__ -#include "../inc/MarlinConfig.h" +#include "../inc/MarlinConfigPre.h" constexpr char axis_codes[XYZE] = { 'X', 'Y', 'Z', 'E' }; @@ -33,6 +33,18 @@ void safe_delay(millis_t ms); void crc16(uint16_t *crc, const void * const data, uint16_t cnt); #endif +#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION) + /** + * These support functions allow the use of large bit arrays of flags that take very + * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration + * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed + * in the future. + */ + FORCE_INLINE void bit_clear(uint16_t bits[16], const uint8_t x, const uint8_t y) { CBI(bits[y], x); } + FORCE_INLINE void bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { SBI(bits[y], x); } + FORCE_INLINE bool is_bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); } +#endif + #if ENABLED(ULTRA_LCD) // Convert uint8_t to string with 123 format diff --git a/Marlin/src/feature/bedlevel/bedlevel.cpp b/Marlin/src/feature/bedlevel/bedlevel.cpp index d1759efa92..2d3c89ee24 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.cpp +++ b/Marlin/src/feature/bedlevel/bedlevel.cpp @@ -41,6 +41,10 @@ #endif #endif +#if G26_MESH_VALIDATION + bool g26_debug_flag; // = false +#endif + bool leveling_is_valid() { return #if ENABLED(MESH_BED_LEVELING) diff --git a/Marlin/src/feature/bedlevel/bedlevel.h b/Marlin/src/feature/bedlevel/bedlevel.h index ecd2297032..cf323175d0 100644 --- a/Marlin/src/feature/bedlevel/bedlevel.h +++ b/Marlin/src/feature/bedlevel/bedlevel.h @@ -23,14 +23,17 @@ #ifndef __BEDLEVEL_H__ #define __BEDLEVEL_H__ -#include "../../inc/MarlinConfig.h" +#include "../../inc/MarlinConfigPre.h" -#if ENABLED(MESH_BED_LEVELING) - #include "mbl/mesh_bed_leveling.h" -#elif ENABLED(AUTO_BED_LEVELING_UBL) - #include "ubl/ubl.h" -#elif HAS_ABL - #include "abl/abl.h" +typedef struct { + int8_t x_index, y_index; + float distance; // When populated, the distance from the search location +} mesh_index_pair; + +#if ENABLED(G26_MESH_VALIDATION) + extern bool g26_debug_flag; +#else + constexpr bool g26_debug_flag = false; #endif #if ENABLED(PROBE_MANUALLY) @@ -68,4 +71,23 @@ void reset_bed_level(); void out_of_range_error(const char* p_edge); #endif +#if ENABLED(AUTO_BED_LEVELING_BILINEAR) + #define _GET_MESH_X(I) bilinear_start[X_AXIS] + I * bilinear_grid_spacing[X_AXIS] + #define _GET_MESH_Y(J) bilinear_start[Y_AXIS] + J * bilinear_grid_spacing[Y_AXIS] +#elif ENABLED(AUTO_BED_LEVELING_UBL) + #define _GET_MESH_X(I) ubl.mesh_index_to_xpos(I) + #define _GET_MESH_Y(J) ubl.mesh_index_to_ypos(J) +#elif ENABLED(MESH_BED_LEVELING) + #define _GET_MESH_X(I) mbl.index_to_xpos[I] + #define _GET_MESH_Y(J) mbl.index_to_ypos[J] +#endif + +#if ENABLED(MESH_BED_LEVELING) + #include "mbl/mesh_bed_leveling.h" +#elif ENABLED(AUTO_BED_LEVELING_UBL) + #include "ubl/ubl.h" +#elif HAS_ABL + #include "abl/abl.h" +#endif + #endif // __BEDLEVEL_H__ diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.cpp b/Marlin/src/feature/bedlevel/ubl/ubl.cpp index 9f4a33f19b..91c9f5eff0 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl.cpp @@ -34,16 +34,6 @@ #include "math.h" - /** - * These support functions allow the use of large bit arrays of flags that take very - * little RAM. Currently they are limited to being 16x16 in size. Changing the declaration - * to unsigned long will allow us to go to 32x32 if higher resolution Mesh's are needed - * in the future. - */ - void bit_clear(uint16_t bits[16], const uint8_t x, const uint8_t y) { CBI(bits[y], x); } - void bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { SBI(bits[y], x); } - bool is_bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y) { return TEST(bits[y], x); } - uint8_t ubl_cnt = 0; void unified_bed_leveling::echo_name() { SERIAL_PROTOCOLPGM("Unified Bed Leveling"); } @@ -74,9 +64,6 @@ 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; - #if ENABLED(ULTRA_LCD) bool unified_bed_leveling::lcd_map_control = false; #endif diff --git a/Marlin/src/feature/bedlevel/ubl/ubl.h b/Marlin/src/feature/bedlevel/ubl/ubl.h index fa7aa65a34..bfebeae967 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl.h +++ b/Marlin/src/feature/bedlevel/ubl/ubl.h @@ -23,9 +23,10 @@ #ifndef UNIFIED_BED_LEVELING_H #define UNIFIED_BED_LEVELING_H -#include "../../../Marlin.h" +#include "../bedlevel.h" #include "../../../module/planner.h" #include "../../../module/motion.h" +#include "../../../Marlin.h" #define UBL_VERSION "1.01" #define UBL_OK false @@ -34,17 +35,6 @@ #define USE_NOZZLE_AS_REFERENCE 0 #define USE_PROBE_AS_REFERENCE 1 -typedef struct { - int8_t x_index, y_index; - float distance; // When populated, the distance from the search location -} mesh_index_pair; - -// ubl.cpp - -void bit_clear(uint16_t bits[16], const uint8_t x, const uint8_t y); -void bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y); -bool is_bit_set(uint16_t bits[16], const uint8_t x, const uint8_t y); - // ubl_motion.cpp void debug_current_and_destination(const char * const title); @@ -56,7 +46,6 @@ enum MeshPointType { INVALID, REAL, SET_IN_BITMAP }; // External references char *ftostr43sign(const float&, char); -bool ubl_lcd_clicked(); extern uint8_t ubl_cnt; @@ -87,22 +76,6 @@ class unified_bed_leveling { static int g29_grid_size; #endif - #if ENABLED(UBL_G26_MESH_VALIDATION) - static float g26_extrusion_multiplier, - g26_retraction_multiplier, - g26_nozzle, - g26_filament_diameter, - g26_prime_length, - g26_x_pos, g26_y_pos, - g26_ooze_amount, - g26_layer_height; - static int16_t g26_bed_temp, - g26_hotend_temp, - g26_repeats; - static int8_t g26_prime_flag; - static bool g26_continue_with_closest, g26_keep_heaters_on; - #endif - static float measure_point_with_encoder(); static float measure_business_card_thickness(float); static bool g29_parameter_parsing(); @@ -119,21 +92,6 @@ class unified_bed_leveling { static bool smart_fill_one(const uint8_t x, const uint8_t y, const int8_t xdir, const int8_t ydir); static void smart_fill_mesh(); - #if ENABLED(UBL_G26_MESH_VALIDATION) - static bool exit_from_g26(); - static bool parse_G26_parameters(); - static void G26_line_to_destination(const float &feed_rate); - static mesh_index_pair find_closest_circle_to_print(const float&, const float&); - static bool look_for_lines_to_connect(); - static bool turn_on_heaters(); - static bool prime_nozzle(); - static void retract_filament(const float where[XYZE]); - static void recover_filament(const float where[XYZE]); - static void print_line_from_here_to_there(const float&, const float&, const float&, const float&, const float&, const float&); - static void move_to(const float&, const float&, const float&, const float&); - inline static void move_to(const float where[XYZE], const float &de) { move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de); } - #endif - public: static void echo_name(); @@ -151,10 +109,6 @@ class unified_bed_leveling { static void G29() _O0; // O0 for no optimization static void smart_fill_wlsf(const float &) _O2; // O2 gives smaller code than Os on A2560 - #if ENABLED(UBL_G26_MESH_VALIDATION) - static void G26(); - #endif - static int8_t storage_slot; static float z_values[GRID_MAX_POINTS_X][GRID_MAX_POINTS_Y]; @@ -183,8 +137,6 @@ class unified_bed_leveling { MESH_MIN_Y + 14 * (MESH_Y_DIST), MESH_MIN_Y + 15 * (MESH_Y_DIST) }; - static bool g26_debug_flag, has_control_of_lcd_panel; - #if ENABLED(ULTRA_LCD) static bool lcd_map_control; #endif diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp index 94bc875f00..4b1ce5936a 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp @@ -677,8 +677,7 @@ lcd_reset_alert_level(); LCD_MESSAGEPGM(""); lcd_quick_feedback(); - - has_control_of_lcd_panel = false; + lcd_external_control = false; #endif return; @@ -738,7 +737,10 @@ void unified_bed_leveling::probe_entire_mesh(const float &rx, const float &ry, const bool do_ubl_mesh_map, const bool stow_probe, bool close_or_far) { mesh_index_pair location; - has_control_of_lcd_panel = true; + #if ENABLED(NEWPANEL) + lcd_external_control = true; + #endif + save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe DEPLOY_PROBE(); @@ -748,12 +750,12 @@ if (do_ubl_mesh_map) display_map(g29_map_type); #if ENABLED(NEWPANEL) - if (ubl_lcd_clicked()) { + if (is_lcd_clicked()) { SERIAL_PROTOCOLLNPGM("\nMesh only partially populated.\n"); lcd_quick_feedback(); STOW_PROBE(); - while (ubl_lcd_clicked()) idle(); - has_control_of_lcd_panel = false; + while (is_lcd_clicked()) idle(); + lcd_external_control = false; restore_ubl_active_state_and_leave(); safe_delay(50); // Debounce the Encoder wheel return; @@ -894,11 +896,11 @@ float unified_bed_leveling::measure_point_with_encoder() { - while (ubl_lcd_clicked()) delay(50); // wait for user to release encoder wheel + while (is_lcd_clicked()) delay(50); // wait for user to release encoder wheel delay(50); // debounce KEEPALIVE_STATE(PAUSED_FOR_USER); - while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here! + while (!is_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here! idle(); if (encoder_diff) { do_blocking_move_to_z(current_position[Z_AXIS] + 0.01 * float(encoder_diff)); @@ -912,7 +914,7 @@ static void echo_and_take_a_measurement() { SERIAL_PROTOCOLLNPGM(" and take a measurement."); } float unified_bed_leveling::measure_business_card_thickness(const float in_height) { - has_control_of_lcd_panel = true; + lcd_external_control = true; save_ubl_active_state_and_disable(); // Disable bed level correction for probing do_blocking_move_to(0.5 * (MESH_MAX_X - (MESH_MIN_X)), 0.5 * (MESH_MAX_Y - (MESH_MIN_Y)), in_height); @@ -944,7 +946,7 @@ SERIAL_PROTOCOLLNPGM("mm thick."); } - has_control_of_lcd_panel = false; + lcd_external_control = false; restore_ubl_active_state_and_leave(); @@ -953,7 +955,7 @@ void unified_bed_leveling::manually_probe_remaining_mesh(const float &rx, const float &ry, const float &z_clearance, const float &thick, const bool do_ubl_mesh_map) { - has_control_of_lcd_panel = true; + lcd_external_control = true; save_ubl_active_state_and_disable(); // we don't do bed level correction because we want the raw data when we probe @@ -978,7 +980,7 @@ do_blocking_move_to_z(z_clearance); KEEPALIVE_STATE(PAUSED_FOR_USER); - has_control_of_lcd_panel = true; + lcd_external_control = true; if (do_ubl_mesh_map) display_map(g29_map_type); // show user where we're probing @@ -987,9 +989,9 @@ const float z_step = 0.01; // existing behavior: 0.01mm per click, occasionally step //const float z_step = 1.0 / planner.axis_steps_per_mm[Z_AXIS]; // approx one step each click - while (ubl_lcd_clicked()) delay(50); // wait for user to release encoder wheel + while (is_lcd_clicked()) delay(50); // wait for user to release encoder wheel delay(50); // debounce - while (!ubl_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here! + while (!is_lcd_clicked()) { // we need the loop to move the nozzle based on the encoder wheel here! idle(); if (encoder_diff) { do_blocking_move_to_z(current_position[Z_AXIS] + float(encoder_diff) * z_step); @@ -997,11 +999,11 @@ } } - // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is + // this sequence to detect an is_lcd_clicked() debounce it and leave if it is // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp). This // should be redone and compressed. const millis_t nxt = millis() + 1500L; - while (ubl_lcd_clicked()) { // debounce and watch for abort + while (is_lcd_clicked()) { // debounce and watch for abort idle(); if (ELAPSED(millis(), nxt)) { SERIAL_PROTOCOLLNPGM("\nMesh only partially populated."); @@ -1009,8 +1011,8 @@ #if ENABLED(NEWPANEL) lcd_quick_feedback(); - while (ubl_lcd_clicked()) idle(); - has_control_of_lcd_panel = false; + while (is_lcd_clicked()) idle(); + lcd_external_control = false; #endif KEEPALIVE_STATE(IN_HANDLER); @@ -1509,7 +1511,7 @@ new_z = FLOOR(new_z * 1000.0) * 0.001; // Chop off digits after the 1000ths place KEEPALIVE_STATE(PAUSED_FOR_USER); - has_control_of_lcd_panel = true; + lcd_external_control = true; if (do_ubl_mesh_map) display_map(g29_map_type); // show the user which point is being adjusted @@ -1523,27 +1525,27 @@ do_blocking_move_to_z(h_offset + new_z); // Move the nozzle as the point is edited #endif idle(); - } while (!ubl_lcd_clicked()); + } while (!is_lcd_clicked()); if (!lcd_map_control) lcd_return_to_status(); // The technique used here generates a race condition for the encoder click. // It could get detected in lcd_mesh_edit (actually _lcd_mesh_fine_tune) or here. // Let's work on specifying a proper API for the LCD ASAP, OK? - has_control_of_lcd_panel = true; + lcd_external_control = true; - // this sequence to detect an ubl_lcd_clicked() debounce it and leave if it is + // this sequence to detect an is_lcd_clicked() debounce it and leave if it is // a Press and Hold is repeated in a lot of places (including G26_Mesh_Validation.cpp). This // should be redone and compressed. const millis_t nxt = millis() + 1500UL; - while (ubl_lcd_clicked()) { // debounce and watch for abort + while (is_lcd_clicked()) { // debounce and watch for abort idle(); if (ELAPSED(millis(), nxt)) { lcd_return_to_status(); do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); LCD_MESSAGEPGM(MSG_EDITING_STOPPED); - while (ubl_lcd_clicked()) idle(); + while (is_lcd_clicked()) idle(); goto FINE_TUNE_EXIT; } @@ -1559,7 +1561,7 @@ FINE_TUNE_EXIT: - has_control_of_lcd_panel = false; + lcd_external_control = false; KEEPALIVE_STATE(IN_HANDLER); if (do_ubl_mesh_map) display_map(g29_map_type); diff --git a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp index 75f0f25d3d..d04ec3dde0 100644 --- a/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp +++ b/Marlin/src/feature/bedlevel/ubl/ubl_motion.cpp @@ -23,9 +23,7 @@ #if ENABLED(AUTO_BED_LEVELING_UBL) - #include "ubl.h" - - #include "../../../Marlin.h" + #include "../bedlevel.h" #include "../../../module/planner.h" #include "../../../module/stepper.h" #include "../../../module/motion.h" @@ -34,6 +32,7 @@ #include "../../../module/delta.h" #endif + #include "../../../Marlin.h" #include extern float destination[XYZE]; @@ -55,7 +54,7 @@ // if the title message starts with a '!' it is so important, we are going to // ignore the status of the g26_debug_flag - if (*title != '!' && !ubl.g26_debug_flag) return; + if (*title != '!' && !g26_debug_flag) return; const float de = destination[E_AXIS] - current_position[E_AXIS]; diff --git a/Marlin/src/gcode/bedlevel/G26.cpp b/Marlin/src/gcode/bedlevel/G26.cpp index 543337ac68..59bd70b2b6 100644 --- a/Marlin/src/gcode/bedlevel/G26.cpp +++ b/Marlin/src/gcode/bedlevel/G26.cpp @@ -24,20 +24,22 @@ * Marlin Firmware -- G26 - Mesh Validation Tool */ -#include "../../../inc/MarlinConfig.h" +#include "../../inc/MarlinConfig.h" -#if ENABLED(UBL_G26_MESH_VALIDATION) +#if ENABLED(G26_MESH_VALIDATION) -#include "ubl.h" +#define G26_OK false +#define G26_ERR true -#include "../../../Marlin.h" -#include "../../../module/planner.h" -#include "../../../module/stepper.h" -#include "../../../module/motion.h" -#include "../../../module/temperature.h" -#include "../../../lcd/ultralcd.h" -#include "../../../gcode/parser.h" -#include "../../bedlevel/bedlevel.h" +#include "../../gcode/gcode.h" +#include "../../feature/bedlevel/bedlevel.h" + +#include "../../Marlin.h" +#include "../../module/planner.h" +#include "../../module/stepper.h" +#include "../../module/motion.h" +#include "../../module/temperature.h" +#include "../../lcd/ultralcd.h" #define EXTRUSION_MULTIPLIER 1.0 #define RETRACTION_MULTIPLIER 1.0 @@ -130,11 +132,6 @@ extern char lcd_status_message[]; #endif -#if ENABLED(NEWPANEL) - void lcd_setstatusPGM(const char* const message, const int8_t level); - void chirp_at_user(); -#endif - // Private functions static uint16_t circle_flags[16], horizontal_mesh_line_flags[16], vertical_mesh_line_flags[16]; @@ -144,41 +141,23 @@ float g26_e_axis_feedrate = 0.025, static bool g26_retracted = false; // Track the retracted state of the nozzle so mismatched // retracts/recovers won't result in a bad state. -float valid_trig_angle(float); - -float unified_bed_leveling::g26_extrusion_multiplier, - unified_bed_leveling::g26_retraction_multiplier, - unified_bed_leveling::g26_nozzle, - unified_bed_leveling::g26_filament_diameter, - unified_bed_leveling::g26_layer_height, - unified_bed_leveling::g26_prime_length, - unified_bed_leveling::g26_x_pos, - unified_bed_leveling::g26_y_pos, - unified_bed_leveling::g26_ooze_amount; - -int16_t unified_bed_leveling::g26_bed_temp, - unified_bed_leveling::g26_hotend_temp; - -int8_t unified_bed_leveling::g26_prime_flag; - -bool unified_bed_leveling::g26_continue_with_closest, - unified_bed_leveling::g26_keep_heaters_on; +float g26_extrusion_multiplier, + g26_retraction_multiplier, + g26_layer_height, + g26_prime_length; -int16_t unified_bed_leveling::g26_repeats; +int16_t g26_bed_temp, + g26_hotend_temp; -void unified_bed_leveling::G26_line_to_destination(const float &feed_rate) { - const float save_feedrate = feedrate_mm_s; - feedrate_mm_s = feed_rate; // use specified feed rate - prepare_move_to_destination(); // will ultimately call ubl.line_to_destination_cartesian or ubl.prepare_linear_move_to for UBL_DELTA - feedrate_mm_s = save_feedrate; // restore global feed rate -} +int8_t g26_prime_flag; #if ENABLED(NEWPANEL) + /** - * Detect ubl_lcd_clicked, debounce it, and return true for cancel + * Detect is_lcd_clicked, debounce it, and return true for cancel */ bool user_canceled() { - if (!ubl_lcd_clicked()) return false; + if (!is_lcd_clicked()) return false; safe_delay(10); // Wait for click to settle #if ENABLED(ULTRA_LCD) @@ -186,207 +165,26 @@ void unified_bed_leveling::G26_line_to_destination(const float &feed_rate) { lcd_quick_feedback(); #endif - while (!ubl_lcd_clicked()) idle(); // Wait for button release + while (!is_lcd_clicked()) idle(); // Wait for button release // If the button is suddenly pressed again, // ask the user to resolve the issue lcd_setstatusPGM(PSTR("Release button"), 99); // will never appear... - while (ubl_lcd_clicked()) idle(); // unless this loop happens + while (is_lcd_clicked()) idle(); // unless this loop happens lcd_reset_status(); return true; } -#endif - -/** - * G26: Mesh Validation Pattern generation. - * - * Used to interactively edit UBL's Mesh by placing the - * nozzle in a problem area and doing a G29 P4 R command. - */ -void unified_bed_leveling::G26() { - SERIAL_ECHOLNPGM("G26 command started. Waiting for heater(s)."); - float tmp, start_angle, end_angle; - int i, xi, yi; - mesh_index_pair location; - - // Don't allow Mesh Validation without homing first, - // or if the parameter parsing did not go OK, abort - if (axis_unhomed_error() || parse_G26_parameters()) return; - - if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) { - do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); - stepper.synchronize(); - set_current_from_destination(); - } - - if (turn_on_heaters()) goto LEAVE; - - current_position[E_AXIS] = 0.0; - sync_plan_position_e(); - - if (g26_prime_flag && prime_nozzle()) goto LEAVE; - - /** - * Bed is preheated - * - * Nozzle is at temperature - * - * Filament is primed! - * - * It's "Show Time" !!! - */ - - ZERO(circle_flags); - ZERO(horizontal_mesh_line_flags); - ZERO(vertical_mesh_line_flags); - - // Move nozzle to the specified height for the first layer - set_destination_from_current(); - destination[Z_AXIS] = g26_layer_height; - move_to(destination, 0.0); - move_to(destination, g26_ooze_amount); - - has_control_of_lcd_panel = true; - //debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern.")); - - /** - * Declare and generate a sin() & cos() table to be used during the circle drawing. This will lighten - * the CPU load and make the arc drawing faster and more smooth - */ - float sin_table[360 / 30 + 1], cos_table[360 / 30 + 1]; - for (i = 0; i <= 360 / 30; i++) { - cos_table[i] = SIZE_OF_INTERSECTION_CIRCLES * cos(RADIANS(valid_trig_angle(i * 30.0))); - sin_table[i] = SIZE_OF_INTERSECTION_CIRCLES * sin(RADIANS(valid_trig_angle(i * 30.0))); - } - - do { - location = g26_continue_with_closest - ? find_closest_circle_to_print(current_position[X_AXIS], current_position[Y_AXIS]) - : find_closest_circle_to_print(g26_x_pos, g26_y_pos); // Find the closest Mesh Intersection to where we are now. - - if (location.x_index >= 0 && location.y_index >= 0) { - const float circle_x = mesh_index_to_xpos(location.x_index), - circle_y = mesh_index_to_ypos(location.y_index); - - // If this mesh location is outside the printable_radius, skip it. - - if (!position_is_reachable(circle_x, circle_y)) continue; - - xi = location.x_index; // Just to shrink the next few lines and make them easier to understand - yi = location.y_index; - - if (g26_debug_flag) { - SERIAL_ECHOPAIR(" Doing circle at: (xi=", xi); - SERIAL_ECHOPAIR(", yi=", yi); - SERIAL_CHAR(')'); - SERIAL_EOL(); - } - - start_angle = 0.0; // assume it is going to be a full circle - end_angle = 360.0; - if (xi == 0) { // Check for bottom edge - start_angle = -90.0; - end_angle = 90.0; - if (yi == 0) // it is an edge, check for the two left corners - start_angle = 0.0; - else if (yi == GRID_MAX_POINTS_Y - 1) - end_angle = 0.0; - } - else if (xi == GRID_MAX_POINTS_X - 1) { // Check for top edge - start_angle = 90.0; - end_angle = 270.0; - if (yi == 0) // it is an edge, check for the two right corners - end_angle = 180.0; - else if (yi == GRID_MAX_POINTS_Y - 1) - start_angle = 180.0; - } - else if (yi == 0) { - start_angle = 0.0; // only do the top side of the cirlce - end_angle = 180.0; - } - else if (yi == GRID_MAX_POINTS_Y - 1) { - start_angle = 180.0; // only do the bottom side of the cirlce - end_angle = 360.0; - } - - for (tmp = start_angle; tmp < end_angle - 0.1; tmp += 30.0) { - - #if ENABLED(NEWPANEL) - if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation - #endif - - int tmp_div_30 = tmp / 30.0; - if (tmp_div_30 < 0) tmp_div_30 += 360 / 30; - if (tmp_div_30 > 11) tmp_div_30 -= 360 / 30; - - float rx = circle_x + cos_table[tmp_div_30], // for speed, these are now a lookup table entry - ry = circle_y + sin_table[tmp_div_30], - xe = circle_x + cos_table[tmp_div_30 + 1], - ye = circle_y + sin_table[tmp_div_30 + 1]; - #if IS_KINEMATIC - // Check to make sure this segment is entirely on the bed, skip if not. - if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue; - #else // not, we need to skip - rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops - ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1); - xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1); - ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1); - #endif - - //if (g26_debug_flag) { - // char ccc, *cptr, seg_msg[50], seg_num[10]; - // strcpy(seg_msg, " segment: "); - // strcpy(seg_num, " \n"); - // cptr = (char*) "01234567890ABCDEF????????"; - // ccc = cptr[tmp_div_30]; - // seg_num[1] = ccc; - // strcat(seg_msg, seg_num); - // debug_current_and_destination(seg_msg); - //} - - print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height); - - } - if (look_for_lines_to_connect()) - goto LEAVE; - } - } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0); - - LEAVE: - lcd_setstatusPGM(PSTR("Leaving G26"), -1); - - retract_filament(destination); - destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; - - //debug_current_and_destination(PSTR("ready to do Z-Raise.")); - move_to(destination, 0); // Raise the nozzle - //debug_current_and_destination(PSTR("done doing Z-Raise.")); - - destination[X_AXIS] = g26_x_pos; // Move back to the starting position - destination[Y_AXIS] = g26_y_pos; - //destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is - - move_to(destination, 0); // Move back to the starting position - //debug_current_and_destination(PSTR("done doing X/Y move.")); - has_control_of_lcd_panel = false; // Give back control of the LCD Panel! - - if (!g26_keep_heaters_on) { - #if HAS_TEMP_BED - thermalManager.setTargetBed(0); - #endif - thermalManager.setTargetHotend(0, 0); + bool exit_from_g26() { + lcd_setstatusPGM(PSTR("Leaving G26"), -1); + while (is_lcd_clicked()) idle(); + return G26_ERR; } -} -float valid_trig_angle(float d) { - while (d > 360.0) d -= 360.0; - while (d < 0.0) d += 360.0; - return d; -} +#endif -mesh_index_pair unified_bed_leveling::find_closest_circle_to_print(const float &X, const float &Y) { +mesh_index_pair find_closest_circle_to_print(const float &X, const float &Y) { float closest = 99999.99; mesh_index_pair return_val; @@ -395,8 +193,8 @@ mesh_index_pair unified_bed_leveling::find_closest_circle_to_print(const float & for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) { for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) { if (!is_bit_set(circle_flags, i, j)) { - const float mx = mesh_index_to_xpos(i), // We found a circle that needs to be printed - my = mesh_index_to_ypos(j); + const float mx = _GET_MESH_X(i), // We found a circle that needs to be printed + my = _GET_MESH_Y(j); // Get the distance to this intersection float f = HYPOT(X - mx, Y - my); @@ -424,136 +222,62 @@ mesh_index_pair unified_bed_leveling::find_closest_circle_to_print(const float & return return_val; } -bool unified_bed_leveling::look_for_lines_to_connect() { - float sx, sy, ex, ey; +void G26_line_to_destination(const float &feed_rate) { + const float save_feedrate = feedrate_mm_s; + feedrate_mm_s = feed_rate; // use specified feed rate + prepare_move_to_destination(); // will ultimately call ubl.line_to_destination_cartesian or ubl.prepare_linear_move_to for UBL_DELTA + feedrate_mm_s = save_feedrate; // restore global feed rate +} - for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) { - for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) { +void move_to(const float &rx, const float &ry, const float &z, const float &e_delta) { + float feed_value; + static float last_z = -999.99; - #if ENABLED(NEWPANEL) - if (user_canceled()) return true; // Check if the user wants to stop the Mesh Validation - #endif + bool has_xy_component = (rx != current_position[X_AXIS] || ry != current_position[Y_AXIS]); // Check if X or Y is involved in the movement. - if (i < GRID_MAX_POINTS_X) { // We can't connect to anything to the right than GRID_MAX_POINTS_X. - // This is already a half circle because we are at the edge of the bed. + if (z != last_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 - if (is_bit_set(circle_flags, i, j) && is_bit_set(circle_flags, i + 1, j)) { // check if we can do a line to the left - if (!is_bit_set(horizontal_mesh_line_flags, i, j)) { + destination[X_AXIS] = current_position[X_AXIS]; + destination[Y_AXIS] = current_position[Y_AXIS]; + destination[Z_AXIS] = z; // We know the last_z==z or we wouldn't be in this block of code. + destination[E_AXIS] = current_position[E_AXIS]; - // - // We found two circles that need a horizontal line to connect them - // Print it! - // - sx = mesh_index_to_xpos( i ) + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // right edge - ex = mesh_index_to_xpos(i + 1) - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // left edge + G26_line_to_destination(feed_value); - sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1); - sy = ey = constrain(mesh_index_to_ypos(j), Y_MIN_POS + 1, Y_MAX_POS - 1); - ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1); + stepper.synchronize(); + set_destination_from_current(); + } - if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey)) { + // Check if X or Y is involved in the movement. + // Yes: a 'normal' movement. No: a retract() or recover() + feed_value = has_xy_component ? PLANNER_XY_FEEDRATE() / 10.0 : planner.max_feedrate_mm_s[E_AXIS] / 1.5; - if (g26_debug_flag) { - SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx); - SERIAL_ECHOPAIR(", sy=", sy); - SERIAL_ECHOPAIR(") -> (ex=", ex); - SERIAL_ECHOPAIR(", ey=", ey); - SERIAL_CHAR(')'); - SERIAL_EOL(); - //debug_current_and_destination(PSTR("Connecting horizontal line.")); - } + if (g26_debug_flag) SERIAL_ECHOLNPAIR("in move_to() feed_value for XY:", feed_value); - print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height); - } - bit_set(horizontal_mesh_line_flags, i, j); // Mark it as done so we don't do it again, even if we skipped it - } - } + destination[X_AXIS] = rx; + destination[Y_AXIS] = ry; + destination[E_AXIS] += e_delta; - if (j < GRID_MAX_POINTS_Y) { // We can't connect to anything further back than GRID_MAX_POINTS_Y. - // This is already a half circle because we are at the edge of the bed. - - if (is_bit_set(circle_flags, i, j) && is_bit_set(circle_flags, i, j + 1)) { // check if we can do a line straight down - if (!is_bit_set( vertical_mesh_line_flags, i, j)) { - // - // We found two circles that need a vertical line to connect them - // Print it! - // - sy = mesh_index_to_ypos( j ) + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // top edge - ey = mesh_index_to_ypos(j + 1) - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // bottom edge - - sx = ex = constrain(mesh_index_to_xpos(i), X_MIN_POS + 1, X_MAX_POS - 1); - sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1); - ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1); - - if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey)) { - - if (g26_debug_flag) { - SERIAL_ECHOPAIR(" Connecting with vertical line (sx=", sx); - SERIAL_ECHOPAIR(", sy=", sy); - SERIAL_ECHOPAIR(") -> (ex=", ex); - SERIAL_ECHOPAIR(", ey=", ey); - SERIAL_CHAR(')'); - SERIAL_EOL(); - debug_current_and_destination(PSTR("Connecting vertical line.")); - } - print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height); - } - bit_set(vertical_mesh_line_flags, i, j); // Mark it as done so we don't do it again, even if skipped - } - } - } - } - } - } - return false; -} - -void unified_bed_leveling::move_to(const float &rx, const float &ry, const float &z, const float &e_delta) { - float feed_value; - static float last_z = -999.99; - - bool has_xy_component = (rx != current_position[X_AXIS] || ry != current_position[Y_AXIS]); // Check if X or Y is involved in the movement. - - if (z != last_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 - - destination[X_AXIS] = current_position[X_AXIS]; - destination[Y_AXIS] = current_position[Y_AXIS]; - destination[Z_AXIS] = z; // We know the last_z==z or we wouldn't be in this block of code. - destination[E_AXIS] = current_position[E_AXIS]; - - G26_line_to_destination(feed_value); - - stepper.synchronize(); - set_destination_from_current(); - } - - // Check if X or Y is involved in the movement. - // Yes: a 'normal' movement. No: a retract() or recover() - 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); - - destination[X_AXIS] = rx; - destination[Y_AXIS] = ry; - destination[E_AXIS] += e_delta; - - G26_line_to_destination(feed_value); + G26_line_to_destination(feed_value); stepper.synchronize(); set_destination_from_current(); +} +FORCE_INLINE void move_to(const float where[XYZE], const float &de) { + move_to(where[X_AXIS], where[Y_AXIS], where[Z_AXIS], de); } -void unified_bed_leveling::retract_filament(const float where[XYZE]) { +void retract_filament(const float where[XYZE]) { if (!g26_retracted) { // Only retract if we are not already retracted! g26_retracted = true; move_to(where, -1.0 * g26_retraction_multiplier); } } -void unified_bed_leveling::recover_filament(const float where[XYZE]) { +void recover_filament(const float where[XYZE]) { if (g26_retracted) { // Only un-retract if we are retracted. move_to(where, 1.2 * g26_retraction_multiplier); g26_retracted = false; @@ -575,7 +299,7 @@ void unified_bed_leveling::recover_filament(const float where[XYZE]) { * segment of a 'circle'. The time this requires is very short and is easily saved by the other * cases where the optimization comes into play. */ -void unified_bed_leveling::print_line_from_here_to_there(const float &sx, const float &sy, const float &sz, const float &ex, const float &ey, const float &ez) { +void print_line_from_here_to_there(const float &sx, const float &sy, const float &sz, const float &ex, const float &ey, const float &ez) { const float dx_s = current_position[X_AXIS] - sx, // find our distance from the start of the actual line segment dy_s = current_position[Y_AXIS] - sy, dist_start = HYPOT2(dx_s, dy_s), // We don't need to do a sqrt(), we can compare the distance^2 @@ -609,32 +333,253 @@ void unified_bed_leveling::print_line_from_here_to_there(const float &sx, const move_to(ex, ey, ez, e_pos_delta); // Get to the ending point with an appropriate amount of extrusion } +inline bool look_for_lines_to_connect() { + float sx, sy, ex, ey; + + for (uint8_t i = 0; i < GRID_MAX_POINTS_X; i++) { + for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++) { + + #if ENABLED(NEWPANEL) + if (user_canceled()) return true; // Check if the user wants to stop the Mesh Validation + #endif + + if (i < GRID_MAX_POINTS_X) { // We can't connect to anything to the right than GRID_MAX_POINTS_X. + // This is already a half circle because we are at the edge of the bed. + + if (is_bit_set(circle_flags, i, j) && is_bit_set(circle_flags, i + 1, j)) { // check if we can do a line to the left + if (!is_bit_set(horizontal_mesh_line_flags, i, j)) { + + // + // We found two circles that need a horizontal line to connect them + // Print it! + // + sx = _GET_MESH_X( i ) + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // right edge + ex = _GET_MESH_X(i + 1) - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // left edge + + sx = constrain(sx, X_MIN_POS + 1, X_MAX_POS - 1); + sy = ey = constrain(_GET_MESH_Y(j), Y_MIN_POS + 1, Y_MAX_POS - 1); + ex = constrain(ex, X_MIN_POS + 1, X_MAX_POS - 1); + + if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey)) { + + if (g26_debug_flag) { + SERIAL_ECHOPAIR(" Connecting with horizontal line (sx=", sx); + SERIAL_ECHOPAIR(", sy=", sy); + SERIAL_ECHOPAIR(") -> (ex=", ex); + SERIAL_ECHOPAIR(", ey=", ey); + SERIAL_CHAR(')'); + SERIAL_EOL(); + //debug_current_and_destination(PSTR("Connecting horizontal line.")); + } + + print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height); + } + bit_set(horizontal_mesh_line_flags, i, j); // Mark it as done so we don't do it again, even if we skipped it + } + } + + if (j < GRID_MAX_POINTS_Y) { // We can't connect to anything further back than GRID_MAX_POINTS_Y. + // This is already a half circle because we are at the edge of the bed. + + if (is_bit_set(circle_flags, i, j) && is_bit_set(circle_flags, i, j + 1)) { // check if we can do a line straight down + if (!is_bit_set( vertical_mesh_line_flags, i, j)) { + // + // We found two circles that need a vertical line to connect them + // Print it! + // + sy = _GET_MESH_Y( j ) + (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // top edge + ey = _GET_MESH_Y(j + 1) - (SIZE_OF_INTERSECTION_CIRCLES - (SIZE_OF_CROSSHAIRS)); // bottom edge + + sx = ex = constrain(_GET_MESH_X(i), X_MIN_POS + 1, X_MAX_POS - 1); + sy = constrain(sy, Y_MIN_POS + 1, Y_MAX_POS - 1); + ey = constrain(ey, Y_MIN_POS + 1, Y_MAX_POS - 1); + + if (position_is_reachable(sx, sy) && position_is_reachable(ex, ey)) { + + if (g26_debug_flag) { + SERIAL_ECHOPAIR(" Connecting with vertical line (sx=", sx); + SERIAL_ECHOPAIR(", sy=", sy); + SERIAL_ECHOPAIR(") -> (ex=", ex); + SERIAL_ECHOPAIR(", ey=", ey); + SERIAL_CHAR(')'); + SERIAL_EOL(); + debug_current_and_destination(PSTR("Connecting vertical line.")); + } + print_line_from_here_to_there(sx, sy, g26_layer_height, ex, ey, g26_layer_height); + } + bit_set(vertical_mesh_line_flags, i, j); // Mark it as done so we don't do it again, even if skipped + } + } + } + } + } + } + return false; +} + +/** + * Turn on the bed and nozzle heat and + * wait for them to get up to temperature. + */ +inline bool turn_on_heaters() { + millis_t next = millis() + 5000UL; + #if HAS_TEMP_BED + #if ENABLED(ULTRA_LCD) + if (g26_bed_temp > 25) { + lcd_setstatusPGM(PSTR("G26 Heating Bed."), 99); + lcd_quick_feedback(); + lcd_external_control = true; + #endif + thermalManager.setTargetBed(g26_bed_temp); + while (abs(thermalManager.degBed() - g26_bed_temp) > 3) { + + #if ENABLED(NEWPANEL) + if (is_lcd_clicked()) return exit_from_g26(); + #endif + + if (ELAPSED(millis(), next)) { + next = millis() + 5000UL; + thermalManager.print_heaterstates(); + SERIAL_EOL(); + } + idle(); + } + #if ENABLED(ULTRA_LCD) + } + lcd_setstatusPGM(PSTR("G26 Heating Nozzle."), 99); + lcd_quick_feedback(); + #endif + #endif + + // Start heating the nozzle and wait for it to reach temperature. + thermalManager.setTargetHotend(g26_hotend_temp, 0); + while (abs(thermalManager.degHotend(0) - g26_hotend_temp) > 3) { + + #if ENABLED(NEWPANEL) + if (is_lcd_clicked()) return exit_from_g26(); + #endif + + if (ELAPSED(millis(), next)) { + next = millis() + 5000UL; + thermalManager.print_heaterstates(); + SERIAL_EOL(); + } + idle(); + } + + #if ENABLED(ULTRA_LCD) + lcd_reset_status(); + lcd_quick_feedback(); + #endif + + return G26_OK; +} + /** - * This function used to be inline code in G26. But there are so many - * parameters it made sense to turn them into static globals and get - * this code out of sight of the main routine. + * Prime the nozzle if needed. Return true on error. */ -bool unified_bed_leveling::parse_G26_parameters() { - - g26_extrusion_multiplier = EXTRUSION_MULTIPLIER; - g26_retraction_multiplier = RETRACTION_MULTIPLIER; - g26_nozzle = MESH_TEST_NOZZLE_SIZE; - g26_filament_diameter = DEFAULT_NOMINAL_FILAMENT_DIA; - g26_layer_height = MESH_TEST_LAYER_HEIGHT; - g26_prime_length = PRIME_LENGTH; - g26_bed_temp = MESH_TEST_BED_TEMP; - g26_hotend_temp = MESH_TEST_HOTEND_TEMP; - g26_prime_flag = 0; - - g26_ooze_amount = parser.linearval('O', OOZE_AMOUNT); - g26_keep_heaters_on = parser.boolval('K'); - g26_continue_with_closest = parser.boolval('C'); +bool prime_nozzle() { + + #if ENABLED(NEWPANEL) + float Total_Prime = 0.0; + + if (g26_prime_flag == -1) { // The user wants to control how much filament gets purged + + lcd_external_control = true; + lcd_setstatusPGM(PSTR("User-Controlled Prime"), 99); + lcd_chirp(); + + set_destination_from_current(); + + recover_filament(destination); // Make sure G26 doesn't think the filament is retracted(). + + while (!is_lcd_clicked()) { + lcd_chirp(); + destination[E_AXIS] += 0.25; + #ifdef PREVENT_LENGTHY_EXTRUDE + Total_Prime += 0.25; + if (Total_Prime >= EXTRUDE_MAXLENGTH) return G26_ERR; + #endif + G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0); + + stepper.synchronize(); // Without this synchronize, the purge is more consistent, + // but because the planner has a buffer, we won't be able + // to stop as quickly. So we put up with the less smooth + // action to give the user a more responsive 'Stop'. + set_destination_from_current(); + idle(); + } + + while (is_lcd_clicked()) idle(); // Debounce Encoder Wheel + + #if ENABLED(ULTRA_LCD) + strcpy_P(lcd_status_message, PSTR("Done Priming")); // We can't do lcd_setstatusPGM() without having it continue; + // So... We cheat to get a message up. + lcd_setstatusPGM(PSTR("Done Priming"), 99); + lcd_quick_feedback(); + lcd_external_control = false; + #endif + } + else + #endif + { + #if ENABLED(ULTRA_LCD) + lcd_setstatusPGM(PSTR("Fixed Length Prime."), 99); + lcd_quick_feedback(); + #endif + set_destination_from_current(); + destination[E_AXIS] += g26_prime_length; + G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0); + stepper.synchronize(); + set_destination_from_current(); + retract_filament(destination); + } + + return G26_OK; +} + +float valid_trig_angle(float d) { + while (d > 360.0) d -= 360.0; + while (d < 0.0) d += 360.0; + return d; +} + +/** + * G26: Mesh Validation Pattern generation. + * + * Used to interactively edit the mesh by placing the + * nozzle in a problem area and doing a G29 P4 R command. + */ +void GcodeSuite::G26() { + SERIAL_ECHOLNPGM("G26 command started. Waiting for heater(s)."); + float tmp, start_angle, end_angle; + int i, xi, yi; + mesh_index_pair location; + + // Don't allow Mesh Validation without homing first, + // or if the parameter parsing did not go OK, abort + if (axis_unhomed_error()) return; + + g26_extrusion_multiplier = EXTRUSION_MULTIPLIER; + g26_retraction_multiplier = RETRACTION_MULTIPLIER; + g26_layer_height = MESH_TEST_LAYER_HEIGHT; + g26_prime_length = PRIME_LENGTH; + g26_bed_temp = MESH_TEST_BED_TEMP; + g26_hotend_temp = MESH_TEST_HOTEND_TEMP; + g26_prime_flag = 0; + + float g26_nozzle = MESH_TEST_NOZZLE_SIZE, + g26_filament_diameter = DEFAULT_NOMINAL_FILAMENT_DIA, + g26_ooze_amount = parser.linearval('O', OOZE_AMOUNT); + + bool g26_continue_with_closest = parser.boolval('C'), + g26_keep_heaters_on = parser.boolval('K'); if (parser.seenval('B')) { g26_bed_temp = parser.value_celsius(); if (!WITHIN(g26_bed_temp, 15, 140)) { SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible."); - return UBL_ERR; + return G26_ERR; } } @@ -642,7 +587,7 @@ bool unified_bed_leveling::parse_G26_parameters() { g26_layer_height = parser.value_linear_units(); if (!WITHIN(g26_layer_height, 0.0, 2.0)) { SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible."); - return UBL_ERR; + return G26_ERR; } } @@ -651,12 +596,12 @@ bool unified_bed_leveling::parse_G26_parameters() { g26_retraction_multiplier = parser.value_float(); if (!WITHIN(g26_retraction_multiplier, 0.05, 15.0)) { SERIAL_PROTOCOLLNPGM("?Specified Retraction Multiplier not plausible."); - return UBL_ERR; + return G26_ERR; } } else { SERIAL_PROTOCOLLNPGM("?Retraction Multiplier must be specified."); - return UBL_ERR; + return G26_ERR; } } @@ -664,7 +609,7 @@ bool unified_bed_leveling::parse_G26_parameters() { g26_nozzle = parser.value_float(); if (!WITHIN(g26_nozzle, 0.1, 1.0)) { SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible."); - return UBL_ERR; + return G26_ERR; } } @@ -674,7 +619,7 @@ bool unified_bed_leveling::parse_G26_parameters() { g26_prime_flag = -1; #else SERIAL_PROTOCOLLNPGM("?Prime length must be specified when not using an LCD."); - return UBL_ERR; + return G26_ERR; #endif } else { @@ -682,7 +627,7 @@ bool unified_bed_leveling::parse_G26_parameters() { g26_prime_length = parser.value_linear_units(); if (!WITHIN(g26_prime_length, 0.0, 25.0)) { SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible."); - return UBL_ERR; + return G26_ERR; } } } @@ -691,7 +636,7 @@ bool unified_bed_leveling::parse_G26_parameters() { g26_filament_diameter = parser.value_linear_units(); if (!WITHIN(g26_filament_diameter, 1.0, 4.0)) { SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible."); - return UBL_ERR; + return G26_ERR; } } g26_extrusion_multiplier *= sq(1.75) / sq(g26_filament_diameter); // If we aren't using 1.75mm filament, we need to @@ -704,7 +649,7 @@ bool unified_bed_leveling::parse_G26_parameters() { g26_hotend_temp = parser.value_celsius(); if (!WITHIN(g26_hotend_temp, 165, 280)) { SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible."); - return UBL_ERR; + return G26_ERR; } } @@ -714,26 +659,27 @@ bool unified_bed_leveling::parse_G26_parameters() { random_deviation = parser.has_value() ? parser.value_float() : 50.0; } + int16_t g26_repeats; #if ENABLED(NEWPANEL) g26_repeats = parser.intval('R', GRID_MAX_POINTS + 1); #else if (!parser.seen('R')) { SERIAL_PROTOCOLLNPGM("?(R)epeat must be specified when not using an LCD."); - return UBL_ERR; + return G26_ERR; } else g26_repeats = parser.has_value() ? parser.value_int() : GRID_MAX_POINTS + 1; #endif if (g26_repeats < 1) { SERIAL_PROTOCOLLNPGM("?(R)epeat value not plausible; must be at least 1."); - return UBL_ERR; + return G26_ERR; } - g26_x_pos = parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position[X_AXIS]; - g26_y_pos = parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position[Y_AXIS]; + float g26_x_pos = parser.seenval('X') ? RAW_X_POSITION(parser.value_linear_units()) : current_position[X_AXIS], + g26_y_pos = parser.seenval('Y') ? RAW_Y_POSITION(parser.value_linear_units()) : current_position[Y_AXIS]; if (!position_is_reachable(g26_x_pos, g26_y_pos)) { SERIAL_PROTOCOLLNPGM("?Specified X,Y coordinate out of bounds."); - return UBL_ERR; + return G26_ERR; } /** @@ -741,139 +687,174 @@ bool unified_bed_leveling::parse_G26_parameters() { */ set_bed_leveling_enabled(!parser.seen('D')); - return UBL_OK; -} - -#if ENABLED(NEWPANEL) - bool unified_bed_leveling::exit_from_g26() { - lcd_setstatusPGM(PSTR("Leaving G26"), -1); - while (ubl_lcd_clicked()) idle(); - return UBL_ERR; + if (current_position[Z_AXIS] < Z_CLEARANCE_BETWEEN_PROBES) { + do_blocking_move_to_z(Z_CLEARANCE_BETWEEN_PROBES); + stepper.synchronize(); + set_current_from_destination(); } -#endif -/** - * Turn on the bed and nozzle heat and - * wait for them to get up to temperature. - */ -bool unified_bed_leveling::turn_on_heaters() { - millis_t next = millis() + 5000UL; - #if HAS_TEMP_BED - #if ENABLED(ULTRA_LCD) - if (g26_bed_temp > 25) { - lcd_setstatusPGM(PSTR("G26 Heating Bed."), 99); - lcd_quick_feedback(); - #endif - has_control_of_lcd_panel = true; - thermalManager.setTargetBed(g26_bed_temp); - while (abs(thermalManager.degBed() - g26_bed_temp) > 3) { + if (turn_on_heaters() != G26_OK) goto LEAVE; - #if ENABLED(NEWPANEL) - if (ubl_lcd_clicked()) return exit_from_g26(); - #endif + current_position[E_AXIS] = 0.0; + sync_plan_position_e(); - if (ELAPSED(millis(), next)) { - next = millis() + 5000UL; - thermalManager.print_heaterstates(); - SERIAL_EOL(); - } - idle(); - } - #if ENABLED(ULTRA_LCD) - } - lcd_setstatusPGM(PSTR("G26 Heating Nozzle."), 99); - lcd_quick_feedback(); - #endif - #endif + if (g26_prime_flag && prime_nozzle()) goto LEAVE; - // Start heating the nozzle and wait for it to reach temperature. - thermalManager.setTargetHotend(g26_hotend_temp, 0); - while (abs(thermalManager.degHotend(0) - g26_hotend_temp) > 3) { + /** + * Bed is preheated + * + * Nozzle is at temperature + * + * Filament is primed! + * + * It's "Show Time" !!! + */ - #if ENABLED(NEWPANEL) - if (ubl_lcd_clicked()) return exit_from_g26(); - #endif + ZERO(circle_flags); + ZERO(horizontal_mesh_line_flags); + ZERO(vertical_mesh_line_flags); - if (ELAPSED(millis(), next)) { - next = millis() + 5000UL; - thermalManager.print_heaterstates(); - SERIAL_EOL(); - } - idle(); - } + // Move nozzle to the specified height for the first layer + set_destination_from_current(); + destination[Z_AXIS] = g26_layer_height; + move_to(destination, 0.0); + move_to(destination, g26_ooze_amount); #if ENABLED(ULTRA_LCD) - lcd_reset_status(); - lcd_quick_feedback(); + lcd_external_control = true; #endif + //debug_current_and_destination(PSTR("Starting G26 Mesh Validation Pattern.")); - return UBL_OK; -} + /** + * Declare and generate a sin() & cos() table to be used during the circle drawing. This will lighten + * the CPU load and make the arc drawing faster and more smooth + */ + float sin_table[360 / 30 + 1], cos_table[360 / 30 + 1]; + for (i = 0; i <= 360 / 30; i++) { + cos_table[i] = SIZE_OF_INTERSECTION_CIRCLES * cos(RADIANS(valid_trig_angle(i * 30.0))); + sin_table[i] = SIZE_OF_INTERSECTION_CIRCLES * sin(RADIANS(valid_trig_angle(i * 30.0))); + } -/** - * Prime the nozzle if needed. Return true on error. - */ -bool unified_bed_leveling::prime_nozzle() { + do { + location = g26_continue_with_closest + ? find_closest_circle_to_print(current_position[X_AXIS], current_position[Y_AXIS]) + : find_closest_circle_to_print(g26_x_pos, g26_y_pos); // Find the closest Mesh Intersection to where we are now. - #if ENABLED(NEWPANEL) - float Total_Prime = 0.0; + if (location.x_index >= 0 && location.y_index >= 0) { + const float circle_x = _GET_MESH_X(location.x_index), + circle_y = _GET_MESH_Y(location.y_index); - if (g26_prime_flag == -1) { // The user wants to control how much filament gets purged + // If this mesh location is outside the printable_radius, skip it. - has_control_of_lcd_panel = true; - lcd_setstatusPGM(PSTR("User-Controlled Prime"), 99); - chirp_at_user(); + if (!position_is_reachable(circle_x, circle_y)) continue; - set_destination_from_current(); + xi = location.x_index; // Just to shrink the next few lines and make them easier to understand + yi = location.y_index; - recover_filament(destination); // Make sure G26 doesn't think the filament is retracted(). + if (g26_debug_flag) { + SERIAL_ECHOPAIR(" Doing circle at: (xi=", xi); + SERIAL_ECHOPAIR(", yi=", yi); + SERIAL_CHAR(')'); + SERIAL_EOL(); + } - while (!ubl_lcd_clicked()) { - chirp_at_user(); - destination[E_AXIS] += 0.25; - #ifdef PREVENT_LENGTHY_EXTRUDE - Total_Prime += 0.25; - if (Total_Prime >= EXTRUDE_MAXLENGTH) return UBL_ERR; + start_angle = 0.0; // assume it is going to be a full circle + end_angle = 360.0; + if (xi == 0) { // Check for bottom edge + start_angle = -90.0; + end_angle = 90.0; + if (yi == 0) // it is an edge, check for the two left corners + start_angle = 0.0; + else if (yi == GRID_MAX_POINTS_Y - 1) + end_angle = 0.0; + } + else if (xi == GRID_MAX_POINTS_X - 1) { // Check for top edge + start_angle = 90.0; + end_angle = 270.0; + if (yi == 0) // it is an edge, check for the two right corners + end_angle = 180.0; + else if (yi == GRID_MAX_POINTS_Y - 1) + start_angle = 180.0; + } + else if (yi == 0) { + start_angle = 0.0; // only do the top side of the cirlce + end_angle = 180.0; + } + else if (yi == GRID_MAX_POINTS_Y - 1) { + start_angle = 180.0; // only do the bottom side of the cirlce + end_angle = 360.0; + } + + for (tmp = start_angle; tmp < end_angle - 0.1; tmp += 30.0) { + + #if ENABLED(NEWPANEL) + if (user_canceled()) goto LEAVE; // Check if the user wants to stop the Mesh Validation #endif - G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0); - stepper.synchronize(); // Without this synchronize, the purge is more consistent, - // but because the planner has a buffer, we won't be able - // to stop as quickly. So we put up with the less smooth - // action to give the user a more responsive 'Stop'. - set_destination_from_current(); - idle(); - } + int tmp_div_30 = tmp / 30.0; + if (tmp_div_30 < 0) tmp_div_30 += 360 / 30; + if (tmp_div_30 > 11) tmp_div_30 -= 360 / 30; - while (ubl_lcd_clicked()) idle(); // Debounce Encoder Wheel + float rx = circle_x + cos_table[tmp_div_30], // for speed, these are now a lookup table entry + ry = circle_y + sin_table[tmp_div_30], + xe = circle_x + cos_table[tmp_div_30 + 1], + ye = circle_y + sin_table[tmp_div_30 + 1]; + #if IS_KINEMATIC + // Check to make sure this segment is entirely on the bed, skip if not. + if (!position_is_reachable(rx, ry) || !position_is_reachable(xe, ye)) continue; + #else // not, we need to skip + rx = constrain(rx, X_MIN_POS + 1, X_MAX_POS - 1); // This keeps us from bumping the endstops + ry = constrain(ry, Y_MIN_POS + 1, Y_MAX_POS - 1); + xe = constrain(xe, X_MIN_POS + 1, X_MAX_POS - 1); + ye = constrain(ye, Y_MIN_POS + 1, Y_MAX_POS - 1); + #endif - #if ENABLED(ULTRA_LCD) - strcpy_P(lcd_status_message, PSTR("Done Priming")); // We can't do lcd_setstatusPGM() without having it continue; - // So... We cheat to get a message up. - lcd_setstatusPGM(PSTR("Done Priming"), 99); - lcd_quick_feedback(); - #endif + //if (g26_debug_flag) { + // char ccc, *cptr, seg_msg[50], seg_num[10]; + // strcpy(seg_msg, " segment: "); + // strcpy(seg_num, " \n"); + // cptr = (char*) "01234567890ABCDEF????????"; + // ccc = cptr[tmp_div_30]; + // seg_num[1] = ccc; + // strcat(seg_msg, seg_num); + // debug_current_and_destination(seg_msg); + //} - has_control_of_lcd_panel = false; + print_line_from_here_to_there(rx, ry, g26_layer_height, xe, ye, g26_layer_height); + } + if (look_for_lines_to_connect()) + goto LEAVE; } - else { - #else - { + } while (--g26_repeats && location.x_index >= 0 && location.y_index >= 0); + + LEAVE: + lcd_setstatusPGM(PSTR("Leaving G26"), -1); + + retract_filament(destination); + destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; + + //debug_current_and_destination(PSTR("ready to do Z-Raise.")); + move_to(destination, 0); // Raise the nozzle + //debug_current_and_destination(PSTR("done doing Z-Raise.")); + + destination[X_AXIS] = g26_x_pos; // Move back to the starting position + destination[Y_AXIS] = g26_y_pos; + //destination[Z_AXIS] = Z_CLEARANCE_BETWEEN_PROBES; // Keep the nozzle where it is + + move_to(destination, 0); // Move back to the starting position + //debug_current_and_destination(PSTR("done doing X/Y move.")); + + #if ENABLED(ULTRA_LCD) + lcd_external_control = false; // Give back control of the LCD Panel! #endif - #if ENABLED(ULTRA_LCD) - lcd_setstatusPGM(PSTR("Fixed Length Prime."), 99); - lcd_quick_feedback(); + + if (!g26_keep_heaters_on) { + #if HAS_TEMP_BED + thermalManager.setTargetBed(0); #endif - set_destination_from_current(); - destination[E_AXIS] += g26_prime_length; - G26_line_to_destination(planner.max_feedrate_mm_s[E_AXIS] / 15.0); - stepper.synchronize(); - set_destination_from_current(); - retract_filament(destination); + thermalManager.setTargetHotend(0, 0); } - - return UBL_OK; } -#endif // UBL_G26_MESH_VALIDATION +#endif // G26_MESH_VALIDATION diff --git a/Marlin/src/gcode/bedlevel/G42.cpp b/Marlin/src/gcode/bedlevel/G42.cpp index 8f1ab7dae0..727e4cf1da 100644 --- a/Marlin/src/gcode/bedlevel/G42.cpp +++ b/Marlin/src/gcode/bedlevel/G42.cpp @@ -44,17 +44,6 @@ void GcodeSuite::G42() { return; } - #if ENABLED(AUTO_BED_LEVELING_BILINEAR) - #define _GET_MESH_X(I) bilinear_start[X_AXIS] + I * bilinear_grid_spacing[X_AXIS] - #define _GET_MESH_Y(J) bilinear_start[Y_AXIS] + J * bilinear_grid_spacing[Y_AXIS] - #elif ENABLED(AUTO_BED_LEVELING_UBL) - #define _GET_MESH_X(I) ubl.mesh_index_to_xpos(I) - #define _GET_MESH_Y(J) ubl.mesh_index_to_ypos(J) - #elif ENABLED(MESH_BED_LEVELING) - #define _GET_MESH_X(I) mbl.index_to_xpos[I] - #define _GET_MESH_Y(J) mbl.index_to_ypos[J] - #endif - set_destination_from_current(); if (hasI) destination[X_AXIS] = _GET_MESH_X(ix); if (hasJ) destination[Y_AXIS] = _GET_MESH_Y(iy); diff --git a/Marlin/src/gcode/bedlevel/ubl/G26.cpp b/Marlin/src/gcode/bedlevel/ubl/G26.cpp deleted file mode 100644 index ccec2fae55..0000000000 --- a/Marlin/src/gcode/bedlevel/ubl/G26.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Marlin 3D Printer Firmware - * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin] - * - * Based on Sprinter and grbl. - * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -/** - * G26.cpp - Unified Bed Leveling - */ - -#include "../../../inc/MarlinConfig.h" - -#if ENABLED(UBL_G26_MESH_VALIDATION) - -#include "../../gcode.h" -#include "../../../feature/bedlevel/ubl/ubl.h" - -void GcodeSuite::G26() { ubl.G26(); } - -#endif // UBL_G26_MESH_VALIDATION diff --git a/Marlin/src/gcode/bedlevel/ubl/M421.cpp b/Marlin/src/gcode/bedlevel/ubl/M421.cpp index 83c8cbbc39..72a9aa9039 100644 --- a/Marlin/src/gcode/bedlevel/ubl/M421.cpp +++ b/Marlin/src/gcode/bedlevel/ubl/M421.cpp @@ -29,7 +29,7 @@ #if ENABLED(AUTO_BED_LEVELING_UBL) #include "../../gcode.h" -#include "../../../feature/bedlevel/ubl/ubl.h" +#include "../../../feature/bedlevel/bedlevel.h" /** * M421: Set a single Mesh Bed Leveling Z coordinate diff --git a/Marlin/src/gcode/bedlevel/ubl/M49.cpp b/Marlin/src/gcode/bedlevel/ubl/M49.cpp index bc80c9842e..cdb0cf0ed1 100644 --- a/Marlin/src/gcode/bedlevel/ubl/M49.cpp +++ b/Marlin/src/gcode/bedlevel/ubl/M49.cpp @@ -21,20 +21,20 @@ */ /** - * M49.cpp - Unified Bed Leveling + * M49.cpp - Toggle the G26 debug flag */ #include "../../../inc/MarlinConfig.h" -#if ENABLED(UBL_G26_MESH_VALIDATION) +#if ENABLED(G26_MESH_VALIDATION) #include "../../gcode.h" #include "../../../feature/bedlevel/bedlevel.h" void GcodeSuite::M49() { - ubl.g26_debug_flag ^= true; - SERIAL_PROTOCOLPGM("UBL Debug Flag turned "); - serialprintPGM(ubl.g26_debug_flag ? PSTR("on.") : PSTR("off.")); + g26_debug_flag ^= true; + SERIAL_PROTOCOLPGM("G26 Debug "); + serialprintPGM(g26_debug_flag ? PSTR("on.") : PSTR("off.")); } -#endif // UBL_G26_MESH_VALIDATION +#endif // G26_MESH_VALIDATION diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index 958c4e017f..fdb73256b0 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -207,7 +207,7 @@ void GcodeSuite::process_parsed_command() { break; #endif // INCH_MODE_SUPPORT - #if ENABLED(UBL_G26_MESH_VALIDATION) + #if ENABLED(G26_MESH_VALIDATION) case 26: // G26: Mesh Validation Pattern generation G26(); break; @@ -342,7 +342,7 @@ void GcodeSuite::process_parsed_command() { case 48: M48(); break; // M48: Z probe repeatability test #endif - #if ENABLED(UBL_G26_MESH_VALIDATION) + #if ENABLED(G26_MESH_VALIDATION) case 49: M49(); break; // M49: Turn on or off G26 debug flag for verbose output #endif diff --git a/Marlin/src/gcode/gcode.h b/Marlin/src/gcode/gcode.h index 24d0d3f078..7f89004ac2 100644 --- a/Marlin/src/gcode/gcode.h +++ b/Marlin/src/gcode/gcode.h @@ -55,7 +55,7 @@ * G19 - Select Plane YZ (Requires CNC_WORKSPACE_PLANES) * G20 - Set input units to inches (Requires INCH_MODE_SUPPORT) * G21 - Set input units to millimeters (Requires INCH_MODE_SUPPORT) - * G26 - Mesh Validation Pattern (Requires UBL_G26_MESH_VALIDATION) + * G26 - Mesh Validation Pattern (Requires G26_MESH_VALIDATION) * G27 - Park Nozzle (Requires NOZZLE_PARK_FEATURE) * G28 - Home one or more axes * G29 - Start or continue the bed leveling probe procedure (Requires bed leveling) @@ -357,7 +357,7 @@ private: static void G21(); #endif - #if ENABLED(UBL_G26_MESH_VALIDATION) + #if ENABLED(G26_MESH_VALIDATION) static void G26(); #endif @@ -453,7 +453,7 @@ private: static void M48(); #endif - #if ENABLED(UBL_G26_MESH_VALIDATION) + #if ENABLED(G26_MESH_VALIDATION) static void M49(); #endif diff --git a/Marlin/src/inc/MarlinConfig.h b/Marlin/src/inc/MarlinConfig.h index cb8e54af18..ac47b0962d 100644 --- a/Marlin/src/inc/MarlinConfig.h +++ b/Marlin/src/inc/MarlinConfig.h @@ -20,8 +20,8 @@ * */ -#ifndef MARLIN_CONFIG_H -#define MARLIN_CONFIG_H +#ifndef _MARLIN_CONFIG_H_ +#define _MARLIN_CONFIG_H_ #include "MarlinConfigPre.h" @@ -36,8 +36,7 @@ // Include all core headers #include "../core/enum.h" #include "../core/language.h" -#include "../core/types.h" #include "../core/utility.h" #include "../core/serial.h" -#endif // MARLIN_CONFIG_H +#endif // _MARLIN_CONFIG_H_ diff --git a/Marlin/src/inc/MarlinConfigPre.h b/Marlin/src/inc/MarlinConfigPre.h index 62831e37ab..fb7258fb0a 100644 --- a/Marlin/src/inc/MarlinConfigPre.h +++ b/Marlin/src/inc/MarlinConfigPre.h @@ -20,8 +20,8 @@ * */ -#ifndef MARLIN_CONFIGPRE_H -#define MARLIN_CONFIGPRE_H +#ifndef _MARLIN_CONFIGPRE_H_ +#define _MARLIN_CONFIGPRE_H_ #include "../core/boards.h" #include "../core/macros.h" @@ -31,4 +31,6 @@ #include "../../Configuration_adv.h" #include "Conditionals_adv.h" -#endif // MARLIN_CONFIGPRE_H +#include "../core/types.h" + +#endif // _MARLIN_CONFIGPRE_H_ diff --git a/Marlin/src/lcd/ultralcd.cpp b/Marlin/src/lcd/ultralcd.cpp index b1ebb29258..ef97797a3a 100644 --- a/Marlin/src/lcd/ultralcd.cpp +++ b/Marlin/src/lcd/ultralcd.cpp @@ -60,6 +60,10 @@ #include "../libs/buzzer.h" #endif +#if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION) + bool lcd_external_control; // = false +#endif + // Initialized by settings.load() int16_t lcd_preheat_hotend_temp[2], lcd_preheat_bed_temp[2], lcd_preheat_fan_speed[2]; @@ -4599,7 +4603,7 @@ void lcd_update() { #if ENABLED(AUTO_BED_LEVELING_UBL) // Don't run the debouncer if UBL owns the display - #define UBL_CONDITION !ubl.has_control_of_lcd_panel + #define UBL_CONDITION !lcd_external_control #else #define UBL_CONDITION true #endif @@ -5070,7 +5074,7 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; } case encrot3: ENCODER_SPIN(encrot2, encrot0); break; } #if ENABLED(AUTO_BED_LEVELING_UBL) - if (ubl.has_control_of_lcd_panel) { + if (lcd_external_control) { 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 // knob has not turned. @@ -5086,14 +5090,14 @@ void lcd_reset_alert_level() { lcd_status_message_level = 0; } bool lcd_detected() { return true; } #endif - #if ENABLED(AUTO_BED_LEVELING_UBL) - - void chirp_at_user() { + #if ENABLED(G26_MESH_VALIDATION) + void lcd_chirp() { lcd_buzz(LCD_FEEDBACK_FREQUENCY_DURATION_MS, LCD_FEEDBACK_FREQUENCY_HZ); } + #endif - bool ubl_lcd_clicked() { return LCD_CLICKED; } - + #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION) + bool is_lcd_clicked() { return LCD_CLICKED; } #endif #endif // ULTIPANEL diff --git a/Marlin/src/lcd/ultralcd.h b/Marlin/src/lcd/ultralcd.h index 0301cf4f57..b0389d9e9d 100644 --- a/Marlin/src/lcd/ultralcd.h +++ b/Marlin/src/lcd/ultralcd.h @@ -29,6 +29,12 @@ #include "../Marlin.h" + #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION) + extern bool lcd_external_control; + #else + constexpr bool lcd_external_control = false; + #endif + #define BUTTON_EXISTS(BN) (defined(BTN_## BN) && BTN_## BN >= 0) #define BUTTON_PRESSED(BN) !READ(BTN_## BN) @@ -123,6 +129,10 @@ void lcd_advanced_pause_show_message(const AdvancedPauseMessage message); #endif + #if ENABLED(G26_MESH_VALIDATION) + void lcd_chirp(); + #endif + #if ENABLED(AUTO_BED_LEVELING_UBL) void lcd_mesh_edit_setup(float initial); float lcd_mesh_edit(); @@ -208,6 +218,10 @@ #define LCD_CLICKED false #endif + #if ENABLED(AUTO_BED_LEVELING_UBL) || ENABLED(G26_MESH_VALIDATION) + bool is_lcd_clicked(); + #endif + #else // no LCD inline void lcd_update() {}