Clean up set_heaters_for_bltouch

This commit is contained in:
Scott Lahteine 2017-04-28 18:22:31 -05:00
parent 7db805930a
commit 1a111180de

View file

@ -2060,57 +2060,58 @@ static void clean_up_after_endstop_or_probe_move() {
#endif #endif
#if ENABLED(BLTOUCH) #if ENABLED(BLTOUCH)
void bltouch_command(int angle) { void bltouch_command(int angle) {
servo[Z_ENDSTOP_SERVO_NR].move(angle); // Give the BL-Touch the command and wait servo[Z_ENDSTOP_SERVO_NR].move(angle); // Give the BL-Touch the command and wait
safe_delay(BLTOUCH_DELAY); safe_delay(BLTOUCH_DELAY);
} }
// /**
// The BL-Touch probes have a HAL effect sensor. The high currents switching * BLTouch probes have a Hall effect sensor. The high currents switching
// on and off cause big magnetic fields that can affect the repeatability of the * on and off cause a magnetic field that can affect the repeatability of the
// sensor. So, for BL-Touch probes, we turn off the heaters during the actual probe. * sensor. So for BLTouch probes, heaters are turned off during the probe,
// And then we quickly turn them back on after we have sampled the point * then quickly turned back on after the point is sampled.
// */
#if ENABLED(BLTOUCH_HEATERS_OFF) #if ENABLED(BLTOUCH_HEATERS_OFF)
void turn_heaters_on_or_off_for_bltouch(const bool deploy) {
static int8_t bltouch_recursion_cnt=0; bool set_heaters_for_bltouch(const bool deploy) {
static millis_t last_emi_protection=0; static bool heaters_were_disabled = false;
static millis_t next_emi_protection;
static float temps_at_entry[HOTENDS]; static float temps_at_entry[HOTENDS];
#if HAS_TEMP_BED #if HAS_TEMP_BED
static float bed_temp_at_entry; static float bed_temp_at_entry;
#endif #endif
if (deploy && bltouch_recursion_cnt>0) // if already in the correct state, we don't need to do anything // If called out of order or far apart something is seriously wrong
return; // with the heaters. if (deploy == heaters_were_disabled
if (!deploy && bltouch_recursion_cnt<1) // if already in the correct state, we don't need to do anything || (next_emi_protection && ELAPSED(millis(), next_emi_protection)))
return; // with the heaters. kill(PSTR(MSG_KILLED));
if (deploy) { if (deploy) {
bltouch_recursion_cnt++; next_emi_protection = millis() + 20 * 1000UL;
last_emi_protection = millis(); HOTEND_LOOP() {
HOTEND_LOOP() temps_at_entry[e] = thermalManager.degTargetHotend(e); // save the current target temperatures temps_at_entry[e] = thermalManager.degTargetHotend(e);
HOTEND_LOOP() thermalManager.setTargetHotend(0, e); // so we know what to restore them to. thermalManager.setTargetHotend(0, e);
}
#if HAS_TEMP_BED #if HAS_TEMP_BED
bed_temp_at_entry = thermalManager.degTargetBed(); bed_temp_at_entry = thermalManager.degTargetBed();
thermalManager.setTargetBed(0.0); thermalManager.setTargetBed(0);
#endif #endif
} }
else { else {
bltouch_recursion_cnt--; // the heaters are only turned back on HOTEND_LOOP() thermalManager.setTargetHotend(temps_at_entry[e], e);
if (bltouch_recursion_cnt==0 && ((last_emi_protection+20000L)>millis())) { // if everything is perfect. It is expected #if HAS_TEMP_BED
HOTEND_LOOP() thermalManager.setTargetHotend(temps_at_entry[e], e); // that the bltouch_recursion_cnt is zero and thermalManager.setTargetBed(bed_temp_at_entry);
#if HAS_TEMP_BED // that the heaters were shut off less than
thermalManager.setTargetBed(bed_temp_at_entry); // 20 seconds ago
#endif #endif
} }
} }
}
#endif #endif // BLTOUCH_HEATERS_OFF
void set_bltouch_deployed(const bool deploy) { void set_bltouch_deployed(const bool deploy) {
#if ENABLED(BLTOUCH_HEATERS_OFF) #if ENABLED(BLTOUCH_HEATERS_OFF)
turn_heaters_on_or_off_for_bltouch(deploy); set_heaters_for_bltouch(deploy);
#endif #endif
if (deploy && TEST_BLTOUCH()) { // If BL-Touch says it's triggered if (deploy && TEST_BLTOUCH()) { // If BL-Touch says it's triggered
bltouch_command(BLTOUCH_RESET); // try to reset it. bltouch_command(BLTOUCH_RESET); // try to reset it.
@ -2134,7 +2135,8 @@ static void clean_up_after_endstop_or_probe_move() {
} }
#endif #endif
} }
#endif
#endif // BLTOUCH
// returns false for ok and true for failure // returns false for ok and true for failure
bool set_probe_deployed(bool deploy) { bool set_probe_deployed(bool deploy) {
@ -2147,7 +2149,7 @@ static void clean_up_after_endstop_or_probe_move() {
#endif #endif
#if ENABLED(BLTOUCH) && ENABLED(BLTOUCH_HEATERS_OFF) #if ENABLED(BLTOUCH) && ENABLED(BLTOUCH_HEATERS_OFF)
turn_heaters_on_or_off_for_bltouch(deploy); set_heaters_for_bltouch(deploy);
#endif #endif
if (endstops.z_probe_enabled == deploy) return false; if (endstops.z_probe_enabled == deploy) return false;