From f20125a3e2453bda994be8fb2ed62c6d189955ce Mon Sep 17 00:00:00 2001 From: DRracer Date: Tue, 11 Jun 2019 16:24:40 +0200 Subject: [PATCH 01/19] Code size reduction - saved almost 2KB --- Firmware/ultralcd.cpp | 114 ++++++++++-------------------------------- Firmware/ultralcd.h | 2 +- 2 files changed, 27 insertions(+), 89 deletions(-) mode change 100644 => 100755 Firmware/ultralcd.h diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f69efbbc..b7f7e68d 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -73,8 +73,8 @@ extern void crashdet_disable(); bool presort_flag = false; #endif -int lcd_commands_type = LCD_COMMAND_IDLE; -int lcd_commands_step = 0; +uint8_t lcd_commands_type = LCD_COMMAND_IDLE; +uint8_t lcd_commands_step = 0; unsigned int custom_message_type = CUSTOM_MSG_TYPE_STATUS; unsigned int custom_message_state = 0; @@ -1060,6 +1060,20 @@ static void lcd_status_screen() feedmultiply = 999; } +//! extracted common code from lcd_commands into a separate function +//! along with the sprintf_P optimization this change gained more than 1.6KB +static void lcd_commands_func1(char *cmd1, uint8_t i, float width, float extr, float extr_short_segment){ + static const char fmt1[] PROGMEM = "G1 X%d Y%-.2f E%-.3f"; + static const char fmt2[] PROGMEM = "G1 Y%-.2f E%-.3f"; + sprintf_P(cmd1, fmt1, 70, (35 - i*width * 2), extr); + enquecommand(cmd1); + sprintf_P(cmd1, fmt2, (35 - (2 * i + 1)*width), extr_short_segment); + enquecommand(cmd1); + sprintf_P(cmd1, fmt1, 50, (35 - (2 * i + 1)*width), extr); + enquecommand(cmd1); + sprintf_P(cmd1, fmt2, (35 - (i + 1)*width * 2), extr_short_segment); + enquecommand(cmd1); +} void lcd_commands() { @@ -1496,27 +1510,8 @@ void lcd_commands() lcd_timeoutToStatus.start(); - for (int i = 0; i < 4; i++) { - strcpy(cmd1, "G1 X70 Y"); - strcat(cmd1, ftostr32(35 - i*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); - strcpy(cmd1, "G1 X50 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (i + 1)*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); + for (uint8_t i = 0; i < 4; i++) { + lcd_commands_func1(cmd1, i, width, extr, extr_short_segment ); } lcd_commands_step = 5; @@ -1525,56 +1520,18 @@ void lcd_commands() if (lcd_commands_step == 5 && !blocks_queued() && cmd_buffer_empty()) { lcd_timeoutToStatus.start(); - for (int i = 4; i < 8; i++) { - strcpy(cmd1, "G1 X70 Y"); - strcat(cmd1, ftostr32(35 - i*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); - strcpy(cmd1, "G1 X50 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (i + 1)*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); + for (uint8_t i = 4; i < 8; i++) { + lcd_commands_func1(cmd1, i, width, extr, extr_short_segment ); } lcd_commands_step = 4; } - + if (lcd_commands_step == 4 && !blocks_queued() && cmd_buffer_empty()) { - lcd_timeoutToStatus.start(); - for (int i = 8; i < 12; i++) { - strcpy(cmd1, "G1 X70 Y"); - strcat(cmd1, ftostr32(35 - i*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); - strcpy(cmd1, "G1 X50 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (i + 1)*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); + lcd_timeoutToStatus.start(); + for (uint8_t i = 8; i < 12; i++) { + lcd_commands_func1(cmd1, i, width, extr, extr_short_segment ); } lcd_commands_step = 3; @@ -1583,27 +1540,8 @@ void lcd_commands() if (lcd_commands_step == 3 && !blocks_queued() && cmd_buffer_empty()) { lcd_timeoutToStatus.start(); - for (int i = 12; i < 16; i++) { - strcpy(cmd1, "G1 X70 Y"); - strcat(cmd1, ftostr32(35 - i*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); - strcpy(cmd1, "G1 X50 Y"); - strcat(cmd1, ftostr32(35 - (2 * i + 1)*width)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - strcpy(cmd1, "G1 Y"); - strcat(cmd1, ftostr32(35 - (i + 1)*width * 2)); - strcat(cmd1, " E"); - strcat(cmd1, ftostr43(extr_short_segment)); - enquecommand(cmd1); + for (uint8_t i = 12; i < 16; i++) { + lcd_commands_func1(cmd1, i, width, extr, extr_short_segment ); } lcd_commands_step = 2; diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h old mode 100644 new mode 100755 index 665c1233..f8cf8365 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -97,7 +97,7 @@ extern void lcd_diag_show_end_stops(); #define LCD_COMMAND_PID_EXTRUDER 7 #define LCD_COMMAND_V2_CAL 8 -extern int lcd_commands_type; +extern uint8_t lcd_commands_type; extern int8_t FSensorStateMenu; #define CUSTOM_MSG_TYPE_STATUS 0 // status message from lcd_status_message variable From baa36ce740ab6113cbb1aef795b3cadc64c602cf Mon Sep 17 00:00:00 2001 From: DRracer Date: Wed, 12 Jun 2019 09:58:42 +0200 Subject: [PATCH 02/19] another almost 200B down by proper usage of smaller data types and enum classes --- Firmware/Marlin.h | 2 +- Firmware/Marlin_main.cpp | 38 +++---- Firmware/cmdqueue.cpp | 2 +- Firmware/mmu.cpp | 6 +- Firmware/ultralcd.cpp | 236 +++++++++++++++++++-------------------- Firmware/ultralcd.h | 59 +++++----- 6 files changed, 174 insertions(+), 169 deletions(-) mode change 100644 => 100755 Firmware/Marlin.h mode change 100644 => 100755 Firmware/cmdqueue.cpp mode change 100644 => 100755 Firmware/mmu.cpp diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h old mode 100644 new mode 100755 index 2e60597d..f53e55cc --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -389,7 +389,7 @@ 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 == CustomMsgTypes::TEMCAL) || saved_printing || (lcd_commands_type == LcdCommands::V2_CAL) || 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 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 711c428b..e0846228 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3157,7 +3157,7 @@ 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 = CustomMsgTypes::STATUS; } //! @brief Rise Z if too low to avoid blob/jam before filament loading @@ -3181,7 +3181,7 @@ void gcode_M701() else { enable_z(); - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; + custom_message_type = CustomMsgTypes::F_LOAD; #ifdef FSENSOR_QUALITY fsensor_oq_meassure_start(40); @@ -3211,7 +3211,7 @@ void gcode_M701() lcd_setstatuspgm(_T(WELCOME_MSG)); disable_z(); loading_flag = false; - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsgTypes::STATUS; #ifdef FSENSOR_QUALITY fsensor_oq_meassure_stop(); @@ -4194,7 +4194,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 = CustomMsgTypes::TEMCAL; custom_message_state = 1; lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION)); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; @@ -4296,7 +4296,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 = CustomMsgTypes::TEMCAL; custom_message_state = 1; lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION)); current_position[X_AXIS] = PINDA_PREHEAT_X; @@ -4364,7 +4364,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsgTypes::STATUS; eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); puts_P(_N("Temperature calibration done.")); @@ -4424,7 +4424,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::STOP_PRINT) { repeatcommand_front(); // repeat G80 with all its parameters enquecommand_front_P((PSTR("G28 W0"))); } @@ -4464,7 +4464,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::STOP_PRINT) { temp_compensation_start(); run = true; repeatcommand_front(); // repeat G80 with all its parameters @@ -4476,14 +4476,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::STOP_PRINT) { 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; + CustomMsgTypes 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 = CustomMsgTypes::MESHBL; custom_message_state = (nMeasPoints * nMeasPoints) + 10; lcd_update(1); @@ -4683,7 +4683,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=CustomMsgTypes::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") @@ -7693,9 +7693,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 != eFILAMENT_ACTION::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::V2_CAL) && !wizard_active) { if (fsensor_check_autoload()) { @@ -7719,7 +7719,7 @@ if(0) show_preheat_nozzle_warning(); lcd_update_enable(true); */ - eFilamentAction=e_FILAMENT_ACTION_autoLoad; + eFilamentAction=eFILAMENT_ACTION::autoLoad; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -8210,7 +8210,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 = CustomMsgTypes::MESHBL; custom_message_state = (x_points_num * y_points_num) + 10; lcd_update(1); @@ -8408,7 +8408,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 = CustomMsgTypes::MESHBL; custom_message_state = (x_points_num * y_points_num) + 10; lcd_update(1); @@ -8558,7 +8558,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 = CustomMsgTypes::TEMPRE; custom_message_state = PINDA_HEAT_T + 1; lcd_update(2); if (degHotend(active_extruder) > EXTRUDE_MINTEMP) { @@ -8579,7 +8579,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 = CustomMsgTypes::STATUS; custom_message_state = 0; } diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp old mode 100644 new mode 100755 index 2e29ad5f..1e1167c4 --- a/Firmware/cmdqueue.cpp +++ b/Firmware/cmdqueue.cpp @@ -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::FARM_MODE_CONFIRM; } } diff --git a/Firmware/mmu.cpp b/Firmware/mmu.cpp old mode 100644 new mode 100755 index 916b3d0f..c289f31d --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -1076,7 +1076,7 @@ if(0) extr_unload(); } else { - eFilamentAction=e_FILAMENT_ACTION_mmuUnLoad; + eFilamentAction=eFILAMENT_ACTION::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 = CustomMsgTypes::F_LOAD; 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 = CustomMsgTypes::STATUS; } else { diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index b7f7e68d..19601df3 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -73,10 +73,10 @@ extern void crashdet_disable(); bool presort_flag = false; #endif -uint8_t lcd_commands_type = LCD_COMMAND_IDLE; +LcdCommands lcd_commands_type = LcdCommands::IDLE; uint8_t lcd_commands_step = 0; -unsigned int custom_message_type = CUSTOM_MSG_TYPE_STATUS; +CustomMsgTypes custom_message_type = CustomMsgTypes::STATUS; unsigned int custom_message_state = 0; @@ -84,7 +84,7 @@ bool isPrintPaused = false; uint8_t farm_mode = 0; int farm_no = 0; int farm_timer = 8; -int farm_status = 0; +uint8_t farm_status = 0; bool printer_connected = true; unsigned long display_time; //just timer for showing pid finished message on lcd; @@ -565,7 +565,7 @@ void lcdui_print_temp(char type, int val_current, int val_target) // Print Z-coordinate (8 chars total) void lcdui_print_Z_coord(void) { - if (custom_message_type == CUSTOM_MSG_TYPE_MESHBL) + if (custom_message_type == CustomMsgTypes::MESHBL) lcd_puts_P(_N("Z --- ")); else lcd_printf_P(_N("Z%6.2f "), current_position[Z_AXIS]); @@ -760,7 +760,7 @@ void lcdui_print_status_line(void) break; } } - else if ((IS_SD_PRINTING) && (custom_message_type == CUSTOM_MSG_TYPE_STATUS)) + else if ((IS_SD_PRINTING) && (custom_message_type == CustomMsgTypes::STATUS)) { // If printing from SD, show what we are printing if(strlen(card.longFilename) > LCD_WIDTH) { @@ -794,10 +794,10 @@ void lcdui_print_status_line(void) { // Otherwise check for other special events switch (custom_message_type) { - case CUSTOM_MSG_TYPE_STATUS: // Nothing special, print status message normally + case CustomMsgTypes::STATUS: // Nothing special, print status message normally lcd_print(lcd_status_message); break; - case CUSTOM_MSG_TYPE_MESHBL: // If mesh bed leveling in progress, show the status + case CustomMsgTypes::MESHBL: // If mesh bed leveling in progress, show the status if (custom_message_state > 10) { lcd_set_cursor(0, 3); @@ -813,7 +813,7 @@ void lcdui_print_status_line(void) { lcd_puts_P(_T(WELCOME_MSG)); lcd_setstatuspgm(_T(WELCOME_MSG)); - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsgTypes::STATUS; } if (custom_message_state > 3 && custom_message_state <= 10 ) { @@ -825,10 +825,10 @@ void lcdui_print_status_line(void) } } break; - case CUSTOM_MSG_TYPE_F_LOAD: // If loading filament, print status + case CustomMsgTypes::F_LOAD: // If loading filament, print status lcd_print(lcd_status_message); break; - case CUSTOM_MSG_TYPE_PIDCAL: // PID tuning in progress + case CustomMsgTypes::PIDCAL: // PID tuning in progress lcd_print(lcd_status_message); if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) { @@ -838,7 +838,7 @@ void lcdui_print_status_line(void) lcd_print(itostr3left(pid_number_of_cycles)); } break; - case CUSTOM_MSG_TYPE_TEMCAL: // PINDA temp calibration in progress + case CustomMsgTypes::TEMCAL: // PINDA temp calibration in progress { char progress[4]; lcd_set_cursor(0, 3); @@ -848,7 +848,7 @@ void lcdui_print_status_line(void) lcd_print(progress); } break; - case CUSTOM_MSG_TYPE_TEMPRE: // temp compensation preheat + case CustomMsgTypes::TEMPRE: // temp compensation preheat lcd_set_cursor(0, 3); lcd_puts_P(_i("PINDA Heating"));////MSG_PINDA_PREHEAT c=20 r=1 if (custom_message_state <= PINDA_HEAT_T) @@ -996,7 +996,7 @@ static void lcd_status_screen() } // end of farm_mode lcd_status_update_delay = 10; /* redraw the main screen every second. This is easier then trying keep track of all things that change on the screen */ - if (lcd_commands_type != LCD_COMMAND_IDLE) + if (lcd_commands_type != LcdCommands::IDLE) lcd_commands(); } // end of lcd_draw_update @@ -1020,7 +1020,7 @@ static void lcd_status_screen() } if (current_click - && (lcd_commands_type != LCD_COMMAND_STOP_PRINT) //click is aborted unless stop print finishes + && (lcd_commands_type != LcdCommands::STOP_PRINT) //click is aborted unless stop print finishes && ( menu_block_entering_on_serious_errors == SERIOUS_ERR_NONE ) // or a serious error blocks entering the menu ) { @@ -1077,15 +1077,15 @@ static void lcd_commands_func1(char *cmd1, uint8_t i, float width, float extr, f void lcd_commands() { - if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE) + if (lcd_commands_type == LcdCommands::LONG_PAUSE) { if (!blocks_queued() && !homing_flag) { lcd_setstatuspgm(_i("Print paused"));////MSG_PRINT_PAUSED c=20 r=1 long_pause(); - if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE) // !!! because "lcd_commands_type" can be changed during/inside "long_pause()" + if (lcd_commands_type == LcdCommands::LONG_PAUSE) // !!! because "lcd_commands_type" can be changed during/inside "long_pause()" { - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::IDLE; lcd_commands_step = 0; } } @@ -1093,7 +1093,7 @@ void lcd_commands() #ifdef SNMM - if (lcd_commands_type == LCD_COMMAND_V2_CAL) + if (lcd_commands_type == LcdCommands::V2_CAL) { char cmd1[30]; float width = 0.4; @@ -1358,7 +1358,7 @@ void lcd_commands() #else //if not SNMM - if (lcd_commands_type == LCD_COMMAND_V2_CAL) + if (lcd_commands_type == LcdCommands::V2_CAL) { char cmd1[30]; static uint8_t filament = 0; @@ -1565,7 +1565,7 @@ void lcd_commands() { lcd_setstatuspgm(_T(WELCOME_MSG)); lcd_commands_step = 0; - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::IDLE; if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) { lcd_wizard(WizState::RepeatLay1Cal); } @@ -1575,7 +1575,7 @@ void lcd_commands() #endif // not SNMM - if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print + if (lcd_commands_type == LcdCommands::STOP_PRINT) /// stop print { @@ -1587,9 +1587,9 @@ void lcd_commands() if (lcd_commands_step == 1 && !blocks_queued()) { lcd_commands_step = 0; - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::IDLE; lcd_setstatuspgm(_T(WELCOME_MSG)); - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsgTypes::STATUS; isPrintPaused = false; } if (lcd_commands_step == 2 && !blocks_queued()) @@ -1645,7 +1645,7 @@ void lcd_commands() if (mmu_enabled) setAllTargetHotends(0); manage_heater(); - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; + custom_message_type = CustomMsgTypes::F_LOAD; lcd_commands_step = 5; } if (lcd_commands_step == 7 && !blocks_queued()) @@ -1667,12 +1667,12 @@ void lcd_commands() } } - if (lcd_commands_type == 3) + if (lcd_commands_type == LcdCommands::UNKNOWN3) { - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::IDLE; } - if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm + if (lcd_commands_type == LcdCommands::FARM_MODE_CONFIRM) /// farm mode confirm { if (lcd_commands_step == 0) { lcd_commands_step = 6; } @@ -1681,7 +1681,7 @@ void lcd_commands() { lcd_confirm_print(); lcd_commands_step = 0; - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::IDLE; } if (lcd_commands_step == 2 && !blocks_queued()) { @@ -1714,11 +1714,11 @@ void lcd_commands() } } - if (lcd_commands_type == LCD_COMMAND_PID_EXTRUDER) { + if (lcd_commands_type == LcdCommands::PID_EXTRUDER) { char cmd1[30]; if (lcd_commands_step == 0) { - custom_message_type = CUSTOM_MSG_TYPE_PIDCAL; + custom_message_type = CustomMsgTypes::PIDCAL; custom_message_state = 1; lcd_draw_update = 3; lcd_commands_step = 3; @@ -1754,10 +1754,10 @@ void lcd_commands() } if ((lcd_commands_step == 1) && ((_millis()- display_time)>2000)) { //calibration finished message lcd_setstatuspgm(_T(WELCOME_MSG)); - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsgTypes::STATUS; pid_temp = DEFAULT_PID_TEMP; lcd_commands_step = 0; - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::IDLE; } } @@ -1775,7 +1775,7 @@ void lcd_return_to_status() lcd_refresh(); // to maybe revive the LCD if static electricity killed it. menu_goto(lcd_status_screen, 0, false, true); menu_depth = 0; - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad + eFilamentAction=eFILAMENT_ACTION::none; // i.e. non-autoLoad } //! @brief Pause print, disable nozzle heater, move to park position @@ -1785,9 +1785,9 @@ void lcd_pause_print() stop_and_save_print_to_ram(0.0,0.0); setAllTargetHotends(0); isPrintPaused = true; - if (LCD_COMMAND_IDLE == lcd_commands_type) + if (LcdCommands::IDLE == lcd_commands_type) { - lcd_commands_type = LCD_COMMAND_LONG_PAUSE; + lcd_commands_type = LcdCommands::LONG_PAUSE; } } @@ -1928,7 +1928,7 @@ void lcd_menu_extruder_info() // NOT static due to using ins lcd_puts_P(_N("Filament sensor\n" "is disabled.")); else { - if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::V2_CAL)) pat9125_update(); lcd_printf_P(_N( "Fil. Xd:%3d Yd:%3d\n" @@ -2314,7 +2314,7 @@ void lcd_set_filament_oq_meass() } -eFILAMENT_ACTION eFilamentAction=e_FILAMENT_ACTION_none; // must be initialized as 'non-autoLoad' +eFILAMENT_ACTION eFilamentAction=eFILAMENT_ACTION::none; // must be initialized as 'non-autoLoad' bool bFilamentFirstRun; bool bFilamentPreheatState; bool bFilamentAction=false; @@ -2331,18 +2331,18 @@ lcd_puts_P(_i("Press the knob")); ////MSG_ c=20 r=1 lcd_set_cursor(0,3); switch(eFilamentAction) { - case e_FILAMENT_ACTION_Load: - case e_FILAMENT_ACTION_autoLoad: - case e_FILAMENT_ACTION_mmuLoad: + case eFILAMENT_ACTION::load: + case eFILAMENT_ACTION::autoLoad: + case eFILAMENT_ACTION::mmuLoad: lcd_puts_P(_i("to load filament")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_unLoad: - case e_FILAMENT_ACTION_mmuUnLoad: + case eFILAMENT_ACTION::unLoad: + case eFILAMENT_ACTION::mmuUnLoad: lcd_puts_P(_i("to unload filament")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_mmuEject: - case e_FILAMENT_ACTION_mmuCut: - case e_FILAMENT_ACTION_none: + case eFILAMENT_ACTION::mmuEject: + case eFILAMENT_ACTION::mmuCut: + case eFILAMENT_ACTION::none: break; } if(lcd_clicked()) @@ -2356,21 +2356,21 @@ if(lcd_clicked()) menu_back(nLevel); switch(eFilamentAction) { - case e_FILAMENT_ACTION_autoLoad: - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad + case eFILAMENT_ACTION::autoLoad: + eFilamentAction=eFILAMENT_ACTION::none; // i.e. non-autoLoad // no break - case e_FILAMENT_ACTION_Load: + case eFILAMENT_ACTION::load: loading_flag=true; enquecommand_P(PSTR("M701")); // load filament break; - case e_FILAMENT_ACTION_unLoad: + case eFILAMENT_ACTION::unLoad: enquecommand_P(PSTR("M702")); // unload filament break; - case e_FILAMENT_ACTION_mmuLoad: - case e_FILAMENT_ACTION_mmuUnLoad: - case e_FILAMENT_ACTION_mmuEject: - case e_FILAMENT_ACTION_mmuCut: - case e_FILAMENT_ACTION_none: + case eFILAMENT_ACTION::mmuLoad: + case eFILAMENT_ACTION::mmuUnLoad: + case eFILAMENT_ACTION::mmuEject: + case eFILAMENT_ACTION::mmuCut: + case eFILAMENT_ACTION::none: break; } } @@ -2394,19 +2394,19 @@ lcdui_print_temp(LCD_STR_THERMOMETER[0],(int)degHotend(0),(int)degTargetHotend(0 lcd_set_cursor(0,1); switch(eFilamentAction) { - case e_FILAMENT_ACTION_Load: - case e_FILAMENT_ACTION_autoLoad: - case e_FILAMENT_ACTION_mmuLoad: + case eFILAMENT_ACTION::load: + case eFILAMENT_ACTION::autoLoad: + case eFILAMENT_ACTION::mmuLoad: lcd_puts_P(_i("Preheating to load")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_unLoad: - case e_FILAMENT_ACTION_mmuUnLoad: + case eFILAMENT_ACTION::unLoad: + case eFILAMENT_ACTION::mmuUnLoad: lcd_puts_P(_i("Preheating to unload")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_mmuEject: + case eFILAMENT_ACTION::mmuEject: lcd_puts_P(_i("Preheating to eject")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_mmuCut: + case eFILAMENT_ACTION::mmuCut: lcd_puts_P(_i("Preheating to cut")); ////MSG_ c=20 r=1 break; } @@ -2425,20 +2425,20 @@ if(lcd_clicked()) setTargetBed((float)nTargetBedOld); } menu_back(); - if(eFilamentAction==e_FILAMENT_ACTION_autoLoad) - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad + if(eFilamentAction==eFILAMENT_ACTION::autoLoad) + eFilamentAction=eFILAMENT_ACTION::none; // i.e. non-autoLoad } else { if(current_temperature[0]>(target_temperature[0]*0.95)) { switch(eFilamentAction) { - case e_FILAMENT_ACTION_Load: - case e_FILAMENT_ACTION_autoLoad: - case e_FILAMENT_ACTION_unLoad: + case eFILAMENT_ACTION::load: + case eFILAMENT_ACTION::autoLoad: + case eFILAMENT_ACTION::unLoad: menu_submenu(mFilamentPrompt); break; - case e_FILAMENT_ACTION_mmuLoad: + case eFILAMENT_ACTION::mmuLoad: nLevel=1; if(!bFilamentPreheatState) nLevel++; @@ -2446,7 +2446,7 @@ else { menu_back(nLevel); menu_submenu(mmu_load_to_nozzle_menu); break; - case e_FILAMENT_ACTION_mmuUnLoad: + case eFILAMENT_ACTION::mmuUnLoad: nLevel=1; if(!bFilamentPreheatState) nLevel++; @@ -2454,7 +2454,7 @@ else { menu_back(nLevel); extr_unload(); break; - case e_FILAMENT_ACTION_mmuEject: + case eFILAMENT_ACTION::mmuEject: nLevel=1; if(!bFilamentPreheatState) nLevel++; @@ -2462,7 +2462,7 @@ else { menu_back(nLevel); menu_submenu(mmu_fil_eject_menu); break; - case e_FILAMENT_ACTION_mmuCut: + case eFILAMENT_ACTION::mmuCut: nLevel=1; if(!bFilamentPreheatState) nLevel++; @@ -2495,44 +2495,44 @@ if(current_temperature[0]>(target_temperature[0]*0.95)) { switch(eFilamentAction) { - case e_FILAMENT_ACTION_Load: - case e_FILAMENT_ACTION_autoLoad: - case e_FILAMENT_ACTION_unLoad: + case eFILAMENT_ACTION::load: + case eFILAMENT_ACTION::autoLoad: + case eFILAMENT_ACTION::unLoad: if(bFilamentWaitingFlag) menu_submenu(mFilamentPrompt); else { nLevel=bFilamentPreheatState?1:2; menu_back(nLevel); - if((eFilamentAction==e_FILAMENT_ACTION_Load)||(eFilamentAction==e_FILAMENT_ACTION_autoLoad)) + if((eFilamentAction==eFILAMENT_ACTION::load)||(eFilamentAction==eFILAMENT_ACTION::autoLoad)) { loading_flag=true; enquecommand_P(PSTR("M701")); // load filament - if(eFilamentAction==e_FILAMENT_ACTION_autoLoad) - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad + if(eFilamentAction==eFILAMENT_ACTION::autoLoad) + eFilamentAction=eFILAMENT_ACTION::none; // i.e. non-autoLoad } - if(eFilamentAction==e_FILAMENT_ACTION_unLoad) + if(eFilamentAction==eFILAMENT_ACTION::unLoad) enquecommand_P(PSTR("M702")); // unload filament } break; - case e_FILAMENT_ACTION_mmuLoad: + case eFILAMENT_ACTION::mmuLoad: nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; menu_back(nLevel); menu_submenu(mmu_load_to_nozzle_menu); break; - case e_FILAMENT_ACTION_mmuUnLoad: + case eFILAMENT_ACTION::mmuUnLoad: nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; menu_back(nLevel); extr_unload(); break; - case e_FILAMENT_ACTION_mmuEject: + case eFILAMENT_ACTION::mmuEject: nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; menu_back(nLevel); menu_submenu(mmu_fil_eject_menu); break; - case e_FILAMENT_ACTION_mmuCut: + case eFILAMENT_ACTION::mmuCut: #ifdef MMU_HAS_CUTTER nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; @@ -2540,7 +2540,7 @@ if(current_temperature[0]>(target_temperature[0]*0.95)) menu_submenu(mmu_cut_filament_menu); #endif //MMU_HAS_CUTTER break; - case e_FILAMENT_ACTION_none: + case eFILAMENT_ACTION::none: break; } if(bFilamentWaitingFlag) @@ -2554,22 +2554,22 @@ else { lcd_set_cursor(0,1); switch(eFilamentAction) { - case e_FILAMENT_ACTION_Load: - case e_FILAMENT_ACTION_autoLoad: - case e_FILAMENT_ACTION_mmuLoad: + case eFILAMENT_ACTION::load: + case eFILAMENT_ACTION::autoLoad: + case eFILAMENT_ACTION::mmuLoad: lcd_puts_P(_i("Preheating to load")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_unLoad: - case e_FILAMENT_ACTION_mmuUnLoad: + case eFILAMENT_ACTION::unLoad: + case eFILAMENT_ACTION::mmuUnLoad: lcd_puts_P(_i("Preheating to unload")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_mmuEject: + case eFILAMENT_ACTION::mmuEject: lcd_puts_P(_i("Preheating to eject")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_mmuCut: + case eFILAMENT_ACTION::mmuCut: lcd_puts_P(_i("Preheating to cut")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_none: + case eFILAMENT_ACTION::none: break; } lcd_set_cursor(0,3); @@ -2588,8 +2588,8 @@ else { setTargetBed((float)nTargetBedOld); } menu_back(); - if(eFilamentAction==e_FILAMENT_ACTION_autoLoad) - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad + if(eFilamentAction==eFILAMENT_ACTION::autoLoad) + eFilamentAction=eFILAMENT_ACTION::none; // i.e. non-autoLoad } } } @@ -2634,8 +2634,8 @@ mFilamentItem(FLEX_PREHEAT_HOTEND_TEMP,FLEX_PREHEAT_HPB_TEMP); void mFilamentBack() { menu_back(); -if(eFilamentAction==e_FILAMENT_ACTION_autoLoad) - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad +if(eFilamentAction==eFILAMENT_ACTION::autoLoad) + eFilamentAction=eFILAMENT_ACTION::none; // i.e. non-autoLoad } void mFilamentMenu() @@ -2666,7 +2666,7 @@ if(0) enquecommand_P(PSTR("M702")); // unload filament } else { - eFilamentAction=e_FILAMENT_ACTION_unLoad; + eFilamentAction=eFILAMENT_ACTION::unLoad; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -2893,7 +2893,7 @@ static void lcd_LoadFilament() if(0) { // menu_back(); // not necessary (see "lcd_return_to_status()" below) - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; + custom_message_type = CustomMsgTypes::F_LOAD; loading_flag = true; enquecommand_P(PSTR("M701")); //load filament SERIAL_ECHOLN("Loading filament"); @@ -2901,7 +2901,7 @@ if(0) } else { - eFilamentAction=e_FILAMENT_ACTION_Load; + eFilamentAction=eFILAMENT_ACTION::load; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -3350,7 +3350,7 @@ void pid_extruder() lcd_set_cursor(1, 2); lcd_print(ftostr3(pid_temp)); if (lcd_clicked()) { - lcd_commands_type = LCD_COMMAND_PID_EXTRUDER; + lcd_commands_type = LcdCommands::PID_EXTRUDER; lcd_return_to_status(); lcd_update(2); } @@ -3952,7 +3952,7 @@ void lcd_bed_calibration_show_result(BedSkewOffsetDetectionResultType result, ui void lcd_temp_cal_show_result(bool result) { - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsgTypes::STATUS; disable_x(); disable_y(); disable_z(); @@ -4573,7 +4573,7 @@ static void lcd_crash_mode_set() }else{ crashdet_enable(); } - if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) menu_goto(lcd_tune_menu, 9, true, true); + if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::V2_CAL)) menu_goto(lcd_tune_menu, 9, true, true); else menu_goto(lcd_settings_menu, 9, true, true); } @@ -4810,14 +4810,14 @@ void lcd_v2_calibration() if (filament < 5) { lcd_commands_step = 20 + filament; - lcd_commands_type = LCD_COMMAND_V2_CAL; + lcd_commands_type = LcdCommands::V2_CAL; } } else { bool loaded = lcd_show_fullscreen_message_yes_no_and_wait_P(_i("Is PLA filament loaded?"), false, true);////MSG_PLA_FILAMENT_LOADED c=20 r=2 if (loaded) { - lcd_commands_type = LCD_COMMAND_V2_CAL; + lcd_commands_type = LcdCommands::V2_CAL; } else { lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4 @@ -5077,7 +5077,7 @@ void lcd_wizard(WizState state) case S::Lay1Cal: lcd_show_fullscreen_message_and_wait_P(_i("Now I will calibrate distance between tip of the nozzle and heatbed surface."));////MSG_WIZARD_V2_CAL c=20 r=8 lcd_show_fullscreen_message_and_wait_P(_i("I will start to print line and you will gradually lower the nozzle by rotating the knob, until you reach optimal height. Check the pictures in our handbook in chapter Calibration."));////MSG_WIZARD_V2_CAL_2 c=20 r=12 - lcd_commands_type = LCD_COMMAND_V2_CAL; + lcd_commands_type = LcdCommands::V2_CAL; lcd_return_to_status(); end = true; break; @@ -5930,7 +5930,7 @@ static void mmu_load_to_nozzle_menu() } else { - eFilamentAction = e_FILAMENT_ACTION_mmuLoad; + eFilamentAction = eFILAMENT_ACTION::mmuLoad; bFilamentFirstRun = false; if (target_temperature[0] >= EXTRUDE_MINTEMP) { @@ -5962,7 +5962,7 @@ static void mmu_fil_eject_menu() } else { - eFilamentAction = e_FILAMENT_ACTION_mmuEject; + eFilamentAction = eFILAMENT_ACTION::mmuEject; bFilamentFirstRun = false; if (target_temperature[0] >= EXTRUDE_MINTEMP) { @@ -5990,7 +5990,7 @@ static void mmu_cut_filament_menu() } else { - eFilamentAction=e_FILAMENT_ACTION_mmuCut; + eFilamentAction=eFILAMENT_ACTION::mmuCut; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -6035,7 +6035,7 @@ static void change_extr_menu(){ //unload filament for single material printer (used in M702 gcode) void unload_filament() { - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; + custom_message_type = CustomMsgTypes::F_LOAD; lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT)); // extr_unload2(); @@ -6070,7 +6070,7 @@ void unload_filament() lcd_update_enable(true); lcd_setstatuspgm(_T(WELCOME_MSG)); - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsgTypes::STATUS; } @@ -6397,13 +6397,13 @@ static void lcd_main_menu() }*/ - if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) + if ( ( IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::V2_CAL)) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) && !homing_flag && !mesh_bed_leveling_flag) { MENU_ITEM_SUBMENU_P(_T(MSG_BABYSTEP_Z), lcd_babystep_z);//8 } - if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) + if ( moves_planned() || IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::V2_CAL)) { MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE } else @@ -6412,7 +6412,7 @@ static void lcd_main_menu() } #ifdef SDSUPPORT - if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL) + if (card.cardOK || lcd_commands_type == LcdCommands::V2_CAL) { if (card.isFileOpen()) { @@ -6428,12 +6428,12 @@ static void lcd_main_menu() MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop); } } - else if (lcd_commands_type == LCD_COMMAND_V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) { + else if (lcd_commands_type == LcdCommands::V2_CAL && mesh_bed_leveling_flag == false && homing_flag == false) { //MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop); } else { - if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + if (!is_usb_printing && (lcd_commands_type != LcdCommands::V2_CAL)) { //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu); /*else*/ { @@ -6457,7 +6457,7 @@ static void lcd_main_menu() #endif - if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL)) + if (IS_SD_PRINTING || is_usb_printing || (lcd_commands_type == LcdCommands::V2_CAL)) { if (farm_mode) { @@ -6501,7 +6501,7 @@ static void lcd_main_menu() } - if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + if (!is_usb_printing && (lcd_commands_type != LcdCommands::V2_CAL)) { MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS } @@ -6557,7 +6557,7 @@ static void lcd_colorprint_change() { enquecommand_P(PSTR("M600")); - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; //just print status message + custom_message_type = CustomMsgTypes::F_LOAD; //just print status message lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS)); lcd_return_to_status(); lcd_draw_update = 3; @@ -6786,7 +6786,7 @@ void lcd_print_stop() lcd_return_to_status(); lcd_ignore_click(true); lcd_commands_step = 0; - lcd_commands_type = LCD_COMMAND_STOP_PRINT; + lcd_commands_type = LcdCommands::STOP_PRINT; // Turn off the print fan SET_OUTPUT(FAN_PIN); WRITE(FAN_PIN, 0); @@ -8359,5 +8359,5 @@ void menu_lcd_lcdupdate_func(void) if (!SdFatUtil::test_stack_integrity()) stack_error(); lcd_ping(); //check that we have received ping command if we are in farm mode lcd_send_status(); - if (lcd_commands_type == LCD_COMMAND_V2_CAL) lcd_commands(); + if (lcd_commands_type == LcdCommands::V2_CAL) lcd_commands(); } diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index f8cf8365..26e282a0 100755 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -89,31 +89,36 @@ 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 : uint8_t { + IDLE = 0, + LOAD_FILAMENT = 1, + STOP_PRINT = 2, + UNKNOWN3 = 3, + FARM_MODE_CONFIRM = 4, + LONG_PAUSE = 5, + PID_EXTRUDER = 7, + V2_CAL = 8, +}; -extern uint8_t 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 CustomMsgTypes : uint8_t { + STATUS = 0, //!< status message from lcd_status_message variable + MESHBL = 1, //!< Mesh bed leveling in progress + F_LOAD = 2, //!< Loading filament in progress + PIDCAL = 3, //!< PID tuning in progress + TEMCAL = 4, //!< PINDA temp calibration + TEMPRE = 5, //!< Temp compensation preheat +}; -extern unsigned int custom_message_type; +extern CustomMsgTypes 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 @@ -145,17 +150,17 @@ void extr_unload_used(); #endif //SNMM void extr_unload(); -typedef enum -{ - 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; +enum class eFILAMENT_ACTION : uint8_t { + none, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state) + load, + autoLoad, + unLoad, + mmuLoad, + mmuUnLoad, + mmuEject, + mmuCut, +}; + extern eFILAMENT_ACTION eFilamentAction; extern bool bFilamentFirstRun; extern bool bFilamentPreheatState; From 4f8ed7f1234274f563b8fa613b27f2060a311779 Mon Sep 17 00:00:00 2001 From: DRracer Date: Wed, 12 Jun 2019 10:31:09 +0200 Subject: [PATCH 03/19] for cycles' variables: int -> uint8_t where appropriate, part1 --- Firmware/temperature.cpp | 2 +- Firmware/tmc2130.cpp | 10 +++++----- Firmware/ultralcd.cpp | 32 ++++++++++++++++---------------- 3 files changed, 22 insertions(+), 22 deletions(-) mode change 100644 => 100755 Firmware/tmc2130.cpp diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 9c49cf79..03845b12 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -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(uint8_t e = 0; e < EXTRUDERS; e++) { iState_sum_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki; } #endif diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp old mode 100644 new mode 100755 index 05ea2ab6..fe04e8da --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -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 (uint8_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 (uint8_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 (uint8_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 (uint8_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 (uint8_t j = 0; j < 4; j++) tmc2130_wr(j, TMC2130_REG_CHOPCONF, 0x00010000); kill(MSG_TMC_OVERTEMP); } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 19601df3..5efa9bf2 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -317,7 +317,7 @@ static void lcd_implementation_drawmenu_sdfile_selected(uint8_t row, char* longF char c; int enc_dif = lcd_encoder_diff; uint8_t n = LCD_WIDTH - 1; - for(int g = 0; g<4;g++){ + for(uint8_t g = 0; g<4;g++){ lcd_set_cursor(0, g); lcd_print(' '); } @@ -2708,11 +2708,11 @@ void lcd_change_success() { static void lcd_loading_progress_bar(uint16_t loading_time_ms) { - for (int i = 0; i < 20; i++) { + for (uint8_t i = 0; i < 20; i++) { lcd_set_cursor(i, 3); lcd_print("."); //loading_time_ms/20 delay - for (int j = 0; j < 5; j++) { + for (uint8_t j = 0; j < 5; j++) { delay_keep_alive(loading_time_ms / 100); } } @@ -3154,7 +3154,7 @@ static void lcd_menu_xyz_offset() float cntr[2]; world2machine_read_valid(vec_x, vec_y, cntr); - for (int i = 0; i < 2; i++) + for (uint8_t i = 0; i < 2; i++) { lcd_puts_at_P(11, i + 2, PSTR("")); lcd_print(cntr[i]); @@ -4822,7 +4822,7 @@ void lcd_v2_calibration() else { lcd_display_message_fullscreen_P(_i("Please load PLA filament first."));////MSG_PLEASE_LOAD_PLA c=20 r=4 lcd_consume_click(); - for (int i = 0; i < 20; i++) { //wait max. 2s + for (uint8_t i = 0; i < 20; i++) { //wait max. 2s delay_keep_alive(100); if (lcd_clicked()) { break; @@ -5549,7 +5549,7 @@ void bowden_menu() { lcd_clear(); lcd_set_cursor(0, 0); lcd_print(">"); - for (int i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { lcd_set_cursor(1, i); lcd_print("Extruder "); lcd_print(i); @@ -5637,7 +5637,7 @@ void bowden_menu() { enc_dif = lcd_encoder_diff; lcd_set_cursor(0, cursor_pos); lcd_print(">"); - for (int i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { lcd_set_cursor(1, i); lcd_print("Extruder "); lcd_print(i); @@ -5764,14 +5764,14 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite if (header) lcd_puts_at_P(0,0,header); const bool last_visible = (first == items_no - 3); - const int8_t ordinary_items = (last_item&&last_visible)?2:3; + const uint8_t ordinary_items = (last_item&&last_visible)?2:3; - for (int i = 0; i < ordinary_items; i++) + for (uint8_t i = 0; i < ordinary_items; i++) { if (item) lcd_puts_at_P(1, i + 1, item); } - for (int i = 0; i < ordinary_items; i++) + for (uint8_t i = 0; i < ordinary_items; i++) { lcd_set_cursor(2 + item_len, i+1); lcd_print(first + i + 1); @@ -5825,7 +5825,7 @@ char reset_menu() { lcd_consume_click(); while (1) { - for (int i = 0; i < 4; i++) { + for (uint8_t i = 0; i < 4; i++) { lcd_set_cursor(1, i); lcd_print(item[first + i]); } @@ -6151,7 +6151,7 @@ unsigned char lcd_choose_color() { item[0] = "Orange"; item[1] = "Black"; //----------------------------------------------------- - unsigned char active_rows; + uint8_t active_rows; static int first = 0; int enc_dif = 0; unsigned char cursor_pos = 1; @@ -6164,7 +6164,7 @@ unsigned char lcd_choose_color() { lcd_consume_click(); while (1) { lcd_puts_at_P(0, 0, PSTR("Choose color:")); - for (int i = 0; i < active_rows; i++) { + for (uint8_t i = 0; i < active_rows; i++) { lcd_set_cursor(1, i+1); lcd_print(item[first + i]); } @@ -7201,7 +7201,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { //end of second measurement, now check for possible errors: - for(int i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length + for(uint8_t i = 0; i < 2; i++){ //check if measured axis length corresponds to expected length printf_P(_N("Measured axis length:%.3f\n"), measured_axis_length[i]); if (abs(measured_axis_length[i] - axis_length) > max_error_mm) { enable_endstops(false); @@ -8065,7 +8065,7 @@ static void menu_action_sdfile(const char* filename) const char end[5] = ".gco"; //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco" - for (int i = 0; i < 8; i++) { + for (uint8_t i = 0; i < 8; i++) { if (strcmp((cmd + i + 4), end) == 0) { //filename is shorter then 8.3, store '\0' character on position where ".gco" string was found to terminate stored string properly eeprom_write_byte((uint8_t*)EEPROM_FILENAME + i, '\0'); @@ -8080,7 +8080,7 @@ static void menu_action_sdfile(const char* filename) eeprom_write_byte((uint8_t*)EEPROM_DIR_DEPTH, depth); for (uint8_t i = 0; i < depth; i++) { - for (int j = 0; j < 8; j++) { + for (uint8_t j = 0; j < 8; j++) { eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]); } } From a3fde091ab024676654a4648d73fdf04947d0690 Mon Sep 17 00:00:00 2001 From: DRracer Date: Fri, 12 Jul 2019 10:10:56 +0200 Subject: [PATCH 04/19] More than 7.5KB saved by slight refactoring of printing to serial line --- Firmware/Marlin.h | 18 +++----- Firmware/MarlinSerial.h | 6 +-- Firmware/Marlin_main.cpp | 18 ++++++++ Firmware/ultralcd.cpp | 97 +++++++++++++++------------------------- 4 files changed, 63 insertions(+), 76 deletions(-) diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index afc01859..c71f70ea 100755 --- a/Firmware/Marlin.h +++ b/Firmware/Marlin.h @@ -79,9 +79,9 @@ extern FILE _uartout; #define SERIAL_PROTOCOL_F(x,y) (MYSERIAL.print(x,y)) #define SERIAL_PROTOCOLPGM(x) (serialprintPGM(PSTR(x))) #define SERIAL_PROTOCOLRPGM(x) (serialprintPGM((x))) -#define SERIAL_PROTOCOLLN(x) (MYSERIAL.print(x),MYSERIAL.write('\n')) -#define SERIAL_PROTOCOLLNPGM(x) (serialprintPGM(PSTR(x)),MYSERIAL.write('\n')) -#define SERIAL_PROTOCOLLNRPGM(x) (serialprintPGM((x)),MYSERIAL.write('\n')) +#define SERIAL_PROTOCOLLN(x) (MYSERIAL.println(x)/*,MYSERIAL.write('\n')*/) +#define SERIAL_PROTOCOLLNPGM(x) (serialprintPGM(PSTR(x)),MYSERIAL.println()/*write('\n')*/) +#define SERIAL_PROTOCOLLNRPGM(x) (serialprintPGM((x)),MYSERIAL.println()/*write('\n')*/) extern const char errormagic[] PROGMEM; @@ -111,15 +111,9 @@ void serial_echopair_P(const char *s_P, unsigned long v); //Things to write to serial from Program memory. Saves 400 to 2k of RAM. -FORCE_INLINE void serialprintPGM(const char *str) -{ - char ch=pgm_read_byte(str); - while(ch) - { - MYSERIAL.write(ch); - ch=pgm_read_byte(++str); - } -} +// Making this FORCE_INLINE is not a good idea when running out of FLASH +// I'd rather skip a few CPU ticks than 5.5KB (!!) of FLASH +void serialprintPGM(const char *str); bool is_buffer_empty(); void get_command(); diff --git a/Firmware/MarlinSerial.h b/Firmware/MarlinSerial.h index d596708e..27e722bc 100644 --- a/Firmware/MarlinSerial.h +++ b/Firmware/MarlinSerial.h @@ -96,7 +96,7 @@ class MarlinSerial //: public Stream static int read(void); static void flush(void); - static FORCE_INLINE int available(void) + static /*FORCE_INLINE*/ int available(void) { return (unsigned int)(RX_BUFFER_SIZE + rx_buffer.head - rx_buffer.tail) % RX_BUFFER_SIZE; } @@ -184,14 +184,14 @@ class MarlinSerial //: public Stream public: - static FORCE_INLINE void write(const char *str) + static /*FORCE_INLINE*/ void write(const char *str) { while (*str) write(*str++); } - static FORCE_INLINE void write(const uint8_t *buffer, size_t size) + static /*FORCE_INLINE*/ void write(const uint8_t *buffer, size_t size) { while (size--) write(*buffer++); diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3bde7239..d21d11b6 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -411,6 +411,24 @@ void serial_echopair_P(const char *s_P, double v) void serial_echopair_P(const char *s_P, unsigned long v) { serialprintPGM(s_P); SERIAL_ECHO(v); } +/*FORCE_INLINE*/ void serialprintPGM(const char *str) +{ +#if 0 + char ch=pgm_read_byte(str); + while(ch) + { + MYSERIAL.write(ch); + ch=pgm_read_byte(++str); + } +#else + // hmm, same size as the above version, the compiler did a good job optimizing the above + while( uint8_t ch = pgm_read_byte(str) ){ + MYSERIAL.write((char)ch); + ++str; + } +#endif +} + #ifdef SDSUPPORT #include "SdFatUtil.h" int freeMemory() { return SdFatUtil::FreeRam(); } diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e1d9e0ab..d3699f45 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3954,6 +3954,13 @@ void lcd_menu_show_sensors_state() // NOT static due to using ins } } +void prusa_statistics_err(char c){ + SERIAL_ECHO("{[ERR:"); + SERIAL_ECHO(c); + SERIAL_ECHO(']'); + prusa_stat_farm_number(); +} + void prusa_statistics(int _message, uint8_t _fil_nr) { #ifdef DEBUG_DISABLE_PRUSA_STATISTICS return; @@ -3963,114 +3970,93 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { case 0: // default message if (busy_state == PAUSED_FOR_USER) - { - SERIAL_ECHO("{"); - prusa_stat_printerstatus(15); - prusa_stat_farm_number(); - prusa_stat_printinfo(); - SERIAL_ECHOLN("}"); + { status_number = 15; } else if (isPrintPaused || card.paused) { - SERIAL_ECHO("{"); - prusa_stat_printerstatus(14); - prusa_stat_farm_number(); - prusa_stat_printinfo(); - SERIAL_ECHOLN("}"); status_number = 14; } else if (IS_SD_PRINTING || loading_flag) { - SERIAL_ECHO("{"); - prusa_stat_printerstatus(4); - prusa_stat_farm_number(); - prusa_stat_printinfo(); - SERIAL_ECHOLN("}"); status_number = 4; } else { - SERIAL_ECHO("{"); - prusa_stat_printerstatus(1); - prusa_stat_farm_number(); - prusa_stat_diameter(); - SERIAL_ECHOLN("}"); status_number = 1; } + SERIAL_ECHO('{'); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + prusa_stat_printinfo(); break; case 1: // 1 heating farm_status = 2; - SERIAL_ECHO("{"); + SERIAL_ECHO('{'); prusa_stat_printerstatus(2); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); status_number = 2; farm_timer = 1; break; case 2: // heating done farm_status = 3; - SERIAL_ECHO("{"); + SERIAL_ECHO('{'); prusa_stat_printerstatus(3); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); + SERIAL_ECHOLN('}'); status_number = 3; farm_timer = 1; if (IS_SD_PRINTING || loading_flag) { farm_status = 4; - SERIAL_ECHO("{"); + SERIAL_ECHO('{'); prusa_stat_printerstatus(4); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); status_number = 4; } else { - SERIAL_ECHO("{"); + SERIAL_ECHO('{'); prusa_stat_printerstatus(3); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); status_number = 3; } farm_timer = 1; break; case 3: // filament change - + // must do a return here to prevent doing SERIAL_ECHOLN("}") at the very end of this function + // saved a considerable amount of FLASH + return; break; case 4: // print succesfull SERIAL_ECHO("{[RES:1][FIL:"); MYSERIAL.print(int(_fil_nr)); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); prusa_stat_printerstatus(status_number); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); farm_timer = 2; break; case 5: // print not succesfull SERIAL_ECHO("{[RES:0][FIL:"); MYSERIAL.print(int(_fil_nr)); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); prusa_stat_printerstatus(status_number); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); farm_timer = 2; break; case 6: // print done SERIAL_ECHO("{[PRN:8]"); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); status_number = 8; farm_timer = 2; break; case 7: // print done - stopped SERIAL_ECHO("{[PRN:9]"); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); status_number = 9; farm_timer = 2; break; @@ -4078,49 +4064,38 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { SERIAL_ECHO("{[PRN:0][PFN:"); status_number = 0; SERIAL_ECHO(farm_no); - SERIAL_ECHOLN("]}"); + SERIAL_ECHO(']'); farm_timer = 2; break; case 20: // echo farm no - SERIAL_ECHO("{"); + SERIAL_ECHO('{'); prusa_stat_printerstatus(status_number); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); farm_timer = 4; break; case 21: // temperatures - SERIAL_ECHO("{"); + SERIAL_ECHO('{'); prusa_stat_temperatures(); prusa_stat_farm_number(); prusa_stat_printerstatus(status_number); - SERIAL_ECHOLN("}"); break; case 22: // waiting for filament change SERIAL_ECHO("{[PRN:5]"); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); status_number = 5; break; case 90: // Error - Thermal Runaway - SERIAL_ECHO("{[ERR:1]"); - prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); + prusa_statistics_err('1'); break; case 91: // Error - Thermal Runaway Preheat - SERIAL_ECHO("{[ERR:2]"); - prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); + prusa_statistics_err('2'); break; case 92: // Error - Min temp - SERIAL_ECHO("{[ERR:3]"); - prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); + prusa_statistics_err('3'); break; case 93: // Error - Max temp - SERIAL_ECHO("{[ERR:4]"); - prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); + prusa_statistics_err('4'); break; case 99: // heartbeat @@ -4128,11 +4103,11 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { prusa_stat_temperatures(); SERIAL_ECHO("[PFN:"); SERIAL_ECHO(farm_no); - SERIAL_ECHO("]"); - SERIAL_ECHOLN("}"); + SERIAL_ECHO(']'); break; } + SERIAL_ECHOLN('}'); } @@ -4140,19 +4115,19 @@ static void prusa_stat_printerstatus(int _status) { SERIAL_ECHO("[PRN:"); SERIAL_ECHO(_status); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); } static void prusa_stat_farm_number() { SERIAL_ECHO("[PFN:"); SERIAL_ECHO(farm_no); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); } static void prusa_stat_diameter() { SERIAL_ECHO("[DIA:"); SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); } static void prusa_stat_temperatures() @@ -4165,7 +4140,7 @@ static void prusa_stat_temperatures() SERIAL_ECHO(current_temperature[0]); SERIAL_ECHO("][ATB:"); SERIAL_ECHO(current_temperature_bed); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); } static void prusa_stat_printinfo() @@ -4189,7 +4164,7 @@ static void prusa_stat_printinfo() } SERIAL_ECHO("][FWR:"); SERIAL_ECHO(FW_VERSION); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); prusa_stat_diameter(); } From 759d9f5a2ee362eab5ca9184bbf7994ba6ced219 Mon Sep 17 00:00:00 2001 From: NotaRobotexe Date: Mon, 15 Jul 2019 11:41:16 +0200 Subject: [PATCH 05/19] small text edits --- Firmware/sound.h | 2 +- lang/lang_en_cz.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Firmware/sound.h b/Firmware/sound.h index 2c14dfee..bdd32ec8 100644 --- a/Firmware/sound.h +++ b/Firmware/sound.h @@ -6,7 +6,7 @@ #define MSG_SOUND_MODE_LOUD "Sound [loud]" #define MSG_SOUND_MODE_ONCE "Sound [once]" #define MSG_SOUND_MODE_SILENT "Sound [silent]" -#define MSG_SOUND_MODE_BLIND "Sound [blind]" +#define MSG_SOUND_MODE_BLIND "Sound [blind]" #define e_SOUND_MODE_NULL 0xFF diff --git a/lang/lang_en_cz.txt b/lang/lang_en_cz.txt index 027d0409..b4f61333 100755 --- a/lang/lang_en_cz.txt +++ b/lang/lang_en_cz.txt @@ -828,7 +828,7 @@ # "Press the knob" -"Stisknete hl. tlacitko" +"Stisknete tlacitko" #MSG_PRINT_PAUSED c=20 r=1 "Print paused" From 8fb30f886a6090fa5bab5beb73a63af3a82e6c28 Mon Sep 17 00:00:00 2001 From: NotaRobotexe Date: Mon, 15 Jul 2019 14:30:21 +0200 Subject: [PATCH 06/19] octoprint stop fix --- Firmware/Marlin_main.cpp | 6 +++++- Firmware/temperature.cpp | 2 +- Firmware/ultralcd.cpp | 1 - 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 3bde7239..6f43c7f8 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6734,6 +6734,10 @@ Sigma_Exit: } break; + case 603: { //! M603 - Stop print + lcd_print_stop(); + } + #ifdef PINDA_THERMISTOR case 860: // M860 - Wait for PINDA thermistor to reach target temperature. { @@ -9501,7 +9505,6 @@ void restore_print_from_ram_and_continue(float e_move) card.setIndex(saved_sdpos); sdpos_atomic = saved_sdpos; card.sdprinting = true; - printf_P(PSTR("ok\n")); //dummy response because of octoprint is waiting for this } else if (saved_printing_type == PRINTING_TYPE_USB) { //was usb printing gcode_LastN = saved_sdpos; //saved_sdpos was reused for storing line number when usb printing @@ -9511,6 +9514,7 @@ void restore_print_from_ram_and_continue(float e_move) else { //not sd printing nor usb printing } + printf_P(PSTR("ok\n")); //dummy response because of octoprint is waiting for this lcd_setstatuspgm(_T(WELCOME_MSG)); saved_printing = false; } diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 779bee32..536e96bf 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -547,7 +547,7 @@ void fanSpeedError(unsigned char _fan) { } else { fan_check_error = EFCE_DETECTED; - + SERIAL_ECHOLNPGM("// action:pause"); //for octoprint } } else { diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e1d9e0ab..e8790886 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6952,7 +6952,6 @@ void lcd_print_stop() if(!card.sdprinting) { SERIAL_ECHOLNPGM("// action:cancel"); // for Octoprint - return; } saved_printing = false; cancel_heatup = true; From 2e25a853f495b172483fb0e9c966d63d5376e732 Mon Sep 17 00:00:00 2001 From: Marek Kuhn Date: Mon, 15 Jul 2019 19:34:12 +0200 Subject: [PATCH 07/19] Added prusatat test --- CMakeLists.txt | 1 + Tests/PrusaStatistics_test.cpp | 340 +++++++++++++++++++++++++++++++++ 2 files changed, 341 insertions(+) create mode 100644 Tests/PrusaStatistics_test.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index c0c2aacd..4ca1d95b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ set(TEST_SOURCES Tests/Example_test.cpp Tests/Timer_test.cpp Tests/AutoDeplete_test.cpp + Tests/PrusaStatistics_test.cpp Firmware/Timer.cpp Firmware/AutoDeplete.cpp ) diff --git a/Tests/PrusaStatistics_test.cpp b/Tests/PrusaStatistics_test.cpp new file mode 100644 index 00000000..fd934a44 --- /dev/null +++ b/Tests/PrusaStatistics_test.cpp @@ -0,0 +1,340 @@ +/** + * @file + * @author Marek Kuhn + */ + +// For now the functions are just COPIED (lots of depencendies in ultralcd.h) + +#include "catch.hpp" +#include + +// Mocking Serial line +std::string SERIAL_BUFFER = ""; + +//#define SERIAL_ECHO(s) ( SERIAL_BUFFER += s ) +/* +#define SERIAL_FLUSH() ( SERIAL_BUFFER.clear() ) +#define SERIAL_ECHOLN(s) { \ + SERIAL_ECHO(s); \ + SERIAL_BUFFER += "\n"; \ +} +*/ +void SERIAL_ECHO(std::string s){ + SERIAL_BUFFER += s; +} + +void SERIAL_ECHO(int i){ + SERIAL_BUFFER += std::to_string(i); +} + +void SERIAL_ECHOLN(std::string s){ + SERIAL_BUFFER += s + "\n"; +} + +void SERIAL_FLUSH(){ + SERIAL_BUFFER.clear(); +} + +std::string itostr3(int i){ + return std::to_string(i); +} + +int _millis(){return 10000;} + +int farm_no; +int busy_state; +int PAUSED_FOR_USER; +int status_number; +int total_filament_used; +int feedmultiply; +int longFilenameOLD; +int starttime; + +int target_temperature[1] = {215}; +int current_temperature[1] = {204}; +int target_temperature_bed = 60; +int current_temperature_bed = 55; + +std::string FW_VERSION; + +struct Card { + int percentDone(){ return 50; } +} card; + +void setup_mockups(){ + farm_no = 0; + + busy_state = 0; + status_number = 0; + PAUSED_FOR_USER = 0; + + total_filament_used = 0; + feedmultiply = 0; + longFilenameOLD = 0; + starttime = 0; + + FW_VERSION = "3.8.0"; +} + +/* +void prusa_statistics(int _message, uint8_t _fil_nr) { +#ifdef DEBUG_DISABLE_PRUSA_STATISTICS + return; +#endif //DEBUG_DISABLE_PRUSA_STATISTICS + switch (_message) + { + + case 0: // default message + if (busy_state == PAUSED_FOR_USER) + { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(15); + prusa_stat_farm_number(); + prusa_stat_printinfo(); + SERIAL_ECHOLN("}"); + status_number = 15; + } + else if (isPrintPaused || card.paused) + { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(14); + prusa_stat_farm_number(); + prusa_stat_printinfo(); + SERIAL_ECHOLN("}"); + status_number = 14; + } + else if (IS_SD_PRINTING) + { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(4); + prusa_stat_farm_number(); + prusa_stat_printinfo(); + SERIAL_ECHOLN("}"); + status_number = 4; + } + else + { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(1); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 1; + } + break; + + case 1: // 1 heating + farm_status = 2; + SERIAL_ECHO("{"); + prusa_stat_printerstatus(2); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 2; + farm_timer = 1; + break; + + case 2: // heating done + farm_status = 3; + SERIAL_ECHO("{"); + prusa_stat_printerstatus(3); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 3; + farm_timer = 1; + + if (IS_SD_PRINTING) + { + farm_status = 4; + SERIAL_ECHO("{"); + prusa_stat_printerstatus(4); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 4; + } + else + { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(3); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 3; + } + farm_timer = 1; + break; + + case 3: // filament change + + break; + case 4: // print succesfull + SERIAL_ECHO("{[RES:1][FIL:"); + MYSERIAL.print(int(_fil_nr)); + SERIAL_ECHO("]"); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + farm_timer = 2; + break; + case 5: // print not succesfull + SERIAL_ECHO("{[RES:0][FIL:"); + MYSERIAL.print(int(_fil_nr)); + SERIAL_ECHO("]"); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + farm_timer = 2; + break; + case 6: // print done + SERIAL_ECHO("{[PRN:8]"); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 8; + farm_timer = 2; + break; + case 7: // print done - stopped + SERIAL_ECHO("{[PRN:9]"); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 9; + farm_timer = 2; + break; + case 8: // printer started + SERIAL_ECHO("{[PRN:0][PFN:"); + status_number = 0; + SERIAL_ECHO(farm_no); + SERIAL_ECHOLN("]}"); + farm_timer = 2; + break; + case 20: // echo farm no + SERIAL_ECHO("{"); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + farm_timer = 4; + break; + case 21: // temperatures + SERIAL_ECHO("{"); + prusa_stat_temperatures(); + prusa_stat_farm_number(); + prusa_stat_printerstatus(status_number); + SERIAL_ECHOLN("}"); + break; + case 22: // waiting for filament change + SERIAL_ECHO("{[PRN:5]"); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + status_number = 5; + break; + + case 90: // Error - Thermal Runaway + SERIAL_ECHO("{[ERR:1]"); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + break; + case 91: // Error - Thermal Runaway Preheat + SERIAL_ECHO("{[ERR:2]"); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + break; + case 92: // Error - Min temp + SERIAL_ECHO("{[ERR:3]"); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + break; + case 93: // Error - Max temp + SERIAL_ECHO("{[ERR:4]"); + prusa_stat_farm_number(); + SERIAL_ECHOLN("}"); + break; + + case 99: // heartbeat + SERIAL_ECHO("{[PRN:99]"); + prusa_stat_temperatures(); + SERIAL_ECHO("[PFN:"); + SERIAL_ECHO(farm_no); + SERIAL_ECHO("]"); + SERIAL_ECHOLN("}"); + + break; + } + +} +*/ +static void prusa_stat_printerstatus(int _status) +{ + SERIAL_ECHO("[PRN:"); + SERIAL_ECHO(_status); + SERIAL_ECHO("]"); +} + +static void prusa_stat_farm_number() { + SERIAL_ECHO("[PFN:"); + SERIAL_ECHO(farm_no); + SERIAL_ECHO("]"); +} + +static void prusa_stat_temperatures() +{ + SERIAL_ECHO("[ST0:"); + SERIAL_ECHO(target_temperature[0]); + SERIAL_ECHO("][STB:"); + SERIAL_ECHO(target_temperature_bed); + SERIAL_ECHO("][AT0:"); + SERIAL_ECHO(current_temperature[0]); + SERIAL_ECHO("][ATB:"); + SERIAL_ECHO(current_temperature_bed); + SERIAL_ECHO("]"); +} + +static void prusa_stat_printinfo() +{ + SERIAL_ECHO("[TFU:"); + SERIAL_ECHO(total_filament_used); + SERIAL_ECHO("][PCD:"); + SERIAL_ECHO(itostr3(card.percentDone())); + SERIAL_ECHO("][FEM:"); + SERIAL_ECHO(itostr3(feedmultiply)); + SERIAL_ECHO("][FNM:"); + SERIAL_ECHO(longFilenameOLD); + SERIAL_ECHO("][TIM:"); + if (starttime != 0) + { + SERIAL_ECHO(_millis() / 1000 - starttime / 1000); + } + else + { + SERIAL_ECHO(0); + } + SERIAL_ECHO("][FWR:"); + SERIAL_ECHO(FW_VERSION); + SERIAL_ECHO("]"); +} + + +TEST_CASE("Printer status is shown", "[prusa_stats]") +{ + SERIAL_FLUSH(); + prusa_stat_printerstatus(1); + CHECK(SERIAL_BUFFER.compare("[PRN:1]") == 0); +} + +TEST_CASE("Printer info is showsn", "[prusa_stats]") +{ + SERIAL_FLUSH(); + setup_mockups(); + prusa_stat_printinfo(); + CHECK(SERIAL_BUFFER.compare("[TFU:0][PCD:50][FEM:0][FNM:0][TIM:0][FWR:3.8.0]") == 0); +} + +TEST_CASE("Printer temperatures are shown", "[prusa_stats]") +{ + SERIAL_FLUSH(); + setup_mockups(); + prusa_stat_temperatures(); + CHECK(SERIAL_BUFFER.compare("[ST0:215][STB:60][AT0:204][ATB:55]") == 0); +} + +TEST_CASE("Prusa_statistics Paused test", "[prusa_stats]") +{ + + + CHECK(1 == 1); +} From 1f4542fe8bd4300efbb9ea0fc01c78aaf7bcb819 Mon Sep 17 00:00:00 2001 From: Marek Kuhn Date: Tue, 16 Jul 2019 15:41:28 +0200 Subject: [PATCH 08/19] Added unit test for prusa_statistics --- Tests/PrusaStatistics_test.cpp | 545 +++++++++++++++++++++++++++++---- 1 file changed, 491 insertions(+), 54 deletions(-) diff --git a/Tests/PrusaStatistics_test.cpp b/Tests/PrusaStatistics_test.cpp index fd934a44..05aaa363 100644 --- a/Tests/PrusaStatistics_test.cpp +++ b/Tests/PrusaStatistics_test.cpp @@ -8,37 +8,15 @@ #include "catch.hpp" #include -// Mocking Serial line -std::string SERIAL_BUFFER = ""; - -//#define SERIAL_ECHO(s) ( SERIAL_BUFFER += s ) -/* -#define SERIAL_FLUSH() ( SERIAL_BUFFER.clear() ) -#define SERIAL_ECHOLN(s) { \ - SERIAL_ECHO(s); \ - SERIAL_BUFFER += "\n"; \ -} -*/ -void SERIAL_ECHO(std::string s){ - SERIAL_BUFFER += s; -} - -void SERIAL_ECHO(int i){ - SERIAL_BUFFER += std::to_string(i); -} - -void SERIAL_ECHOLN(std::string s){ - SERIAL_BUFFER += s + "\n"; -} - -void SERIAL_FLUSH(){ - SERIAL_BUFFER.clear(); -} std::string itostr3(int i){ return std::to_string(i); } +std::string eeprom_read_word(uint16_t* i){ + return "eeprom_read"; +} + int _millis(){return 10000;} int farm_no; @@ -49,18 +27,28 @@ int total_filament_used; int feedmultiply; int longFilenameOLD; int starttime; +int isPrintPaused; +int IS_SD_PRINTING; +int farm_status; +int farm_timer; +int loading_flag; -int target_temperature[1] = {215}; -int current_temperature[1] = {204}; -int target_temperature_bed = 60; -int current_temperature_bed = 55; +int target_temperature[1]; +int current_temperature[1]; +int target_temperature_bed; +int current_temperature_bed; + +uint16_t nozzle_diameter; +uint16_t* EEPROM_NOZZLE_DIAMETER_uM; std::string FW_VERSION; struct Card { + int paused = 0; int percentDone(){ return 50; } } card; + void setup_mockups(){ farm_no = 0; @@ -74,9 +62,119 @@ void setup_mockups(){ starttime = 0; FW_VERSION = "3.8.0"; + + isPrintPaused = 0; + IS_SD_PRINTING = 0; + farm_status = 0; + farm_timer = 1; + loading_flag = 0; + + target_temperature[0] = {215}; + current_temperature[0] = {204}; + target_temperature_bed = 60; + current_temperature_bed = 55; + + nozzle_diameter = 400; + EEPROM_NOZZLE_DIAMETER_uM = &nozzle_diameter; + +} + + +// Copy of pre 3.8 version set of functions +namespace old_code +{ + +// Mocking Serial line +std::string SERIAL_BUFFER = ""; + +void SERIAL_ECHO(std::string s){ + SERIAL_BUFFER += s; +} + +void SERIAL_ECHO(int i){ + SERIAL_BUFFER += std::to_string(i); +} + +void SERIAL_ECHO(char c){ + SERIAL_BUFFER += char(c); +} + +void SERIAL_ECHOLN(std::string s){ + SERIAL_BUFFER += s + "\n"; +} + +void SERIAL_ECHOLN(char c){ + SERIAL_BUFFER += char(c); +} + +void SERIAL_RESET(){ + SERIAL_BUFFER.clear(); +} + +struct MySerial { + void print(int i){ + SERIAL_ECHO(i); + } +} MYSERIAL; + + +static void prusa_stat_printerstatus(int _status) +{ + SERIAL_ECHO("[PRN:"); + SERIAL_ECHO(_status); + SERIAL_ECHO("]"); +} + +static void prusa_stat_farm_number() { + SERIAL_ECHO("[PFN:"); + SERIAL_ECHO(farm_no); + SERIAL_ECHO("]"); +} + +static void prusa_stat_diameter() { + SERIAL_ECHO("[DIA:"); + SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)); + SERIAL_ECHO("]"); +} + +static void prusa_stat_temperatures() +{ + SERIAL_ECHO("[ST0:"); + SERIAL_ECHO(target_temperature[0]); + SERIAL_ECHO("][STB:"); + SERIAL_ECHO(target_temperature_bed); + SERIAL_ECHO("][AT0:"); + SERIAL_ECHO(current_temperature[0]); + SERIAL_ECHO("][ATB:"); + SERIAL_ECHO(current_temperature_bed); + SERIAL_ECHO("]"); +} + +static void prusa_stat_printinfo() +{ + SERIAL_ECHO("[TFU:"); + SERIAL_ECHO(total_filament_used); + SERIAL_ECHO("][PCD:"); + SERIAL_ECHO(itostr3(card.percentDone())); + SERIAL_ECHO("][FEM:"); + SERIAL_ECHO(itostr3(feedmultiply)); + SERIAL_ECHO("][FNM:"); + SERIAL_ECHO(longFilenameOLD); + SERIAL_ECHO("][TIM:"); + if (starttime != 0) + { + SERIAL_ECHO(_millis() / 1000 - starttime / 1000); + } + else + { + SERIAL_ECHO(0); + } + SERIAL_ECHO("][FWR:"); + SERIAL_ECHO(FW_VERSION); + SERIAL_ECHO("]"); + prusa_stat_diameter(); } -/* void prusa_statistics(int _message, uint8_t _fil_nr) { #ifdef DEBUG_DISABLE_PRUSA_STATISTICS return; @@ -103,7 +201,7 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { SERIAL_ECHOLN("}"); status_number = 14; } - else if (IS_SD_PRINTING) + else if (IS_SD_PRINTING || loading_flag) { SERIAL_ECHO("{"); prusa_stat_printerstatus(4); @@ -117,6 +215,7 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { SERIAL_ECHO("{"); prusa_stat_printerstatus(1); prusa_stat_farm_number(); + prusa_stat_diameter(); SERIAL_ECHOLN("}"); status_number = 1; } @@ -141,7 +240,7 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { status_number = 3; farm_timer = 1; - if (IS_SD_PRINTING) + if (IS_SD_PRINTING || loading_flag) { farm_status = 4; SERIAL_ECHO("{"); @@ -257,18 +356,62 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { } } -*/ +} + +// Copy of 3.8 version of functions +namespace new_code +{ + +// Mocking Serial line +std::string SERIAL_BUFFER = ""; + +void SERIAL_ECHO(std::string s){ + SERIAL_BUFFER += s; +} + +void SERIAL_ECHO(int i){ + SERIAL_BUFFER += std::to_string(i); +} + +void SERIAL_ECHO(char c){ + SERIAL_BUFFER += char(c); +} + +void SERIAL_ECHOLN(std::string s){ + SERIAL_BUFFER += s + "\n"; +} + +void SERIAL_ECHOLN(char c){ + SERIAL_BUFFER += char(c); +} + +void SERIAL_RESET(){ + SERIAL_BUFFER.clear(); +} + +struct MySerial { + void print(int i){ + SERIAL_ECHO(i); + } +} MYSERIAL; + static void prusa_stat_printerstatus(int _status) -{ +{ SERIAL_ECHO("[PRN:"); SERIAL_ECHO(_status); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); } static void prusa_stat_farm_number() { SERIAL_ECHO("[PFN:"); SERIAL_ECHO(farm_no); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); +} + +static void prusa_stat_diameter() { + SERIAL_ECHO("[DIA:"); + SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)); + SERIAL_ECHO(']'); } static void prusa_stat_temperatures() @@ -281,7 +424,7 @@ static void prusa_stat_temperatures() SERIAL_ECHO(current_temperature[0]); SERIAL_ECHO("][ATB:"); SERIAL_ECHO(current_temperature_bed); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); } static void prusa_stat_printinfo() @@ -305,36 +448,330 @@ static void prusa_stat_printinfo() } SERIAL_ECHO("][FWR:"); SERIAL_ECHO(FW_VERSION); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); + prusa_stat_diameter(); } +void prusa_statistics_err(char c){ + SERIAL_ECHO("{[ERR:"); + SERIAL_ECHO(c); + SERIAL_ECHO(']'); + prusa_stat_farm_number(); +} + + +void prusa_statistics(int _message, uint8_t _fil_nr) { +#ifdef DEBUG_DISABLE_PRUSA_STATISTICS + return; +#endif //DEBUG_DISABLE_PRUSA_STATISTICS + switch (_message) + { + + case 0: // default message + if (busy_state == PAUSED_FOR_USER) + { + status_number = 15; + } + else if (isPrintPaused || card.paused) + { + status_number = 14; + } + else if (IS_SD_PRINTING || loading_flag) + { + status_number = 4; + } + else + { + status_number = 1; + } + SERIAL_ECHO('{'); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + prusa_stat_printinfo(); + break; + + case 1: // 1 heating + farm_status = 2; + SERIAL_ECHO('{'); + prusa_stat_printerstatus(2); + prusa_stat_farm_number(); + status_number = 2; + farm_timer = 1; + break; + + case 2: // heating done + farm_status = 3; + SERIAL_ECHO('{'); + prusa_stat_printerstatus(3); + prusa_stat_farm_number(); + SERIAL_ECHOLN('}'); + status_number = 3; + farm_timer = 1; + + if (IS_SD_PRINTING || loading_flag) + { + farm_status = 4; + SERIAL_ECHO('{'); + prusa_stat_printerstatus(4); + prusa_stat_farm_number(); + status_number = 4; + } + else + { + SERIAL_ECHO('{'); + prusa_stat_printerstatus(3); + prusa_stat_farm_number(); + status_number = 3; + } + farm_timer = 1; + break; + + case 3: // filament change + // must do a return here to prevent doing SERIAL_ECHOLN("}") at the very end of this function + // saved a considerable amount of FLASH + return; + break; + case 4: // print succesfull + SERIAL_ECHO("{[RES:1][FIL:"); + MYSERIAL.print(int(_fil_nr)); + SERIAL_ECHO(']'); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + farm_timer = 2; + break; + case 5: // print not succesfull + SERIAL_ECHO("{[RES:0][FIL:"); + MYSERIAL.print(int(_fil_nr)); + SERIAL_ECHO(']'); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + farm_timer = 2; + break; + case 6: // print done + SERIAL_ECHO("{[PRN:8]"); + prusa_stat_farm_number(); + status_number = 8; + farm_timer = 2; + break; + case 7: // print done - stopped + SERIAL_ECHO("{[PRN:9]"); + prusa_stat_farm_number(); + status_number = 9; + farm_timer = 2; + break; + case 8: // printer started + SERIAL_ECHO("{[PRN:0][PFN:"); + status_number = 0; + SERIAL_ECHO(farm_no); + SERIAL_ECHO(']'); + farm_timer = 2; + break; + case 20: // echo farm no + SERIAL_ECHO('{'); + prusa_stat_printerstatus(status_number); + prusa_stat_farm_number(); + farm_timer = 4; + break; + case 21: // temperatures + SERIAL_ECHO('{'); + prusa_stat_temperatures(); + prusa_stat_farm_number(); + prusa_stat_printerstatus(status_number); + break; + case 22: // waiting for filament change + SERIAL_ECHO("{[PRN:5]"); + prusa_stat_farm_number(); + status_number = 5; + break; + + case 90: // Error - Thermal Runaway + prusa_statistics_err('1'); + break; + case 91: // Error - Thermal Runaway Preheat + prusa_statistics_err('2'); + break; + case 92: // Error - Min temp + prusa_statistics_err('3'); + break; + case 93: // Error - Max temp + prusa_statistics_err('4'); + break; + + case 99: // heartbeat + SERIAL_ECHO("{[PRN:99]"); + prusa_stat_temperatures(); + SERIAL_ECHO("[PFN:"); + SERIAL_ECHO(farm_no); + SERIAL_ECHO(']'); + + break; + } + SERIAL_ECHOLN('}'); + +} + +} // end namespace new + +void SERIALS_RESET(){ + old_code::SERIAL_RESET(); + new_code::SERIAL_RESET(); +} + +std::string SERIALS_SERIALIZE(){ + return old_code::SERIAL_BUFFER + "\n" + new_code::SERIAL_BUFFER; +} +void SERIALS_PRINT(){ + std::cout << "[Printing buffers...] \n"; + std::cout << old_code::SERIAL_BUFFER << "\n"; + std::cout << new_code::SERIAL_BUFFER << "\n"; +} + +int SERIALS_COMPARE(){ + // Trim the newline at the end + + if(old_code::SERIAL_BUFFER.back() == '\n'){ + old_code::SERIAL_BUFFER.pop_back(); + } + if(new_code::SERIAL_BUFFER.back() == '\n'){ + new_code::SERIAL_BUFFER.pop_back(); + } + + std::cout << "Comparing: \n"; + std::cout << old_code::SERIAL_BUFFER << "\n"; + std::cout << new_code::SERIAL_BUFFER << "\n"; + + return old_code::SERIAL_BUFFER.compare(new_code::SERIAL_BUFFER); +} + + +// --------------- TEST CASES ---------------- // + +TEST_CASE("Serials compare ignore newline at the end", "[helper]") +{ + SERIALS_RESET(); + old_code::SERIAL_BUFFER = "Hello compare me."; + new_code::SERIAL_BUFFER = "Hello compare me."; + CHECK(SERIALS_COMPARE() == 0); + + SERIALS_RESET(); + old_code::SERIAL_BUFFER = "Hello compare me.\n"; + new_code::SERIAL_BUFFER = "Hello compare me."; + CHECK(SERIALS_COMPARE() == 0); + + SERIALS_RESET(); + old_code::SERIAL_BUFFER = "Hello compare me."; + new_code::SERIAL_BUFFER = "Hello compare me.\n"; + CHECK(SERIALS_COMPARE() == 0); +} TEST_CASE("Printer status is shown", "[prusa_stats]") { - SERIAL_FLUSH(); - prusa_stat_printerstatus(1); - CHECK(SERIAL_BUFFER.compare("[PRN:1]") == 0); + SERIALS_RESET(); + setup_mockups(); + + old_code::prusa_stat_printerstatus(1); + new_code::prusa_stat_printerstatus(1); + + INFO(SERIALS_SERIALIZE()); + CHECK(SERIALS_COMPARE() == 0); } -TEST_CASE("Printer info is showsn", "[prusa_stats]") + +TEST_CASE("Printer info is shown", "[prusa_stats]") { - SERIAL_FLUSH(); + SERIALS_RESET(); setup_mockups(); - prusa_stat_printinfo(); - CHECK(SERIAL_BUFFER.compare("[TFU:0][PCD:50][FEM:0][FNM:0][TIM:0][FWR:3.8.0]") == 0); + + old_code::prusa_stat_printinfo(); + new_code::prusa_stat_printinfo(); + + INFO(SERIALS_SERIALIZE()); + CHECK(SERIALS_COMPARE() == 0); } TEST_CASE("Printer temperatures are shown", "[prusa_stats]") { - SERIAL_FLUSH(); + SERIALS_RESET(); setup_mockups(); - prusa_stat_temperatures(); - CHECK(SERIAL_BUFFER.compare("[ST0:215][STB:60][AT0:204][ATB:55]") == 0); -} -TEST_CASE("Prusa_statistics Paused test", "[prusa_stats]") -{ + old_code::prusa_stat_temperatures(); + new_code::prusa_stat_temperatures(); - - CHECK(1 == 1); + INFO(SERIALS_SERIALIZE()); + CHECK(SERIALS_COMPARE() == 0); +} + +TEST_CASE("Prusa_statistics test", "[prusa_stats]") +{ + SERIALS_RESET(); + setup_mockups(); + + int test_codes[] = {0,1,2,3,4,5,6,7,8,20,21,22,90,91,92,93,99}; + int size = sizeof(test_codes)/sizeof(test_codes[0]); + + for(int i = 0; i < size; i++){ + std::cout << "Testing prusa_statistics(" << std::to_string(i) << ")\n"; + + switch(i) + { + case 0: { + busy_state = 0; + PAUSED_FOR_USER = 0; + old_code::prusa_statistics(test_codes[i],0); + new_code::prusa_statistics(test_codes[i],0); + CHECK(SERIALS_COMPARE() == 0); + SERIALS_RESET(); + + busy_state = 1; + PAUSED_FOR_USER = 0; + isPrintPaused = 1; + old_code::prusa_statistics(test_codes[i],0); + new_code::prusa_statistics(test_codes[i],0); + CHECK(SERIALS_COMPARE() == 0); + SERIALS_RESET(); + + isPrintPaused = 0; + card.paused = 0; + IS_SD_PRINTING = 1; + old_code::prusa_statistics(test_codes[i],0); + new_code::prusa_statistics(test_codes[i],0); + CHECK(SERIALS_COMPARE() == 0); + SERIALS_RESET(); + + busy_state = 1; + PAUSED_FOR_USER = 0; + isPrintPaused = 0; + IS_SD_PRINTING = 0; + loading_flag = 0; + old_code::prusa_statistics(test_codes[i],0); + new_code::prusa_statistics(test_codes[i],0); + CHECK(SERIALS_COMPARE() == 0); + SERIALS_RESET(); + break; + } + case 2: { + IS_SD_PRINTING = 1; + old_code::prusa_statistics(test_codes[i],0); + new_code::prusa_statistics(test_codes[i],0); + CHECK(SERIALS_COMPARE() == 0); + SERIALS_RESET(); + + IS_SD_PRINTING = 0; + loading_flag = 0; + old_code::prusa_statistics(test_codes[i],0); + new_code::prusa_statistics(test_codes[i],0); + CHECK(SERIALS_COMPARE() == 0); + SERIALS_RESET(); + + break; + } + default:{ + + old_code::prusa_statistics(test_codes[i],0); + new_code::prusa_statistics(test_codes[i],0); + CHECK(SERIALS_COMPARE() == 0); + SERIALS_RESET(); + } + } + } } From e6255e8451acfec30c363561869deac8465f0710 Mon Sep 17 00:00:00 2001 From: NotaRobotexe Date: Tue, 16 Jul 2019 19:18:31 +0200 Subject: [PATCH 09/19] octoprint fan error work --- Firmware/Marlin_main.cpp | 1 - Firmware/messages.c | 1 + Firmware/messages.h | 1 + Firmware/temperature.cpp | 9 +++++---- 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 6f43c7f8..35827021 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -9432,7 +9432,6 @@ void stop_and_save_print_to_ram(float z_move, float e_move) if(!saved_extruder_relative_mode){ enquecommand(PSTR("M83"), true); } - //retract 45mm/s // A single sprintf may not be faster, but is definitely 20B shorter // than a sequence of commands building the string piece by piece diff --git a/Firmware/messages.c b/Firmware/messages.c index 0a750612..5c6cb796 100644 --- a/Firmware/messages.c +++ b/Firmware/messages.c @@ -128,3 +128,4 @@ const char MSG_ENDSTOP_OPEN[] PROGMEM_N1 = "open"; //// const char MSG_POWERUP[] PROGMEM_N1 = "PowerUp"; //// const char MSG_ERR_STOPPED[] PROGMEM_N1 = "Printer stopped due to errors. Fix the error and use M999 to restart. (Temperature is reset. Set it after restarting)"; //// const char MSG_ENDSTOP_HIT[] PROGMEM_N1 = "TRIGGERED"; //// +const char MSG_OCTOPRINT_PAUSE[] PROGMEM_N1 = "// action:pause"; //// diff --git a/Firmware/messages.h b/Firmware/messages.h index 6260e0d3..1dc4880c 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -129,6 +129,7 @@ extern const char MSG_ERR_STOPPED[]; extern const char MSG_ENDSTOP_HIT[]; extern const char MSG_EJECT_FILAMENT[]; extern const char MSG_CUT_FILAMENT[]; +extern const char MSG_OCTOPRINT_PAUSE[]; #if defined(__cplusplus) } diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 536e96bf..f9bb11f8 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -40,7 +40,7 @@ #include #include "adc.h" #include "ConfigurationStore.h" - +#include "messages.h" #include "Timer.h" #include "Configuration_prusa.h" @@ -541,18 +541,18 @@ static void fanSpeedErrorBeep(const char *serialMsg, const char *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 - if (card.sdprinting) { + if (card.sdprinting || is_usb_printing) { if (heating_status != 0) { lcd_print_stop(); } else { fan_check_error = EFCE_DETECTED; - SERIAL_ECHOLNPGM("// action:pause"); //for octoprint + SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); } } else { + SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); //for octoprint setTargetHotend0(0); - SERIAL_ECHOLNPGM("// action:pause"); //for octoprint } switch (_fan) { case 0: // extracting the same code from case 0 and case 1 into a function saves 72B @@ -562,6 +562,7 @@ void fanSpeedError(unsigned char _fan) { fanSpeedErrorBeep(PSTR("Print fan speed is lower than expected"), PSTR("Err: PRINT FAN ERROR") ); break; } + SERIAL_PROTOCOLLNRPGM(MSG_OK); } #endif //(defined(TACH_0) && TACH_0 >-1) || (defined(TACH_1) && TACH_1 > -1) From 1c44eddf8169fb36a3018247a1aa8107b84d5c8a Mon Sep 17 00:00:00 2001 From: NotaRobotexe Date: Wed, 17 Jul 2019 12:32:27 +0200 Subject: [PATCH 10/19] crash and filament unload sound change --- Firmware/sound.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Firmware/sound.cpp b/Firmware/sound.cpp index 7b965a2d..b01285a5 100644 --- a/Firmware/sound.cpp +++ b/Firmware/sound.cpp @@ -61,17 +61,18 @@ switch(eSoundMode) Sound_SaveMode(); } +//if critical is true then silend and once mode is ignored void Sound_MakeCustom(uint16_t ms,uint16_t tone_,bool critical){ if (!critical){ if (eSoundMode != e_SOUND_MODE_SILENT){ if(!tone_){ WRITE(BEEPER, HIGH); - delayMicroseconds(ms); + _delay(ms); WRITE(BEEPER, LOW); } else{ _tone(BEEPER, tone_); - delayMicroseconds(ms); + _delay(ms); _noTone(BEEPER); } } @@ -79,13 +80,13 @@ void Sound_MakeCustom(uint16_t ms,uint16_t tone_,bool critical){ else{ if(!tone_){ WRITE(BEEPER, HIGH); - delayMicroseconds(ms); + _delay(ms); WRITE(BEEPER, LOW); - delayMicroseconds(100); + _delay(ms); } else{ _tone(BEEPER, tone_); - delayMicroseconds(ms); + _delay(ms); _noTone(BEEPER); } } @@ -134,10 +135,10 @@ switch(eSoundMode) static void Sound_DoSound_Blind_Alert(void) { - _tone(BEEPER,100); - delayMicroseconds(50); + _tone(BEEPER,300); + _delay_ms(75); _noTone(BEEPER); - delayMicroseconds(200); + _delay_ms(75); } static void Sound_DoSound_Encoder_Move(void) @@ -169,7 +170,7 @@ for(nI=0;nI<10;nI++) static void Sound_DoSound_Prompt(void) { WRITE(BEEPER,HIGH); -delayMicroseconds(500); +_delay_ms(500); WRITE(BEEPER,LOW); } From b8fec59f216a020c0e28dcdfe06f75d891ea6c68 Mon Sep 17 00:00:00 2001 From: NotaRobotexe Date: Wed, 17 Jul 2019 19:59:31 +0200 Subject: [PATCH 11/19] octoprint fan error fix --- Firmware/Marlin_main.cpp | 11 +++++++++-- Firmware/temperature.cpp | 3 ++- Firmware/ultralcd.cpp | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 35827021..e536df96 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3393,8 +3393,15 @@ void process_commands() if (fan_check_error){ 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 + + if(is_usb_printing){ + SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); + } + else{ + lcd_pause_print(); + } + + } // otherwise it has already been reported, so just ignore further processing return; } #endif diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index f9bb11f8..1ef85549 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -524,6 +524,8 @@ void checkFanSpeed() fan_speed_errors[1] = 0; fanSpeedError(1); //print fan } + + SERIAL_PROTOCOLLNRPGM(MSG_OK); //for octoprint } //! Prints serialMsg to serial port, displays lcdMsg onto the LCD and beeps. @@ -547,7 +549,6 @@ void fanSpeedError(unsigned char _fan) { } else { fan_check_error = EFCE_DETECTED; - SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); } } else { diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index e8790886..c70fe8fc 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -1658,6 +1658,7 @@ void lcd_pause_print() { lcd_commands_type = LcdCommands::LongPause; } + SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); //pause for octoprint } From 121e60655af40e2abee8ede37146f00c55682923 Mon Sep 17 00:00:00 2001 From: leptun Date: Thu, 18 Jul 2019 10:14:03 +0300 Subject: [PATCH 12/19] Fix lcd not initing after WDT reset --- Firmware/lcd.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index b2f90c6c..1f4e6e2f 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -196,8 +196,21 @@ static void lcd_putchar(char c, FILE *) void lcd_init(void) { + WRITE(LCD_PINS_ENABLE,LOW); SET_OUTPUT(LCD_PINS_RS); SET_OUTPUT(LCD_PINS_ENABLE); + +#ifdef LCD_8BIT + SET_OUTPUT(LCD_PINS_D0); + SET_OUTPUT(LCD_PINS_D1); + SET_OUTPUT(LCD_PINS_D2); + SET_OUTPUT(LCD_PINS_D3); +#endif + SET_OUTPUT(LCD_PINS_D4); + SET_OUTPUT(LCD_PINS_D5); + SET_OUTPUT(LCD_PINS_D6); + SET_OUTPUT(LCD_PINS_D7); + #ifdef LCD_8BIT lcd_displayfunction |= LCD_8BITMODE; #endif From 03e80ce4a8eac8855050f967ce8b675732cd5741 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20K=C3=BChn?= Date: Thu, 18 Jul 2019 16:50:44 +0200 Subject: [PATCH 13/19] PFW-917 Adjust Z value persists across update to v3.8 --- Firmware/eeprom.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp index 1be708d0..f2d89716 100644 --- a/Firmware/eeprom.cpp +++ b/Firmware/eeprom.cpp @@ -71,6 +71,12 @@ void eeprom_init() } if(is_uninitialized) { + // When upgrading from version older version (before multiple sheets were implemented in v3.8.0) + // Sheet 1 uses the previous Live adjust Z (@EEPROM_BABYSTEP_Z) + if(i == 0){ + int last_babystep = eeprom_read_word((uint16_t *)EEPROM_BABYSTEP_Z); + eeprom_write_word(reinterpret_cast(&(EEPROM_Sheets_base->s[i].z_offset)), last_babystep); + } eeprom_write(&(EEPROM_Sheets_base->s[i].name[0]), static_cast(i + '1')); eeprom_write(&(EEPROM_Sheets_base->s[i].name[1]), '\0'); } From 94e79806bce1c73bae384b6b25ecd64585078bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20K=C3=BChn?= Date: Fri, 19 Jul 2019 13:51:55 +0200 Subject: [PATCH 14/19] Updated doxygen docs to work better with confluence. --- Firmware/Marlin_main.cpp | 936 +++++++++++++++++++++++++++++++-------- Firmware/doxyfile | 2 +- 2 files changed, 763 insertions(+), 175 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 8ac1aaf5..0415b2bf 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -3256,14 +3256,19 @@ extern uint8_t st_backlash_x; extern uint8_t st_backlash_y; #endif //BACKLASH_Y +//! \ingroup marlin_main + //! @brief Parse and process commands //! //! look here for descriptions of G-codes: http://linuxcnc.org/handbook/gcode/g-code.html //! http://objects.reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes //! -//! Implemented Codes +//! +//! Implemented Codes //! ------------------- //! +//! * _This list is not updated. Current documentation is maintained inside the process_cmd function._ +//! //!@n PRUSA CODES //!@n P F - Returns FW versions //!@n P R - Returns revision of printer @@ -3386,6 +3391,15 @@ extern uint8_t st_backlash_y; //! //!@n M928 - Start SD logging (M928 filename.g) - ended by M29 //!@n M999 - Restart after being stopped by error +//!

+ +/** @defgroup marlin_main Marlin main */ + +/** \ingroup GCodes */ + +//! _This is a list of currently implemented G Codes in Prusa firmware (dynamically generated from doxygen)_ + + void process_commands() { #ifdef FANCHECK @@ -3444,21 +3458,33 @@ void process_commands() #ifdef TMC2130 else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("CRASH_"), 6) == 0) { - if(code_seen("CRASH_DETECTED")) //! CRASH_DETECTED + + //! ### CRASH_DETECTED - TMC2130 + // --------------------------------- + if(code_seen("CRASH_DETECTED")) { uint8_t mask = 0; if (code_seen('X')) mask |= X_AXIS_MASK; if (code_seen('Y')) mask |= Y_AXIS_MASK; crashdet_detected(mask); } - else if(code_seen("CRASH_RECOVER")) //! CRASH_RECOVER + + //! ### CRASH_RECOVER - TMC2130 + // ---------------------------------- + else if(code_seen("CRASH_RECOVER")) crashdet_recover(); - else if(code_seen("CRASH_CANCEL")) //! CRASH_CANCEL + + //! ### CRASH_CANCEL - TMC2130 + // ---------------------------------- + else if(code_seen("CRASH_CANCEL")) crashdet_cancel(); } else if (strncmp_P(CMDBUFFER_CURRENT_STRING, PSTR("TMC_"), 4) == 0) { - if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_WAVE_"), 9) == 0) //! TMC_SET_WAVE_ + + //! ### TMC_SET_WAVE_ + // -------------------- + if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_WAVE_"), 9) == 0) { uint8_t axis = *(CMDBUFFER_CURRENT_STRING + 13); axis = (axis == 'E')?3:(axis - 'X'); @@ -3468,7 +3494,10 @@ void process_commands() tmc2130_set_wave(axis, 247, fac); } } - else if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_STEP_"), 9) == 0) //! TMC_SET_STEP_ + + //! ### TMC_SET_STEP_ + // ------------------ + else if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_STEP_"), 9) == 0) { uint8_t axis = *(CMDBUFFER_CURRENT_STRING + 13); axis = (axis == 'E')?3:(axis - 'X'); @@ -3479,7 +3508,10 @@ void process_commands() tmc2130_goto_step(axis, step & (4*res - 1), 2, 1000, res); } } - else if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_CHOP_"), 9) == 0) //! TMC_SET_CHOP_ + + //! ### TMC_SET_CHOP_ + // ------------------- + else if (strncmp_P(CMDBUFFER_CURRENT_STRING + 4, PSTR("SET_CHOP_"), 9) == 0) { uint8_t axis = *(CMDBUFFER_CURRENT_STRING + 13); axis = (axis == 'E')?3:(axis - 'X'); @@ -3530,19 +3562,50 @@ void process_commands() } #endif //BACKLASH_Y #endif //TMC2130 - else if(code_seen("PRUSA")){ - if (code_seen("Ping")) { //! PRUSA Ping + else if(code_seen("PRUSA")){ + /*! + * + ### PRUSA - Internal command set + + Set of internal PRUSA commands + + PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | fsensor_recover | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | Beat | FR ] + + - `Ping` + - `PRN` - Prints revision of the printer + - `FAN` - Prints fan details + - `fn` - Prints farm no. + - `thx` + - `uvlo` + - `fsensor_recover` - Filament sensor recover - restore print and continue + - `MMURES` - Reset MMU + - `RESET` - (Careful!) + - `fv` - ? + - `M28` + - `SN` + - `Fir` - Prints firmware version + - `Rev`- Prints filament size, elelectronics, nozzle type + - `Lang` - Reset the language + - `Lz` + - `Beat` - Kick farm link timer + - `FR` - Full factory reset + - `nozzle D G1 case 1: // G1 if(Stopped == false) { @@ -3907,19 +3973,30 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) //ClearToSend(); } break; - case 2: // G2 - CW ARC + + //! ### G2 - CW ARC + // ------------------------------ + case 2: if(Stopped == false) { get_arc_coordinates(); prepare_arc_move(true); } break; - case 3: // G3 - CCW ARC + + + //! ### G3 - CCW ARC + // ------------------------------- + case 3: if(Stopped == false) { get_arc_coordinates(); prepare_arc_move(false); } break; - case 4: // G4 dwell + + + //! ### G4 - Dwell + // ------------------------------- + case 4: codenum = 0; if(code_seen('P')) codenum = code_value(); // milliseconds to wait if(code_seen('S')) codenum = code_value() * 1000; // seconds to wait @@ -3934,7 +4011,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; #ifdef FWRETRACT - case 10: // G10 retract + + + //! ### G10 Retract + // ------------------------------ + case 10: #if EXTRUDERS > 1 retracted_swap[active_extruder]=(code_seen('S') && code_value_long() == 1); // checks for swap retract argument retract(true,retracted_swap[active_extruder]); @@ -3942,7 +4023,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) retract(true); #endif break; - case 11: // G11 retract_recover + + + //! ### G11 - Retract recover + // ----------------------------- + case 11: #if EXTRUDERS > 1 retract(false,retracted_swap[active_extruder]); #else @@ -3950,7 +4035,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif break; #endif //FWRETRACT - case 28: //G28 Home all Axis one at a time + + + //! ### G28 - Home all Axis one at a time + // -------------------------------------------- + case 28: { long home_x_value = 0; long home_y_value = 0; @@ -3977,8 +4066,13 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; } + #ifdef ENABLE_AUTO_BED_LEVELING - case 29: // G29 Detailed Z-Probe, probes the bed at 3 or more points. + + + //! ### G29 - Detailed Z-Probe + // -------------------------------- + case 29: { #if Z_MIN_PIN == -1 #error "You must have a Z_MIN endstop in order to enable Auto Bed Leveling feature! Z_MIN_PIN must point to a valid hardware pin." @@ -4121,7 +4215,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; #ifndef Z_PROBE_SLED - case 30: // G30 Single Z Probe + + //! ### G30 - Single Z Probe + // ------------------------------------ + case 30: { st_synchronize(); // TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly @@ -4143,17 +4240,27 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; #else - case 31: // dock the sled + + //! ### G31 - Dock the sled + // --------------------------- + case 31: dock_sled(true); break; - case 32: // undock the sled + + + //! ### G32 - Undock the sled + // ---------------------------- + case 32: dock_sled(false); break; #endif // Z_PROBE_SLED #endif // ENABLE_AUTO_BED_LEVELING #ifdef MESH_BED_LEVELING - case 30: // G30 Single Z Probe + + //! ### G30 - Single Z Probe + // ---------------------------- + case 30: { st_synchronize(); // TODO: make sure the bed_level_rotation_matrix is identity or the planner will get set incorectly @@ -4169,7 +4276,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - + //! ### G75 - Print temperature interpolation + // --------------------------------------------- case 75: { for (int i = 40; i <= 110; i++) @@ -4177,7 +4285,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - case 76: //! G76 - PINDA probe temperature calibration + //! ### G76 - PINDA probe temperature calibration + // ------------------------------------------------ + case 76: { #ifdef PINDA_THERMISTOR if (true) @@ -4434,18 +4544,16 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; - - /** - * G80: Mesh-based Z probe, probes a grid and produces a - * mesh to compensate for variable bed height - * + //! ### G80 - Mesh-based Z probe + // ----------------------------------- + + /* + * Probes a grid and produces a mesh to compensate for variable bed height * The S0 report the points as below - * @code{.unparsed} * +----> X-axis * | * | * v Y-axis - * @endcode */ case 80: @@ -4869,8 +4977,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /** - * G81: Print mesh bed leveling status and bed profile if activated + //! ### G81 - Mesh bed leveling status + // ----------------------------------------- + + /* + * Prints mesh bed leveling status and bed profile if activated */ case 81: if (mbl.active) { @@ -4894,7 +5005,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #if 0 - /** + /* * G82: Single Z probe at current location * * WARNING! USE WITH CAUTION! If you'll try to probe where is no leveling pad, nasty things can happen! @@ -4910,7 +5021,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) SERIAL_PROTOCOLPGM("\n"); break; - /** + /* * G83: Prusa3D specific: Babystep in Z and store to EEPROM */ case 83: @@ -4935,7 +5046,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - /** + /* * G84: Prusa3D specific: UNDO Babystep Z (move Z axis back) */ case 84: @@ -4943,7 +5054,7 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) // babystepLoadZ = 0; break; - /** + /* * G85: Prusa3D specific: Pick best babystep */ case 85: @@ -4951,38 +5062,58 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #endif - /** - * G86: Prusa3D specific: Disable babystep correction after home. - * This G-code will be performed at the start of a calibration script. - */ + /** + * ### G86 - Disable babystep correction after home + * + * This G-code will be performed at the start of a calibration script. + * (Prusa3D specific) + */ case 86: calibration_status_store(CALIBRATION_STATUS_LIVE_ADJUST); break; - /** - * G87: Prusa3D specific: Enable babystep correction after home - * This G-code will be performed at the end of a calibration script. - */ + + + /** + * ### G87 - Enable babystep correction after home + * + * + * This G-code will be performed at the end of a calibration script. + * (Prusa3D specific) + */ case 87: calibration_status_store(CALIBRATION_STATUS_CALIBRATED); break; - /** - * G88: Prusa3D specific: Don't know what it is for, it is in V2Calibration.gcode - */ + + /** + * ### G88 - Reserved + * + * Currently has no effect. + */ + + // Prusa3D specific: Don't know what it is for, it is in V2Calibration.gcode + case 88: break; #endif // ENABLE_MESH_BED_LEVELING - - case 90: // G90 + //! ### G90 - Switch off relative mode + // ------------------------------- + case 90: relative_mode = false; break; - case 91: // G91 + + //! ### G91 - Switch on relative mode + // ------------------------------- + case 91: relative_mode = true; break; - case 92: // G92 + + //! ### G92 - Set position + // ----------------------------- + case 92: if(!code_seen(axis_codes[E_AXIS])) st_synchronize(); for(int8_t i=0; i < NUM_AXIS; i++) { @@ -4999,7 +5130,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } break; - case 98: //! G98 (activate farm mode) + + //! ### G98 - Activate farm mode + // ----------------------------------- + case 98: farm_mode = 1; PingTime = _millis(); eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode); @@ -5009,7 +5143,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) fCheckModeInit(); // alternatively invoke printer reset break; - case 99: //! G99 (deactivate farm mode) + //! ### G99 - Deactivate farm mode + // ------------------------------------- + case 99: farm_mode = 0; lcd_printer_connected(); eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode); @@ -5023,6 +5159,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) gcode_in_progress = 0; } // end if(code_seen('G')) + + //! --------------------------------------------------------------------------------- + else if(code_seen('M')) { @@ -5041,6 +5180,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) switch(mcode_in_progress) { + //! ### M0, M1 - Stop the printer + // --------------------------------------------------------------- case 0: // M0 - Unconditional stop - Wait for user button press on LCD case 1: // M1 - Conditional stop - Wait for user button press on LCD { @@ -5088,6 +5229,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) LCD_MESSAGERPGM(_T(WELCOME_MSG)); } break; + + //! ### M17 - Enable axes + // --------------------------------- case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE enable_x(); @@ -5099,44 +5243,68 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) break; #ifdef SDSUPPORT - case 20: // M20 - list SD card + + //! ### M20 - SD Card file list + // ----------------------------------- + case 20: SERIAL_PROTOCOLLNRPGM(_N("Begin file list"));////MSG_BEGIN_FILE_LIST card.ls(); SERIAL_PROTOCOLLNRPGM(_N("End file list"));////MSG_END_FILE_LIST break; - case 21: // M21 - init SD card + //! ### M21 - Init SD card + // ------------------------------------ + case 21: card.initsd(); - break; - case 22: //M22 - release SD card + + //! ### M22 - Release SD card + // ----------------------------------- + case 22: card.release(); - break; - case 23: //M23 - Select file + + //! ### M23 - Select file + // ----------------------------------- + case 23: starpos = (strchr(strchr_pointer + 4,'*')); if(starpos!=NULL) *(starpos)='\0'; card.openFile(strchr_pointer + 4,true); break; - case 24: //M24 - Start SD print + + //! ### M24 - Start SD print + // ---------------------------------- + case 24: if (!card.paused) failstats_reset_print(); card.startFileprint(); starttime=_millis(); break; - case 25: //M25 - Pause SD print + + //! ### M25 - Pause SD print + // ---------------------------------- + case 25: card.pauseSDPrint(); break; - case 26: //M26 - Set SD index + + //! ### M26 - Set SD index + // ---------------------------------- + case 26: if(card.cardOK && code_seen('S')) { card.setIndex(code_value_long()); } break; - case 27: //M27 - Get SD status + + //! ### M27 - Get SD status + // ---------------------------------- + case 27: card.getStatus(); break; - case 28: //M28 - Start SD write + + //! ### M28 - Start SD write + // --------------------------------- + case 28: starpos = (strchr(strchr_pointer + 4,'*')); if(starpos != NULL){ char* npos = strchr(CMDBUFFER_CURRENT_STRING, 'N'); @@ -5145,11 +5313,18 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } card.openFile(strchr_pointer+4,false); break; - case 29: //M29 - Stop SD write + + //! ### M29 - Stop SD write + // ------------------------------------- + //! Currently has no effect. + case 29: //processed in write to file routine above //card,saving = false; break; - case 30: //M30 Delete File + + //! ### M30 - Delete file + // ---------------------------------- + case 30: if (card.cardOK){ card.closefile(); starpos = (strchr(strchr_pointer + 4,'*')); @@ -5161,7 +5336,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) card.removeFile(strchr_pointer + 4); } break; - case 32: //M32 - Select file and start SD print + + //! ### M32 - Select file and start SD print + // ------------------------------------ + case 32: { if(card.sdprinting) { st_synchronize(); @@ -5196,7 +5374,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) starttime=_millis(); //procedure calls count as normal print time. } } break; - case 928: //M928 - Start SD write + + //! ### M982 - Start SD write + // --------------------------------- + case 928: starpos = (strchr(strchr_pointer + 5,'*')); if(starpos != NULL){ char* npos = strchr(CMDBUFFER_CURRENT_STRING, 'N'); @@ -5208,6 +5389,8 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #endif //SDSUPPORT + //! ### M31 - Report current print time + // -------------------------------------------------- case 31: //M31 take time since the start of the SD print or an M109 command { stoptime=_millis(); @@ -5223,7 +5406,10 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) autotempShutdown(); } break; - case 42: //M42 -Change pin status via gcode + + //! ### M42 - Set pin state + // ----------------------------- + case 42: if (code_seen('S')) { int pin_status = code_value(); @@ -5250,7 +5436,11 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } } break; - case 44: //! M44: Prusa3D: Reset the bed skew and offset calibration. + + + //! ### M44 - Reset the bed skew and offset calibration (Prusa specific) + // -------------------------------------------------------------------- + case 44: // M44: Prusa3D: Reset the bed skew and offset calibration. // Reset the baby step value and the baby step applied flag. calibration_status_store(CALIBRATION_STATUS_ASSEMBLED); @@ -5264,7 +5454,9 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) world2machine_revert_to_uncorrected(); break; - case 45: //! M45: Prusa3D: bed skew and offset with manual Z up + //! ### M45 - Bed skew and offset with manual Z up (Prusa specific) + // ------------------------------------------------------ + case 45: // M45: Prusa3D: bed skew and offset with manual Z up { int8_t verbosity_level = 0; bool only_Z = code_seen('Z'); @@ -5303,15 +5495,17 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) } */ + //! ### M47 - Show end stops dialog on the display (Prusa specific) + // ---------------------------------------------------- case 47: - //! M47: Prusa3D: Show end stops dialog on the display. + KEEPALIVE_STATE(PAUSED_FOR_USER); lcd_diag_show_end_stops(); KEEPALIVE_STATE(IN_HANDLER); break; #if 0 - case 48: //! M48: scan the bed induction sensor points, print the sensor trigger coordinates to the serial line for visualization on the PC. + case 48: // M48: scan the bed induction sensor points, print the sensor trigger coordinates to the serial line for visualization on the PC. { // Disable the default update procedure of the display. We will do a modal dialog. lcd_update_enable(false); @@ -5349,11 +5543,15 @@ if(eSoundMode!=e_SOUND_MODE_SILENT) #ifdef ENABLE_AUTO_BED_LEVELING #ifdef Z_PROBE_REPEATABILITY_TEST - //! M48 Z-Probe repeatability measurement function. + + //! ### M48 - Z-Probe repeatability measurement function. + // ------------------------------------------------------ //! - //! Usage: M48 - //! - //! This function assumes the bed has been homed. Specificaly, that a G28 command + //! _Usage:_ + //! + //! M48 + //! + //! This function assumes the bed has been homed. Specifically, that a G28 command //! as been issued prior to invoking the M48 Z-Probe repeatability measurement function. //! Any information generated by a prior G29 Bed leveling command will be lost and need to be //! regenerated. @@ -5599,6 +5797,13 @@ Sigma_Exit: } #endif // Z_PROBE_REPEATABILITY_TEST #endif // ENABLE_AUTO_BED_LEVELING + + //! ### M73 - Set/get print progress + // ------------------------------------- + //! _Usage:_ + //! + //! M73 P R Q S + //! case 73: //M73 show percent done and time remaining if(code_seen('P')) print_percent_done_normal = code_value(); if(code_seen('R')) print_time_remaining_normal = code_value(); @@ -5612,6 +5817,8 @@ Sigma_Exit: } break; + //! ### M104 - Set hotend temperature + // ----------------------------------------- case 104: // M104 { uint8_t extruder; @@ -5625,13 +5832,22 @@ Sigma_Exit: setWatch(); break; } - case 112: // M112 -Emergency Stop + + //! ### M112 - Emergency stop + // ----------------------------------------- + case 112: kill(_n(""), 3); break; - case 140: // M140 set bed temp + + //! ### M140 - Set bed temperature + // ----------------------------------------- + case 140: if (code_seen('S')) setTargetBed(code_value()); break; - case 105 : // M105 + + //! ### M105 - Report temperatures + // ----------------------------------------- + case 105: { uint8_t extruder; if(setTargetedHotend(105, extruder)){ @@ -5725,8 +5941,11 @@ Sigma_Exit: return; break; } + + //! ### M109 - Wait for extruder temperature + // ------------------------------------------------- case 109: - {// M109 - Wait for extruder heater to reach target. + { uint8_t extruder; if(setTargetedHotend(109, extruder)){ break; @@ -5776,7 +5995,10 @@ Sigma_Exit: previous_millis_cmd = _millis(); } break; - case 190: // M190 - Wait for bed heater to reach target. + + //! ### M190 - Wait for bed temperature + // --------------------------------------- + case 190: #if defined(TEMP_BED_PIN) && TEMP_BED_PIN > -1 LCD_MESSAGERPGM(_T(MSG_BED_HEATING)); heating_status = 3; @@ -5827,7 +6049,10 @@ Sigma_Exit: break; #if defined(FAN_PIN) && FAN_PIN > -1 - case 106: //!M106 Sxxx Fan On S 0 .. 255 + + //! ### M106 - Set fan speed + // ------------------------------------------- + case 106: // M106 Sxxx Fan On S 0 .. 255 if (code_seen('S')){ fanSpeed=constrain(code_value(),0,255); } @@ -5835,13 +6060,19 @@ Sigma_Exit: fanSpeed=255; } break; - case 107: //M107 Fan Off + + //! ### M107 - Fan off + // ------------------------------- + case 107: fanSpeed = 0; break; #endif //FAN_PIN #if defined(PS_ON_PIN) && PS_ON_PIN > -1 - case 80: // M80 - Turn on Power Supply + + //! ### M80 - Turn on the Power Supply + // ------------------------------- + case 80: SET_OUTPUT(PS_ON_PIN); //GND WRITE(PS_ON_PIN, PS_ON_AWAKE); @@ -5859,7 +6090,9 @@ Sigma_Exit: break; #endif - case 81: // M81 - Turn off Power Supply + //! ### M81 - Turn off Power Supply + // -------------------------------------- + case 81: disable_heater(); st_synchronize(); disable_e0(); @@ -5880,12 +6113,24 @@ Sigma_Exit: lcd_update(0); break; + //! ### M82 - Set E axis to absolute mode + // --------------------------------------- case 82: axis_relative_modes[3] = false; break; + + //! ### M83 - Set E axis to relative mode + // --------------------------------------- case 83: axis_relative_modes[3] = true; break; + + //! ### M84, M18 - Disable steppers + //--------------------------------------- + //! This command can be used to set the stepper inactivity timeout (`S`) or to disable steppers (`X`,`Y`,`Z`,`E`) + //! + //! M84 [E] [S] [X] [Y] [Z] + //! case 18: //compatibility case 84: // M84 if(code_seen('S')){ @@ -5921,21 +6166,35 @@ Sigma_Exit: print_time_remaining_init(); snmm_filaments_used = 0; break; + + //! ### M85 - Set max inactive time + // --------------------------------------- case 85: // M85 if(code_seen('S')) { max_inactive_time = code_value() * 1000; } break; #ifdef SAFETYTIMER - case 86: // M86 - set safety timer expiration time in seconds; M86 S0 will disable safety timer - //when safety timer expires heatbed and nozzle target temperatures are set to zero + + //! ### M86 - Set safety timer expiration time + //! + //! _Usage:_ + //! M86 S + //! + //! Sets the safety timer expiration time in seconds. M86 S0 will disable safety timer. + //! When safety timer expires, heatbed and nozzle target temperatures are set to zero. + case 86: if (code_seen('S')) { safetytimer_inactive_time = code_value() * 1000; safetyTimer.start(); } break; #endif - case 92: // M92 + + //! ### M92 Set Axis steps-per-unit + // --------------------------------------- + //! Same syntax as G92 + case 92: for(int8_t i=0; i < NUM_AXIS; i++) { if(code_seen(axis_codes[i])) @@ -5956,11 +6215,17 @@ Sigma_Exit: } } break; - case 110: //! M110 N - reset line pos + + //! ### M110 - Set Line number + // --------------------------------------- + case 110: if (code_seen('N')) gcode_LastN = code_value_long(); break; - case 113: // M113 - Get or set Host Keepalive interval + + //! ### M113 - Get or set host keep-alive interval + // ------------------------------------------ + case 113: if (code_seen('S')) { host_keepalive_interval = (uint8_t)code_value_short(); // NOMORE(host_keepalive_interval, 60); @@ -5971,6 +6236,16 @@ Sigma_Exit: SERIAL_PROTOCOLLN(""); } break; + + //! ### M115 - Firmware info + // -------------------------------------- + //! Print the firmware info and capabilities + //! + //! M115 [V] [U] + //! + //! Without any arguments, prints Prusa firmware version number, machine type, extruder count and UUID. + //! `M115 U` Checks the firmware version provided. If the firmware version provided by the U code is higher than the currently running firmware, + //! pause the print for 30s and ask the user to upgrade the firmware. case 115: // M115 if (code_seen('V')) { // Report the Prusa version number. @@ -5992,22 +6267,43 @@ Sigma_Exit: SERIAL_ECHOLNPGM(MACHINE_UUID); } break; -/* case 117: // M117 display message + + //! ### M114 - Get current position + // ------------------------------------- + case 114: + gcode_M114(); + break; + + + + //! ### M117 - Set LCD Message + // -------------------------------------- + + /* + M117 moved up to get the high priority + + case 117: // M117 display message starpos = (strchr(strchr_pointer + 5,'*')); if(starpos!=NULL) *(starpos)='\0'; lcd_setstatus(strchr_pointer + 5); break;*/ - case 114: // M114 - gcode_M114(); - break; - case 120: //! M120 - Disable endstops + + //! ### M120 - Disable endstops + // ---------------------------------------- + case 120: enable_endstops(false) ; break; - case 121: //! M121 - Enable endstops + + //! ### M121 - Enable endstops + // ---------------------------------------- + case 121: enable_endstops(true) ; break; - case 119: // M119 + + //! ### M119 - Get endstop states + // ---------------------------------------- + case 119: SERIAL_PROTOCOLRPGM(_N("Reporting endstop status"));////MSG_M119_REPORT SERIAL_PROTOCOLLN(""); #if defined(X_MIN_PIN) && X_MIN_PIN > -1 @@ -6066,8 +6362,12 @@ Sigma_Exit: #endif break; //TODO: update for all axis, use for loop + #ifdef BLINKM - case 150: // M150 + + //! ### M150 - Set RGB(W) Color + // ------------------------------------------- + case 150: { byte red; byte grn; @@ -6081,6 +6381,9 @@ Sigma_Exit: } break; #endif //BLINKM + + //! ### M200 - Set filament diameter + // ---------------------------------------- case 200: // M200 D set filament diameter and set E axis units to cubic millimeters (use S0 to set back to millimeters). { @@ -6119,7 +6422,10 @@ Sigma_Exit: calculate_extruder_multipliers(); } break; - case 201: // M201 + + //! ### M201 - Set Print Max Acceleration + // ------------------------------------------- + case 201: for (int8_t i = 0; i < NUM_AXIS; i++) { if (code_seen(axis_codes[i])) @@ -6151,6 +6457,9 @@ Sigma_Exit: } break; #endif + + //! ### M203 - Set Max Feedrate + // --------------------------------------- case 203: // M203 max feedrate mm/sec for (int8_t i = 0; i < NUM_AXIS; i++) { @@ -6174,10 +6483,17 @@ Sigma_Exit: } } break; + + //! ### M204 - Acceleration settings + // ------------------------------------------ + //! Supporting old format: + //! + //! M204 S[normal moves] T[filmanent only moves] + //! + //! and new format: + //! + //! M204 P[printing moves] R[filmanent only moves] T[travel moves] (as of now T is ignored) case 204: - //! M204 acclereration settings. - //!@n Supporting old format: M204 S[normal moves] T[filmanent only moves] - //!@n and new format: M204 P[printing moves] R[filmanent only moves] T[travel moves] (as of now T is ignored) { if(code_seen('S')) { // Legacy acceleration format. This format is used by the legacy Marlin, MK2 or MK3 firmware, @@ -6201,7 +6517,19 @@ Sigma_Exit: } } break; - case 205: //M205 advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk + + //! ### M205 - Set advanced settings + // --------------------------------------------- + //! Set some advanced settings related to movement. + //! + //! M205 [S] [T] [B] [X] [Y] [Z] [E] + /*! + - `S` - Minimum feedrate for print moves (unit/s) + - `T` - Minimum feedrate for travel moves (units/s) + - `B` - Minimum segment time (us) + - `X` - Maximum X jerk (units/s), similarly for other axes + */ + case 205: { if(code_seen('S')) cs.minimumfeedrate = code_value(); if(code_seen('T')) cs.mintravelfeedrate = code_value(); @@ -6214,13 +6542,19 @@ Sigma_Exit: if (cs.max_jerk[Y_AXIS] > DEFAULT_YJERK) cs.max_jerk[Y_AXIS] = DEFAULT_YJERK; } break; - case 206: // M206 additional homing offset + + //! ### M206 - Set additional homing offsets + // ---------------------------------------------- + case 206: for(int8_t i=0; i < 3; i++) { if(code_seen(axis_codes[i])) cs.add_homing[i] = code_value(); } break; #ifdef FWRETRACT + + //! ### M207 - Set firmware retraction + // -------------------------------------------------- case 207: //M207 - set retract length S[positive mm] F[feedrate mm/min] Z[additional zlift/hop] { if(code_seen('S')) @@ -6236,6 +6570,9 @@ Sigma_Exit: cs.retract_zlift = code_value() ; } }break; + + //! ### M208 - Set retract recover length + // -------------------------------------------- case 208: // M208 - set retract recover length S[positive mm surplus to the M207 S*] F[feedrate mm/min] { if(code_seen('S')) @@ -6247,6 +6584,9 @@ Sigma_Exit: cs.retract_recover_feedrate = code_value()/60 ; } }break; + + //! ### M209 - Enable/disable automatict retract + // --------------------------------------------- case 209: // M209 - S<1=true/0=false> enable automatic retract detect if the slicer did not support G10/11: every normal extrude-only move will be classified as retract depending on the direction. { if(code_seen('S')) @@ -6287,6 +6627,9 @@ Sigma_Exit: }break; #endif // FWRETRACT #if EXTRUDERS > 1 + + // ### M218 - Set hotend offset + // ---------------------------------------- case 218: // M218 - set hotend offset (in mm), T X Y { uint8_t extruder; @@ -6314,6 +6657,8 @@ Sigma_Exit: }break; #endif + //! ### M220 Set feedrate percentage + // ----------------------------------------------- case 220: // M220 S- set speed factor override percentage { if (code_seen('B')) //backup current speed factor @@ -6329,6 +6674,9 @@ Sigma_Exit: } } break; + + //! ### M221 - Set extrude factor override percentage + // ---------------------------------------------------- case 221: // M221 S- set extrude factor override percentage { if(code_seen('S')) @@ -6351,6 +6699,8 @@ Sigma_Exit: } break; + //! ### M226 - Wait for Pin state + // ------------------------------------------ case 226: // M226 P S- Wait until the specified pin reaches the state required { if(code_seen('P')){ @@ -6404,6 +6754,9 @@ Sigma_Exit: break; #if NUM_SERVOS > 0 + + //! ### M280 - Set/Get servo position + // -------------------------------------------- case 280: // M280 - set servo position absolute. P: servo index, S: angle or microseconds { int servo_index = -1; @@ -6442,6 +6795,9 @@ Sigma_Exit: #endif // NUM_SERVOS > 0 #if (LARGE_FLASH == true && ( BEEPER > 0 || defined(ULTRALCD) || defined(LCD_USE_I2C_BUZZER))) + + //! ### M300 - Play tone + // ----------------------- case 300: // M300 { int beepS = code_seen('S') ? code_value() : 110; @@ -6461,7 +6817,10 @@ Sigma_Exit: #endif // M300 #ifdef PIDTEMP - case 301: // M301 + + //! ### M301 - Set hotend PID + // --------------------------------------- + case 301: { if(code_seen('P')) cs.Kp = code_value(); if(code_seen('I')) cs.Ki = scalePID_i(code_value()); @@ -6489,7 +6848,10 @@ Sigma_Exit: break; #endif //PIDTEMP #ifdef PIDTEMPBED - case 304: // M304 + + //! ### M304 - Set bed PID + // -------------------------------------- + case 304: { if(code_seen('P')) cs.bedKp = code_value(); if(code_seen('I')) cs.bedKi = scalePID_i(code_value()); @@ -6507,6 +6869,9 @@ Sigma_Exit: } break; #endif //PIDTEMP + + //! ### M240 - Trigger camera + // -------------------------------------------- case 240: // M240 Triggers a camera by emulating a Canon RC-1 : http://www.doc-diy.net/photo/rc-1_hacked/ { #ifdef CHDK @@ -6539,7 +6904,10 @@ Sigma_Exit: } break; #ifdef PREVENT_DANGEROUS_EXTRUDE - case 302: // allow cold extrudes, or set the minimum extrude temperature + + //! ### M302 - Allow cold extrude, or set minimum extrude temperature + // ------------------------------------------------------------------- + case 302: { float temp = .0; if (code_seen('S')) temp=code_value(); @@ -6547,7 +6915,10 @@ Sigma_Exit: } break; #endif - case 303: // M303 PID autotune + + //! ### M303 - PID autotune + // ------------------------------------- + case 303: { float temp = 150.0; int e=0; @@ -6560,17 +6931,22 @@ Sigma_Exit: PID_autotune(temp, e, c); } break; - case 400: // M400 finish all moves + + //! ### M400 - Wait for all moves to finish + // ----------------------------------------- + case 400: { st_synchronize(); } break; - case 403: //! M403 set filament type (material) for particular extruder and send this information to mmu + //! ### M403 - Set filament type (material) for particular extruder and notify the MMU + // ---------------------------------------------- + case 403: { - //! currently three different materials are needed (default, flex and PVA) - //! add storing this information for different load/unload profiles etc. in the future - //!firmware does not wait for "ok" from mmu + // currently three different materials are needed (default, flex and PVA) + // add storing this information for different load/unload profiles etc. in the future + // firmware does not wait for "ok" from mmu if (mmu_enabled) { uint8_t extruder = 255; @@ -6582,27 +6958,41 @@ Sigma_Exit: } break; - case 500: // M500 Store settings in EEPROM + //! ### M500 - Store settings in EEPROM + // ----------------------------------------- + case 500: { Config_StoreSettings(); } break; - case 501: // M501 Read settings from EEPROM + + //! ### M501 - Read settings from EEPROM + // ---------------------------------------- + case 501: { Config_RetrieveSettings(); } break; - case 502: // M502 Revert to default settings + + //! ### M502 - Revert all settings to factory default + // ------------------------------------------------- + case 502: { Config_ResetDefault(); } break; - case 503: // M503 print settings currently in memory + + //! ### M503 - Repport all settings currently in memory + // ------------------------------------------------- + case 503: { Config_PrintSettings(); } break; - case 509: //M509 Force language selection + + //! ### M509 - Force language selection + // ------------------------------------------------ + case 509: { lang_reset(); SERIAL_ECHO_START; @@ -6610,6 +7000,9 @@ Sigma_Exit: } break; #ifdef ABORT_ON_ENDSTOP_HIT_FEATURE_ENABLED + + //! ### M540 - Abort print on endstop hit (enable/disable) + // ----------------------------------------------------- case 540: { if(code_seen('S')) abort_on_endstop_hit = code_value() > 0; @@ -6654,6 +7047,9 @@ Sigma_Exit: #endif // CUSTOM_M_CODE_SET_Z_PROBE_OFFSET #ifdef FILAMENTCHANGEENABLE + + //! ### M600 - Initiate Filament change procedure + // -------------------------------------- case 600: //Pause for filament change X[pos] Y[pos] Z[relative lift] E[initial retract] L[later retract distance for removal] { st_synchronize(); @@ -6728,24 +7124,39 @@ Sigma_Exit: } break; #endif //FILAMENTCHANGEENABLE - case 601: //! M601 - Pause print + + //! ### M601 - Pause print + // ------------------------------- + case 601: { cmdqueue_pop_front(); //trick because we want skip this command (M601) after restore lcd_pause_print(); } break; - case 602: { //! M602 - Resume print + //! ### M602 - Resume print + // ------------------------------- + case 602: { lcd_resume_print(); } break; - case 603: { //! M603 - Stop print + //! ### M603 - Stop print + // ------------------------------- + case 603: { lcd_print_stop(); } #ifdef PINDA_THERMISTOR - case 860: // M860 - Wait for PINDA thermistor to reach target temperature. + //! ### M860 - Wait for extruder temperature (PINDA) + // -------------------------------------------------------------- + /*! + Wait for PINDA thermistor to reach target temperature + + M860 [S] + + */ + case 860: { int set_target_pinda = 0; @@ -6789,7 +7200,18 @@ Sigma_Exit: break; } - case 861: // M861 - Set/Read PINDA temperature compensation offsets + //! ### M861 - Set/Get PINDA temperature compensation offsets + // ----------------------------------------------------------- + /*! + + M861 [ ? | ! | Z | S [I] ] + + - `?` - Print current EEPROM offset values + - `!` - Set factory default values + - `Z` - Set all values to 0 (effectively disabling PINDA temperature compensation) + - `S` `I` - Set compensation ustep value S for compensation table index I + */ + case 861: if (code_seen('?')) { // ? - Print out current EEPROM offset values uint8_t cal_status = calibration_status_pinda(); int16_t usteps = 0; @@ -6860,7 +7282,9 @@ Sigma_Exit: break; #endif //PINDA_THERMISTOR - + + //! ### M862 - Print checking + // ---------------------------------------------- case 862: // M862: print checking float nDummy; uint8_t nCommand; @@ -6921,12 +7345,16 @@ Sigma_Exit: break; #ifdef LIN_ADVANCE - case 900: // M900: Set LIN_ADVANCE options. + //! ### M900 - Set Linear advance options + // ---------------------------------------------- + case 900: gcode_M900(); break; #endif - case 907: // M907 Set digital trimpot motor current using axis codes. + //! ### M907 - Set digital trimpot motor current using axis codes + // --------------------------------------------------------------- + case 907: { #ifdef TMC2130 for (int i = 0; i < NUM_AXIS; i++) @@ -6957,7 +7385,10 @@ Sigma_Exit: #endif //TMC2130 } break; - case 908: // M908 Control digital trimpot directly. + + //! ### M908 - Control digital trimpot directly + // --------------------------------------------------------- + case 908: { #if defined(DIGIPOTSS_PIN) && DIGIPOTSS_PIN > -1 uint8_t channel,current; @@ -6970,13 +7401,17 @@ Sigma_Exit: #ifdef TMC2130_SERVICE_CODES_M910_M918 - case 910: //! M910 - TMC2130 init + //! ### M910 - TMC2130 init + // ----------------------------------------------- + case 910: { tmc2130_init(); } break; - case 911: //! M911 - Set TMC2130 holding currents + //! ### M911 - Set TMC2130 holding currents + // ------------------------------------------------- + case 911: { if (code_seen('X')) tmc2130_set_current_h(0, code_value()); if (code_seen('Y')) tmc2130_set_current_h(1, code_value()); @@ -6985,7 +7420,9 @@ Sigma_Exit: } break; - case 912: //! M912 - Set TMC2130 running currents + //! ### M912 - Set TMC2130 running currents + // ----------------------------------------------- + case 912: { if (code_seen('X')) tmc2130_set_current_r(0, code_value()); if (code_seen('Y')) tmc2130_set_current_r(1, code_value()); @@ -6993,13 +7430,18 @@ Sigma_Exit: if (code_seen('E')) tmc2130_set_current_r(3, code_value()); } break; - case 913: //! M913 - Print TMC2130 currents + + //! ### M913 - Print TMC2130 currents + // ----------------------------- + case 913: { tmc2130_print_currents(); } break; - case 914: //! M914 - Set normal mode + //! ### M914 - Set TMC2130 normal mode + // ------------------------------ + case 914: { tmc2130_mode = TMC2130_MODE_NORMAL; update_mode_profile(); @@ -7007,7 +7449,9 @@ Sigma_Exit: } break; - case 915: //! M915 - Set silent mode + //! ### M95 - Set TMC2130 silent mode + // ------------------------------ + case 915: { tmc2130_mode = TMC2130_MODE_SILENT; update_mode_profile(); @@ -7015,7 +7459,9 @@ Sigma_Exit: } break; - case 916: //! M916 - Set sg_thrs + //! ### M916 - Set TMC2130 Stallguard sensitivity threshold + // ------------------------------------------------------- + case 916: { if (code_seen('X')) tmc2130_sg_thr[X_AXIS] = code_value(); if (code_seen('Y')) tmc2130_sg_thr[Y_AXIS] = code_value(); @@ -7026,7 +7472,9 @@ Sigma_Exit: } break; - case 917: //! M917 - Set TMC2130 pwm_ampl + //! ### M917 - Set TMC2130 PWM amplitude offset (pwm_ampl) + // -------------------------------------------------------------- + case 917: { if (code_seen('X')) tmc2130_set_pwm_ampl(0, code_value()); if (code_seen('Y')) tmc2130_set_pwm_ampl(1, code_value()); @@ -7035,7 +7483,9 @@ Sigma_Exit: } break; - case 918: //! M918 - Set TMC2130 pwm_grad + //! ### M918 - Set TMC2130 PWM amplitude gradient (pwm_grad) + // ------------------------------------------------------------- + case 918: { if (code_seen('X')) tmc2130_set_pwm_grad(0, code_value()); if (code_seen('Y')) tmc2130_set_pwm_grad(1, code_value()); @@ -7046,7 +7496,10 @@ Sigma_Exit: #endif //TMC2130_SERVICE_CODES_M910_M918 - case 350: //! M350 - Set microstepping mode. Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. + //! ### M350 - Set microstepping mode + // --------------------------------------------------- + //! Warning: Steps per unit remains unchanged. S code sets stepping mode for all drivers. + case 350: { #ifdef TMC2130 if(code_seen('E')) @@ -7083,7 +7536,13 @@ Sigma_Exit: #endif //TMC2130 } break; - case 351: //! M351 - Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. + + //! ### M351 - Toggle Microstep Pins + // ----------------------------------- + //! Toggle MS1 MS2 pins directly, S# determines MS1 or MS2, X# sets the pin high/low. + //! + //! M351 [B<0|1>] [E<0|1>] S<1|2> [X<0|1>] [Y<0|1>] [Z<0|1>] + case 351: { #if defined(X_MS1_PIN) && X_MS1_PIN > -1 if(code_seen('S')) switch((int)code_value()) @@ -7101,14 +7560,28 @@ Sigma_Exit: #endif } break; - case 701: //! M701 - load filament + + //! ### M701 - Load filament + // ------------------------- + case 701: { if (mmu_enabled && code_seen('E')) tmp_extruder = code_value(); gcode_M701(); } break; - case 702: //! M702 [U C] - + + //! ### M702 - Unload filament + // ------------------------ + /*! + + M702 [U C] + + - `U` Unload all filaments used in current print + - `C` Unload just current filament + - without any parameters unload all filaments + */ + case 702: { #ifdef SNMM if (code_seen('U')) @@ -7130,7 +7603,9 @@ Sigma_Exit: } break; - case 999: // M999: Restart after being stopped + //! ### M999 - Restart after being stopped + // ------------------------------------ + case 999: Stopped = false; lcd_reset_alert_level(); gcode_LastN = Stopped_gcode_LastN; @@ -7144,6 +7619,10 @@ Sigma_Exit: } } // end if(code_seen('M')) (end of M codes) + + //! ----------------------------------------------------------------------------------------- + //! T Codes + //! //! T - select extruder in case of multi extruder printer //! select filament in case of MMU_V2 //! if extruder is "?", open menu to let the user select extruder/filament @@ -7337,46 +7816,95 @@ Sigma_Exit: } } // end if(code_seen('T')) (end of T codes) + //! ---------------------------------------------------------------------------------------------- + else if (code_seen('D')) // D codes (debug) { switch((int)code_value()) { - case -1: //! D-1 - Endless loop + + //! ### D-1 - Endless loop + // ------------------- + case -1: dcode__1(); break; #ifdef DEBUG_DCODES - case 0: //! D0 - Reset + + //! ### D0 - Reset + // -------------- + case 0: dcode_0(); break; - case 1: //! D1 - Clear EEPROM + + //! ### D1 - Clear EEPROM + // ------------------ + case 1: dcode_1(); break; - case 2: //! D2 - Read/Write RAM + + //! ### D2 - Read/Write RAM + // -------------------- + case 2: dcode_2(); break; #endif //DEBUG_DCODES #ifdef DEBUG_DCODE3 - case 3: //! D3 - Read/Write EEPROM + + //! ### D3 - Read/Write EEPROM + // ----------------------- + case 3: dcode_3(); break; #endif //DEBUG_DCODE3 #ifdef DEBUG_DCODES - case 4: //! D4 - Read/Write PIN + + //! ### D4 - Read/Write PIN + // --------------------- + case 4: dcode_4(); break; #endif //DEBUG_DCODES #ifdef DEBUG_DCODE5 - case 5: // D5 - Read/Write FLASH + + //! ### D5 - Read/Write FLASH + // ------------------------ + case 5: dcode_5(); break; break; #endif //DEBUG_DCODE5 #ifdef DEBUG_DCODES - case 6: // D6 - Read/Write external FLASH + + //! ### D6 - Read/Write external FLASH + // --------------------------------------- + case 6: dcode_6(); break; - case 7: //! D7 - Read/Write Bootloader + + //! ### D7 - Read/Write Bootloader + // ------------------------------- + case 7: dcode_7(); break; - case 8: //! D8 - Read/Write PINDA + + //! ### D8 - Read/Write PINDA + // --------------------------- + case 8: dcode_8(); break; - case 9: //! D9 - Read/Write ADC + + // ### D9 - Read/Write ADC + // ------------------------ + case 9: dcode_9(); break; - case 10: //! D10 - XYZ calibration = OK + + //! ### D10 - XYZ calibration = OK + // ------------------------------ + case 10: dcode_10(); break; #endif //DEBUG_DCODES #ifdef HEATBED_ANALYSIS + + //! ### D80 - Bed check + // --------------------- + /*! + - `E` - dimension x + - `F` - dimention y + - `G` - points_x + - `H` - points_y + - `I` - offset_x + - `J` - offset_y + */ case 80: { float dimension_x = 40; @@ -7401,6 +7929,16 @@ Sigma_Exit: bed_check(dimension_x,dimension_y,points_x,points_y,offset_x,offset_y); }break; + //! ### D81 - Bed analysis + // ----------------------------- + /*! + - `E` - dimension x + - `F` - dimention y + - `G` - points_x + - `H` - points_y + - `I` - offset_x + - `J` - offset_y + */ case 81: { float dimension_x = 40; @@ -7423,7 +7961,10 @@ Sigma_Exit: #endif //HEATBED_ANALYSIS #ifdef DEBUG_DCODES - case 106: //D106 print measured fan speed for different pwm values + + //! ### D106 print measured fan speed for different pwm values + // -------------------------------------------------------------- + case 106: { for (int i = 255; i > 0; i = i - 5) { fanSpeed = i; @@ -7437,12 +7978,52 @@ Sigma_Exit: }break; #ifdef TMC2130 - case 2130: //! D2130 - TMC2130 + //! ### D2130 - TMC2130 Trinamic stepper controller + // --------------------------- + + + /*! + + + D2130[subcommand][value] + + - : + - '0' current off + - '1' current on + - '+' single step + - * value sereval steps + - '-' dtto oposite direction + - '?' read register + - * "mres" + - * "step" + - * "mscnt" + - * "mscuract" + - * "wave" + - '!' set register + - * "mres" + - * "step" + - * "wave" + - '@' home calibrate axis + + Example: + + D2130E?wave ... print extruder microstep linearity compensation curve + + D2130E!wave0 ... disable extruder linearity compensation curve, (sine curve is used) + + D2130E!wave220 ... (sin(x))^1.1 extruder microstep compensation curve used + */ + + + case 2130: dcode_2130(); break; #endif //TMC2130 #if (defined (FILAMENT_SENSOR) && defined(PAT9125)) - case 9125: //! D9125 - FILAMENT_SENSOR + + //! ### D9125 - FILAMENT_SENSOR + // --------------------------------- + case 9125: dcode_9125(); break; #endif //FILAMENT_SENSOR @@ -7461,6 +8042,13 @@ Sigma_Exit: ClearToSend(); } + + + /** @defgroup GCodes G-Code List + */ + +// --------------------------------------------------- + void FlushSerialRequestResend() { //char cmdbuffer[bufindr][100]="Resend:"; diff --git a/Firmware/doxyfile b/Firmware/doxyfile index 9c2d550c..346ce604 100644 --- a/Firmware/doxyfile +++ b/Firmware/doxyfile @@ -2050,7 +2050,7 @@ PERLMOD_MAKEVAR_PREFIX = # C-preprocessor directives found in the sources and include files. # The default value is: YES. -ENABLE_PREPROCESSING = YES +ENABLE_PREPROCESSING = NO # If the MACRO_EXPANSION tag is set to YES, doxygen will expand all macro names # in the source code. If set to NO, only conditional compilation will be From bd4bfbe58622352f6da7be93b4eb0c8868a0c370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20K=C3=BChn?= Date: Fri, 19 Jul 2019 16:15:12 +0200 Subject: [PATCH 15/19] Added M862 details --- Firmware/Marlin_main.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 0415b2bf..0e5850b9 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -7285,6 +7285,24 @@ Sigma_Exit: //! ### M862 - Print checking // ---------------------------------------------- + /*! + Checks the parameters of the printer and gcode and performs compatibility check + + - M862.1 [ P | Q ] + + - M862.2 [ P | Q ] + + - M862.3 [ P | Q ] + + - M862.4 [ P | Q] + + - M862.5 [ P | Q] + + + When run with P<> argument, the check is performed against the input value. + When run with Q argument, the current value is shown. + + */ case 862: // M862: print checking float nDummy; uint8_t nCommand; From 254dd7463b1615f79db9b08f53592710a4ed86d9 Mon Sep 17 00:00:00 2001 From: DRracer Date: Mon, 22 Jul 2019 17:08:10 +0200 Subject: [PATCH 16/19] fix tests --- Tests/PrusaStatistics_test.cpp | 84 ++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/Tests/PrusaStatistics_test.cpp b/Tests/PrusaStatistics_test.cpp index 05aaa363..587a3fb0 100644 --- a/Tests/PrusaStatistics_test.cpp +++ b/Tests/PrusaStatistics_test.cpp @@ -13,41 +13,42 @@ std::string itostr3(int i){ return std::to_string(i); } -std::string eeprom_read_word(uint16_t* i){ +std::string eeprom_read_word(uint16_t* /*i*/){ return "eeprom_read"; } int _millis(){return 10000;} -int farm_no; -int busy_state; -int PAUSED_FOR_USER; -int status_number; -int total_filament_used; -int feedmultiply; -int longFilenameOLD; -int starttime; -int isPrintPaused; -int IS_SD_PRINTING; -int farm_status; -int farm_timer; -int loading_flag; +static int farm_no; +static int busy_state; +static int PAUSED_FOR_USER; +static int status_number; +static int total_filament_used; +static int feedmultiply; +static int longFilenameOLD; +static int starttime; +static int isPrintPaused; +static int IS_SD_PRINTING; +static int farm_status; +static int farm_timer; +static int loading_flag; -int target_temperature[1]; -int current_temperature[1]; -int target_temperature_bed; -int current_temperature_bed; +static int target_temperature[1]; +static int current_temperature[1]; +static int target_temperature_bed; +static int current_temperature_bed; -uint16_t nozzle_diameter; -uint16_t* EEPROM_NOZZLE_DIAMETER_uM; +static uint16_t nozzle_diameter; +static uint16_t* EEPROM_NOZZLE_DIAMETER_uM; -std::string FW_VERSION; +static std::string FW_VERSION; struct Card { int paused = 0; int percentDone(){ return 50; } -} card; +}; +static Card card; void setup_mockups(){ farm_no = 0; @@ -85,7 +86,7 @@ namespace old_code { // Mocking Serial line -std::string SERIAL_BUFFER = ""; +static std::string SERIAL_BUFFER = ""; void SERIAL_ECHO(std::string s){ SERIAL_BUFFER += s; @@ -115,8 +116,12 @@ struct MySerial { void print(int i){ SERIAL_ECHO(i); } -} MYSERIAL; + void println(){ + SERIAL_ECHO("\n"); + } +}; +static MySerial MYSERIAL; static void prusa_stat_printerstatus(int _status) { @@ -363,7 +368,7 @@ namespace new_code { // Mocking Serial line -std::string SERIAL_BUFFER = ""; +static std::string SERIAL_BUFFER = ""; void SERIAL_ECHO(std::string s){ SERIAL_BUFFER += s; @@ -383,6 +388,7 @@ void SERIAL_ECHOLN(std::string s){ void SERIAL_ECHOLN(char c){ SERIAL_BUFFER += char(c); + SERIAL_BUFFER += "\n"; } void SERIAL_RESET(){ @@ -393,7 +399,12 @@ struct MySerial { void print(int i){ SERIAL_ECHO(i); } -} MYSERIAL; + void println(){ + SERIAL_ECHO("\n"); + } +}; + +static MySerial MYSERIAL; static void prusa_stat_printerstatus(int _status) { @@ -459,6 +470,12 @@ void prusa_statistics_err(char c){ prusa_stat_farm_number(); } +void prusa_statistics_case0(uint8_t statnr){ + SERIAL_ECHO("{"); + prusa_stat_printerstatus(statnr); + prusa_stat_farm_number(); + prusa_stat_printinfo(); +} void prusa_statistics(int _message, uint8_t _fil_nr) { #ifdef DEBUG_DISABLE_PRUSA_STATISTICS @@ -470,24 +487,24 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { case 0: // default message if (busy_state == PAUSED_FOR_USER) { - status_number = 15; + prusa_statistics_case0(15); } else if (isPrintPaused || card.paused) { - status_number = 14; + prusa_statistics_case0(14); } else if (IS_SD_PRINTING || loading_flag) { - status_number = 4; + prusa_statistics_case0(4); } else { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(1); + prusa_stat_farm_number(); + prusa_stat_diameter(); status_number = 1; } - SERIAL_ECHO('{'); - prusa_stat_printerstatus(status_number); - prusa_stat_farm_number(); - prusa_stat_printinfo(); break; case 1: // 1 heating @@ -530,7 +547,6 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { // must do a return here to prevent doing SERIAL_ECHOLN("}") at the very end of this function // saved a considerable amount of FLASH return; - break; case 4: // print succesfull SERIAL_ECHO("{[RES:1][FIL:"); MYSERIAL.print(int(_fil_nr)); From b96c9700ce75c5f96587517387219a5c85a50c72 Mon Sep 17 00:00:00 2001 From: DRracer Date: Mon, 22 Jul 2019 17:10:04 +0200 Subject: [PATCH 17/19] fix prusa_statistics code size optimization according to unit test results --- Firmware/ultralcd.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index b7f076d3..f3832d17 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -3962,6 +3962,13 @@ void prusa_statistics_err(char c){ prusa_stat_farm_number(); } +static void prusa_statistics_case0(uint8_t statnr){ + SERIAL_ECHO("{"); + prusa_stat_printerstatus(statnr); + prusa_stat_farm_number(); + prusa_stat_printinfo(); +} + void prusa_statistics(int _message, uint8_t _fil_nr) { #ifdef DEBUG_DISABLE_PRUSA_STATISTICS return; @@ -3972,24 +3979,24 @@ void prusa_statistics(int _message, uint8_t _fil_nr) { case 0: // default message if (busy_state == PAUSED_FOR_USER) { - status_number = 15; + prusa_statistics_case0(15); } else if (isPrintPaused || card.paused) { - status_number = 14; + prusa_statistics_case0(14); } else if (IS_SD_PRINTING || loading_flag) { - status_number = 4; + prusa_statistics_case0(4); } else { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(1); + prusa_stat_farm_number(); + prusa_stat_diameter(); status_number = 1; } - SERIAL_ECHO('{'); - prusa_stat_printerstatus(status_number); - prusa_stat_farm_number(); - prusa_stat_printinfo(); break; case 1: // 1 heating From 6f79ef4c9cf06b7c843d32eef2e95729cca2c0c7 Mon Sep 17 00:00:00 2001 From: DRracer Date: Mon, 22 Jul 2019 17:29:43 +0200 Subject: [PATCH 18/19] resolve hidden conflicts in commented code --- Firmware/Marlin_main.cpp | 8 -------- Firmware/ultralcd.cpp | 4 ---- 2 files changed, 12 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index d3b15f51..35722679 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -8943,11 +8943,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; -<<<<<<< HEAD custom_message_type = CustomMsg::MeshBedLeveling; -======= - custom_message_type = CustomMsgTypes::MESHBL; ->>>>>>> origin/code-size-reduction custom_message_state = (x_points_num * y_points_num) + 10; lcd_update(1); @@ -9145,11 +9141,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; -<<<<<<< HEAD custom_message_type = CustomMsg::MeshBedLeveling; -======= - custom_message_type = CustomMsgTypes::MESHBL; ->>>>>>> origin/code-size-reduction custom_message_state = (x_points_num * y_points_num) + 10; lcd_update(1); diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 46bcde1c..ac7539d6 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -6600,11 +6600,7 @@ static void lcd_main_menu() if(fan_check_error == EFCE_OK) MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT #else -<<<<<<< HEAD - MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT -======= MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT ->>>>>>> upstream/MK3 #endif } From 23ed612efe29546259c10ecaac2474f83fec4590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20K=C3=BChn?= Date: Mon, 22 Jul 2019 18:45:41 +0200 Subject: [PATCH 19/19] Updated linux build manual --- README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 765204a5..c44983ba 100644 --- a/README.md +++ b/README.md @@ -14,11 +14,24 @@ # Build ## Linux -Run shell script build.sh to build for MK3 and flash with Slic3er. -If you have a different printer model, follow step [2.b](#2b) from Windows build first. -If you wish to flash from Arduino, follow step [2.c](#2c) from Windows build first. -The script downloads Arduino with our modifications and Rambo board support installed, unpacks it into folder PF-build-env-\ on the same level, as your Prusa-Firmware folder is located, builds firmware for MK3 using that Arduino in Prusa-Firmware-build folder on the same level as Prusa-Firmware, runs secondary language support scripts. Firmware with secondary language support is generated in lang subfolder. Use firmware.hex for MK3 variant. Use firmware_\.hex for other printers. Don't forget to follow step [2.b](#2b) first for non-MK3 printers. +1. Clone this repository and checkout the correct branch for your desired release version. + +2. Set your printer model. + - For MK3 --> skip to step 3. + - If you have a different printer model, follow step [2.b](#2b) from Windows build + +3. Run `sudo ./build.sh` + - Output hex file is at `"PrusaFirmware/lang/firmware.hex"` . In the same folder you can hex files for other languages as well. + +4. Connect your printer and flash with PrusaSlicer ( Configuration --> Flash printer firmware ) or Slic3r PE. + - If you wish to flash from Arduino, follow step [2.c](#2c) from Windows build first. + + +_Notes:_ + +The script downloads Arduino with our modifications and Rambo board support installed, unpacks it into folder `PF-build-env-\` on the same level, as your Prusa-Firmware folder is located, builds firmware for MK3 using that Arduino in Prusa-Firmware-build folder on the same level as Prusa-Firmware, runs secondary language support scripts. Firmware with secondary language support is generated in lang subfolder. Use firmware.hex for MK3 variant. Use `firmware_\.hex` for other printers. Don't forget to follow step [2.b](#2b) first for non-MK3 printers. + ## Windows ### Using Arduino note: Multi language build is not supported.