2016-03-25 01:19:46 -05:00
|
|
|
/**
|
2016-03-24 13:01:20 -05:00
|
|
|
* Marlin 3D Printer Firmware
|
2017-03-18 10:15:54 -05:00
|
|
|
* Copyright (C) 2016, 2017 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2015-05-17 03:44:53 -05:00
|
|
|
*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
2016-03-24 13:01:20 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-25 01:19:46 -05:00
|
|
|
/**
|
2015-05-17 03:44:53 -05:00
|
|
|
* About Marlin
|
|
|
|
*
|
|
|
|
* This firmware is a mashup between Sprinter and grbl.
|
|
|
|
* - https://github.com/kliment/Sprinter
|
2018-02-06 02:28:18 -06:00
|
|
|
* - https://github.com/grbl/grbl
|
2015-04-13 19:17:36 -05:00
|
|
|
*/
|
2012-11-06 05:06:41 -06:00
|
|
|
|
2016-11-18 21:54:38 -06:00
|
|
|
#include "Marlin.h"
|
|
|
|
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "lcd/ultralcd.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
#include "module/motion.h"
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "module/planner.h"
|
|
|
|
#include "module/stepper.h"
|
|
|
|
#include "module/endstops.h"
|
2017-09-08 15:35:25 -05:00
|
|
|
#include "module/probe.h"
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "module/temperature.h"
|
|
|
|
#include "sd/cardreader.h"
|
|
|
|
#include "module/configuration_store.h"
|
2017-09-09 00:18:43 -05:00
|
|
|
#include "module/printcounter.h" // PrintCounter or Stopwatch
|
2017-06-17 18:36:10 -05:00
|
|
|
#ifdef ARDUINO
|
2017-09-06 06:28:33 -05:00
|
|
|
#include <pins_arduino.h>
|
2017-06-17 18:36:10 -05:00
|
|
|
#endif
|
2017-09-06 06:28:33 -05:00
|
|
|
#include <math.h>
|
|
|
|
#include "libs/nozzle.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
|
|
|
|
#include "gcode/gcode.h"
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "gcode/parser.h"
|
2017-09-07 22:33:16 -05:00
|
|
|
#include "gcode/queue.h"
|
2016-11-18 21:54:38 -06:00
|
|
|
|
2017-09-14 15:33:07 -05:00
|
|
|
#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
|
|
|
|
#include "libs/buzzer.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-17 18:45:21 -05:00
|
|
|
#if ENABLED(DIGIPOT_I2C)
|
|
|
|
#include "feature/digipot/digipot.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 00:06:16 -05:00
|
|
|
#if ENABLED(MIXING_EXTRUDER)
|
|
|
|
#include "feature/mixing.h"
|
|
|
|
#endif
|
|
|
|
|
2016-11-18 21:54:38 -06:00
|
|
|
#if ENABLED(BEZIER_CURVE_SUPPORT)
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "module/planner_bezier.h"
|
2016-11-18 21:54:38 -06:00
|
|
|
#endif
|
|
|
|
|
2017-08-25 17:03:07 -05:00
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
2017-09-08 14:47:47 -05:00
|
|
|
#include "feature/Max7219_Debug_LEDs.h"
|
2017-08-25 17:03:07 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 14:47:47 -05:00
|
|
|
#if HAS_COLOR_LEDS
|
|
|
|
#include "feature/leds/leds.h"
|
2017-06-10 01:02:15 -05:00
|
|
|
#endif
|
|
|
|
|
2016-11-18 21:54:38 -06:00
|
|
|
#if HAS_SERVOS
|
2017-11-19 13:39:46 -06:00
|
|
|
#include "module/servo.h"
|
2016-11-18 21:54:38 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_DIGIPOTSS
|
|
|
|
#include <SPI.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "feature/dac/stepper_dac.h"
|
2016-11-18 21:54:38 -06:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(EXPERIMENTAL_I2CBUS)
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "feature/twibus.h"
|
2017-09-17 02:49:13 -05:00
|
|
|
TWIBus i2c;
|
2016-11-18 21:54:38 -06:00
|
|
|
#endif
|
|
|
|
|
2017-06-09 07:06:23 -05:00
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
2017-09-06 06:28:33 -05:00
|
|
|
#include "feature/I2CPositionEncoder.h"
|
2017-06-09 07:06:23 -05:00
|
|
|
#endif
|
|
|
|
|
2016-11-18 21:54:38 -06:00
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
2018-04-12 20:25:08 -05:00
|
|
|
#include HAL_PATH(HAL, endstop_interrupts.h)
|
2016-11-18 21:54:38 -06:00
|
|
|
#endif
|
|
|
|
|
2017-12-15 15:03:14 -06:00
|
|
|
#if HAS_TRINAMIC
|
|
|
|
#include "feature/tmc_util.h"
|
2017-09-17 18:34:04 -05:00
|
|
|
#endif
|
|
|
|
|
2015-07-31 00:24:43 -05:00
|
|
|
#if ENABLED(SDSUPPORT)
|
2015-01-29 20:52:21 -06:00
|
|
|
CardReader card;
|
2012-11-06 05:06:41 -06:00
|
|
|
#endif
|
2015-01-29 20:52:21 -06:00
|
|
|
|
2016-09-29 15:06:01 -05:00
|
|
|
#if ENABLED(G38_PROBE_TARGET)
|
2016-09-26 01:30:34 -05:00
|
|
|
bool G38_move = false,
|
|
|
|
G38_endstop_hit = false;
|
2016-09-19 14:17:10 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-08 15:35:25 -05: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 10:15:54 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-16 02:13:07 -05:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT)
|
|
|
|
#include "feature/pause.h"
|
|
|
|
#endif
|
2017-09-09 00:18:43 -05:00
|
|
|
|
2018-04-21 19:41:26 -05:00
|
|
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
|
|
|
#include "feature/power_loss_recovery.h"
|
|
|
|
#endif
|
|
|
|
|
2017-10-10 02:35:20 -05:00
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
|
|
|
#include "feature/runout.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-16 05:09:34 -05:00
|
|
|
#if ENABLED(TEMP_STAT_LEDS)
|
|
|
|
#include "feature/leds/tempstat.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-17 18:56:29 -05:00
|
|
|
#if HAS_CASE_LIGHT
|
|
|
|
#include "feature/caselight.h"
|
|
|
|
#endif
|
|
|
|
|
2017-11-04 21:01:41 -05:00
|
|
|
#if HAS_FANMUX
|
|
|
|
#include "feature/fanmux.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 01:05:44 -05:00
|
|
|
#if (ENABLED(SWITCHING_EXTRUDER) && !DONT_SWITCH) || ENABLED(SWITCHING_NOZZLE) || ENABLED(PARKING_EXTRUDER)
|
|
|
|
#include "module/tool_change.h"
|
|
|
|
#endif
|
|
|
|
|
2017-09-18 01:44:59 -05:00
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
|
|
|
#include "feature/controllerfan.h"
|
|
|
|
#endif
|
|
|
|
|
2015-04-08 02:56:19 -05:00
|
|
|
bool Running = true;
|
|
|
|
|
2016-10-04 21:32:37 -05:00
|
|
|
/**
|
|
|
|
* axis_homed
|
|
|
|
* Flags that each linear axis was homed.
|
|
|
|
* XYZ on cartesian, ABC on delta, ABZ on SCARA.
|
|
|
|
*
|
|
|
|
* axis_known_position
|
|
|
|
* Flags that the position is known in each linear axis. Set when homed.
|
|
|
|
* Cleared whenever a stepper powers off, potentially losing its position.
|
|
|
|
*/
|
|
|
|
bool axis_homed[XYZ] = { false }, axis_known_position[XYZ] = { false };
|
2015-04-08 02:56:19 -05:00
|
|
|
|
2016-05-31 10:26:08 -05:00
|
|
|
#if ENABLED(TEMPERATURE_UNITS_SUPPORT)
|
|
|
|
TempUnit input_temp_units = TEMPUNIT_C;
|
|
|
|
#endif
|
|
|
|
|
2016-03-05 20:27:45 -06:00
|
|
|
#if FAN_COUNT > 0
|
2017-05-03 17:12:14 -05:00
|
|
|
int16_t fanSpeeds[FAN_COUNT] = { 0 };
|
2017-10-30 00:10:00 -05:00
|
|
|
#if ENABLED(EXTRA_FAN_SPEED)
|
2017-10-16 01:41:45 -05:00
|
|
|
int16_t old_fanSpeeds[FAN_COUNT],
|
|
|
|
new_fanSpeeds[FAN_COUNT];
|
|
|
|
#endif
|
2017-05-07 06:06:06 -05:00
|
|
|
#if ENABLED(PROBING_FANS_OFF)
|
2018-03-21 05:45:23 -05:00
|
|
|
bool fans_paused; // = false;
|
2017-05-07 06:06:06 -05:00
|
|
|
int16_t paused_fanSpeeds[FAN_COUNT] = { 0 };
|
|
|
|
#endif
|
2016-03-05 20:27:45 -06:00
|
|
|
#endif
|
|
|
|
|
2016-10-06 22:06:33 -05:00
|
|
|
// For M109 and M190, this flag may be cleared (by M108) to exit the wait loop
|
2016-07-06 21:59:19 -05:00
|
|
|
volatile bool wait_for_heatup = true;
|
2015-04-08 02:56:19 -05:00
|
|
|
|
2016-10-06 22:06:33 -05:00
|
|
|
// For M0/M1, this flag may be cleared (by M108) to exit the wait-for-user loop
|
2017-04-09 11:12:08 -05:00
|
|
|
#if HAS_RESUME_CONTINUE
|
2018-03-21 05:45:23 -05:00
|
|
|
volatile bool wait_for_user; // = false;
|
2016-09-11 20:51:53 -05:00
|
|
|
#endif
|
|
|
|
|
2018-03-21 00:29:09 -05:00
|
|
|
#if HAS_AUTO_REPORTING || ENABLED(HOST_KEEPALIVE_FEATURE)
|
2018-03-07 01:57:09 -06:00
|
|
|
bool suspend_auto_report; // = false
|
|
|
|
#endif
|
|
|
|
|
2015-04-03 17:45:41 -05:00
|
|
|
// Inactivity shutdown
|
2018-03-21 05:45:23 -05:00
|
|
|
millis_t max_inactive_time, // = 0
|
2017-09-16 23:57:09 -05:00
|
|
|
stepper_inactive_time = (DEFAULT_STEPPER_DEACTIVE_TIME) * 1000UL;
|
2016-04-18 01:13:07 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#ifdef CHDK
|
2018-03-21 05:45:23 -05:00
|
|
|
millis_t chdkHigh; // = 0;
|
|
|
|
bool chdkActive; // = false;
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
2016-10-02 01:48:17 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
|
|
|
I2CPositionEncodersMgr I2CPEM;
|
|
|
|
#endif
|
2017-04-14 22:44:08 -05:00
|
|
|
|
2016-09-15 13:22:23 -05:00
|
|
|
/**
|
2017-09-08 15:35:25 -05:00
|
|
|
* ***************************************************************************
|
|
|
|
* ******************************** FUNCTIONS ********************************
|
|
|
|
* ***************************************************************************
|
2016-09-15 13:22:23 -05:00
|
|
|
*/
|
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
void setup_killpin() {
|
|
|
|
#if HAS_KILL
|
|
|
|
SET_INPUT_PULLUP(KILL_PIN);
|
2016-09-15 15:43:06 -05:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
2016-07-08 08:59:33 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
void setup_powerhold() {
|
|
|
|
#if HAS_SUICIDE
|
|
|
|
OUT_WRITE(SUICIDE_PIN, HIGH);
|
2016-07-08 08:59:33 -05:00
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
#if HAS_POWER_SWITCH
|
|
|
|
#if ENABLED(PS_DEFAULT_OFF)
|
2018-02-06 00:22:30 -06:00
|
|
|
PSU_OFF();
|
2017-09-08 15:35:25 -05:00
|
|
|
#else
|
2018-02-06 00:22:30 -06:00
|
|
|
PSU_ON();
|
2017-04-14 22:44:08 -05:00
|
|
|
#endif
|
|
|
|
#endif
|
2017-09-08 15:35:25 -05:00
|
|
|
}
|
2017-04-14 22:44:08 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
/**
|
|
|
|
* Stepper Reset (RigidBoard, et.al.)
|
|
|
|
*/
|
|
|
|
#if HAS_STEPPER_RESET
|
|
|
|
void disableStepperDrivers() {
|
|
|
|
OUT_WRITE(STEPPER_RESET_PIN, LOW); // drive it down to hold in reset motor driver chips
|
|
|
|
}
|
|
|
|
void enableStepperDrivers() { SET_INPUT(STEPPER_RESET_PIN); } // set to input, which allows it to be pulled high by pullups
|
|
|
|
#endif
|
2016-08-27 19:53:02 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0
|
2015-04-28 21:10:07 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
void i2c_on_receive(int bytes) { // just echo all bytes received to serial
|
|
|
|
i2c.receive(bytes);
|
|
|
|
}
|
2017-04-14 22:44:08 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
void i2c_on_request() { // just send dummy data for now
|
|
|
|
i2c.reply("Hello World!\n");
|
|
|
|
}
|
2015-07-09 18:57:44 -05:00
|
|
|
|
2017-09-08 15:35:25 -05:00
|
|
|
#endif
|
2014-06-23 10:09:57 -05:00
|
|
|
|
2017-09-06 06:28:33 -05:00
|
|
|
/**
|
|
|
|
* Sensitive pin test for M42, M226
|
|
|
|
*/
|
2017-10-26 13:37:26 -05: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 06:28:33 -05:00
|
|
|
return false;
|
|
|
|
}
|
2016-07-19 10:24:44 -05:00
|
|
|
|
2017-09-06 06:28:33 -05:00
|
|
|
void quickstop_stepper() {
|
|
|
|
stepper.quick_stop();
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2017-09-06 06:28:33 -05:00
|
|
|
set_current_from_steppers_for_axis(ALL_AXES);
|
|
|
|
SYNC_PLAN_POSITION_KINEMATIC();
|
|
|
|
}
|
2016-10-05 14:34:07 -05:00
|
|
|
|
2015-04-03 21:25:22 -05:00
|
|
|
void enable_all_steppers() {
|
2018-02-19 16:12:04 -06:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.power_on();
|
|
|
|
#endif
|
2017-04-11 11:10:26 -05:00
|
|
|
enable_X();
|
|
|
|
enable_Y();
|
|
|
|
enable_Z();
|
|
|
|
enable_E0();
|
|
|
|
enable_E1();
|
|
|
|
enable_E2();
|
|
|
|
enable_E3();
|
|
|
|
enable_E4();
|
2015-04-03 21:25:22 -05:00
|
|
|
}
|
|
|
|
|
2017-03-17 21:12:19 -05:00
|
|
|
void disable_e_steppers() {
|
2017-04-11 11:10:26 -05:00
|
|
|
disable_E0();
|
|
|
|
disable_E1();
|
|
|
|
disable_E2();
|
|
|
|
disable_E3();
|
|
|
|
disable_E4();
|
2015-04-03 17:31:35 -05:00
|
|
|
}
|
|
|
|
|
2018-01-04 05:06:34 -06: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-17 21:12:19 -05:00
|
|
|
void disable_all_steppers() {
|
2017-04-11 11:10:26 -05:00
|
|
|
disable_X();
|
|
|
|
disable_Y();
|
|
|
|
disable_Z();
|
2017-03-17 21:12:19 -05:00
|
|
|
disable_e_steppers();
|
|
|
|
}
|
|
|
|
|
2015-04-03 17:31:35 -05:00
|
|
|
/**
|
2015-04-04 01:42:50 -05: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
|
|
|
|
* - Check if pin CHDK needs to go LOW
|
|
|
|
* - 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)
|
2015-04-03 17:31:35 -05:00
|
|
|
*/
|
2018-04-08 04:00:26 -05:00
|
|
|
void manage_inactivity(const bool ignore_stepper_queue/*=false*/) {
|
2015-08-05 06:40:36 -05:00
|
|
|
|
2016-06-19 20:05:57 -05:00
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
2018-02-18 02:42:09 -06:00
|
|
|
runout.run();
|
2015-04-03 17:31:35 -05:00
|
|
|
#endif
|
|
|
|
|
2016-03-28 07:25:27 -05:00
|
|
|
if (commands_in_queue < BUFSIZE) get_available_commands();
|
2015-04-03 17:31:35 -05:00
|
|
|
|
2017-03-28 19:45:54 -05:00
|
|
|
const millis_t ms = millis();
|
2015-04-03 17:31:35 -05:00
|
|
|
|
2018-03-21 19:30:06 -05:00
|
|
|
if (max_inactive_time && ELAPSED(ms, gcode.previous_move_ms + max_inactive_time)) {
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_ERROR_START();
|
2017-05-20 03:03:08 -05:00
|
|
|
SERIAL_ECHOLNPAIR(MSG_KILL_INACTIVE_TIME, parser.command_ptr);
|
2017-03-14 12:24:46 -05:00
|
|
|
kill(PSTR(MSG_KILLED));
|
|
|
|
}
|
2017-02-10 00:13:58 -06:00
|
|
|
|
|
|
|
// Prevent steppers timing-out in the middle of M600
|
2017-05-26 13:01:02 -05:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE) && ENABLED(PAUSE_PARK_NO_STEPPER_TIMEOUT)
|
2017-12-30 04:03:41 -06:00
|
|
|
#define MOVE_AWAY_TEST !did_pause_print
|
2017-02-10 00:13:58 -06:00
|
|
|
#else
|
2017-05-26 13:01:02 -05:00
|
|
|
#define MOVE_AWAY_TEST true
|
2017-01-21 17:10:57 -06:00
|
|
|
#endif
|
2017-03-14 02:25:34 -05:00
|
|
|
|
2018-03-21 19:30:06 -05:00
|
|
|
if (stepper_inactive_time) {
|
|
|
|
if (planner.has_blocks_queued())
|
|
|
|
gcode.previous_move_ms = ms; // reset_stepper_timeout to keep steppers powered
|
|
|
|
else if (MOVE_AWAY_TEST && !ignore_stepper_queue && ELAPSED(ms, gcode.previous_move_ms + stepper_inactive_time)) {
|
|
|
|
#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
|
|
|
|
#if ENABLED(AUTO_BED_LEVELING_UBL) && ENABLED(ULTIPANEL) // Only needed with an LCD
|
|
|
|
if (ubl.lcd_map_control) ubl.lcd_map_control = defer_return_to_status = false;
|
|
|
|
#endif
|
|
|
|
}
|
2015-06-01 03:42:28 -05:00
|
|
|
}
|
2015-03-07 14:43:15 -06:00
|
|
|
|
2015-04-04 01:42:50 -05:00
|
|
|
#ifdef CHDK // Check if pin should be set to LOW after M240 set it to HIGH
|
2017-03-16 21:49:39 -05:00
|
|
|
if (chdkActive && ELAPSED(ms, chdkHigh + CHDK_DELAY)) {
|
2014-03-10 15:57:08 -05:00
|
|
|
chdkActive = false;
|
|
|
|
WRITE(CHDK, LOW);
|
|
|
|
}
|
|
|
|
#endif
|
2015-04-03 17:31:35 -05:00
|
|
|
|
|
|
|
#if HAS_KILL
|
2015-08-05 06:40:36 -05:00
|
|
|
|
2014-12-28 12:54:06 -06:00
|
|
|
// Check if the kill button was pressed and wait just in case it was an accidental
|
|
|
|
// key kill key press
|
|
|
|
// -------------------------------------------------------------------------------
|
2015-04-03 17:45:41 -05:00
|
|
|
static int killCount = 0; // make the inactivity button a bit less responsive
|
|
|
|
const int KILL_DELAY = 750;
|
2015-04-03 17:31:35 -05:00
|
|
|
if (!READ(KILL_PIN))
|
2015-10-03 01:08:58 -05:00
|
|
|
killCount++;
|
2014-12-28 12:54:06 -06:00
|
|
|
else if (killCount > 0)
|
2015-10-03 01:08:58 -05:00
|
|
|
killCount--;
|
2015-04-03 17:31:35 -05:00
|
|
|
|
2014-12-28 12:54:06 -06:00
|
|
|
// Exceeded threshold and we can confirm that it was not accidental
|
|
|
|
// KILL the machine
|
|
|
|
// ----------------------------------------------------------------
|
2017-03-14 12:24:46 -05:00
|
|
|
if (killCount >= KILL_DELAY) {
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_ERROR_START();
|
2017-03-14 12:24:46 -05:00
|
|
|
SERIAL_ERRORLNPGM(MSG_KILL_BUTTON);
|
|
|
|
kill(PSTR(MSG_KILLED));
|
|
|
|
}
|
2012-11-06 05:06:41 -06:00
|
|
|
#endif
|
2014-12-28 12:54:06 -06:00
|
|
|
|
2015-04-03 17:31:35 -05:00
|
|
|
#if HAS_HOME
|
2014-12-28 12:54:06 -06:00
|
|
|
// Check to see if we have to home, use poor man's debouncer
|
|
|
|
// ---------------------------------------------------------
|
2015-04-03 17:45:41 -05:00
|
|
|
static int homeDebounceCount = 0; // poor man's debouncing count
|
2015-09-13 13:20:43 -05:00
|
|
|
const int HOME_DEBOUNCE_DELAY = 2500;
|
2016-12-06 14:22:34 -06:00
|
|
|
if (!IS_SD_PRINTING && !READ(HOME_PIN)) {
|
2015-04-03 17:31:35 -05:00
|
|
|
if (!homeDebounceCount) {
|
2016-02-20 19:35:35 -06:00
|
|
|
enqueue_and_echo_commands_P(PSTR("G28"));
|
2015-05-04 12:48:49 -05:00
|
|
|
LCD_MESSAGEPGM(MSG_AUTO_HOME);
|
2015-04-03 17:31:35 -05:00
|
|
|
}
|
|
|
|
if (homeDebounceCount < HOME_DEBOUNCE_DELAY)
|
|
|
|
homeDebounceCount++;
|
|
|
|
else
|
|
|
|
homeDebounceCount = 0;
|
2014-12-28 12:54:06 -06:00
|
|
|
}
|
2015-04-03 17:31:35 -05:00
|
|
|
#endif
|
2015-08-05 06:40:36 -05:00
|
|
|
|
2017-05-04 16:38:29 -05:00
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
2017-09-18 01:44:59 -05:00
|
|
|
controllerfan_update(); // Check if fan should be turned on to cool stepper drivers down
|
2012-11-06 05:06:41 -06:00
|
|
|
#endif
|
2015-04-03 17:31:35 -05:00
|
|
|
|
2018-02-19 16:12:04 -06:00
|
|
|
#if ENABLED(AUTO_POWER_CONTROL)
|
|
|
|
powerManager.check();
|
|
|
|
#endif
|
|
|
|
|
2015-07-31 00:24:43 -05:00
|
|
|
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
|
2018-02-09 03:32:40 -06:00
|
|
|
if (thermalManager.degHotend(active_extruder) > EXTRUDER_RUNOUT_MINTEMP
|
2018-03-21 19:30:06 -05:00
|
|
|
&& ELAPSED(ms, gcode.previous_move_ms + (EXTRUDER_RUNOUT_SECONDS) * 1000UL)
|
|
|
|
&& !planner.has_blocks_queued()
|
2018-02-09 03:32:40 -06:00
|
|
|
) {
|
2016-06-28 17:06:56 -05:00
|
|
|
#if ENABLED(SWITCHING_EXTRUDER)
|
2017-07-06 12:10:06 -05:00
|
|
|
const bool oldstatus = E0_ENABLE_READ;
|
2017-04-11 11:10:26 -05:00
|
|
|
enable_E0();
|
2016-06-28 17:06:56 -05:00
|
|
|
#else // !SWITCHING_EXTRUDER
|
2017-07-06 12:10:06 -05:00
|
|
|
bool oldstatus;
|
2015-10-03 01:08:58 -05:00
|
|
|
switch (active_extruder) {
|
2017-07-06 12:10:06 -05:00
|
|
|
default: oldstatus = E0_ENABLE_READ; enable_E0(); break;
|
2016-06-28 17:06:56 -05:00
|
|
|
#if E_STEPPERS > 1
|
2017-04-18 14:39:45 -05:00
|
|
|
case 1: oldstatus = E1_ENABLE_READ; enable_E1(); break;
|
2016-06-28 17:06:56 -05:00
|
|
|
#if E_STEPPERS > 2
|
2017-04-18 14:39:45 -05:00
|
|
|
case 2: oldstatus = E2_ENABLE_READ; enable_E2(); break;
|
2016-06-28 17:06:56 -05:00
|
|
|
#if E_STEPPERS > 3
|
2017-04-18 14:39:45 -05:00
|
|
|
case 3: oldstatus = E3_ENABLE_READ; enable_E3(); break;
|
2017-04-06 16:46:52 -05:00
|
|
|
#if E_STEPPERS > 4
|
2017-04-18 14:39:45 -05:00
|
|
|
case 4: oldstatus = E4_ENABLE_READ; enable_E4(); break;
|
2017-04-06 16:46:52 -05:00
|
|
|
#endif // E_STEPPERS > 4
|
|
|
|
#endif // E_STEPPERS > 3
|
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
2015-10-03 01:08:58 -05:00
|
|
|
}
|
2016-06-28 17:06:56 -05:00
|
|
|
#endif // !SWITCHING_EXTRUDER
|
|
|
|
|
2017-03-20 16:41:59 -05:00
|
|
|
const float olde = current_position[E_AXIS];
|
|
|
|
current_position[E_AXIS] += EXTRUDER_RUNOUT_EXTRUDE;
|
|
|
|
planner.buffer_line_kinematic(current_position, MMM_TO_MMS(EXTRUDER_RUNOUT_SPEED), active_extruder);
|
|
|
|
current_position[E_AXIS] = olde;
|
|
|
|
planner.set_e_position_mm(olde);
|
2018-05-12 01:38:02 -05:00
|
|
|
planner.synchronize();
|
2016-06-28 17:06:56 -05:00
|
|
|
#if ENABLED(SWITCHING_EXTRUDER)
|
|
|
|
E0_ENABLE_WRITE(oldstatus);
|
|
|
|
#else
|
|
|
|
switch (active_extruder) {
|
2017-04-18 14:39:45 -05:00
|
|
|
case 0: E0_ENABLE_WRITE(oldstatus); break;
|
2016-06-28 17:06:56 -05:00
|
|
|
#if E_STEPPERS > 1
|
2017-04-18 14:39:45 -05:00
|
|
|
case 1: E1_ENABLE_WRITE(oldstatus); break;
|
2016-06-28 17:06:56 -05:00
|
|
|
#if E_STEPPERS > 2
|
2017-04-18 14:39:45 -05:00
|
|
|
case 2: E2_ENABLE_WRITE(oldstatus); break;
|
2016-06-28 17:06:56 -05:00
|
|
|
#if E_STEPPERS > 3
|
2017-04-18 14:39:45 -05:00
|
|
|
case 3: E3_ENABLE_WRITE(oldstatus); break;
|
2017-04-06 16:46:52 -05:00
|
|
|
#if E_STEPPERS > 4
|
2017-04-18 14:39:45 -05:00
|
|
|
case 4: E4_ENABLE_WRITE(oldstatus); break;
|
2017-04-06 16:46:52 -05:00
|
|
|
#endif // E_STEPPERS > 4
|
|
|
|
#endif // E_STEPPERS > 3
|
|
|
|
#endif // E_STEPPERS > 2
|
|
|
|
#endif // E_STEPPERS > 1
|
2016-06-28 17:06:56 -05:00
|
|
|
}
|
|
|
|
#endif // !SWITCHING_EXTRUDER
|
2018-03-21 19:30:06 -05:00
|
|
|
|
|
|
|
gcode.previous_move_ms = ms; // reset_stepper_timeout to keep steppers powered
|
2012-11-06 05:06:41 -06:00
|
|
|
}
|
2016-06-28 17:06:56 -05:00
|
|
|
#endif // EXTRUDER_RUNOUT_PREVENT
|
2015-04-03 17:31:35 -05:00
|
|
|
|
2015-07-31 00:24:43 -05:00
|
|
|
#if ENABLED(DUAL_X_CARRIAGE)
|
2013-08-07 09:10:26 -05:00
|
|
|
// handle delayed move timeout
|
2016-04-10 17:55:12 -05:00
|
|
|
if (delayed_move_time && ELAPSED(ms, delayed_move_time + 1000UL) && IsRunning()) {
|
2013-08-07 09:10:26 -05:00
|
|
|
// travel moves have been received so enact them
|
|
|
|
delayed_move_time = 0xFFFFFFFFUL; // force moves to be done
|
2017-10-21 11:42:26 -05:00
|
|
|
set_destination_from_current();
|
2016-06-10 21:23:41 -05:00
|
|
|
prepare_move_to_destination();
|
2013-08-07 09:10:26 -05:00
|
|
|
}
|
2013-10-20 05:12:35 -05:00
|
|
|
#endif
|
2015-04-03 17:31:35 -05:00
|
|
|
|
2015-07-31 00:24:43 -05:00
|
|
|
#if ENABLED(TEMP_STAT_LEDS)
|
2015-04-03 17:31:35 -05:00
|
|
|
handle_status_leds();
|
2013-10-20 05:12:35 -05:00
|
|
|
#endif
|
2015-04-03 17:31:35 -05:00
|
|
|
|
2017-12-15 15:03:14 -06:00
|
|
|
#if ENABLED(MONITOR_DRIVER_STATUS)
|
|
|
|
monitor_tmc_driver();
|
2017-03-06 23:00:43 -06:00
|
|
|
#endif
|
|
|
|
|
2017-11-15 19:01:52 -06: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;
|
|
|
|
}
|
2012-11-06 05:06:41 -06:00
|
|
|
}
|
|
|
|
|
2016-09-13 02:11:45 -05:00
|
|
|
/**
|
|
|
|
* Standard idle routine keeps the machine alive
|
|
|
|
*/
|
|
|
|
void idle(
|
2017-05-26 13:01:02 -05:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
2016-09-13 02:11:45 -05:00
|
|
|
bool no_stepper_sleep/*=false*/
|
|
|
|
#endif
|
|
|
|
) {
|
2017-08-25 17:03:07 -05:00
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
|
|
|
Max7219_idle_tasks();
|
|
|
|
#endif // MAX7219_DEBUG
|
|
|
|
|
2016-09-13 02:11:45 -05:00
|
|
|
lcd_update();
|
2016-11-08 18:03:40 -06:00
|
|
|
|
2017-09-08 23:49:49 -05:00
|
|
|
#if ENABLED(HOST_KEEPALIVE_FEATURE)
|
|
|
|
gcode.host_keepalive();
|
|
|
|
#endif
|
2016-11-08 18:03:40 -06:00
|
|
|
|
2016-09-13 02:11:45 -05:00
|
|
|
manage_inactivity(
|
2017-05-26 13:01:02 -05:00
|
|
|
#if ENABLED(ADVANCED_PAUSE_FEATURE)
|
2016-09-13 02:11:45 -05:00
|
|
|
no_stepper_sleep
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
|
|
|
|
thermalManager.manage_heater();
|
|
|
|
|
|
|
|
#if ENABLED(PRINTCOUNTER)
|
|
|
|
print_job_timer.tick();
|
|
|
|
#endif
|
|
|
|
|
2016-10-04 21:31:50 -05:00
|
|
|
#if HAS_BUZZER && DISABLED(LCD_USE_I2C_BUZZER)
|
2016-09-13 02:11:45 -05:00
|
|
|
buzzer.tick();
|
|
|
|
#endif
|
2017-06-09 07:06:23 -05:00
|
|
|
|
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
2018-02-08 03:57:11 -06:00
|
|
|
static millis_t i2cpem_next_update_ms;
|
2018-03-21 19:30:06 -05:00
|
|
|
if (planner.has_blocks_queued() && ELAPSED(millis(), i2cpem_next_update_ms)) {
|
2017-06-09 07:06:23 -05:00
|
|
|
I2CPEM.update();
|
2018-02-08 03:57:11 -06:00
|
|
|
i2cpem_next_update_ms = millis() + I2CPE_MIN_UPD_TIME_MS;
|
2017-06-09 07:06:23 -05:00
|
|
|
}
|
|
|
|
#endif
|
2017-12-20 23:22:08 -06:00
|
|
|
|
|
|
|
#ifdef HAL_IDLETASK
|
|
|
|
HAL_idletask();
|
|
|
|
#endif
|
2018-03-07 01:57:09 -06: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
|
2016-09-13 02:11:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Kill all activity and lock the machine.
|
|
|
|
* After this the machine will need to be reset.
|
|
|
|
*/
|
2015-10-03 01:08:58 -05:00
|
|
|
void kill(const char* lcd_msg) {
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_ERROR_START();
|
2016-07-09 21:50:45 -05:00
|
|
|
SERIAL_ERRORLNPGM(MSG_ERR_KILLED);
|
|
|
|
|
2017-03-21 09:06:01 -05:00
|
|
|
thermalManager.disable_all_heaters();
|
|
|
|
disable_all_steppers();
|
2017-03-28 19:45:54 -05:00
|
|
|
|
2015-07-31 00:24:43 -05:00
|
|
|
#if ENABLED(ULTRA_LCD)
|
2016-07-09 21:50:45 -05:00
|
|
|
kill_screen(lcd_msg);
|
2015-10-04 10:33:55 -05:00
|
|
|
#else
|
|
|
|
UNUSED(lcd_msg);
|
2015-05-20 15:03:16 -05:00
|
|
|
#endif
|
2015-05-20 13:53:48 -05:00
|
|
|
|
2017-04-01 00:23:14 -05:00
|
|
|
_delay_ms(600); // Wait a short time (allows messages to get out before shutting down.
|
2012-11-06 05:06:41 -06:00
|
|
|
cli(); // Stop interrupts
|
2017-03-28 19:45:54 -05:00
|
|
|
|
2017-03-21 09:06:01 -05:00
|
|
|
_delay_ms(250); //Wait to ensure all interrupts routines stopped
|
|
|
|
thermalManager.disable_all_heaters(); //turn off heaters again
|
2013-06-06 17:49:25 -05:00
|
|
|
|
2017-07-27 23:42:01 -05:00
|
|
|
#ifdef ACTION_ON_KILL
|
2017-07-02 03:44:24 -05:00
|
|
|
SERIAL_ECHOLNPGM("//action:" ACTION_ON_KILL);
|
|
|
|
#endif
|
2017-07-06 21:24:30 -05:00
|
|
|
|
2015-03-30 18:50:05 -05:00
|
|
|
#if HAS_POWER_SWITCH
|
2018-03-18 20:58:10 -05:00
|
|
|
PSU_OFF();
|
2015-03-30 18:50:05 -05:00
|
|
|
#endif
|
|
|
|
|
2017-09-27 04:40:48 -05:00
|
|
|
#if HAS_SUICIDE
|
|
|
|
suicide();
|
|
|
|
#endif
|
|
|
|
|
2016-03-03 17:35:18 -06:00
|
|
|
while (1) {
|
2016-03-07 15:27:01 -06:00
|
|
|
#if ENABLED(USE_WATCHDOG)
|
|
|
|
watchdog_reset();
|
|
|
|
#endif
|
2016-03-03 17:35:18 -06:00
|
|
|
} // Wait for reset
|
2012-11-06 05:06:41 -06:00
|
|
|
}
|
|
|
|
|
2016-09-13 02:11:45 -05:00
|
|
|
/**
|
|
|
|
* Turn off heaters and stop the print in progress
|
|
|
|
* After a stop the machine may be resumed with M999
|
|
|
|
*/
|
2016-04-18 02:05:22 -05:00
|
|
|
void stop() {
|
2017-05-07 06:06:06 -05:00
|
|
|
thermalManager.disable_all_heaters(); // 'unpause' taken care of in here
|
|
|
|
|
|
|
|
#if ENABLED(PROBING_FANS_OFF)
|
|
|
|
if (fans_paused) fans_pause(false); // put things back the way they were
|
|
|
|
#endif
|
|
|
|
|
2015-05-17 03:47:02 -05:00
|
|
|
if (IsRunning()) {
|
|
|
|
Stopped_gcode_LastN = gcode_LastN; // Save last g_code for restart
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_ERROR_START();
|
2015-05-17 03:47:02 -05:00
|
|
|
SERIAL_ERRORLNPGM(MSG_ERR_STOPPED);
|
|
|
|
LCD_MESSAGEPGM(MSG_STOPPED);
|
2017-04-01 00:23:14 -05:00
|
|
|
safe_delay(350); // allow enough time for messages to get out before stopping
|
|
|
|
Running = false;
|
2012-11-06 05:06:41 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-11 20:21:54 -05: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() {
|
|
|
|
|
2017-12-20 23:42:46 -06:00
|
|
|
#ifdef HAL_INIT
|
|
|
|
HAL_init();
|
|
|
|
#endif
|
|
|
|
|
2017-08-25 17:03:07 -05:00
|
|
|
#if ENABLED(MAX7219_DEBUG)
|
|
|
|
Max7219_init();
|
|
|
|
#endif
|
|
|
|
|
2017-11-13 15:23:30 -06:00
|
|
|
#if ENABLED(DISABLE_JTAG)
|
2016-09-11 20:21:54 -05:00
|
|
|
// Disable JTAG on AT90USB chips to free up pins for IO
|
|
|
|
MCUCR = 0x80;
|
|
|
|
MCUCR = 0x80;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR)
|
2018-02-18 02:42:09 -06:00
|
|
|
runout.setup();
|
2016-09-11 20:21:54 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
setup_killpin();
|
|
|
|
|
|
|
|
setup_powerhold();
|
|
|
|
|
|
|
|
#if HAS_STEPPER_RESET
|
|
|
|
disableStepperDrivers();
|
|
|
|
#endif
|
|
|
|
|
2017-11-05 08:49:38 -06: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;
|
|
|
|
while(!MYSERIAL0 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
|
|
|
#if NUM_SERIAL > 1
|
|
|
|
serial_connect_timeout = millis() + 1000UL;
|
|
|
|
while(!MYSERIAL1 && PENDING(millis(), serial_connect_timeout)) { /*nada*/ }
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
SERIAL_PROTOCOLLNPGM("start");
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_ECHO_START();
|
2016-09-11 20:21:54 -05:00
|
|
|
|
2018-02-10 14:08:53 -06:00
|
|
|
#if ENABLED(HAVE_TMC2130)
|
|
|
|
tmc_init_cs_pins();
|
|
|
|
#endif
|
|
|
|
#if ENABLED(HAVE_TMC2208)
|
|
|
|
tmc2208_serial_begin();
|
|
|
|
#endif
|
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
// Check startup - does nothing if bootloader sets MCUSR to 0
|
2017-06-17 18:36:10 -05:00
|
|
|
byte mcu = HAL_get_reset_source();
|
2017-06-16 14:20:58 -05: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-11 20:21:54 -05:00
|
|
|
if (mcu & 32) SERIAL_ECHOLNPGM(MSG_SOFTWARE_RESET);
|
2017-06-17 18:36:10 -05:00
|
|
|
HAL_clear_reset_source();
|
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
SERIAL_ECHOPGM(MSG_MARLIN);
|
2016-09-12 17:49:35 -05:00
|
|
|
SERIAL_CHAR(' ');
|
|
|
|
SERIAL_ECHOLNPGM(SHORT_BUILD_VERSION);
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_EOL();
|
2016-09-11 20:21:54 -05:00
|
|
|
|
2016-09-12 17:49:35 -05:00
|
|
|
#if defined(STRING_DISTRIBUTION_DATE) && defined(STRING_CONFIG_H_AUTHOR)
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_ECHO_START();
|
2016-09-12 17:49:35 -05:00
|
|
|
SERIAL_ECHOPGM(MSG_CONFIGURATION_VER);
|
|
|
|
SERIAL_ECHOPGM(STRING_DISTRIBUTION_DATE);
|
|
|
|
SERIAL_ECHOLNPGM(MSG_AUTHOR STRING_CONFIG_H_AUTHOR);
|
2017-08-21 16:30:08 -05:00
|
|
|
SERIAL_ECHO_START();
|
2016-09-12 17:49:35 -05:00
|
|
|
SERIAL_ECHOLNPGM("Compiled: " __DATE__);
|
|
|
|
#endif
|
2016-09-11 20:21:54 -05:00
|
|
|
|
2017-06-09 10:51:23 -05:00
|
|
|
SERIAL_ECHO_START();
|
2016-09-12 17:49:35 -05:00
|
|
|
SERIAL_ECHOPAIR(MSG_FREE_MEMORY, freeMemory());
|
|
|
|
SERIAL_ECHOLNPAIR(MSG_PLANNER_BUFFER_BYTES, (int)sizeof(block_t)*BLOCK_BUFFER_SIZE);
|
2016-09-11 20:21:54 -05:00
|
|
|
|
2017-09-07 22:33:16 -05:00
|
|
|
queue_setup();
|
2016-09-11 20:21:54 -05:00
|
|
|
|
|
|
|
// Load data from EEPROM if available (or use defaults)
|
|
|
|
// This also updates variables in the planner, elsewhere
|
2017-04-09 21:47:49 -05:00
|
|
|
(void)settings.load();
|
2018-03-04 21:23:43 -06:00
|
|
|
|
2017-04-14 21:41:21 -05:00
|
|
|
#if HAS_M206_COMMAND
|
2017-03-04 18:01:33 -06:00
|
|
|
// Initialize current position based on home_offset
|
2017-03-04 19:19:06 -06:00
|
|
|
COPY(current_position, home_offset);
|
2017-03-04 18:01:33 -06:00
|
|
|
#else
|
|
|
|
ZERO(current_position);
|
|
|
|
#endif
|
2016-09-11 20:21:54 -05:00
|
|
|
|
|
|
|
// Vital to init stepper/planner equivalent for current_position
|
|
|
|
SYNC_PLAN_POSITION_KINEMATIC();
|
|
|
|
|
|
|
|
thermalManager.init(); // Initialize temperature loop
|
|
|
|
|
2018-03-04 21:23:43 -06:00
|
|
|
print_job_timer.init(); // Initial setup of print job timer
|
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
stepper.init(); // Initialize stepper, this enables interrupts!
|
2017-09-08 15:35:25 -05:00
|
|
|
|
|
|
|
#if HAS_SERVOS
|
|
|
|
servo_init();
|
|
|
|
#endif
|
2016-09-11 20:21:54 -05:00
|
|
|
|
2018-04-01 23:54:12 -05:00
|
|
|
#if HAS_Z_SERVO_PROBE
|
2017-11-19 13:39:46 -06:00
|
|
|
servo_probe_init();
|
|
|
|
#endif
|
|
|
|
|
2016-11-01 06:24:21 -05:00
|
|
|
#if HAS_PHOTOGRAPH
|
|
|
|
OUT_WRITE(PHOTOGRAPH_PIN, LOW);
|
|
|
|
#endif
|
|
|
|
|
2016-10-05 14:34:07 -05:00
|
|
|
#if HAS_CASE_LIGHT
|
2016-11-27 23:51:51 -06:00
|
|
|
update_case_light();
|
2016-10-05 14:34:07 -05:00
|
|
|
#endif
|
|
|
|
|
2017-04-07 13:52:45 -05:00
|
|
|
#if ENABLED(SPINDLE_LASER_ENABLE)
|
|
|
|
OUT_WRITE(SPINDLE_LASER_ENABLE_PIN, !SPINDLE_LASER_ENABLE_INVERT); // init spindle to off
|
|
|
|
#if SPINDLE_DIR_CHANGE
|
|
|
|
OUT_WRITE(SPINDLE_DIR_PIN, SPINDLE_INVERT_DIR ? 255 : 0); // init rotation to clockwise (M3)
|
|
|
|
#endif
|
2017-09-06 06:28:33 -05:00
|
|
|
#if ENABLED(SPINDLE_LASER_PWM) && defined(SPINDLE_LASER_PWM_PIN) && SPINDLE_LASER_PWM_PIN >= 0
|
2017-04-07 13:52:45 -05:00
|
|
|
SET_OUTPUT(SPINDLE_LASER_PWM_PIN);
|
|
|
|
analogWrite(SPINDLE_LASER_PWM_PIN, SPINDLE_LASER_PWM_INVERT ? 255 : 0); // set to lowest speed
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
#if HAS_BED_PROBE
|
|
|
|
endstops.enable_z_probe(false);
|
|
|
|
#endif
|
|
|
|
|
2017-05-04 16:38:29 -05:00
|
|
|
#if ENABLED(USE_CONTROLLER_FAN)
|
2017-05-02 20:18:31 -05:00
|
|
|
SET_OUTPUT(CONTROLLER_FAN_PIN); //Set pin used for driver cooling fan
|
2016-09-11 20:21:54 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAS_STEPPER_RESET
|
|
|
|
enableStepperDrivers();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DIGIPOT_I2C)
|
|
|
|
digipot_i2c_init();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(DAC_STEPPER_CURRENT)
|
|
|
|
dac_init();
|
|
|
|
#endif
|
|
|
|
|
2017-04-14 16:36:02 -05:00
|
|
|
#if (ENABLED(Z_PROBE_SLED) || ENABLED(SOLENOID_PROBE)) && HAS_SOLENOID_1
|
|
|
|
OUT_WRITE(SOL1_PIN, LOW); // turn it off
|
|
|
|
#endif
|
2016-09-11 20:21:54 -05:00
|
|
|
|
2017-07-02 02:26:49 -05:00
|
|
|
#if HAS_HOME
|
|
|
|
SET_INPUT_PULLUP(HOME_PIN);
|
|
|
|
#endif
|
2016-09-11 20:21:54 -05:00
|
|
|
|
2016-09-24 15:33:29 -05:00
|
|
|
#if PIN_EXISTS(STAT_LED_RED)
|
|
|
|
OUT_WRITE(STAT_LED_RED_PIN, LOW); // turn it off
|
2016-09-11 20:21:54 -05:00
|
|
|
#endif
|
|
|
|
|
2016-09-24 15:33:29 -05:00
|
|
|
#if PIN_EXISTS(STAT_LED_BLUE)
|
|
|
|
OUT_WRITE(STAT_LED_BLUE_PIN, LOW); // turn it off
|
2016-09-11 20:21:54 -05:00
|
|
|
#endif
|
|
|
|
|
2017-11-28 01:07:10 -06:00
|
|
|
#if HAS_COLOR_LEDS
|
|
|
|
leds.setup();
|
2017-07-13 10:01:21 -05:00
|
|
|
#endif
|
|
|
|
|
2017-04-14 16:54:53 -05:00
|
|
|
#if ENABLED(RGB_LED) || ENABLED(RGBW_LED)
|
2017-03-18 10:17:00 -05:00
|
|
|
SET_OUTPUT(RGB_LED_R_PIN);
|
|
|
|
SET_OUTPUT(RGB_LED_G_PIN);
|
|
|
|
SET_OUTPUT(RGB_LED_B_PIN);
|
2017-04-14 16:54:53 -05:00
|
|
|
#if ENABLED(RGBW_LED)
|
|
|
|
SET_OUTPUT(RGB_LED_W_PIN);
|
|
|
|
#endif
|
2016-11-29 19:51:13 -06:00
|
|
|
#endif
|
|
|
|
|
2017-06-02 13:57:31 -05:00
|
|
|
#if ENABLED(MK2_MULTIPLEXER)
|
|
|
|
SET_OUTPUT(E_MUX0_PIN);
|
|
|
|
SET_OUTPUT(E_MUX1_PIN);
|
|
|
|
SET_OUTPUT(E_MUX2_PIN);
|
|
|
|
#endif
|
2017-08-25 17:03:07 -05:00
|
|
|
|
2017-08-15 07:48:10 -05:00
|
|
|
#if HAS_FANMUX
|
|
|
|
fanmux_init();
|
|
|
|
#endif
|
2017-08-25 17:03:07 -05:00
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
lcd_init();
|
2018-05-13 17:18:19 -05:00
|
|
|
lcd_reset_status();
|
2017-07-02 00:35:41 -05:00
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
#if ENABLED(SHOW_BOOTSCREEN)
|
2017-11-03 05:58:20 -05:00
|
|
|
lcd_bootscreen();
|
2016-09-11 20:21:54 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(MIXING_EXTRUDER) && MIXING_VIRTUAL_TOOLS > 1
|
2017-09-18 00:06:16 -05:00
|
|
|
mixing_tools_init();
|
2016-09-11 20:21:54 -05:00
|
|
|
#endif
|
|
|
|
|
2017-01-21 18:10:02 -06:00
|
|
|
#if ENABLED(BLTOUCH)
|
2017-09-08 15:35:25 -05:00
|
|
|
bltouch_init();
|
2017-01-21 18:10:02 -06:00
|
|
|
#endif
|
|
|
|
|
2017-06-09 07:06:23 -05:00
|
|
|
#if ENABLED(I2C_POSITION_ENCODERS)
|
|
|
|
I2CPEM.init();
|
|
|
|
#endif
|
|
|
|
|
2016-09-11 20:21:54 -05:00
|
|
|
#if ENABLED(EXPERIMENTAL_I2CBUS) && I2C_SLAVE_ADDRESS > 0
|
|
|
|
i2c.onReceive(i2c_on_receive);
|
|
|
|
i2c.onRequest(i2c_on_request);
|
|
|
|
#endif
|
2016-11-05 16:38:48 -05:00
|
|
|
|
|
|
|
#if ENABLED(ENDSTOP_INTERRUPTS_FEATURE)
|
2016-11-18 21:53:45 -06:00
|
|
|
setup_endstop_interrupts();
|
2016-11-05 16:38:48 -05:00
|
|
|
#endif
|
2017-06-05 17:41:38 -05:00
|
|
|
|
2017-08-18 04:11:00 -05:00
|
|
|
#if ENABLED(SWITCHING_EXTRUDER) && !DONT_SWITCH
|
2017-06-04 08:40:57 -05:00
|
|
|
move_extruder_servo(0); // Initialize extruder servo
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(SWITCHING_NOZZLE)
|
|
|
|
move_nozzle_servo(0); // Initialize nozzle servo
|
|
|
|
#endif
|
2017-08-21 16:30:08 -05:00
|
|
|
|
2017-08-13 16:35:59 -05:00
|
|
|
#if ENABLED(PARKING_EXTRUDER)
|
2017-09-18 01:05:44 -05:00
|
|
|
pe_magnet_init();
|
2017-08-13 16:35:59 -05:00
|
|
|
#endif
|
2018-03-08 17:34:50 -06:00
|
|
|
|
2018-04-21 19:41:26 -05:00
|
|
|
#if ENABLED(POWER_LOSS_RECOVERY)
|
|
|
|
do_print_job_recovery();
|
|
|
|
#endif
|
|
|
|
|
2018-03-08 17:34:50 -06:00
|
|
|
#if ENABLED(USE_WATCHDOG) // Reinit watchdog after HAL_get_reset_source call
|
|
|
|
watchdog_init();
|
|
|
|
#endif
|
2016-09-11 20:21:54 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The main Marlin program loop
|
|
|
|
*
|
|
|
|
* - Save or log commands to SD
|
|
|
|
* - Process available commands (if not saving)
|
|
|
|
* - Call endstop manager
|
2018-05-01 01:01:02 -05:00
|
|
|
* - Call inactivity manager
|
2016-09-11 20:21:54 -05:00
|
|
|
*/
|
|
|
|
void loop() {
|
|
|
|
|
2018-04-04 20:13:27 -05:00
|
|
|
for (;;) {
|
2018-04-15 18:27:54 -05:00
|
|
|
|
2018-05-01 01:01:02 -05:00
|
|
|
#if ENABLED(SDSUPPORT)
|
|
|
|
card.checkautostart();
|
|
|
|
#endif
|
|
|
|
|
2018-04-15 18:27:54 -05:00
|
|
|
#if ENABLED(SDSUPPORT) && ENABLED(ULTIPANEL)
|
|
|
|
if (abort_sd_printing) {
|
|
|
|
abort_sd_printing = false;
|
|
|
|
card.stopSDPrint(
|
|
|
|
#if SD_RESORT
|
|
|
|
true
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
clear_command_queue();
|
|
|
|
quickstop_stepper();
|
|
|
|
print_job_timer.stop();
|
|
|
|
thermalManager.disable_all_heaters();
|
|
|
|
#if FAN_COUNT > 0
|
|
|
|
for (uint8_t i = 0; i < FAN_COUNT; i++) fanSpeeds[i] = 0;
|
|
|
|
#endif
|
|
|
|
wait_for_heatup = false;
|
|
|
|
}
|
|
|
|
#endif // SDSUPPORT && ULTIPANEL
|
|
|
|
|
2018-04-04 20:13:27 -05:00
|
|
|
if (commands_in_queue < BUFSIZE) get_available_commands();
|
|
|
|
advance_command_queue();
|
|
|
|
endstops.report_state();
|
|
|
|
idle();
|
|
|
|
}
|
2016-09-11 20:21:54 -05:00
|
|
|
}
|