|
@@ -19,8 +19,6 @@
|
|
#include "tmc2130.h"
|
|
#include "tmc2130.h"
|
|
#endif //TMC2130
|
|
#endif //TMC2130
|
|
|
|
|
|
-#define CHECK_FINDA ((IS_SD_PRINTING || is_usb_printing) && (mcode_in_progress != 600) && !saved_printing && e_active())
|
|
|
|
-
|
|
|
|
#define MMU_TODELAY 100
|
|
#define MMU_TODELAY 100
|
|
#define MMU_TIMEOUT 10
|
|
#define MMU_TIMEOUT 10
|
|
#define MMU_CMD_TIMEOUT 45000ul //5min timeout for mmu commands (except P0)
|
|
#define MMU_CMD_TIMEOUT 45000ul //5min timeout for mmu commands (except P0)
|
|
@@ -41,7 +39,7 @@ uint8_t mmu_cmd = 0;
|
|
|
|
|
|
//idler ir sensor
|
|
//idler ir sensor
|
|
uint8_t mmu_idl_sens = 0;
|
|
uint8_t mmu_idl_sens = 0;
|
|
-bool mmu_idler_sensor_detected = false;
|
|
|
|
|
|
+bool ir_sensor_detected = false;
|
|
bool mmu_loading_flag = false;
|
|
bool mmu_loading_flag = false;
|
|
|
|
|
|
uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN;
|
|
uint8_t mmu_extruder = MMU_FILAMENT_UNKNOWN;
|
|
@@ -116,23 +114,31 @@ void mmu_init(void)
|
|
_delay_ms(10); //wait 10ms for sure
|
|
_delay_ms(10); //wait 10ms for sure
|
|
mmu_reset(); //reset mmu (HW or SW), do not wait for response
|
|
mmu_reset(); //reset mmu (HW or SW), do not wait for response
|
|
mmu_state = -1;
|
|
mmu_state = -1;
|
|
- PIN_INP(MMU_IDLER_SENSOR_PIN); //input mode
|
|
|
|
- PIN_SET(MMU_IDLER_SENSOR_PIN); //pullup
|
|
|
|
|
|
+ PIN_INP(IR_SENSOR_PIN); //input mode
|
|
|
|
+ PIN_SET(IR_SENSOR_PIN); //pullup
|
|
}
|
|
}
|
|
|
|
|
|
//returns true if idler IR sensor was detected, otherwise returns false
|
|
//returns true if idler IR sensor was detected, otherwise returns false
|
|
-bool check_for_idler_sensor()
|
|
|
|
|
|
+bool check_for_ir_sensor()
|
|
{
|
|
{
|
|
|
|
+#ifdef IR_SENSOR
|
|
|
|
+ return true;
|
|
|
|
+#endif //IR_SENSOR
|
|
|
|
+
|
|
bool detected = false;
|
|
bool detected = false;
|
|
- //if MMU_IDLER_SENSOR_PIN input is low and pat9125sensor is not present we detected idler sensor
|
|
|
|
- if ((PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) && fsensor_not_responding)
|
|
|
|
- {
|
|
|
|
- detected = true;
|
|
|
|
- //printf_P(PSTR("Idler IR sensor detected\n"));
|
|
|
|
|
|
+ //if IR_SENSOR_PIN input is low and pat9125sensor is not present we detected idler sensor
|
|
|
|
+ if ((PIN_GET(IR_SENSOR_PIN) == 0)
|
|
|
|
+#ifdef PAT9125
|
|
|
|
+ && fsensor_not_responding
|
|
|
|
+#endif //PAT9125
|
|
|
|
+ )
|
|
|
|
+ {
|
|
|
|
+ detected = true;
|
|
|
|
+ //printf_P(PSTR("Idler IR sensor detected\n"));
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
- //printf_P(PSTR("Idler IR sensor not detected\n"));
|
|
|
|
|
|
+ //printf_P(PSTR("Idler IR sensor not detected\n"));
|
|
}
|
|
}
|
|
return detected;
|
|
return detected;
|
|
}
|
|
}
|
|
@@ -224,8 +230,6 @@ void mmu_loop(void)
|
|
#endif //MMU_DEBUG && MMU_FINDA_DEBUG
|
|
#endif //MMU_DEBUG && MMU_FINDA_DEBUG
|
|
puts_P(PSTR("MMU - ENABLED"));
|
|
puts_P(PSTR("MMU - ENABLED"));
|
|
mmu_enabled = true;
|
|
mmu_enabled = true;
|
|
- //if we have filament loaded into the nozzle, we can decide if printer has idler sensor right now; otherwise we will will wait till start of T-code so it will be detected on beginning of second T-code
|
|
|
|
- if(check_for_idler_sensor()) mmu_idler_sensor_detected = true;
|
|
|
|
mmu_state = 1;
|
|
mmu_state = 1;
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
@@ -241,7 +245,7 @@ void mmu_loop(void)
|
|
mmu_printf_P(PSTR("T%d\n"), filament);
|
|
mmu_printf_P(PSTR("T%d\n"), filament);
|
|
mmu_state = 3; // wait for response
|
|
mmu_state = 3; // wait for response
|
|
mmu_fil_loaded = true;
|
|
mmu_fil_loaded = true;
|
|
- if(mmu_idler_sensor_detected) mmu_idl_sens = 1; //if idler sensor detected, use it for T-code
|
|
|
|
|
|
+ if(ir_sensor_detected) mmu_idl_sens = 1; //if idler sensor detected, use it for T-code
|
|
}
|
|
}
|
|
else if ((mmu_cmd >= MMU_CMD_L0) && (mmu_cmd <= MMU_CMD_L4))
|
|
else if ((mmu_cmd >= MMU_CMD_L0) && (mmu_cmd <= MMU_CMD_L4))
|
|
{
|
|
{
|
|
@@ -259,7 +263,7 @@ void mmu_loop(void)
|
|
#endif //MMU_DEBUG
|
|
#endif //MMU_DEBUG
|
|
mmu_puts_P(PSTR("C0\n")); //send 'continue loading'
|
|
mmu_puts_P(PSTR("C0\n")); //send 'continue loading'
|
|
mmu_state = 3;
|
|
mmu_state = 3;
|
|
- if(mmu_idler_sensor_detected) mmu_idl_sens = 1; //if idler sensor detected use it for C0 code
|
|
|
|
|
|
+ if(ir_sensor_detected) mmu_idl_sens = 1; //if idler sensor detected use it for C0 code
|
|
}
|
|
}
|
|
else if (mmu_cmd == MMU_CMD_U0)
|
|
else if (mmu_cmd == MMU_CMD_U0)
|
|
{
|
|
{
|
|
@@ -301,7 +305,9 @@ void mmu_loop(void)
|
|
}
|
|
}
|
|
else if ((mmu_last_response + 300) < millis()) //request every 300ms
|
|
else if ((mmu_last_response + 300) < millis()) //request every 300ms
|
|
{
|
|
{
|
|
- if(check_for_idler_sensor()) mmu_idler_sensor_detected = true;
|
|
|
|
|
|
+#ifndef IR_SENSOR
|
|
|
|
+ if(check_for_ir_sensor()) ir_sensor_detected = true;
|
|
|
|
+#endif //IR_SENSOR not defined
|
|
#if defined MMU_DEBUG && defined MMU_FINDA_DEBUG
|
|
#if defined MMU_DEBUG && defined MMU_FINDA_DEBUG
|
|
puts_P(PSTR("MMU <= 'P0'"));
|
|
puts_P(PSTR("MMU <= 'P0'"));
|
|
#endif //MMU_DEBUG && MMU_FINDA_DEBUG
|
|
#endif //MMU_DEBUG && MMU_FINDA_DEBUG
|
|
@@ -317,7 +323,7 @@ void mmu_loop(void)
|
|
printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
|
|
printf_P(PSTR("MMU => '%dok'\n"), mmu_finda);
|
|
#endif //MMU_DEBUG && MMU_FINDA_DEBUG
|
|
#endif //MMU_DEBUG && MMU_FINDA_DEBUG
|
|
//printf_P(PSTR("Eact: %d\n"), int(e_active()));
|
|
//printf_P(PSTR("Eact: %d\n"), int(e_active()));
|
|
- if (!mmu_finda && CHECK_FINDA && fsensor_enabled) {
|
|
|
|
|
|
+ if (!mmu_finda && CHECK_FSENSOR && fsensor_enabled) {
|
|
fsensor_stop_and_save_print();
|
|
fsensor_stop_and_save_print();
|
|
enquecommand_front_P(PSTR("FSENSOR_RECOVER")); //then recover
|
|
enquecommand_front_P(PSTR("FSENSOR_RECOVER")); //then recover
|
|
if (lcd_autoDepleteEnabled()) enquecommand_front_P(PSTR("M600 AUTO")); //save print and run M600 command
|
|
if (lcd_autoDepleteEnabled()) enquecommand_front_P(PSTR("M600 AUTO")); //save print and run M600 command
|
|
@@ -333,21 +339,18 @@ void mmu_loop(void)
|
|
}
|
|
}
|
|
return;
|
|
return;
|
|
case 3: //response to mmu commands
|
|
case 3: //response to mmu commands
|
|
- if (mmu_idler_sensor_detected) {
|
|
|
|
- if (mmu_idl_sens)
|
|
|
|
|
|
+ if (mmu_idl_sens && ir_sensor_detected) {
|
|
|
|
+ if (PIN_GET(IR_SENSOR_PIN) == 0 && mmu_loading_flag)
|
|
{
|
|
{
|
|
- if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0 && mmu_loading_flag)
|
|
|
|
- {
|
|
|
|
#ifdef MMU_DEBUG
|
|
#ifdef MMU_DEBUG
|
|
printf_P(PSTR("MMU <= 'A'\n"));
|
|
printf_P(PSTR("MMU <= 'A'\n"));
|
|
#endif //MMU_DEBUG
|
|
#endif //MMU_DEBUG
|
|
mmu_puts_P(PSTR("A\n")); //send 'abort' request
|
|
mmu_puts_P(PSTR("A\n")); //send 'abort' request
|
|
mmu_idl_sens = 0;
|
|
mmu_idl_sens = 0;
|
|
//printf_P(PSTR("MMU IDLER_SENSOR = 0 - ABORT\n"));
|
|
//printf_P(PSTR("MMU IDLER_SENSOR = 0 - ABORT\n"));
|
|
- }
|
|
|
|
- //else
|
|
|
|
- //printf_P(PSTR("MMU IDLER_SENSOR = 1 - WAIT\n"));
|
|
|
|
}
|
|
}
|
|
|
|
+ //else
|
|
|
|
+ //printf_P(PSTR("MMU IDLER_SENSOR = 1 - WAIT\n"));
|
|
}
|
|
}
|
|
if (mmu_rx_ok() > 0)
|
|
if (mmu_rx_ok() > 0)
|
|
{
|
|
{
|
|
@@ -441,7 +444,7 @@ void mmu_load_step() {
|
|
bool mmu_get_response(uint8_t move)
|
|
bool mmu_get_response(uint8_t move)
|
|
{
|
|
{
|
|
mmu_loading_flag = false;
|
|
mmu_loading_flag = false;
|
|
- if (!mmu_idler_sensor_detected) move = MMU_NO_MOVE;
|
|
|
|
|
|
+ if (!ir_sensor_detected) move = MMU_NO_MOVE;
|
|
|
|
|
|
printf_P(PSTR("mmu_get_response - begin move:%d\n"), move);
|
|
printf_P(PSTR("mmu_get_response - begin move:%d\n"), move);
|
|
KEEPALIVE_STATE(IN_PROCESS);
|
|
KEEPALIVE_STATE(IN_PROCESS);
|
|
@@ -471,10 +474,10 @@ bool mmu_get_response(uint8_t move)
|
|
mmu_loading_flag = true;
|
|
mmu_loading_flag = true;
|
|
mmu_load_step();
|
|
mmu_load_step();
|
|
//don't rely on "ok" signal from mmu unit; if filament detected by idler sensor during loading stop loading movements to prevent infinite loading
|
|
//don't rely on "ok" signal from mmu unit; if filament detected by idler sensor during loading stop loading movements to prevent infinite loading
|
|
- if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) move = MMU_NO_MOVE;
|
|
|
|
|
|
+ if (PIN_GET(IR_SENSOR_PIN) == 0) move = MMU_NO_MOVE;
|
|
break;
|
|
break;
|
|
case MMU_UNLOAD_MOVE:
|
|
case MMU_UNLOAD_MOVE:
|
|
- if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) //filament is still detected by idler sensor, printer helps with unlading
|
|
|
|
|
|
+ if (PIN_GET(IR_SENSOR_PIN) == 0) //filament is still detected by idler sensor, printer helps with unlading
|
|
{
|
|
{
|
|
printf_P(PSTR("Unload 1\n"));
|
|
printf_P(PSTR("Unload 1\n"));
|
|
current_position[E_AXIS] = current_position[E_AXIS] - MMU_LOAD_FEEDRATE * MMU_LOAD_TIME_MS*0.001;
|
|
current_position[E_AXIS] = current_position[E_AXIS] - MMU_LOAD_FEEDRATE * MMU_LOAD_TIME_MS*0.001;
|
|
@@ -489,7 +492,7 @@ bool mmu_get_response(uint8_t move)
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case MMU_TCODE_MOVE: //first do unload and then continue with infinite loading movements
|
|
case MMU_TCODE_MOVE: //first do unload and then continue with infinite loading movements
|
|
- if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) //filament detected by idler sensor, we must unload first
|
|
|
|
|
|
+ if (PIN_GET(IR_SENSOR_PIN) == 0) //filament detected by idler sensor, we must unload first
|
|
{
|
|
{
|
|
printf_P(PSTR("Unload 2\n"));
|
|
printf_P(PSTR("Unload 2\n"));
|
|
current_position[E_AXIS] = current_position[E_AXIS] - MMU_LOAD_FEEDRATE * MMU_LOAD_TIME_MS*0.001;
|
|
current_position[E_AXIS] = current_position[E_AXIS] - MMU_LOAD_FEEDRATE * MMU_LOAD_TIME_MS*0.001;
|
|
@@ -674,7 +677,7 @@ void mmu_load_to_nozzle()
|
|
|
|
|
|
bool saved_e_relative_mode = axis_relative_modes[E_AXIS];
|
|
bool saved_e_relative_mode = axis_relative_modes[E_AXIS];
|
|
if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true;
|
|
if (!saved_e_relative_mode) axis_relative_modes[E_AXIS] = true;
|
|
- if (mmu_idler_sensor_detected)
|
|
|
|
|
|
+ if (ir_sensor_detected)
|
|
{
|
|
{
|
|
current_position[E_AXIS] += 3.0f;
|
|
current_position[E_AXIS] += 3.0f;
|
|
}
|
|
}
|
|
@@ -1330,16 +1333,16 @@ void mmu_eject_filament(uint8_t filament, bool recover)
|
|
void mmu_continue_loading()
|
|
void mmu_continue_loading()
|
|
{
|
|
{
|
|
|
|
|
|
- if (mmu_idler_sensor_detected) {
|
|
|
|
|
|
+ if (ir_sensor_detected) {
|
|
for (uint8_t i = 0; i < MMU_IDLER_SENSOR_ATTEMPTS_NR; i++) {
|
|
for (uint8_t i = 0; i < MMU_IDLER_SENSOR_ATTEMPTS_NR; i++) {
|
|
- if (PIN_GET(MMU_IDLER_SENSOR_PIN) == 0) return;
|
|
|
|
|
|
+ if (PIN_GET(IR_SENSOR_PIN) == 0) return;
|
|
#ifdef MMU_DEBUG
|
|
#ifdef MMU_DEBUG
|
|
printf_P(PSTR("Additional load attempt nr. %d\n"), i);
|
|
printf_P(PSTR("Additional load attempt nr. %d\n"), i);
|
|
#endif // MMU_DEBUG
|
|
#endif // MMU_DEBUG
|
|
mmu_command(MMU_CMD_C0);
|
|
mmu_command(MMU_CMD_C0);
|
|
manage_response(true, true, MMU_LOAD_MOVE);
|
|
manage_response(true, true, MMU_LOAD_MOVE);
|
|
}
|
|
}
|
|
- if (PIN_GET(MMU_IDLER_SENSOR_PIN) != 0) {
|
|
|
|
|
|
+ if (PIN_GET(IR_SENSOR_PIN) != 0) {
|
|
uint8_t mmu_load_fail = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL);
|
|
uint8_t mmu_load_fail = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL);
|
|
uint16_t mmu_load_fail_tot = eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT);
|
|
uint16_t mmu_load_fail_tot = eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT);
|
|
if(mmu_load_fail < 255) eeprom_update_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL, mmu_load_fail + 1);
|
|
if(mmu_load_fail < 255) eeprom_update_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL, mmu_load_fail + 1);
|
|
@@ -1365,7 +1368,7 @@ void mmu_continue_loading()
|
|
mmu_fil_loaded = false; //so we can retry same T-code again
|
|
mmu_fil_loaded = false; //so we can retry same T-code again
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- else { //mmu_idler_sensor_detected == false
|
|
|
|
|
|
+ else { //mmu_ir_sensor_detected == false
|
|
mmu_command(MMU_CMD_C0);
|
|
mmu_command(MMU_CMD_C0);
|
|
}
|
|
}
|
|
}
|
|
}
|