Use enum for mmu_cmd instead of plain integer type.
This commit is contained in:
parent
bb7eeef1f4
commit
9e873ac0f7
@ -3037,7 +3037,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
|
||||
lcd_set_cursor(0, 2);
|
||||
lcd_puts_P(_T(MSG_PLEASE_WAIT));
|
||||
|
||||
mmu_command(MMU_CMD_R0);
|
||||
mmu_command(MmuCmd::R0);
|
||||
manage_response(false, false);
|
||||
}
|
||||
}
|
||||
@ -6933,7 +6933,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
|
||||
return; //dont execute the same T-code twice in a row
|
||||
}
|
||||
st_synchronize();
|
||||
mmu_command(MMU_CMD_T0 + tmp_extruder);
|
||||
mmu_command(static_cast<MmuCmd>(MmuCmd::T0 + tmp_extruder));
|
||||
manage_response(true, true, MMU_TCODE_MOVE);
|
||||
}
|
||||
}
|
||||
@ -6974,7 +6974,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
|
||||
printf_P(PSTR("Duplicit T-code ignored.\n"));
|
||||
return; //dont execute the same T-code twice in a row
|
||||
}
|
||||
mmu_command(MMU_CMD_T0 + tmp_extruder);
|
||||
mmu_command(static_cast<MmuCmd>(MmuCmd::T0 + tmp_extruder));
|
||||
|
||||
manage_response(true, true, MMU_TCODE_MOVE);
|
||||
mmu_continue_loading();
|
||||
|
@ -53,7 +53,7 @@ bool mmu_fil_loaded = false; //if true: blocks execution of duplicit T-codes
|
||||
|
||||
static S mmu_state = S::Disabled;
|
||||
|
||||
uint8_t mmu_cmd = 0;
|
||||
MmuCmd mmu_cmd = MmuCmd::None;
|
||||
|
||||
//idler ir sensor
|
||||
uint8_t mmu_idl_sens = 0;
|
||||
@ -74,7 +74,7 @@ int16_t mmu_buildnr = -1;
|
||||
uint32_t mmu_last_request = 0;
|
||||
uint32_t mmu_last_response = 0;
|
||||
|
||||
uint8_t mmu_last_cmd = 0;
|
||||
MmuCmd mmu_last_cmd = MmuCmd::None;
|
||||
uint16_t mmu_power_failures = 0;
|
||||
|
||||
|
||||
@ -259,58 +259,58 @@ void mmu_loop(void)
|
||||
case S::Idle:
|
||||
if (mmu_cmd) //command request ?
|
||||
{
|
||||
if ((mmu_cmd >= MMU_CMD_T0) && (mmu_cmd <= MMU_CMD_T4))
|
||||
if ((mmu_cmd >= MmuCmd::T0) && (mmu_cmd <= MmuCmd::T4))
|
||||
{
|
||||
filament = mmu_cmd - MMU_CMD_T0;
|
||||
filament = mmu_cmd - MmuCmd::T0;
|
||||
DEBUG_PRINTF_P(PSTR("MMU <= 'T%d'\n"), filament);
|
||||
mmu_printf_P(PSTR("T%d\n"), filament);
|
||||
mmu_state = S::WaitCmd; // wait for response
|
||||
mmu_fil_loaded = true;
|
||||
mmu_idl_sens = 1;
|
||||
}
|
||||
else if ((mmu_cmd >= MMU_CMD_L0) && (mmu_cmd <= MMU_CMD_L4))
|
||||
else if ((mmu_cmd >= MmuCmd::L0) && (mmu_cmd <= MmuCmd::L4))
|
||||
{
|
||||
filament = mmu_cmd - MMU_CMD_L0;
|
||||
filament = mmu_cmd - MmuCmd::L0;
|
||||
DEBUG_PRINTF_P(PSTR("MMU <= 'L%d'\n"), filament);
|
||||
mmu_printf_P(PSTR("L%d\n"), filament);
|
||||
mmu_state = S::WaitCmd; // wait for response
|
||||
}
|
||||
else if (mmu_cmd == MMU_CMD_C0)
|
||||
else if (mmu_cmd == MmuCmd::C0)
|
||||
{
|
||||
DEBUG_PRINTF_P(PSTR("MMU <= 'C0'\n"));
|
||||
mmu_puts_P(PSTR("C0\n")); //send 'continue loading'
|
||||
mmu_state = S::WaitCmd;
|
||||
mmu_idl_sens = 1;
|
||||
}
|
||||
else if (mmu_cmd == MMU_CMD_U0)
|
||||
else if (mmu_cmd == MmuCmd::U0)
|
||||
{
|
||||
DEBUG_PRINTF_P(PSTR("MMU <= 'U0'\n"));
|
||||
mmu_puts_P(PSTR("U0\n")); //send 'unload current filament'
|
||||
mmu_fil_loaded = false;
|
||||
mmu_state = S::WaitCmd;
|
||||
}
|
||||
else if ((mmu_cmd >= MMU_CMD_E0) && (mmu_cmd <= MMU_CMD_E4))
|
||||
else if ((mmu_cmd >= MmuCmd::E0) && (mmu_cmd <= MmuCmd::E4))
|
||||
{
|
||||
int filament = mmu_cmd - MMU_CMD_E0;
|
||||
int filament = mmu_cmd - MmuCmd::E0;
|
||||
DEBUG_PRINTF_P(PSTR("MMU <= 'E%d'\n"), filament);
|
||||
mmu_printf_P(PSTR("E%d\n"), filament); //send eject filament
|
||||
mmu_fil_loaded = false;
|
||||
mmu_state = S::WaitCmd;
|
||||
}
|
||||
else if (mmu_cmd == MMU_CMD_R0)
|
||||
else if (mmu_cmd == MmuCmd::R0)
|
||||
{
|
||||
DEBUG_PRINTF_P(PSTR("MMU <= 'R0'\n"));
|
||||
mmu_puts_P(PSTR("R0\n")); //send recover after eject
|
||||
mmu_state = S::WaitCmd;
|
||||
}
|
||||
else if (mmu_cmd == MMU_CMD_S3)
|
||||
else if (mmu_cmd == MmuCmd::S3)
|
||||
{
|
||||
DEBUG_PRINTF_P(PSTR("MMU <= 'S3'\n"));
|
||||
mmu_puts_P(PSTR("S3\n")); //send power failures request
|
||||
mmu_state = S::GetDrvError;
|
||||
}
|
||||
mmu_last_cmd = mmu_cmd;
|
||||
mmu_cmd = 0;
|
||||
mmu_cmd = MmuCmd::None;
|
||||
}
|
||||
else if ((mmu_last_response + 300) < _millis()) //request every 300ms
|
||||
{
|
||||
@ -367,7 +367,7 @@ void mmu_loop(void)
|
||||
{
|
||||
DEBUG_PRINTF_P(PSTR("MMU => 'ok'\n"));
|
||||
mmu_attempt_nr = 0;
|
||||
mmu_last_cmd = 0;
|
||||
mmu_last_cmd = MmuCmd::None;
|
||||
mmu_ready = true;
|
||||
mmu_state = S::Idle;
|
||||
}
|
||||
@ -380,8 +380,8 @@ void mmu_loop(void)
|
||||
mmu_cmd = mmu_last_cmd;
|
||||
}
|
||||
else {
|
||||
mmu_cmd = 0;
|
||||
mmu_last_cmd = 0; //check
|
||||
mmu_cmd = MmuCmd::None;
|
||||
mmu_last_cmd = MmuCmd::None; //check
|
||||
mmu_attempt_nr = 0;
|
||||
}
|
||||
}
|
||||
@ -393,7 +393,7 @@ void mmu_loop(void)
|
||||
{
|
||||
fscanf_P(uart2io, PSTR("%d"), &mmu_power_failures); //scan power failures
|
||||
DEBUG_PRINTF_P(PSTR("MMU => 'ok'\n"));
|
||||
mmu_last_cmd = 0;
|
||||
mmu_last_cmd = MmuCmd::None;
|
||||
mmu_ready = true;
|
||||
mmu_state = S::Idle;
|
||||
}
|
||||
@ -430,20 +430,20 @@ int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament)
|
||||
//! Call manage_response() after enqueuing to process command.
|
||||
//! If T command is enqueued, it disables current for extruder motor if TMC2130 driver present.
|
||||
//! If T or L command is enqueued, it marks filament loaded in AutoDeplete module.
|
||||
void mmu_command(uint8_t cmd)
|
||||
void mmu_command(MmuCmd cmd)
|
||||
{
|
||||
if ((cmd >= MMU_CMD_T0) && (cmd <= MMU_CMD_T4))
|
||||
if ((cmd >= MmuCmd::T0) && (cmd <= MmuCmd::T4))
|
||||
{
|
||||
//disable extruder motor
|
||||
#ifdef TMC2130
|
||||
tmc2130_set_pwr(E_AXIS, 0);
|
||||
#endif //TMC2130
|
||||
//printf_P(PSTR("E-axis disabled\n"));
|
||||
ad_markLoaded(cmd - MMU_CMD_T0);
|
||||
ad_markLoaded(cmd - MmuCmd::T0);
|
||||
}
|
||||
if ((cmd >= MMU_CMD_L0) && (cmd <= MMU_CMD_L4))
|
||||
if ((cmd >= MmuCmd::L0) && (cmd <= MmuCmd::L4))
|
||||
{
|
||||
ad_markLoaded(cmd - MMU_CMD_L0);
|
||||
ad_markLoaded(cmd - MmuCmd::L0);
|
||||
}
|
||||
|
||||
mmu_cmd = cmd;
|
||||
@ -787,7 +787,7 @@ void mmu_M600_load_filament(bool automatic)
|
||||
|
||||
// printf_P(PSTR("T code: %d \n"), tmp_extruder);
|
||||
// mmu_printf_P(PSTR("T%d\n"), tmp_extruder);
|
||||
mmu_command(MMU_CMD_T0 + tmp_extruder);
|
||||
mmu_command(static_cast<MmuCmd>(MmuCmd::T0 + tmp_extruder));
|
||||
|
||||
manage_response(false, true, MMU_LOAD_MOVE);
|
||||
mmu_continue_loading();
|
||||
@ -878,8 +878,8 @@ void display_loading()
|
||||
void extr_adj(int extruder) //loading filament for SNMM
|
||||
{
|
||||
#ifndef SNMM
|
||||
uint8_t cmd = MMU_CMD_L0 + extruder;
|
||||
if (cmd > MMU_CMD_L4)
|
||||
MmuCmd cmd = static_cast<MmuCmd>(MmuCmd::L0 + extruder);
|
||||
if (cmd > MmuCmd::L4)
|
||||
{
|
||||
printf_P(PSTR("Filament out of range %d \n"),extruder);
|
||||
return;
|
||||
@ -999,7 +999,7 @@ void extr_unload()
|
||||
|
||||
mmu_filament_ramming();
|
||||
|
||||
mmu_command(MMU_CMD_U0);
|
||||
mmu_command(MmuCmd::U0);
|
||||
// get response
|
||||
manage_response(false, true, MMU_UNLOAD_MOVE);
|
||||
|
||||
@ -1296,7 +1296,7 @@ void lcd_mmu_load_to_nozzle(uint8_t filament_nr)
|
||||
lcd_set_cursor(0, 1); lcd_puts_P(_T(MSG_LOADING_FILAMENT));
|
||||
lcd_print(" ");
|
||||
lcd_print(tmp_extruder + 1);
|
||||
mmu_command(MMU_CMD_T0 + tmp_extruder);
|
||||
mmu_command(static_cast<MmuCmd>(MmuCmd::T0 + tmp_extruder));
|
||||
manage_response(true, true, MMU_TCODE_MOVE);
|
||||
mmu_continue_loading();
|
||||
mmu_extruder = tmp_extruder; //filament change is finished
|
||||
@ -1333,12 +1333,12 @@ void mmu_eject_filament(uint8_t filament, bool recover)
|
||||
current_position[E_AXIS] -= 80;
|
||||
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 2500 / 60, active_extruder);
|
||||
st_synchronize();
|
||||
mmu_command(MMU_CMD_E0 + filament);
|
||||
mmu_command(static_cast<MmuCmd>(MmuCmd::E0 + filament));
|
||||
manage_response(false, false, MMU_UNLOAD_MOVE);
|
||||
if (recover)
|
||||
{
|
||||
lcd_show_fullscreen_message_and_wait_P(_i("Please remove filament and then press the knob."));
|
||||
mmu_command(MMU_CMD_R0);
|
||||
mmu_command(MmuCmd::R0);
|
||||
manage_response(false, false);
|
||||
}
|
||||
|
||||
@ -1361,7 +1361,7 @@ static void load_more()
|
||||
{
|
||||
if (PIN_GET(IR_SENSOR_PIN) == 0) return;
|
||||
DEBUG_PRINTF_P(PSTR("Additional load attempt nr. %d\n"), i);
|
||||
mmu_command(MMU_CMD_C0);
|
||||
mmu_command(MmuCmd::C0);
|
||||
manage_response(true, true, MMU_LOAD_MOVE);
|
||||
}
|
||||
}
|
||||
@ -1378,7 +1378,7 @@ void mmu_continue_loading()
|
||||
if(mmu_load_fail < 255) eeprom_update_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL, mmu_load_fail + 1);
|
||||
if(mmu_load_fail_tot < 65535) eeprom_update_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT, mmu_load_fail_tot + 1);
|
||||
|
||||
mmu_command(MMU_CMD_T0 + tmp_extruder);
|
||||
mmu_command(static_cast<MmuCmd>(MmuCmd::T0 + tmp_extruder));
|
||||
manage_response(true, true, MMU_TCODE_MOVE);
|
||||
load_more();
|
||||
|
||||
@ -1399,7 +1399,7 @@ void mmu_continue_loading()
|
||||
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 50, active_extruder);
|
||||
st_synchronize();
|
||||
|
||||
mmu_command(MMU_CMD_U0);
|
||||
mmu_command(MmuCmd::U0);
|
||||
manage_response(false, true, MMU_UNLOAD_MOVE);
|
||||
|
||||
setAllTargetHotends(0);
|
||||
@ -1410,6 +1410,6 @@ void mmu_continue_loading()
|
||||
}
|
||||
}
|
||||
else { //mmu_ir_sensor_detected == false
|
||||
mmu_command(MMU_CMD_C0);
|
||||
mmu_command(MmuCmd::C0);
|
||||
}
|
||||
}
|
||||
|
@ -32,26 +32,29 @@ extern uint16_t mmu_power_failures;
|
||||
#define MMU_LOAD_FEEDRATE 19.02f //mm/s
|
||||
#define MMU_LOAD_TIME_MS 2000 //should be fine tuned to load time for shortest allowed PTFE tubing and maximum loading speed
|
||||
|
||||
#define MMU_CMD_NONE 0
|
||||
#define MMU_CMD_T0 0x10
|
||||
#define MMU_CMD_T1 0x11
|
||||
#define MMU_CMD_T2 0x12
|
||||
#define MMU_CMD_T3 0x13
|
||||
#define MMU_CMD_T4 0x14
|
||||
#define MMU_CMD_L0 0x20
|
||||
#define MMU_CMD_L1 0x21
|
||||
#define MMU_CMD_L2 0x22
|
||||
#define MMU_CMD_L3 0x23
|
||||
#define MMU_CMD_L4 0x24
|
||||
#define MMU_CMD_C0 0x30
|
||||
#define MMU_CMD_U0 0x40
|
||||
#define MMU_CMD_E0 0x50
|
||||
#define MMU_CMD_E1 0x51
|
||||
#define MMU_CMD_E2 0x52
|
||||
#define MMU_CMD_E3 0x53
|
||||
#define MMU_CMD_E4 0x54
|
||||
#define MMU_CMD_R0 0x60
|
||||
#define MMU_CMD_S3 0x73
|
||||
enum MmuCmd : uint_least8_t
|
||||
{
|
||||
None,
|
||||
T0,
|
||||
T1,
|
||||
T2,
|
||||
T3,
|
||||
T4,
|
||||
L0,
|
||||
L1,
|
||||
L2,
|
||||
L3,
|
||||
L4,
|
||||
C0,
|
||||
U0,
|
||||
E0,
|
||||
E1,
|
||||
E2,
|
||||
E3,
|
||||
E4,
|
||||
R0,
|
||||
S3,
|
||||
};
|
||||
|
||||
extern int mmu_puts_P(const char* str);
|
||||
|
||||
@ -70,7 +73,7 @@ extern void mmu_reset(void);
|
||||
|
||||
extern int8_t mmu_set_filament_type(uint8_t extruder, uint8_t filament);
|
||||
|
||||
extern void mmu_command(uint8_t cmd);
|
||||
extern void mmu_command(MmuCmd cmd);
|
||||
|
||||
extern bool mmu_get_response(uint8_t move = 0);
|
||||
|
||||
|
@ -1986,7 +1986,7 @@ static void lcd_menu_fails_stats_mmu_total()
|
||||
// MMU load fails 000
|
||||
//
|
||||
//////////////////////
|
||||
mmu_command(MMU_CMD_S3);
|
||||
mmu_command(MmuCmd::S3);
|
||||
lcd_timeoutToStatus.stop(); //infinite timeout
|
||||
uint8_t fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL_TOT);
|
||||
uint16_t load_fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL_TOT);
|
||||
@ -7208,7 +7208,7 @@ static bool selftest_irsensor()
|
||||
mmu_filament_ramming();
|
||||
}
|
||||
progress = lcd_selftest_screen(testScreen::fsensor, progress, 1, true, 0);
|
||||
mmu_command(MMU_CMD_U0);
|
||||
mmu_command(MmuCmd::U0);
|
||||
manage_response(false, false);
|
||||
|
||||
for(uint_least8_t i = 0; i < 200; ++i)
|
||||
|
Loading…
Reference in New Issue
Block a user