2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2016-03-24 19:01:20 +01:00
|
|
|
* Marlin 3D Printer Firmware
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2019 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2015-05-17 10:44:53 +02:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-28 06:57:50 +02:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2015-05-17 10:44:53 +02:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
2016-03-24 19:01:20 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-25 07:19:46 +01:00
|
|
|
/**
|
2015-05-17 10:44:53 +02:00
|
|
|
* About Marlin
|
|
|
|
*
|
|
|
|
* This firmware is a mashup between Sprinter and grbl.
|
|
|
|
* - https://github.com/kliment/Sprinter
|
2018-02-06 09:28:18 +01:00
|
|
|
* - https://github.com/grbl/grbl
|
2015-04-14 02:17:36 +02:00
|
|
|
*/
|
2012-11-06 12:06:41 +01:00
|
|
|
|
2016-11-19 04:54:38 +01:00
|
|
|
#include "Marlin.h"
|
|
|
|
|
2019-03-29 20:07:43 +01:00
|
|
|
#include "core/utility.h"
|
2017-09-06 13:28:33 +02:00
|
|
|
#include "lcd/ultralcd.h"
|
2017-09-08 05:33:16 +02:00
|
|
|
#include "module/motion.h"
|
2017-09-06 13:28:33 +02:00
|
|
|
#include "module/planner.h"
|
|
|
|
#include "module/stepper.h"
|
|
|
|
#include "module/endstops.h"
|
2017-09-08 22:35:25 +02:00
|
|
|
#include "module/probe.h"
|
2017-09-06 13:28:33 +02:00
|
|
|
#include "module/temperature.h"
|
|
|
|
#include "sd/cardreader.h"
|
|
|
|
#include "module/configuration_store.h"
|
2017-09-09 07:18:43 +02:00
|
|
|
#include "module/printcounter.h" // PrintCounter or Stopwatch
|
2018-09-08 19:08:31 +02:00
|
|
|
#include "feature/closedloop.h"
|
|
|
|
|
2018-10-20 08:44:46 +02:00
|
|
|
#include "HAL/shared/Delay.h"
|
|
|
|
|
2019-01-24 02:06:54 +01:00
|
|
|
#include "module/stepper_indirection.h"
|
|
|
|
|
2017-06-18 01:36:10 +02:00
|
|
|
#ifdef ARDUINO
|
2017-09-06 13:28:33 +02:00
|
|
|
#include <pins_arduino.h>
|
2017-06-18 01:36:10 +02:00
|
|
|
#endif
|
2017-09-06 13:28:33 +02:00
|
|
|
#include <math.h>
|
|
|
|
#include "libs/nozzle.h"
|
2017-09-08 05:33:16 +02:00
|
|
|
|
|
|
|
#include "gcode/gcode.h"
|
2017-09-06 13:28:33 +02:00
|
|
|
#include "gcode/parser.h"
|
2017-09-08 05:33:16 +02:00
|
|
|
#include "gcode/queue.h"
|
2016-11-19 04:54:38 +01:00
|
|
|
|
2019-02-12 22:55:47 +01:00
|
|
|
#if ENABLED(HOST_ACTION_COMMANDS)
|
|
|
|
#include "feature/host_actions.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-14 22:33:07 +02:00
|
|
|
#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
|
|
|
|
#include "libs/buzzer.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 01:45:21 +02:00
|
|
|
#if ENABLED(DIGIPOT_I2C)
|
|
|
|
#include "feature/digipot/digipot.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 07:06:16 +02:00
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#include "feature/mixing.h"
|
|
|
|
#endif
|
|
|
|
|
2017-08-26 00:03:07 +02:00
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
2017-09-08 21:47:47 +02:00
|
|
|
#include "feature/Max7219_Debug_LEDs.h"
|
2017-08-26 00:03:07 +02:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 21:47:47 +02:00
|
|
|
#if HAS_COLOR_LEDS
|
|
|
|
#include "feature/leds/leds.h"
|
2017-06-10 08:02:15 +02:00
|
|
|
#endif
|
|
|
|
|
2019-03-17 11:57:25 +01:00
|
|
|
#if ENABLED(BLTOUCH)
|
|
|
|
#include "feature/bltouch.h"
|
|
|
|
#endif
|
|
|
|
|
2016-11-19 04:54:38 +01:00
|
|
|
#if HAS_SERVOS
|
2017-11-19 20:39:46 +01:00
|
|
|
#include "module/servo.h"
|
2016-11-19 04:54:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
2017-09-06 13:28:33 +02:00
|
|
|
#include "feature/dac/stepper_dac.h"
|
2016-11-19 04:54:38 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(EXPERIMENTAL_I2CBUS)
|
2017-09-06 13:28:33 +02:00
|
|
|
#include "feature/twibus.h"
|
2017-09-17 09:49:13 +02:00
|
|
|
TWIBus i2c;
|
2016-11-19 04:54:38 +01:00
|
|
|
#endif
|
|
|
|
|
2017-06-09 14:06:23 +02:00
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
2017-09-06 13:28:33 +02:00
|
|
|
#include "feature/I2CPositionEncoder.h"
|
2017-06-09 14:06:23 +02:00
|
|
|
#endif
|
|
|
|
|
2019-06-11 14:27:39 +02:00
|
|
|
#if HAS_TRINAMIC && DISABLED(PS_DEFAULT_OFF)
|
2017-12-15 22:03:14 +01:00
|
|
|
#include "feature/tmc_util.h"
|
2017-09-18 01:34:04 +02:00
|
|
|
#endif
|
|
|
|
|
2019-06-28 06:06:49 +02:00
|
|
|
#if HAS_CUTTER
|
|
|
|
#include "feature/spindle_laser.h"
|
|
|
|
#endif
|
|
|
|
|
2015-07-31 07:24:43 +02:00
|
|
|
#if ENABLED(SDSUPPORT)
|
2015-01-30 03:52:21 +01:00
|
|
|
CardReader card;
|
2012-11-06 12:06:41 +01:00
|
|
|
#endif
|
2015-01-30 03:52:21 +01:00
|
|
|
|
2016-09-29 22:06:01 +02:00
|
|
|
#if ENABLED(G38_PROBE_TARGET)
|
2019-03-10 23:22:09 +01:00
|
|
|
uint8_t G38_move; // = 0
|
|
|
|
bool G38_did_trigger; // = false
|
2016-09-19 21:17:10 +02:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#if ENABLED(DELTA)
|
|
|
|
#include "module/delta.h"
|
|
|
|
#elif IS_SCARA
|
|
|
|
#include "module/scara.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_LEVELING
|
|
|
|
#include "feature/bedlevel/bedlevel.h"
|
2017-03-18 16:15:54 +01:00
|
|
|
#endif
|
|
|
|
|
2019-03-17 05:43:06 +01:00
|
|
|
#if BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT)
|
2017-09-16 09:13:07 +02:00
|
|
|
#include "feature/pause.h"
|
|
|
|
#endif
|
2017-09-09 07:18:43 +02:00
|
|
|
|
2018-04-22 02:41:26 +02:00
|
|
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
|
|
|
#include "feature/power_loss_recovery.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-13 03:08:34 +01:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2017-10-10 09:35:20 +02:00
|
|
|
#include "feature/runout.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-16 12:09:34 +02:00
|
|
|
#if ENABLED(TEMP_STAT_LEDS)
|
|
|
|
#include "feature/leds/tempstat.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 01:56:29 +02:00
|
|
|
#if HAS_CASE_LIGHT
|
|
|
|
#include "feature/caselight.h"
|
|
|
|
#endif
|
|
|
|
|
2017-11-05 03:01:41 +01:00
|
|
|
#if HAS_FANMUX
|
|
|
|
#include "feature/fanmux.h"
|
|
|
|
#endif
|
|
|
|
|
2019-07-01 12:55:23 +02:00
|
|
|
#if DO_SWITCH_EXTRUDER || ANY(SWITCHING_NOZZLE, PARKING_EXTRUDER, MAGNETIC_PARKING_EXTRUDER, ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
|
2017-09-18 08:05:44 +02:00
|
|
|
#include "module/tool_change.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 08:44:59 +02:00
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
|
|
|
#include "feature/controllerfan.h"
|
|
|
|
#endif
|
|
|
|
|
2019-02-01 02:10:52 +01:00
|
|
|
#if ENABLED(PRUSA_MMU2)
|
|
|
|
#include "feature/prusa_MMU2/mmu2.h"
|
|
|
|
#endif
|
|
|
|
|
2018-10-08 22:44:05 +02:00
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
#include "lcd/extensible_ui/ui_api.h"
|
|
|
|
#endif
|
|
|
|
|
2019-01-24 02:06:54 +01:00
|
|
|
#if HAS_DRIVER(L6470)
|
|
|
|
#include "libs/L6470/L6470_Marlin.h"
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 09:56:19 +02:00
|
|
|
bool Running = true;
|
|
|
|
|
2016-10-07 05:06:33 +02:00
|
|
|
// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
|
2019-03-10 15:13:54 +01:00
|
|
|
bool wait_for_heatup = true;
|
2015-04-08 09:56:19 +02:00
|
|
|
|
2016-10-07 05:06:33 +02:00
|
|
|
// For M0/M1, this flag may be cleared (by M108) to exit the wait-for-user loop
|
2017-04-09 18:12:08 +02:00
|
|
|
#if HAS_RESUME_CONTINUE
|
2019-03-09 21:13:50 +01:00
|
|
|
bool wait_for_user; // = false;
|
2016-09-12 03:51:53 +02:00
|
|
|
#endif
|
|
|
|
|
2018-03-21 06:29:09 +01:00
|
|
|
#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
|
2018-03-07 08:57:09 +01:00
|
|
|
bool suspend_auto_report; // = false
|
|
|
|
#endif
|
|
|
|
|
2015-04-04 00:45:41 +02:00
|
|
|
// Inactivity shutdown
|
2018-03-21 11:45:23 +01:00
|
|
|
millis_t max_inactive_time, // = 0
|
2017-09-17 06:57:09 +02:00
|
|
|
stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
|
2016-04-18 08:13:07 +02:00
|
|
|
|
2018-11-05 08:08:40 +01:00
|
|
|
#if PIN_EXISTS(CHDK)
|
|
|
|
extern millis_t chdk_timeout;
|
2017-09-08 22:35:25 +02:00
|
|
|
#endif
|
2016-10-02 08:48:17 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
|
|
|
I2CPositionEncodersMgr I2CPEM;
|
|
|
|
#endif
|
2017-04-15 05:44:08 +02:00
|
|
|
|
2016-09-15 20:22:23 +02:00
|
|
|
/**
|
2017-09-08 22:35:25 +02:00
|
|
|
* ***************************************************************************
|
|
|
|
* ******************************** FUNCTIONS ********************************
|
|
|
|
* ***************************************************************************
|
2016-09-15 20:22:23 +02:00
|
|
|
*/
|
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
void setup_killpin() {
|
|
|
|
#if HAS_KILL
|
|
|
|
SET_INPUT_PULLUP(KILL_PIN);
|
2016-09-15 22:43:06 +02:00
|
|
|
#endif
|
2017-09-08 22:35:25 +02:00
|
|
|
}
|
2016-07-08 15:59:33 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
void setup_powerhold() {
|
|
|
|
#if HAS_SUICIDE
|
|
|
|
OUT_WRITE(SUICIDE_PIN, HIGH);
|
2016-07-08 15:59:33 +02:00
|
|
|
#endif
|
2017-09-08 22:35:25 +02:00
|
|
|
#if HAS_POWER_SWITCH
|
|
|
|
#if ENABLED(PS_DEFAULT_OFF)
|
2019-02-20 12:28:40 +01:00
|
|
|
powersupply_on = true; PSU_OFF();
|
2017-09-08 22:35:25 +02:00
|
|
|
#else
|
2019-02-20 12:28:40 +01:00
|
|
|
powersupply_on = false; PSU_ON();
|
2017-04-15 05:44:08 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-09-08 22:35:25 +02:00
|
|
|
}
|
2017-04-15 05:44:08 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
/**
|
|
|
|
* Stepper Reset (RigidBoard, et.al.)
|
|
|
|
*/
|
|
|
|
#if HAS_STEPPER_RESET
|
2019-02-20 12:28:40 +01:00
|
|
|
void disableStepperDrivers() { OUT_WRITE(STEPPER_RESET_PIN, LOW); } // Drive down to keep motor driver chips in reset
|
|
|
|
void enableStepperDrivers() { SET_INPUT(STEPPER_RESET_PIN); } // Set to input, allowing pullups to pull the pin high
|
2017-09-08 22:35:25 +02:00
|
|
|
#endif
|
2016-08-28 02:53:02 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0
|
2015-04-29 04:10:07 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
void i2c_on_receive(int bytes) { // just echo all bytes received to serial
|
|
|
|
i2c.receive(bytes);
|
|
|
|
}
|
2017-04-15 05:44:08 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
void i2c_on_request() { // just send dummy data for now
|
|
|
|
i2c.reply("Hello World!\n");
|
|
|
|
}
|
2015-07-10 01:57:44 +02:00
|
|
|
|
2017-09-08 22:35:25 +02:00
|
|
|
#endif
|
2014-06-23 17:09:57 +02:00
|
|
|
|
2017-09-06 13:28:33 +02:00
|
|
|
/**
|
|
|
|
* Sensitive pin test for M42, M226
|
|
|
|
*/
|
2018-10-11 07:58:41 +02:00
|
|
|
|
|
|
|
#include "pins/sensitive_pins.h"
|
|
|
|
|
2017-10-26 20:37:26 +02:00
|
|
|
bool pin_is_protected(const pin_t pin) {
|
|
|
|
static const pin_t sensitive_pins[] PROGMEM = SENSITIVE_PINS;
|
|
|
|
for (uint8_t i = 0; i < COUNT(sensitive_pins); i++) {
|
|
|
|
pin_t sensitive_pin;
|
|
|
|
memcpy_P(&sensitive_pin, &sensitive_pins[i], sizeof(pin_t));
|
|
|
|
if (pin == sensitive_pin) return true;
|
|
|
|
}
|
2017-09-06 13:28:33 +02:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-19 17:24:44 +02:00
|
|
|
|
2018-06-11 00:45:39 +02:00
|
|
|
void protected_pin_err() {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ERROR_MSG(MSG_ERR_PROTECTED_PIN);
|
2018-06-11 00:45:39 +02:00
|
|
|
}
|
|
|
|
|
2017-09-06 13:28:33 +02:00
|
|
|
void quickstop_stepper() {
|
2018-05-09 07:17:53 +02:00
|
|
|
planner.quick_stop();
|
2018-05-12 08:38:02 +02:00
|
|
|
planner.synchronize();
|
2017-09-06 13:28:33 +02:00
|
|
|
set_current_from_steppers_for_axis(ALL_AXES);
|
2018-09-17 04:24:15 +02:00
|
|
|
sync_plan_position();
|
2017-09-06 13:28:33 +02:00
|
|
|
}
|
2016-10-05 21:34:07 +02:00
|
|
|
|
2015-04-04 04:25:22 +02:00
|
|
|
void enable_all_steppers() {
|
2018-02-19 23:12:04 +01:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.power_on();
|
|
|
|
#endif
|
2017-04-11 18:10:26 +02:00
|
|
|
enable_X();
|
|
|
|
enable_Y();
|
|
|
|
enable_Z();
|
|
|
|
enable_E0();
|
|
|
|
enable_E1();
|
|
|
|
enable_E2();
|
|
|
|
enable_E3();
|
|
|
|
enable_E4();
|
2018-09-13 08:35:55 +02:00
|
|
|
enable_E5();
|
2015-04-04 04:25:22 +02:00
|
|
|
}
|
|
|
|
|
2017-03-18 03:12:19 +01:00
|
|
|
void disable_e_steppers() {
|
2017-04-11 18:10:26 +02:00
|
|
|
disable_E0();
|
|
|
|
disable_E1();
|
|
|
|
disable_E2();
|
|
|
|
disable_E3();
|
|
|
|
disable_E4();
|
2018-09-13 08:35:55 +02:00
|
|
|
disable_E5();
|
2015-04-04 00:31:35 +02:00
|
|
|
}
|
|
|
|
|
2018-01-04 12:06:34 +01:00
|
|
|
void disable_e_stepper(const uint8_t e) {
|
|
|
|
switch (e) {
|
|
|
|
case 0: disable_E0(); break;
|
|
|
|
case 1: disable_E1(); break;
|
|
|
|
case 2: disable_E2(); break;
|
|
|
|
case 3: disable_E3(); break;
|
|
|
|
case 4: disable_E4(); break;
|
2018-09-13 08:35:55 +02:00
|
|
|
case 5: disable_E5(); break;
|
2018-01-04 12:06:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-18 03:12:19 +01:00
|
|
|
void disable_all_steppers() {
|
2017-04-11 18:10:26 +02:00
|
|
|
disable_X();
|
|
|
|
disable_Y();
|
|
|
|
disable_Z();
|
2017-03-18 03:12:19 +01:00
|
|
|
disable_e_steppers();
|
|
|
|
}
|
|
|
|
|
2019-02-13 03:08:34 +01:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2019-02-12 22:55:47 +01:00
|
|
|
|
|
|
|
void event_filament_runout() {
|
|
|
|
|
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
if (did_pause_print) return; // Action already in progress. Purge triggered repeated runout.
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
|
|
|
ExtUI::onFilamentRunout(ExtUI::getActiveTool());
|
|
|
|
#endif
|
2019-01-28 05:43:13 +01:00
|
|
|
|
2019-03-17 05:43:06 +01:00
|
|
|
#if EITHER(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS)
|
2019-02-14 04:05:18 +01:00
|
|
|
const char tool = '0'
|
|
|
|
#if NUM_RUNOUT_SENSORS > 1
|
|
|
|
+ active_extruder
|
|
|
|
#endif
|
|
|
|
;
|
|
|
|
#endif
|
2019-02-12 22:55:47 +01:00
|
|
|
|
|
|
|
//action:out_of_filament
|
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
host_prompt_reason = PROMPT_FILAMENT_RUNOUT;
|
|
|
|
host_action_prompt_end();
|
|
|
|
host_action_prompt_begin(PSTR("FilamentRunout T"), false);
|
|
|
|
SERIAL_CHAR(tool);
|
|
|
|
SERIAL_EOL();
|
|
|
|
host_action_prompt_show();
|
|
|
|
#endif
|
|
|
|
|
2019-02-14 03:39:38 +01:00
|
|
|
const bool run_runout_script = !runout.host_handling;
|
|
|
|
|
2019-02-12 22:55:47 +01:00
|
|
|
#if ENABLED(HOST_ACTION_COMMANDS)
|
2019-02-14 03:39:38 +01:00
|
|
|
if (run_runout_script
|
2019-02-12 22:55:47 +01:00
|
|
|
&& ( strstr(FILAMENT_RUNOUT_SCRIPT, "M600")
|
|
|
|
|| strstr(FILAMENT_RUNOUT_SCRIPT, "M125")
|
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
|
|
|
|| strstr(FILAMENT_RUNOUT_SCRIPT, "M25")
|
|
|
|
#endif
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
host_action_paused(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Legacy Repetier command for use until newer version supports standard dialog
|
|
|
|
// To be removed later when pause command also triggers dialog
|
|
|
|
#ifdef ACTION_ON_FILAMENT_RUNOUT
|
|
|
|
host_action(PSTR(ACTION_ON_FILAMENT_RUNOUT " T"), false);
|
|
|
|
SERIAL_CHAR(tool);
|
|
|
|
SERIAL_EOL();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
host_action_pause(false);
|
|
|
|
}
|
|
|
|
SERIAL_ECHOPGM(" " ACTION_REASON_ON_FILAMENT_RUNOUT " ");
|
|
|
|
SERIAL_CHAR(tool);
|
|
|
|
SERIAL_EOL();
|
|
|
|
#endif // HOST_ACTION_COMMANDS
|
|
|
|
|
2019-02-14 03:39:38 +01:00
|
|
|
if (run_runout_script)
|
2019-06-19 07:00:19 +02:00
|
|
|
queue.inject_P(PSTR(FILAMENT_RUNOUT_SCRIPT));
|
2019-01-28 05:43:13 +01:00
|
|
|
}
|
|
|
|
|
2019-02-13 03:08:34 +01:00
|
|
|
#endif // HAS_FILAMENT_SENSOR
|
2019-02-12 22:55:47 +01:00
|
|
|
|
|
|
|
#if ENABLED(G29_RETRY_AND_RECOVER)
|
|
|
|
|
|
|
|
void event_probe_failure() {
|
2019-02-19 21:45:03 +01:00
|
|
|
#ifdef ACTION_ON_G29_FAILURE
|
|
|
|
host_action(PSTR(ACTION_ON_G29_FAILURE));
|
|
|
|
#endif
|
2019-02-12 22:55:47 +01:00
|
|
|
#ifdef G29_FAILURE_COMMANDS
|
2019-02-14 03:39:38 +01:00
|
|
|
gcode.process_subcommands_now_P(PSTR(G29_FAILURE_COMMANDS));
|
2019-02-12 22:55:47 +01:00
|
|
|
#endif
|
|
|
|
#if ENABLED(G29_HALT_ON_FAILURE)
|
|
|
|
#ifdef ACTION_ON_CANCEL
|
|
|
|
host_action_cancel();
|
|
|
|
#endif
|
|
|
|
kill(PSTR(MSG_ERR_PROBING_FAILED));
|
|
|
|
#endif
|
|
|
|
}
|
2019-01-28 05:43:13 +01:00
|
|
|
|
2019-02-12 22:55:47 +01:00
|
|
|
void event_probe_recover() {
|
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
|
|
|
host_prompt_do(PROMPT_INFO, PSTR("G29 Retrying"));
|
|
|
|
#endif
|
|
|
|
#ifdef ACTION_ON_G29_RECOVER
|
|
|
|
host_action(PSTR(ACTION_ON_G29_RECOVER));
|
|
|
|
#endif
|
2019-02-19 21:45:03 +01:00
|
|
|
#ifdef G29_RECOVER_COMMANDS
|
|
|
|
gcode.process_subcommands_now_P(PSTR(G29_RECOVER_COMMANDS));
|
|
|
|
#endif
|
2019-02-12 22:55:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2019-01-28 05:43:13 +01:00
|
|
|
|
2015-04-04 00:31:35 +02:00
|
|
|
/**
|
2015-04-04 08:42:50 +02:00
|
|
|
* Manage several activities:
|
|
|
|
* - Check for Filament Runout
|
|
|
|
* - Keep the command buffer full
|
|
|
|
* - Check for maximum inactive time between commands
|
|
|
|
* - Check for maximum inactive time between stepper commands
|
2018-11-05 08:08:40 +01:00
|
|
|
* - Check if CHDK_PIN needs to go LOW
|
2015-04-04 08:42:50 +02:00
|
|
|
* - Check for KILL button held down
|
|
|
|
* - Check for HOME button held down
|
|
|
|
* - Check if cooling fan needs to be switched on
|
|
|
|
* - Check if an idle but hot extruder needs filament extruded (EXTRUDER_RUNOUT_PREVENT)
|
2019-02-27 04:03:13 +01:00
|
|
|
* - Pulse FET_SAFETY_PIN if it exists
|
2015-04-04 00:31:35 +02:00
|
|
|
*/
|
2019-02-27 04:03:13 +01:00
|
|
|
|
2018-04-08 11:00:26 +02:00
|
|
|
void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
|
2015-08-05 13:40:36 +02:00
|
|
|
|
2019-02-13 03:08:34 +01:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2018-02-18 09:42:09 +01:00
|
|
|
runout.run();
|
2015-04-04 00:31:35 +02:00
|
|
|
#endif
|
|
|
|
|
2019-06-19 07:00:19 +02:00
|
|
|
if (queue.length < BUFSIZE) queue.get_available_commands();
|
2015-04-04 00:31:35 +02:00
|
|
|
|
2017-03-29 02:45:54 +02:00
|
|
|
const millis_t ms = millis();
|
2015-04-04 00:31:35 +02:00
|
|
|
|
2018-03-22 01:30:06 +01:00
|
|
|
if (max_inactive_time && ELAPSED(ms, gcode.previous_move_ms + max_inactive_time)) {
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_ERROR_START();
|
2017-05-20 10:03:08 +02:00
|
|
|
SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr);
|
2018-10-19 04:20:56 +02:00
|
|
|
kill();
|
2017-03-14 18:24:46 +01:00
|
|
|
}
|
2017-02-10 07:13:58 +01:00
|
|
|
|
|
|
|
// Prevent steppers timing-out in the middle of M600
|
2019-03-17 05:43:06 +01:00
|
|
|
#if BOTH(ADVANCED_PAUSE_FEATURE, PAUSE_PARK_NO_STEPPER_TIMEOUT)
|
2017-12-30 11:03:41 +01:00
|
|
|
#define MOVE_AWAY_TEST !did_pause_print
|
2017-02-10 07:13:58 +01:00
|
|
|
#else
|
2017-05-26 20:01:02 +02:00
|
|
|
#define MOVE_AWAY_TEST true
|
2017-01-22 00:10:57 +01:00
|
|
|
#endif
|
2017-03-14 08:25:34 +01:00
|
|
|
|
2018-03-22 01:30:06 +01:00
|
|
|
if (stepper_inactive_time) {
|
2019-01-24 02:06:54 +01:00
|
|
|
static bool already_shutdown_steppers; // = false
|
2018-03-22 01:30:06 +01:00
|
|
|
if (planner.has_blocks_queued())
|
2019-04-10 22:51:48 +02:00
|
|
|
gcode.reset_stepper_timeout();
|
2018-03-22 01:30:06 +01:00
|
|
|
else if (MOVE_AWAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) {
|
2019-01-24 02:06:54 +01:00
|
|
|
if (!already_shutdown_steppers) {
|
|
|
|
already_shutdown_steppers = true; // L6470 SPI will consume 99% of free time without this
|
|
|
|
#if ENABLED(DISABLE_INACTIVE_X)
|
|
|
|
disable_X();
|
|
|
|
#endif
|
|
|
|
#if ENABLED(DISABLE_INACTIVE_Y)
|
|
|
|
disable_Y();
|
|
|
|
#endif
|
|
|
|
#if ENABLED(DISABLE_INACTIVE_Z)
|
|
|
|
disable_Z();
|
|
|
|
#endif
|
|
|
|
#if ENABLED(DISABLE_INACTIVE_E)
|
|
|
|
disable_e_steppers();
|
|
|
|
#endif
|
2019-04-10 22:51:48 +02:00
|
|
|
#if HAS_LCD_MENU && ENABLED(AUTO_BED_LEVELING_UBL)
|
|
|
|
if (ubl.lcd_map_control) {
|
|
|
|
ubl.lcd_map_control = false;
|
|
|
|
ui.defer_status_screen(false);
|
|
|
|
}
|
2019-01-24 02:06:54 +01:00
|
|
|
#endif
|
|
|
|
}
|
2018-03-22 01:30:06 +01:00
|
|
|
}
|
2019-01-24 02:06:54 +01:00
|
|
|
else
|
|
|
|
already_shutdown_steppers = false;
|
2015-06-01 10:42:28 +02:00
|
|
|
}
|
2015-03-07 21:43:15 +01:00
|
|
|
|
2018-11-05 08:08:40 +01:00
|
|
|
#if PIN_EXISTS(CHDK) // Check if pin should be set to LOW (after M240 set it HIGH)
|
2019-02-14 22:09:35 +01:00
|
|
|
if (chdk_timeout && ELAPSED(ms, chdk_timeout)) {
|
|
|
|
chdk_timeout = 0;
|
2018-11-05 08:08:40 +01:00
|
|
|
WRITE(CHDK_PIN, LOW);
|
2014-03-10 21:57:08 +01:00
|
|
|
}
|
|
|
|
#endif
|
2015-04-04 00:31:35 +02:00
|
|
|
|
|
|
|
#if HAS_KILL
|
2015-08-05 13:40:36 +02:00
|
|
|
|
2014-12-28 19:54:06 +01:00
|
|
|
// Check if the kill button was pressed and wait just in case it was an accidental
|
|
|
|
// key kill key press
|
|
|
|
// -------------------------------------------------------------------------------
|
2015-04-04 00:45:41 +02:00
|
|
|
static int killCount = 0; // make the inactivity button a bit less responsive
|
|
|
|
const int KILL_DELAY = 750;
|
2015-04-04 00:31:35 +02:00
|
|
|
if (!READ(KILL_PIN))
|
2015-10-03 08:08:58 +02:00
|
|
|
killCount++;
|
2014-12-28 19:54:06 +01:00
|
|
|
else if (killCount > 0)
|
2015-10-03 08:08:58 +02:00
|
|
|
killCount--;
|
2015-04-04 00:31:35 +02:00
|
|
|
|
2014-12-28 19:54:06 +01:00
|
|
|
// Exceeded threshold and we can confirm that it was not accidental
|
|
|
|
// KILL the machine
|
|
|
|
// ----------------------------------------------------------------
|
2017-03-14 18:24:46 +01:00
|
|
|
if (killCount >= KILL_DELAY) {
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ERROR_MSG(MSG_KILL_BUTTON);
|
2018-10-19 04:20:56 +02:00
|
|
|
kill();
|
2017-03-14 18:24:46 +01:00
|
|
|
}
|
2012-11-06 12:06:41 +01:00
|
|
|
#endif
|
2014-12-28 19:54:06 +01:00
|
|
|
|
2015-04-04 00:31:35 +02:00
|
|
|
#if HAS_HOME
|
2019-06-27 22:07:45 +02:00
|
|
|
// Handle a standalone HOME button
|
|
|
|
constexpr millis_t HOME_DEBOUNCE_DELAY = 1000UL;
|
|
|
|
static millis_t next_home_key_ms; // = 0
|
|
|
|
if (!IS_SD_PRINTING() && !READ(HOME_PIN)) { // HOME_PIN goes LOW when pressed
|
|
|
|
const millis_t ms = millis();
|
|
|
|
if (ELAPSED(ms, next_home_key_ms)) {
|
|
|
|
next_home_key_ms = ms + HOME_DEBOUNCE_DELAY;
|
2015-05-04 19:48:49 +02:00
|
|
|
LCD_MESSAGEPGM(MSG_AUTO_HOME);
|
2019-06-27 22:07:45 +02:00
|
|
|
queue.enqueue_now_P(PSTR("G28"));
|
2015-04-04 00:31:35 +02:00
|
|
|
}
|
2014-12-28 19:54:06 +01:00
|
|
|
}
|
2015-04-04 00:31:35 +02:00
|
|
|
#endif
|
2015-08-05 13:40:36 +02:00
|
|
|
|
2017-05-04 23:38:29 +02:00
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
2017-09-18 08:44:59 +02:00
|
|
|
controllerfan_update(); // Check if fan should be turned on to cool stepper drivers down
|
2012-11-06 12:06:41 +01:00
|
|
|
#endif
|
2015-04-04 00:31:35 +02:00
|
|
|
|
2018-02-19 23:12:04 +01:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.check();
|
|
|
|
#endif
|
|
|
|
|
2015-07-31 07:24:43 +02:00
|
|
|
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
|
2018-02-09 10:32:40 +01:00
|
|
|
if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
|
2018-03-22 01:30:06 +01:00
|
|
|
&& ELAPSED(ms, gcode.previous_move_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
|
|
|
|
&& !planner.has_blocks_queued()
|
2018-02-09 10:32:40 +01:00
|
|
|
) {
|
2016-06-29 00:06:56 +02:00
|
|
|
#if ENABLED(SWITCHING_EXTRUDER)
|
2018-05-28 00:56:21 +02:00
|
|
|
bool oldstatus;
|
|
|
|
switch (active_extruder) {
|
|
|
|
default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
case 2: case 3: oldstatus = E1_ENABLE_READ; enable_E1(); break;
|
|
|
|
#if E_STEPPERS > 2
|
2018-09-13 08:35:55 +02:00
|
|
|
case 4: case 5: oldstatus = E2_ENABLE_READ; enable_E2(); break;
|
2018-05-28 00:56:21 +02:00
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
|
|
|
}
|
2016-06-29 00:06:56 +02:00
|
|
|
#else // !SWITCHING_EXTRUDER
|
2017-07-06 19:10:06 +02:00
|
|
|
bool oldstatus;
|
2015-10-03 08:08:58 +02:00
|
|
|
switch (active_extruder) {
|
2017-07-06 19:10:06 +02:00
|
|
|
default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
|
2016-06-29 00:06:56 +02:00
|
|
|
#if E_STEPPERS > 1
|
2017-04-18 21:39:45 +02:00
|
|
|
case 1: oldstatus = E1_ENABLE_READ; enable_E1(); break;
|
2016-06-29 00:06:56 +02:00
|
|
|
#if E_STEPPERS > 2
|
2017-04-18 21:39:45 +02:00
|
|
|
case 2: oldstatus = E2_ENABLE_READ; enable_E2(); break;
|
2016-06-29 00:06:56 +02:00
|
|
|
#if E_STEPPERS > 3
|
2017-04-18 21:39:45 +02:00
|
|
|
case 3: oldstatus = E3_ENABLE_READ; enable_E3(); break;
|
2017-04-06 23:46:52 +02:00
|
|
|
#if E_STEPPERS > 4
|
2017-04-18 21:39:45 +02:00
|
|
|
case 4: oldstatus = E4_ENABLE_READ; enable_E4(); break;
|
2018-09-13 08:35:55 +02:00
|
|
|
#if E_STEPPERS > 5
|
|
|
|
case 5: oldstatus = E5_ENABLE_READ; enable_E5(); break;
|
|
|
|
#endif // E_STEPPERS > 5
|
2017-04-06 23:46:52 +02:00
|
|
|
#endif // E_STEPPERS > 4
|
|
|
|
#endif // E_STEPPERS > 3
|
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
2015-10-03 08:08:58 +02:00
|
|
|
}
|
2016-06-29 00:06:56 +02:00
|
|
|
#endif // !SWITCHING_EXTRUDER
|
|
|
|
|
2017-03-20 22:41:59 +01:00
|
|
|
const float olde = current_position[E_AXIS];
|
|
|
|
current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE;
|
2018-09-17 04:24:15 +02:00
|
|
|
planner.buffer_line(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
|
2017-03-20 22:41:59 +01:00
|
|
|
current_position[E_AXIS] = olde;
|
|
|
|
planner.set_e_position_mm(olde);
|
2018-05-12 08:38:02 +02:00
|
|
|
planner.synchronize();
|
2018-05-28 00:56:21 +02:00
|
|
|
|
2016-06-29 00:06:56 +02:00
|
|
|
#if ENABLED(SWITCHING_EXTRUDER)
|
2018-05-28 00:56:21 +02:00
|
|
|
switch (active_extruder) {
|
|
|
|
default: oldstatus = E0_ENABLE_WRITE(oldstatus); break;
|
|
|
|
#if E_STEPPERS > 1
|
|
|
|
case 2: case 3: oldstatus = E1_ENABLE_WRITE(oldstatus); break;
|
|
|
|
#if E_STEPPERS > 2
|
2018-09-13 08:35:55 +02:00
|
|
|
case 4: case 5: oldstatus = E2_ENABLE_WRITE(oldstatus); break;
|
2018-05-28 00:56:21 +02:00
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
|
|
|
}
|
|
|
|
#else // !SWITCHING_EXTRUDER
|
2016-06-29 00:06:56 +02:00
|
|
|
switch (active_extruder) {
|
2017-04-18 21:39:45 +02:00
|
|
|
case 0: E0_ENABLE_WRITE(oldstatus); break;
|
2016-06-29 00:06:56 +02:00
|
|
|
#if E_STEPPERS > 1
|
2017-04-18 21:39:45 +02:00
|
|
|
case 1: E1_ENABLE_WRITE(oldstatus); break;
|
2016-06-29 00:06:56 +02:00
|
|
|
#if E_STEPPERS > 2
|
2017-04-18 21:39:45 +02:00
|
|
|
case 2: E2_ENABLE_WRITE(oldstatus); break;
|
2016-06-29 00:06:56 +02:00
|
|
|
#if E_STEPPERS > 3
|
2017-04-18 21:39:45 +02:00
|
|
|
case 3: E3_ENABLE_WRITE(oldstatus); break;
|
2017-04-06 23:46:52 +02:00
|
|
|
#if E_STEPPERS > 4
|
2017-04-18 21:39:45 +02:00
|
|
|
case 4: E4_ENABLE_WRITE(oldstatus); break;
|
2018-09-13 08:35:55 +02:00
|
|
|
#if E_STEPPERS > 5
|
|
|
|
case 5: E5_ENABLE_WRITE(oldstatus); break;
|
|
|
|
#endif // E_STEPPERS > 5
|
2017-04-06 23:46:52 +02:00
|
|
|
#endif // E_STEPPERS > 4
|
|
|
|
#endif // E_STEPPERS > 3
|
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
2016-06-29 00:06:56 +02:00
|
|
|
}
|
|
|
|
#endif // !SWITCHING_EXTRUDER
|
2018-03-22 01:30:06 +01:00
|
|
|
|
2019-04-10 22:51:48 +02:00
|
|
|
gcode.reset_stepper_timeout();
|
2012-11-06 12:06:41 +01:00
|
|
|
}
|
2016-06-29 00:06:56 +02:00
|
|
|
#endif // EXTRUDER_RUNOUT_PREVENT
|
2015-04-04 00:31:35 +02:00
|
|
|
|
2015-07-31 07:24:43 +02:00
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
2013-08-07 16:10:26 +02:00
|
|
|
// handle delayed move timeout
|
2016-04-11 00:55:12 +02:00
|
|
|
if (delayed_move_time && ELAPSED(ms, delayed_move_time + 1000UL) && IsRunning()) {
|
2013-08-07 16:10:26 +02:00
|
|
|
// travel moves have been received so enact them
|
|
|
|
delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
|
2017-10-21 18:42:26 +02:00
|
|
|
set_destination_from_current();
|
2016-06-11 04:23:41 +02:00
|
|
|
prepare_move_to_destination();
|
2013-08-07 16:10:26 +02:00
|
|
|
}
|
2013-10-20 12:12:35 +02:00
|
|
|
#endif
|
2015-04-04 00:31:35 +02:00
|
|
|
|
2015-07-31 07:24:43 +02:00
|
|
|
#if ENABLED(TEMP_STAT_LEDS)
|
2015-04-04 00:31:35 +02:00
|
|
|
handle_status_leds();
|
2013-10-20 12:12:35 +02:00
|
|
|
#endif
|
2015-04-04 00:31:35 +02:00
|
|
|
|
2017-12-15 22:03:14 +01:00
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
|
|
|
monitor_tmc_driver();
|
2017-03-07 06:00:43 +01:00
|
|
|
#endif
|
|
|
|
|
2019-01-24 02:06:54 +01:00
|
|
|
#if ENABLED(MONITOR_L6470_DRIVER_STATUS)
|
|
|
|
L6470.monitor_driver();
|
|
|
|
#endif
|
|
|
|
|
2017-11-16 02:01:52 +01:00
|
|
|
// Limit check_axes_activity frequency to 10Hz
|
|
|
|
static millis_t next_check_axes_ms = 0;
|
|
|
|
if (ELAPSED(ms, next_check_axes_ms)) {
|
|
|
|
planner.check_axes_activity();
|
|
|
|
next_check_axes_ms = ms + 100UL;
|
|
|
|
}
|
2019-02-27 04:03:13 +01:00
|
|
|
|
|
|
|
#if PIN_EXISTS(FET_SAFETY)
|
|
|
|
static millis_t FET_next;
|
|
|
|
if (ELAPSED(ms, FET_next)) {
|
|
|
|
FET_next = ms + FET_SAFETY_DELAY; // 2uS pulse every FET_SAFETY_DELAY mS
|
|
|
|
OUT_WRITE(FET_SAFETY_PIN, !FET_SAFETY_INVERTED);
|
|
|
|
DELAY_US(2);
|
|
|
|
WRITE(FET_SAFETY_PIN, FET_SAFETY_INVERTED);
|
|
|
|
}
|
|
|
|
#endif
|
2012-11-06 12:06:41 +01:00
|
|
|
}
|
|
|
|
|
2016-09-13 09:11:45 +02:00
|
|
|
/**
|
|
|
|
* Standard idle routine keeps the machine alive
|
|
|
|
*/
|
|
|
|
void idle(
|
2017-05-26 20:01:02 +02:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
2016-09-13 09:11:45 +02:00
|
|
|
bool no_stepper_sleep/*=false*/
|
|
|
|
#endif
|
|
|
|
) {
|
2017-08-26 00:03:07 +02:00
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
2018-08-18 08:33:13 +02:00
|
|
|
max7219.idle_tasks();
|
2018-06-19 05:04:03 +02:00
|
|
|
#endif
|
2017-08-26 00:03:07 +02:00
|
|
|
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.update();
|
2016-11-09 01:03:40 +01:00
|
|
|
|
2017-09-09 06:49:49 +02:00
|
|
|
#if ENABLED(HOST_KEEPALIVE_FEATURE)
|
|
|
|
gcode.host_keepalive();
|
|
|
|
#endif
|
2016-11-09 01:03:40 +01:00
|
|
|
|
2016-09-13 09:11:45 +02:00
|
|
|
manage_inactivity(
|
2017-05-26 20:01:02 +02:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
2016-09-13 09:11:45 +02:00
|
|
|
no_stepper_sleep
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
thermalManager.manage_heater();
|
|
|
|
|
|
|
|
#if ENABLED(PRINTCOUNTER)
|
|
|
|
print_job_timer.tick();
|
|
|
|
#endif
|
|
|
|
|
2016-10-05 04:31:50 +02:00
|
|
|
#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
|
2016-09-13 09:11:45 +02:00
|
|
|
buzzer.tick();
|
|
|
|
#endif
|
2017-06-09 14:06:23 +02:00
|
|
|
|
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
2018-02-08 10:57:11 +01:00
|
|
|
static millis_t i2cpem_next_update_ms;
|
2018-03-22 01:30:06 +01:00
|
|
|
if (planner.has_blocks_queued() && ELAPSED(millis(), i2cpem_next_update_ms)) {
|
2017-06-09 14:06:23 +02:00
|
|
|
I2CPEM.update();
|
2018-02-08 10:57:11 +01:00
|
|
|
i2cpem_next_update_ms = millis() + I2CPE_MIN_UPD_TIME_MS;
|
2017-06-09 14:06:23 +02:00
|
|
|
}
|
|
|
|
#endif
|
2017-12-21 06:22:08 +01:00
|
|
|
|
|
|
|
#ifdef HAL_IDLETASK
|
|
|
|
HAL_idletask();
|
|
|
|
#endif
|
2018-03-07 08:57:09 +01:00
|
|
|
|
|
|
|
#if HAS_AUTO_REPORTING
|
|
|
|
if (!suspend_auto_report) {
|
|
|
|
#if ENABLED(AUTO_REPORT_TEMPERATURES)
|
|
|
|
thermalManager.auto_report_temperatures();
|
|
|
|
#endif
|
|
|
|
#if ENABLED(AUTO_REPORT_SD_STATUS)
|
|
|
|
card.auto_report_sd_status();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
2018-07-02 17:06:17 +02:00
|
|
|
|
|
|
|
#if ENABLED(USB_FLASH_DRIVE_SUPPORT)
|
|
|
|
Sd2Card::idle();
|
|
|
|
#endif
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#if ENABLED(PRUSA_MMU2)
|
2019-04-09 00:56:40 +02:00
|
|
|
mmu2.mmu_loop();
|
2019-02-01 02:10:52 +01:00
|
|
|
#endif
|
2016-09-13 09:11:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kill all activity and lock the machine.
|
|
|
|
* After this the machine will need to be reset.
|
|
|
|
*/
|
2019-05-09 18:45:55 +02:00
|
|
|
void kill(PGM_P const lcd_msg/*=nullptr*/) {
|
2017-03-21 15:06:01 +01:00
|
|
|
thermalManager.disable_all_heaters();
|
2017-03-29 02:45:54 +02:00
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ERROR_MSG(MSG_ERR_KILLED);
|
2018-10-19 20:30:37 +02:00
|
|
|
|
2019-05-08 03:32:50 +02:00
|
|
|
#if HAS_DISPLAY
|
2018-11-11 19:16:24 +01:00
|
|
|
ui.kill_screen(lcd_msg ? lcd_msg : PSTR(MSG_KILLED));
|
2015-10-04 17:33:55 +02:00
|
|
|
#else
|
|
|
|
UNUSED(lcd_msg);
|
2015-05-20 22:03:16 +02:00
|
|
|
#endif
|
2015-05-20 20:53:48 +02:00
|
|
|
|
2017-07-28 06:42:01 +02:00
|
|
|
#ifdef ACTION_ON_KILL
|
2019-01-28 05:43:13 +01:00
|
|
|
host_action_kill();
|
2017-07-02 10:44:24 +02:00
|
|
|
#endif
|
2017-07-07 04:24:30 +02:00
|
|
|
|
2018-10-19 04:20:56 +02:00
|
|
|
minkill();
|
|
|
|
}
|
|
|
|
|
|
|
|
void minkill() {
|
|
|
|
|
2018-10-20 08:44:46 +02:00
|
|
|
// Wait a short time (allows messages to get out before shutting down.
|
2018-10-21 20:43:21 +02:00
|
|
|
for (int i = 1000; i--;) DELAY_US(600);
|
2018-10-20 08:44:46 +02:00
|
|
|
|
|
|
|
cli(); // Stop interrupts
|
|
|
|
|
|
|
|
// Wait to ensure all interrupts stopped
|
2018-10-21 20:43:21 +02:00
|
|
|
for (int i = 1000; i--;) DELAY_US(250);
|
2018-10-19 04:20:56 +02:00
|
|
|
|
|
|
|
thermalManager.disable_all_heaters(); // turn off heaters again
|
|
|
|
|
2015-03-31 01:50:05 +02:00
|
|
|
#if HAS_POWER_SWITCH
|
2018-03-19 02:58:10 +01:00
|
|
|
PSU_OFF();
|
2015-03-31 01:50:05 +02:00
|
|
|
#endif
|
|
|
|
|
2017-09-27 11:40:48 +02:00
|
|
|
#if HAS_SUICIDE
|
|
|
|
suicide();
|
|
|
|
#endif
|
|
|
|
|
2019-03-10 15:57:38 +01:00
|
|
|
#if HAS_KILL
|
|
|
|
|
|
|
|
// Wait for kill to be released
|
|
|
|
while (!READ(KILL_PIN)) {
|
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
watchdog_reset();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wait for kill to be pressed
|
|
|
|
while (READ(KILL_PIN)) {
|
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
watchdog_reset();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void(*resetFunc)(void) = 0; // Declare resetFunc() at address 0
|
|
|
|
resetFunc(); // Jump to address 0
|
|
|
|
|
|
|
|
#else // !HAS_KILL
|
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
watchdog_reset();
|
|
|
|
#endif
|
|
|
|
} // Wait for reset
|
|
|
|
|
|
|
|
#endif // !HAS_KILL
|
2012-11-06 12:06:41 +01:00
|
|
|
}
|
|
|
|
|
2016-09-13 09:11:45 +02:00
|
|
|
/**
|
|
|
|
* Turn off heaters and stop the print in progress
|
|
|
|
* After a stop the machine may be resumed with M999
|
|
|
|
*/
|
2016-04-18 09:05:22 +02:00
|
|
|
void stop() {
|
2017-05-07 13:06:06 +02:00
|
|
|
thermalManager.disable_all_heaters(); // 'unpause' taken care of in here
|
2018-10-19 04:20:56 +02:00
|
|
|
print_job_timer.stop();
|
2017-05-07 13:06:06 +02:00
|
|
|
|
|
|
|
#if ENABLED(PROBING_FANS_OFF)
|
2019-01-12 07:41:48 +01:00
|
|
|
if (thermalManager.fans_paused) thermalManager.set_fans_paused(false); // put things back the way they were
|
2017-05-07 13:06:06 +02:00
|
|
|
#endif
|
|
|
|
|
2015-05-17 10:47:02 +02:00
|
|
|
if (IsRunning()) {
|
2019-06-19 07:00:19 +02:00
|
|
|
queue.stop();
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ERROR_MSG(MSG_ERR_STOPPED);
|
2015-05-17 10:47:02 +02:00
|
|
|
LCD_MESSAGEPGM(MSG_STOPPED);
|
2017-04-01 07:23:14 +02:00
|
|
|
safe_delay(350); // allow enough time for messages to get out before stopping
|
|
|
|
Running = false;
|
2012-11-06 12:06:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-12 03:21:54 +02:00
|
|
|
/**
|
|
|
|
* Marlin entry-point: Set up before the program loop
|
|
|
|
* - Set up the kill pin, filament runout, power hold
|
|
|
|
* - Start the serial port
|
|
|
|
* - Print startup messages and diagnostics
|
|
|
|
* - Get EEPROM or default settings
|
|
|
|
* - Initialize managers for:
|
|
|
|
* • temperature
|
|
|
|
* • planner
|
|
|
|
* • watchdog
|
|
|
|
* • stepper
|
|
|
|
* • photo pin
|
|
|
|
* • servos
|
|
|
|
* • LCD controller
|
|
|
|
* • Digipot I2C
|
|
|
|
* • Z probe sled
|
|
|
|
* • status LEDs
|
|
|
|
*/
|
|
|
|
void setup() {
|
|
|
|
|
2019-06-27 23:29:17 +02:00
|
|
|
HAL_init();
|
2017-12-21 06:42:46 +01:00
|
|
|
|
2019-01-24 02:06:54 +01:00
|
|
|
#if HAS_DRIVER(L6470)
|
|
|
|
L6470.init(); // setup SPI and then init chips
|
|
|
|
#endif
|
|
|
|
|
2017-08-26 00:03:07 +02:00
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
2018-08-18 08:33:13 +02:00
|
|
|
max7219.init();
|
2017-08-26 00:03:07 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-30 02:00:49 +02:00
|
|
|
#if ENABLED(DISABLE_DEBUG)
|
|
|
|
// Disable any hardware debug to free up pins for IO
|
|
|
|
#ifdef JTAGSWD_DISABLE
|
|
|
|
JTAGSWD_DISABLE();
|
|
|
|
#elif defined(JTAG_DISABLE)
|
|
|
|
JTAG_DISABLE();
|
|
|
|
#else
|
|
|
|
#error "DISABLE_DEBUG is not supported for the selected MCU/Board"
|
|
|
|
#endif
|
|
|
|
#elif ENABLED(DISABLE_JTAG)
|
2018-09-28 01:02:50 +02:00
|
|
|
// Disable JTAG to free up pins for IO
|
|
|
|
#ifdef JTAG_DISABLE
|
|
|
|
JTAG_DISABLE();
|
|
|
|
#else
|
|
|
|
#error "DISABLE_JTAG is not supported for the selected MCU/Board"
|
|
|
|
#endif
|
2016-09-12 03:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
2019-02-13 03:08:34 +01:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2018-02-18 09:42:09 +01:00
|
|
|
runout.setup();
|
2016-09-12 03:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
setup_killpin();
|
2019-06-05 06:18:51 +02:00
|
|
|
|
2019-06-20 22:47:50 +02:00
|
|
|
#if HAS_DRIVER(TMC2208) || HAS_DRIVER(TMC2209)
|
|
|
|
tmc_serial_begin();
|
2019-05-26 13:07:12 +02:00
|
|
|
#endif
|
2019-06-05 06:18:51 +02:00
|
|
|
|
2016-09-12 03:21:54 +02:00
|
|
|
setup_powerhold();
|
|
|
|
|
|
|
|
#if HAS_STEPPER_RESET
|
|
|
|
disableStepperDrivers();
|
|
|
|
#endif
|
|
|
|
|
2017-11-05 15:49:38 +01:00
|
|
|
#if NUM_SERIAL > 0
|
|
|
|
MYSERIAL0.begin(BAUDRATE);
|
|
|
|
#if NUM_SERIAL > 1
|
|
|
|
MYSERIAL1.begin(BAUDRATE);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NUM_SERIAL > 0
|
|
|
|
uint32_t serial_connect_timeout = millis() + 1000UL;
|
2017-10-08 18:38:10 +02:00
|
|
|
while (!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
2017-11-05 15:49:38 +01:00
|
|
|
#if NUM_SERIAL > 1
|
|
|
|
serial_connect_timeout = millis() + 1000UL;
|
2017-10-08 18:38:10 +02:00
|
|
|
while (!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
2017-11-05 15:49:38 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHOLNPGM("start");
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_ECHO_START();
|
2016-09-12 03:21:54 +02:00
|
|
|
|
2018-10-07 00:18:10 +02:00
|
|
|
#if TMC_HAS_SPI
|
2018-10-03 09:48:49 +02:00
|
|
|
#if DISABLED(TMC_USE_SW_SPI)
|
|
|
|
SPI.begin();
|
|
|
|
#endif
|
2018-02-10 21:08:53 +01:00
|
|
|
tmc_init_cs_pins();
|
|
|
|
#endif
|
|
|
|
|
2018-07-02 06:11:42 +02:00
|
|
|
#ifdef BOARD_INIT
|
|
|
|
BOARD_INIT();
|
|
|
|
#endif
|
|
|
|
|
2016-09-12 03:21:54 +02:00
|
|
|
// Check startup - does nothing if bootloader sets MCUSR to 0
|
2017-06-18 01:36:10 +02:00
|
|
|
byte mcu = HAL_get_reset_source();
|
2017-06-16 21:20:58 +02:00
|
|
|
if (mcu & 1) SERIAL_ECHOLNPGM(MSG_POWERUP);
|
|
|
|
if (mcu & 2) SERIAL_ECHOLNPGM(MSG_EXTERNAL_RESET);
|
|
|
|
if (mcu & 4) SERIAL_ECHOLNPGM(MSG_BROWNOUT_RESET);
|
|
|
|
if (mcu & 8) SERIAL_ECHOLNPGM(MSG_WATCHDOG_RESET);
|
2016-09-12 03:21:54 +02:00
|
|
|
if (mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET);
|
2017-06-18 01:36:10 +02:00
|
|
|
HAL_clear_reset_source();
|
|
|
|
|
2016-09-12 03:21:54 +02:00
|
|
|
SERIAL_ECHOPGM(MSG_MARLIN);
|
2016-09-13 00:49:35 +02:00
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
SERIAL_ECHOLNPGM(SHORT_BUILD_VERSION);
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_EOL();
|
2016-09-12 03:21:54 +02:00
|
|
|
|
2016-09-13 00:49:35 +02:00
|
|
|
#if defined(STRING_DISTRIBUTION_DATE) && defined(STRING_CONFIG_H_AUTHOR)
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_ECHO_START();
|
2016-09-13 00:49:35 +02:00
|
|
|
SERIAL_ECHOPGM(MSG_CONFIGURATION_VER);
|
|
|
|
SERIAL_ECHOPGM(STRING_DISTRIBUTION_DATE);
|
|
|
|
SERIAL_ECHOLNPGM(MSG_AUTHOR STRING_CONFIG_H_AUTHOR);
|
2018-11-29 23:58:58 +01:00
|
|
|
SERIAL_ECHO_MSG("Compiled: " __DATE__);
|
2016-09-13 00:49:35 +02:00
|
|
|
#endif
|
2016-09-12 03:21:54 +02:00
|
|
|
|
2017-06-09 17:51:23 +02:00
|
|
|
SERIAL_ECHO_START();
|
2019-03-05 13:46:19 +01:00
|
|
|
SERIAL_ECHOLNPAIR(MSG_FREE_MEMORY, freeMemory(), MSG_PLANNER_BUFFER_BYTES, (int)sizeof(block_t) * (BLOCK_BUFFER_SIZE));
|
2016-09-12 03:21:54 +02:00
|
|
|
|
2019-05-04 06:53:15 +02:00
|
|
|
// UI must be initialized before EEPROM
|
|
|
|
// (because EEPROM code calls the UI).
|
|
|
|
ui.init();
|
|
|
|
ui.reset_status();
|
|
|
|
|
|
|
|
#if HAS_SPI_LCD && ENABLED(SHOW_BOOTSCREEN)
|
|
|
|
ui.show_bootscreen();
|
|
|
|
#endif
|
|
|
|
|
2019-06-15 22:32:09 +02:00
|
|
|
#if ENABLED(SDIO_SUPPORT) && !PIN_EXISTS(SD_DETECT)
|
2019-05-02 07:45:21 +02:00
|
|
|
// Auto-mount the SD for EEPROM.dat emulation
|
|
|
|
if (!card.isDetected()) card.initsd();
|
|
|
|
#endif
|
|
|
|
|
2016-09-12 03:21:54 +02:00
|
|
|
// Load data from EEPROM if available (or use defaults)
|
|
|
|
// This also updates variables in the planner, elsewhere
|
2019-07-04 02:11:30 +02:00
|
|
|
(void)settings.load();
|
2018-03-05 04:23:43 +01:00
|
|
|
|
2017-04-15 04:41:21 +02:00
|
|
|
#if HAS_M206_COMMAND
|
2017-03-05 01:01:33 +01:00
|
|
|
// Initialize current position based on home_offset
|
2018-12-03 01:06:20 +01:00
|
|
|
LOOP_XYZ(a) current_position[a] += home_offset[a];
|
2017-03-05 01:01:33 +01:00
|
|
|
#endif
|
2016-09-12 03:21:54 +02:00
|
|
|
|
|
|
|
// Vital to init stepper/planner equivalent for current_position
|
2018-09-17 04:24:15 +02:00
|
|
|
sync_plan_position();
|
2016-09-12 03:21:54 +02:00
|
|
|
|
|
|
|
thermalManager.init(); // Initialize temperature loop
|
|
|
|
|
2018-03-05 04:23:43 +01:00
|
|
|
print_job_timer.init(); // Initial setup of print job timer
|
|
|
|
|
2018-05-16 09:08:43 +02:00
|
|
|
endstops.init(); // Init endstops and pullups
|
|
|
|
|
|
|
|
stepper.init(); // Init stepper. This enables interrupts!
|
2017-09-08 22:35:25 +02:00
|
|
|
|
|
|
|
#if HAS_SERVOS
|
|
|
|
servo_init();
|
|
|
|
#endif
|
2016-09-12 03:21:54 +02:00
|
|
|
|
2018-04-02 06:54:12 +02:00
|
|
|
#if HAS_Z_SERVO_PROBE
|
2017-11-19 20:39:46 +01:00
|
|
|
servo_probe_init();
|
|
|
|
#endif
|
|
|
|
|
2016-11-01 12:24:21 +01:00
|
|
|
#if HAS_PHOTOGRAPH
|
|
|
|
OUT_WRITE(PHOTOGRAPH_PIN, LOW);
|
|
|
|
#endif
|
|
|
|
|
2019-06-28 06:06:49 +02:00
|
|
|
#if HAS_CUTTER
|
|
|
|
cutter.init();
|
2017-04-07 20:52:45 +02:00
|
|
|
#endif
|
|
|
|
|
2019-06-14 01:43:11 +02:00
|
|
|
#if ENABLED(COOLANT_MIST)
|
|
|
|
OUT_WRITE(COOLANT_MIST_PIN, COOLANT_MIST_INVERT); // Init Mist Coolant OFF
|
|
|
|
#endif
|
|
|
|
#if ENABLED(COOLANT_FLOOD)
|
|
|
|
OUT_WRITE(COOLANT_FLOOD_PIN, COOLANT_FLOOD_INVERT); // Init Flood Coolant OFF
|
|
|
|
#endif
|
|
|
|
|
2016-09-12 03:21:54 +02:00
|
|
|
#if HAS_BED_PROBE
|
|
|
|
endstops.enable_z_probe(false);
|
|
|
|
#endif
|
|
|
|
|
2017-05-04 23:38:29 +02:00
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
2018-10-02 01:33:52 +02:00
|
|
|
SET_OUTPUT(CONTROLLER_FAN_PIN);
|
2016-09-12 03:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_STEPPER_RESET
|
|
|
|
enableStepperDrivers();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DIGIPOT_I2C)
|
|
|
|
digipot_i2c_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
|
|
|
dac_init();
|
|
|
|
#endif
|
|
|
|
|
2019-03-17 05:43:06 +01:00
|
|
|
#if EITHER(Z_PROBE_SLED, SOLENOID_PROBE) && HAS_SOLENOID_1
|
2018-10-02 01:33:52 +02:00
|
|
|
OUT_WRITE(SOL1_PIN, LOW); // OFF
|
2017-04-14 23:36:02 +02:00
|
|
|
#endif
|
2016-09-12 03:21:54 +02:00
|
|
|
|
2017-07-02 09:26:49 +02:00
|
|
|
#if HAS_HOME
|
|
|
|
SET_INPUT_PULLUP(HOME_PIN);
|
|
|
|
#endif
|
2016-09-12 03:21:54 +02:00
|
|
|
|
2016-09-24 22:33:29 +02:00
|
|
|
#if PIN_EXISTS(STAT_LED_RED)
|
2018-10-02 01:33:52 +02:00
|
|
|
OUT_WRITE(STAT_LED_RED_PIN, LOW); // OFF
|
2016-09-12 03:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
2016-09-24 22:33:29 +02:00
|
|
|
#if PIN_EXISTS(STAT_LED_BLUE)
|
2018-10-02 01:33:52 +02:00
|
|
|
OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // OFF
|
2016-09-12 03:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
2017-11-28 08:07:10 +01:00
|
|
|
#if HAS_COLOR_LEDS
|
|
|
|
leds.setup();
|
2017-07-13 17:01:21 +02:00
|
|
|
#endif
|
|
|
|
|
2019-01-16 01:50:56 +01:00
|
|
|
#if HAS_CASE_LIGHT
|
2019-01-17 20:20:26 +01:00
|
|
|
#if DISABLED(CASE_LIGHT_USE_NEOPIXEL)
|
2019-03-13 12:51:15 +01:00
|
|
|
if (PWM_PIN(CASE_LIGHT_PIN)) SET_PWM(CASE_LIGHT_PIN); else SET_OUTPUT(CASE_LIGHT_PIN);
|
2019-01-17 20:20:26 +01:00
|
|
|
#endif
|
2019-01-16 01:50:56 +01:00
|
|
|
update_case_light();
|
|
|
|
#endif
|
|
|
|
|
2017-06-02 20:57:31 +02:00
|
|
|
#if ENABLED(MK2_MULTIPLEXER)
|
|
|
|
SET_OUTPUT(E_MUX0_PIN);
|
|
|
|
SET_OUTPUT(E_MUX1_PIN);
|
|
|
|
SET_OUTPUT(E_MUX2_PIN);
|
|
|
|
#endif
|
2017-08-26 00:03:07 +02:00
|
|
|
|
2017-08-15 14:48:10 +02:00
|
|
|
#if HAS_FANMUX
|
|
|
|
fanmux_init();
|
|
|
|
#endif
|
2017-08-26 00:03:07 +02:00
|
|
|
|
2018-10-16 10:38:57 +02:00
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
mixer.init();
|
2016-09-12 03:21:54 +02:00
|
|
|
#endif
|
|
|
|
|
2017-01-22 01:10:02 +01:00
|
|
|
#if ENABLED(BLTOUCH)
|
2019-05-26 04:56:47 +02:00
|
|
|
bltouch.init(/*set_voltage=*/true);
|
2017-01-22 01:10:02 +01:00
|
|
|
#endif
|
|
|
|
|
2017-06-09 14:06:23 +02:00
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
|
|
|
I2CPEM.init();
|
|
|
|
#endif
|
|
|
|
|
2016-09-12 03:21:54 +02:00
|
|
|
#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0
|
|
|
|
i2c.onReceive(i2c_on_receive);
|
|
|
|
i2c.onRequest(i2c_on_request);
|
|
|
|
#endif
|
2016-11-05 22:38:48 +01:00
|
|
|
|
2018-05-18 20:16:59 +02:00
|
|
|
#if DO_SWITCH_EXTRUDER
|
2018-11-17 03:47:07 +01:00
|
|
|
move_extruder_servo(0); // Initialize extruder servo
|
2017-06-04 15:40:57 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(SWITCHING_NOZZLE)
|
2019-02-04 07:19:56 +01:00
|
|
|
// Initialize nozzle servo(s)
|
|
|
|
#if SWITCHING_NOZZLE_TWO_SERVOS
|
|
|
|
lower_nozzle(0);
|
|
|
|
raise_nozzle(1);
|
|
|
|
#else
|
|
|
|
move_nozzle_servo(0);
|
|
|
|
#endif
|
2017-06-04 15:40:57 +02:00
|
|
|
#endif
|
2017-08-21 23:30:08 +02:00
|
|
|
|
2019-02-06 13:30:53 +01:00
|
|
|
#if ENABLED(MAGNETIC_PARKING_EXTRUDER)
|
|
|
|
mpe_settings_init();
|
|
|
|
#endif
|
|
|
|
|
2017-08-13 23:35:59 +02:00
|
|
|
#if ENABLED(PARKING_EXTRUDER)
|
2019-02-06 13:30:53 +01:00
|
|
|
pe_solenoid_init();
|
2017-08-13 23:35:59 +02:00
|
|
|
#endif
|
2018-03-09 00:34:50 +01:00
|
|
|
|
2019-07-01 12:55:23 +02:00
|
|
|
#if ENABLED(ELECTROMAGNETIC_SWITCHING_TOOLHEAD)
|
|
|
|
est_init();
|
|
|
|
#endif
|
|
|
|
|
2018-04-22 02:41:26 +02:00
|
|
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
2018-11-17 03:47:07 +01:00
|
|
|
recovery.check();
|
2018-04-22 02:41:26 +02:00
|
|
|
#endif
|
|
|
|
|
2018-11-17 03:47:07 +01:00
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
watchdog_init(); // Reinit watchdog after HAL_get_reset_source call
|
2018-03-09 00:34:50 +01:00
|
|
|
#endif
|
2018-09-08 19:08:31 +02:00
|
|
|
|
|
|
|
#if ENABLED(EXTERNAL_CLOSED_LOOP_CONTROLLER)
|
|
|
|
init_closedloop();
|
|
|
|
#endif
|
2018-09-12 10:49:46 +02:00
|
|
|
|
2019-07-04 02:11:30 +02:00
|
|
|
#if ENABLED(INIT_SDCARD_ON_BOOT) && !HAS_SPI_LCD
|
|
|
|
card.beginautostart();
|
2018-09-12 10:49:46 +02:00
|
|
|
#endif
|
2018-12-10 03:54:48 +01:00
|
|
|
|
|
|
|
#if HAS_TRINAMIC && DISABLED(PS_DEFAULT_OFF)
|
|
|
|
test_tmc_connection(true, true, true, true);
|
|
|
|
#endif
|
2019-02-01 02:10:52 +01:00
|
|
|
|
|
|
|
#if ENABLED(PRUSA_MMU2)
|
|
|
|
mmu2.init();
|
|
|
|
#endif
|
2016-09-12 03:21:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main Marlin program loop
|
|
|
|
*
|
|
|
|
* - Save or log commands to SD
|
|
|
|
* - Process available commands (if not saving)
|
|
|
|
* - Call endstop manager
|
2018-05-01 08:01:02 +02:00
|
|
|
* - Call inactivity manager
|
2016-09-12 03:21:54 +02:00
|
|
|
*/
|
|
|
|
void loop() {
|
|
|
|
|
2018-04-05 03:13:27 +02:00
|
|
|
for (;;) {
|
2018-04-16 01:27:54 +02:00
|
|
|
|
2018-05-01 08:01:02 +02:00
|
|
|
#if ENABLED(SDSUPPORT)
|
2019-06-11 06:57:55 +02:00
|
|
|
|
2018-05-01 08:01:02 +02:00
|
|
|
card.checkautostart();
|
2018-10-19 22:27:07 +02:00
|
|
|
|
2018-11-17 05:39:16 +01:00
|
|
|
if (card.flag.abort_sd_printing) {
|
2018-04-16 01:27:54 +02:00
|
|
|
card.stopSDPrint(
|
|
|
|
#if SD_RESORT
|
|
|
|
true
|
|
|
|
#endif
|
|
|
|
);
|
2019-06-19 07:00:19 +02:00
|
|
|
queue.clear();
|
2018-04-16 01:27:54 +02:00
|
|
|
quickstop_stepper();
|
|
|
|
print_job_timer.stop();
|
2019-06-11 06:57:55 +02:00
|
|
|
#if DISABLED(SD_ABORT_NO_COOLDOWN)
|
|
|
|
thermalManager.disable_all_heaters();
|
|
|
|
#endif
|
2019-01-12 07:41:48 +01:00
|
|
|
thermalManager.zero_fan_speeds();
|
2018-04-16 01:27:54 +02:00
|
|
|
wait_for_heatup = false;
|
2018-07-03 06:21:28 +02:00
|
|
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
|
|
|
card.removeJobRecoveryFile();
|
|
|
|
#endif
|
2019-04-03 05:09:30 +02:00
|
|
|
#ifdef EVENT_GCODE_SD_STOP
|
2019-06-19 07:00:19 +02:00
|
|
|
queue.inject_P(PSTR(EVENT_GCODE_SD_STOP));
|
2019-04-04 03:21:06 +02:00
|
|
|
#endif
|
2018-04-16 01:27:54 +02:00
|
|
|
}
|
2019-06-11 06:57:55 +02:00
|
|
|
|
2018-10-19 21:25:07 +02:00
|
|
|
#endif // SDSUPPORT
|
2018-04-16 01:27:54 +02:00
|
|
|
|
2019-06-19 07:00:19 +02:00
|
|
|
if (queue.length < BUFSIZE) queue.get_available_commands();
|
|
|
|
queue.advance();
|
2018-07-12 00:33:26 +02:00
|
|
|
endstops.event_handler();
|
2018-04-05 03:13:27 +02:00
|
|
|
idle();
|
|
|
|
}
|
2016-09-12 03:21:54 +02:00
|
|
|
}
|