Refactor Tx/Tc/T? commands

This commit is contained in:
D.R.racer 2022-04-21 09:38:54 +02:00
parent 4732859a98
commit 4fa4b3b2fc
4 changed files with 58 additions and 86 deletions

View File

@ -3542,9 +3542,10 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
if (MMU2::mmu2.Enabled()) { if (MMU2::mmu2.Enabled()) {
if (!automatic) { if (!automatic) {
if (saved_printing) if (saved_printing){
MMU2::mmu2.eject_filament(MMU2::mmu2.get_current_tool(), // if M600 was invoked by filament senzor (FINDA) eject filament so user can easily remove it
false); // if M600 was invoked by filament senzor (FINDA) eject filament so user can easily remove it MMU2::mmu2.eject_filament(MMU2::mmu2.get_current_tool(), false);
}
//@@TODO mmu_M600_wait_and_beep(); //@@TODO mmu_M600_wait_and_beep();
if (saved_printing) { if (saved_printing) {

View File

@ -1,13 +1,14 @@
#include "Tcodes.h" #include "Tcodes.h"
#include "AutoDeplete.h"
#include "Marlin.h" #include "Marlin.h"
#include "language.h"
#include "messages.h"
#include "mmu2.h" #include "mmu2.h"
#include "stepper.h" #include "stepper.h"
#include "ultralcd.h"
#include <avr/pgmspace.h> #include <avr/pgmspace.h>
#include <ctype.h> #include <ctype.h>
#include <stdint.h> #include <stdint.h>
#include "language.h"
#include "messages.h"
#include "ultralcd.h"
#include <stdio.h> #include <stdio.h>
static const char duplicate_Tcode_ignored[] PROGMEM = "Duplicate T-code ignored."; static const char duplicate_Tcode_ignored[] PROGMEM = "Duplicate T-code ignored.";
@ -20,30 +21,6 @@ inline void TCodeInvalid() {
SERIAL_ECHOLNPGM("Invalid T code."); SERIAL_ECHOLNPGM("Invalid T code.");
} }
// load to bondtech gears; if mmu is not present do nothing
void TCodeX() {
if (MMU2::mmu2.Enabled()) {
uint8_t selectedSlot = choose_menu_P(_T(MSG_CHOOSE_FILAMENT), _T(MSG_FILAMENT));
if ((selectedSlot == MMU2::mmu2.get_current_tool()) /*&& mmu_fil_loaded @@TODO */){
// dont execute the same T-code twice in a row
puts_P(duplicate_Tcode_ignored);
} else {
st_synchronize();
MMU2::mmu2.tool_change(selectedSlot);
}
}
}
// load to from bondtech gears to nozzle (nozzle should be preheated)
void TCodeC() {
if (MMU2::mmu2.Enabled()) {
st_synchronize();
// @@TODO mmu_continue_loading(usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal));
// mmu_extruder = selectedSlot; // filament change is finished
// MMU2::mmu2.load_filament_to_nozzle();
}
}
struct SChooseFromMenu { struct SChooseFromMenu {
uint8_t slot:7; uint8_t slot:7;
uint8_t loadToNozzle:1; uint8_t loadToNozzle:1;
@ -60,32 +37,38 @@ SChooseFromMenu TCodeChooseFromMenu() {
} }
void TCodes(char *const strchr_pointer, uint8_t codeValue) { void TCodes(char *const strchr_pointer, uint8_t codeValue) {
uint8_t index; uint8_t index = 1;
for (index = 1; strchr_pointer[index] == ' ' || strchr_pointer[index] == '\t'; index++) for ( /*nothing*/ ; strchr_pointer[index] == ' ' || strchr_pointer[index] == '\t'; index++)
; ;
strchr_pointer[index] = tolower(strchr_pointer[index]); strchr_pointer[index] = tolower(strchr_pointer[index]);
if (IsInvalidTCode(strchr_pointer, index)) if (IsInvalidTCode(strchr_pointer, index)){
TCodeInvalid(); TCodeInvalid();
else if (strchr_pointer[index] == 'x') } else if (strchr_pointer[index] == 'x'){
TCodeX(); // load to bondtech gears; if mmu is not present do nothing
else if (strchr_pointer[index] == 'c') if (MMU2::mmu2.Enabled()) {
TCodeC(); MMU2::mmu2.tool_change(strchr_pointer[index], choose_menu_P(_T(MSG_CHOOSE_EXTRUDER), _T(MSG_EXTRUDER)));
else { }
} else if (strchr_pointer[index] == 'c'){
// load from bondtech gears to nozzle (nozzle should be preheated)
if (MMU2::mmu2.Enabled()) {
MMU2::mmu2.tool_change(strchr_pointer[index], 0);
}
} else {
SChooseFromMenu selectedSlot; SChooseFromMenu selectedSlot;
if (strchr_pointer[index] == '?') if (strchr_pointer[index] == '?')
selectedSlot = TCodeChooseFromMenu(); selectedSlot = TCodeChooseFromMenu();
else { else {
selectedSlot.slot = codeValue; selectedSlot.slot = codeValue;
if (MMU2::mmu2.Enabled() && lcd_autoDepleteEnabled()) { if (MMU2::mmu2.Enabled() && lcd_autoDepleteEnabled()) {
// @@TODO selectedSlot.slot = ad_getAlternative(selectedSlot); selectedSlot.slot = ad_getAlternative(selectedSlot.slot);
} }
} }
st_synchronize(); st_synchronize();
if (MMU2::mmu2.Enabled()) { if (MMU2::mmu2.Enabled()) {
if ((selectedSlot.slot == MMU2::mmu2.get_current_tool()) /*&& mmu_fil_loaded @@TODO*/){ if (selectedSlot.slot == MMU2::mmu2.get_current_tool()){
// don't execute the same T-code twice in a row // don't execute the same T-code twice in a row
puts_P(duplicate_Tcode_ignored); puts_P(duplicate_Tcode_ignored);
} else { } else {
@ -96,8 +79,6 @@ void TCodes(char *const strchr_pointer, uint8_t codeValue) {
} }
#endif // defined(MMU_HAS_CUTTER) && defined(MMU_ALWAYS_CUT) #endif // defined(MMU_HAS_CUTTER) && defined(MMU_ALWAYS_CUT)
MMU2::mmu2.tool_change(selectedSlot.slot); MMU2::mmu2.tool_change(selectedSlot.slot);
// @@TODO mmu_continue_loading(usb_timer.running() || (lcd_commands_type == LcdCommands::Layer1Cal));
if (selectedSlot.loadToNozzle){ // for single material usage with mmu if (selectedSlot.loadToNozzle){ // for single material usage with mmu
MMU2::mmu2.load_filament_to_nozzle(selectedSlot.slot); MMU2::mmu2.load_filament_to_nozzle(selectedSlot.slot);
} }

View File

@ -13,8 +13,8 @@
#include "stepper.h" #include "stepper.h"
#include "strlen_cx.h" #include "strlen_cx.h"
#include "temperature.h" #include "temperature.h"
#include "ultralcd.h"
// @@TODO remove this and enable it in the configuration files
// Settings for filament load / unload from the LCD menu. // Settings for filament load / unload from the LCD menu.
// This is for Prusa MK3-style extruders. Customize for your hardware. // This is for Prusa MK3-style extruders. Customize for your hardware.
#define MMU2_FILAMENTCHANGE_EJECT_FEED 80.0 #define MMU2_FILAMENTCHANGE_EJECT_FEED 80.0
@ -70,6 +70,18 @@ namespace MMU2 {
void execute_extruder_sequence(const E_Step *sequence, int steps); void execute_extruder_sequence(const E_Step *sequence, int steps);
template<typename F>
void waitForHotendTargetTemp(uint16_t delay, F f){
while (((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5)) {
f();
delay_keep_alive(delay);
}
}
void WaitForHotendTargetTempBeep(){
waitForHotendTargetTemp(3000, []{ Sound_MakeSound(e_SOUND_TYPE_StandardPrompt); } );
}
MMU2 mmu2; MMU2 mmu2;
MMU2::MMU2() MMU2::MMU2()
@ -209,41 +221,32 @@ bool MMU2::tool_change(uint8_t index) {
///- T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically ///- T? Gcode to extrude shouldn't have to follow, load to extruder wheels is done automatically
///- Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load. ///- Tx Same as T?, except nozzle doesn't have to be preheated. Tc must be placed after extruder nozzle is preheated to finish filament load.
///- Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated. ///- Tc Load to nozzle after filament was prepared by Tx and extruder nozzle is already heated.
bool MMU2::tool_change(const char *special) { bool MMU2::tool_change(char code, uint8_t slot) {
if( ! WaitForMMUReady()) if( ! WaitForMMUReady())
return false; return false;
#if 0 //@@TODO
BlockRunoutRAII blockRunout; BlockRunoutRAII blockRunout;
switch (*special) { switch (code) {
case '?': { case '?': {
uint8_t index = 0; // mmu2_choose_filament(); //@@TODO GUI - user selects waitForHotendTargetTemp(100, []{});
while (!thermalManager.wait_for_hotend(active_extruder, false)) load_filament_to_nozzle(slot);
safe_delay(100);
load_filament_to_nozzle(index);
} break; } break;
case 'x': { case 'x': {
planner.synchronize(); st_synchronize();
uint8_t index = 0; //mmu2_choose_filament(); //@@TODO GUI - user selects logic.ToolChange(slot);
disable_E0(); manage_response(false, false);
logic.ToolChange(index); extruder = slot;
manage_response(false, false); // true, true);
enable_E0();
extruder = index;
SetActiveExtruder(0); SetActiveExtruder(0);
} break; } break;
case 'c': { case 'c': {
while (!thermalManager.wait_for_hotend(active_extruder, false)) waitForHotendTargetTemp(100, []{});
safe_delay(100); execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, sizeof(load_to_nozzle_sequence) / sizeof (load_to_nozzle_sequence[0]));
execute_extruder_sequence((const E_Step *)load_to_nozzle_sequence, COUNT(load_to_nozzle_sequence));
} break; } break;
} }
#endif
return true; return true;
} }
@ -268,12 +271,7 @@ bool MMU2::unload() {
if( ! WaitForMMUReady()) if( ! WaitForMMUReady())
return false; return false;
// @@TODO WaitForHotendTargetTempBeep();
// if (thermalManager.tooColdToExtrude(active_extruder)) {
// Sound_MakeSound(e_SOUND_TYPE_Prompt);
// LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
// return false;
// }
{ {
ReportingRAII rep(CommandInProgress::UnloadFilament); ReportingRAII rep(CommandInProgress::UnloadFilament);
@ -328,12 +326,9 @@ bool MMU2::load_filament_to_nozzle(uint8_t index) {
LoadingToNozzleRAII ln(*this); LoadingToNozzleRAII ln(*this);
// @@TODO how is this supposed to be done in 8bit FW? WaitForHotendTargetTempBeep();
/* if (thermalManager.tooColdToExtrude(active_extruder)) {
Sound_MakeSound(e_SOUND_TYPE_Prompt); {
LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
return false;
} else*/ {
// used for MMU-menu operation "Load to Nozzle" // used for MMU-menu operation "Load to Nozzle"
ReportingRAII rep(CommandInProgress::ToolChange); ReportingRAII rep(CommandInProgress::ToolChange);
BlockRunoutRAII blockRunout; BlockRunoutRAII blockRunout;
@ -360,12 +355,7 @@ bool MMU2::eject_filament(uint8_t index, bool recover) {
if( ! WaitForMMUReady()) if( ! WaitForMMUReady())
return false; return false;
//@@TODO WaitForHotendTargetTempBeep();
// if (thermalManager.tooColdToExtrude(active_extruder)) {
// Sound_MakeSound(e_SOUND_TYPE_Prompt);
// LCD_ALERTMESSAGEPGM(MSG_HOTEND_TOO_COLD);
// return false;
// }
ReportingRAII rep(CommandInProgress::EjectFilament); ReportingRAII rep(CommandInProgress::EjectFilament);
current_position[E_AXIS] -= MMU2_FILAMENTCHANGE_EJECT_FEED; current_position[E_AXIS] -= MMU2_FILAMENTCHANGE_EJECT_FEED;
@ -456,11 +446,9 @@ void MMU2::ResumeAndUnPark(bool move_axes, bool turn_off_nozzle) {
MMU2_ECHO_MSG("Restoring hotend temperature "); MMU2_ECHO_MSG("Restoring hotend temperature ");
SERIAL_ECHOLN(resume_hotend_temp); SERIAL_ECHOLN(resume_hotend_temp);
setTargetHotend(resume_hotend_temp, active_extruder); setTargetHotend(resume_hotend_temp, active_extruder);
waitForHotendTargetTemp(3000, []{
if (((degTargetHotend(active_extruder) - degHotend(active_extruder)) > 5)) { lcd_display_message_fullscreen_P(_i("MMU OK. Resuming temperature...")); // better report the event and let the GUI do its work somewhere else
// @@TODO lcd_display_message_fullscreen_P(_i("MMU OK. Resuming temperature...")); // better report the event and let the GUI do its work somewhere else });
delay_keep_alive(3000);
}
LogEchoEvent("Hotend temperature reached"); LogEchoEvent("Hotend temperature reached");
} }

View File

@ -77,7 +77,7 @@ public:
bool tool_change(uint8_t index); bool tool_change(uint8_t index);
/// Handling of special Tx, Tc, T? commands /// Handling of special Tx, Tc, T? commands
bool tool_change(const char *special); bool tool_change(char code, uint8_t slot);
/// Unload of filament in collaboration with the MMU. /// Unload of filament in collaboration with the MMU.
/// That includes rotating the printer's extruder in order to release filament. /// That includes rotating the printer's extruder in order to release filament.
@ -196,6 +196,8 @@ private:
/// true in case we are doing the LoadToNozzle operation - that means the filament shall be loaded all the way down to the nozzle /// true in case we are doing the LoadToNozzle operation - that means the filament shall be loaded all the way down to the nozzle
/// unlike the mid-print ToolChange commands, which only load the first ~30mm and then the G-code takes over. /// unlike the mid-print ToolChange commands, which only load the first ~30mm and then the G-code takes over.
bool loadingToNozzle; bool loadingToNozzle;
}; };
/// following Marlin's way of doing stuff - one and only instance of MMU implementation in the code base /// following Marlin's way of doing stuff - one and only instance of MMU implementation in the code base