Merge branch 'MK3' into sound

This commit is contained in:
Marek Bel 2019-06-17 17:24:28 +02:00
commit 24cec4091b
31 changed files with 1343 additions and 774 deletions

View File

@ -7,8 +7,8 @@
#define STR(x) STR_HELPER(x) #define STR(x) STR_HELPER(x)
// Firmware version // Firmware version
#define FW_VERSION "3.7.1" #define FW_VERSION "3.7.2-RC1"
#define FW_COMMIT_NR 2266 #define FW_COMMIT_NR 2359
// FW_VERSION_UNKNOWN means this is an unofficial build. // FW_VERSION_UNKNOWN means this is an unofficial build.
// The firmware should only be checked into github with this symbol. // The firmware should only be checked into github with this symbol.
#define FW_DEV_VERSION FW_VERSION_UNKNOWN #define FW_DEV_VERSION FW_VERSION_UNKNOWN

12
Firmware/Marlin.h Normal file → Executable file
View File

@ -214,6 +214,9 @@ void manage_inactivity(bool ignore_stepper_queue=false);
#endif #endif
#define FARM_FILAMENT_COLOR_NONE 99;
enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5}; enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5};
#define X_AXIS_MASK 1 #define X_AXIS_MASK 1
#define Y_AXIS_MASK 2 #define Y_AXIS_MASK 2
@ -389,7 +392,14 @@ extern bool wizard_active; //autoload temporarily disabled during wizard
extern LongTimer safetyTimer; extern LongTimer safetyTimer;
#define PRINT_PERCENT_DONE_INIT 0xff #define PRINT_PERCENT_DONE_INIT 0xff
#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CUSTOM_MSG_TYPE_TEMCAL) || saved_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL) || card.paused || mmu_print_saved) #define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || card.paused || mmu_print_saved)
//! Beware - mcode_in_progress is set as soon as the command gets really processed,
//! which is not the same as posting the M600 command into the command queue
//! There can be a considerable lag between posting M600 and its real processing which might result
//! in posting multiple M600's into the command queue
//! Instead, the fsensor uses another state variable :( , which is set to true, when the M600 command is enqued
//! and is reset to false when the fsensor returns into its filament runout finished handler
//! I'd normally change this macro, but who knows what would happen in the MMU :)
#define CHECK_FSENSOR ((IS_SD_PRINTING || is_usb_printing) && (mcode_in_progress != 600) && !saved_printing && e_active()) #define CHECK_FSENSOR ((IS_SD_PRINTING || is_usb_printing) && (mcode_in_progress != 600) && !saved_printing && e_active())
extern void calculate_extruder_multipliers(); extern void calculate_extruder_multipliers();

317
Firmware/Marlin_main.cpp Normal file → Executable file
View File

@ -214,8 +214,6 @@ static LongTimer crashDetTimer;
bool mesh_bed_leveling_flag = false; bool mesh_bed_leveling_flag = false;
bool mesh_bed_run_from_menu = false; bool mesh_bed_run_from_menu = false;
int8_t FarmMode = 0;
bool prusa_sd_card_upload = false; bool prusa_sd_card_upload = false;
unsigned int status_number = 0; unsigned int status_number = 0;
@ -853,6 +851,7 @@ void show_fw_version_warnings() {
//! @brief try to check if firmware is on right type of printer //! @brief try to check if firmware is on right type of printer
static void check_if_fw_is_on_right_printer(){ static void check_if_fw_is_on_right_printer(){
#ifdef FILAMENT_SENSOR #ifdef FILAMENT_SENSOR
if((PRINTER_TYPE == PRINTER_MK3) || (PRINTER_TYPE == PRINTER_MK3S)){
#ifdef IR_SENSOR #ifdef IR_SENSOR
swi2c_init(); swi2c_init();
const uint8_t pat9125_detected = swi2c_readByte_A8(PAT9125_I2C_ADDR,0x00,NULL); const uint8_t pat9125_detected = swi2c_readByte_A8(PAT9125_I2C_ADDR,0x00,NULL);
@ -866,6 +865,7 @@ static void check_if_fw_is_on_right_printer(){
if (ir_detected){ if (ir_detected){
lcd_show_fullscreen_message_and_wait_P(_i("MK3 firmware detected on MK3S printer"));} lcd_show_fullscreen_message_and_wait_P(_i("MK3 firmware detected on MK3S printer"));}
#endif //PAT9125 #endif //PAT9125
}
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
} }
@ -993,7 +993,7 @@ static void w25x20cl_err_msg()
void setup() void setup()
{ {
mmu_init(); mmu_init();
ultralcd_init(); ultralcd_init();
#if (LCD_BL_PIN != -1) && defined (LCD_BL_PIN) #if (LCD_BL_PIN != -1) && defined (LCD_BL_PIN)
@ -1049,6 +1049,9 @@ void setup()
//disabled filament autoload (PFW360) //disabled filament autoload (PFW360)
fsensor_autoload_set(false); fsensor_autoload_set(false);
#endif //FILAMENT_SENSOR #endif //FILAMENT_SENSOR
// ~ FanCheck -> on
if(!(eeprom_read_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED)))
eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED,true);
} }
MYSERIAL.begin(BAUDRATE); MYSERIAL.begin(BAUDRATE);
fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream
@ -1282,8 +1285,11 @@ void setup()
#endif //TMC2130 #endif //TMC2130
st_init(); // Initialize stepper, this enables interrupts! st_init(); // Initialize stepper, this enables interrupts!
#ifdef UVLO_SUPPORT
setup_uvlo_interrupt();
#endif //UVLO_SUPPORT
#ifdef TMC2130 #ifdef TMC2130
tmc2130_mode = silentMode?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL; tmc2130_mode = silentMode?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
@ -1486,10 +1492,6 @@ void setup()
} }
check_babystep(); //checking if Z babystep is in allowed range check_babystep(); //checking if Z babystep is in allowed range
#ifdef UVLO_SUPPORT
setup_uvlo_interrupt();
#endif //UVLO_SUPPORT
#if !defined(DEBUG_DISABLE_FANCHECK) && defined(FANCHECK) && defined(TACH_1) && TACH_1 >-1 #if !defined(DEBUG_DISABLE_FANCHECK) && defined(FANCHECK) && defined(TACH_1) && TACH_1 >-1
setup_fan_interrupt(); setup_fan_interrupt();
#endif //DEBUG_DISABLE_FANCHECK #endif //DEBUG_DISABLE_FANCHECK
@ -1629,6 +1631,7 @@ void setup()
} }
#endif //UVLO_SUPPORT #endif //UVLO_SUPPORT
fCheckModeInit();
KEEPALIVE_STATE(NOT_BUSY); KEEPALIVE_STATE(NOT_BUSY);
#ifdef WATCHDOG #ifdef WATCHDOG
wdt_enable(WDTO_4S); wdt_enable(WDTO_4S);
@ -2982,6 +2985,32 @@ void gcode_M114()
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
} }
//! extracted code to compute z_shift for M600 in case of filament change operation
//! requested from fsensors.
//! The function ensures, that the printhead lifts to at least 25mm above the heat bed
//! unlike the previous implementation, which was adding 25mm even when the head was
//! printing at e.g. 24mm height.
//! A safety margin of FILAMENTCHANGE_ZADD is added in all cases to avoid touching
//! the printout.
//! This function is templated to enable fast change of computation data type.
//! @return new z_shift value
template<typename T>
static T gcode_M600_filament_change_z_shift()
{
#ifdef FILAMENTCHANGE_ZADD
static_assert(Z_MAX_POS < (255 - FILAMENTCHANGE_ZADD), "Z-range too high, change the T type from uint8_t to uint16_t");
// avoid floating point arithmetics when not necessary - results in shorter code
T ztmp = T( current_position[Z_AXIS] );
T z_shift = 0;
if(ztmp < T(25)){
z_shift = T(25) - ztmp; // make sure to be at least 25mm above the heat bed
}
return z_shift + T(FILAMENTCHANGE_ZADD); // always move above printout
#else
return T(0);
#endif
}
static void gcode_M600(bool automatic, float x_position, float y_position, float z_shift, float e_shift, float /*e_shift_late*/) static void gcode_M600(bool automatic, float x_position, float y_position, float z_shift, float e_shift, float /*e_shift_late*/)
{ {
st_synchronize(); st_synchronize();
@ -3112,10 +3141,9 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
#endif //IR_SENSOR #endif //IR_SENSOR
lcd_setstatuspgm(_T(WELCOME_MSG)); lcd_setstatuspgm(_T(WELCOME_MSG));
custom_message_type = CUSTOM_MSG_TYPE_STATUS; custom_message_type = CustomMsg::Status;
} }
//! @brief Rise Z if too low to avoid blob/jam before filament loading //! @brief Rise Z if too low to avoid blob/jam before filament loading
//! //!
//! It doesn't plan_buffer_line(), as it expects plan_buffer_line() to be called after //! It doesn't plan_buffer_line(), as it expects plan_buffer_line() to be called after
@ -3129,6 +3157,11 @@ void gcode_M701()
{ {
printf_P(PSTR("gcode_M701 begin\n")); printf_P(PSTR("gcode_M701 begin\n"));
if (farm_mode)
{
prusa_statistics(22);
}
if (mmu_enabled) if (mmu_enabled)
{ {
extr_adj(tmp_extruder);//loads current extruder extr_adj(tmp_extruder);//loads current extruder
@ -3137,7 +3170,7 @@ void gcode_M701()
else else
{ {
enable_z(); enable_z();
custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; custom_message_type = CustomMsg::FilamentLoading;
#ifdef FSENSOR_QUALITY #ifdef FSENSOR_QUALITY
fsensor_oq_meassure_start(40); fsensor_oq_meassure_start(40);
@ -3165,7 +3198,7 @@ void gcode_M701()
lcd_setstatuspgm(_T(WELCOME_MSG)); lcd_setstatuspgm(_T(WELCOME_MSG));
disable_z(); disable_z();
loading_flag = false; loading_flag = false;
custom_message_type = CUSTOM_MSG_TYPE_STATUS; custom_message_type = CustomMsg::Status;
#ifdef FSENSOR_QUALITY #ifdef FSENSOR_QUALITY
fsensor_oq_meassure_stop(); fsensor_oq_meassure_stop();
@ -3370,8 +3403,10 @@ void process_commands()
{ {
#ifdef FANCHECK #ifdef FANCHECK
if (fan_check_error){ if (fan_check_error){
fan_check_error = false; if( fan_check_error == EFCE_DETECTED ){
lcd_pause_print(); fan_check_error = EFCE_REPORTED;
lcd_pause_print();
} // otherwise it has already been reported, so just ignore further processing
return; return;
} }
#endif #endif
@ -3601,7 +3636,39 @@ void process_commands()
} else if(code_seen("FR")) { //! PRUSA FR } else if(code_seen("FR")) { //! PRUSA FR
// Factory full reset // Factory full reset
factory_reset(0); factory_reset(0);
}
//-//
/*
} else if(code_seen("qqq")) {
MYSERIAL.println("=== checking ===");
MYSERIAL.println(eeprom_read_byte((uint8_t*)EEPROM_CHECK_MODE),DEC);
MYSERIAL.println(eeprom_read_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER),DEC);
MYSERIAL.println(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM),DEC);
MYSERIAL.println(farm_mode,DEC);
MYSERIAL.println(eCheckMode,DEC);
} else if(code_seen("www")) {
MYSERIAL.println("=== @ FF ===");
eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,0xFF);
eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,0xFF);
eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF);
*/
} else if (code_seen("nozzle")) { //! PRUSA nozzle
uint16_t nDiameter;
if(code_seen('D'))
{
nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um]
nozzle_diameter_check(nDiameter);
}
else if(code_seen("set") && farm_mode)
{
strchr_pointer++; // skip 2nd char (~ 'e')
strchr_pointer++; // skip 3rd char (~ 't')
nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um]
eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)e_NOZZLE_DIAMETER_NULL); // for correct synchronization after farm-mode exiting
eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
}
else SERIAL_PROTOCOLLN((float)eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)/1000.0);
}
//else if (code_seen('Cal')) { //else if (code_seen('Cal')) {
// lcd_calibration(); // lcd_calibration();
// } // }
@ -4146,7 +4213,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
// setTargetHotend(200, 0); // setTargetHotend(200, 0);
setTargetBed(70 + (start_temp - 30)); setTargetBed(70 + (start_temp - 30));
custom_message_type = CUSTOM_MSG_TYPE_TEMCAL; custom_message_type = CustomMsg::TempCal;
custom_message_state = 1; custom_message_state = 1;
lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION)); lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION));
current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
@ -4248,7 +4315,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
break; break;
} }
puts_P(_N("PINDA probe calibration start")); puts_P(_N("PINDA probe calibration start"));
custom_message_type = CUSTOM_MSG_TYPE_TEMCAL; custom_message_type = CustomMsg::TempCal;
custom_message_state = 1; custom_message_state = 1;
lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION)); lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION));
current_position[X_AXIS] = PINDA_PREHEAT_X; current_position[X_AXIS] = PINDA_PREHEAT_X;
@ -4316,7 +4383,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
} }
custom_message_type = CUSTOM_MSG_TYPE_STATUS; custom_message_type = CustomMsg::Status;
eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
puts_P(_N("Temperature calibration done.")); puts_P(_N("Temperature calibration done."));
@ -4376,7 +4443,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
// We don't know where we are! HOME! // We don't know where we are! HOME!
// Push the commands to the front of the message queue in the reverse order! // Push the commands to the front of the message queue in the reverse order!
// There shall be always enough space reserved for these commands. // There shall be always enough space reserved for these commands.
if (lcd_commands_type != LCD_COMMAND_STOP_PRINT) { if (lcd_commands_type != LcdCommands::StopPrint) {
repeatcommand_front(); // repeat G80 with all its parameters repeatcommand_front(); // repeat G80 with all its parameters
enquecommand_front_P((PSTR("G28 W0"))); enquecommand_front_P((PSTR("G28 W0")));
} }
@ -4416,7 +4483,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
if (temp_comp_start) if (temp_comp_start)
if (run == false && temp_cal_active == true && calibration_status_pinda() == true && target_temperature_bed >= 50) { if (run == false && temp_cal_active == true && calibration_status_pinda() == true && target_temperature_bed >= 50) {
if (lcd_commands_type != LCD_COMMAND_STOP_PRINT) { if (lcd_commands_type != LcdCommands::StopPrint) {
temp_compensation_start(); temp_compensation_start();
run = true; run = true;
repeatcommand_front(); // repeat G80 with all its parameters repeatcommand_front(); // repeat G80 with all its parameters
@ -4428,14 +4495,14 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
break; break;
} }
run = false; run = false;
if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) { if (lcd_commands_type == LcdCommands::StopPrint) {
mesh_bed_leveling_flag = false; mesh_bed_leveling_flag = false;
break; break;
} }
// Save custom message state, set a new custom message state to display: Calibrating point 9. // Save custom message state, set a new custom message state to display: Calibrating point 9.
unsigned int custom_message_type_old = custom_message_type; CustomMsg custom_message_type_old = custom_message_type;
unsigned int custom_message_state_old = custom_message_state; unsigned int custom_message_state_old = custom_message_state;
custom_message_type = CUSTOM_MSG_TYPE_MESHBL; custom_message_type = CustomMsg::MeshBedLeveling;
custom_message_state = (nMeasPoints * nMeasPoints) + 10; custom_message_state = (nMeasPoints * nMeasPoints) + 10;
lcd_update(1); lcd_update(1);
@ -4635,7 +4702,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
enable_z_endstop(bState); enable_z_endstop(bState);
} while (st_get_position_mm(Z_AXIS) > MESH_HOME_Z_SEARCH); // i.e. Z-leveling not o.k. } while (st_get_position_mm(Z_AXIS) > MESH_HOME_Z_SEARCH); // i.e. Z-leveling not o.k.
// plan_set_z_position(MESH_HOME_Z_SEARCH); // is not necessary ('do-while' loop always ends at the expected Z-position) // plan_set_z_position(MESH_HOME_Z_SEARCH); // is not necessary ('do-while' loop always ends at the expected Z-position)
custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery custom_message_type=CustomMsg::Status; // display / status-line recovery
lcd_update_enable(true); // display / status-line recovery lcd_update_enable(true); // display / status-line recovery
gcode_G28(true, true, true); // X & Y & Z-homing (must be after individual Z-homing (problem with spool-holder)!) gcode_G28(true, true, true); // X & Y & Z-homing (must be after individual Z-homing (problem with spool-holder)!)
repeatcommand_front(); // re-run (i.e. of "G80") repeatcommand_front(); // re-run (i.e. of "G80")
@ -4911,6 +4978,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no); EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
SilentModeMenu = SILENT_MODE_OFF; SilentModeMenu = SILENT_MODE_OFF;
eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu); eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
fCheckModeInit(); // alternatively invoke printer reset
break; break;
case 99: //! G99 (deactivate farm mode) case 99: //! G99 (deactivate farm mode)
@ -4918,6 +4986,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT)
lcd_printer_connected(); lcd_printer_connected();
eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode); eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
lcd_update(2); lcd_update(2);
fCheckModeInit(); // alternatively invoke printer reset
break; break;
default: default:
printf_P(PSTR("Unknown G code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); printf_P(PSTR("Unknown G code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE);
@ -5880,7 +5949,7 @@ Sigma_Exit:
SERIAL_PROTOCOLLNRPGM(FW_VERSION_STR_P()); SERIAL_PROTOCOLLNRPGM(FW_VERSION_STR_P());
} else if (code_seen('U')) { } else if (code_seen('U')) {
// Check the firmware version provided. If the firmware version provided by the U code is higher than the currently running firmware, // Check the firmware version provided. If the firmware version provided by the U code is higher than the currently running firmware,
// pause the print and ask the user to upgrade the firmware. // pause the print for 30s and ask the user to upgrade the firmware.
show_upgrade_dialog_if_version_newer(++ strchr_pointer); show_upgrade_dialog_if_version_newer(++ strchr_pointer);
} else { } else {
SERIAL_ECHOPGM("FIRMWARE_NAME:Prusa-Firmware "); SERIAL_ECHOPGM("FIRMWARE_NAME:Prusa-Firmware ");
@ -6563,7 +6632,7 @@ Sigma_Exit:
float x_position = current_position[X_AXIS]; float x_position = current_position[X_AXIS];
float y_position = current_position[Y_AXIS]; float y_position = current_position[Y_AXIS];
float z_shift = 0; float z_shift = 0; // is it necessary to be a float?
float e_shift_init = 0; float e_shift_init = 0;
float e_shift_late = 0; float e_shift_late = 0;
bool automatic = false; bool automatic = false;
@ -6599,10 +6668,7 @@ Sigma_Exit:
} }
else else
{ {
#ifdef FILAMENTCHANGE_ZADD z_shift = gcode_M600_filament_change_z_shift<uint8_t>();
z_shift= FILAMENTCHANGE_ZADD ;
if(current_position[Z_AXIS] < 25) z_shift+= 25 ;
#endif
} }
//Move XY to side //Move XY to side
if(code_seen('X')) if(code_seen('X'))
@ -7062,8 +7128,14 @@ Sigma_Exit:
} }
else else
{ {
#if defined(MMU_HAS_CUTTER) && defined(MMU_ALWAYS_CUT)
if (EEPROM_MMU_CUTTER_ENABLED_always == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
{
mmu_command(MmuCmd::K0 + tmp_extruder);
manage_response(true, true, MMU_UNLOAD_MOVE);
}
#endif //defined(MMU_HAS_CUTTER) && defined(MMU_ALWAYS_CUT)
mmu_command(MmuCmd::T0 + tmp_extruder); mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE); manage_response(true, true, MMU_TCODE_MOVE);
mmu_continue_loading(is_usb_printing); mmu_continue_loading(is_usb_printing);
@ -7617,7 +7689,7 @@ static void handleSafetyTimer()
{ {
safetyTimer.start(); safetyTimer.start();
} }
else if (safetyTimer.expired(safetytimer_inactive_time)) else if (safetyTimer.expired(farm_mode?FARM_DEFAULT_SAFETYTIMER_TIME_ms:safetytimer_inactive_time))
{ {
setTargetBed(0); setTargetBed(0);
setAllTargetHotends(0); setAllTargetHotends(0);
@ -7639,9 +7711,9 @@ bool bInhibitFlag;
#ifdef IR_SENSOR #ifdef IR_SENSOR
bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active
#endif // IR_SENSOR #endif // IR_SENSOR
if ((mcode_in_progress != 600) && (eFilamentAction != e_FILAMENT_ACTION_autoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active if ((mcode_in_progress != 600) && (eFilamentAction != FilamentAction::AutoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active
{ {
if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL) && !wizard_active) if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && !wizard_active)
{ {
if (fsensor_check_autoload()) if (fsensor_check_autoload())
{ {
@ -7662,7 +7734,7 @@ if(0)
show_preheat_nozzle_warning(); show_preheat_nozzle_warning();
lcd_update_enable(true); lcd_update_enable(true);
*/ */
eFilamentAction=e_FILAMENT_ACTION_autoLoad; eFilamentAction=FilamentAction::AutoLoad;
bFilamentFirstRun=false; bFilamentFirstRun=false;
if(target_temperature[0]>=EXTRUDE_MINTEMP) if(target_temperature[0]>=EXTRUDE_MINTEMP)
{ {
@ -8136,7 +8208,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi
float bed_zero_ref_y = (-0.6f + Y_PROBE_OFFSET_FROM_EXTRUDER); float bed_zero_ref_y = (-0.6f + Y_PROBE_OFFSET_FROM_EXTRUDER);
float mesh_home_z_search = 4; float mesh_home_z_search = 4;
float measure_z_heigth = 0.2f; float measure_z_height = 0.2f;
float row[x_points_num]; float row[x_points_num];
int ix = 0; int ix = 0;
int iy = 0; int iy = 0;
@ -8153,7 +8225,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi
unsigned int custom_message_type_old = custom_message_type; unsigned int custom_message_type_old = custom_message_type;
unsigned int custom_message_state_old = custom_message_state; unsigned int custom_message_state_old = custom_message_state;
custom_message_type = CUSTOM_MSG_TYPE_MESHBL; custom_message_type = CustomMsg::MeshBedLeveling;
custom_message_state = (x_points_num * y_points_num) + 10; custom_message_state = (x_points_num * y_points_num) + 10;
lcd_update(1); lcd_update(1);
@ -8171,7 +8243,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi
} }
st_synchronize(); st_synchronize();
*/ */
destination[Z_AXIS] = measure_z_heigth; destination[Z_AXIS] = measure_z_height;
plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], Z_LIFT_FEEDRATE, active_extruder); plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], Z_LIFT_FEEDRATE, active_extruder);
for(int8_t i=0; i < NUM_AXIS; i++) { for(int8_t i=0; i < NUM_AXIS; i++) {
current_position[i] = destination[i]; current_position[i] = destination[i];
@ -8351,7 +8423,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_
} }
unsigned int custom_message_type_old = custom_message_type; unsigned int custom_message_type_old = custom_message_type;
unsigned int custom_message_state_old = custom_message_state; unsigned int custom_message_state_old = custom_message_state;
custom_message_type = CUSTOM_MSG_TYPE_MESHBL; custom_message_type = CustomMsg::MeshBedLeveling;
custom_message_state = (x_points_num * y_points_num) + 10; custom_message_state = (x_points_num * y_points_num) + 10;
lcd_update(1); lcd_update(1);
@ -8501,7 +8573,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_
void temp_compensation_start() { void temp_compensation_start() {
custom_message_type = CUSTOM_MSG_TYPE_TEMPRE; custom_message_type = CustomMsg::TempCompPreheat;
custom_message_state = PINDA_HEAT_T + 1; custom_message_state = PINDA_HEAT_T + 1;
lcd_update(2); lcd_update(2);
if (degHotend(active_extruder) > EXTRUDE_MINTEMP) { if (degHotend(active_extruder) > EXTRUDE_MINTEMP) {
@ -8522,7 +8594,7 @@ void temp_compensation_start() {
if (custom_message_state == 99 || custom_message_state == 9) lcd_update(2); //force whole display redraw if number of digits changed if (custom_message_state == 99 || custom_message_state == 9) lcd_update(2); //force whole display redraw if number of digits changed
else lcd_update(1); else lcd_update(1);
} }
custom_message_type = CUSTOM_MSG_TYPE_STATUS; custom_message_type = CustomMsg::Status;
custom_message_state = 0; custom_message_state = 0;
} }
@ -8661,12 +8733,10 @@ void serialecho_temperatures() {
SERIAL_PROTOCOL_F(degBed(), 1); SERIAL_PROTOCOL_F(degBed(), 1);
SERIAL_PROTOCOLLN(""); SERIAL_PROTOCOLLN("");
} }
extern uint32_t sdpos_atomic; extern uint32_t sdpos_atomic;
#ifdef UVLO_SUPPORT #ifdef UVLO_SUPPORT
void uvlo_() void uvlo_()
{ {
unsigned long time_start = _millis(); unsigned long time_start = _millis();
bool sd_print = card.sdprinting; bool sd_print = card.sdprinting;
@ -8713,12 +8783,10 @@ void uvlo_()
// Store the current extruder position. // Store the current extruder position.
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), st_get_position_mm(E_AXIS)); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E), st_get_position_mm(E_AXIS));
eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1); eeprom_update_byte((uint8_t*)EEPROM_UVLO_E_ABS, axis_relative_modes[3]?0:1);
// Clean the input command queue. // Clean the input command queue.
cmdqueue_reset(); cmdqueue_reset();
card.sdprinting = false; card.sdprinting = false;
// card.closefile(); // card.closefile();
// Enable stepper driver interrupt to move Z axis. // Enable stepper driver interrupt to move Z axis.
// This should be fine as the planner and command queues are empty and the SD card printing is disabled. // This should be fine as the planner and command queues are empty and the SD card printing is disabled.
//FIXME one may want to disable serial lines at this point of time to avoid interfering with the command queue, //FIXME one may want to disable serial lines at this point of time to avoid interfering with the command queue,
@ -8734,26 +8802,25 @@ void uvlo_()
st_synchronize(); st_synchronize();
disable_e0(); disable_e0();
plan_buffer_line( plan_buffer_line(
current_position[X_AXIS], current_position[X_AXIS],
current_position[Y_AXIS], current_position[Y_AXIS],
current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS],
current_position[E_AXIS] - default_retraction, current_position[E_AXIS] - default_retraction,
40, active_extruder); 40, active_extruder);
st_synchronize(); st_synchronize();
disable_e0(); disable_e0();
plan_buffer_line( plan_buffer_line(
current_position[X_AXIS], current_position[X_AXIS],
current_position[Y_AXIS], current_position[Y_AXIS],
current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS], current_position[Z_AXIS] + UVLO_Z_AXIS_SHIFT + float((1024 - z_microsteps + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS],
current_position[E_AXIS] - default_retraction, current_position[E_AXIS] - default_retraction,
40, active_extruder); 40, active_extruder);
st_synchronize(); st_synchronize();
disable_e0(); disable_e0();
disable_z(); disable_z();
// Move Z up to the next 0th full step. // Move Z up to the next 0th full step.
// Write the file position. // Write the file position.
eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position); eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position);
@ -8769,9 +8836,10 @@ void uvlo_()
// for reaching the zero full step before powering off. // for reaching the zero full step before powering off.
eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps); eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps);
// Store the current position. // Store the current position.
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position[X_AXIS]);
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]); eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position[Y_AXIS]);
eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z), current_position[Z_AXIS]); eeprom_update_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z , current_position[Z_AXIS]);
// Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates) // Store the current feed rate, temperatures, fan speed and extruder multipliers (flow rates)
EEPROM_save_B(EEPROM_UVLO_FEEDRATE, &feedrate_bckp); EEPROM_save_B(EEPROM_UVLO_FEEDRATE, &feedrate_bckp);
eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]); eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]);
@ -8797,16 +8865,14 @@ void uvlo_()
// Increment power failure counter // Increment power failure counter
eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1);
eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1);
printf_P(_N("UVLO - end %d\n"), _millis() - time_start);
printf_P(_N("UVLO - end %d\n"), _millis() - time_start);
#if 0 #if 0
// Move the print head to the side of the print until all the power stored in the power supply capacitors is depleted. // Move the print head to the side of the print until all the power stored in the power supply capacitors is depleted.
current_position[X_AXIS] = (current_position[X_AXIS] < 0.5f * (X_MIN_POS + X_MAX_POS)) ? X_MIN_POS : X_MAX_POS; current_position[X_AXIS] = (current_position[X_AXIS] < 0.5f * (X_MIN_POS + X_MAX_POS)) ? X_MIN_POS : X_MAX_POS;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder); plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
st_synchronize(); st_synchronize();
#endif #endif
wdt_enable(WDTO_500MS); wdt_enable(WDTO_500MS);
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
while(1) while(1)
@ -8832,30 +8898,29 @@ tmc2130_set_current_r(Z_AXIS, 20);
#ifdef TMC2130 #ifdef TMC2130
z_microsteps=tmc2130_rd_MSCNT(Z_TMC2130_CS); z_microsteps=tmc2130_rd_MSCNT(Z_TMC2130_CS);
#endif //TMC2130 #endif //TMC2130
planner_abort_hard(); planner_abort_hard();
sei();
plan_buffer_line(
current_position[X_AXIS],
current_position[Y_AXIS],
// current_position[Z_AXIS]+float((1024-z_microsteps+7)>>4)/axis_steps_per_unit[Z_AXIS],
current_position[Z_AXIS]+UVLO_Z_AXIS_SHIFT+float((1024-z_microsteps+7)>>4)/cs.axis_steps_per_unit[Z_AXIS],
current_position[E_AXIS],
40, active_extruder);
st_synchronize();
disable_z(); disable_z();
// Finaly store the "power outage" flag. //save current position only in case, where the printer is moving on Z axis, which is only when EEPROM_UVLO is 1
//if(sd_print) //EEPROM_UVLO is 1 after normal uvlo or after recover_print(), when the extruder is moving on Z axis after rehome
eeprom_update_byte((uint8_t*)EEPROM_UVLO,2); if(eeprom_read_byte((uint8_t*)EEPROM_UVLO)!=2){
eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]);
eeprom_update_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS),z_microsteps);
}
eeprom_update_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS),z_microsteps); //after multiple power panics current Z axis is unknow
eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]); //in this case we set EEPROM_UVLO_TINY_CURRENT_POSITION_Z to last know position which is EEPROM_UVLO_CURRENT_POSITION_Z
if(eeprom_read_float((float*)EEPROM_UVLO_TINY_CURRENT_POSITION_Z) < 0.001f){
eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), eeprom_read_float((float*)EEPROM_UVLO_CURRENT_POSITION_Z));
eeprom_update_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS), eeprom_read_word((uint16_t*)EEPROM_UVLO_Z_MICROSTEPS));
}
// Finaly store the "power outage" flag.
eeprom_update_byte((uint8_t*)EEPROM_UVLO,2);
// Increment power failure counter // Increment power failure counter
eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1); eeprom_update_byte((uint8_t*)EEPROM_POWER_COUNT, eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) + 1);
eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1); eeprom_update_word((uint16_t*)EEPROM_POWER_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) + 1);
wdt_enable(WDTO_500MS); wdt_enable(WDTO_500MS);
WRITE(BEEPER,HIGH); WRITE(BEEPER,HIGH);
while(1) while(1)
@ -8917,7 +8982,9 @@ void setup_uvlo_interrupt() {
ISR(INT4_vect) { ISR(INT4_vect) {
EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once
SERIAL_ECHOLNPGM("INT4"); SERIAL_ECHOLNPGM("INT4");
if(IS_SD_PRINTING && (!(eeprom_read_byte((uint8_t*)EEPROM_UVLO))) ) uvlo_(); //fire normal uvlo only in case where EEPROM_UVLO is 0 or if IS_SD_PRINTING is 1.
//Don't change || to && because in some case the printer can be moving although IS_SD_PRINTING is zero
if((IS_SD_PRINTING ) || (!(eeprom_read_byte((uint8_t*)EEPROM_UVLO)))) uvlo_();
if(eeprom_read_byte((uint8_t*)EEPROM_UVLO)) uvlo_tiny(); if(eeprom_read_byte((uint8_t*)EEPROM_UVLO)) uvlo_tiny();
} }
@ -8925,14 +8992,14 @@ void recover_print(uint8_t automatic) {
char cmd[30]; char cmd[30];
lcd_update_enable(true); lcd_update_enable(true);
lcd_update(2); lcd_update(2);
lcd_setstatuspgm(_i("Recovering print "));////MSG_RECOVERING_PRINT c=20 r=1 lcd_setstatuspgm(_i("Recovering print "));////MSG_RECOVERING_PRINT c=20 r=1
bool bTiny=(eeprom_read_byte((uint8_t*)EEPROM_UVLO)==2);
recover_machine_state_after_power_panic(bTiny); //recover position, temperatures and extrude_multipliers
bool bTiny=(eeprom_read_byte((uint8_t*)EEPROM_UVLO)==2);
recover_machine_state_after_power_panic(bTiny); //recover position, temperatures and extrude_multipliers
// Lift the print head, so one may remove the excess priming material. // Lift the print head, so one may remove the excess priming material.
if(!bTiny&&(current_position[Z_AXIS]<25)) if(!bTiny&&(current_position[Z_AXIS]<25))
enquecommand_P(PSTR("G1 Z25 F800")); enquecommand_P(PSTR("G1 Z25 F800"));
// Home X and Y axes. Homing just X and Y shall not touch the babystep and the world2machine transformation status. // Home X and Y axes. Homing just X and Y shall not touch the babystep and the world2machine transformation status.
enquecommand_P(PSTR("G28 X Y")); enquecommand_P(PSTR("G28 X Y"));
// Set the target bed and nozzle temperatures and wait. // Set the target bed and nozzle temperatures and wait.
@ -8952,8 +9019,7 @@ void recover_print(uint8_t automatic) {
// Restart the print. // Restart the print.
restore_print_from_eeprom(); restore_print_from_eeprom();
printf_P(_N("Current pos Z_AXIS:%.3f\nCurrent pos E_AXIS:%.3f\n"), current_position[Z_AXIS], current_position[E_AXIS]);
printf_P(_N("Current pos Z_AXIS:%.3f\nCurrent pos E_AXIS:%.3f\n"), current_position[Z_AXIS], current_position[E_AXIS]);
} }
void recover_machine_state_after_power_panic(bool bTiny) void recover_machine_state_after_power_panic(bool bTiny)
@ -8963,14 +9029,36 @@ void recover_machine_state_after_power_panic(bool bTiny)
// The logical XY coordinates are needed to recover the machine Z coordinate corrected by the mesh bed leveling. // The logical XY coordinates are needed to recover the machine Z coordinate corrected by the mesh bed leveling.
current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0)); current_position[X_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0));
current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)); current_position[Y_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4));
// 2) Restore the mesh bed leveling offsets. This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case.
mbl.active = false;
for (int8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) {
uint8_t ix = mesh_point % MESH_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1
uint8_t iy = mesh_point / MESH_NUM_X_POINTS;
// Scale the z value to 10u resolution.
int16_t v;
eeprom_read_block(&v, (void*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL+2*mesh_point), 2);
if (v != 0)
mbl.active = true;
mbl.z_values[iy][ix] = float(v) * 0.001f;
}
// Recover the logical coordinate of the Z axis at the time of the power panic. // Recover the logical coordinate of the Z axis at the time of the power panic.
// The current position after power panic is moved to the next closest 0th full step. // The current position after power panic is moved to the next closest 0th full step.
if(bTiny) if(bTiny){
current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z)) + current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z))
UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS)) + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS]; + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS))
else + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS];
//after multiple power panics the print is slightly in the air so get it little bit down.
//Not exactly sure why is this happening, but it has something to do with bed leveling and world2machine coordinates
current_position[Z_AXIS] -= 0.4*mbl.get_z(current_position[X_AXIS], current_position[Y_AXIS]);
}
else{
current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)) + current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)) +
UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS)) + 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS]; UVLO_Z_AXIS_SHIFT + float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS))
+ 7) >> 4) / cs.axis_steps_per_unit[Z_AXIS];
}
if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_E_ABS)) { if (eeprom_read_byte((uint8_t*)EEPROM_UVLO_E_ABS)) {
current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E)); current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E));
sprintf_P(cmd, PSTR("G92 E")); sprintf_P(cmd, PSTR("G92 E"));
@ -8983,21 +9071,8 @@ void recover_machine_state_after_power_panic(bool bTiny)
SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial "); SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
print_world_coordinates(); print_world_coordinates();
// 2) Initialize the logical to physical coordinate system transformation. // 3) Initialize the logical to physical coordinate system transformation.
world2machine_initialize(); world2machine_initialize();
// 3) Restore the mesh bed leveling offsets. This is 2*7*7=98 bytes, which takes 98*3.4us=333us in worst case.
mbl.active = false;
for (int8_t mesh_point = 0; mesh_point < MESH_NUM_X_POINTS * MESH_NUM_Y_POINTS; ++ mesh_point) {
uint8_t ix = mesh_point % MESH_NUM_X_POINTS; // from 0 to MESH_NUM_X_POINTS - 1
uint8_t iy = mesh_point / MESH_NUM_X_POINTS;
// Scale the z value to 10u resolution.
int16_t v;
eeprom_read_block(&v, (void*)(EEPROM_UVLO_MESH_BED_LEVELING_FULL+2*mesh_point), 2);
if (v != 0)
mbl.active = true;
mbl.z_values[iy][ix] = float(v) * 0.001f;
}
// SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial "); // SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
// print_mesh_bed_leveling_table(); // print_mesh_bed_leveling_table();
@ -9013,7 +9088,7 @@ void recover_machine_state_after_power_panic(bool bTiny)
axis_known_position[X_AXIS] = true; enable_x(); axis_known_position[X_AXIS] = true; enable_x();
axis_known_position[Y_AXIS] = true; enable_y(); axis_known_position[Y_AXIS] = true; enable_y();
axis_known_position[Z_AXIS] = true; enable_z(); axis_known_position[Z_AXIS] = true; enable_z();
SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial "); SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
print_physical_coordinates(); print_physical_coordinates();
@ -9077,6 +9152,8 @@ void restore_print_from_eeprom() {
strcat_P(cmd, PSTR(" Y")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4)))); strcat_P(cmd, PSTR(" Y")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4))));
strcat_P(cmd, PSTR(" F2000")); strcat_P(cmd, PSTR(" F2000"));
enquecommand(cmd); enquecommand(cmd);
//moving on Z axis ahead, set EEPROM_UVLO to 1, so normal uvlo can fire
eeprom_update_byte((uint8_t*)EEPROM_UVLO,1);
// Move the Z axis down to the print, in logical coordinates. // Move the Z axis down to the print, in logical coordinates.
strcpy_P(cmd, PSTR("G1 Z")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z)))); strcpy_P(cmd, PSTR("G1 Z")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z))));
enquecommand(cmd); enquecommand(cmd);
@ -9266,22 +9343,20 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
// First unretract (relative extrusion) // First unretract (relative extrusion)
if(!saved_extruder_relative_mode){ if(!saved_extruder_relative_mode){
strcpy_P(buf, PSTR("M83")); enquecommand(PSTR("M83"), true);
enquecommand(buf, false);
} }
//retract 45mm/s //retract 45mm/s
strcpy_P(buf, PSTR("G1 E")); // A single sprintf may not be faster, but is definitely 20B shorter
dtostrf(e_move, 6, 3, buf + strlen(buf)); // than a sequence of commands building the string piece by piece
strcat_P(buf, PSTR(" F")); // A snprintf would have been a safer call, but since it is not used
dtostrf(2700, 8, 3, buf + strlen(buf)); // in the whole program, its implementation would bring more bytes to the total size
// The behavior of dtostrf 8,3 should be roughly the same as %-0.3
sprintf_P(buf, PSTR("G1 E%-0.3f F2700"), e_move);
enquecommand(buf, false); enquecommand(buf, false);
// Then lift Z axis // Then lift Z axis
strcpy_P(buf, PSTR("G1 Z")); sprintf_P(buf, PSTR("G1 Z%-0.3f F%-0.3f"), saved_pos[Z_AXIS] + z_move, homing_feedrate[Z_AXIS]);
dtostrf(saved_pos[Z_AXIS] + z_move, 8, 3, buf + strlen(buf));
strcat_P(buf, PSTR(" F"));
dtostrf(homing_feedrate[Z_AXIS], 8, 3, buf + strlen(buf));
// At this point the command queue is empty. // At this point the command queue is empty.
enquecommand(buf, false); enquecommand(buf, false);
// If this call is invoked from the main Arduino loop() function, let the caller know that the command // If this call is invoked from the main Arduino loop() function, let the caller know that the command
@ -9307,6 +9382,12 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
void restore_print_from_ram_and_continue(float e_move) void restore_print_from_ram_and_continue(float e_move)
{ {
if (!saved_printing) return; if (!saved_printing) return;
#ifdef FANCHECK
// Do not allow resume printing if fans are still not ok
if( fan_check_error != EFCE_OK )return;
#endif
// for (int axis = X_AXIS; axis <= E_AXIS; axis++) // for (int axis = X_AXIS; axis <= E_AXIS; axis++)
// current_position[axis] = st_get_position_mm(axis); // current_position[axis] = st_get_position_mm(axis);
active_extruder = saved_active_extruder; //restore active_extruder active_extruder = saved_active_extruder; //restore active_extruder

View File

@ -242,6 +242,7 @@ void CardReader::startFileprint()
{ {
sdprinting = true; sdprinting = true;
paused = false; paused = false;
Stopped = false;
#ifdef SDCARD_SORT_ALPHA #ifdef SDCARD_SORT_ALPHA
//flush_presort(); //flush_presort();
#endif #endif

View File

@ -161,6 +161,7 @@ private:
void flush_presort(); void flush_presort();
#endif #endif
}; };
extern bool Stopped;
extern CardReader card; extern CardReader card;
#define IS_SD_PRINTING (card.sdprinting) #define IS_SD_PRINTING (card.sdprinting)

2
Firmware/cmdqueue.cpp Normal file → Executable file
View File

@ -598,7 +598,7 @@ void get_command()
if (farm_mode) if (farm_mode)
{ {
prusa_statistics(6); prusa_statistics(6);
lcd_commands_type = LCD_COMMAND_FARM_MODE_CONFIRM; lcd_commands_type = LcdCommands::FarmModeConfirm;
} }
} }

View File

@ -155,11 +155,18 @@
#define EEPROM_MMU_LOAD_FAIL (EEPROM_MMU_LOAD_FAIL_TOT - 1) //uint8_t #define EEPROM_MMU_LOAD_FAIL (EEPROM_MMU_LOAD_FAIL_TOT - 1) //uint8_t
#define EEPROM_MMU_CUTTER_ENABLED (EEPROM_MMU_LOAD_FAIL - 1) #define EEPROM_MMU_CUTTER_ENABLED (EEPROM_MMU_LOAD_FAIL - 1)
#define EEPROM_UVLO_MESH_BED_LEVELING_FULL (EEPROM_MMU_CUTTER_ENABLED - 12*12*2) //allow 12 calibration points for future expansion #define EEPROM_UVLO_MESH_BED_LEVELING_FULL (EEPROM_MMU_CUTTER_ENABLED - 12*12*2) //allow 12 calibration points for future expansion
#define EEPROM_MBL_TYPE (EEPROM_UVLO_MESH_BED_LEVELING_FULL-1) //uint8_t for mesh bed leveling precision #define EEPROM_MBL_TYPE (EEPROM_UVLO_MESH_BED_LEVELING_FULL-1) //uint8_t for mesh bed leveling precision
#define EEPROM_MBL_MAGNET_ELIMINATION (EEPROM_MBL_TYPE -1) #define EEPROM_MBL_MAGNET_ELIMINATION (EEPROM_MBL_TYPE -1)
#define EEPROM_MBL_POINTS_NR (EEPROM_MBL_MAGNET_ELIMINATION -1) //uint8_t number of points in one exis for mesh bed leveling #define EEPROM_MBL_POINTS_NR (EEPROM_MBL_MAGNET_ELIMINATION -1) //uint8_t number of points in one exis for mesh bed leveling
#define EEPROM_MBL_PROBE_NR (EEPROM_MBL_POINTS_NR-1) //number of measurements for each point #define EEPROM_MBL_PROBE_NR (EEPROM_MBL_POINTS_NR-1) //number of measurements for each point
#define EEPROM_MMU_STEALTH (EEPROM_MBL_PROBE_NR-1) #define EEPROM_MMU_STEALTH (EEPROM_MBL_PROBE_NR-1)
#define EEPROM_CHECK_MODE (EEPROM_MMU_STEALTH-1) // uint8
#define EEPROM_NOZZLE_DIAMETER (EEPROM_CHECK_MODE-1) // uint8
#define EEPROM_NOZZLE_DIAMETER_uM (EEPROM_NOZZLE_DIAMETER-2) // uint16
// !!!!! // !!!!!
// !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!!
// !!!!! // !!!!!
@ -201,5 +208,11 @@
static M500_conf * const EEPROM_M500_base = reinterpret_cast<M500_conf*>(20); //offset for storing settings using M500 static M500_conf * const EEPROM_M500_base = reinterpret_cast<M500_conf*>(20); //offset for storing settings using M500
#endif #endif
enum
{
EEPROM_MMU_CUTTER_ENABLED_enabled = 1,
EEPROM_MMU_CUTTER_ENABLED_always = 2,
};
#endif // EEPROM_H #endif // EEPROM_H

214
Firmware/first_lay_cal.cpp Normal file
View File

@ -0,0 +1,214 @@
//! @file
//! @date Jun 10, 2019
//! @author Marek Bel
//! @brief First layer (Z offset) calibration
#include "first_lay_cal.h"
#include "Configuration_prusa.h"
#include "language.h"
#include "Marlin.h"
#include "mmu.h"
#include <avr/pgmspace.h>
//! @brief Preheat
void lay1cal_preheat()
{
static const char cmd_preheat_0[] PROGMEM = "M107";
static const char cmd_preheat_1[] PROGMEM = "M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP);
static const char cmd_preheat_2[] PROGMEM = "M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP);
static const char cmd_preheat_3[] PROGMEM = "M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP);
static const char cmd_preheat_4[] PROGMEM = "M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP);
static const char cmd_preheat_5[] PROGMEM = "G28";
static const char cmd_preheat_6[] PROGMEM = "G92 E0.0";
static const char * const preheat_cmd[] PROGMEM =
{
cmd_preheat_0,
cmd_preheat_1,
cmd_preheat_2,
cmd_preheat_3,
cmd_preheat_4,
cmd_preheat_5, //call MSG_M117_V2_CALIBRATION before
cmd_preheat_6,
};
for (uint8_t i = 0; i < (sizeof(preheat_cmd)/sizeof(preheat_cmd[0])); ++i)
{
if (5 == i) enquecommand_P(_T(MSG_M117_V2_CALIBRATION));
enquecommand_P(static_cast<char*>(pgm_read_ptr(&preheat_cmd[i])));
}
}
//! @brief Print intro line
//! @param cmd_buffer character buffer needed to format gcodes
//! @param filament filament to use (applies for MMU only)
void lay1cal_intro_line(char *cmd_buffer, uint8_t filament)
{
static const char cmd_intro_mmu_0[] PROGMEM = "M83";
static const char cmd_intro_mmu_1[] PROGMEM = "G1 Y-3.0 F1000.0";
static const char cmd_intro_mmu_2[] PROGMEM = "G1 Z0.4 F1000.0";
static const char cmd_intro_mmu_3[] PROGMEM = "G1 X55.0 E32.0 F1073.0"; // call T code before
static const char cmd_intro_mmu_4[] PROGMEM = "G1 X5.0 E32.0 F1800.0";
static const char cmd_intro_mmu_5[] PROGMEM = "G1 X55.0 E8.0 F2000.0";
static const char cmd_intro_mmu_6[] PROGMEM = "G1 Z0.3 F1000.0";
static const char cmd_intro_mmu_7[] PROGMEM = "G92 E0.0";
static const char cmd_intro_mmu_8[] PROGMEM = "G1 X240.0 E25.0 F2200.0";
static const char cmd_intro_mmu_9[] PROGMEM = "G1 Y-2.0 F1000.0";
static const char cmd_intro_mmu_10[] PROGMEM = "G1 X55.0 E25 F1400.0";
static const char cmd_intro_mmu_11[] PROGMEM = "G1 Z0.20 F1000.0";
static const char cmd_intro_mmu_12[] PROGMEM = "G1 X5.0 E4.0 F1000.0";
static const char * const intro_mmu_cmd[] PROGMEM =
{
cmd_intro_mmu_0,
cmd_intro_mmu_1,
cmd_intro_mmu_2,
cmd_intro_mmu_3, // call T code before
cmd_intro_mmu_4,
cmd_intro_mmu_5,
cmd_intro_mmu_6,
cmd_intro_mmu_7,
cmd_intro_mmu_8,
cmd_intro_mmu_9,
cmd_intro_mmu_10,
cmd_intro_mmu_11,
cmd_intro_mmu_12,
};
if (mmu_enabled)
{
for (uint8_t i = 0; i < (sizeof(intro_mmu_cmd)/sizeof(intro_mmu_cmd[0])); ++i)
{
if (3 == i)
{
sprintf_P(cmd_buffer, PSTR("T%d"), filament);
enquecommand(cmd_buffer);
}
enquecommand_P(static_cast<char*>(pgm_read_ptr(&intro_mmu_cmd[i])));
}
}
else
{
enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0"));
enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0"));
}
}
//! @brief Setup for printing meander
void lay1cal_before_meander()
{
static const char cmd_pre_meander_0[] PROGMEM = "G92 E0.0";
static const char cmd_pre_meander_1[] PROGMEM = "G21"; //set units to millimeters TODO unsupported command
static const char cmd_pre_meander_2[] PROGMEM = "G90"; //use absolute coordinates
static const char cmd_pre_meander_3[] PROGMEM = "M83"; //use relative distances for extrusion TODO: duplicate
static const char cmd_pre_meander_4[] PROGMEM = "G1 E-1.50000 F2100.00000";
static const char cmd_pre_meander_5[] PROGMEM = "G1 Z5 F7200.000";
static const char cmd_pre_meander_6[] PROGMEM = "M204 S1000"; //set acceleration
static const char cmd_pre_meander_7[] PROGMEM = "G1 F4000";
static const char * const cmd_pre_meander[] PROGMEM =
{
cmd_pre_meander_0,
cmd_pre_meander_1,
cmd_pre_meander_2,
cmd_pre_meander_3,
cmd_pre_meander_4,
cmd_pre_meander_5,
cmd_pre_meander_6,
cmd_pre_meander_7,
};
for (uint8_t i = 0; i < (sizeof(cmd_pre_meander)/sizeof(cmd_pre_meander[0])); ++i)
{
enquecommand_P(static_cast<char*>(pgm_read_ptr(&cmd_pre_meander[i])));
}
}
//! @brief Count extrude length
//!
//! @param layer_height layer height in mm
//! @param extrusion_width extrusion width in mm
//! @param extrusion_length extrusion length in mm
//! @return filament length in mm which needs to be extruded to form line
static constexpr float count_e(float layer_height, float extrusion_width, float extrusion_length)
{
return (extrusion_length * layer_height * extrusion_width / (M_PI * pow(1.75, 2) / 4));
}
static const float width = 0.4; //!< line width
static const float length = 20 - width; //!< line length
static const float height = 0.2; //!< layer height TODO This is wrong, as current Z height is 0.15 mm
static const float extr = count_e(height, width, length); //!< E axis movement needed to print line
//! @brief Print meander
//! @param cmd_buffer character buffer needed to format gcodes
void lay1cal_meander(char *cmd_buffer)
{
static const char cmd_meander_0[] PROGMEM = "G1 X50 Y155";
static const char cmd_meander_1[] PROGMEM = "G1 Z0.150 F7200.000";
static const char cmd_meander_2[] PROGMEM = "G1 F1080";
static const char cmd_meander_3[] PROGMEM = "G1 X75 Y155 E2.5";
static const char cmd_meander_4[] PROGMEM = "G1 X100 Y155 E2";
static const char cmd_meander_5[] PROGMEM = "G1 X200 Y155 E2.62773";
static const char cmd_meander_6[] PROGMEM = "G1 X200 Y135 E0.66174";
static const char cmd_meander_7[] PROGMEM = "G1 X50 Y135 E3.62773";
static const char cmd_meander_8[] PROGMEM = "G1 X50 Y115 E0.49386";
static const char cmd_meander_9[] PROGMEM = "G1 X200 Y115 E3.62773";
static const char cmd_meander_10[] PROGMEM = "G1 X200 Y95 E0.49386";
static const char cmd_meander_11[] PROGMEM = "G1 X50 Y95 E3.62773";
static const char cmd_meander_12[] PROGMEM = "G1 X50 Y75 E0.49386";
static const char cmd_meander_13[] PROGMEM = "G1 X200 Y75 E3.62773";
static const char cmd_meander_14[] PROGMEM = "G1 X200 Y55 E0.49386";
static const char cmd_meander_15[] PROGMEM = "G1 X50 Y55 E3.62773";
static const char * const cmd_meander[] PROGMEM =
{
cmd_meander_0,
cmd_meander_1,
cmd_meander_2,
cmd_meander_3,
cmd_meander_4,
cmd_meander_5,
cmd_meander_6,
cmd_meander_7,
cmd_meander_8,
cmd_meander_9,
cmd_meander_10,
cmd_meander_11,
cmd_meander_12,
cmd_meander_13,
cmd_meander_14,
cmd_meander_15,
};
for (uint8_t i = 0; i < (sizeof(cmd_meander)/sizeof(cmd_meander[0])); ++i)
{
enquecommand_P(static_cast<char*>(pgm_read_ptr(&cmd_meander[i])));
}
sprintf_P(cmd_buffer, PSTR("G1 X50 Y35 E%-.3f"), extr);
enquecommand(cmd_buffer);
}
//! @brief Print square
//!
//! This function needs to be called 16 times for i from 0 to 15.
//!
//! @param cmd_buffer character buffer needed to format gcodes
//! @param i iteration
void lay1cal_square(char *cmd_buffer, uint8_t i)
{
const float extr_short_segment = count_e(height, width, width);
static const char fmt1[] PROGMEM = "G1 X%d Y%-.2f E%-.3f";
static const char fmt2[] PROGMEM = "G1 Y%-.2f E%-.3f";
sprintf_P(cmd_buffer, fmt1, 70, (35 - i*width * 2), extr);
enquecommand(cmd_buffer);
sprintf_P(cmd_buffer, fmt2, (35 - (2 * i + 1)*width), extr_short_segment);
enquecommand(cmd_buffer);
sprintf_P(cmd_buffer, fmt1, 50, (35 - (2 * i + 1)*width), extr);
enquecommand(cmd_buffer);
sprintf_P(cmd_buffer, fmt2, (35 - (i + 1)*width * 2), extr_short_segment);
enquecommand(cmd_buffer);
}

15
Firmware/first_lay_cal.h Normal file
View File

@ -0,0 +1,15 @@
//! @file
//! @date Jun 10, 2019
//! @author Marek Bel
#ifndef FIRMWARE_FIRST_LAY_CAL_H_
#define FIRMWARE_FIRST_LAY_CAL_H_
#include <stdint.h>
void lay1cal_preheat();
void lay1cal_intro_line(char *cmd_buffer, uint8_t filament);
void lay1cal_before_meander();
void lay1cal_meander(char *cmd_buffer);
void lay1cal_square(char *cmd_buffer, uint8_t i);
#endif /* FIRMWARE_FIRST_LAY_CAL_H_ */

67
Firmware/fsensor.cpp Normal file → Executable file
View File

@ -57,6 +57,11 @@ bool fsensor_not_responding = false;
bool fsensor_printing_saved = false; bool fsensor_printing_saved = false;
//! enable/disable quality meassurement //! enable/disable quality meassurement
bool fsensor_oq_meassure_enabled = false; bool fsensor_oq_meassure_enabled = false;
//! as explained in the CHECK_FSENSOR macro: this flag is set to true when fsensor posts
//! the M600 into the command queue, which elliminates the hazard of having posted multiple M600's
//! before the first one gets read and started processing.
//! Btw., the IR fsensor could do up to 6 posts before the command queue managed to start processing the first M600 ;)
static bool fsensor_m600_enqueued = false;
//! number of errors, updated in ISR //! number of errors, updated in ISR
uint8_t fsensor_err_cnt = 0; uint8_t fsensor_err_cnt = 0;
@ -123,6 +128,7 @@ void fsensor_restore_print_and_continue(void)
printf_P(PSTR("fsensor_restore_print_and_continue\n")); printf_P(PSTR("fsensor_restore_print_and_continue\n"));
fsensor_watch_runout = true; fsensor_watch_runout = true;
fsensor_err_cnt = 0; fsensor_err_cnt = 0;
fsensor_m600_enqueued = false;
restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change
} }
@ -516,6 +522,47 @@ void fsensor_st_block_chunk(block_t* bl, int cnt)
} }
} }
//! This ensures generating z-position at least 25mm above the heat bed.
//! Making this a template enables changing the computation data type easily at all spots where necessary.
//! @param current_z current z-position
//! @return z-position at least 25mm above the heat bed plus FILAMENTCHANGE_ZADD
template <typename T>
inline T fsensor_clamp_z(float current_z){
T z( current_z );
if(z < T(25)){ // make sure the compiler understands, that the constant 25 is of correct type
// - necessary for uint8_t -> results in shorter code
z = T(25); // move to at least 25mm above heat bed
}
return z + T(FILAMENTCHANGE_ZADD); // always move above the printout by FILAMENTCHANGE_ZADD (default 2mm)
}
//! Common code for enqueing M600 and supplemental codes into the command queue.
//! Used both for the IR sensor and the PAT9125
void fsensor_enque_M600(){
printf_P(PSTR("fsensor_update - M600\n"));
eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1);
eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1);
enquecommand_front_P(PSTR("PRUSA fsensor_recover"));
fsensor_m600_enqueued = true;
enquecommand_front_P((PSTR("M600")));
#define xstr(a) str(a)
#define str(a) #a
static const char gcodeMove[] PROGMEM =
"G1 X" xstr(FILAMENTCHANGE_XPOS)
" Y" xstr(FILAMENTCHANGE_YPOS)
" Z%u";
#undef str
#undef xstr
char buf[32];
// integer arithmetics is far shorter, I don't need a precise float position here, just move a bit above
// 8bit arithmetics in fsensor_clamp_z is 10B shorter than 16bit (not talking about float ;) )
// The compile-time static_assert here ensures, that the computation gets enough bits in case of Z-range too high,
// i.e. makes the user change the data type, which also results in larger code
static_assert(Z_MAX_POS < (255 - FILAMENTCHANGE_ZADD), "Z-range too high, change fsensor_clamp_z<uint8_t> to <uint16_t>");
sprintf_P(buf, gcodeMove, fsensor_clamp_z<uint8_t>(current_position[Z_AXIS]) );
enquecommand_front(buf, false);
}
//! @brief filament sensor update (perform M600 on filament runout) //! @brief filament sensor update (perform M600 on filament runout)
//! //!
//! Works only if filament sensor is enabled. //! Works only if filament sensor is enabled.
@ -524,7 +571,7 @@ void fsensor_st_block_chunk(block_t* bl, int cnt)
void fsensor_update(void) void fsensor_update(void)
{ {
#ifdef PAT9125 #ifdef PAT9125
if (fsensor_enabled && fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX)) if (fsensor_enabled && fsensor_watch_runout && (fsensor_err_cnt > FSENSOR_ERR_MAX) && ( ! fsensor_m600_enqueued) )
{ {
bool autoload_enabled_tmp = fsensor_autoload_enabled; bool autoload_enabled_tmp = fsensor_autoload_enabled;
fsensor_autoload_enabled = false; fsensor_autoload_enabled = false;
@ -564,25 +611,17 @@ void fsensor_update(void)
} }
else else
{ {
printf_P(PSTR("fsensor_update - M600\n")); fsensor_enque_M600();
eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1);
eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1);
enquecommand_front_P(PSTR("PRUSA fsensor_recover"));
enquecommand_front_P((PSTR("M600")));
fsensor_watch_runout = false; fsensor_watch_runout = false;
} }
fsensor_autoload_enabled = autoload_enabled_tmp; fsensor_autoload_enabled = autoload_enabled_tmp;
fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp; fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp;
} }
#else //PAT9125 #else //PAT9125
if ((digitalRead(IR_SENSOR_PIN) == 1) && CHECK_FSENSOR && fsensor_enabled && ir_sensor_detected) if ((digitalRead(IR_SENSOR_PIN) == 1) && CHECK_FSENSOR && fsensor_enabled && ir_sensor_detected && ( ! fsensor_m600_enqueued) )
{ {
fsensor_stop_and_save_print(); fsensor_stop_and_save_print();
printf_P(PSTR("fsensor_update - M600\n")); fsensor_enque_M600();
eeprom_update_byte((uint8_t*)EEPROM_FERROR_COUNT, eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) + 1);
eeprom_update_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) + 1);
enquecommand_front_P(PSTR("PRUSA fsensor_recover"));
enquecommand_front_P((PSTR("M600")));
} }
#endif //PAT9125 #endif //PAT9125
} }

1
Firmware/fsensor.h Normal file → Executable file
View File

@ -18,6 +18,7 @@ extern bool fsensor_oq_meassure_enabled;
//! @name save restore printing //! @name save restore printing
//! @{ //! @{
extern void fsensor_stop_and_save_print(void); extern void fsensor_stop_and_save_print(void);
//! restore print - restore position and heatup to original temperature
extern void fsensor_restore_print_and_continue(void); extern void fsensor_restore_print_and_continue(void);
//! @} //! @}

View File

@ -25,7 +25,7 @@ uint8_t menu_data[MENU_DATA_SIZE];
#endif #endif
uint8_t menu_depth = 0; uint8_t menu_depth = 0;
uint8_t menu_block_entering_on_serious_errors = SERIOUS_ERR_NONE;
uint8_t menu_line = 0; uint8_t menu_line = 0;
uint8_t menu_item = 0; uint8_t menu_item = 0;
uint8_t menu_row = 0; uint8_t menu_row = 0;

View File

@ -28,6 +28,27 @@ extern uint8_t menu_data[MENU_DATA_SIZE];
extern uint8_t menu_depth; extern uint8_t menu_depth;
//! definition of serious errors possibly blocking the main menu
//! Use them as bit mask, so that the code may set various errors at the same time
enum ESeriousErrors {
SERIOUS_ERR_NONE = 0,
SERIOUS_ERR_MINTEMP_HEATER = 0x01,
SERIOUS_ERR_MINTEMP_BED = 0x02
}; // and possibly others in the future.
//! this is a flag for disabling entering the main menu. If this is set
//! to anything != 0, the only the main status screen will be shown on the
//! LCD and the user will be prevented from entering the menu.
//! Now used only to block doing anything with the printer when there is
//! the infamous MINTEMP error (SERIOUS_ERR_MINTEMP).
extern uint8_t menu_block_entering_on_serious_errors;
//! a pair of macros for manipulating the serious errors
//! a c++ class would have been better
#define menu_set_serious_error(x) menu_block_entering_on_serious_errors |= x;
#define menu_unset_serious_error(x) menu_block_entering_on_serious_errors &= ~x;
#define menu_is_serious_error(x) (menu_block_entering_on_serious_errors & x) != 0
extern uint8_t menu_line; extern uint8_t menu_line;
extern uint8_t menu_item; extern uint8_t menu_item;
extern uint8_t menu_row; extern uint8_t menu_row;

24
Firmware/mmu.cpp Normal file → Executable file
View File

@ -1076,7 +1076,7 @@ if(0)
extr_unload(); extr_unload();
} }
else { else {
eFilamentAction=e_FILAMENT_ACTION_mmuUnLoad; eFilamentAction=FilamentAction::MmuUnLoad;
bFilamentFirstRun=false; bFilamentFirstRun=false;
if(target_temperature[0]>=EXTRUDE_MINTEMP) if(target_temperature[0]>=EXTRUDE_MINTEMP)
{ {
@ -1372,13 +1372,13 @@ void lcd_mmu_load_to_nozzle(uint8_t filament_nr)
mmu_load_to_nozzle(); mmu_load_to_nozzle();
load_filament_final_feed(); load_filament_final_feed();
st_synchronize(); st_synchronize();
custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; custom_message_type = CustomMsg::FilamentLoading;
lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT)); lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
lcd_return_to_status(); lcd_return_to_status();
lcd_update_enable(true); lcd_update_enable(true);
lcd_load_filament_color_check(); lcd_load_filament_color_check();
lcd_setstatuspgm(_T(WELCOME_MSG)); lcd_setstatuspgm(_T(WELCOME_MSG));
custom_message_type = CUSTOM_MSG_TYPE_STATUS; custom_message_type = CustomMsg::Status;
} }
else else
{ {
@ -1511,20 +1511,20 @@ void mmu_continue_loading(bool blocking)
enum class Ls : uint_least8_t enum class Ls : uint_least8_t
{ {
enter, Enter,
retry, Retry,
unload, Unload,
}; };
Ls state = Ls::enter; Ls state = Ls::Enter;
while (PIN_GET(IR_SENSOR_PIN) != 0) while (PIN_GET(IR_SENSOR_PIN) != 0)
{ {
switch (state) switch (state)
{ {
case Ls::enter: case Ls::Enter:
increment_load_fail(); increment_load_fail();
// no break // no break
case Ls::retry: case Ls::Retry:
#ifdef MMU_HAS_CUTTER #ifdef MMU_HAS_CUTTER
if (1 == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED)) if (1 == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED))
{ {
@ -1535,9 +1535,9 @@ void mmu_continue_loading(bool blocking)
mmu_command(MmuCmd::T0 + tmp_extruder); mmu_command(MmuCmd::T0 + tmp_extruder);
manage_response(true, true, MMU_TCODE_MOVE); manage_response(true, true, MMU_TCODE_MOVE);
load_more(); load_more();
state = Ls::unload; state = Ls::Unload;
break; break;
case Ls::unload: case Ls::Unload:
stop_and_save_print_to_ram(0, 0); stop_and_save_print_to_ram(0, 0);
//lift z //lift z
@ -1562,7 +1562,7 @@ void mmu_continue_loading(bool blocking)
{ {
marlin_wait_for_click(); marlin_wait_for_click();
restore_print_from_ram_and_continue(0); restore_print_from_ram_and_continue(0);
state = Ls::retry; state = Ls::Retry;
} }
else else
{ {

0
Firmware/pins_Einsy_1_0.h Normal file → Executable file
View File

View File

@ -95,7 +95,7 @@ float current_temperature_bed = 0.0;
#endif #endif
#ifdef FANCHECK #ifdef FANCHECK
volatile bool fan_check_error = false; volatile uint8_t fan_check_error = EFCE_OK;
#endif #endif
unsigned char soft_pwm_bed; unsigned char soft_pwm_bed;
@ -434,7 +434,7 @@ static void temp_runaway_stop(bool isPreheat, bool isBed);
void updatePID() void updatePID()
{ {
#ifdef PIDTEMP #ifdef PIDTEMP
for(int e = 0; e < EXTRUDERS; e++) { for(uint_least8_t e = 0; e < EXTRUDERS; e++) {
iState_sum_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki; iState_sum_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki;
} }
#endif #endif
@ -512,6 +512,12 @@ void checkFanSpeed()
else fan_speed_errors[1] = 0; else fan_speed_errors[1] = 0;
#endif #endif
// drop the fan_check_error flag when both fans are ok
if( fan_speed_errors[0] == 0 && fan_speed_errors[1] == 0 && fan_check_error == EFCE_REPORTED){
// we may even send some info to the LCD from here
fan_check_error = EFCE_OK;
}
if ((fan_speed_errors[0] > max_extruder_fan_errors) && fans_check_enabled) { if ((fan_speed_errors[0] > max_extruder_fan_errors) && fans_check_enabled) {
fan_speed_errors[0] = 0; fan_speed_errors[0] = 0;
fanSpeedError(0); //extruder fan fanSpeedError(0); //extruder fan
@ -522,6 +528,18 @@ void checkFanSpeed()
} }
} }
//! Prints serialMsg to serial port, displays lcdMsg onto the LCD and beeps.
//! Extracted from fanSpeedError to save some space.
//! @param serialMsg pointer into PROGMEM, this text will be printed to the serial port
//! @param lcdMsg pointer into PROGMEM, this text will be printed onto the LCD
static void fanSpeedErrorBeep(const char *serialMsg, const char *lcdMsg){
SERIAL_ECHOLNRPGM(serialMsg);
if (get_message_level() == 0) {
Sound_MakeCustom(200,0,true);
LCD_ALERTMESSAGERPGM(lcdMsg);
}
}
void fanSpeedError(unsigned char _fan) { void fanSpeedError(unsigned char _fan) {
if (get_message_level() != 0 && isPrintPaused) return; if (get_message_level() != 0 && isPrintPaused) return;
//to ensure that target temp. is not set to zero in case taht we are resuming print //to ensure that target temp. is not set to zero in case taht we are resuming print
@ -530,7 +548,8 @@ void fanSpeedError(unsigned char _fan) {
lcd_print_stop(); lcd_print_stop();
} }
else { else {
fan_check_error = true; fan_check_error = EFCE_DETECTED;
} }
} }
else { else {
@ -538,19 +557,11 @@ void fanSpeedError(unsigned char _fan) {
SERIAL_ECHOLNPGM("// action:pause"); //for octoprint SERIAL_ECHOLNPGM("// action:pause"); //for octoprint
} }
switch (_fan) { switch (_fan) {
case 0: case 0: // extracting the same code from case 0 and case 1 into a function saves 72B
SERIAL_ECHOLNPGM("Extruder fan speed is lower then expected"); fanSpeedErrorBeep(PSTR("Extruder fan speed is lower than expected"), PSTR("Err: EXTR. FAN ERROR") );
if (get_message_level() == 0) {
Sound_MakeCustom(200,0,true);
LCD_ALERTMESSAGEPGM("Err: EXTR. FAN ERROR");
}
break; break;
case 1: case 1:
SERIAL_ECHOLNPGM("Print fan speed is lower then expected"); fanSpeedErrorBeep(PSTR("Print fan speed is lower than expected"), PSTR("Err: PRINT FAN ERROR") );
if (get_message_level() == 0) {
Sound_MakeCustom(200,0,true);
LCD_ALERTMESSAGEPGM("Err: PRINT FAN ERROR");
}
break; break;
} }
} }
@ -1457,6 +1468,15 @@ void disable_heater()
#endif #endif
#endif #endif
} }
//! codes of alert messages for the LCD - it is shorter to compare an uin8_t
//! than raw const char * of the messages themselves.
//! Could be used for MAXTEMP situations too - after reaching MAXTEMP and turning off the heater automagically
//! the heater/bed may cool down and a similar alert message like "MAXTERM fixed..." may be displayed.
enum { LCDALERT_NONE = 0, LCDALERT_HEATERMINTEMP, LCDALERT_BEDMINTEMP, LCDALERT_MINTEMPFIXED, LCDALERT_PLEASERESTART };
//! remember the last alert message sent to the LCD
//! to prevent flicker and improve speed
uint8_t last_alert_sent_to_lcd = LCDALERT_NONE;
void max_temp_error(uint8_t e) { void max_temp_error(uint8_t e) {
disable_heater(); disable_heater();
@ -1489,13 +1509,23 @@ void min_temp_error(uint8_t e) {
#endif #endif
//if (current_temperature_ambient < MINTEMP_MINAMBIENT) return; //if (current_temperature_ambient < MINTEMP_MINAMBIENT) return;
disable_heater(); disable_heater();
static const char err[] PROGMEM = "Err: MINTEMP";
if(IsStopped() == false) { if(IsStopped() == false) {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLN((int)e); SERIAL_ERRORLN((int)e);
SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !"); SERIAL_ERRORLNPGM(": Extruder switched off. MINTEMP triggered !");
LCD_ALERTMESSAGEPGM("Err: MINTEMP"); lcd_setalertstatuspgm(err);
last_alert_sent_to_lcd = LCDALERT_HEATERMINTEMP;
} else if( last_alert_sent_to_lcd != LCDALERT_HEATERMINTEMP ){ // only update, if the lcd message is to be changed (i.e. not the same as last time)
// we are already stopped due to some error, only update the status message without flickering
lcd_updatestatuspgm(err);
last_alert_sent_to_lcd = LCDALERT_HEATERMINTEMP;
} }
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
// if( last_alert_sent_to_lcd != LCDALERT_HEATERMINTEMP ){
// last_alert_sent_to_lcd = LCDALERT_HEATERMINTEMP;
// lcd_print_stop();
// }
Stop(); Stop();
#endif #endif
if (farm_mode) { prusa_statistics(92); } if (farm_mode) { prusa_statistics(92); }
@ -1525,10 +1555,16 @@ void bed_min_temp_error(void) {
#if HEATER_BED_PIN > -1 #if HEATER_BED_PIN > -1
WRITE(HEATER_BED_PIN, 0); WRITE(HEATER_BED_PIN, 0);
#endif #endif
static const char err[] PROGMEM = "Err: MINTEMP BED";
if(IsStopped() == false) { if(IsStopped() == false) {
SERIAL_ERROR_START; SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Temperature heated bed switched off. MINTEMP triggered !"); SERIAL_ERRORLNPGM("Temperature heated bed switched off. MINTEMP triggered !");
LCD_ALERTMESSAGEPGM("Err: MINTEMP BED"); lcd_setalertstatuspgm(err);
last_alert_sent_to_lcd = LCDALERT_BEDMINTEMP;
} else if( last_alert_sent_to_lcd != LCDALERT_BEDMINTEMP ){ // only update, if the lcd message is to be changed (i.e. not the same as last time)
// we are already stopped due to some error, only update the status message without flickering
lcd_updatestatuspgm(err);
last_alert_sent_to_lcd = LCDALERT_BEDMINTEMP;
} }
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE #ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
Stop(); Stop();
@ -2002,6 +2038,58 @@ void check_max_temp()
#endif #endif
} }
//! number of repeating the same state with consecutive step() calls
//! used to slow down text switching
struct alert_automaton_mintemp {
private:
enum { ALERT_AUTOMATON_SPEED_DIV = 5 };
enum class States : uint8_t { Init = 0, TempAboveMintemp, ShowPleaseRestart, ShowMintemp };
States state = States::Init;
uint8_t repeat = ALERT_AUTOMATON_SPEED_DIV;
void substep(States next_state){
if( repeat == 0 ){
state = next_state; // advance to the next state
repeat = ALERT_AUTOMATON_SPEED_DIV; // and prepare repeating for it too
} else {
--repeat;
}
}
public:
//! brief state automaton step routine
//! @param current_temp current hotend/bed temperature (for computing simple hysteresis)
//! @param mintemp minimal temperature including hysteresis to check current_temp against
void step(float current_temp, float mintemp){
static const char m2[] PROGMEM = "MINTEMP fixed";
static const char m1[] PROGMEM = "Please restart";
switch(state){
case States::Init: // initial state - check hysteresis
if( current_temp > mintemp ){
state = States::TempAboveMintemp;
}
// otherwise keep the Err MINTEMP alert message on the display,
// i.e. do not transfer to state 1
break;
case States::TempAboveMintemp: // the temperature has risen above the hysteresis check
lcd_setalertstatuspgm(m2);
substep(States::ShowMintemp);
last_alert_sent_to_lcd = LCDALERT_MINTEMPFIXED;
break;
case States::ShowPleaseRestart: // displaying "Please restart"
lcd_updatestatuspgm(m1);
substep(States::ShowMintemp);
last_alert_sent_to_lcd = LCDALERT_PLEASERESTART;
break;
case States::ShowMintemp: // displaying "MINTEMP fixed"
lcd_updatestatuspgm(m2);
substep(States::ShowPleaseRestart);
last_alert_sent_to_lcd = LCDALERT_MINTEMPFIXED;
break;
}
}
};
static alert_automaton_mintemp alert_automaton_hotend, alert_automaton_bed;
void check_min_temp_heater0() void check_min_temp_heater0()
{ {
@ -2011,7 +2099,17 @@ void check_min_temp_heater0()
#else #else
if (current_temperature_raw[0] <= minttemp_raw[0]) { if (current_temperature_raw[0] <= minttemp_raw[0]) {
#endif #endif
menu_set_serious_error(SERIOUS_ERR_MINTEMP_HEATER);
min_temp_error(0); min_temp_error(0);
} else if( menu_is_serious_error(SERIOUS_ERR_MINTEMP_HEATER) ) {
// no recovery, just force the user to restart the printer
// which is a safer variant than just continuing printing
// The automaton also checks for hysteresis - the temperature must have reached a few degrees above the MINTEMP, before
// we shall signalize, that MINTEMP has been fixed
// Code notice: normally the alert_automaton instance would have been placed here
// as static alert_automaton_mintemp alert_automaton_hotend, but
// due to stupid compiler that takes 16 more bytes.
alert_automaton_hotend.step(current_temperature[0], minttemp[0] + TEMP_HYSTERESIS);
} }
} }
@ -2022,7 +2120,12 @@ void check_min_temp_bed()
#else #else
if (current_temperature_bed_raw <= bed_minttemp_raw) { if (current_temperature_bed_raw <= bed_minttemp_raw) {
#endif #endif
menu_set_serious_error(SERIOUS_ERR_MINTEMP_BED);
bed_min_temp_error(); bed_min_temp_error();
} else if( menu_is_serious_error(SERIOUS_ERR_MINTEMP_BED) ){
// no recovery, just force the user to restart the printer
// which is a safer variant than just continuing printing
alert_automaton_bed.step(current_temperature_bed, BED_MINTEMP + TEMP_HYSTERESIS);
} }
} }

7
Firmware/temperature.h Normal file → Executable file
View File

@ -238,7 +238,12 @@ void checkExtruderAutoFans();
#if (defined(FANCHECK) && defined(TACH_0) && (TACH_0 > -1)) #if (defined(FANCHECK) && defined(TACH_0) && (TACH_0 > -1))
extern volatile bool fan_check_error; enum {
EFCE_OK = 0, //!< normal operation, both fans are ok
EFCE_DETECTED, //!< fan error detected, but not reported yet
EFCE_REPORTED //!< fan error detected and reported to LCD and serial
};
extern volatile uint8_t fan_check_error;
void countFanSpeed(); void countFanSpeed();
void checkFanSpeed(); void checkFanSpeed();

10
Firmware/tmc2130.cpp Normal file → Executable file
View File

@ -158,7 +158,7 @@ void tmc2130_init()
SET_INPUT(Y_TMC2130_DIAG); SET_INPUT(Y_TMC2130_DIAG);
SET_INPUT(Z_TMC2130_DIAG); SET_INPUT(Z_TMC2130_DIAG);
SET_INPUT(E0_TMC2130_DIAG); SET_INPUT(E0_TMC2130_DIAG);
for (int axis = 0; axis < 2; axis++) // X Y axes for (uint_least8_t axis = 0; axis < 2; axis++) // X Y axes
{ {
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000);
@ -169,7 +169,7 @@ void tmc2130_init()
tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS); tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS);
//tmc2130_wr_THIGH(axis, TMC2130_THIGH); //tmc2130_wr_THIGH(axis, TMC2130_THIGH);
} }
for (int axis = 2; axis < 3; axis++) // Z axis for (uint_least8_t axis = 2; axis < 3; axis++) // Z axis
{ {
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000);
@ -183,7 +183,7 @@ void tmc2130_init()
tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS); tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS);
#endif //TMC2130_STEALTH_Z #endif //TMC2130_STEALTH_Z
} }
for (int axis = 3; axis < 4; axis++) // E axis for (uint_least8_t axis = 3; axis < 4; axis++) // E axis
{ {
tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]);
tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000);
@ -383,7 +383,7 @@ void tmc2130_check_overtemp()
static uint32_t checktime = 0; static uint32_t checktime = 0;
if (_millis() - checktime > 1000 ) if (_millis() - checktime > 1000 )
{ {
for (int i = 0; i < 4; i++) for (uint_least8_t i = 0; i < 4; i++)
{ {
uint32_t drv_status = 0; uint32_t drv_status = 0;
skip_debug_msg = true; skip_debug_msg = true;
@ -392,7 +392,7 @@ void tmc2130_check_overtemp()
{ // BIT 26 - over temp prewarning ~120C (+-20C) { // BIT 26 - over temp prewarning ~120C (+-20C)
SERIAL_ERRORRPGM(MSG_TMC_OVERTEMP); SERIAL_ERRORRPGM(MSG_TMC_OVERTEMP);
SERIAL_ECHOLN(i); SERIAL_ECHOLN(i);
for (int j = 0; j < 4; j++) for (uint_least8_t j = 0; j < 4; j++)
tmc2130_wr(j, TMC2130_REG_CHOPCONF, 0x00010000); tmc2130_wr(j, TMC2130_REG_CHOPCONF, 0x00010000);
kill(MSG_TMC_OVERTEMP); kill(MSG_TMC_OVERTEMP);
} }

File diff suppressed because it is too large Load Diff

70
Firmware/ultralcd.h Normal file → Executable file
View File

@ -18,7 +18,16 @@ extern void menu_lcd_lcdupdate_func(void);
void ultralcd_init(); void ultralcd_init();
void lcd_setstatus(const char* message); void lcd_setstatus(const char* message);
void lcd_setstatuspgm(const char* message); void lcd_setstatuspgm(const char* message);
//! return to the main status screen and display the alert message
//! Beware - it has sideeffects:
//! - always returns the display to the main status screen
//! - always makes lcd_reset (which is slow and causes flicker)
//! - does not update the message if there is already one (i.e. lcd_status_message_level > 0)
void lcd_setalertstatuspgm(const char* message); void lcd_setalertstatuspgm(const char* message);
//! only update the alert message on the main status screen
//! has no sideeffects, may be called multiple times
void lcd_updatestatuspgm(const char *message);
void lcd_reset_alert_level(); void lcd_reset_alert_level();
uint8_t get_message_level(); uint8_t get_message_level();
void lcd_adjust_z(); void lcd_adjust_z();
@ -80,31 +89,37 @@ extern void lcd_diag_show_end_stops();
// To be used in lcd_commands_type. // To be used in lcd_commands_type.
#define LCD_COMMAND_IDLE 0 enum class LcdCommands : uint_least8_t
#define LCD_COMMAND_LOAD_FILAMENT 1 {
#define LCD_COMMAND_STOP_PRINT 2 Idle,
#define LCD_COMMAND_FARM_MODE_CONFIRM 4 LoadFilament,
#define LCD_COMMAND_LONG_PAUSE 5 StopPrint,
#define LCD_COMMAND_PID_EXTRUDER 7 FarmModeConfirm,
#define LCD_COMMAND_V2_CAL 8 LongPause,
PidExtruder,
Layer1Cal,
};
extern int lcd_commands_type; extern LcdCommands lcd_commands_type;
extern int8_t FSensorStateMenu; extern int8_t FSensorStateMenu;
#define CUSTOM_MSG_TYPE_STATUS 0 // status message from lcd_status_message variable enum class CustomMsg : uint_least8_t
#define CUSTOM_MSG_TYPE_MESHBL 1 // Mesh bed leveling in progress {
#define CUSTOM_MSG_TYPE_F_LOAD 2 // Loading filament in progress Status, //!< status message from lcd_status_message variable
#define CUSTOM_MSG_TYPE_PIDCAL 3 // PID tuning in progress MeshBedLeveling, //!< Mesh bed leveling in progress
#define CUSTOM_MSG_TYPE_TEMCAL 4 // PINDA temp calibration FilamentLoading, //!< Loading filament in progress
#define CUSTOM_MSG_TYPE_TEMPRE 5 // Temp compensation preheat PidCal, //!< PID tuning in progress
TempCal, //!< PINDA temperature calibration
TempCompPreheat, //!< Temperature compensation preheat
};
extern unsigned int custom_message_type; extern CustomMsg custom_message_type;
extern unsigned int custom_message_state; extern unsigned int custom_message_state;
extern uint8_t farm_mode; extern uint8_t farm_mode;
extern int farm_no; extern int farm_no;
extern int farm_timer; extern int farm_timer;
extern int farm_status; extern uint8_t farm_status;
#ifdef TMC2130 #ifdef TMC2130
#define SILENT_MODE_NORMAL 0 #define SILENT_MODE_NORMAL 0
@ -136,18 +151,19 @@ void extr_unload_used();
#endif //SNMM #endif //SNMM
void extr_unload(); void extr_unload();
typedef enum enum class FilamentAction : uint_least8_t
{ {
e_FILAMENT_ACTION_none, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state) None, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state)
e_FILAMENT_ACTION_Load, Load,
e_FILAMENT_ACTION_autoLoad, AutoLoad,
e_FILAMENT_ACTION_unLoad, UnLoad,
e_FILAMENT_ACTION_mmuLoad, MmuLoad,
e_FILAMENT_ACTION_mmuUnLoad, MmuUnLoad,
e_FILAMENT_ACTION_mmuEject, MmuEject,
e_FILAMENT_ACTION_mmuCut, MmuCut,
} eFILAMENT_ACTION; };
extern eFILAMENT_ACTION eFilamentAction;
extern FilamentAction eFilamentAction;
extern bool bFilamentFirstRun; extern bool bFilamentFirstRun;
extern bool bFilamentPreheatState; extern bool bFilamentPreheatState;
extern bool bFilamentAction; extern bool bFilamentAction;

View File

@ -298,7 +298,7 @@ bool show_upgrade_dialog_if_version_newer(const char *version_string)
Sound_MakeCustom(50,1000,false); Sound_MakeCustom(50,1000,false);
delay_keep_alive(500); delay_keep_alive(500);
Sound_MakeCustom(50,1000,false); Sound_MakeCustom(50,1000,false);
lcd_wait_for_click(); lcd_wait_for_click_delay(30);
lcd_update_enable(true); lcd_update_enable(true);
lcd_clear(); lcd_clear();
lcd_update(0); lcd_update(0);
@ -321,3 +321,46 @@ void update_current_firmware_version_to_eeprom()
eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR, ver_current[3]); eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR, ver_current[3]);
} }
} }
//-//
eNOZZLE_DIAMETER eNozzleDiameter=e_NOZZLE_DIAMETER_400;
eCHECK_MODE eCheckMode=e_CHECK_MODE_none;
void fCheckModeInit()
{
eCheckMode=(eCHECK_MODE)eeprom_read_byte((uint8_t*)EEPROM_CHECK_MODE);
if(eCheckMode==e_CHECK_MODE_NULL)
{
eCheckMode=e_CHECK_MODE_warn;
eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)eCheckMode);
}
if(farm_mode)
eCheckMode=e_CHECK_MODE_strict;
eNozzleDiameter=(eNOZZLE_DIAMETER)eeprom_read_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER);
if((eNozzleDiameter==e_NOZZLE_DIAMETER_NULL)&& !farm_mode)
{
eNozzleDiameter=e_NOZZLE_DIAMETER_400;
eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)eNozzleDiameter);
eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,400);
}
}
void nozzle_diameter_check(uint16_t nDiameter)
{
uint16_t nDiameter_um;
nDiameter_um=eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM);
if(nDiameter==nDiameter_um)
return;
switch(eCheckMode)
{
case e_CHECK_MODE_warn:
lcd_show_fullscreen_message_and_wait_P(_i("Nozzle diameter doesn't match! Press the knob to continue."));
break;
case e_CHECK_MODE_strict:
lcd_show_fullscreen_message_and_wait_P(_i("Nozzle diameter doesn't match! Print is aborted, press the knob."));
lcd_print_stop();
break;
}
}

View File

@ -33,4 +33,29 @@ inline void eeprom_update_int8(unsigned char* addr, int8_t v) {
eeprom_update_byte(addr, *reinterpret_cast<uint8_t*>(&v)); eeprom_update_byte(addr, *reinterpret_cast<uint8_t*>(&v));
} }
//-//
#define e_CHECK_MODE_NULL 0xFF
#define e_NOZZLE_DIAMETER_NULL 0xFF
typedef enum
{
e_NOZZLE_DIAMETER_250,
e_NOZZLE_DIAMETER_400,
e_NOZZLE_DIAMETER_600
} eNOZZLE_DIAMETER;
typedef enum
{
e_CHECK_MODE_none,
e_CHECK_MODE_warn,
e_CHECK_MODE_strict
} eCHECK_MODE;
extern eNOZZLE_DIAMETER eNozzleDiameter;
extern eCHECK_MODE eCheckMode;
void fCheckModeInit();
void nozzle_diameter_check(uint16_t nDiameter);
#endif /* UTIL_H */ #endif /* UTIL_H */

View File

@ -315,7 +315,7 @@ PREHEAT SETTINGS
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 40 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215
@ -438,6 +438,7 @@ THERMISTORS SETTINGS
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
#define M600_TIMEOUT 600 //seconds #define M600_TIMEOUT 600 //seconds

View File

@ -314,7 +314,7 @@ PREHEAT SETTINGS
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 40 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215
@ -437,6 +437,7 @@ THERMISTORS SETTINGS
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
#define M600_TIMEOUT 600 //seconds #define M600_TIMEOUT 600 //seconds

View File

@ -112,6 +112,7 @@
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor // Filament sensor
#define FILAMENT_SENSOR #define FILAMENT_SENSOR
@ -371,7 +372,7 @@
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 40 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215

View File

@ -113,6 +113,7 @@
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor // Filament sensor
#define FILAMENT_SENSOR #define FILAMENT_SENSOR
@ -372,7 +373,7 @@
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 40 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215

View File

@ -112,6 +112,7 @@
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor // Filament sensor
#define FILAMENT_SENSOR #define FILAMENT_SENSOR
@ -371,7 +372,7 @@
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 40 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215
@ -505,6 +506,13 @@
#define MMU_DEBUG //print communication between MMU2 and printer on serial #define MMU_DEBUG //print communication between MMU2 and printer on serial
//#define MMU_HAS_CUTTER //#define MMU_HAS_CUTTER
// This is experimental feature requested by our test department.
// There is no known use for ordinary user. If enabled by this macro
// and enabled from printer menu (not enabled by default). It cuts filament
// every time when switching filament from gcode. MMU_HAS_CUTTER needs to be
// defined.
//#define MMU_ALWAYS_CUT
#define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning
#endif //__CONFIGURATION_PRUSA_H #endif //__CONFIGURATION_PRUSA_H

View File

@ -113,6 +113,7 @@
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor // Filament sensor
#define FILAMENT_SENSOR #define FILAMENT_SENSOR
@ -372,7 +373,7 @@
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 40 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215
@ -506,6 +507,13 @@
#define MMU_DEBUG //print communication between MMU2 and printer on serial #define MMU_DEBUG //print communication between MMU2 and printer on serial
//#define MMU_HAS_CUTTER //#define MMU_HAS_CUTTER
// This is experimental feature requested by our test department.
// There is no known use for ordinary user. If enabled by this macro
// and enabled from printer menu (not enabled by default). It cuts filament
// every time when switching filament from gcode. MMU_HAS_CUTTER needs to be
// defined.
//#define MMU_ALWAYS_CUT
#define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning
#endif //__CONFIGURATION_PRUSA_H #endif //__CONFIGURATION_PRUSA_H

View File

@ -131,6 +131,7 @@
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor // Filament sensor
#define FILAMENT_SENSOR #define FILAMENT_SENSOR
@ -480,7 +481,7 @@
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 60 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215

View File

@ -131,6 +131,7 @@
// Safety timer // Safety timer
#define SAFETYTIMER #define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30 #define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor // Filament sensor
#define FILAMENT_SENSOR #define FILAMENT_SENSOR
@ -480,7 +481,7 @@
*------------------------------------*/ *------------------------------------*/
#define FARM_PREHEAT_HOTEND_TEMP 250 #define FARM_PREHEAT_HOTEND_TEMP 250
#define FARM_PREHEAT_HPB_TEMP 60 #define FARM_PREHEAT_HPB_TEMP 80
#define FARM_PREHEAT_FAN_SPEED 0 #define FARM_PREHEAT_FAN_SPEED 0
#define PLA_PREHEAT_HOTEND_TEMP 215 #define PLA_PREHEAT_HOTEND_TEMP 215
@ -627,6 +628,14 @@
#define MMU_HWRESET #define MMU_HWRESET
#define MMU_DEBUG //print communication between MMU2 and printer on serial #define MMU_DEBUG //print communication between MMU2 and printer on serial
//#define MMU_HAS_CUTTER //#define MMU_HAS_CUTTER
// This is experimental feature requested by our test department.
// There is no known use for ordinary user. If enabled by this macro
// and enabled from printer menu (not enabled by default). It cuts filament
// every time when switching filament from gcode. MMU_HAS_CUTTER needs to be
// defined.
//#define MMU_ALWAYS_CUT
#define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning #define MMU_IDLER_SENSOR_ATTEMPTS_NR 21 //max. number of attempts to load filament if first load failed; value for max bowden length and case when loading fails right at the beginning
#endif //__CONFIGURATION_PRUSA_H #endif //__CONFIGURATION_PRUSA_H

View File

@ -38,7 +38,7 @@ def parse_txt(lang, no_warning):
if rows is None: if rows is None:
rows = 1 rows = 1
if len(translation) > cols*rows: if len(translation)-2 > cols*rows:
stderr.write( stderr.write(
"[E]: Text %s is longer then definiton on line %d\n" % "[E]: Text %s is longer then definiton on line %d\n" %
(translation, lines)) (translation, lines))
@ -56,7 +56,7 @@ def main():
usage="$(prog)s lang") usage="$(prog)s lang")
parser.add_argument( parser.add_argument(
"lang", nargs='?', default="en", type=str, "lang", nargs='?', default="en", type=str,
help="Check lang file (en|cs|de|es|fr|it)") help="Check lang file (en|cs|de|es|fr|it|pl)")
parser.add_argument( parser.add_argument(
"--no-warning", action="store_true", "--no-warning", action="store_true",
help="Disable warnings") help="Disable warnings")