|
@@ -3838,6 +3838,17 @@ void process_commands()
|
|
|
} else if(code_seen("FR")) {
|
|
|
|
|
|
factory_reset(0);
|
|
|
+ } else if(code_seen("MBL")) {
|
|
|
+
|
|
|
+ if(code_seen("V")) {
|
|
|
+ bool value = code_value_short();
|
|
|
+ st_synchronize();
|
|
|
+ if(value != mbl.active) {
|
|
|
+ mbl.active = value;
|
|
|
+
|
|
|
+ plan_set_z_position(current_position[Z_AXIS]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
|
@@ -10492,15 +10503,11 @@ void uvlo_()
|
|
|
tmc2130_set_current_r(E_AXIS, 20);
|
|
|
#endif
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- uint16_t z_microsteps = 0;
|
|
|
-#ifdef TMC2130
|
|
|
- z_microsteps = tmc2130_rd_MSCNT(Z_TMC2130_CS);
|
|
|
-#endif
|
|
|
+
|
|
|
+ uint8_t saved_target_temperature_bed = target_temperature_bed;
|
|
|
+ uint8_t saved_target_temperature_ext = target_temperature[active_extruder];
|
|
|
+ setAllTargetHotends(0);
|
|
|
+ setTargetBed(0);
|
|
|
|
|
|
|
|
|
long sd_position = sdpos_atomic;
|
|
@@ -10525,40 +10532,52 @@ void uvlo_()
|
|
|
feedrate_bckp = feedrate;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ bool mbl_was_active = mbl.active;
|
|
|
+ mbl.active = false;
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
planner_abort_hard();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+ float logical_z = current_position[Z_AXIS];
|
|
|
+ if(mbl_was_active) logical_z -= mbl.get_z(st_get_position_mm(X_AXIS), st_get_position_mm(Y_AXIS));
|
|
|
+ eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z, logical_z);
|
|
|
+
|
|
|
+
|
|
|
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), current_position[E_AXIS]);
|
|
|
eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1);
|
|
|
|
|
|
|
|
|
cmdqueue_reset();
|
|
|
card.sdprinting = false;
|
|
|
-
|
|
|
saved_printing = true;
|
|
|
|
|
|
|
|
|
|
|
|
sei();
|
|
|
|
|
|
-
|
|
|
- plan_buffer_line(current_position[X_AXIS],
|
|
|
- current_position[Y_AXIS],
|
|
|
- current_position[Z_AXIS],
|
|
|
- current_position[E_AXIS] - default_retraction,
|
|
|
- 95, active_extruder);
|
|
|
+
|
|
|
+ current_position[E_AXIS] -= default_retraction;
|
|
|
+ plan_buffer_line_curposXYZE(95, active_extruder);
|
|
|
st_synchronize();
|
|
|
disable_e0();
|
|
|
|
|
|
-
|
|
|
- plan_buffer_line(current_position[X_AXIS],
|
|
|
- current_position[Y_AXIS],
|
|
|
- current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS],
|
|
|
- current_position[E_AXIS] - default_retraction,
|
|
|
- 40, active_extruder);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ uint16_t z_res = tmc2130_get_res(Z_AXIS);
|
|
|
+ uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
|
|
|
+ current_position[Z_AXIS] += float(1024 - z_microsteps)
|
|
|
+ / (z_res * cs.axis_steps_per_unit[Z_AXIS])
|
|
|
+ + UVLO_Z_AXIS_SHIFT;
|
|
|
+ plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60, active_extruder);
|
|
|
st_synchronize();
|
|
|
disable_z();
|
|
|
|
|
@@ -10570,24 +10589,24 @@ void uvlo_()
|
|
|
uint8_t ix = mesh_point % MESH_NUM_X_POINTS;
|
|
|
uint8_t iy = mesh_point / MESH_NUM_X_POINTS;
|
|
|
|
|
|
- int16_t v = mbl.active ? int16_t(floor(mbl.z_values[iy][ix] * 1000.f + 0.5f)) : 0;
|
|
|
+ int16_t v = mbl_was_active ? int16_t(floor(mbl.z_values[iy][ix] * 1000.f + 0.5f)) : 0;
|
|
|
eeprom_update_word((uint16_t*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL +2*mesh_point), *reinterpret_cast<uint16_t*>(&v));
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
+
|
|
|
+ eeprom_update_float((float*)EEPROM_UVLO_TINY_CURRENT_POSITION_Z, current_position[Z_AXIS]);
|
|
|
+ z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
|
|
|
eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps);
|
|
|
|
|
|
|
|
|
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]);
|
|
|
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]);
|
|
|
- eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z , current_position[Z_AXIS]);
|
|
|
|
|
|
|
|
|
eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDRATE, feedrate_bckp);
|
|
|
eeprom_update_word((uint16_t*)EEPROM_UVLO_FEEDMULTIPLY, feedmultiply);
|
|
|
- eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]);
|
|
|
- eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed);
|
|
|
+ eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, saved_target_temperature_ext);
|
|
|
+ eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, saved_target_temperature_bed);
|
|
|
eeprom_update_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED, fanSpeed);
|
|
|
eeprom_update_float((float*)(EEPROM_EXTRUDER_MULTIPLIER_0), extruder_multiplier[0]);
|
|
|
#if EXTRUDERS > 1
|
|
@@ -10611,9 +10630,6 @@ void uvlo_()
|
|
|
|
|
|
if(sd_print) eeprom_update_byte((uint8_t*)EEPROM_UVLO, 1);
|
|
|
|
|
|
- st_synchronize();
|
|
|
- printf_P(_N("stps%d\n"), tmc2130_rd_MSCNT(Z_AXIS));
|
|
|
-
|
|
|
|
|
|
eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1);
|
|
|
eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1);
|
|
@@ -10634,44 +10650,68 @@ void uvlo_()
|
|
|
|
|
|
void uvlo_tiny()
|
|
|
{
|
|
|
-uint16_t z_microsteps=0;
|
|
|
+ unsigned long time_start = _millis();
|
|
|
|
|
|
-
|
|
|
-disable_x();
|
|
|
-disable_y();
|
|
|
-disable_e0();
|
|
|
-
|
|
|
-#ifdef TMC2130
|
|
|
-tmc2130_set_current_h(Z_AXIS, 20);
|
|
|
-tmc2130_set_current_r(Z_AXIS, 20);
|
|
|
-#endif
|
|
|
+
|
|
|
+ disable_x();
|
|
|
+ disable_y();
|
|
|
+ disable_e0();
|
|
|
|
|
|
-
|
|
|
#ifdef TMC2130
|
|
|
-z_microsteps=tmc2130_rd_MSCNT(Z_TMC2130_CS);
|
|
|
+ tmc2130_set_current_h(Z_AXIS, 20);
|
|
|
+ tmc2130_set_current_r(Z_AXIS, 20);
|
|
|
#endif
|
|
|
-planner_abort_hard();
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-if(eeprom_read_byte((uint8_t*)EEPROM_UVLO)!=2){
|
|
|
- eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]);
|
|
|
- eeprom_update_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS),z_microsteps);
|
|
|
-}
|
|
|
+
|
|
|
+ setAllTargetHotends(0);
|
|
|
+ setTargetBed(0);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-if(eeprom_read_float((float*)EEPROM_UVLO_TINY_CURRENT_POSITION_Z) < 0.001f){
|
|
|
- eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), eeprom_read_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z));
|
|
|
- eeprom_update_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS), eeprom_read_word((uint16_t*)EEPROM_UVLO_Z_MICROSTEPS));
|
|
|
-}
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ mbl.active = false;
|
|
|
+ planner_abort_hard();
|
|
|
+
|
|
|
+
|
|
|
+ if(abs(current_position[Z_AXIS] - eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z))) >= 1.f/cs.axis_steps_per_unit[Z_AXIS])
|
|
|
+ {
|
|
|
+
|
|
|
+ cmdqueue_reset();
|
|
|
+ card.sdprinting = false;
|
|
|
+ saved_printing = true;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sei();
|
|
|
+
|
|
|
+
|
|
|
+ uint16_t z_res = tmc2130_get_res(Z_AXIS);
|
|
|
+ uint16_t z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
|
|
|
+ current_position[Z_AXIS] += float(1024 - z_microsteps)
|
|
|
+ / (z_res * cs.axis_steps_per_unit[Z_AXIS])
|
|
|
+ + UVLO_TINY_Z_AXIS_SHIFT;
|
|
|
+ plan_buffer_line_curposXYZE(homing_feedrate[Z_AXIS]/60, active_extruder);
|
|
|
+ st_synchronize();
|
|
|
+ disable_z();
|
|
|
+
|
|
|
+
|
|
|
+ eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]);
|
|
|
+
|
|
|
+
|
|
|
+ z_microsteps = tmc2130_rd_MSCNT(Z_AXIS);
|
|
|
+ eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ eeprom_update_byte((uint8_t*)EEPROM_UVLO,2);
|
|
|
+
|
|
|
+
|
|
|
+ eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1);
|
|
|
+ eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1);
|
|
|
|
|
|
-
|
|
|
-eeprom_update_byte((uint8_t*)EEPROM_UVLO,2);
|
|
|
+ printf_P(_N("UVLO_TINY - end %d\n"), _millis() - time_start);
|
|
|
|
|
|
-
|
|
|
-eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1);
|
|
|
-eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1);
|
|
|
|
|
|
wdt_enable(WDTO_1S);
|
|
|
WRITE(BEEPER,HIGH);
|
|
@@ -10744,13 +10784,16 @@ void recover_print(uint8_t automatic) {
|
|
|
lcd_update(2);
|
|
|
lcd_setstatuspgm(_i("Recovering print "));
|
|
|
|
|
|
- bool bTiny=(eeprom_read_byte((uint8_t*)EEPROM_UVLO)==2);
|
|
|
- recover_machine_state_after_power_panic(bTiny);
|
|
|
-
|
|
|
- if(!bTiny&&(current_position[Z_AXIS]<25))
|
|
|
- enquecommand_P(PSTR("G1 Z25 F800"));
|
|
|
+
|
|
|
+ bool mbl_was_active = recover_machine_state_after_power_panic();
|
|
|
+
|
|
|
+
|
|
|
+ bool raise_z = (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 1);
|
|
|
+ if(raise_z && (current_position[Z_AXIS]<25))
|
|
|
+ enquecommand_P(PSTR("G1 Z25 F800"));
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
enquecommand_P(PSTR("G28 X Y"));
|
|
|
|
|
|
sprintf_P(cmd, PSTR("M104 S%d"), target_temperature[active_extruder]);
|
|
@@ -10774,19 +10817,19 @@ void recover_print(uint8_t automatic) {
|
|
|
printf_P(_N("After waiting for temp:\nCurrent pos X_AXIS:%.3f\nCurrent pos Y_AXIS:%.3f\n"), current_position[X_AXIS], current_position[Y_AXIS]);
|
|
|
|
|
|
|
|
|
- restore_print_from_eeprom();
|
|
|
+ restore_print_from_eeprom(mbl_was_active);
|
|
|
printf_P(_N("Current pos Z_AXIS:%.3f\nCurrent pos E_AXIS:%.3f\n"), current_position[Z_AXIS], current_position[E_AXIS]);
|
|
|
}
|
|
|
|
|
|
-void recover_machine_state_after_power_panic(bool bTiny)
|
|
|
+bool recover_machine_state_after_power_panic()
|
|
|
{
|
|
|
-
|
|
|
-
|
|
|
- current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0));
|
|
|
- current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4));
|
|
|
+
|
|
|
+ current_position[X_AXIS] = 0;
|
|
|
+ current_position[Y_AXIS] = 0;
|
|
|
|
|
|
-
|
|
|
- mbl.active = false;
|
|
|
+
|
|
|
+
|
|
|
+ bool mbl_was_active = false;
|
|
|
for (int8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) {
|
|
|
uint8_t ix = mesh_point % MESH_NUM_X_POINTS;
|
|
|
uint8_t iy = mesh_point / MESH_NUM_X_POINTS;
|
|
@@ -10794,26 +10837,13 @@ void recover_machine_state_after_power_panic(bool bTiny)
|
|
|
int16_t v;
|
|
|
eeprom_read_block(&v, (void*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL+2*mesh_point), 2);
|
|
|
if (v != 0)
|
|
|
- mbl.active = true;
|
|
|
+ mbl_was_active = true;
|
|
|
mbl.z_values[iy][ix] = float(v) * 0.001f;
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
- if(bTiny){
|
|
|
- current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z))
|
|
|
- + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS))
|
|
|
- + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS];
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- current_position[Z_AXIS] -= 0.4*mbl.get_z(current_position[X_AXIS], current_position[Y_AXIS]);
|
|
|
- }
|
|
|
- else{
|
|
|
- current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)) +
|
|
|
- UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS))
|
|
|
- + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS];
|
|
|
- }
|
|
|
+ current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z));
|
|
|
|
|
|
|
|
|
current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E));
|
|
@@ -10832,17 +10862,13 @@ void recover_machine_state_after_power_panic(bool bTiny)
|
|
|
|
|
|
babystep_load();
|
|
|
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]);
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- axis_known_position[X_AXIS] = true; enable_x();
|
|
|
- axis_known_position[Y_AXIS] = true; enable_y();
|
|
|
- axis_known_position[Z_AXIS] = true; enable_z();
|
|
|
-
|
|
|
- SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
|
|
|
- print_physical_coordinates();
|
|
|
+
|
|
|
+ axis_known_position[Z_AXIS] = true;
|
|
|
+ enable_z();
|
|
|
|
|
|
|
|
|
target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND);
|
|
@@ -10867,9 +10893,11 @@ void recover_machine_state_after_power_panic(bool bTiny)
|
|
|
#ifdef LIN_ADVANCE
|
|
|
extruder_advance_K = eeprom_read_float((float*)EEPROM_UVLO_LA_K);
|
|
|
#endif
|
|
|
+
|
|
|
+ return mbl_was_active;
|
|
|
}
|
|
|
|
|
|
-void restore_print_from_eeprom() {
|
|
|
+void restore_print_from_eeprom(bool mbl_was_active) {
|
|
|
int feedrate_rec;
|
|
|
int feedmultiply_rec;
|
|
|
uint8_t fan_speed_rec;
|
|
@@ -10910,17 +10938,23 @@ void restore_print_from_eeprom() {
|
|
|
enquecommand(cmd);
|
|
|
uint32_t position = eeprom_read_dword((uint32_t*)(EEPROM_FILE_POSITION));
|
|
|
SERIAL_ECHOPGM("Position read from eeprom:");
|
|
|
- MYSERIAL.println(position);
|
|
|
-
|
|
|
- strcpy_P(cmd, PSTR("G1 X")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0))));
|
|
|
- strcat_P(cmd, PSTR(" Y")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4))));
|
|
|
- strcat_P(cmd, PSTR(" F2000"));
|
|
|
+ MYSERIAL.println(position);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ sprintf_P(cmd, PSTR("G1 X%f Y%f F2000"),
|
|
|
+ eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)),
|
|
|
+ eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)));
|
|
|
enquecommand(cmd);
|
|
|
-
|
|
|
- eeprom_update_byte((uint8_t*)EEPROM_UVLO,1);
|
|
|
-
|
|
|
- strcpy_P(cmd, PSTR("G1 Z")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z))));
|
|
|
+
|
|
|
+
|
|
|
+ if (mbl_was_active)
|
|
|
+ enquecommand_P(PSTR("PRUSA MBL V1"));
|
|
|
+
|
|
|
+
|
|
|
+ sprintf_P(cmd, PSTR("G1 Z%f"), eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)));
|
|
|
enquecommand(cmd);
|
|
|
+
|
|
|
|
|
|
sprintf_P(cmd, PSTR("G1 E%0.3f F2700"), default_retraction);
|
|
|
enquecommand(cmd);
|