Merge branch 'MK3' into MK3_LA15

This commit is contained in:
Marek Bel 2019-06-13 15:39:50 +02:00
commit 6717590631
27 changed files with 1329 additions and 775 deletions

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

@ -214,6 +214,9 @@ void manage_inactivity(bool ignore_stepper_queue=false);
#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};
#define X_AXIS_MASK 1
#define Y_AXIS_MASK 2
@ -389,7 +392,14 @@ extern bool wizard_active; //autoload temporarily disabled during wizard
extern LongTimer safetyTimer;
#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())
extern void calculate_extruder_multipliers();

308
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_run_from_menu = false;
int8_t FarmMode = 0;
bool prusa_sd_card_upload = false;
unsigned int status_number = 0;
@ -1004,7 +1002,7 @@ static void w25x20cl_err_msg()
void setup()
{
mmu_init();
ultralcd_init();
#if (LCD_BL_PIN != -1) && defined (LCD_BL_PIN)
@ -1060,6 +1058,9 @@ void setup()
//disabled filament autoload (PFW360)
fsensor_autoload_set(false);
#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);
fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream
@ -1293,8 +1294,11 @@ void setup()
#endif //TMC2130
st_init(); // Initialize stepper, this enables interrupts!
#ifdef UVLO_SUPPORT
setup_uvlo_interrupt();
#endif //UVLO_SUPPORT
#ifdef TMC2130
tmc2130_mode = silentMode?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL;
@ -1497,10 +1501,6 @@ void setup()
}
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
setup_fan_interrupt();
#endif //DEBUG_DISABLE_FANCHECK
@ -1640,6 +1640,7 @@ void setup()
}
#endif //UVLO_SUPPORT
fCheckModeInit();
KEEPALIVE_STATE(NOT_BUSY);
#ifdef WATCHDOG
wdt_enable(WDTO_4S);
@ -2985,6 +2986,32 @@ void gcode_M114()
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*/)
{
st_synchronize();
@ -3115,10 +3142,9 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
#endif //IR_SENSOR
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
//!
//! It doesn't plan_buffer_line(), as it expects plan_buffer_line() to be called after
@ -3140,7 +3166,7 @@ void gcode_M701()
else
{
enable_z();
custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
custom_message_type = CustomMsg::FilamentLoading;
#ifdef FSENSOR_QUALITY
fsensor_oq_meassure_start(40);
@ -3170,7 +3196,7 @@ void gcode_M701()
lcd_setstatuspgm(_T(WELCOME_MSG));
disable_z();
loading_flag = false;
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
#ifdef FSENSOR_QUALITY
fsensor_oq_meassure_stop();
@ -3375,8 +3401,10 @@ void process_commands()
{
#ifdef FANCHECK
if (fan_check_error){
fan_check_error = false;
lcd_pause_print();
if( fan_check_error == EFCE_DETECTED ){
fan_check_error = EFCE_REPORTED;
lcd_pause_print();
} // otherwise it has already been reported, so just ignore further processing
return;
}
#endif
@ -3606,7 +3634,39 @@ void process_commands()
} else if(code_seen("FR")) { //! PRUSA FR
// Factory full reset
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')) {
// lcd_calibration();
// }
@ -4151,7 +4211,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
// setTargetHotend(200, 0);
setTargetBed(70 + (start_temp - 30));
custom_message_type = CUSTOM_MSG_TYPE_TEMCAL;
custom_message_type = CustomMsg::TempCal;
custom_message_state = 1;
lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION));
current_position[Z_AXIS] = MESH_HOME_Z_SEARCH;
@ -4253,7 +4313,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
break;
}
puts_P(_N("PINDA probe calibration start"));
custom_message_type = CUSTOM_MSG_TYPE_TEMCAL;
custom_message_type = CustomMsg::TempCal;
custom_message_state = 1;
lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION));
current_position[X_AXIS] = PINDA_PREHEAT_X;
@ -4321,7 +4381,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
}
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1);
puts_P(_N("Temperature calibration done."));
@ -4381,7 +4441,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
// We don't know where we are! HOME!
// Push the commands to the front of the message queue in the reverse order!
// 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
enquecommand_front_P((PSTR("G28 W0")));
}
@ -4421,7 +4481,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
if (temp_comp_start)
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();
run = true;
repeatcommand_front(); // repeat G80 with all its parameters
@ -4433,14 +4493,14 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
break;
}
run = false;
if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) {
if (lcd_commands_type == LcdCommands::StopPrint) {
mesh_bed_leveling_flag = false;
break;
}
// 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;
custom_message_type = CUSTOM_MSG_TYPE_MESHBL;
custom_message_type = CustomMsg::MeshBedLeveling;
custom_message_state = (nMeasPoints * nMeasPoints) + 10;
lcd_update(1);
@ -4640,7 +4700,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
enable_z_endstop(bState);
} 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)
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
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")
@ -4916,6 +4976,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no);
SilentModeMenu = SILENT_MODE_OFF;
eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
fCheckModeInit(); // alternatively invoke printer reset
break;
case 99: //! G99 (deactivate farm mode)
@ -4923,6 +4984,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
lcd_printer_connected();
eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
lcd_update(2);
fCheckModeInit(); // alternatively invoke printer reset
break;
default:
printf_P(PSTR("Unknown G code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE);
@ -6571,7 +6633,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
float x_position = current_position[X_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_late = 0;
bool automatic = false;
@ -6607,10 +6669,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
}
else
{
#ifdef FILAMENTCHANGE_ZADD
z_shift= FILAMENTCHANGE_ZADD ;
if(current_position[Z_AXIS] < 25) z_shift+= 25 ;
#endif
z_shift = gcode_M600_filament_change_z_shift<uint8_t>();
}
//Move XY to side
if(code_seen('X'))
@ -7070,8 +7129,14 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE))
}
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);
manage_response(true, true, MMU_TCODE_MOVE);
mmu_continue_loading(is_usb_printing);
@ -7618,7 +7683,7 @@ static void handleSafetyTimer()
{
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);
setAllTargetHotends(0);
@ -7640,9 +7705,9 @@ bool bInhibitFlag;
#ifdef IR_SENSOR
bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active
#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())
{
@ -7666,7 +7731,7 @@ if(0)
show_preheat_nozzle_warning();
lcd_update_enable(true);
*/
eFilamentAction=e_FILAMENT_ACTION_autoLoad;
eFilamentAction=FilamentAction::AutoLoad;
bFilamentFirstRun=false;
if(target_temperature[0]>=EXTRUDE_MINTEMP)
{
@ -8140,7 +8205,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 mesh_home_z_search = 4;
float measure_z_heigth = 0.2f;
float measure_z_height = 0.2f;
float row[x_points_num];
int ix = 0;
int iy = 0;
@ -8157,7 +8222,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_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;
lcd_update(1);
@ -8175,7 +8240,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi
}
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);
for(int8_t i=0; i < NUM_AXIS; i++) {
current_position[i] = destination[i];
@ -8355,7 +8420,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_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;
lcd_update(1);
@ -8505,7 +8570,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_
void temp_compensation_start() {
custom_message_type = CUSTOM_MSG_TYPE_TEMPRE;
custom_message_type = CustomMsg::TempCompPreheat;
custom_message_state = PINDA_HEAT_T + 1;
lcd_update(2);
if (degHotend(active_extruder) > EXTRUDE_MINTEMP) {
@ -8526,7 +8591,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
else lcd_update(1);
}
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
custom_message_state = 0;
}
@ -8665,12 +8730,10 @@ void serialecho_temperatures() {
SERIAL_PROTOCOL_F(degBed(), 1);
SERIAL_PROTOCOLLN("");
}
extern uint32_t sdpos_atomic;
#ifdef UVLO_SUPPORT
void uvlo_()
void uvlo_()
{
unsigned long time_start = _millis();
bool sd_print = card.sdprinting;
@ -8717,12 +8780,10 @@ void uvlo_()
// Store the current extruder position.
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);
// Clean the input command queue.
cmdqueue_reset();
card.sdprinting = false;
// card.closefile();
// card.closefile();
// 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.
//FIXME one may want to disable serial lines at this point of time to avoid interfering with the command queue,
@ -8738,26 +8799,25 @@ void uvlo_()
st_synchronize();
disable_e0();
plan_buffer_line(
current_position[X_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],
plan_buffer_line(
current_position[X_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[E_AXIS] - default_retraction,
40, active_extruder);
st_synchronize();
disable_e0();
plan_buffer_line(
current_position[X_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[E_AXIS] - default_retraction,
40, active_extruder);
current_position[X_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[E_AXIS] - default_retraction,
40, active_extruder);
st_synchronize();
disable_e0();
disable_z();
// Move Z up to the next 0th full step.
// Write the file position.
eeprom_update_dword((uint32_t*)(EEPROM_FILE_POSITION), sd_position);
@ -8773,9 +8833,10 @@ void uvlo_()
// for reaching the zero full step before powering off.
eeprom_update_word((uint16_t*)(EEPROM_UVLO_Z_MICROSTEPS), z_microsteps);
// 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 + 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)
EEPROM_save_B(EEPROM_UVLO_FEEDRATE, &feedrate_bckp);
eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]);
@ -8804,16 +8865,14 @@ void uvlo_()
// Increment power failure counter
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);
printf_P(_N("UVLO - end %d\n"), _millis() - time_start);
printf_P(_N("UVLO - end %d\n"), _millis() - time_start);
#if 0
// 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;
plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], 500, active_extruder);
st_synchronize();
#endif
wdt_enable(WDTO_500MS);
WRITE(BEEPER,HIGH);
while(1)
@ -8839,30 +8898,29 @@ tmc2130_set_current_r(Z_AXIS, 20);
#ifdef TMC2130
z_microsteps=tmc2130_rd_MSCNT(Z_TMC2130_CS);
#endif //TMC2130
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();
// Finaly store the "power outage" flag.
//if(sd_print)
eeprom_update_byte((uint8_t*)EEPROM_UVLO,2);
//save current position only in case, where the printer is moving on Z axis, which is only when EEPROM_UVLO is 1
//EEPROM_UVLO is 1 after normal uvlo or after recover_print(), when the extruder is moving on Z axis after rehome
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);
eeprom_update_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z), current_position[Z_AXIS]);
//after multiple power panics current Z axis is unknow
//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
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);
wdt_enable(WDTO_500MS);
WRITE(BEEPER,HIGH);
while(1)
@ -8924,7 +8982,9 @@ void setup_uvlo_interrupt() {
ISR(INT4_vect) {
EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once
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();
}
@ -8932,14 +8992,14 @@ void recover_print(uint8_t automatic) {
char cmd[30];
lcd_update_enable(true);
lcd_update(2);
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
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
// 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"));
// 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"));
// Set the target bed and nozzle temperatures and wait.
@ -8959,8 +9019,7 @@ void recover_print(uint8_t automatic) {
// Restart the print.
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)
@ -8970,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.
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));
// 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.
// The current position after power panic is moved to the next closest 0th full step.
if(bTiny)
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];
else
if(bTiny){
current_position[Z_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_TINY_CURRENT_POSITION_Z))
+ float((1024 - eeprom_read_word((uint16_t*)(EEPROM_UVLO_TINY_Z_MICROSTEPS))
+ 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)) +
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)) {
current_position[E_AXIS] = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_E));
sprintf_P(cmd, PSTR("G92 E"));
@ -8990,21 +9071,8 @@ void recover_machine_state_after_power_panic(bool bTiny)
SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
print_world_coordinates();
// 2) Initialize the logical to physical coordinate system transformation.
// 3) Initialize the logical to physical coordinate system transformation.
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 ");
// print_mesh_bed_leveling_table();
@ -9020,7 +9088,7 @@ void recover_machine_state_after_power_panic(bool bTiny)
axis_known_position[X_AXIS] = true; enable_x();
axis_known_position[Y_AXIS] = true; enable_y();
axis_known_position[Z_AXIS] = true; enable_z();
SERIAL_ECHOPGM("recover_machine_state_after_power_panic, initial ");
print_physical_coordinates();
@ -9087,6 +9155,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(" F2000"));
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.
strcpy_P(cmd, PSTR("G1 Z")); strcat(cmd, ftostr32(eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z))));
enquecommand(cmd);
@ -9274,22 +9344,20 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
// First unretract (relative extrusion)
if(!saved_extruder_relative_mode){
strcpy_P(buf, PSTR("M83"));
enquecommand(buf, false);
enquecommand(PSTR("M83"), true);
}
//retract 45mm/s
strcpy_P(buf, PSTR("G1 E"));
dtostrf(e_move, 6, 3, buf + strlen(buf));
strcat_P(buf, PSTR(" F"));
dtostrf(2700, 8, 3, buf + strlen(buf));
// A single sprintf may not be faster, but is definitely 20B shorter
// than a sequence of commands building the string piece by piece
// A snprintf would have been a safer call, but since it is not used
// 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);
// Then lift Z axis
strcpy_P(buf, PSTR("G1 Z"));
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));
sprintf_P(buf, PSTR("G1 Z%-0.3f F%-0.3f"), saved_pos[Z_AXIS] + z_move, homing_feedrate[Z_AXIS]);
// At this point the command queue is empty.
enquecommand(buf, false);
// If this call is invoked from the main Arduino loop() function, let the caller know that the command
@ -9315,6 +9383,12 @@ void stop_and_save_print_to_ram(float z_move, float e_move)
void restore_print_from_ram_and_continue(float e_move)
{
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++)
// current_position[axis] = st_get_position_mm(axis);
active_extruder = saved_active_extruder; //restore active_extruder

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

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

View file

@ -155,13 +155,19 @@
#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_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_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_PROBE_NR (EEPROM_MBL_POINTS_NR-1) //number of measurements for each point
#define EEPROM_MMU_STEALTH (EEPROM_MBL_PROBE_NR-1)
#define EEPROM_UVLO_LA_K (EEPROM_MMU_STEALTH-4) // float
#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
#define EEPROM_UVLO_LA_K (EEPROM_NOZZLE_DIAMETER_uM-4) // float
// !!!!!
// !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!!
// !!!!!
@ -203,5 +209,11 @@
static M500_conf * const EEPROM_M500_base = reinterpret_cast<M500_conf*>(20); //offset for storing settings using M500
#endif
enum
{
EEPROM_MMU_CUTTER_ENABLED_enabled = 1,
EEPROM_MMU_CUTTER_ENABLED_always = 2,
};
#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

@ -54,6 +54,11 @@ bool fsensor_not_responding = false;
bool fsensor_printing_saved = false;
//! enable/disable quality meassurement
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
uint8_t fsensor_err_cnt = 0;
@ -120,6 +125,7 @@ void fsensor_restore_print_and_continue(void)
printf_P(PSTR("fsensor_restore_print_and_continue\n"));
fsensor_watch_runout = true;
fsensor_err_cnt = 0;
fsensor_m600_enqueued = false;
restore_print_from_ram_and_continue(0); //XYZ = orig, E - no change
}
@ -501,6 +507,47 @@ void fsensor_st_block_chunk(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)
//!
//! Works only if filament sensor is enabled.
@ -509,7 +556,7 @@ void fsensor_st_block_chunk(int cnt)
void fsensor_update(void)
{
#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;
fsensor_autoload_enabled = false;
@ -549,25 +596,17 @@ void fsensor_update(void)
}
else
{
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"));
enquecommand_front_P((PSTR("M600")));
fsensor_enque_M600();
fsensor_watch_runout = false;
}
fsensor_autoload_enabled = autoload_enabled_tmp;
fsensor_oq_meassure_enabled = oq_meassure_enabled_tmp;
}
#else //PAT9125
if ((digitalRead(IR_SENSOR_PIN) == 1) && CHECK_FSENSOR && fsensor_enabled && ir_sensor_detected)
{
fsensor_stop_and_save_print();
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"));
enquecommand_front_P((PSTR("M600")));
if ((digitalRead(IR_SENSOR_PIN) == 1) && CHECK_FSENSOR && fsensor_enabled && ir_sensor_detected && ( ! fsensor_m600_enqueued) )
{
fsensor_stop_and_save_print();
fsensor_enque_M600();
}
#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
//! @{
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);
//! @}

View file

@ -26,7 +26,7 @@ uint8_t menu_data[MENU_DATA_SIZE];
#endif
uint8_t menu_depth = 0;
uint8_t menu_block_entering_on_serious_errors = SERIOUS_ERR_NONE;
uint8_t menu_line = 0;
uint8_t menu_item = 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;
//! 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_item;
extern uint8_t menu_row;

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

@ -1076,7 +1076,7 @@ if(0)
extr_unload();
}
else {
eFilamentAction=e_FILAMENT_ACTION_mmuUnLoad;
eFilamentAction=FilamentAction::MmuUnLoad;
bFilamentFirstRun=false;
if(target_temperature[0]>=EXTRUDE_MINTEMP)
{
@ -1372,13 +1372,13 @@ void lcd_mmu_load_to_nozzle(uint8_t filament_nr)
mmu_load_to_nozzle();
load_filament_final_feed();
st_synchronize();
custom_message_type = CUSTOM_MSG_TYPE_F_LOAD;
custom_message_type = CustomMsg::FilamentLoading;
lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT));
lcd_return_to_status();
lcd_update_enable(true);
lcd_load_filament_color_check();
lcd_setstatuspgm(_T(WELCOME_MSG));
custom_message_type = CUSTOM_MSG_TYPE_STATUS;
custom_message_type = CustomMsg::Status;
}
else
{
@ -1511,20 +1511,20 @@ void mmu_continue_loading(bool blocking)
enum class Ls : uint_least8_t
{
enter,
retry,
unload,
Enter,
Retry,
Unload,
};
Ls state = Ls::enter;
Ls state = Ls::Enter;
while (PIN_GET(IR_SENSOR_PIN) != 0)
{
switch (state)
{
case Ls::enter:
case Ls::Enter:
increment_load_fail();
// no break
case Ls::retry:
case Ls::Retry:
#ifdef MMU_HAS_CUTTER
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);
manage_response(true, true, MMU_TCODE_MOVE);
load_more();
state = Ls::unload;
state = Ls::Unload;
break;
case Ls::unload:
case Ls::Unload:
stop_and_save_print_to_ram(0, 0);
//lift z
@ -1562,7 +1562,7 @@ void mmu_continue_loading(bool blocking)
{
marlin_wait_for_click();
restore_print_from_ram_and_continue(0);
state = Ls::retry;
state = Ls::Retry;
}
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
#ifdef FANCHECK
volatile bool fan_check_error = false;
volatile uint8_t fan_check_error = EFCE_OK;
#endif
unsigned char soft_pwm_bed;
@ -434,7 +434,7 @@ static void temp_runaway_stop(bool isPreheat, bool isBed);
void updatePID()
{
#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;
}
#endif
@ -512,6 +512,12 @@ void checkFanSpeed()
else fan_speed_errors[1] = 0;
#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) {
fan_speed_errors[0] = 0;
fanSpeedError(0); //extruder fan
@ -522,6 +528,23 @@ 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) {
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)){
WRITE(BEEPER, HIGH);
delayMicroseconds(200);
WRITE(BEEPER, LOW);
delayMicroseconds(100); // what is this wait for?
}
LCD_ALERTMESSAGERPGM(lcdMsg);
}
}
void fanSpeedError(unsigned char _fan) {
if (get_message_level() != 0 && isPrintPaused) return;
//to ensure that target temp. is not set to zero in case taht we are resuming print
@ -530,7 +553,8 @@ void fanSpeedError(unsigned char _fan) {
lcd_print_stop();
}
else {
fan_check_error = true;
fan_check_error = EFCE_DETECTED;
}
}
else {
@ -538,27 +562,11 @@ void fanSpeedError(unsigned char _fan) {
SERIAL_ECHOLNPGM("// action:pause"); //for octoprint
}
switch (_fan) {
case 0:
SERIAL_ECHOLNPGM("Extruder fan speed is lower then expected");
if (get_message_level() == 0) {
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
WRITE(BEEPER, HIGH);
delayMicroseconds(200);
WRITE(BEEPER, LOW);
delayMicroseconds(100);
LCD_ALERTMESSAGEPGM("Err: EXTR. FAN ERROR");
}
case 0: // extracting the same code from case 0 and case 1 into a function saves 72B
fanSpeedErrorBeep(PSTR("Extruder fan speed is lower than expected"), PSTR("Err: EXTR. FAN ERROR") );
break;
case 1:
SERIAL_ECHOLNPGM("Print fan speed is lower then expected");
if (get_message_level() == 0) {
if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT))
WRITE(BEEPER, HIGH);
delayMicroseconds(200);
WRITE(BEEPER, LOW);
delayMicroseconds(100);
LCD_ALERTMESSAGEPGM("Err: PRINT FAN ERROR");
}
fanSpeedErrorBeep(PSTR("Print fan speed is lower than expected"), PSTR("Err: PRINT FAN ERROR") );
break;
}
}
@ -1469,6 +1477,15 @@ void disable_heater()
#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) {
disable_heater();
@ -1502,13 +1519,23 @@ void min_temp_error(uint8_t e) {
#endif
//if (current_temperature_ambient < MINTEMP_MINAMBIENT) return;
disable_heater();
static const char err[] PROGMEM = "Err: MINTEMP";
if(IsStopped() == false) {
SERIAL_ERROR_START;
SERIAL_ERRORLN((int)e);
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
// if( last_alert_sent_to_lcd != LCDALERT_HEATERMINTEMP ){
// last_alert_sent_to_lcd = LCDALERT_HEATERMINTEMP;
// lcd_print_stop();
// }
Stop();
#endif
if (farm_mode) { prusa_statistics(92); }
@ -1538,10 +1565,16 @@ void bed_min_temp_error(void) {
#if HEATER_BED_PIN > -1
WRITE(HEATER_BED_PIN, 0);
#endif
static const char err[] PROGMEM = "Err: MINTEMP BED";
if(IsStopped() == false) {
SERIAL_ERROR_START;
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
Stop();
@ -2015,6 +2048,58 @@ void check_max_temp()
#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()
{
@ -2024,7 +2109,17 @@ void check_min_temp_heater0()
#else
if (current_temperature_raw[0] <= minttemp_raw[0]) {
#endif
menu_set_serious_error(SERIOUS_ERR_MINTEMP_HEATER);
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);
}
}
@ -2035,7 +2130,12 @@ void check_min_temp_bed()
#else
if (current_temperature_bed_raw <= bed_minttemp_raw) {
#endif
menu_set_serious_error(SERIOUS_ERR_MINTEMP_BED);
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))
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 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(Z_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_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000);
@ -169,7 +169,7 @@ void tmc2130_init()
tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS);
//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_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000);
@ -183,7 +183,7 @@ void tmc2130_init()
tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS);
#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_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000);
@ -383,7 +383,7 @@ void tmc2130_check_overtemp()
static uint32_t checktime = 0;
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;
skip_debug_msg = true;
@ -392,7 +392,7 @@ void tmc2130_check_overtemp()
{ // BIT 26 - over temp prewarning ~120C (+-20C)
SERIAL_ERRORRPGM(MSG_TMC_OVERTEMP);
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);
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 lcd_setstatus(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);
//! 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();
uint8_t get_message_level();
void lcd_adjust_z();
@ -80,31 +89,37 @@ extern void lcd_diag_show_end_stops();
// To be used in lcd_commands_type.
#define LCD_COMMAND_IDLE 0
#define LCD_COMMAND_LOAD_FILAMENT 1
#define LCD_COMMAND_STOP_PRINT 2
#define LCD_COMMAND_FARM_MODE_CONFIRM 4
#define LCD_COMMAND_LONG_PAUSE 5
#define LCD_COMMAND_PID_EXTRUDER 7
#define LCD_COMMAND_V2_CAL 8
enum class LcdCommands : uint_least8_t
{
Idle,
LoadFilament,
StopPrint,
FarmModeConfirm,
LongPause,
PidExtruder,
Layer1Cal,
};
extern int lcd_commands_type;
extern LcdCommands lcd_commands_type;
extern int8_t FSensorStateMenu;
#define CUSTOM_MSG_TYPE_STATUS 0 // status message from lcd_status_message variable
#define CUSTOM_MSG_TYPE_MESHBL 1 // Mesh bed leveling in progress
#define CUSTOM_MSG_TYPE_F_LOAD 2 // Loading filament in progress
#define CUSTOM_MSG_TYPE_PIDCAL 3 // PID tuning in progress
#define CUSTOM_MSG_TYPE_TEMCAL 4 // PINDA temp calibration
#define CUSTOM_MSG_TYPE_TEMPRE 5 // Temp compensation preheat
enum class CustomMsg : uint_least8_t
{
Status, //!< status message from lcd_status_message variable
MeshBedLeveling, //!< Mesh bed leveling in progress
FilamentLoading, //!< Loading filament in progress
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 uint8_t farm_mode;
extern int farm_no;
extern int farm_timer;
extern int farm_status;
extern uint8_t farm_status;
#ifdef TMC2130
#define SILENT_MODE_NORMAL 0
@ -136,18 +151,19 @@ void extr_unload_used();
#endif //SNMM
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)
e_FILAMENT_ACTION_Load,
e_FILAMENT_ACTION_autoLoad,
e_FILAMENT_ACTION_unLoad,
e_FILAMENT_ACTION_mmuLoad,
e_FILAMENT_ACTION_mmuUnLoad,
e_FILAMENT_ACTION_mmuEject,
e_FILAMENT_ACTION_mmuCut,
} eFILAMENT_ACTION;
extern eFILAMENT_ACTION eFilamentAction;
None, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state)
Load,
AutoLoad,
UnLoad,
MmuLoad,
MmuUnLoad,
MmuEject,
MmuCut,
};
extern FilamentAction eFilamentAction;
extern bool bFilamentFirstRun;
extern bool bFilamentPreheatState;
extern bool bFilamentAction;

View file

@ -327,3 +327,46 @@ void update_current_firmware_version_to_eeprom()
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));
}
//-//
#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 */

View file

@ -315,7 +315,7 @@ PREHEAT SETTINGS
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215
@ -438,6 +438,7 @@ THERMISTORS SETTINGS
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
#define M600_TIMEOUT 600 //seconds

View file

@ -314,7 +314,7 @@ PREHEAT SETTINGS
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215
@ -437,6 +437,7 @@ THERMISTORS SETTINGS
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
#define M600_TIMEOUT 600 //seconds

View file

@ -112,6 +112,7 @@
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor
#define FILAMENT_SENSOR
@ -371,7 +372,7 @@
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215

View file

@ -113,6 +113,7 @@
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor
#define FILAMENT_SENSOR
@ -372,7 +373,7 @@
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215

View file

@ -112,6 +112,7 @@
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor
#define FILAMENT_SENSOR
@ -371,7 +372,7 @@
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215
@ -505,6 +506,13 @@
#define MMU_DEBUG //print communication between MMU2 and printer on serial
//#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
#endif //__CONFIGURATION_PRUSA_H

View file

@ -113,6 +113,7 @@
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor
#define FILAMENT_SENSOR
@ -372,7 +373,7 @@
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215
@ -506,6 +507,13 @@
#define MMU_DEBUG //print communication between MMU2 and printer on serial
//#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
#endif //__CONFIGURATION_PRUSA_H

View file

@ -131,6 +131,7 @@
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor
#define FILAMENT_SENSOR
@ -480,7 +481,7 @@
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215

View file

@ -131,6 +131,7 @@
// Safety timer
#define SAFETYTIMER
#define DEFAULT_SAFETYTIMER_TIME_MINS 30
#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul)
// Filament sensor
#define FILAMENT_SENSOR
@ -480,7 +481,7 @@
*------------------------------------*/
#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 PLA_PREHEAT_HOTEND_TEMP 215
@ -627,6 +628,14 @@
#define MMU_HWRESET
#define MMU_DEBUG //print communication between MMU2 and printer on serial
//#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
#endif //__CONFIGURATION_PRUSA_H