diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 78929e9f..d91f74fb 100644 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -21,6 +21,7 @@ #include "Configuration.h" #include "pins.h" #include "Timer.h" +extern int mbl_z_probe_nr; #ifndef AT90USB #define HardwareSerial_h // trick to disable the standard HWserial diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d70e66ea..084241c5 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -167,6 +167,7 @@ CardReader card; unsigned long PingTime = _millis(); unsigned long NcTime; +int mbl_z_probe_nr = 4; //numer of Z measurements for each point in mesh bed leveling calibration //used for PINDA temp calibration and pause print #define DEFAULT_RETRACTION 1 @@ -1465,7 +1466,8 @@ void setup() if (eeprom_read_byte((uint8_t*)EEPROM_SD_SORT) == 255) { eeprom_write_byte((uint8_t*)EEPROM_SD_SORT, 0); } - mbl_mode_init(); + //mbl_mode_init(); + mbl_settings_init(); check_babystep(); //checking if Z babystep is in allowed range #ifdef UVLO_SUPPORT @@ -4325,6 +4327,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) */ case 80: + #ifdef MK1BP break; #endif //MK1BP @@ -4363,6 +4366,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) nMeasPoints = 3; } } + else { + nMeasPoints = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); + } uint8_t nProbeRetry = 3; if (code_seen('R')) { @@ -4371,6 +4377,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) nProbeRetry = 10; } } + else { + nProbeRetry = eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR) - 1; + } + bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0); bool temp_comp_start = true; #ifdef PINDA_THERMISTOR @@ -4670,7 +4680,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) if (nMeasPoints == 3) { mbl.upsample_3x3(); //interpolation from 3x3 to 7x7 points using largrangian polynomials while using the same array z_values[iy][ix] for storing (just coppying measured data to new destination and interpolating between them) } - if (nMeasPoints == 7) { + if (nMeasPoints == 7 && magnet_elimination) { mbl_interpolation(nMeasPoints); } // SERIAL_ECHOLNPGM("Upsample finished"); diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 3dc0a092..8a15248e 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -156,6 +156,9 @@ #define EEPROM_MMU_CUTTER_ENABLED (EEPROM_MMU_LOAD_FAIL - 1) #define EEPROM_UVLO_MESH_BED_LEVELING_FULL (EEPROM_MMU_CUTTER_ENABLED - 12*12*2) //allow 12 calibration points for future expansion #define EEPROM_MBL_TYPE (EEPROM_UVLO_MESH_BED_LEVELING_FULL-1) //uint8_t for mesh bed leveling precision +#define EEPROM_MBL_MAGNET_ELIMINATION (EEPROM_MBL_TYPE -1) +#define EEPROM_MBL_POINTS_NR (EEPROM_MBL_MAGNET_ELIMINATION -1) //uint8_t number of points in one exis for mesh bed leveling +#define EEPROM_MBL_PROBE_NR (EEPROM_MBL_POINTS_NR-1) // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index c5fc5829..9b3c78f1 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -985,7 +985,7 @@ inline bool find_bed_induction_sensor_point_z(float minimum_z, uint8_t n_iter, i // SERIAL_ECHOLNPGM(""); float dz = i?abs(current_position[Z_AXIS] - (z / i)):0; z += current_position[Z_AXIS]; -// printf_P(PSTR(" Z[%d] = %d, dz=%d\n"), i, (int)(current_position[Z_AXIS] * 1000), (int)(dz * 1000)); + printf_P(PSTR("Z[%d] = %d, dz=%d\n"), i, (int)(current_position[Z_AXIS] * 1000), (int)(dz * 1000)); if (dz > 0.05) goto error;//deviation > 50um } current_position[Z_AXIS] = z; @@ -3048,7 +3048,7 @@ void count_xyz_details(float (&distanceMin)[2]) { distanceMin[mesh_point] = (y - Y_MIN_POS_CALIBRATION_POINT_OUT_OF_REACH); } } - +/* e_MBL_TYPE e_mbl_type = e_MBL_OPTIMAL; void mbl_mode_set() { @@ -3066,6 +3066,24 @@ void mbl_mode_init() { if (mbl_type == 0xFF) e_mbl_type = e_MBL_OPTIMAL; else e_mbl_type = mbl_type; } +*/ + +void mbl_settings_init() { +//3x3 mesh; 3 Z-probes on each point, magnet elimination on +//magnet elimination: use aaproximate Z-coordinate instead of measured values for points which are near magnets + if (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) == 0xFF) { + eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, 1); + } + if (eeprom_read_byte((uint8_t*)EEPROM_MBL_PROBE_NR) == 0xFF) { + eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, 3); + } + mbl_z_probe_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); + if (mbl_z_probe_nr == 0xFF) { + mbl_z_probe_nr = 4; + eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mbl_z_probe_nr); + } + +} bool mbl_point_measurement_valid(uint8_t ix, uint8_t iy, uint8_t meas_points, bool zigzag) { //"human readable" heatbed plan diff --git a/Firmware/mesh_bed_calibration.h b/Firmware/mesh_bed_calibration.h index 7fd8011c..954db9c3 100644 --- a/Firmware/mesh_bed_calibration.h +++ b/Firmware/mesh_bed_calibration.h @@ -200,15 +200,16 @@ extern void babystep_reset(); extern void count_xyz_details(float (&distanceMin)[2]); extern bool sample_z(); - +/* typedef enum { e_MBL_FAST, e_MBL_OPTIMAL, e_MBL_PREC } e_MBL_TYPE; - -extern e_MBL_TYPE e_mbl_type; -extern void mbl_mode_set(); -extern void mbl_mode_init(); +*/ +//extern e_MBL_TYPE e_mbl_type; +//extern void mbl_mode_set(); +//extern void mbl_mode_init(); +extern void mbl_settings_init(); extern bool mbl_point_measurement_valid(uint8_t ix, uint8_t iy, uint8_t meas_points, bool zigzag); extern void mbl_interpolation(uint8_t meas_points); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 4e3d76b4..77492ac0 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -47,6 +47,7 @@ char longFilenameOLD[LONG_FILENAME_LENGTH]; static void lcd_sd_updir(); +static void lcd_mesh_bed_leveling_settings(); int8_t ReInitLCD = 0; @@ -5325,6 +5326,7 @@ do\ while (0) #endif // SDCARD_SORT_ALPHA +/* #define SETTINGS_MBL_MODE \ do\ {\ @@ -5345,7 +5347,7 @@ do\ }\ }\ while (0) - +*/ #define SETTINGS_SOUND \ do\ @@ -5395,7 +5397,7 @@ static void lcd_settings_menu() SETTINGS_SILENT_MODE; - MENU_ITEM_SUBMENU_P(_i("Mesh bed leveling"), lcd_mesh_bed_leveling_settings);////MSG_TEMPERATURE c=0 r=0 + MENU_ITEM_SUBMENU_P(_i("Mesh bed leveling"), lcd_mesh_bed_leveling_settings);////MSG_MBL_SETTINGS c=18 r=1 #if defined (TMC2130) && defined (LINEARITY_CORRECTION) MENU_ITEM_SUBMENU_P(_i("Lin. correction"), lcd_settings_linearity_correction_menu); @@ -6632,10 +6634,46 @@ static void lcd_tune_menu() MENU_END(); } -static void mesh_bed_leveling_menu() -{ +static void mbl_magnets_elimination_set() { + bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0); + magnet_elimination = !magnet_elimination; + eeprom_update_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION, (uint8_t)magnet_elimination); +} - SETTINGS_MBL_MODE; +static void mbl_mesh_set() { + uint8_t mesh_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); + if(mesh_nr == 3) mesh_nr = 7; + else mesh_nr = 3; + eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mesh_nr); +} + +static void lcd_mesh_bed_leveling_settings() +{ + + bool magnet_elimination = (eeprom_read_byte((uint8_t*)EEPROM_MBL_MAGNET_ELIMINATION) > 0); + uint8_t points_nr = eeprom_read_byte((uint8_t*)EEPROM_MBL_POINTS_NR); + + MENU_BEGIN(); + // leaving menu - this condition must be immediately before MENU_ITEM_BACK_P + if (((menu_item == menu_line) && menu_clicked && (lcd_encoder == menu_item)) || menu_leaving) + { + eeprom_update_byte((uint8_t*)EEPROM_MBL_PROBE_NR, (uint8_t)mbl_z_probe_nr); + } + MENU_ITEM_BACK_P(_T(MSG_SETTINGS)); + if(points_nr == 3) MENU_ITEM_FUNCTION_P(_i("Mesh [3x3]"), mbl_mesh_set); + else MENU_ITEM_FUNCTION_P(_i("Mesh [7x7]"), mbl_mesh_set); + MENU_ITEM_EDIT_int3_P(_i("Probe nr."), &mbl_z_probe_nr, 1, 5); + if (points_nr == 7) { + if (magnet_elimination) MENU_ITEM_FUNCTION_P(_i("Magnets eli [On]"), mbl_magnets_elimination_set); + else MENU_ITEM_FUNCTION_P(_i("Magnets eli [Off]"), mbl_magnets_elimination_set); + } + else menu_item_text_P(_i("MAgnets eli [N/A]")); + MENU_END(); + /*if(menu_leaving) + { + eeprom_update_byte((uint8_t*)EEPROM_MBL_POINTS_NR, mbl_z_probe_nr); + }*/ + //SETTINGS_MBL_MODE; } static void lcd_control_temperature_menu()