2017-10-10 02:35:20 -05:00
|
|
|
/**
|
|
|
|
* Marlin 3D Printer Firmware
|
2020-02-03 08:00:57 -06:00
|
|
|
* Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
2017-10-10 02:35:20 -05:00
|
|
|
*
|
|
|
|
* Based on Sprinter and grbl.
|
2019-06-27 23:57:50 -05:00
|
|
|
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
2017-10-10 02:35:20 -05: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
|
2020-07-22 22:20:14 -05:00
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2017-10-10 02:35:20 -05:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* feature/runout.cpp - Runout sensor support
|
|
|
|
*/
|
|
|
|
|
2018-02-18 02:42:09 -06:00
|
|
|
#include "../inc/MarlinConfigPre.h"
|
2017-10-10 02:35:20 -05:00
|
|
|
|
2019-02-12 20:08:34 -06:00
|
|
|
#if HAS_FILAMENT_SENSOR
|
2017-10-10 02:35:20 -05:00
|
|
|
|
2018-02-18 02:42:09 -06:00
|
|
|
#include "runout.h"
|
2017-10-10 02:35:20 -05:00
|
|
|
|
2018-11-14 11:45:57 -06:00
|
|
|
FilamentMonitor runout;
|
2017-10-10 02:35:20 -05:00
|
|
|
|
2018-11-14 11:45:57 -06:00
|
|
|
bool FilamentMonitorBase::enabled = true,
|
2019-02-12 15:55:47 -06:00
|
|
|
FilamentMonitorBase::filament_ran_out; // = false
|
|
|
|
|
|
|
|
#if ENABLED(HOST_ACTION_COMMANDS)
|
|
|
|
bool FilamentMonitorBase::host_handling; // = false
|
|
|
|
#endif
|
2018-02-18 02:42:09 -06:00
|
|
|
|
2020-04-22 21:03:28 -05:00
|
|
|
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
|
|
|
|
#include "../module/tool_change.h"
|
2020-10-19 04:24:57 -05:00
|
|
|
#define DEBUG_OUT ENABLED(DEBUG_TOOLCHANGE_MIGRATION_FEATURE)
|
|
|
|
#include "../core/debug_out.h"
|
2020-04-22 21:03:28 -05:00
|
|
|
#endif
|
|
|
|
|
2020-05-05 23:18:23 -05:00
|
|
|
#if HAS_FILAMENT_RUNOUT_DISTANCE
|
2018-10-16 07:28:52 -05:00
|
|
|
float RunoutResponseDelayed::runout_distance_mm = FILAMENT_RUNOUT_DISTANCE_MM;
|
2021-02-28 20:16:22 -06:00
|
|
|
volatile float RunoutResponseDelayed::runout_mm_countdown[NUM_RUNOUT_SENSORS];
|
2020-05-05 23:18:23 -05:00
|
|
|
#if ENABLED(FILAMENT_MOTION_SENSOR)
|
|
|
|
uint8_t FilamentSensorEncoder::motion_detected;
|
|
|
|
#endif
|
2018-10-16 07:28:52 -05:00
|
|
|
#else
|
2021-02-28 20:16:22 -06:00
|
|
|
int8_t RunoutResponseDebounced::runout_count[NUM_RUNOUT_SENSORS]; // = 0
|
2018-10-16 07:28:52 -05:00
|
|
|
#endif
|
2017-10-10 02:35:20 -05:00
|
|
|
|
2019-10-02 18:51:25 -05:00
|
|
|
//
|
|
|
|
// Filament Runout event handler
|
|
|
|
//
|
2020-01-02 19:01:38 -06:00
|
|
|
#include "../MarlinCore.h"
|
2021-01-21 03:40:07 -06:00
|
|
|
#include "../feature/pause.h"
|
2019-10-02 18:51:25 -05:00
|
|
|
#include "../gcode/queue.h"
|
|
|
|
|
|
|
|
#if ENABLED(HOST_ACTION_COMMANDS)
|
|
|
|
#include "host_actions.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if ENABLED(EXTENSIBLE_UI)
|
2020-03-13 16:29:29 -05:00
|
|
|
#include "../lcd/extui/ui_api.h"
|
2021-09-07 02:15:24 -05:00
|
|
|
#elif ENABLED(DWIN_CREALITY_LCD_ENHANCED)
|
|
|
|
#include "../lcd/e3v2/enhanced/dwin.h"
|
2019-10-02 18:51:25 -05:00
|
|
|
#endif
|
|
|
|
|
2021-02-28 20:16:22 -06:00
|
|
|
void event_filament_runout(const uint8_t extruder) {
|
2019-10-02 18:51:25 -05:00
|
|
|
|
2021-01-21 03:40:07 -06:00
|
|
|
if (did_pause_print) return; // Action already in progress. Purge triggered repeated runout.
|
2019-10-02 18:51:25 -05:00
|
|
|
|
2020-04-22 21:03:28 -05:00
|
|
|
#if ENABLED(TOOLCHANGE_MIGRATION_FEATURE)
|
2020-06-27 21:57:01 -05:00
|
|
|
if (migration.in_progress) {
|
2020-10-19 04:24:57 -05:00
|
|
|
DEBUG_ECHOLNPGM("Migration Already In Progress");
|
2020-06-27 21:57:01 -05:00
|
|
|
return; // Action already in progress. Purge triggered repeated runout.
|
|
|
|
}
|
|
|
|
if (migration.automode) {
|
2020-10-19 04:24:57 -05:00
|
|
|
DEBUG_ECHOLNPGM("Migration Starting");
|
2020-06-27 21:57:01 -05:00
|
|
|
if (extruder_migration()) return;
|
|
|
|
}
|
2020-04-22 21:03:28 -05:00
|
|
|
#endif
|
|
|
|
|
2021-02-28 20:16:22 -06:00
|
|
|
TERN_(EXTENSIBLE_UI, ExtUI::onFilamentRunout(ExtUI::getTool(extruder)));
|
2021-09-07 02:15:24 -05:00
|
|
|
TERN_(DWIN_CREALITY_LCD_ENHANCED, DWIN_FilamentRunout(extruder));
|
2019-10-02 18:51:25 -05:00
|
|
|
|
2021-02-28 20:16:22 -06:00
|
|
|
#if ANY(HOST_PROMPT_SUPPORT, HOST_ACTION_COMMANDS, MULTI_FILAMENT_SENSOR)
|
|
|
|
const char tool = '0' + TERN0(MULTI_FILAMENT_SENSOR, extruder);
|
2019-10-02 18:51:25 -05:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//action:out_of_filament
|
|
|
|
#if ENABLED(HOST_PROMPT_SUPPORT)
|
2021-09-27 11:55:08 -05:00
|
|
|
host_action_prompt_begin(PROMPT_FILAMENT_RUNOUT, F("FilamentRunout T"), tool);
|
2019-10-02 18:51:25 -05:00
|
|
|
host_action_prompt_show();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
const bool run_runout_script = !runout.host_handling;
|
|
|
|
|
|
|
|
#if ENABLED(HOST_ACTION_COMMANDS)
|
|
|
|
if (run_runout_script
|
|
|
|
&& ( strstr(FILAMENT_RUNOUT_SCRIPT, "M600")
|
|
|
|
|| strstr(FILAMENT_RUNOUT_SCRIPT, "M125")
|
2020-10-19 04:24:57 -05:00
|
|
|
|| TERN0(ADVANCED_PAUSE_FEATURE, strstr(FILAMENT_RUNOUT_SCRIPT, "M25"))
|
2019-10-02 18:51:25 -05:00
|
|
|
)
|
|
|
|
) {
|
|
|
|
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
|
2021-09-27 11:55:08 -05:00
|
|
|
host_action(F(ACTION_ON_FILAMENT_RUNOUT " T"), false);
|
2019-10-02 18:51:25 -05:00
|
|
|
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
|
|
|
|
|
2021-02-28 20:16:22 -06:00
|
|
|
if (run_runout_script) {
|
|
|
|
#if MULTI_FILAMENT_SENSOR
|
|
|
|
char script[strlen(FILAMENT_RUNOUT_SCRIPT) + 1];
|
|
|
|
sprintf_P(script, PSTR(FILAMENT_RUNOUT_SCRIPT), tool);
|
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
2021-09-09 04:57:05 -05:00
|
|
|
SERIAL_ECHOLNPGM("Runout Command: ", script);
|
2021-02-28 20:16:22 -06:00
|
|
|
#endif
|
|
|
|
queue.inject(script);
|
|
|
|
#else
|
|
|
|
#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
|
|
|
|
SERIAL_ECHOPGM("Runout Command: ");
|
|
|
|
SERIAL_ECHOLNPGM(FILAMENT_RUNOUT_SCRIPT);
|
|
|
|
#endif
|
2021-09-25 21:11:31 -05:00
|
|
|
queue.inject(F(FILAMENT_RUNOUT_SCRIPT));
|
2021-02-28 20:16:22 -06:00
|
|
|
#endif
|
|
|
|
}
|
2019-10-02 18:51:25 -05:00
|
|
|
}
|
|
|
|
|
2019-02-12 20:08:34 -06:00
|
|
|
#endif // HAS_FILAMENT_SENSOR
|