diff --git a/.gitignore b/.gitignore index bbd9b9ac2..dec628d07 100644 --- a/.gitignore +++ b/.gitignore @@ -51,3 +51,4 @@ Firmware/Doc /build-env/ /Firmware/Firmware.vcxproj /Firmware/Configuration_prusa_bckp.h +/Firmware/variants/printers.h diff --git a/.travis.yml b/.travis.yml index 790e5b306..4d9039dc0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,13 @@ dist: trusty before_install: - sudo apt-get install -y ninja-build + # Arduino IDE adds a lot of noise caused by network traffic, trying to firewall it off + - sudo iptables -P INPUT DROP + - sudo iptables -P FORWARD DROP + - sudo iptables -P OUTPUT ACCEPT + - sudo iptables -A INPUT -i lo -j ACCEPT + - sudo iptables -A OUTPUT -o lo -j ACCEPT + - sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT script: - bash -x test.sh - cp Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h Firmware/Configuration_prusa.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c0c2aacd0..4ca1d95be 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/Firmware/Configuration.cpp b/Firmware/Configuration.cpp new file mode 100644 index 000000000..f87849285 --- /dev/null +++ b/Firmware/Configuration.cpp @@ -0,0 +1,10 @@ +#include "Configuration.h" +#include "Configuration_prusa.h" + +const uint16_t _nPrinterType PROGMEM=PRINTER_TYPE; +const char _sPrinterName[] PROGMEM=PRINTER_NAME; +const uint16_t _nPrinterMmuType PROGMEM=PRINTER_MMU_TYPE; +const char _sPrinterMmuName[] PROGMEM=PRINTER_MMU_NAME; + +uint16_t nPrinterType; +PGM_P sPrinterName; \ No newline at end of file diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 4cd696978..f32538cc1 100644 --- a/Firmware/Configuration.h +++ b/Firmware/Configuration.h @@ -6,6 +6,15 @@ #define STR_HELPER(x) #x #define STR(x) STR_HELPER(x) +//-// +#include +extern const uint16_t _nPrinterType; +extern const char _sPrinterName[] PROGMEM; +extern const uint16_t _nPrinterMmuType; +extern const char _sPrinterMmuName[] PROGMEM; +extern uint16_t nPrinterType; +extern PGM_P sPrinterName; + // Firmware version #define FW_VERSION "3.7.3" #define FW_COMMIT_NR 2370 @@ -15,6 +24,9 @@ #define FW_REPOSITORY "Unknown" #define FW_VERSION_FULL FW_VERSION "-" STR(FW_COMMIT_NR) +// G-code language level +#define GCODE_LEVEL 1 + // Debug version has debugging enabled (the symbol DEBUG_BUILD is set). // The debug build may be a bit slower than the non-debug build, therefore the debug build should // not be shipped to a customer. diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h old mode 100644 new mode 100755 index 2e60597dc..582cea348 --- 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(); @@ -172,6 +166,17 @@ void manage_inactivity(bool ignore_stepper_queue=false); #define disable_z() {} #endif +#ifdef PSU_Delta + void init_force_z(); + void check_force_z(); + #undef disable_z + #define disable_z() disable_force_z() + void disable_force_z(); + #undef enable_z + #define enable_z() enable_force_z() + void enable_force_z(); +#endif // PSU_Delta + @@ -214,6 +219,9 @@ void manage_inactivity(bool ignore_stepper_queue=false); #endif +#define FARM_FILAMENT_COLOR_NONE 99; + + enum AxisEnum {X_AXIS=0, Y_AXIS=1, Z_AXIS=2, E_AXIS=3, X_HEAD=4, Y_HEAD=5}; #define X_AXIS_MASK 1 #define Y_AXIS_MASK 2 @@ -300,6 +308,11 @@ extern bool axis_known_position[3]; extern int fanSpeed; extern int8_t lcd_change_fil_state; +const char smooth1[] PROGMEM = "Smooth1"; +const char smooth2[] PROGMEM = "Smooth2"; +const char textured[] PROGMEM = "Textur1"; +const char *const defaultSheetNames[] PROGMEM = {smooth1,smooth2,textured}; + #ifdef TMC2130 void homeaxis(int axis, uint8_t cnt = 1, uint8_t* pstep = 0); #else @@ -320,7 +333,6 @@ extern float retract_recover_length_swap; extern uint8_t host_keepalive_interval; - extern unsigned long starttime; extern unsigned long stoptime; extern int bowden_length[4]; @@ -389,7 +401,8 @@ extern bool wizard_active; //autoload temporarily disabled during wizard extern LongTimer safetyTimer; #define PRINT_PERCENT_DONE_INIT 0xff -#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CUSTOM_MSG_TYPE_TEMCAL) || saved_printing || (lcd_commands_type == LCD_COMMAND_V2_CAL) || card.paused || mmu_print_saved) +#define PRINTER_ACTIVE (IS_SD_PRINTING || is_usb_printing || isPrintPaused || (custom_message_type == CustomMsg::TempCal) || saved_printing || (lcd_commands_type == LcdCommands::Layer1Cal) || card.paused || mmu_print_saved) + //! Beware - mcode_in_progress is set as soon as the command gets really processed, //! which is not the same as posting the M600 command into the command queue //! There can be a considerable lag between posting M600 and its real processing which might result diff --git a/Firmware/MarlinSerial.h b/Firmware/MarlinSerial.h index d596708e4..27e722bc0 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 0df610458..483d3018b 100755 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -43,8 +43,10 @@ * */ +//-// +#include "Configuration.h" #include "Marlin.h" - + #ifdef ENABLE_AUTO_BED_LEVELING #include "vector_3.h" #ifdef AUTO_BED_LEVELING_GRID @@ -214,8 +216,6 @@ static LongTimer crashDetTimer; bool mesh_bed_leveling_flag = false; bool mesh_bed_run_from_menu = false; -int8_t FarmMode = 0; - bool prusa_sd_card_upload = false; unsigned int status_number = 0; @@ -356,7 +356,6 @@ unsigned long starttime=0; unsigned long stoptime=0; unsigned long _usb_timer = 0; - bool extruder_under_pressure = true; @@ -412,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(); } @@ -659,19 +676,13 @@ static void factory_reset(char level) // Level 0: Language reset case 0: -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - WRITE(BEEPER, HIGH); - _delay_ms(100); - WRITE(BEEPER, LOW); + Sound_MakeCustom(100,0,false); lang_reset(); break; //Level 1: Reset statistics case 1: -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - WRITE(BEEPER, HIGH); - _delay_ms(100); - WRITE(BEEPER, LOW); + Sound_MakeCustom(100,0,false); eeprom_update_dword((uint32_t *)EEPROM_TOTALTIME, 0); eeprom_update_dword((uint32_t *)EEPROM_FILAMENTUSED, 0); @@ -726,11 +737,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) fsensor_enable(); fsensor_autoload_set(true); #endif //FILAMENT_SENSOR - -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - WRITE(BEEPER, HIGH); - _delay_ms(100); - WRITE(BEEPER, LOW); + Sound_MakeCustom(100,0,false); //_delay_ms(2000); break; @@ -740,11 +747,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) lcd_puts_P(PSTR("Factory RESET")); lcd_puts_at_P(1, 2, PSTR("ERASING all data")); -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - WRITE(BEEPER, HIGH); - _delay_ms(100); - WRITE(BEEPER, LOW); - + Sound_MakeCustom(100,0,false); er_progress = 0; lcd_puts_at_P(3, 3, PSTR(" ")); lcd_set_cursor(3, 3); @@ -790,12 +793,8 @@ int uart_putchar(char c, FILE *) void lcd_splash() { -// lcd_puts_at_P(0, 1, PSTR(" Original Prusa ")); -// lcd_puts_at_P(0, 2, PSTR(" 3D Printers ")); -// lcd_puts_P(PSTR("\x1b[1;3HOriginal Prusa\x1b[2;4H3D Printers")); -// fputs_P(PSTR(ESC_2J ESC_H(1,1) "Original Prusa i3" ESC_H(3,2) "Prusa Research"), lcdout); - lcd_puts_P(PSTR(ESC_2J ESC_H(1,1) "Original Prusa i3" ESC_H(3,2) "Prusa Research")); -// lcd_printf_P(_N(ESC_2J "x:%.3f\ny:%.3f\nz:%.3f\ne:%.3f"), _x, _y, _z, _e); + lcd_clear(); // clears display and homes screen + lcd_puts_P(PSTR("\n Original Prusa i3\n Prusa Research")); } @@ -814,7 +813,7 @@ void factory_reset() SET_OUTPUT(BEEPER); -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) + if(eSoundMode!=e_SOUND_MODE_SILENT) WRITE(BEEPER, HIGH); while (!READ(BTN_ENC)); @@ -925,7 +924,7 @@ void update_sec_lang_from_external_flash() uint32_t src_addr; if (lang_get_header(lang, &header, &src_addr)) { - fputs_P(PSTR(ESC_H(1,3) "Language update."), lcdout); + lcd_puts_at_P(1,3,PSTR("Language update.")); for (uint8_t i = 0; i < state; i++) fputc('.', lcdout); _delay(100); boot_reserved = (state + 1) | (lang << 4); @@ -999,8 +998,8 @@ void list_sec_lang_from_external_flash() static void w25x20cl_err_msg() { - lcd_puts_P(_n(ESC_2J ESC_H(0,0) "External SPI flash" ESC_H(0,1) "W25X20CL is not res-" - ESC_H(0,2) "ponding. Language" ESC_H(0,3) "switch unavailable.")); + lcd_clear(); + lcd_puts_P(_n("External SPI flash\nW25X20CL is not res-\nponding. Language\nswitch unavailable.")); } // "Setup" function is called by the Arduino framework on startup. @@ -1065,6 +1064,9 @@ void setup() //disabled filament autoload (PFW360) fsensor_autoload_set(false); #endif //FILAMENT_SENSOR + // ~ FanCheck -> on + if(!(eeprom_read_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED))) + eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED,true); } MYSERIAL.begin(BAUDRATE); fdev_setup_stream(uartout, uart_putchar, NULL, _FDEV_SETUP_WRITE); //setup uart out stream @@ -1075,6 +1077,7 @@ void setup() SERIAL_ECHO_START; printf_P(PSTR(" " FW_VERSION_FULL "\n")); + //SERIAL_ECHOPAIR("Active sheet before:", static_cast(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))); #ifdef DEBUG_SEC_LANG lang_table_header_t header; @@ -1309,6 +1312,9 @@ void setup() update_mode_profile(); tmc2130_init(); #endif //TMC2130 +#ifdef PSU_Delta + init_force_z(); // ! important for correct Z-axis initialization +#endif // PSU_Delta setup_photpin(); @@ -1346,7 +1352,7 @@ void setup() } #endif //TMC2130 -#if defined(Z_AXIS_ALWAYS_ON) +#if defined(Z_AXIS_ALWAYS_ON) && !defined(PSU_Delta) enable_z(); #endif farm_mode = eeprom_read_byte((uint8_t*)EEPROM_FARM_MODE); @@ -1423,20 +1429,7 @@ void setup() printf_P(PSTR("Card NG!\n")); #endif //DEBUG_SD_SPEED_TEST - if (eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_POWER_COUNT, 0); - if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_CRASH_COUNT_X, 0); - if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_CRASH_COUNT_Y, 0); - if (eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_FERROR_COUNT, 0); - if (eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_POWER_COUNT_TOT, 0); - if (eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT, 0); - if (eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT, 0); - if (eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, 0); - - if (eeprom_read_word((uint16_t*)EEPROM_MMU_FAIL_TOT) == 0xffff) eeprom_update_word((uint16_t *)EEPROM_MMU_FAIL_TOT, 0); - if (eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) == 0xffff) eeprom_update_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT, 0); - if (eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_FAIL, 0); - if (eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0); - + eeprom_init(); #ifdef SNMM if (eeprom_read_dword((uint32_t*)EEPROM_BOWDEN_LENGTH) == 0x0ffffffff) { //bowden length used for SNMM int _z = BOWDEN_LENGTH; @@ -1503,7 +1496,6 @@ void setup() SilentModeMenu_MMU = 1; eeprom_write_byte((uint8_t*)EEPROM_MMU_STEALTH, SilentModeMenu_MMU); } - check_babystep(); //checking if Z babystep is in allowed range #if !defined(DEBUG_DISABLE_FANCHECK) && defined(FANCHECK) && defined(TACH_1) && TACH_1 >-1 setup_fan_interrupt(); @@ -1517,8 +1509,10 @@ void setup() #ifndef DEBUG_DISABLE_STARTMSGS KEEPALIVE_STATE(PAUSED_FOR_USER); - check_if_fw_is_on_right_printer(); - show_fw_version_warnings(); + if (!farm_mode) { + check_if_fw_is_on_right_printer(); + show_fw_version_warnings(); + } switch (hw_changed) { //if motherboard or printer type was changed inform user as it can indicate flashing wrong firmware version @@ -1644,11 +1638,12 @@ void setup() } #endif //UVLO_SUPPORT + fCheckModeInit(); + fSetMmuMode(mmu_enabled); KEEPALIVE_STATE(NOT_BUSY); #ifdef WATCHDOG wdt_enable(WDTO_4S); #endif //WATCHDOG - } @@ -2357,11 +2352,7 @@ void refresh_cmd_timeout(void) #endif //FWRETRACT void trace() { -//if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - _tone(BEEPER, 440); - _delay(25); - _noTone(BEEPER); - _delay(20); + Sound_MakeCustom(25,440,true); } /* void ramming() { @@ -3157,7 +3148,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 = CustomMsg::Status; } //! @brief Rise Z if too low to avoid blob/jam before filament loading @@ -3173,6 +3164,11 @@ void gcode_M701() { printf_P(PSTR("gcode_M701 begin\n")); + if (farm_mode) + { + prusa_statistics(22); + } + if (mmu_enabled) { extr_adj(tmp_extruder);//loads current extruder @@ -3181,7 +3177,7 @@ void gcode_M701() else { enable_z(); - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; + custom_message_type = CustomMsg::FilamentLoading; #ifdef FSENSOR_QUALITY fsensor_oq_meassure_start(40); @@ -3199,9 +3195,7 @@ void gcode_M701() load_filament_final_feed(); //slow sequence st_synchronize(); - if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) _tone(BEEPER, 500); - delay_keep_alive(50); - _noTone(BEEPER); + Sound_MakeCustom(50,500,false); if (!farm_mode && loading_flag) { lcd_load_filament_color_check(); @@ -3211,7 +3205,7 @@ void gcode_M701() lcd_setstatuspgm(_T(WELCOME_MSG)); disable_z(); loading_flag = false; - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsg::Status; #ifdef FSENSOR_QUALITY fsensor_oq_meassure_stop(); @@ -3332,14 +3326,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 @@ -3462,14 +3461,30 @@ 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 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 @@ -3513,21 +3528,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'); @@ -3537,7 +3564,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'); @@ -3548,7 +3578,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'); @@ -3599,21 +3632,54 @@ 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 set ` - set nozzle diameter (farm mode only), e.g. `PRUSA nozzle set 0.4` + - `nozzle D` - check the nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle D0.4` + - `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle` + * + */ + + + if (code_seen("Ping")) { // PRUSA Ping if (farm_mode) { PingTime = _millis(); //MYSERIAL.print(farm_no); MYSERIAL.println(": OK"); } } - else if (code_seen("PRN")) { //! PRUSA PRN + else if (code_seen("PRN")) { // PRUSA PRN printf_P(_N("%d"), status_number); } else if( code_seen("FANPINTST") ){ gcode_PRUSA_BadRAMBoFanTest(); }else if (code_seen("FAN")) { //! PRUSA FAN printf_P(_N("E0:%d RPM\nPRN0:%d RPM\n"), 60*fan_speed[0], 60*fan_speed[1]); - }else if (code_seen("fn")) { //! PRUSA fn + }else if (code_seen("fn")) { // PRUSA fn if (farm_mode) { printf_P(_N("%d"), farm_no); } @@ -3622,26 +3688,26 @@ void process_commands() } } - else if (code_seen("thx")) //! PRUSA thx + else if (code_seen("thx")) // PRUSA thx { no_response = false; } - else if (code_seen("uvlo")) //! PRUSA uvlo + else if (code_seen("uvlo")) // PRUSA uvlo { eeprom_update_byte((uint8_t*)EEPROM_UVLO,0); enquecommand_P(PSTR("M24")); } #ifdef FILAMENT_SENSOR - else if (code_seen("fsensor_recover")) //! PRUSA fsensor_recover + else if (code_seen("fsensor_recover")) // PRUSA fsensor_recover { fsensor_restore_print_and_continue(); } #endif //FILAMENT_SENSOR - else if (code_seen("MMURES")) //! PRUSA MMURES + else if (code_seen("MMURES")) // PRUSA MMURES { mmu_reset(); } - else if (code_seen("RESET")) { //! PRUSA RESET + else if (code_seen("RESET")) { // PRUSA RESET // careful! if (farm_mode) { #if (defined(WATCHDOG) && (MOTHERBOARD == BOARD_EINSY_1_0a)) @@ -3657,7 +3723,7 @@ void process_commands() else { MYSERIAL.println("Not in farm mode."); } - }else if (code_seen("fv")) { //! PRUSA fv + }else if (code_seen("fv")) { // PRUSA fv // get file version #ifdef SDSUPPORT card.openFile(strchr_pointer + 3,true); @@ -3672,36 +3738,102 @@ void process_commands() #endif // SDSUPPORT - } else if (code_seen("M28")) { //! PRUSA M28 + } else if (code_seen("M28")) { // PRUSA M28 trace(); prusa_sd_card_upload = true; card.openFile(strchr_pointer+4,false); - } else if (code_seen("SN")) { //! PRUSA SN + } else if (code_seen("SN")) { // PRUSA SN gcode_PRUSA_SN(); - } else if(code_seen("Fir")){ //! PRUSA Fir + } else if(code_seen("Fir")){ // PRUSA Fir SERIAL_PROTOCOLLN(FW_VERSION_FULL); - } else if(code_seen("Rev")){ //! PRUSA Rev + } else if(code_seen("Rev")){ // PRUSA Rev SERIAL_PROTOCOLLN(FILAMENT_SIZE "-" ELECTRONICS "-" NOZZLE_TYPE ); - } else if(code_seen("Lang")) { //! PRUSA Lang + } else if(code_seen("Lang")) { // PRUSA Lang lang_reset(); - } else if(code_seen("Lz")) { //! PRUSA Lz + } else if(code_seen("Lz")) { // PRUSA Lz EEPROM_save_B(EEPROM_BABYSTEP_Z,0); - } else if(code_seen("Beat")) { //! PRUSA Beat + } else if(code_seen("Beat")) { // PRUSA Beat // Kick farm link timer kicktime = _millis(); - } else if(code_seen("FR")) { //! PRUSA FR + } else if(code_seen("FR")) { // PRUSA FR // Factory full reset factory_reset(0); - } + +//-// +/* + } else if(code_seen("rrr")) { +MYSERIAL.println("=== checking ==="); +MYSERIAL.println(eeprom_read_byte((uint8_t*)EEPROM_CHECK_MODE),DEC); +MYSERIAL.println(eeprom_read_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER),DEC); +MYSERIAL.println(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM),DEC); +MYSERIAL.println(farm_mode,DEC); +MYSERIAL.println(eCheckMode,DEC); + } else if(code_seen("www")) { +MYSERIAL.println("=== @ FF ==="); +eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,0xFF); +eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,0xFF); +eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF); +*/ + } else if (code_seen("nozzle")) { // PRUSA nozzle + uint16_t nDiameter; + if(code_seen('D')) + { + nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um] + nozzle_diameter_check(nDiameter); + } + else if(code_seen("set") && farm_mode) + { + strchr_pointer++; // skip 1st char (~ 's') + strchr_pointer++; // skip 2nd char (~ 'e') + nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um] + eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)ClNozzleDiameter::_Diameter_Undef); // for correct synchronization after farm-mode exiting + eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter); + } + else SERIAL_PROTOCOLLN((float)eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)/1000.0); + +//-// !!! SupportMenu +/* +// musi byt PRED "PRUSA model" + } else if (code_seen("smodel")) { //! PRUSA smodel + size_t nOffset; +// ! -> "l" + strchr_pointer+=5*sizeof(*strchr_pointer); // skip 1st - 5th char (~ 'smode') + nOffset=strspn(strchr_pointer+1," \t\n\r\v\f"); + if(*(strchr_pointer+1+nOffset)) + printer_smodel_check(strchr_pointer); + else SERIAL_PROTOCOLLN(PRINTER_NAME); + } else if (code_seen("model")) { //! PRUSA model + uint16_t nPrinterModel; + strchr_pointer+=4*sizeof(*strchr_pointer); // skip 1st - 4th char (~ 'mode') + nPrinterModel=(uint16_t)code_value_long(); + if(nPrinterModel!=0) + printer_model_check(nPrinterModel); + else SERIAL_PROTOCOLLN(PRINTER_TYPE); + } else if (code_seen("version")) { //! PRUSA version + strchr_pointer+=7*sizeof(*strchr_pointer); // skip 1st - 7th char (~ 'version') + while(*strchr_pointer==' ') // skip leading spaces + strchr_pointer++; + if(*strchr_pointer!=0) + fw_version_check(strchr_pointer); + else SERIAL_PROTOCOLLN(FW_VERSION); + } else if (code_seen("gcode")) { //! PRUSA gcode + uint16_t nGcodeLevel; + strchr_pointer+=4*sizeof(*strchr_pointer); // skip 1st - 4th char (~ 'gcod') + nGcodeLevel=(uint16_t)code_value_long(); + if(nGcodeLevel!=0) + gcode_level_check(nGcodeLevel); + else SERIAL_PROTOCOLLN(GCODE_LEVEL); +*/ + } //else if (code_seen('Cal')) { // lcd_calibration(); // } @@ -3715,6 +3847,9 @@ void process_commands() // printf_P(_N("BEGIN G-CODE=%u\n"), gcode_in_progress); switch (gcode_in_progress) { + + //! ### G0, G1 - Coordinated movement X Y Z E + // -------------------------------------- case 0: // G0 -> G1 case 1: // G1 if(Stopped == false) { @@ -3786,7 +3921,7 @@ void process_commands() SET_OUTPUT(BEEPER); if (counterBeep== 0){ -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) +if(eSoundMode!=e_SOUND_MODE_SILENT) WRITE(BEEPER,HIGH); } @@ -3912,19 +4047,30 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) //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 @@ -3939,7 +4085,11 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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]); @@ -3947,7 +4097,11 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) retract(true); #endif break; - case 11: // G11 retract_recover + + + //! ### G11 - Retract recover + // ----------------------------- + case 11: #if EXTRUDERS > 1 retract(false,retracted_swap[active_extruder]); #else @@ -3955,7 +4109,11 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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; @@ -3982,8 +4140,13 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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." @@ -4126,7 +4289,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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 @@ -4148,17 +4314,27 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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 @@ -4174,7 +4350,8 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } break; - + //! ### G75 - Print temperature interpolation + // --------------------------------------------- case 75: { for (int i = 40; i <= 110; i++) @@ -4182,7 +4359,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } break; - case 76: //! G76 - PINDA probe temperature calibration + //! ### G76 - PINDA probe temperature calibration + // ------------------------------------------------ + case 76: { #ifdef PINDA_THERMISTOR if (true) @@ -4246,7 +4425,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) // setTargetHotend(200, 0); setTargetBed(70 + (start_temp - 30)); - custom_message_type = CUSTOM_MSG_TYPE_TEMCAL; + custom_message_type = CustomMsg::TempCal; custom_message_state = 1; lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION)); current_position[Z_AXIS] = MESH_HOME_Z_SEARCH; @@ -4348,7 +4527,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) break; } puts_P(_N("PINDA probe calibration start")); - custom_message_type = CUSTOM_MSG_TYPE_TEMCAL; + custom_message_type = CustomMsg::TempCal; custom_message_state = 1; lcd_setstatuspgm(_T(MSG_TEMP_CALIBRATION)); current_position[X_AXIS] = PINDA_PREHEAT_X; @@ -4416,7 +4595,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsg::Status; eeprom_update_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); puts_P(_N("Temperature calibration done.")); @@ -4439,18 +4618,16 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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: @@ -4476,7 +4653,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) // We don't know where we are! HOME! // Push the commands to the front of the message queue in the reverse order! // There shall be always enough space reserved for these commands. - if (lcd_commands_type != LCD_COMMAND_STOP_PRINT) { + if (lcd_commands_type != LcdCommands::StopPrint) { repeatcommand_front(); // repeat G80 with all its parameters enquecommand_front_P((PSTR("G28 W0"))); } @@ -4516,7 +4693,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) if (temp_comp_start) if (run == false && temp_cal_active == true && calibration_status_pinda() == true && target_temperature_bed >= 50) { - if (lcd_commands_type != LCD_COMMAND_STOP_PRINT) { + if (lcd_commands_type != LcdCommands::StopPrint) { temp_compensation_start(); run = true; repeatcommand_front(); // repeat G80 with all its parameters @@ -4528,14 +4705,14 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) break; } run = false; - if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) { + if (lcd_commands_type == LcdCommands::StopPrint) { mesh_bed_leveling_flag = false; break; } // Save custom message state, set a new custom message state to display: Calibrating point 9. - unsigned int custom_message_type_old = custom_message_type; + CustomMsg custom_message_type_old = custom_message_type; unsigned int custom_message_state_old = custom_message_state; - custom_message_type = CUSTOM_MSG_TYPE_MESHBL; + custom_message_type = CustomMsg::MeshBedLeveling; custom_message_state = (nMeasPoints * nMeasPoints) + 10; lcd_update(1); @@ -4735,7 +4912,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) enable_z_endstop(bState); } while (st_get_position_mm(Z_AXIS) > MESH_HOME_Z_SEARCH); // i.e. Z-leveling not o.k. // plan_set_z_position(MESH_HOME_Z_SEARCH); // is not necessary ('do-while' loop always ends at the expected Z-position) - custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery + custom_message_type=CustomMsg::Status; // display / status-line recovery lcd_update_enable(true); // display / status-line recovery gcode_G28(true, true, true); // X & Y & Z-homing (must be after individual Z-homing (problem with spool-holder)!) repeatcommand_front(); // re-run (i.e. of "G80") @@ -4874,8 +5051,11 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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) { @@ -4899,7 +5079,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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! @@ -4915,7 +5095,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) SERIAL_PROTOCOLPGM("\n"); break; - /** + /* * G83: Prusa3D specific: Babystep in Z and store to EEPROM */ case 83: @@ -4940,7 +5120,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } break; - /** + /* * G84: Prusa3D specific: UNDO Babystep Z (move Z axis back) */ case 84: @@ -4948,7 +5128,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) // babystepLoadZ = 0; break; - /** + /* * G85: Prusa3D specific: Pick best babystep */ case 85: @@ -4956,38 +5136,58 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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++) { @@ -5004,20 +5204,27 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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); EEPROM_save_B(EEPROM_FARM_NUMBER, &farm_no); SilentModeMenu = SILENT_MODE_OFF; eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu); + fCheckModeInit(); // alternatively invoke printer reset break; - case 99: //! G99 (deactivate farm mode) + //! ### G99 - Deactivate farm mode + // ------------------------------------- + case 99: farm_mode = 0; lcd_printer_connected(); eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode); lcd_update(2); + fCheckModeInit(); // alternatively invoke printer reset break; default: printf_P(PSTR("Unknown G code: %s \n"), cmdbuffer + bufindr + CMDHDRSIZE); @@ -5026,6 +5233,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) gcode_in_progress = 0; } // end if(code_seen('G')) + + //! --------------------------------------------------------------------------------- + else if(code_seen('M')) { @@ -5044,6 +5254,8 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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 { @@ -5091,6 +5303,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) LCD_MESSAGERPGM(_T(WELCOME_MSG)); } break; + + //! ### M17 - Enable axes + // --------------------------------- case 17: LCD_MESSAGERPGM(_i("No move."));////MSG_NO_MOVE enable_x(); @@ -5102,44 +5317,68 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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'); @@ -5148,11 +5387,18 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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,'*')); @@ -5164,7 +5410,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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(); @@ -5199,7 +5448,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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'); @@ -5211,6 +5463,8 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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(); @@ -5226,7 +5480,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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(); @@ -5253,7 +5510,11 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } } 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); @@ -5267,7 +5528,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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'); @@ -5306,15 +5569,17 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } */ + //! ### 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); @@ -5352,11 +5617,15 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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. @@ -5602,6 +5871,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(); @@ -5615,6 +5891,8 @@ Sigma_Exit: } break; + //! ### M104 - Set hotend temperature + // ----------------------------------------- case 104: // M104 { uint8_t extruder; @@ -5628,13 +5906,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)){ @@ -5728,8 +6015,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; @@ -5779,7 +6069,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; @@ -5830,7 +6123,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); } @@ -5838,13 +6134,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); @@ -5862,7 +6164,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(); @@ -5883,12 +6187,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')){ @@ -5924,21 +6240,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])) @@ -5959,11 +6289,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); @@ -5974,13 +6310,23 @@ 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. SERIAL_PROTOCOLLNRPGM(FW_VERSION_STR_P()); } else if (code_seen('U')) { // Check the firmware version provided. If the firmware version provided by the U code is higher than the currently running firmware, - // pause the print and ask the user to upgrade the firmware. + // pause the print for 30s and ask the user to upgrade the firmware. show_upgrade_dialog_if_version_newer(++ strchr_pointer); } else { SERIAL_ECHOPGM("FIRMWARE_NAME:Prusa-Firmware "); @@ -5995,22 +6341,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 @@ -6069,8 +6436,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; @@ -6084,6 +6455,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). { @@ -6122,7 +6496,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])) @@ -6154,6 +6531,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++) { @@ -6177,10 +6557,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, @@ -6204,7 +6591,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(); @@ -6217,13 +6616,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')) @@ -6239,6 +6644,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')) @@ -6250,6 +6658,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')) @@ -6290,6 +6701,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; @@ -6317,6 +6731,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 @@ -6332,6 +6748,9 @@ Sigma_Exit: } } break; + + //! ### M221 - Set extrude factor override percentage + // ---------------------------------------------------- case 221: // M221 S- set extrude factor override percentage { if(code_seen('S')) @@ -6354,6 +6773,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')){ @@ -6407,6 +6828,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; @@ -6445,6 +6869,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; @@ -6452,10 +6879,7 @@ Sigma_Exit: if (beepS > 0) { #if BEEPER > 0 -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - _tone(BEEPER, beepS); - _delay(beepP); - _noTone(BEEPER); + Sound_MakeCustom(beepP,beepS,false); #endif } else @@ -6467,7 +6891,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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()); @@ -6495,7 +6922,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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()); @@ -6513,6 +6943,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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 @@ -6545,7 +6978,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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(); @@ -6553,7 +6989,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } break; #endif - case 303: // M303 PID autotune + + //! ### M303 - PID autotune + // ------------------------------------- + case 303: { float temp = 150.0; int e=0; @@ -6566,17 +7005,22 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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; @@ -6588,27 +7032,41 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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; @@ -6616,6 +7074,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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; @@ -6660,6 +7121,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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(); @@ -6734,20 +7198,39 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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; + //! ### 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; @@ -6791,7 +7274,18 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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; @@ -6862,14 +7356,110 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) break; #endif //PINDA_THERMISTOR + + //! ### 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. + + M862.3 accepts text identifiers of printer types too. + The syntax of M862.3 is (note the quotes around the type): + + M862.3 P "MK3S" + + Accepted printer type identifiers and their numeric counterparts: + - MK1 (100) + - MK2 (200) + - MK2MM (201) + - MK2S (202) + - MK2SMM (203) + - MK2.5 (250) + - MK2.5MMU2 (20250) + - MK2.5S (252) + - MK2.5SMMU2S (20252) + - MK3 (300) + - MK3MMU2 (20300) + - MK3S (302) + - MK3SMMU2S (20302) + */ + case 862: // M862: print checking + float nDummy; + uint8_t nCommand; + nCommand=(uint8_t)(modff(code_value_float(),&nDummy)*10.0+0.5); + switch((ClPrintChecking)nCommand) + { + case ClPrintChecking::_Nozzle: // ~ .1 + uint16_t nDiameter; + if(code_seen('P')) + { + nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um] + nozzle_diameter_check(nDiameter); + } +/* + else if(code_seen('S')&&farm_mode) + { + nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um] + eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)ClNozzleDiameter::_Diameter_Undef); // for correct synchronization after farm-mode exiting + eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter); + } +*/ + else if(code_seen('Q')) + SERIAL_PROTOCOLLN((float)eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)/1000.0); + break; + case ClPrintChecking::_Model: // ~ .2 + if(code_seen('P')) + { + uint16_t nPrinterModel; + nPrinterModel=(uint16_t)code_value_long(); + printer_model_check(nPrinterModel); + } + else if(code_seen('Q')) + SERIAL_PROTOCOLLN(nPrinterType); + break; + case ClPrintChecking::_Smodel: // ~ .3 + if(code_seen('P')) + printer_smodel_check(strchr_pointer); + else if(code_seen('Q')) + SERIAL_PROTOCOLLNRPGM(sPrinterName); + break; + case ClPrintChecking::_Version: // ~ .4 + if(code_seen('P')) + fw_version_check(++strchr_pointer); + else if(code_seen('Q')) + SERIAL_PROTOCOLLN(FW_VERSION); + break; + case ClPrintChecking::_Gcode: // ~ .5 + if(code_seen('P')) + { + uint16_t nGcodeLevel; + nGcodeLevel=(uint16_t)code_value_long(); + gcode_level_check(nGcodeLevel); + } + else if(code_seen('Q')) + SERIAL_PROTOCOLLN(GCODE_LEVEL); + break; + } + 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++) @@ -6900,7 +7490,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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; @@ -6913,13 +7506,17 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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()); @@ -6928,7 +7525,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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()); @@ -6936,13 +7535,18 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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(); @@ -6950,7 +7554,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } break; - case 915: //! M915 - Set silent mode + //! ### M95 - Set TMC2130 silent mode + // ------------------------------ + case 915: { tmc2130_mode = TMC2130_MODE_SILENT; update_mode_profile(); @@ -6958,7 +7564,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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(); @@ -6969,7 +7577,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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()); @@ -6978,7 +7588,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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()); @@ -6989,7 +7601,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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')) @@ -7026,7 +7641,13 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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()) @@ -7044,14 +7665,28 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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')) @@ -7073,7 +7708,9 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } 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; @@ -7087,6 +7724,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } } // 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 @@ -7280,46 +7921,95 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) } } // 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; @@ -7344,6 +8034,16 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) 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; @@ -7366,7 +8066,10 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) #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; @@ -7380,12 +8083,52 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) }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 @@ -7404,6 +8147,13 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) ClearToSend(); } + + + /** @defgroup GCodes G-Code List + */ + +// --------------------------------------------------- + void FlushSerialRequestResend() { //char cmdbuffer[bufindr][100]="Resend:"; @@ -7723,7 +8473,7 @@ static void handleSafetyTimer() { safetyTimer.start(); } - else if (safetyTimer.expired(safetytimer_inactive_time)) + else if (safetyTimer.expired(farm_mode?FARM_DEFAULT_SAFETYTIMER_TIME_ms:safetytimer_inactive_time)) { setTargetBed(0); setAllTargetHotends(0); @@ -7745,9 +8495,9 @@ bool bInhibitFlag; #ifdef IR_SENSOR bInhibitFlag=(menu_menu==lcd_menu_show_sensors_state); // Support::SensorInfo menu active #endif // IR_SENSOR - if ((mcode_in_progress != 600) && (eFilamentAction != e_FILAMENT_ACTION_autoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active + if ((mcode_in_progress != 600) && (eFilamentAction != FilamentAction::AutoLoad) && (!bInhibitFlag)) //M600 not in progress, preHeat @ autoLoad menu not active, Support::ExtruderInfo/SensorInfo menu not active { - if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL) && !wizard_active) + if (!moves_planned() && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal) && !wizard_active) { if (fsensor_check_autoload()) { @@ -7757,10 +8507,7 @@ bool bInhibitFlag; //-// if (degHotend0() > EXTRUDE_MINTEMP) if(0) { - if ((eSoundMode == e_SOUND_MODE_LOUD) || (eSoundMode == e_SOUND_MODE_ONCE)) - _tone(BEEPER, 1000); - delay_keep_alive(50); - _noTone(BEEPER); + Sound_MakeCustom(50,1000,false); loading_flag = true; enquecommand_front_P((PSTR("M701"))); } @@ -7771,7 +8518,7 @@ if(0) show_preheat_nozzle_warning(); lcd_update_enable(true); */ - eFilamentAction=e_FILAMENT_ACTION_autoLoad; + eFilamentAction=FilamentAction::AutoLoad; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -8170,12 +8917,15 @@ static void wait_for_heater(long codenum, uint8_t extruder) { void check_babystep() { - int babystep_z; - EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystep_z); + int babystep_z = eeprom_read_word(reinterpret_cast(&(EEPROM_Sheets_base-> + s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset))); + if ((babystep_z < Z_BABYSTEP_MIN) || (babystep_z > Z_BABYSTEP_MAX)) { babystep_z = 0; //if babystep value is out of min max range, set it to 0 SERIAL_ECHOLNPGM("Z live adjust out of range. Setting to 0"); - EEPROM_save_B(EEPROM_BABYSTEP_Z, &babystep_z); + eeprom_write_word(reinterpret_cast(&(EEPROM_Sheets_base-> + s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)), + babystep_z); lcd_show_fullscreen_message_and_wait_P(PSTR("Z live adjust out of range. Setting to 0. Click to continue.")); lcd_update_enable(true); } @@ -8245,7 +8995,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi float bed_zero_ref_y = (-0.6f + Y_PROBE_OFFSET_FROM_EXTRUDER); float mesh_home_z_search = 4; - float measure_z_heigth = 0.2f; + float measure_z_height = 0.2f; float row[x_points_num]; int ix = 0; int iy = 0; @@ -8262,7 +9012,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi unsigned int custom_message_type_old = custom_message_type; unsigned int custom_message_state_old = custom_message_state; - custom_message_type = CUSTOM_MSG_TYPE_MESHBL; + custom_message_type = CustomMsg::MeshBedLeveling; custom_message_state = (x_points_num * y_points_num) + 10; lcd_update(1); @@ -8280,7 +9030,7 @@ void bed_check(float x_dimension, float y_dimension, int x_points_num, int y_poi } st_synchronize(); */ - destination[Z_AXIS] = measure_z_heigth; + destination[Z_AXIS] = measure_z_height; plan_buffer_line(destination[X_AXIS], destination[Y_AXIS], destination[Z_AXIS], destination[E_AXIS], Z_LIFT_FEEDRATE, active_extruder); for(int8_t i=0; i < NUM_AXIS; i++) { current_position[i] = destination[i]; @@ -8460,7 +9210,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_ } unsigned int custom_message_type_old = custom_message_type; unsigned int custom_message_state_old = custom_message_state; - custom_message_type = CUSTOM_MSG_TYPE_MESHBL; + custom_message_type = CustomMsg::MeshBedLeveling; custom_message_state = (x_points_num * y_points_num) + 10; lcd_update(1); @@ -8610,7 +9360,7 @@ void bed_analysis(float x_dimension, float y_dimension, int x_points_num, int y_ void temp_compensation_start() { - custom_message_type = CUSTOM_MSG_TYPE_TEMPRE; + custom_message_type = CustomMsg::TempCompPreheat; custom_message_state = PINDA_HEAT_T + 1; lcd_update(2); if (degHotend(active_extruder) > EXTRUDE_MINTEMP) { @@ -8631,7 +9381,7 @@ void temp_compensation_start() { if (custom_message_state == 99 || custom_message_state == 9) lcd_update(2); //force whole display redraw if number of digits changed else lcd_update(1); } - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsg::Status; custom_message_state = 0; } @@ -9020,8 +9770,7 @@ ISR(INT4_vect) { EIMSK &= ~(1 << 4); //disable INT4 interrupt to make sure that this code will be executed just once SERIAL_ECHOLNPGM("INT4"); //fire normal uvlo only in case where EEPROM_UVLO is 0 or if IS_SD_PRINTING is 1. - //Don't change || to && because in some case the printer can be moving although IS_SD_PRINTING is zero - if((IS_SD_PRINTING ) || (!(eeprom_read_byte((uint8_t*)EEPROM_UVLO)))) uvlo_(); + if(PRINTER_ACTIVE && (!(eeprom_read_byte((uint8_t*)EEPROM_UVLO)))) uvlo_(); if(eeprom_read_byte((uint8_t*)EEPROM_UVLO)) uvlo_tiny(); } @@ -9382,7 +10131,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 @@ -9410,10 +10158,11 @@ void stop_and_save_print_to_ram(float z_move, float e_move) //! @brief Restore print from ram //! -//! Restore print saved by stop_and_save_print_to_ram(). Is blocking, -//! waits for extruder temperature restore, then restores position and continues -//! print moves. -//! Internaly lcd_update() is called by wait_for_heater(). +//! Restore print saved by stop_and_save_print_to_ram(). Is blocking, restores +//! print fan speed, waits for extruder temperature restore, then restores +//! position and continues print moves. +//! +//! Internally lcd_update() is called by wait_for_heater(). //! //! @param e_move void restore_print_from_ram_and_continue(float e_move) @@ -9428,7 +10177,9 @@ void restore_print_from_ram_and_continue(float e_move) // for (int axis = X_AXIS; axis <= E_AXIS; axis++) // current_position[axis] = st_get_position_mm(axis); active_extruder = saved_active_extruder; //restore active_extruder - if (saved_extruder_temperature) { + fanSpeed = saved_fanSpeed; + if (degTargetHotend(saved_active_extruder) != saved_extruder_temperature) + { setTargetHotendSafe(saved_extruder_temperature, saved_active_extruder); heating_status = 1; wait_for_heater(_millis(), saved_active_extruder); @@ -9436,7 +10187,6 @@ void restore_print_from_ram_and_continue(float e_move) } feedrate = saved_feedrate2; //restore feedrate axis_relative_modes[E_AXIS] = saved_extruder_relative_mode; - fanSpeed = saved_fanSpeed; float e = saved_pos[E_AXIS] - e_move; plan_set_e_position(e); @@ -9464,7 +10214,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 @@ -9474,6 +10223,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; } @@ -9610,7 +10360,7 @@ void M600_wait_for_user(float HotendTempBckp) { } SET_OUTPUT(BEEPER); if (counterBeep == 0) { - if((eSoundMode==e_SOUND_MODE_LOUD)||((eSoundMode==e_SOUND_MODE_ONCE)&&bFirst)) + if((eSoundMode==e_SOUND_MODE_BLIND)|| (eSoundMode==e_SOUND_MODE_LOUD)||((eSoundMode==e_SOUND_MODE_ONCE)&&bFirst)) { bFirst=false; WRITE(BEEPER, HIGH); @@ -9713,10 +10463,7 @@ void M600_load_filament() { #ifdef FILAMENT_SENSOR if (fsensor_check_autoload()) { -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - _tone(BEEPER, 1000); - delay_keep_alive(50); - _noTone(BEEPER); + Sound_MakeCustom(50,1000,false); break; } #endif //FILAMENT_SENSOR @@ -9732,10 +10479,7 @@ if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) M600_load_filament_movements(); -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - _tone(BEEPER, 500); - delay_keep_alive(50); - _noTone(BEEPER); + Sound_MakeCustom(50,1000,false); #ifdef FSENSOR_QUALITY fsensor_oq_meassure_stop(); @@ -9771,3 +10515,69 @@ void marlin_wait_for_click() } #define FIL_LOAD_LENGTH 60 + +#ifdef PSU_Delta +bool bEnableForce_z; + +void init_force_z() +{ +WRITE(Z_ENABLE_PIN,Z_ENABLE_ON); +bEnableForce_z=true; // "true"-value enforce "disable_force_z()" executing +disable_force_z(); +} + +void check_force_z() +{ +if(!(bEnableForce_z||eeprom_read_byte((uint8_t*)EEPROM_SILENT))) + init_force_z(); // causes enforced switching into disable-state +} + +void disable_force_z() +{ +uint16_t z_microsteps=0; + +if(!bEnableForce_z) + return; // motor already disabled (may be ;-p ) +bEnableForce_z=false; + +// alignment to full-step +#ifdef TMC2130 +z_microsteps=tmc2130_rd_MSCNT(Z_TMC2130_CS); +#endif // TMC2130 +planner_abort_hard(); +sei(); +plan_buffer_line( + current_position[X_AXIS], + current_position[Y_AXIS], + current_position[Z_AXIS]+float((1024-z_microsteps+7)>>4)/cs.axis_steps_per_unit[Z_AXIS], + current_position[E_AXIS], + 40, active_extruder); +st_synchronize(); + +// switching to silent mode +#ifdef TMC2130 +tmc2130_mode=TMC2130_MODE_SILENT; +update_mode_profile(); +tmc2130_init(true); +#endif // TMC2130 + +axis_known_position[Z_AXIS]=false; +} + + +void enable_force_z() +{ +if(bEnableForce_z) + return; // motor already enabled (may be ;-p ) +bEnableForce_z=true; + +// mode recovering +#ifdef TMC2130 +tmc2130_mode=eeprom_read_byte((uint8_t*)EEPROM_SILENT)?TMC2130_MODE_SILENT:TMC2130_MODE_NORMAL; +update_mode_profile(); +tmc2130_init(true); +#endif // TMC2130 + +WRITE(Z_ENABLE_PIN,Z_ENABLE_ON); // slightly redundant ;-p +} +#endif // PSU_Delta diff --git a/Firmware/cmdqueue.cpp b/Firmware/cmdqueue.cpp old mode 100644 new mode 100755 index 2e29ad5f9..37b6388d0 --- 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::FarmModeConfirm; } } diff --git a/Firmware/doxyfile b/Firmware/doxyfile index 9c2d550c0..346ce6045 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 diff --git a/Firmware/eeprom.cpp b/Firmware/eeprom.cpp new file mode 100644 index 000000000..94314ddd4 --- /dev/null +++ b/Firmware/eeprom.cpp @@ -0,0 +1,95 @@ +//! @file +//! @date Jun 20, 2019 +//! @author Marek Běl + +#include "eeprom.h" +#include "Marlin.h" + +#include +#include + + +#include "language.h" + +#if 0 +template +static T eeprom_read(T *address); + +template<> +char eeprom_read(char *address) +{ + return eeprom_read_byte(reinterpret_cast(address)); +} +#endif + +template +static void eeprom_write(T *address, T value); + +template<> +void eeprom_write(char *addres, char value) +{ + eeprom_write_byte(reinterpret_cast(addres), static_cast(value)); +} + + +template +static bool eeprom_is_uninitialized(T *address); + +template <> +bool eeprom_is_uninitialized(char *address) +{ + return (0xff == eeprom_read_byte(reinterpret_cast(address))); +} + +bool is_sheet_initialized(uint8_t sheet_num){ + return (0xffff != eeprom_read_word(reinterpret_cast(&(EEPROM_Sheets_base-> + s[sheet_num].z_offset)))); +} + +void eeprom_init() +{ + if (eeprom_read_byte((uint8_t*)EEPROM_POWER_COUNT) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_POWER_COUNT, 0); + if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_CRASH_COUNT_X, 0); + if (eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_CRASH_COUNT_Y, 0); + if (eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT) == 0xff) eeprom_write_byte((uint8_t*)EEPROM_FERROR_COUNT, 0); + if (eeprom_read_word((uint16_t*)EEPROM_POWER_COUNT_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_POWER_COUNT_TOT, 0); + if (eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT, 0); + if (eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT, 0); + if (eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT) == 0xffff) eeprom_write_word((uint16_t*)EEPROM_FERROR_COUNT_TOT, 0); + + if (eeprom_read_word((uint16_t*)EEPROM_MMU_FAIL_TOT) == 0xffff) eeprom_update_word((uint16_t *)EEPROM_MMU_FAIL_TOT, 0); + if (eeprom_read_word((uint16_t*)EEPROM_MMU_LOAD_FAIL_TOT) == 0xffff) eeprom_update_word((uint16_t *)EEPROM_MMU_LOAD_FAIL_TOT, 0); + if (eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_FAIL, 0); + if (eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL) == 0xff) eeprom_update_byte((uint8_t *)EEPROM_MMU_LOAD_FAIL, 0); + if (eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)) == 0xff) eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), 0); + + for (uint_least8_t i = 0; i < (sizeof(Sheets::s)/sizeof(Sheets::s[0])); ++i) + { + bool is_uninitialized = true; + for (uint_least8_t j = 0; j < (sizeof(Sheet::name)/sizeof(Sheet::name[0])); ++j) + { + if (!eeprom_is_uninitialized(&(EEPROM_Sheets_base->s[i].name[j]))) is_uninitialized = false; + } + if(is_uninitialized) + { + + char sheet_PROGMEM_buffer[8]; + strcpy_P(sheet_PROGMEM_buffer, (char *)pgm_read_word(&(defaultSheetNames[i]))); + for (uint_least8_t a = 0; a < sizeof(Sheet::name); ++a){ + eeprom_write(&(EEPROM_Sheets_base->s[i].name[a]), sheet_PROGMEM_buffer[a]); + } + + // 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); + } + } + } + check_babystep(); +} + + + + diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index 899d52359..c41fb9ff9 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -1,6 +1,36 @@ #ifndef EEPROM_H #define EEPROM_H +#include + +#ifdef __cplusplus +void eeprom_init(); +extern bool is_sheet_initialized(uint8_t sheet_num); +#endif + + +typedef struct +{ + char name[7]; //!< Can be null terminated, doesn't need to be null terminated + int16_t z_offset; //!< Z_BABYSTEP_MIN .. Z_BABYSTEP_MAX = Z_BABYSTEP_MIN*2/1000 [mm] .. Z_BABYSTEP_MAX*2/1000 [mm] + uint8_t bed_temp; //!< 0 .. 254 [°C] + uint8_t pinda_temp; //!< 0 .. 254 [°C] +} Sheet; + +typedef struct +{ + Sheet s[3]; + uint8_t active_sheet; +} Sheets; +// sizeof(Sheets). Do not change it unless EEPROM_Sheets_base is last item in EEPROM. +// Otherwise it would move following items. +#define EEPROM_SHEETS_SIZEOF 34 + +#ifdef __cplusplus +static_assert(sizeof(Sheets) == EEPROM_SHEETS_SIZEOF, "Sizeof(Sheets) is not EEPROM_SHEETS_SIZEOF."); +#endif + +#define EEPROM_EMPTY_VALUE 0xFF // The total size of the EEPROM is // 4096 for the Atmega2560 #define EEPROM_TOP 4096 @@ -155,36 +185,32 @@ #define EEPROM_MMU_LOAD_FAIL (EEPROM_MMU_LOAD_FAIL_TOT - 1) //uint8_t #define EEPROM_MMU_CUTTER_ENABLED (EEPROM_MMU_LOAD_FAIL - 1) #define EEPROM_UVLO_MESH_BED_LEVELING_FULL (EEPROM_MMU_CUTTER_ENABLED - 12*12*2) //allow 12 calibration points for future expansion + #define EEPROM_MBL_TYPE (EEPROM_UVLO_MESH_BED_LEVELING_FULL-1) //uint8_t for mesh bed leveling precision #define EEPROM_MBL_MAGNET_ELIMINATION (EEPROM_MBL_TYPE -1) #define EEPROM_MBL_POINTS_NR (EEPROM_MBL_MAGNET_ELIMINATION -1) //uint8_t number of points in one exis for mesh bed leveling #define EEPROM_MBL_PROBE_NR (EEPROM_MBL_POINTS_NR-1) //number of measurements for each point + #define EEPROM_MMU_STEALTH (EEPROM_MBL_PROBE_NR-1) + +#define EEPROM_CHECK_MODE (EEPROM_MMU_STEALTH-1) // uint8 +#define EEPROM_NOZZLE_DIAMETER (EEPROM_CHECK_MODE-1) // uint8 +#define EEPROM_NOZZLE_DIAMETER_uM (EEPROM_NOZZLE_DIAMETER-2) // uint16 +#define EEPROM_CHECK_MODEL (EEPROM_NOZZLE_DIAMETER_uM-1) // uint8 +#define EEPROM_CHECK_VERSION (EEPROM_CHECK_MODEL-1) // uint8 +#define EEPROM_CHECK_GCODE (EEPROM_CHECK_VERSION-1) // uint8 + +#define EEPROM_SHEETS_BASE (EEPROM_CHECK_GCODE - EEPROM_SHEETS_SIZEOF) // Sheets +static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE); + + +//This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items. +#define EEPROM_LAST_ITEM EEPROM_SHEETS_BASE // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! -//TMC2130 configuration -#define EEPROM_TMC_AXIS_SIZE //axis configuration block size -#define EEPROM_TMC_X (EEPROM_TMC + 0 * EEPROM_TMC_AXIS_SIZE) //X axis configuration blok -#define EEPROM_TMC_Y (EEPROM_TMC + 1 * EEPROM_TMC_AXIS_SIZE) //Y axis -#define EEPROM_TMC_Z (EEPROM_TMC + 2 * EEPROM_TMC_AXIS_SIZE) //Z axis -#define EEPROM_TMC_E (EEPROM_TMC + 3 * EEPROM_TMC_AXIS_SIZE) //E axis -//TMC2130 - X axis -#define EEPROM_TMC_X_USTEPS_INTPOL (EEPROM_TMC_X + 0) // 1byte, bit 0..4 USTEPS, bit 7 INTPOL -#define EEPROM_TMC_X_PWM_AMPL (EEPROM_TMC_X + 1) // 1byte (0..255) -#define EEPROM_TMC_X_PWM_GRAD_FREQ (EEPROM_TMC_X + 2) // 1byte, bit 0..3 GRAD, bit 4..5 FREQ -#define EEPROM_TMC_X_TCOOLTHRS (EEPROM_TMC_X + 3) // 2bytes (0..) -#define EEPROM_TMC_X_SG_THRS (EEPROM_TMC_X + 5) // 1byte, (-64..+63) -#define EEPROM_TMC_X_CURRENT_H (EEPROM_TMC_X + 6) // 1byte, (0..63) -#define EEPROM_TMC_X_CURRENT_R (EEPROM_TMC_X + 7) // 1byte, (0..63) -#define EEPROM_TMC_X_HOME_SG_THRS (EEPROM_TMC_X + 8) // 1byte, (-64..+63) -#define EEPROM_TMC_X_HOME_CURRENT_R (EEPROM_TMC_X + 9) // 1byte, (-64..+63) -#define EEPROM_TMC_X_HOME_DTCOOLTHRS (EEPROM_TMC_X + 10) // 1byte (-128..+127) -#define EEPROM_TMC_X_DTCOOLTHRS_LOW (EEPROM_TMC_X + 11) // 1byte (-128..+127) -#define EEPROM_TMC_X_DTCOOLTHRS_HIGH (EEPROM_TMC_X + 12) // 1byte (-128..+127) -#define EEPROM_TMC_X_SG_THRS_LOW (EEPROM_TMC_X + 13) // 1byte, (-64..+63) -#define EEPROM_TMC_X_SG_THRS_HIGH (EEPROM_TMC_X + 14) // 1byte, (-64..+63) + // Currently running firmware, each digit stored as uint16_t. // The flavor differentiates a dev, alpha, beta, release candidate or a release version. @@ -198,7 +224,9 @@ #ifdef __cplusplus #include "ConfigurationStore.h" -static M500_conf * const EEPROM_M500_base = reinterpret_cast(20); //offset for storing settings using M500 +static_assert(EEPROM_FIRMWARE_VERSION_END < 20, "Firmware version EEPROM address conflicts with EEPROM_M500_base"); +static constexpr M500_conf * const EEPROM_M500_base = reinterpret_cast(20); //offset for storing settings using M500 +static_assert(((sizeof(M500_conf) + 20) < EEPROM_LAST_ITEM), "M500_conf address space conflicts with previous items."); #endif enum diff --git a/Firmware/first_lay_cal.cpp b/Firmware/first_lay_cal.cpp new file mode 100644 index 000000000..bfec021fd --- /dev/null +++ b/Firmware/first_lay_cal.cpp @@ -0,0 +1,214 @@ +//! @file +//! @date Jun 10, 2019 +//! @author Marek Bel +//! @brief First layer (Z offset) calibration + +#include "first_lay_cal.h" +#include "Configuration_prusa.h" +#include "language.h" +#include "Marlin.h" +#include "mmu.h" +#include + +//! @brief Preheat +void lay1cal_preheat() +{ + static const char cmd_preheat_0[] PROGMEM = "M107"; + static const char cmd_preheat_1[] PROGMEM = "M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP); + static const char cmd_preheat_2[] PROGMEM = "M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP); + static const char cmd_preheat_3[] PROGMEM = "M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP); + static const char cmd_preheat_4[] PROGMEM = "M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP); + static const char cmd_preheat_5[] PROGMEM = "G28"; + static const char cmd_preheat_6[] PROGMEM = "G92 E0.0"; + + static const char * const preheat_cmd[] PROGMEM = + { + cmd_preheat_0, + cmd_preheat_1, + cmd_preheat_2, + cmd_preheat_3, + cmd_preheat_4, + cmd_preheat_5, //call MSG_M117_V2_CALIBRATION before + cmd_preheat_6, + }; + + for (uint8_t i = 0; i < (sizeof(preheat_cmd)/sizeof(preheat_cmd[0])); ++i) + { + if (5 == i) enquecommand_P(_T(MSG_M117_V2_CALIBRATION)); + enquecommand_P(static_cast(pgm_read_ptr(&preheat_cmd[i]))); + } + +} + +//! @brief Print intro line +//! @param cmd_buffer character buffer needed to format gcodes +//! @param filament filament to use (applies for MMU only) +void lay1cal_intro_line(char *cmd_buffer, uint8_t filament) +{ + static const char cmd_intro_mmu_0[] PROGMEM = "M83"; + static const char cmd_intro_mmu_1[] PROGMEM = "G1 Y-3.0 F1000.0"; + static const char cmd_intro_mmu_2[] PROGMEM = "G1 Z0.4 F1000.0"; + static const char cmd_intro_mmu_3[] PROGMEM = "G1 X55.0 E32.0 F1073.0"; // call T code before + static const char cmd_intro_mmu_4[] PROGMEM = "G1 X5.0 E32.0 F1800.0"; + static const char cmd_intro_mmu_5[] PROGMEM = "G1 X55.0 E8.0 F2000.0"; + static const char cmd_intro_mmu_6[] PROGMEM = "G1 Z0.3 F1000.0"; + static const char cmd_intro_mmu_7[] PROGMEM = "G92 E0.0"; + static const char cmd_intro_mmu_8[] PROGMEM = "G1 X240.0 E25.0 F2200.0"; + static const char cmd_intro_mmu_9[] PROGMEM = "G1 Y-2.0 F1000.0"; + static const char cmd_intro_mmu_10[] PROGMEM = "G1 X55.0 E25 F1400.0"; + static const char cmd_intro_mmu_11[] PROGMEM = "G1 Z0.20 F1000.0"; + static const char cmd_intro_mmu_12[] PROGMEM = "G1 X5.0 E4.0 F1000.0"; + + static const char * const intro_mmu_cmd[] PROGMEM = + { + cmd_intro_mmu_0, + cmd_intro_mmu_1, + cmd_intro_mmu_2, + cmd_intro_mmu_3, // call T code before + cmd_intro_mmu_4, + cmd_intro_mmu_5, + cmd_intro_mmu_6, + cmd_intro_mmu_7, + cmd_intro_mmu_8, + cmd_intro_mmu_9, + cmd_intro_mmu_10, + cmd_intro_mmu_11, + cmd_intro_mmu_12, + }; + + if (mmu_enabled) + { + for (uint8_t i = 0; i < (sizeof(intro_mmu_cmd)/sizeof(intro_mmu_cmd[0])); ++i) + { + if (3 == i) + { + sprintf_P(cmd_buffer, PSTR("T%d"), filament); + enquecommand(cmd_buffer); + } + enquecommand_P(static_cast(pgm_read_ptr(&intro_mmu_cmd[i]))); + } + } + else + { + enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0")); + enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0")); + } +} + +//! @brief Setup for printing meander +void lay1cal_before_meander() +{ + static const char cmd_pre_meander_0[] PROGMEM = "G92 E0.0"; + static const char cmd_pre_meander_1[] PROGMEM = "G21"; //set units to millimeters TODO unsupported command + static const char cmd_pre_meander_2[] PROGMEM = "G90"; //use absolute coordinates + static const char cmd_pre_meander_3[] PROGMEM = "M83"; //use relative distances for extrusion TODO: duplicate + static const char cmd_pre_meander_4[] PROGMEM = "G1 E-1.50000 F2100.00000"; + static const char cmd_pre_meander_5[] PROGMEM = "G1 Z5 F7200.000"; + static const char cmd_pre_meander_6[] PROGMEM = "M204 S1000"; //set acceleration + static const char cmd_pre_meander_7[] PROGMEM = "G1 F4000"; + + static const char * const cmd_pre_meander[] PROGMEM = + { + cmd_pre_meander_0, + cmd_pre_meander_1, + cmd_pre_meander_2, + cmd_pre_meander_3, + cmd_pre_meander_4, + cmd_pre_meander_5, + cmd_pre_meander_6, + cmd_pre_meander_7, + }; + + for (uint8_t i = 0; i < (sizeof(cmd_pre_meander)/sizeof(cmd_pre_meander[0])); ++i) + { + enquecommand_P(static_cast(pgm_read_ptr(&cmd_pre_meander[i]))); + } +} + + +//! @brief Count extrude length +//! +//! @param layer_height layer height in mm +//! @param extrusion_width extrusion width in mm +//! @param extrusion_length extrusion length in mm +//! @return filament length in mm which needs to be extruded to form line +static constexpr float count_e(float layer_height, float extrusion_width, float extrusion_length) +{ + return (extrusion_length * layer_height * extrusion_width / (M_PI * pow(1.75, 2) / 4)); +} + +static const float width = 0.4; //!< line width +static const float length = 20 - width; //!< line length +static const float height = 0.2; //!< layer height TODO This is wrong, as current Z height is 0.15 mm +static const float extr = count_e(height, width, length); //!< E axis movement needed to print line + +//! @brief Print meander +//! @param cmd_buffer character buffer needed to format gcodes +void lay1cal_meander(char *cmd_buffer) +{ + static const char cmd_meander_0[] PROGMEM = "G1 X50 Y155"; + static const char cmd_meander_1[] PROGMEM = "G1 Z0.150 F7200.000"; + static const char cmd_meander_2[] PROGMEM = "G1 F1080"; + static const char cmd_meander_3[] PROGMEM = "G1 X75 Y155 E2.5"; + static const char cmd_meander_4[] PROGMEM = "G1 X100 Y155 E2"; + static const char cmd_meander_5[] PROGMEM = "G1 X200 Y155 E2.62773"; + static const char cmd_meander_6[] PROGMEM = "G1 X200 Y135 E0.66174"; + static const char cmd_meander_7[] PROGMEM = "G1 X50 Y135 E3.62773"; + static const char cmd_meander_8[] PROGMEM = "G1 X50 Y115 E0.49386"; + static const char cmd_meander_9[] PROGMEM = "G1 X200 Y115 E3.62773"; + static const char cmd_meander_10[] PROGMEM = "G1 X200 Y95 E0.49386"; + static const char cmd_meander_11[] PROGMEM = "G1 X50 Y95 E3.62773"; + static const char cmd_meander_12[] PROGMEM = "G1 X50 Y75 E0.49386"; + static const char cmd_meander_13[] PROGMEM = "G1 X200 Y75 E3.62773"; + static const char cmd_meander_14[] PROGMEM = "G1 X200 Y55 E0.49386"; + static const char cmd_meander_15[] PROGMEM = "G1 X50 Y55 E3.62773"; + + static const char * const cmd_meander[] PROGMEM = + { + cmd_meander_0, + cmd_meander_1, + cmd_meander_2, + cmd_meander_3, + cmd_meander_4, + cmd_meander_5, + cmd_meander_6, + cmd_meander_7, + cmd_meander_8, + cmd_meander_9, + cmd_meander_10, + cmd_meander_11, + cmd_meander_12, + cmd_meander_13, + cmd_meander_14, + cmd_meander_15, + }; + + for (uint8_t i = 0; i < (sizeof(cmd_meander)/sizeof(cmd_meander[0])); ++i) + { + enquecommand_P(static_cast(pgm_read_ptr(&cmd_meander[i]))); + } + sprintf_P(cmd_buffer, PSTR("G1 X50 Y35 E%-.3f"), extr); + enquecommand(cmd_buffer); +} + +//! @brief Print square +//! +//! This function needs to be called 16 times for i from 0 to 15. +//! +//! @param cmd_buffer character buffer needed to format gcodes +//! @param i iteration +void lay1cal_square(char *cmd_buffer, uint8_t i) +{ + const float extr_short_segment = count_e(height, width, width); + + static const char fmt1[] PROGMEM = "G1 X%d Y%-.2f E%-.3f"; + static const char fmt2[] PROGMEM = "G1 Y%-.2f E%-.3f"; + sprintf_P(cmd_buffer, fmt1, 70, (35 - i*width * 2), extr); + enquecommand(cmd_buffer); + sprintf_P(cmd_buffer, fmt2, (35 - (2 * i + 1)*width), extr_short_segment); + enquecommand(cmd_buffer); + sprintf_P(cmd_buffer, fmt1, 50, (35 - (2 * i + 1)*width), extr); + enquecommand(cmd_buffer); + sprintf_P(cmd_buffer, fmt2, (35 - (i + 1)*width * 2), extr_short_segment); + enquecommand(cmd_buffer); +} diff --git a/Firmware/first_lay_cal.h b/Firmware/first_lay_cal.h new file mode 100644 index 000000000..1f338cc51 --- /dev/null +++ b/Firmware/first_lay_cal.h @@ -0,0 +1,15 @@ +//! @file +//! @date Jun 10, 2019 +//! @author Marek Bel + +#ifndef FIRMWARE_FIRST_LAY_CAL_H_ +#define FIRMWARE_FIRST_LAY_CAL_H_ +#include + +void lay1cal_preheat(); +void lay1cal_intro_line(char *cmd_buffer, uint8_t filament); +void lay1cal_before_meander(); +void lay1cal_meander(char *cmd_buffer); +void lay1cal_square(char *cmd_buffer, uint8_t i); + +#endif /* FIRMWARE_FIRST_LAY_CAL_H_ */ diff --git a/Firmware/fsensor.cpp b/Firmware/fsensor.cpp index fd7936ee9..f20f647d6 100755 --- a/Firmware/fsensor.cpp +++ b/Firmware/fsensor.cpp @@ -522,19 +522,6 @@ void fsensor_st_block_chunk(block_t* bl, int cnt) } } -//! This ensures generating z-position at least 25mm above the heat bed. -//! Making this a template enables changing the computation data type easily at all spots where necessary. -//! @param current_z current z-position -//! @return z-position at least 25mm above the heat bed plus FILAMENTCHANGE_ZADD -template -inline T fsensor_clamp_z(float current_z){ - T z( current_z ); - if(z < T(25)){ // make sure the compiler understands, that the constant 25 is of correct type - // - necessary for uint8_t -> results in shorter code - z = T(25); // move to at least 25mm above heat bed - } - return z + T(FILAMENTCHANGE_ZADD); // always move above the printout by FILAMENTCHANGE_ZADD (default 2mm) -} //! Common code for enqueing M600 and supplemental codes into the command queue. //! Used both for the IR sensor and the PAT9125 @@ -545,22 +532,6 @@ void fsensor_enque_M600(){ enquecommand_front_P(PSTR("PRUSA fsensor_recover")); fsensor_m600_enqueued = true; enquecommand_front_P((PSTR("M600"))); -#define xstr(a) str(a) -#define str(a) #a - static const char gcodeMove[] PROGMEM = - "G1 X" xstr(FILAMENTCHANGE_XPOS) - " Y" xstr(FILAMENTCHANGE_YPOS) - " Z%u"; -#undef str -#undef xstr - char buf[32]; - // integer arithmetics is far shorter, I don't need a precise float position here, just move a bit above - // 8bit arithmetics in fsensor_clamp_z is 10B shorter than 16bit (not talking about float ;) ) - // The compile-time static_assert here ensures, that the computation gets enough bits in case of Z-range too high, - // i.e. makes the user change the data type, which also results in larger code - static_assert(Z_MAX_POS < (255 - FILAMENTCHANGE_ZADD), "Z-range too high, change fsensor_clamp_z to "); - sprintf_P(buf, gcodeMove, fsensor_clamp_z(current_position[Z_AXIS]) ); - enquecommand_front(buf, false); } //! @brief filament sensor update (perform M600 on filament runout) diff --git a/Firmware/heatbed_pwm.cpp b/Firmware/heatbed_pwm.cpp new file mode 100755 index 000000000..8a913b638 --- /dev/null +++ b/Firmware/heatbed_pwm.cpp @@ -0,0 +1,109 @@ +#include +#include +#include "io_atmega2560.h" + +// All this is about silencing the heat bed, as it behaves like a loudspeaker. +// Basically, we want the PWM heating switched at 30Hz (or so) which is a well ballanced +// frequency for both power supply units (i.e. both PSUs are reasonably silent). +// The only trouble is the rising or falling edge of bed heating - that creates an audible click. +// This audible click may be suppressed by making the rising or falling edge NOT sharp. +// Of course, making non-sharp edges in digital technology is not easy, but there is a solution. +// It is possible to do a fast PWM sequence with duty starting from 0 to 255. +// Doing this at higher frequency than the bed "loudspeaker" can handle makes the click barely audible. +// Technically: +// timer0 is set to fast PWM mode at 62.5kHz (timer0 is linked to the bed heating pin) (zero prescaler) +// To keep the bed switching at 30Hz - we don't want the PWM running at 62kHz all the time +// since it would burn the heatbed's MOSFET: +// 16MHz/256 levels of PWM duty gives us 62.5kHz +// 62.5kHz/256 gives ~244Hz, that is still too fast - 244/8 gives ~30Hz, that's what we need +// So the automaton runs atop of inner 8 (or 16) cycles. +// The finite automaton is running in the ISR(TIMER0_OVF_vect) + +///! Definition off finite automaton states +enum class States : uint8_t { + ZERO = 0, + RISE = 1, + ONE = 2, + FALL = 3 +}; + +///! State table for the inner part of the finite automaton +///! Basically it specifies what shall happen if the outer automaton is requesting setting the heat pin to 0 (OFF) or 1 (ON) +///! ZERO: steady 0 (OFF), no change for the whole period +///! RISE: 8 (16) fast PWM cycles with increasing duty up to steady ON +///! ONE: steady 1 (ON), no change for the whole period +///! FALL: 8 (16) fast PWM cycles with decreasing duty down to steady OFF +///! @@TODO move it into progmem +static States stateTable[4*2] = { +// off on +States::ZERO, States::RISE, // ZERO +States::FALL, States::ONE, // RISE +States::FALL, States::ONE, // ONE +States::ZERO, States::RISE // FALL +}; + +///! Inner states of the finite automaton +static States state = States::ZERO; + +///! Inner and outer PWM counters +static uint8_t outer = 0; +static uint8_t inner = 0; +static uint8_t pwm = 0; + +///! the slow PWM duty for the next 30Hz cycle +///! Set in the whole firmware at various places +extern unsigned char soft_pwm_bed; + +/// Fine tuning of automaton cycles +#if 1 +static const uint8_t innerMax = 16; +static const uint8_t innerShift = 4; +#else +static const uint8_t innerMax = 8; +static const uint8_t innerShift = 5; +#endif + +ISR(TIMER0_OVF_vect) // timer compare interrupt service routine +{ + if( inner ){ + switch(state){ + case States::ZERO: + OCR0B = 255; + // Commenting the following code saves 6B, but it is left here for reference + // It is not necessary to set it all over again, because we can only get into the ZERO state from the FALL state (which sets this register) +// TCCR0A |= (1 << COM0B1) | (1 << COM0B0); + break; + case States::RISE: + OCR0B = (innerMax - inner) << innerShift; +// TCCR0A |= (1 << COM0B1); // this bit is always 1 + TCCR0A &= ~(1 << COM0B0); + break; + case States::ONE: + OCR0B = 255; + // again - may be skipped, because we get into the ONE state only from RISE (which sets this register) +// TCCR0A |= (1 << COM0B1); + TCCR0A &= ~(1 << COM0B0); + break; + case States::FALL: + OCR0B = (innerMax - inner) << innerShift; // this is the same as in RISE, because now we are setting the zero part of duty due to inverting mode + // must switch to inverting mode already here, because it takes a whole PWM cycle and it would make a "1" at the end of this pwm cycle + TCCR0A |= /*(1 << COM0B1) |*/ (1 << COM0B0); + break; + } + --inner; + } else { + if( ! outer ){ // at the end of 30Hz PWM period + // synchro is not needed (almost), soft_pwm_bed is just 1 byte, 1-byte write instruction is atomic + pwm = soft_pwm_bed << 1; + } + if( pwm > outer || pwm >= 254 ){ + // soft_pwm_bed has a range of 0-127, that why a <<1 is done here. That also means that we may get only up to 254 which we want to be full-time 1 (ON) + state = stateTable[ uint8_t(state) * 2 + 1 ]; + } else { + // switch OFF + state = stateTable[ uint8_t(state) * 2 + 0 ]; + } + ++outer; + inner = innerMax; + } +} diff --git a/Firmware/io_atmega2560.h b/Firmware/io_atmega2560.h index e8c756ffb..e353eb05e 100644 --- a/Firmware/io_atmega2560.h +++ b/Firmware/io_atmega2560.h @@ -368,6 +368,7 @@ #define PIN_SET(pin) PORT(pin) |= __MSK(pin) #define PIN_VAL(pin, val) if (val) PIN_SET(pin); else PIN_CLR(pin); #define PIN_GET(pin) (PIN(pin) & __MSK(pin)) +#define PIN_INQ(pin) (PORT(pin) & __MSK(pin)) #endif //_IO_ATMEGA2560 diff --git a/Firmware/lcd.cpp b/Firmware/lcd.cpp index e5d020c0b..fd3e1328f 100644 --- a/Firmware/lcd.cpp +++ b/Firmware/lcd.cpp @@ -10,12 +10,19 @@ #include "Configuration.h" #include "pins.h" #include -//#include +#include #include "Marlin.h" #include "fastio.h" //-// #include "sound.h" +#define LCD_DEFAULT_DELAY 100 + +#if (defined(LCD_PINS_D0) && defined(LCD_PINS_D1) && defined(LCD_PINS_D2) && defined(LCD_PINS_D3)) + #define LCD_8BIT +#endif + +// #define VT100 // commands #define LCD_CLEARDISPLAY 0x01 @@ -55,242 +62,204 @@ #define LCD_5x10DOTS 0x04 #define LCD_5x8DOTS 0x00 +// bitmasks for flag argument settings +#define LCD_RS_FLAG 0x01 +#define LCD_HALF_FLAG 0x02 FILE _lcdout; // = {0}; Global variable is always zero initialized, no need to explicitly state that. +uint8_t lcd_displayfunction = 0; +uint8_t lcd_displaycontrol = 0; +uint8_t lcd_displaymode = 0; -uint8_t lcd_rs_pin; // LOW: command. HIGH: character. -uint8_t lcd_rw_pin; // LOW: write to LCD. HIGH: read from LCD. -uint8_t lcd_enable_pin; // activated by a HIGH pulse. -uint8_t lcd_data_pins[8]; - -uint8_t lcd_displayfunction; -uint8_t lcd_displaycontrol; -uint8_t lcd_displaymode; - -uint8_t lcd_numlines; uint8_t lcd_currline; +#ifdef VT100 uint8_t lcd_escape[8]; +#endif +static void lcd_display(void); -void lcd_pulseEnable(void) -{ - digitalWrite(lcd_enable_pin, LOW); - delayMicroseconds(1); - digitalWrite(lcd_enable_pin, HIGH); - delayMicroseconds(1); // enable pulse must be >450ns - digitalWrite(lcd_enable_pin, LOW); - delayMicroseconds(100); // commands need > 37us to settle +#if 0 +static void lcd_no_display(void); +static void lcd_no_cursor(void); +static void lcd_cursor(void); +static void lcd_no_blink(void); +static void lcd_blink(void); +static void lcd_scrollDisplayLeft(void); +static void lcd_scrollDisplayRight(void); +static void lcd_leftToRight(void); +static void lcd_rightToLeft(void); +static void lcd_autoscroll(void); +static void lcd_no_autoscroll(void); +#endif + +#ifdef VT100 +void lcd_escape_write(uint8_t chr); +#endif + +static void lcd_pulseEnable(void) +{ + WRITE(LCD_PINS_ENABLE,HIGH); + _delay_us(1); // enable pulse must be >450ns + WRITE(LCD_PINS_ENABLE,LOW); } -void lcd_write4bits(uint8_t value) +static void lcd_writebits(uint8_t value) { - for (int i = 0; i < 4; i++) - { - pinMode(lcd_data_pins[i], OUTPUT); - digitalWrite(lcd_data_pins[i], (value >> i) & 0x01); - } +#ifdef LCD_8BIT + WRITE(LCD_PINS_D0, value & 0x01); + WRITE(LCD_PINS_D1, value & 0x02); + WRITE(LCD_PINS_D2, value & 0x04); + WRITE(LCD_PINS_D3, value & 0x08); +#endif + WRITE(LCD_PINS_D4, value & 0x10); + WRITE(LCD_PINS_D5, value & 0x20); + WRITE(LCD_PINS_D6, value & 0x40); + WRITE(LCD_PINS_D7, value & 0x80); + lcd_pulseEnable(); } -void lcd_write8bits(uint8_t value) +static void lcd_send(uint8_t data, uint8_t flags, uint16_t duration = LCD_DEFAULT_DELAY) { - for (int i = 0; i < 8; i++) + WRITE(LCD_PINS_RS,flags&LCD_RS_FLAG); + _delay_us(5); + lcd_writebits(data); +#ifndef LCD_8BIT + if (!(flags & LCD_HALF_FLAG)) { - pinMode(lcd_data_pins[i], OUTPUT); - digitalWrite(lcd_data_pins[i], (value >> i) & 0x01); + _delay_us(LCD_DEFAULT_DELAY); + lcd_writebits(data<<4); } - lcd_pulseEnable(); +#endif + delayMicroseconds(duration); } -// write either command or data, with automatic 4/8-bit selection -void lcd_send(uint8_t value, uint8_t mode) +static void lcd_command(uint8_t value, uint16_t delayExtra = 0) { - digitalWrite(lcd_rs_pin, mode); - // if there is a RW pin indicated, set it low to Write - if (lcd_rw_pin != 255) digitalWrite(lcd_rw_pin, LOW); - if (lcd_displayfunction & LCD_8BITMODE) - lcd_write8bits(value); - else - { - lcd_write4bits(value>>4); - lcd_write4bits(value); - } + lcd_send(value, LOW, LCD_DEFAULT_DELAY + delayExtra); } -void lcd_command(uint8_t value) -{ - lcd_send(value, LOW); -} - -void lcd_clear(void); -void lcd_home(void); -void lcd_no_display(void); -void lcd_display(void); -void lcd_no_cursor(void); -void lcd_cursor(void); -void lcd_no_blink(void); -void lcd_blink(void); -void lcd_scrollDisplayLeft(void); -void lcd_scrollDisplayRight(void); -void lcd_leftToRight(void); -void lcd_rightToLeft(void); -void lcd_autoscroll(void); -void lcd_no_autoscroll(void); -void lcd_set_cursor(uint8_t col, uint8_t row); -void lcd_createChar_P(uint8_t location, const uint8_t* charmap); - -uint8_t lcd_escape_write(uint8_t chr); - -uint8_t lcd_write(uint8_t value) +static void lcd_write(uint8_t value) { if (value == '\n') { if (lcd_currline > 3) lcd_currline = -1; lcd_set_cursor(0, lcd_currline + 1); // LF - return 1; + return; } - if (lcd_escape[0] || (value == 0x1b)) - return lcd_escape_write(value); + #ifdef VT100 + if (lcd_escape[0] || (value == 0x1b)){ + lcd_escape_write(value); + return; + } + #endif lcd_send(value, HIGH); - return 1; // assume sucess } -static void lcd_begin(uint8_t lines, uint8_t dotsize, uint8_t clear) +static void lcd_begin(uint8_t clear) { - if (lines > 1) lcd_displayfunction |= LCD_2LINE; - lcd_numlines = lines; lcd_currline = 0; - // for some 1 line displays you can select a 10 pixel high font - if ((dotsize != 0) && (lines == 1)) lcd_displayfunction |= LCD_5x10DOTS; - // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! - // according to datasheet, we need at least 40ms after power rises above 2.7V - // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 - _delay_us(50000); - // Now we pull both RS and R/W low to begin commands - digitalWrite(lcd_rs_pin, LOW); - digitalWrite(lcd_enable_pin, LOW); - if (lcd_rw_pin != 255) - digitalWrite(lcd_rw_pin, LOW); - //put the LCD into 4 bit or 8 bit mode - if (!(lcd_displayfunction & LCD_8BITMODE)) - { - // this is according to the hitachi HD44780 datasheet - // figure 24, pg 46 - // we start in 8bit mode, try to set 4 bit mode - lcd_write4bits(0x03); - _delay_us(4500); // wait min 4.1ms - // second try - lcd_write4bits(0x03); - _delay_us(4500); // wait min 4.1ms - // third go! - lcd_write4bits(0x03); - _delay_us(150); - // finally, set to 4-bit interface - lcd_write4bits(0x02); - } - else - { - // this is according to the hitachi HD44780 datasheet - // page 45 figure 23 - // Send function set command sequence - lcd_command(LCD_FUNCTIONSET | lcd_displayfunction); - _delay_us(4500); // wait more than 4.1ms - // second try - lcd_command(LCD_FUNCTIONSET | lcd_displayfunction); - _delay_us(150); - // third go - lcd_command(LCD_FUNCTIONSET | lcd_displayfunction); - } - // finally, set # lines, font size, etc. - lcd_command(LCD_FUNCTIONSET | lcd_displayfunction); - _delay_us(60); + + lcd_send(LCD_FUNCTIONSET | LCD_8BITMODE, LOW | LCD_HALF_FLAG, 4500); // wait min 4.1ms + // second try + lcd_send(LCD_FUNCTIONSET | LCD_8BITMODE, LOW | LCD_HALF_FLAG, 150); + // third go! + lcd_send(LCD_FUNCTIONSET | LCD_8BITMODE, LOW | LCD_HALF_FLAG, 150); +#ifndef LCD_8BIT + // set to 4-bit interface + lcd_send(LCD_FUNCTIONSET | LCD_4BITMODE, LOW | LCD_HALF_FLAG, 150); +#endif + + // finally, set # lines, font size, etc.0 + lcd_command(LCD_FUNCTIONSET | lcd_displayfunction); // turn the display on with no cursor or blinking default - lcd_displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; + lcd_displaycontrol = LCD_CURSOROFF | LCD_BLINKOFF; lcd_display(); - _delay_us(60); // clear it off if (clear) lcd_clear(); - _delay_us(3000); // Initialize to default text direction (for romance languages) lcd_displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; // set the entry mode lcd_command(LCD_ENTRYMODESET | lcd_displaymode); - _delay_us(60); + + #ifdef VT100 lcd_escape[0] = 0; + #endif } -int lcd_putchar(char c, FILE *) +static void lcd_putchar(char c, FILE *) { lcd_write(c); - return 0; } void lcd_init(void) { - uint8_t fourbitmode = 1; - lcd_rs_pin = LCD_PINS_RS; - lcd_rw_pin = 255; - lcd_enable_pin = LCD_PINS_ENABLE; - lcd_data_pins[0] = LCD_PINS_D4; - lcd_data_pins[1] = LCD_PINS_D5; - lcd_data_pins[2] = LCD_PINS_D6; - lcd_data_pins[3] = LCD_PINS_D7; - lcd_data_pins[4] = 0; - lcd_data_pins[5] = 0; - lcd_data_pins[6] = 0; - lcd_data_pins[7] = 0; - pinMode(lcd_rs_pin, OUTPUT); - // we can save 1 pin by not using RW. Indicate by passing 255 instead of pin# - if (lcd_rw_pin != 255) pinMode(lcd_rw_pin, OUTPUT); - pinMode(lcd_enable_pin, OUTPUT); - if (fourbitmode) lcd_displayfunction = LCD_4BITMODE | LCD_1LINE | LCD_5x8DOTS; - else lcd_displayfunction = LCD_8BITMODE | LCD_1LINE | LCD_5x8DOTS; - lcd_begin(LCD_HEIGHT, LCD_5x8DOTS, 1); - //lcd_clear(); + 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 + lcd_displayfunction |= LCD_2LINE; + _delay_us(50000); + lcd_begin(1); //first time init fdev_setup_stream(lcdout, lcd_putchar, NULL, _FDEV_SETUP_WRITE); //setup lcdout stream } void lcd_refresh(void) { - lcd_begin(LCD_HEIGHT, LCD_5x8DOTS, 1); + lcd_begin(1); lcd_set_custom_characters(); } void lcd_refresh_noclear(void) { - lcd_begin(LCD_HEIGHT, LCD_5x8DOTS, 0); + lcd_begin(0); lcd_set_custom_characters(); } - - void lcd_clear(void) { - lcd_command(LCD_CLEARDISPLAY); // clear display, set cursor position to zero - _delay_us(1600); // this command takes a long time + lcd_command(LCD_CLEARDISPLAY, 1600); // clear display, set cursor position to zero + lcd_currline = 0; } void lcd_home(void) { - lcd_command(LCD_RETURNHOME); // set cursor position to zero - _delay_us(1600); // this command takes a long time! + lcd_command(LCD_RETURNHOME, 1600); // set cursor position to zero + lcd_currline = 0; } // Turn the display on/off (quickly) +void lcd_display(void) +{ + lcd_displaycontrol |= LCD_DISPLAYON; + lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol); +} + +#if 0 void lcd_no_display(void) { lcd_displaycontrol &= ~LCD_DISPLAYON; lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol); } +#endif -void lcd_display(void) -{ - lcd_displaycontrol |= LCD_DISPLAYON; - lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol); -} - +#ifdef VT100 //required functions for VT100 // Turns the underline cursor on/off void lcd_no_cursor(void) { @@ -303,7 +272,9 @@ void lcd_cursor(void) lcd_displaycontrol |= LCD_CURSORON; lcd_command(LCD_DISPLAYCONTROL | lcd_displaycontrol); } +#endif +#if 0 // Turn on and off the blinking cursor void lcd_no_blink(void) { @@ -355,12 +326,13 @@ void lcd_no_autoscroll(void) lcd_displaymode &= ~LCD_ENTRYSHIFTINCREMENT; lcd_command(LCD_ENTRYMODESET | lcd_displaymode); } +#endif void lcd_set_cursor(uint8_t col, uint8_t row) { int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 }; - if ( row >= lcd_numlines ) - row = lcd_numlines-1; // we count rows starting w/0 + if (row >= LCD_HEIGHT) + row = LCD_HEIGHT - 1; // we count rows starting w/0 lcd_currline = row; lcd_command(LCD_SETDDRAMADDR | (col + row_offsets[row])); } @@ -375,12 +347,14 @@ void lcd_createChar_P(uint8_t location, const uint8_t* charmap) lcd_send(pgm_read_byte(&charmap[i]), HIGH); } +#ifdef VT100 + //Supported VT100 escape codes: //EraseScreen "\x1b[2J" //CursorHome "\x1b[%d;%dH" //CursorShow "\x1b[?25h" //CursorHide "\x1b[?25l" -uint8_t lcd_escape_write(uint8_t chr) +void lcd_escape_write(uint8_t chr) { #define escape_cnt (lcd_escape[0]) //escape character counter #define is_num_msk (lcd_escape[1]) //numeric character bit mask @@ -410,26 +384,26 @@ uint8_t lcd_escape_write(uint8_t chr) switch (escape_cnt++) { case 0: - if (chr == 0x1b) return 1; // escape = "\x1b" + if (chr == 0x1b) return; // escape = "\x1b" break; case 1: is_num_msk = 0x00; // reset 'is number' bit mask - if (chr == '[') return 1; // escape = "\x1b[" + if (chr == '[') return; // escape = "\x1b[" break; case 2: switch (chr) { - case '2': return 1; // escape = "\x1b[2" - case '?': return 1; // escape = "\x1b[?" + case '2': return; // escape = "\x1b[2" + case '?': return; // escape = "\x1b[?" default: - if (chr_is_num) return 1; // escape = "\x1b[%1d" + if (chr_is_num) return; // escape = "\x1b[%1d" } break; case 3: switch (lcd_escape[2]) { case '?': // escape = "\x1b[?" - if (chr == '2') return 1; // escape = "\x1b[?2" + if (chr == '2') return; // escape = "\x1b[?2" break; case '2': if (chr == 'J') // escape = "\x1b[2J" @@ -438,20 +412,20 @@ uint8_t lcd_escape_write(uint8_t chr) if (e_2_is_num && // escape = "\x1b[%1d" ((chr == ';') || // escape = "\x1b[%1d;" chr_is_num)) // escape = "\x1b[%2d" - return 1; + return; } break; case 4: switch (lcd_escape[2]) { case '?': // "\x1b[?" - if ((lcd_escape[3] == '2') && (chr == '5')) return 1; // escape = "\x1b[?25" + if ((lcd_escape[3] == '2') && (chr == '5')) return; // escape = "\x1b[?25" break; default: if (e_2_is_num) // escape = "\x1b[%1d" { - if ((lcd_escape[3] == ';') && chr_is_num) return 1; // escape = "\x1b[%1d;%1d" - else if (e_3_is_num && (chr == ';')) return 1; // escape = "\x1b[%2d;" + if ((lcd_escape[3] == ';') && chr_is_num) return; // escape = "\x1b[%1d;%1d" + else if (e_3_is_num && (chr == ';')) return; // escape = "\x1b[%2d;" } } break; @@ -478,10 +452,10 @@ uint8_t lcd_escape_write(uint8_t chr) if (chr == 'H') // escape = "\x1b%1d;%1dH" lcd_set_cursor(e4_num, e2_num); // CursorHome else if (chr_is_num) - return 1; // escape = "\x1b%1d;%2d" + return; // escape = "\x1b%1d;%2d" } else if (e_3_is_num && (lcd_escape[4] == ';') && chr_is_num) - return 1; // escape = "\x1b%2d;%1d" + return; // escape = "\x1b%2d;%1d" } } break; @@ -495,7 +469,7 @@ uint8_t lcd_escape_write(uint8_t chr) if (chr == 'H') // escape = "\x1b%2d;%1dH" lcd_set_cursor(e5_num, e23_num); // CursorHome else if (chr_is_num) // "\x1b%2d;%2d" - return 1; + return; } } break; @@ -506,10 +480,9 @@ uint8_t lcd_escape_write(uint8_t chr) break; } escape_cnt = 0; // reset escape - return 1; // assume sucess } - +#endif //VT100 int lcd_putc(int c) @@ -648,16 +621,6 @@ void lcd_printFloat(double number, uint8_t digits) } - - - - - - - - - - uint8_t lcd_draw_update = 2; int32_t lcd_encoder = 0; uint8_t lcd_encoder_bits = 0; @@ -704,16 +667,13 @@ uint8_t lcd_clicked(void) void lcd_beeper_quick_feedback(void) { - SET_OUTPUT(BEEPER); //-// Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); /* for(int8_t i = 0; i < 10; i++) { - WRITE(BEEPER,HIGH); - delayMicroseconds(100); - WRITE(BEEPER,LOW); - delayMicroseconds(100); + Sound_MakeCustom(100,0,false); + _delay_us(100); } */ } @@ -725,13 +685,6 @@ void lcd_quick_feedback(void) lcd_beeper_quick_feedback(); } - - - - - - - void lcd_update(uint8_t lcdDrawUpdateOverride) { if (lcd_draw_update < lcdDrawUpdateOverride) diff --git a/Firmware/lcd.h b/Firmware/lcd.h index 9f3eb5c13..307e9486c 100644 --- a/Firmware/lcd.h +++ b/Firmware/lcd.h @@ -11,8 +11,7 @@ extern FILE _lcdout; #define lcdout (&_lcdout) -extern int lcd_putchar(char c, FILE *stream); - +extern void lcd_putchar(char c, FILE *stream); extern void lcd_init(void); @@ -20,13 +19,10 @@ extern void lcd_refresh(void); extern void lcd_refresh_noclear(void); - - extern void lcd_clear(void); extern void lcd_home(void); - /*extern void lcd_no_display(void); extern void lcd_display(void); extern void lcd_no_blink(void); @@ -45,7 +41,6 @@ extern void lcd_set_cursor(uint8_t col, uint8_t row); extern void lcd_createChar_P(uint8_t, const uint8_t*); - extern int lcd_putc(int c); extern int lcd_puts_P(const char* str); extern int lcd_puts_at_P(uint8_t c, uint8_t r, const char* str); @@ -66,7 +61,9 @@ extern void lcd_print(double, int = 2); //! @brief Clear screen #define ESC_2J "\x1b[2J" +//! @brief Show cursor #define ESC_25h "\x1b[?25h" +//! @brief Hide cursor #define ESC_25l "\x1b[?25l" //! @brief Set cursor to //! @param c column @@ -118,9 +115,6 @@ extern lcd_lcdupdate_func_t lcd_lcdupdate_func; - - - extern uint8_t lcd_clicked(void); extern void lcd_beeper_quick_feedback(void); @@ -128,13 +122,6 @@ extern void lcd_beeper_quick_feedback(void); //Cause an LCD refresh, and give the user visual or audible feedback that something has happened extern void lcd_quick_feedback(void); - - - - - - - extern void lcd_update(uint8_t lcdDrawUpdateOverride); extern void lcd_update_enable(uint8_t enabled); @@ -165,29 +152,6 @@ private: }; - - - - - - - - - - - - - - - - - -/** -* Implementation of the LCD display routines for a Hitachi HD44780 display. These are common LCD character displays. -* When selecting the Russian language, a slightly different LCD implementation is used to handle UTF8 characters. -**/ - - //////////////////////////////////// // Setup button and encode mappings for each panel (into 'lcd_buttons' variable // @@ -223,8 +187,6 @@ private: #define encrot3 1 - - //Custom characters defined in the first 8 characters of the LCD #define LCD_STR_BEDTEMP "\x00" #define LCD_STR_DEGREE "\x01" diff --git a/Firmware/menu.cpp b/Firmware/menu.cpp index e0364056e..7839bbdc0 100755 --- a/Firmware/menu.cpp +++ b/Firmware/menu.cpp @@ -11,8 +11,7 @@ #include "ultralcd.h" #include "language.h" #include "static_assert.h" - - +#include "sound.h" extern int32_t lcd_encoder; @@ -65,7 +64,11 @@ void menu_goto(menu_func_t menu, const uint32_t encoder, const bool feedback, bo void menu_start(void) { if (lcd_encoder > 0x8000) lcd_encoder = 0; - if (lcd_encoder < 0) lcd_encoder = 0; + if (lcd_encoder < 0) + { + lcd_encoder = 0; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); + } if (lcd_encoder < menu_top) menu_top = lcd_encoder; menu_line = menu_top; @@ -75,7 +78,10 @@ void menu_start(void) void menu_end(void) { if (lcd_encoder >= menu_item) + { lcd_encoder = menu_item - 1; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); + } if (((uint8_t)lcd_encoder) >= menu_top + LCD_HEIGHT) { menu_top = lcd_encoder - LCD_HEIGHT + 1; @@ -168,16 +174,61 @@ int menu_draw_item_printf_P(char type_char, const char* format, ...) } */ +static char menu_selection_mark(){ + return (lcd_encoder == menu_item)?'>':' '; +} + static void menu_draw_item_puts_P(char type_char, const char* str) { lcd_set_cursor(0, menu_row); - lcd_printf_P(PSTR("%c%-18.18S%c"), (lcd_encoder == menu_item)?'>':' ', str, type_char); + lcd_printf_P(PSTR("%c%-18.18S%c"), menu_selection_mark(), str, type_char); +} + +//! @brief Format sheet name +//! +//! @param[in] sheet_E Sheet in EEPROM +//! @param[out] buffer for formatted output +void menu_format_sheet_E(const Sheet &sheet_E, SheetFormatBuffer &buffer) +{ + uint_least8_t index = sprintf_P(buffer.c, PSTR("%.10S "), _T(MSG_SHEET)); + eeprom_read_block(&(buffer.c[index]), sheet_E.name, 7); + //index += 7; + buffer.c[index + 7] = '\0'; +} + +//! @brief Format sheet name in select menu +//! +//! @param[in] sheet_E Sheet in EEPROM +//! @param[out] buffer for formatted output +void menu_format_sheet_select_E(const Sheet &sheet_E, SheetFormatBuffer &buffer) +{ + uint_least8_t index = sprintf_P(buffer.c,PSTR("%-9.9S["), _T(MSG_SHEET)); + eeprom_read_block(&(buffer.c[index]), sheet_E.name, 7); + buffer.c[index + 7] = ']'; + buffer.c[index + 8] = '\0'; +} + +static void menu_draw_item_select_sheet_E(char type_char, const Sheet &sheet) +{ + lcd_set_cursor(0, menu_row); + SheetFormatBuffer buffer; + menu_format_sheet_select_E(sheet, buffer); + lcd_printf_P(PSTR("%c%-18.18s%c"), menu_selection_mark(), buffer.c, type_char); +} + + +static void menu_draw_item_puts_E(char type_char, const Sheet &sheet) +{ + lcd_set_cursor(0, menu_row); + SheetFormatBuffer buffer; + menu_format_sheet_E(sheet, buffer); + lcd_printf_P(PSTR("%c%-18.18s%c"), menu_selection_mark(), buffer.c, type_char); } static void menu_draw_item_puts_P(char type_char, const char* str, char num) { lcd_set_cursor(0, menu_row); - lcd_printf_P(PSTR("%c%-.16S "), (lcd_encoder == menu_item)?'>':' ', str); + lcd_printf_P(PSTR("%c%-.16S "), menu_selection_mark(), str); lcd_putc(num); lcd_set_cursor(19, menu_row); lcd_putc(type_char); @@ -224,6 +275,36 @@ uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu) return 0; } +uint8_t menu_item_submenu_E(const Sheet &sheet, menu_func_t submenu) +{ + if (menu_item == menu_line) + { + if (lcd_draw_update) menu_draw_item_puts_E(LCD_STR_ARROW_RIGHT[0], sheet); + if (menu_clicked && (lcd_encoder == menu_item)) + { + menu_submenu(submenu); + return menu_item_ret(); + } + } + menu_item++; + return 0; +} + +uint8_t menu_item_submenu_select_sheet_E(const Sheet &sheet, menu_func_t submenu) +{ + if (menu_item == menu_line) + { + if (lcd_draw_update) menu_draw_item_select_sheet_E(LCD_STR_ARROW_RIGHT[0], sheet); + if (menu_clicked && (lcd_encoder == menu_item)) + { + menu_submenu(submenu); + return menu_item_ret(); + } + } + menu_item++; + return 0; +} + uint8_t menu_item_back_P(const char* str) { if (menu_item == menu_line) @@ -399,7 +480,7 @@ uint8_t menu_item_edit_P(const char* str, T pval, int16_t min_val, int16_t max_v if (lcd_draw_update) { lcd_set_cursor(0, menu_row); - menu_draw_P((lcd_encoder == menu_item)?'>':' ', str, *pval); + menu_draw_P(menu_selection_mark(), str, *pval); } if (menu_clicked && (lcd_encoder == menu_item)) { diff --git a/Firmware/menu.h b/Firmware/menu.h index 5f73e18b0..d9bbf876c 100755 --- a/Firmware/menu.h +++ b/Firmware/menu.h @@ -3,6 +3,7 @@ #define _MENU_H #include +#include "eeprom.h" #define MENU_DATA_SIZE 32 @@ -99,6 +100,12 @@ extern uint8_t menu_item_text_P(const char* str); #define MENU_ITEM_SUBMENU_P(str, submenu) do { if (menu_item_submenu_P(str, submenu)) return; } while (0) extern uint8_t menu_item_submenu_P(const char* str, menu_func_t submenu); +#define MENU_ITEM_SUBMENU_E(sheet, submenu) do { if (menu_item_submenu_E(sheet, submenu)) return; } while (0) +extern uint8_t menu_item_submenu_E(const Sheet &sheet, menu_func_t submenu); + +#define MENU_ITEM_SUBMENU_SELECT_SHEET_E(sheet, submenu) do { if (menu_item_submenu_select_sheet_E(sheet, submenu)) return; } while (0) +extern uint8_t menu_item_submenu_select_sheet_E(const Sheet &sheet, menu_func_t submenu); + #define MENU_ITEM_BACK_P(str) do { if (menu_item_back_P(str)) return; } while (0) extern uint8_t menu_item_back_P(const char* str); @@ -125,6 +132,13 @@ extern void menu_draw_float31(const char* str, float val); extern void menu_draw_float13(const char* str, float val); +struct SheetFormatBuffer +{ + char c[19]; +}; + +extern void menu_format_sheet_E(const Sheet &sheet_E, SheetFormatBuffer &buffer); + #define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) do { if (menu_item_edit_P(str, pval, minval, maxval)) return; } while (0) //#define MENU_ITEM_EDIT_int3_P(str, pval, minval, maxval) MENU_ITEM_EDIT(int3, str, pval, minval, maxval) diff --git a/Firmware/mesh_bed_calibration.cpp b/Firmware/mesh_bed_calibration.cpp index 91dadaefa..1edac56bf 100644 --- a/Firmware/mesh_bed_calibration.cpp +++ b/Firmware/mesh_bed_calibration.cpp @@ -3031,7 +3031,8 @@ void babystep_load() check_babystep(); //checking if babystep is in allowed range, otherwise setting babystep to 0 // End of G80: Apply the baby stepping value. - EEPROM_read_B(EEPROM_BABYSTEP_Z, &babystepLoadZ); + babystepLoadZ = eeprom_read_word(reinterpret_cast(&(EEPROM_Sheets_base-> + s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset))); #if 0 SERIAL_ECHO("Z baby step: "); @@ -3186,4 +3187,4 @@ void mbl_interpolation(uint8_t meas_points) { } } } -} \ No newline at end of file +} diff --git a/Firmware/messages.c b/Firmware/messages.c index 53ec20e86..1c36e43c5 100644 --- a/Firmware/messages.c +++ b/Firmware/messages.c @@ -10,7 +10,7 @@ //internationalized messages const char MSG_AUTO_HOME[] PROGMEM_I1 = ISTR("Auto home"); //// const char MSG_AUTO_MODE_ON[] PROGMEM_I1 = ISTR("Mode [auto power]"); //// -const char MSG_BABYSTEP_Z[] PROGMEM_I1 = ISTR("Live adjust Z"); //// +const char MSG_BABYSTEP_Z[] PROGMEM_I1 = ISTR("Live adjust Z"); //// c=18 const char MSG_BABYSTEP_Z_NOT_SET[] PROGMEM_I1 = ISTR("Distance between tip of the nozzle and the bed surface has not been set yet. Please follow the manual, chapter First steps, section First layer calibration."); ////c=20 r=12 const char MSG_BED[] PROGMEM_I1 = ISTR("Bed"); //// const char MSG_BED_DONE[] PROGMEM_I1 = ISTR("Bed done"); //// @@ -55,6 +55,7 @@ const char MSG_CUT_FILAMENT[] PROGMEM_I1 = ISTR("Cut filament"); //// Number 1 t const char MSG_M117_V2_CALIBRATION[] PROGMEM_I1 = ISTR("M117 First layer cal."); ////c=25 r=1 const char MSG_MAIN[] PROGMEM_I1 = ISTR("Main"); //// const char MSG_BACK[] PROGMEM_I1 = ISTR("Back"); //// +const char MSG_SHEET[] PROGMEM_I1 = ISTR("Sheet"); ////c=10 const char MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1[] PROGMEM_I1 = ISTR("Measuring reference height of calibration point"); ////c=60 const char MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2[] PROGMEM_I1 = ISTR(" of 9"); ////c=14 const char MSG_MENU_CALIBRATION[] PROGMEM_I1 = ISTR("Calibration"); //// @@ -83,6 +84,7 @@ const char MSG_SELFTEST_MOTOR[] PROGMEM_I1 = ISTR("Motor"); //// const char MSG_SELFTEST_FILAMENT_SENSOR[] PROGMEM_I1 = ISTR("Filament sensor"); ////c=17 const char MSG_SELFTEST_WIRINGERROR[] PROGMEM_I1 = ISTR("Wiring error"); //// const char MSG_SETTINGS[] PROGMEM_I1 = ISTR("Settings"); //// +const char MSG_HW_SETUP[] PROGMEM_I1 = ISTR("HW Setup"); //// const char MSG_SILENT_MODE_OFF[] PROGMEM_I1 = ISTR("Mode [high power]"); //// const char MSG_SILENT_MODE_ON[] PROGMEM_I1 = ISTR("Mode [silent]"); //// const char MSG_STEALTH_MODE_OFF[] PROGMEM_I1 = ISTR("Mode [Normal]"); //// @@ -100,6 +102,7 @@ const char MSG_WIZARD_DONE[] PROGMEM_I1 = ISTR("All is done. Happy printing!"); const char MSG_WIZARD_HEATING[] PROGMEM_I1 = ISTR("Preheating nozzle. Please wait."); ////c=20 r=3 const char MSG_WIZARD_QUIT[] PROGMEM_I1 = ISTR("You can always resume the Wizard from Calibration -> Wizard."); ////c=20 r=8 const char MSG_YES[] PROGMEM_I1 = ISTR("Yes"); //// +const char MSG_V2_CALIBRATION[] PROGMEM_I1 = ISTR("First layer cal."); ////c=17 r=1 const char WELCOME_MSG[] PROGMEM_I1 = ISTR(CUSTOM_MENDEL_NAME " OK."); ////c=20 //not internationalized messages const char MSG_SD_WORKDIR_FAIL[] PROGMEM_N1 = "workDir open failed"; //// @@ -126,3 +129,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 d74412fca..b48337efd 100644 --- a/Firmware/messages.h +++ b/Firmware/messages.h @@ -54,6 +54,7 @@ extern const char MSG_LOADING_FILAMENT[]; extern const char MSG_M117_V2_CALIBRATION[]; extern const char MSG_MAIN[]; extern const char MSG_BACK[]; +extern const char MSG_SHEET[]; extern const char MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE1[]; extern const char MSG_MEASURE_BED_REFERENCE_HEIGHT_LINE2[]; extern const char MSG_MENU_CALIBRATION[]; @@ -83,6 +84,7 @@ extern const char MSG_SELFTEST_MOTOR[]; extern const char MSG_SELFTEST_FILAMENT_SENSOR[]; extern const char MSG_SELFTEST_WIRINGERROR[]; extern const char MSG_SETTINGS[]; +extern const char MSG_HW_SETUP[]; extern const char MSG_SILENT_MODE_OFF[]; extern const char MSG_SILENT_MODE_ON[]; extern const char MSG_STEALTH_MODE_OFF[]; @@ -100,6 +102,7 @@ extern const char MSG_WIZARD_DONE[]; extern const char MSG_WIZARD_HEATING[]; extern const char MSG_WIZARD_QUIT[]; extern const char MSG_YES[]; +extern const char MSG_V2_CALIBRATION[]; extern const char WELCOME_MSG[]; //not internationalized messages extern const char MSG_BROWNOUT_RESET[]; @@ -127,6 +130,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/mmu.cpp b/Firmware/mmu.cpp old mode 100644 new mode 100755 index 916b3d0fd..d6e533dfb --- a/Firmware/mmu.cpp +++ b/Firmware/mmu.cpp @@ -15,6 +15,8 @@ #include #include "io_atmega2560.h" #include "AutoDeplete.h" +//-// +#include "util.h" #ifdef TMC2130 #include "tmc2130.h" @@ -81,9 +83,11 @@ uint16_t mmu_power_failures = 0; #ifdef MMU_DEBUG +static const auto DEBUG_PUTCHAR = putchar; static const auto DEBUG_PUTS_P = puts_P; static const auto DEBUG_PRINTF_P = printf_P; #else //MMU_DEBUG +#define DEBUG_PUTCHAR(c) #define DEBUG_PUTS_P(str) #define DEBUG_PRINTF_P( __fmt, ... ) #endif //MMU_DEBUG @@ -263,6 +267,9 @@ void mmu_loop(void) FDEBUG_PRINTF_P(PSTR("MMU => '%dok'\n"), mmu_finda); puts_P(PSTR("MMU - ENABLED")); mmu_enabled = true; + //-// + // ... PrinterType/Name + fSetMmuMode(true); mmu_state = S::Idle; } return; @@ -416,9 +423,11 @@ void mmu_loop(void) } else if ((mmu_last_request + MMU_CMD_TIMEOUT) < _millis()) { //resend request after timeout (5 min) - if (mmu_last_cmd >= MmuCmd::T0 && mmu_last_cmd <= MmuCmd::T4) + if (mmu_last_cmd != MmuCmd::None) { - if (mmu_attempt_nr++ < MMU_MAX_RESEND_ATTEMPTS) { + if (mmu_attempt_nr++ < MMU_MAX_RESEND_ATTEMPTS && + mmu_last_cmd >= MmuCmd::T0 && mmu_last_cmd <= MmuCmd::T4) + { DEBUG_PRINTF_P(PSTR("MMU retry attempt nr. %d\n"), mmu_attempt_nr - 1); mmu_cmd = mmu_last_cmd; } @@ -831,7 +840,7 @@ void mmu_M600_wait_and_beep() { } SET_OUTPUT(BEEPER); if (counterBeep == 0) { - if((eSoundMode==e_SOUND_MODE_LOUD)||((eSoundMode==e_SOUND_MODE_ONCE)&&bFirst)) + if((eSoundMode==e_SOUND_MODE_BLIND)|| (eSoundMode==e_SOUND_MODE_LOUD)||((eSoundMode==e_SOUND_MODE_ONCE)&&bFirst)) { bFirst=false; WRITE(BEEPER, HIGH); @@ -969,7 +978,7 @@ void extr_adj(uint8_t extruder) //loading filament for SNMM { #ifndef SNMM MmuCmd cmd = MmuCmd::L0 + extruder; - if (cmd > MmuCmd::L4) + if (extruder > (MmuCmd::L4 - MmuCmd::L0)) { printf_P(PSTR("Filament out of range %d \n"),extruder); return; @@ -1076,7 +1085,7 @@ if(0) extr_unload(); } else { - eFilamentAction=e_FILAMENT_ACTION_mmuUnLoad; + eFilamentAction=FilamentAction::MmuUnLoad; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -1372,13 +1381,13 @@ void lcd_mmu_load_to_nozzle(uint8_t filament_nr) mmu_load_to_nozzle(); load_filament_final_feed(); st_synchronize(); - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; + custom_message_type = CustomMsg::FilamentLoading; lcd_setstatuspgm(_T(MSG_LOADING_FILAMENT)); lcd_return_to_status(); lcd_update_enable(true); lcd_load_filament_color_check(); lcd_setstatuspgm(_T(WELCOME_MSG)); - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsg::Status; } else { @@ -1447,26 +1456,69 @@ bFilamentAction=false; // NOT in "mmu_fil_eject_menu( } } +//! @brief Fits filament tip into heatbreak? +//! +//! If PTFE tube is jammed, this causes filament to be unloaded and no longer +//! being detected by the pulley IR sensor. +//! @retval true Fits +//! @retval false Doesn't fit +static bool can_load() +{ + current_position[E_AXIS] += 60; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], + current_position[E_AXIS], MMU_LOAD_FEEDRATE, active_extruder); + current_position[E_AXIS] -= 52; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], + current_position[E_AXIS], MMU_LOAD_FEEDRATE, active_extruder); + st_synchronize(); + + uint_least8_t filament_detected_count = 0; + const float e_increment = 0.2; + const uint_least8_t steps = 6.0 / e_increment; + DEBUG_PUTS_P(PSTR("MMU can_load:")); + for(uint_least8_t i = 0; i < steps; ++i) + { + current_position[E_AXIS] -= e_increment; + plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], + current_position[E_AXIS], MMU_LOAD_FEEDRATE, active_extruder); + st_synchronize(); + if(0 == PIN_GET(IR_SENSOR_PIN)) + { + ++filament_detected_count; + DEBUG_PUTCHAR('O'); + } + else + { + DEBUG_PUTCHAR('o'); + } + } + if (filament_detected_count > steps - 4) + { + DEBUG_PUTS_P(PSTR(" succeeded.")); + return true; + } + else + { + DEBUG_PUTS_P(PSTR(" failed.")); + return false; + } +} + //! @brief load more //! //! Try to feed more filament from MMU if it is not detected by filament sensor. -//! Move filament back and forth to nozzle in order to detect jam. -//! If PTFE tube is jammed, this cause filament to be unloaded and no longer -//! detected by pulley IR sensor in next step. -static void load_more() +//! @retval true Success, filament detected by IR sensor +//! @retval false Failed, filament not detected by IR sensor after maximum number of attempts +static bool load_more() { for (uint8_t i = 0; i < MMU_IDLER_SENSOR_ATTEMPTS_NR; i++) { - if (PIN_GET(IR_SENSOR_PIN) == 0) break; + if (PIN_GET(IR_SENSOR_PIN) == 0) return true; DEBUG_PRINTF_P(PSTR("Additional load attempt nr. %d\n"), i); mmu_command(MmuCmd::C0); manage_response(true, true, MMU_LOAD_MOVE); } - current_position[E_AXIS] += 60; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], MMU_LOAD_FEEDRATE, active_extruder); - current_position[E_AXIS] -= 58; - plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS], MMU_LOAD_FEEDRATE, active_extruder); - st_synchronize(); + return false; } static void increment_load_fail() @@ -1507,24 +1559,28 @@ void mmu_continue_loading(bool blocking) return; } - load_more(); + bool success = load_more(); + if (success) success = can_load(); enum class Ls : uint_least8_t { - enter, - retry, - unload, + Enter, + Retry, + Unload, }; - Ls state = Ls::enter; + Ls state = Ls::Enter; - while (PIN_GET(IR_SENSOR_PIN) != 0) + const uint_least8_t max_retry = 2; + uint_least8_t retry = 0; + + while (!success) { switch (state) { - case Ls::enter: + case Ls::Enter: increment_load_fail(); // no break - case Ls::retry: + case Ls::Retry: #ifdef MMU_HAS_CUTTER if (1 == eeprom_read_byte((uint8_t*)EEPROM_MMU_CUTTER_ENABLED)) { @@ -1534,10 +1590,12 @@ void mmu_continue_loading(bool blocking) #endif //MMU_HAS_CUTTER mmu_command(MmuCmd::T0 + tmp_extruder); manage_response(true, true, MMU_TCODE_MOVE); - load_more(); - state = Ls::unload; + success = load_more(); + if (success) success = can_load(); + ++retry; // overflow not handled, as it is not dangerous. + if (retry >= max_retry) state = Ls::Unload; break; - case Ls::unload: + case Ls::Unload: stop_and_save_print_to_ram(0, 0); //lift z @@ -1562,7 +1620,7 @@ void mmu_continue_loading(bool blocking) { marlin_wait_for_click(); restore_print_from_ram_and_continue(0); - state = Ls::retry; + state = Ls::Retry; } else { diff --git a/Firmware/printers.h b/Firmware/printers.h index 8111beb05..e26431302 100644 --- a/Firmware/printers.h +++ b/Firmware/printers.h @@ -3,14 +3,38 @@ #define PRINTER_UNKNOWN 0 -#define PRINTER_MK1 100 -#define PRINTER_MK2 200 -#define PRINTER_MK2_SNMM 201 -#define PRINTER_MK25 250 -#define PRINTER_MK25_SNMM 251 -#define PRINTER_MK25S 252 -#define PRINTER_MK3 300 -#define PRINTER_MK3_SNMM 301 -#define PRINTER_MK3S 302 +// *** MK1 +#define PRINTER_MK1 100 +#define PRINTER_MK1_NAME "MK1" +// *** MK2 +#define PRINTER_MK2 200 +#define PRINTER_MK2_NAME "MK2" +#define PRINTER_MK2_SNMM 201 // better is "10200" +#define PRINTER_MK2_SNMM_NAME "MK2MM" // better is "MK2MMU1" +// *** MK2S ??? is same as "MK2" ??? +#define PRINTER_MK2S 202 +#define PRINTER_MK2S_NAME "MK2S" +#define PRINTER_MK2S_SNMM 203 // better is "10202" +#define PRINTER_MK2S_SNMM_NAME "MK2SMM" // better is "MK2SMMU1" +// *** MK2.5 +#define PRINTER_MK25 250 +#define PRINTER_MK25_NAME "MK2.5" +#define PRINTER_MK25_MMU2 20250 +#define PRINTER_MK25_MMU2_NAME "MK2.5MMU2" +// *** MK2.5S +#define PRINTER_MK25S 252 +#define PRINTER_MK25S_NAME "MK2.5S" +#define PRINTER_MK25S_MMU2 20252 +#define PRINTER_MK25S_MMU2_NAME "MK2.5SMMU2S" +// *** MK3 +#define PRINTER_MK3 300 +#define PRINTER_MK3_NAME "MK3" +#define PRINTER_MK3_MMU2 20300 +#define PRINTER_MK3_MMU2_NAME "MK3MMU2" +// *** MK3S +#define PRINTER_MK3S 302 +#define PRINTER_MK3S_NAME "MK3S" +#define PRINTER_MK3S_MMU2 20302 +#define PRINTER_MK3S_MMU2_NAME "MK3SMMU2S" #endif //PRINTERS_H diff --git a/Firmware/sound.cpp b/Firmware/sound.cpp index ba6ea726a..52d880a04 100644 --- a/Firmware/sound.cpp +++ b/Firmware/sound.cpp @@ -17,7 +17,8 @@ static void Sound_SaveMode(void); static void Sound_DoSound_Echo(void); static void Sound_DoSound_Prompt(void); static void Sound_DoSound_Alert(bool bOnce); - +static void Sound_DoSound_Encoder_Move(void); +static void Sound_DoSound_Blind_Alert(void); void Sound_Init(void) { @@ -49,9 +50,9 @@ switch(eSoundMode) eSoundMode=e_SOUND_MODE_SILENT; break; case e_SOUND_MODE_SILENT: - eSoundMode=e_SOUND_MODE_MUTE; + eSoundMode=e_SOUND_MODE_BLIND; break; - case e_SOUND_MODE_MUTE: + case e_SOUND_MODE_BLIND: eSoundMode=e_SOUND_MODE_LOUD; break; default: @@ -60,6 +61,37 @@ 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); + _delay(ms); + WRITE(BEEPER, LOW); + } + else{ + _tone(BEEPER, tone_); + _delay(ms); + _noTone(BEEPER); + } + } + } + else{ + if(!tone_){ + WRITE(BEEPER, HIGH); + _delay(ms); + WRITE(BEEPER, LOW); + _delay(ms); + } + else{ + _tone(BEEPER, tone_); + _delay(ms); + _noTone(BEEPER); + } + } +} + void Sound_MakeSound(eSOUND_TYPE eSoundType) { switch(eSoundMode) @@ -84,13 +116,48 @@ switch(eSoundMode) if(eSoundType==e_SOUND_TYPE_StandardAlert) Sound_DoSound_Alert(true); break; - case e_SOUND_MODE_MUTE: - break; + case e_SOUND_MODE_BLIND: + if(eSoundType==e_SOUND_TYPE_ButtonEcho) + Sound_DoSound_Echo(); + if(eSoundType==e_SOUND_TYPE_StandardPrompt) + Sound_DoSound_Prompt(); + if(eSoundType==e_SOUND_TYPE_StandardAlert) + Sound_DoSound_Alert(false); + if(eSoundType==e_SOUND_TYPE_EncoderMove) + Sound_DoSound_Encoder_Move(); + if(eSoundType==e_SOUND_TYPE_BlindAlert) + Sound_DoSound_Blind_Alert(); + break; default: - ; + break; } } +static void Sound_DoSound_Blind_Alert(void) +{ + uint8_t nI; + + for(nI=0; nI<20; nI++) + { + WRITE(BEEPER,HIGH); + delayMicroseconds(94); + WRITE(BEEPER,LOW); + delayMicroseconds(94); + } +} + + static void Sound_DoSound_Encoder_Move(void) +{ +uint8_t nI; + + for(nI=0;nI<5;nI++) + { + WRITE(BEEPER,HIGH); + delayMicroseconds(75); + WRITE(BEEPER,LOW); + delayMicroseconds(75); + } +} static void Sound_DoSound_Echo(void) { @@ -108,7 +175,7 @@ for(nI=0;nI<10;nI++) static void Sound_DoSound_Prompt(void) { WRITE(BEEPER,HIGH); -delay_keep_alive(500); +_delay_ms(500); WRITE(BEEPER,LOW); } @@ -120,8 +187,8 @@ nMax=bOnce?1:3; for(nI=0;nI #ifndef SOUND_H #define SOUND_H @@ -5,16 +6,16 @@ #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_MUTE "Sound [mute]" +#define MSG_SOUND_MODE_BLIND "Sound [blind]" #define e_SOUND_MODE_NULL 0xFF typedef enum - {e_SOUND_MODE_LOUD,e_SOUND_MODE_ONCE,e_SOUND_MODE_SILENT,e_SOUND_MODE_MUTE} eSOUND_MODE; + {e_SOUND_MODE_LOUD,e_SOUND_MODE_ONCE,e_SOUND_MODE_SILENT,e_SOUND_MODE_BLIND} eSOUND_MODE; #define e_SOUND_MODE_DEFAULT e_SOUND_MODE_LOUD typedef enum - {e_SOUND_TYPE_ButtonEcho,e_SOUND_TYPE_EncoderEcho,e_SOUND_TYPE_StandardPrompt,e_SOUND_TYPE_StandardConfirm,e_SOUND_TYPE_StandardWarning,e_SOUND_TYPE_StandardAlert} eSOUND_TYPE; + {e_SOUND_TYPE_ButtonEcho,e_SOUND_TYPE_EncoderEcho,e_SOUND_TYPE_StandardPrompt,e_SOUND_TYPE_StandardConfirm,e_SOUND_TYPE_StandardWarning,e_SOUND_TYPE_StandardAlert,e_SOUND_TYPE_EncoderMove,e_SOUND_TYPE_BlindAlert} eSOUND_TYPE; typedef enum {e_SOUND_CLASS_Echo,e_SOUND_CLASS_Prompt,e_SOUND_CLASS_Confirm,e_SOUND_CLASS_Warning,e_SOUND_CLASS_Alert} eSOUND_CLASS; @@ -27,6 +28,7 @@ extern void Sound_Default(void); extern void Sound_Save(void); extern void Sound_CycleState(void); extern void Sound_MakeSound(eSOUND_TYPE eSoundType); +extern void Sound_MakeCustom(uint16_t ms,uint16_t tone_ ,bool critical); //static void Sound_DoSound_Echo(void); //static void Sound_DoSound_Prompt(void); diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 74d25777c..860d761cf 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -1122,7 +1122,7 @@ void clear_current_adv_vars() { } #endif // LIN_ADVANCE - + void st_init() { #ifdef TMC2130 @@ -1306,6 +1306,9 @@ void st_init() SET_OUTPUT(Z2_STEP_PIN); WRITE(Z2_STEP_PIN,INVERT_Z_STEP_PIN); #endif + #ifdef PSU_Delta + init_force_z(); + #endif // PSU_Delta disable_z(); #endif #if defined(E0_STEP_PIN) && (E0_STEP_PIN > -1) diff --git a/Firmware/system_timer.h b/Firmware/system_timer.h index d4fbfc39b..ca8f2f9ab 100644 --- a/Firmware/system_timer.h +++ b/Firmware/system_timer.h @@ -4,7 +4,7 @@ #define FIRMWARE_SYSTEM_TIMER_H_ #include "Arduino.h" -//#define SYSTEM_TIMER_2 +#define SYSTEM_TIMER_2 #ifdef SYSTEM_TIMER_2 #include "timer02.h" @@ -13,12 +13,15 @@ #define _delay delay2 #define _tone tone2 #define _noTone noTone2 + +#define timer02_set_pwm0(pwm0) + #else //SYSTEM_TIMER_2 #define _millis millis #define _micros micros #define _delay delay -#define _tone tone -#define _noTone noTone +#define _tone(x, y) /*tone*/ +#define _noTone(x) /*noTone*/ #define timer02_set_pwm0(pwm0) #endif //SYSTEM_TIMER_2 diff --git a/Firmware/temperature.cpp b/Firmware/temperature.cpp index 7ea6d07cc..391607e8c 100755 --- a/Firmware/temperature.cpp +++ b/Firmware/temperature.cpp @@ -40,12 +40,10 @@ #include #include "adc.h" #include "ConfigurationStore.h" - +#include "messages.h" #include "Timer.h" #include "Configuration_prusa.h" - - //=========================================================================== //=============================public variables============================ //=========================================================================== @@ -434,7 +432,7 @@ static void temp_runaway_stop(bool isPreheat, bool isBed); void updatePID() { #ifdef PIDTEMP - for(int e = 0; e < EXTRUDERS; e++) { + for(uint_least8_t e = 0; e < EXTRUDERS; e++) { iState_sum_max[e] = PID_INTEGRAL_DRIVE_MAX / cs.Ki; } #endif @@ -505,8 +503,11 @@ void checkFanSpeed() fans_check_enabled = (eeprom_read_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED) > 0); static unsigned char fan_speed_errors[2] = { 0,0 }; #if (defined(FANCHECK) && defined(TACH_0) && (TACH_0 >-1)) - if ((fan_speed[0] == 0) && (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE)) fan_speed_errors[0]++; - else fan_speed_errors[0] = 0; + if ((fan_speed[0] == 0) && (current_temperature[0] > EXTRUDER_AUTO_FAN_TEMPERATURE)){ fan_speed_errors[0]++;} + else{ + fan_speed_errors[0] = 0; + host_keepalive(); + } #endif #if (defined(FANCHECK) && defined(TACH_1) && (TACH_1 >-1)) if ((fan_speed[1] < 5) && ((blocks_queued() ? block_buffer[block_buffer_tail].fan_speed : fanSpeed) > MIN_PRINT_FAN_SPEED)) fan_speed_errors[1]++; @@ -536,12 +537,7 @@ void checkFanSpeed() static void fanSpeedErrorBeep(const char *serialMsg, const char *lcdMsg){ SERIAL_ECHOLNRPGM(serialMsg); if (get_message_level() == 0) { - if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)){ - WRITE(BEEPER, HIGH); - delayMicroseconds(200); - WRITE(BEEPER, LOW); - delayMicroseconds(100); // what is this wait for? - } + Sound_MakeCustom(200,0,true); LCD_ALERTMESSAGERPGM(lcdMsg); } } @@ -549,18 +545,17 @@ 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; - } } else { + SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); //for octoprint setTargetHotend0(0); - SERIAL_ECHOLNPGM("// action:pause"); //for octoprint heating_status = 0; fan_check_error = EFCE_REPORTED; } @@ -572,6 +567,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) @@ -1133,18 +1129,9 @@ void tp_init() adc_init(); -#ifdef SYSTEM_TIMER_2 - timer02_init(); + timer0_init(); OCR2B = 128; TIMSK2 |= (1< -1 - WRITE(HEATER_BED_PIN,LOW); + #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + //WRITE(HEATER_BED_PIN,LOW); #endif #endif } @@ -1509,7 +1492,6 @@ void max_temp_error(uint8_t e) { SET_OUTPUT(BEEPER); WRITE(FAN_PIN, 1); WRITE(EXTRUDER_0_AUTO_FAN_PIN, 1); -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)) WRITE(BEEPER, 1); // fanSpeed will consumed by the check_axes_activity() routine. fanSpeed=255; @@ -1547,7 +1529,7 @@ void min_temp_error(uint8_t e) { void bed_max_temp_error(void) { #if HEATER_BED_PIN > -1 - WRITE(HEATER_BED_PIN, 0); + //WRITE(HEATER_BED_PIN, 0); #endif if(IsStopped() == false) { SERIAL_ERROR_START; @@ -1566,7 +1548,7 @@ void bed_min_temp_error(void) { #endif //if (current_temperature_ambient < MINTEMP_MINAMBIENT) return; #if HEATER_BED_PIN > -1 - WRITE(HEATER_BED_PIN, 0); + //WRITE(HEATER_BED_PIN, 0); #endif static const char err[] PROGMEM = "Err: MINTEMP BED"; if(IsStopped() == false) { @@ -1663,7 +1645,6 @@ void adc_ready(void) //callback from adc when sampling finished } // extern "C" - // Timer2 (originaly timer0) is shared with millies #ifdef SYSTEM_TIMER_2 ISR(TIMER2_COMPB_vect) @@ -1679,8 +1660,8 @@ ISR(TIMER0_COMPB_vect) if (!temp_meas_ready) adc_cycle(); lcd_buttons_update(); - static unsigned char pwm_count = (1 << SOFT_PWM_SCALE); - static unsigned char soft_pwm_0; + static uint8_t pwm_count = (1 << SOFT_PWM_SCALE); + static uint8_t soft_pwm_0; #ifdef SLOW_PWM_HEATERS static unsigned char slow_pwm_count = 0; static unsigned char state_heater_0 = 0; @@ -1701,7 +1682,7 @@ ISR(TIMER0_COMPB_vect) #endif #endif #if HEATER_BED_PIN > -1 - static unsigned char soft_pwm_b; + // @@DR static unsigned char soft_pwm_b; #ifdef SLOW_PWM_HEATERS static unsigned char state_heater_b = 0; static unsigned char state_timer_heater_b = 0; @@ -1736,14 +1717,25 @@ ISR(TIMER0_COMPB_vect) #endif } #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 + +#if 0 // @@DR vypnuto pro hw pwm bedu + // tuhle prasarnu bude potreba poustet ve stanovenych intervalech, jinak nemam moc sanci zareagovat + // teoreticky by se tato cast uz vubec nemusela poustet if ((pwm_count & ((1 << HEATER_BED_SOFT_PWM_BITS) - 1)) == 0) { soft_pwm_b = soft_pwm_bed >> (7 - HEATER_BED_SOFT_PWM_BITS); -#ifndef SYSTEM_TIMER_2 - if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0); -#endif //SYSTEM_TIMER_2 +# ifndef SYSTEM_TIMER_2 + // tady budu krokovat pomalou frekvenci na automatu - tohle je rizeni spinani a rozepinani + // jako ridici frekvenci mam 2khz, jako vystupni frekvenci mam 30hz + // 2kHz jsou ovsem ve slysitelnem pasmu, mozna bude potreba jit s frekvenci nahoru (a tomu taky prizpusobit ostatni veci) + // Teoreticky bych mohl stahnout OCR0B citac na 6, cimz bych se dostal nekam ke 40khz a tady potom honit PWM rychleji nebo i pomaleji + // to nicemu nevadi. Soft PWM scale by se 20x zvetsilo (no dobre, 16x), cimz by se to posunulo k puvodnimu 30Hz PWM + //if(soft_pwm_b > 0) WRITE(HEATER_BED_PIN,1); else WRITE(HEATER_BED_PIN,0); +# endif //SYSTEM_TIMER_2 } #endif +#endif + #ifdef FAN_SOFT_PWM if ((pwm_count & ((1 << FAN_SOFT_PWM_BITS) - 1)) == 0) { @@ -1765,8 +1757,14 @@ ISR(TIMER0_COMPB_vect) #if EXTRUDERS > 2 if(soft_pwm_2 < pwm_count) WRITE(HEATER_2_PIN,0); #endif + +#if 0 // @@DR #if defined(HEATER_BED_PIN) && HEATER_BED_PIN > -1 - if (soft_pwm_b < (pwm_count & ((1 << HEATER_BED_SOFT_PWM_BITS) - 1))) WRITE(HEATER_BED_PIN,0); + if (soft_pwm_b < (pwm_count & ((1 << HEATER_BED_SOFT_PWM_BITS) - 1))){ + //WRITE(HEATER_BED_PIN,0); + } + //WRITE(HEATER_BED_PIN, pwm_count & 1 ); +#endif #endif #ifdef FAN_SOFT_PWM if (soft_pwm_fan < (pwm_count & ((1 << FAN_SOFT_PWM_BITS) - 1))) WRITE(FAN_PIN,0); @@ -2056,8 +2054,8 @@ void check_max_temp() struct alert_automaton_mintemp { private: enum { ALERT_AUTOMATON_SPEED_DIV = 5 }; - enum class States : uint8_t { INIT = 0, TEMP_ABOVE_MINTEMP, SHOW_PLEASE_RESTART, SHOW_MINTEMP }; - States state = States::INIT; + enum class States : uint8_t { Init = 0, TempAboveMintemp, ShowPleaseRestart, ShowMintemp }; + States state = States::Init; uint8_t repeat = ALERT_AUTOMATON_SPEED_DIV; void substep(States next_state){ @@ -2076,26 +2074,26 @@ public: static const char m2[] PROGMEM = "MINTEMP fixed"; static const char m1[] PROGMEM = "Please restart"; switch(state){ - case States::INIT: // initial state - check hysteresis + case States::Init: // initial state - check hysteresis if( current_temp > mintemp ){ - state = States::TEMP_ABOVE_MINTEMP; + state = States::TempAboveMintemp; } // otherwise keep the Err MINTEMP alert message on the display, // i.e. do not transfer to state 1 break; - case States::TEMP_ABOVE_MINTEMP: // the temperature has risen above the hysteresis check + case States::TempAboveMintemp: // the temperature has risen above the hysteresis check lcd_setalertstatuspgm(m2); - substep(States::SHOW_MINTEMP); + substep(States::ShowMintemp); last_alert_sent_to_lcd = LCDALERT_MINTEMPFIXED; break; - case States::SHOW_PLEASE_RESTART: // displaying "Please restart" + case States::ShowPleaseRestart: // displaying "Please restart" lcd_updatestatuspgm(m1); - substep(States::SHOW_MINTEMP); + substep(States::ShowMintemp); last_alert_sent_to_lcd = LCDALERT_PLEASERESTART; break; - case States::SHOW_MINTEMP: // displaying "MINTEMP fixed" + case States::ShowMintemp: // displaying "MINTEMP fixed" lcd_updatestatuspgm(m2); - substep(States::SHOW_PLEASE_RESTART); + substep(States::ShowPleaseRestart); last_alert_sent_to_lcd = LCDALERT_MINTEMPFIXED; break; } diff --git a/Firmware/temperature.h b/Firmware/temperature.h index 27a7e713d..e9ba11b47 100755 --- a/Firmware/temperature.h +++ b/Firmware/temperature.h @@ -122,6 +122,7 @@ inline void babystepsTodoZsubtract(int n) //inline so that there is no performance decrease. //deg=degreeCelsius +// Doesn't save FLASH when FORCE_INLINE removed. FORCE_INLINE float degHotend(uint8_t extruder) { return current_temperature[extruder]; }; @@ -140,6 +141,7 @@ FORCE_INLINE float degBed() { return current_temperature_bed; }; +// Doesn't save FLASH when FORCE_INLINE removed. FORCE_INLINE float degTargetHotend(uint8_t extruder) { return target_temperature[extruder]; }; @@ -148,11 +150,13 @@ FORCE_INLINE float degTargetBed() { return target_temperature_bed; }; +// Doesn't save FLASH when FORCE_INLINE removed. FORCE_INLINE void setTargetHotend(const float &celsius, uint8_t extruder) { target_temperature[extruder] = celsius; resetPID(extruder); }; +// Doesn't save FLASH when not inlined. static inline void setTargetHotendSafe(const float &celsius, uint8_t extruder) { if (extruder #include -#include "Arduino.h" #include "io_atmega2560.h" #define BEEPER 84 -uint8_t timer02_pwm0 = 0; - -void timer02_set_pwm0(uint8_t pwm0) -{ - if (timer02_pwm0 == pwm0) return; - if (pwm0) - { - TCCR0A |= (2 << COM0B0); - OCR0B = pwm0 - 1; - } - else - { - TCCR0A &= ~(2 << COM0B0); - OCR0B = 0; - } - timer02_pwm0 = pwm0; -} - -void timer02_init(void) +void timer0_init(void) { //save sreg uint8_t _sreg = SREG; //disable interrupts for sure cli(); - //mask timer0 interrupts - disable all - TIMSK0 &= ~(1<> 3) #define FRACT_MAX (1000 >> 3) -//extern volatile unsigned long timer0_overflow_count; -//extern volatile unsigned long timer0_millis; -//unsigned char timer0_fract = 0; volatile unsigned long timer2_overflow_count; volatile unsigned long timer2_millis; unsigned char timer2_fract = 0; diff --git a/Firmware/timer02.h b/Firmware/timer02.h index 103360b9c..48a4842fe 100644 --- a/Firmware/timer02.h +++ b/Firmware/timer02.h @@ -11,24 +11,25 @@ extern "C" { #endif //defined(__cplusplus) +///! Initializes TIMER0 for fast PWM mode-driven bed heating +extern void timer0_init(void); -extern uint8_t timer02_pwm0; - -extern void timer02_set_pwm0(uint8_t pwm0); - -extern void timer02_init(void); - +///! Reimplemented original millis() using timer2 extern unsigned long millis2(void); +///! Reimplemented original micros() using timer2 extern unsigned long micros2(void); +///! Reimplemented original delay() using timer2 extern void delay2(unsigned long ms); +///! Reimplemented original tone() using timer2 +///! Does not perform any PWM tone generation, it just sets the beeper pin to 1 extern void tone2(uint8_t _pin, unsigned int frequency/*, unsigned long duration*/); +///! Turn off beeping - set beeper pin to 0 extern void noTone2(uint8_t _pin); - #if defined(__cplusplus) } #endif //defined(__cplusplus) diff --git a/Firmware/tmc2130.cpp b/Firmware/tmc2130.cpp old mode 100644 new mode 100755 index 05ea2ab6a..15188fc42 --- a/Firmware/tmc2130.cpp +++ b/Firmware/tmc2130.cpp @@ -142,8 +142,11 @@ uint16_t __tcoolthrs(uint8_t axis) } return 0; } - +#ifdef PSU_Delta +void tmc2130_init(bool bSupressFlag) +#else void tmc2130_init() +#endif { // DBG(_n("tmc2130_init(), mode=%S\n"), tmc2130_mode?_n("STEALTH"):_n("NORMAL")); WRITE(X_TMC2130_CS, HIGH); @@ -158,7 +161,7 @@ void tmc2130_init() SET_INPUT(Y_TMC2130_DIAG); SET_INPUT(Z_TMC2130_DIAG); SET_INPUT(E0_TMC2130_DIAG); - for (int axis = 0; axis < 2; axis++) // X Y axes + for (uint_least8_t axis = 0; axis < 2; axis++) // X Y axes { tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); @@ -169,7 +172,7 @@ void tmc2130_init() tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS); //tmc2130_wr_THIGH(axis, TMC2130_THIGH); } - for (int axis = 2; axis < 3; axis++) // Z axis + for (uint_least8_t axis = 2; axis < 3; axis++) // Z axis { tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); @@ -183,7 +186,7 @@ void tmc2130_init() tmc2130_wr_TPWMTHRS(axis, TMC2130_TPWMTHRS); #endif //TMC2130_STEALTH_Z } - for (int axis = 3; axis < 4; axis++) // E axis + for (uint_least8_t axis = 3; axis < 4; axis++) // E axis { tmc2130_setup_chopper(axis, tmc2130_mres[axis], tmc2130_current_h[axis], tmc2130_current_r[axis]); tmc2130_wr(axis, TMC2130_REG_TPOWERDOWN, 0x00000000); @@ -216,6 +219,11 @@ void tmc2130_init() tmc2130_set_wave(E_AXIS, 247, tmc2130_wave_fac[E_AXIS]); #endif //TMC2130_LINEARITY_CORRECTION +#ifdef PSU_Delta + if(!bSupressFlag) + check_force_z(); +#endif // PSU_Delta + } uint8_t tmc2130_sample_diag() @@ -383,7 +391,7 @@ void tmc2130_check_overtemp() static uint32_t checktime = 0; if (_millis() - checktime > 1000 ) { - for (int i = 0; i < 4; i++) + for (uint_least8_t i = 0; i < 4; i++) { uint32_t drv_status = 0; skip_debug_msg = true; @@ -392,7 +400,7 @@ void tmc2130_check_overtemp() { // BIT 26 - over temp prewarning ~120C (+-20C) SERIAL_ERRORRPGM(MSG_TMC_OVERTEMP); SERIAL_ECHOLN(i); - for (int j = 0; j < 4; j++) + for (uint_least8_t j = 0; j < 4; j++) tmc2130_wr(j, TMC2130_REG_CHOPCONF, 0x00010000); kill(MSG_TMC_OVERTEMP); } diff --git a/Firmware/tmc2130.h b/Firmware/tmc2130.h index 1c854f79c..ed4c0d7c0 100644 --- a/Firmware/tmc2130.h +++ b/Firmware/tmc2130.h @@ -51,7 +51,11 @@ typedef struct extern tmc2130_chopper_config_t tmc2130_chopper_config[4]; //initialize tmc2130 +#ifdef PSU_Delta +extern void tmc2130_init(bool bSupressFlag=false); +#else extern void tmc2130_init(); +#endif //check diag pins (called from stepper isr) extern void tmc2130_st_isr(); //update stall guard (called from st_synchronize inside the loop) diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 47c42747a..ac8a302fd 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -40,6 +40,7 @@ #include "static_assert.h" #include "io_atmega2560.h" +#include "first_lay_cal.h" int scrollstuff = 0; @@ -73,10 +74,10 @@ extern void crashdet_disable(); bool presort_flag = false; #endif -int lcd_commands_type = LCD_COMMAND_IDLE; -int lcd_commands_step = 0; +LcdCommands lcd_commands_type = LcdCommands::Idle; +static uint8_t lcd_commands_step = 0; -unsigned int custom_message_type = CUSTOM_MSG_TYPE_STATUS; +CustomMsg custom_message_type = CustomMsg::Status; unsigned int custom_message_state = 0; @@ -84,7 +85,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; @@ -130,6 +131,7 @@ static void lcd_control_volumetric_menu(); static void lcd_settings_linearity_correction_menu_save(); static void prusa_stat_printerstatus(int _status); static void prusa_stat_farm_number(); +static void prusa_stat_diameter(); static void prusa_stat_temperatures(); static void prusa_stat_printinfo(); static void lcd_farm_no(); @@ -165,42 +167,42 @@ static bool lcd_selfcheck_pulleys(int axis); #endif //TMC2130 static bool lcd_selfcheck_check_heater(bool _isbed); -enum class testScreen : uint_least8_t +enum class TestScreen : uint_least8_t { - extruderFan, - printFan, - fansOk, - endStops, - axisX, - axisY, - axisZ, - bed, - hotend, - hotendOk, - fsensor, - fsensorOk, - allCorrect, - failed, - home, + ExtruderFan, + PrintFan, + FansOk, + EndStops, + AxisX, + AxisY, + AxisZ, + Bed, + Hotend, + HotendOk, + Fsensor, + FsensorOk, + AllCorrect, + Failed, + Home, }; enum class TestError : uint_least8_t { - heater, - bed, - endstops, - motor, - endstop, - printFan, - extruderFan, - pulley, - axis, - swappedFan, - wiringFsensor, - triggeringFsensor, + Heater, + Bed, + Endstops, + Motor, + Endstop, + PrintFan, + ExtruderFan, + Pulley, + Axis, + SwappedFan, + WiringFsensor, + TriggeringFsensor, }; -static int lcd_selftest_screen(testScreen screen, int _progress, int _progress_scale, bool _clear, int _delay); +static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_scale, bool _clear, int _delay); static void lcd_selftest_screen_step(int _row, int _col, int _state, const char *_name, const char *_indicator); static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite, bool _default=false); @@ -209,10 +211,10 @@ static bool lcd_selftest_manual_fan_check(int _fan, bool check_opposite, /** Enumerate for lcd_selftest_fan_auto function. */ enum class FanCheck : uint_least8_t { - success, - printFan = TestError::printFan, - extruderFan = TestError::extruderFan, - swappedFan = TestError::swappedFan, + Success, + PrintFan, + ExtruderFan, + SwappedFan, }; /** @@ -245,7 +247,6 @@ static char snmm_stop_print_menu(); #ifdef SDCARD_SORT_ALPHA static void lcd_sort_type_set(); #endif -static float count_e(float layer_heigth, float extrusion_width, float extrusion_length); static void lcd_babystep_z(); static void lcd_send_status(); #ifdef FARM_CONNECT_MESSAGE @@ -256,6 +257,11 @@ static void lcd_connect_printer(); void lcd_finishstatus(); static void lcd_sdcard_menu(); +static void lcd_sheet_menu(); + +static void lcd_select_sheet_0_menu(); +static void lcd_select_sheet_1_menu(); +static void lcd_select_sheet_2_menu(); #ifdef DELTA_CALIBRATION_MENU static void lcd_delta_calibrate_menu(); @@ -297,6 +303,8 @@ static void menu_action_sddirectory(const char* filename); bool lcd_oldcardstatus; #endif +uint8_t selected_sheet = 0; + bool ignore_click = false; bool wait_for_unclick; @@ -306,6 +314,7 @@ bool wait_for_unclick; #endif bool bMain; // flag (i.e. 'fake parameter') for 'lcd_sdcard_menu()' function +bool bSettings; // flag (i.e. 'fake parameter') for 'lcd_hw_setup_menu()' function @@ -317,7 +326,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(uint_least8_t g = 0; g<4;g++){ lcd_set_cursor(0, g); lcd_print(' '); } @@ -565,7 +574,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 == CustomMsg::MeshBedLeveling) lcd_puts_P(_N("Z --- ")); else lcd_printf_P(_N("Z%6.2f "), current_position[Z_AXIS]); @@ -760,7 +769,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 == CustomMsg::Status)) { // If printing from SD, show what we are printing if(strlen(card.longFilename) > LCD_WIDTH) { @@ -794,10 +803,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 CustomMsg::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 CustomMsg::MeshBedLeveling: // If mesh bed leveling in progress, show the status if (custom_message_state > 10) { lcd_set_cursor(0, 3); @@ -813,7 +822,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 = CustomMsg::Status; } if (custom_message_state > 3 && custom_message_state <= 10 ) { @@ -825,10 +834,10 @@ void lcdui_print_status_line(void) } } break; - case CUSTOM_MSG_TYPE_F_LOAD: // If loading filament, print status + case CustomMsg::FilamentLoading: // If loading filament, print status lcd_print(lcd_status_message); break; - case CUSTOM_MSG_TYPE_PIDCAL: // PID tuning in progress + case CustomMsg::PidCal: // PID tuning in progress lcd_print(lcd_status_message); if (pid_cycle <= pid_number_of_cycles && custom_message_state > 0) { @@ -838,7 +847,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 CustomMsg::TempCal: // PINDA temp calibration in progress { char progress[4]; lcd_set_cursor(0, 3); @@ -848,7 +857,7 @@ void lcdui_print_status_line(void) lcd_print(progress); } break; - case CUSTOM_MSG_TYPE_TEMPRE: // temp compensation preheat + case CustomMsg::TempCompPreheat: // 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) @@ -987,6 +996,8 @@ static void lcd_status_screen() { case 8: prusa_statistics(21); + if(loading_flag) + prusa_statistics(22); break; case 5: if (IS_SD_PRINTING) @@ -996,7 +1007,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 +1031,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::StopPrint) //click is aborted unless stop print finishes && ( menu_block_entering_on_serious_errors == SERIOUS_ERR_NONE ) // or a serious error blocks entering the menu ) { @@ -1060,18 +1071,17 @@ static void lcd_status_screen() feedmultiply = 999; } - void lcd_commands() -{ - if (lcd_commands_type == LCD_COMMAND_LONG_PAUSE) +{ + if (lcd_commands_type == LcdCommands::LongPause) { 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::LongPause) // !!! because "lcd_commands_type" can be changed during/inside "long_pause()" { - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::Idle; lcd_commands_step = 0; } } @@ -1079,7 +1089,7 @@ void lcd_commands() #ifdef SNMM - if (lcd_commands_type == LCD_COMMAND_V2_CAL) + if (lcd_commands_type == LcdCommands::Layer1Cal) { char cmd1[30]; float width = 0.4; @@ -1344,300 +1354,115 @@ void lcd_commands() #else //if not SNMM - if (lcd_commands_type == LCD_COMMAND_V2_CAL) + if (lcd_commands_type == LcdCommands::Layer1Cal) { char cmd1[30]; static uint8_t filament = 0; - float width = 0.4; - float length = 20 - width; - float extr = count_e(0.2, width, length); - float extr_short_segment = count_e(0.2, width, width); + if(lcd_commands_step>1) lcd_timeoutToStatus.start(); //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen - if (lcd_commands_step == 0 && !blocks_queued() && cmd_buffer_empty()) - { - lcd_commands_step = 10; - } - if (lcd_commands_step == 20 && !blocks_queued() && cmd_buffer_empty()) - { - filament = 0; - lcd_commands_step = 10; - } - if (lcd_commands_step == 21 && !blocks_queued() && cmd_buffer_empty()) + if (!blocks_queued() && cmd_buffer_empty()) { - filament = 1; - lcd_commands_step = 10; - } - if (lcd_commands_step == 22 && !blocks_queued() && cmd_buffer_empty()) - { - filament = 2; - lcd_commands_step = 10; - } - if (lcd_commands_step == 23 && !blocks_queued() && cmd_buffer_empty()) - { - filament = 3; - lcd_commands_step = 10; - } - if (lcd_commands_step == 24 && !blocks_queued() && cmd_buffer_empty()) - { - filament = 4; - lcd_commands_step = 10; - } - - if (lcd_commands_step == 10) - { - enquecommand_P(PSTR("M107")); - enquecommand_P(PSTR("M104 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP))); - enquecommand_P(PSTR("M140 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP))); - enquecommand_P(PSTR("M190 S" STRINGIFY(PLA_PREHEAT_HPB_TEMP))); - enquecommand_P(PSTR("M109 S" STRINGIFY(PLA_PREHEAT_HOTEND_TEMP))); - enquecommand_P(_T(MSG_M117_V2_CALIBRATION)); - enquecommand_P(PSTR("G28")); - enquecommand_P(PSTR("G92 E0.0")); - - lcd_commands_step = 9; - } - if (lcd_commands_step == 9 && !blocks_queued() && cmd_buffer_empty()) - { - lcd_clear(); - menu_depth = 0; - menu_submenu(lcd_babystep_z); - - if (mmu_enabled) + switch(lcd_commands_step) { - enquecommand_P(PSTR("M83")); //intro line - enquecommand_P(PSTR("G1 Y-3.0 F1000.0")); //intro line - enquecommand_P(PSTR("G1 Z0.4 F1000.0")); //intro line - strcpy(cmd1, "T"); - strcat(cmd1, itostr3left(filament)); - enquecommand(cmd1); - enquecommand_P(PSTR("G1 X55.0 E32.0 F1073.0")); //intro line - enquecommand_P(PSTR("G1 X5.0 E32.0 F1800.0")); //intro line - enquecommand_P(PSTR("G1 X55.0 E8.0 F2000.0")); //intro line - enquecommand_P(PSTR("G1 Z0.3 F1000.0")); //intro line - enquecommand_P(PSTR("G92 E0.0")); //intro line - enquecommand_P(PSTR("G1 X240.0 E25.0 F2200.0")); //intro line - enquecommand_P(PSTR("G1 Y-2.0 F1000.0")); //intro line - enquecommand_P(PSTR("G1 X55.0 E25 F1400.0")); //intro line - enquecommand_P(PSTR("G1 Z0.20 F1000.0")); //intro line - enquecommand_P(PSTR("G1 X5.0 E4.0 F1000.0")); //intro line - - } else - { - enquecommand_P(PSTR("G1 X60.0 E9.0 F1000.0")); //intro line - enquecommand_P(PSTR("G1 X100.0 E12.5 F1000.0")); //intro line - } - - lcd_commands_step = 8; - } - if (lcd_commands_step == 8 && !blocks_queued() && cmd_buffer_empty()) - { - - enquecommand_P(PSTR("G92 E0.0")); - enquecommand_P(PSTR("G21")); //set units to millimeters - enquecommand_P(PSTR("G90")); //use absolute coordinates - enquecommand_P(PSTR("M83")); //use relative distances for extrusion - enquecommand_P(PSTR("G1 E-1.50000 F2100.00000")); - enquecommand_P(PSTR("G1 Z5 F7200.000")); - enquecommand_P(PSTR("M204 S1000")); //set acceleration - enquecommand_P(PSTR("G1 F4000")); - lcd_commands_step = 7; + case 0: + lcd_commands_step = 10; + break; + case 20: + filament = 0; + lcd_commands_step = 10; + break; + case 21: + filament = 1; + lcd_commands_step = 10; + break; + case 22: + filament = 2; + lcd_commands_step = 10; + break; + case 23: + filament = 3; + lcd_commands_step = 10; + break; + case 24: + filament = 4; + lcd_commands_step = 10; + break; + case 10: + lay1cal_preheat(); + lcd_commands_step = 9; + break; + case 9: + lcd_clear(); + menu_depth = 0; + menu_submenu(lcd_babystep_z); + lay1cal_intro_line(cmd1, filament); + lcd_commands_step = 8; + break; + case 8: + lay1cal_before_meander(); + lcd_commands_step = 7; + break; + case 7: + lay1cal_meander(cmd1); + lcd_commands_step = 6; + break; + case 6: + for (uint8_t i = 0; i < 4; i++) + { + lay1cal_square(cmd1, i); + } + lcd_commands_step = 5; + break; + case 5: + for (uint8_t i = 4; i < 8; i++) + { + lay1cal_square(cmd1, i); + } + lcd_commands_step = 4; + break; + case 4: + for (uint8_t i = 8; i < 12; i++) + { + lay1cal_square(cmd1, i); + } + lcd_commands_step = 3; + break; + case 3: + for (uint8_t i = 12; i < 16; i++) + { + lay1cal_square(cmd1, i); + } + lcd_commands_step = 2; + break; + case 2: + enquecommand_P(PSTR("M107")); //turn off printer fan + enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract + enquecommand_P(PSTR("M104 S0")); // turn off temperature + enquecommand_P(PSTR("M140 S0")); // turn off heatbed + enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z + enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position + if (mmu_enabled) enquecommand_P(PSTR("M702 C")); //unload from nozzle + enquecommand_P(PSTR("M84"));// disable motors + forceMenuExpire = true; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen + lcd_commands_step = 1; + break; + case 1: + lcd_setstatuspgm(_T(WELCOME_MSG)); + lcd_commands_step = 0; + lcd_commands_type = LcdCommands::Idle; + if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) + { + lcd_wizard(WizState::RepeatLay1Cal); + } + break; } - if (lcd_commands_step == 7 && !blocks_queued() && cmd_buffer_empty()) //draw meander - { - lcd_timeoutToStatus.start(); - - - //just opposite direction - /*enquecommand_P(PSTR("G1 X50 Y55")); - enquecommand_P(PSTR("G1 F1080")); - enquecommand_P(PSTR("G1 X200 Y55 E3.62773")); - enquecommand_P(PSTR("G1 X200 Y75 E0.49386")); - enquecommand_P(PSTR("G1 X50 Y75 E3.62773")); - enquecommand_P(PSTR("G1 X50 Y95 E0.49386")); - enquecommand_P(PSTR("G1 X200 Y95 E3.62773")); - enquecommand_P(PSTR("G1 X200 Y115 E0.49386")); - enquecommand_P(PSTR("G1 X50 Y115 E3.62773")); - enquecommand_P(PSTR("G1 X50 Y135 E0.49386")); - enquecommand_P(PSTR("G1 X200 Y135 E3.62773")); - enquecommand_P(PSTR("G1 X200 Y155 E0.66174")); - enquecommand_P(PSTR("G1 X100 Y155 E2.62773")); - enquecommand_P(PSTR("G1 X75 Y155 E2")); - enquecommand_P(PSTR("G1 X50 Y155 E2.5")); - enquecommand_P(PSTR("G1 E - 0.07500 F2100.00000"));*/ - - - enquecommand_P(PSTR("G1 X50 Y155")); - enquecommand_P(PSTR("G1 Z0.150 F7200.000")); - enquecommand_P(PSTR("G1 F1080")); - enquecommand_P(PSTR("G1 X75 Y155 E2.5")); - enquecommand_P(PSTR("G1 X100 Y155 E2")); - enquecommand_P(PSTR("G1 X200 Y155 E2.62773")); - enquecommand_P(PSTR("G1 X200 Y135 E0.66174")); - enquecommand_P(PSTR("G1 X50 Y135 E3.62773")); - enquecommand_P(PSTR("G1 X50 Y115 E0.49386")); - enquecommand_P(PSTR("G1 X200 Y115 E3.62773")); - enquecommand_P(PSTR("G1 X200 Y95 E0.49386")); - enquecommand_P(PSTR("G1 X50 Y95 E3.62773")); - enquecommand_P(PSTR("G1 X50 Y75 E0.49386")); - enquecommand_P(PSTR("G1 X200 Y75 E3.62773")); - enquecommand_P(PSTR("G1 X200 Y55 E0.49386")); - enquecommand_P(PSTR("G1 X50 Y55 E3.62773")); - - strcpy(cmd1, "G1 X50 Y35 E"); - strcat(cmd1, ftostr43(extr)); - enquecommand(cmd1); - - lcd_commands_step = 6; - } - - if (lcd_commands_step == 6 && !blocks_queued() && cmd_buffer_empty()) - { - - 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); - } - - lcd_commands_step = 5; - } - - 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); - } - - 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_commands_step = 3; - } - - 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); - } - - lcd_commands_step = 2; - } - - if (lcd_commands_step == 2 && !blocks_queued() && cmd_buffer_empty()) - { - lcd_timeoutToStatus.start(); - enquecommand_P(PSTR("M107")); //turn off printer fan - enquecommand_P(PSTR("G1 E-0.07500 F2100.00000")); //retract - enquecommand_P(PSTR("M104 S0")); // turn off temperature - enquecommand_P(PSTR("M140 S0")); // turn off heatbed - enquecommand_P(PSTR("G1 Z10 F1300.000")); //lift Z - enquecommand_P(PSTR("G1 X10 Y180 F4000")); //Go to parking position - if (mmu_enabled) enquecommand_P(PSTR("M702 C")); //unload from nozzle - enquecommand_P(PSTR("M84"));// disable motors - forceMenuExpire = true; //if user dont confirm live adjust Z value by pressing the knob, we are saving last value by timeout to status screen - lcd_commands_step = 1; - } - if (lcd_commands_step == 1 && !blocks_queued() && cmd_buffer_empty()) - { - lcd_setstatuspgm(_T(WELCOME_MSG)); - lcd_commands_step = 0; - lcd_commands_type = 0; - if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) == 1) { - lcd_wizard(WizState::RepeatLay1Cal); } } - } - #endif // not SNMM - if (lcd_commands_type == LCD_COMMAND_STOP_PRINT) /// stop print + if (lcd_commands_type == LcdCommands::StopPrint) /// stop print { @@ -1649,9 +1474,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 = CustomMsg::Status; isPrintPaused = false; } if (lcd_commands_step == 2 && !blocks_queued()) @@ -1707,7 +1532,7 @@ void lcd_commands() if (mmu_enabled) setAllTargetHotends(0); manage_heater(); - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; + custom_message_type = CustomMsg::FilamentLoading; lcd_commands_step = 5; } if (lcd_commands_step == 7 && !blocks_queued()) @@ -1729,12 +1554,7 @@ void lcd_commands() } } - if (lcd_commands_type == 3) - { - lcd_commands_type = 0; - } - - if (lcd_commands_type == LCD_COMMAND_FARM_MODE_CONFIRM) /// farm mode confirm + if (lcd_commands_type == LcdCommands::FarmModeConfirm) /// farm mode confirm { if (lcd_commands_step == 0) { lcd_commands_step = 6; } @@ -1743,7 +1563,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()) { @@ -1776,11 +1596,11 @@ void lcd_commands() } } - if (lcd_commands_type == LCD_COMMAND_PID_EXTRUDER) { + if (lcd_commands_type == LcdCommands::PidExtruder) { char cmd1[30]; if (lcd_commands_step == 0) { - custom_message_type = CUSTOM_MSG_TYPE_PIDCAL; + custom_message_type = CustomMsg::PidCal; custom_message_state = 1; lcd_draw_update = 3; lcd_commands_step = 3; @@ -1816,28 +1636,22 @@ 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 = CustomMsg::Status; pid_temp = DEFAULT_PID_TEMP; lcd_commands_step = 0; - lcd_commands_type = 0; + lcd_commands_type = LcdCommands::Idle; } } } -static float count_e(float layer_heigth, float extrusion_width, float extrusion_length) { - //returns filament length in mm which needs to be extrude to form line with extrusion_length * extrusion_width * layer heigth dimensions - float extr = extrusion_length * layer_heigth * extrusion_width / (M_PI * pow(1.75, 2) / 4); - return extr; -} - 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=FilamentAction::None; // i.e. non-autoLoad } //! @brief Pause print, disable nozzle heater, move to park position @@ -1847,10 +1661,11 @@ 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::LongPause; } + SERIAL_PROTOCOLLNRPGM(MSG_OCTOPRINT_PAUSE); //pause for octoprint } @@ -1964,8 +1779,8 @@ void lcd_menu_extruder_info() // NOT static due to using ins lcd_timeoutToStatus.stop(); //infinite timeout + lcd_home(); lcd_printf_P(_N( - ESC_H(0,0) "%S: %4d RPM\n" "%S: %4d RPM\n" ), @@ -1990,7 +1805,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::Layer1Cal)) pat9125_update(); lcd_printf_P(_N( "Fil. Xd:%3d Yd:%3d\n" @@ -2026,8 +1841,8 @@ static void lcd_menu_fails_stats_mmu_print() lcd_timeoutToStatus.stop(); //infinite timeout uint8_t fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL); uint16_t load_fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL); -// lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); - lcd_printf_P(PSTR(ESC_H(0,0) "%S" ESC_H(1,1) "%S %-3d" ESC_H(1,2) "%S %-3d" ESC_H(1,3)), _i("Last print failures"), _i("MMU fails"), fails, _i("MMU load fails"), load_fails); + lcd_home(); + lcd_printf_P(PSTR("%S\n" " %S %-3d\n" " %S %-3d"), _i("Last print failures"), _i("MMU fails"), fails, _i("MMU load fails"), load_fails); menu_back_if_clicked_fb(); } @@ -2043,8 +1858,8 @@ static void lcd_menu_fails_stats_mmu_total() lcd_timeoutToStatus.stop(); //infinite timeout uint8_t fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_FAIL_TOT); uint16_t load_fails = eeprom_read_byte((uint8_t*)EEPROM_MMU_LOAD_FAIL_TOT); -// lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); - lcd_printf_P(PSTR(ESC_H(0,0) "%S" ESC_H(1,1) "%S %-3d" ESC_H(1,2) "%S %-3d" ESC_H(1,3) "%S %-3d"), _i("Total failures"), _i("MMU fails"), fails, _i("MMU load fails"), load_fails, _i("MMU power fails"), mmu_power_failures); + lcd_home(); + lcd_printf_P(PSTR("%S\n" " %S %-3d\n" " %S %-3d\n" " %S %-3d"), _i("Total failures"), _i("MMU fails"), fails, _i("MMU load fails"), load_fails, _i("MMU power fails"), mmu_power_failures); menu_back_if_clicked_fb(); } @@ -2062,8 +1877,8 @@ static void lcd_menu_fails_stats_total() uint16_t filam = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); uint16_t crashX = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_X_TOT); uint16_t crashY = eeprom_read_word((uint16_t*)EEPROM_CRASH_COUNT_Y_TOT); -// lcd_printf_P(PSTR(ESC_H(0,0) "Total failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); - lcd_printf_P(PSTR(ESC_H(0,0) "%S" ESC_H(1,1) "%S %-3d" ESC_H(1,2) "%S %-3d" ESC_H(1,3) "%S X %-3d Y %-3d"), _i("Total failures"), _i("Power failures"), power, _i("Filam. runouts"), filam, _i("Crash"), crashX, crashY); + lcd_home(); + lcd_printf_P(PSTR("%S\n" " %S %-3d\n" " %S %-3d\n" " %S X %-3d Y %-3d"), _i("Total failures"), _i("Power failures"), power, _i("Filam. runouts"), filam, _i("Crash"), crashX, crashY); menu_back_if_clicked_fb(); } @@ -2080,8 +1895,8 @@ static void lcd_menu_fails_stats_print() uint8_t filam = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint8_t crashX = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_X); uint8_t crashY = eeprom_read_byte((uint8_t*)EEPROM_CRASH_COUNT_Y); -// lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Power failures %-3d" ESC_H(1,2) "Filam. runouts %-3d" ESC_H(1,3) "Crash X %-3d Y %-3d"), power, filam, crashX, crashY); - lcd_printf_P(PSTR(ESC_H(0,0) "%S" ESC_H(1,1) "%S %-3d" ESC_H(1,2) "%S %-3d" ESC_H(1,3) "%S X %-3d Y %-3d"), _i("Last print failures"), _i("Power failures"), power, _i("Filam. runouts"), filam, _i("Crash"), crashX, crashY); + lcd_home(); + lcd_printf_P(PSTR("%S\n" " %S %-3d\n" " %S %-3d\n" " %S X %-3d Y %-3d"), _i("Last print failures"), _i("Power failures"), power, _i("Filam. runouts"), filam, _i("Crash"), crashX, crashY); menu_back_if_clicked_fb(); } @@ -2122,7 +1937,8 @@ static void lcd_menu_fails_stats() lcd_timeoutToStatus.stop(); //infinite timeout uint8_t filamentLast = eeprom_read_byte((uint8_t*)EEPROM_FERROR_COUNT); uint16_t filamentTotal = eeprom_read_word((uint16_t*)EEPROM_FERROR_COUNT_TOT); - lcd_printf_P(PSTR(ESC_H(0,0) "Last print failures" ESC_H(1,1) "Filam. runouts %-3d" ESC_H(0,2) "Total failures" ESC_H(1,3) "Filam. runouts %-3d"), filamentLast, filamentTotal); + lcd_home(); + lcd_printf_P(PSTR("Last print failures\n" " Filam. runouts %-3d\n" "Total failures\n" " Filam. runouts %-3d"), filamentLast, filamentTotal); menu_back_if_clicked(); } #else @@ -2146,7 +1962,8 @@ extern char* __malloc_heap_end; static void lcd_menu_debug() { #ifdef DEBUG_STACK_MONITOR - lcd_printf_P(PSTR(ESC_H(1,1) "RAM statistics" ESC_H(5,1) "SP_min: 0x%04x" ESC_H(1,2) "heap_start: 0x%04x" ESC_H(3,3) "heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); + lcd_home(); + lcd_printf_P(PSTR("RAM statistics\n" " SP_min: 0x%04x\n" " heap_start: 0x%04x\n" " heap_end: 0x%04x"), SP_min, __malloc_heap_start, __malloc_heap_end); #endif //DEBUG_STACK_MONITOR menu_back_if_clicked_fb(); @@ -2156,12 +1973,12 @@ static void lcd_menu_debug() static void lcd_menu_temperatures() { lcd_timeoutToStatus.stop(); //infinite timeout - - lcd_printf_P(PSTR(ESC_H(1,0) "%S: %d%c" ESC_H(1,1) "%S: %d%c"), _i("Nozzle"), (int)current_temperature[0], '\x01', _i("Bed"), (int)current_temperature_bed, '\x01'); + lcd_home(); + lcd_printf_P(PSTR(" %S: %d%c \n" " %S: %d%c \n"), _i("Nozzle"), (int)current_temperature[0], '\x01', _i("Bed"), (int)current_temperature_bed, '\x01'); #ifdef AMBIENT_THERMISTOR - lcd_printf_P(PSTR(ESC_H(1,2) "%S: %d%c" ESC_H(1,3) "PINDA: %d%c"), _i("Ambient"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01'); + lcd_printf_P(PSTR(" %S: %d%c\n" " PINDA: %d%c"), _i("Ambient"), (int)current_temperature_ambient, '\x01', (int)current_temperature_pinda, '\x01'); #else //AMBIENT_THERMISTOR - lcd_printf_P(PSTR(ESC_H(1,2) "PINDA: %d%c"), (int)current_temperature_pinda, '\x01'); + lcd_printf_P(PSTR(" PINDA: %d%c"), (int)current_temperature_pinda, '\x01'); #endif //AMBIENT_THERMISTOR menu_back_if_clicked(); @@ -2177,7 +1994,8 @@ static void lcd_menu_voltages() lcd_timeoutToStatus.stop(); //infinite timeout float volt_pwr = VOLT_DIV_REF * ((float)current_voltage_raw_pwr / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; float volt_bed = VOLT_DIV_REF * ((float)current_voltage_raw_bed / (1023 * OVERSAMPLENR)) / VOLT_DIV_FAC; - lcd_printf_P(PSTR(ESC_H(1,1)"PWR: %d.%01dV" ESC_H(1,2)"BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed))); + lcd_home(); + lcd_printf_P(PSTR(" PWR: %d.%01dV\n" " BED: %d.%01dV"), (int)volt_pwr, (int)(10*fabs(volt_pwr - (int)volt_pwr)), (int)volt_bed, (int)(10*fabs(volt_bed - (int)volt_bed))); menu_back_if_clicked(); } #endif //defined VOLT_BED_PIN || defined VOLT_PWR_PIN @@ -2185,7 +2003,8 @@ static void lcd_menu_voltages() #ifdef TMC2130 static void lcd_menu_belt_status() { - lcd_printf_P(PSTR(ESC_H(1,0) "%S" ESC_H(2,1) "X %d" ESC_H(2,2) "Y %d" ), _i("Belt status"), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y))); + lcd_home(); + lcd_printf_P(PSTR("%S\n" " X %d\n" " Y %d"), _i("Belt status"), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_X)), eeprom_read_word((uint16_t*)(EEPROM_BELTSTATUS_Y))); menu_back_if_clicked(); } #endif //TMC2130 @@ -2215,7 +2034,6 @@ static void lcd_preheat_menu() MENU_ITEM_FUNCTION_P(PSTR("farm - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(FARM_PREHEAT_HPB_TEMP)), lcd_preheat_farm); MENU_ITEM_FUNCTION_P(PSTR("nozzle - " STRINGIFY(FARM_PREHEAT_HOTEND_TEMP) "/0"), lcd_preheat_farm_nozzle); MENU_ITEM_FUNCTION_P(_T(MSG_COOLDOWN), lcd_cooldown); - MENU_ITEM_FUNCTION_P(PSTR("ABS - " STRINGIFY(ABS_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(ABS_PREHEAT_HPB_TEMP)), lcd_preheat_abs); } else { MENU_ITEM_FUNCTION_P(PSTR("PLA - " STRINGIFY(PLA_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PLA_PREHEAT_HPB_TEMP)), lcd_preheat_pla); MENU_ITEM_FUNCTION_P(PSTR("PET - " STRINGIFY(PET_PREHEAT_HOTEND_TEMP) "/" STRINGIFY(PET_PREHEAT_HPB_TEMP)), lcd_preheat_pet); @@ -2376,7 +2194,7 @@ void lcd_set_filament_oq_meass() } -eFILAMENT_ACTION eFilamentAction=e_FILAMENT_ACTION_none; // must be initialized as 'non-autoLoad' +FilamentAction eFilamentAction=FilamentAction::None; // must be initialized as 'non-autoLoad' bool bFilamentFirstRun; bool bFilamentPreheatState; bool bFilamentAction=false; @@ -2393,18 +2211,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 FilamentAction::Load: + case FilamentAction::AutoLoad: + case FilamentAction::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 FilamentAction::UnLoad: + case FilamentAction::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 FilamentAction::MmuEject: + case FilamentAction::MmuCut: + case FilamentAction::None: break; } if(lcd_clicked()) @@ -2418,21 +2236,21 @@ if(lcd_clicked()) menu_back(nLevel); switch(eFilamentAction) { - case e_FILAMENT_ACTION_autoLoad: - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad + case FilamentAction::AutoLoad: + eFilamentAction=FilamentAction::None; // i.e. non-autoLoad // no break - case e_FILAMENT_ACTION_Load: + case FilamentAction::Load: loading_flag=true; enquecommand_P(PSTR("M701")); // load filament break; - case e_FILAMENT_ACTION_unLoad: + case FilamentAction::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 FilamentAction::MmuLoad: + case FilamentAction::MmuUnLoad: + case FilamentAction::MmuEject: + case FilamentAction::MmuCut: + case FilamentAction::None: break; } } @@ -2456,19 +2274,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; } @@ -2487,20 +2305,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++; @@ -2508,7 +2326,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++; @@ -2516,7 +2334,7 @@ else { menu_back(nLevel); extr_unload(); break; - case e_FILAMENT_ACTION_mmuEject: + case eFILAMENT_ACTION::mmuEject: nLevel=1; if(!bFilamentPreheatState) nLevel++; @@ -2524,7 +2342,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++; @@ -2557,44 +2375,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 FilamentAction::Load: + case FilamentAction::AutoLoad: + case FilamentAction::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==FilamentAction::Load)||(eFilamentAction==FilamentAction::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==FilamentAction::AutoLoad) + eFilamentAction=FilamentAction::None; // i.e. non-autoLoad } - if(eFilamentAction==e_FILAMENT_ACTION_unLoad) + if(eFilamentAction==FilamentAction::UnLoad) enquecommand_P(PSTR("M702")); // unload filament } break; - case e_FILAMENT_ACTION_mmuLoad: + case FilamentAction::MmuLoad: nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; menu_back(nLevel); menu_submenu(mmu_load_to_nozzle_menu); break; - case e_FILAMENT_ACTION_mmuUnLoad: + case FilamentAction::MmuUnLoad: nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; menu_back(nLevel); extr_unload(); break; - case e_FILAMENT_ACTION_mmuEject: + case FilamentAction::MmuEject: nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; menu_back(nLevel); menu_submenu(mmu_fil_eject_menu); break; - case e_FILAMENT_ACTION_mmuCut: + case FilamentAction::MmuCut: #ifdef MMU_HAS_CUTTER nLevel=bFilamentPreheatState?1:2; bFilamentAction=true; @@ -2602,7 +2420,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 FilamentAction::None: break; } if(bFilamentWaitingFlag) @@ -2616,22 +2434,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 FilamentAction::Load: + case FilamentAction::AutoLoad: + case FilamentAction::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 FilamentAction::UnLoad: + case FilamentAction::MmuUnLoad: lcd_puts_P(_i("Preheating to unload")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_mmuEject: + case FilamentAction::MmuEject: lcd_puts_P(_i("Preheating to eject")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_mmuCut: + case FilamentAction::MmuCut: lcd_puts_P(_i("Preheating to cut")); ////MSG_ c=20 r=1 break; - case e_FILAMENT_ACTION_none: + case FilamentAction::None: break; } lcd_set_cursor(0,3); @@ -2650,8 +2468,8 @@ else { setTargetBed((float)nTargetBedOld); } menu_back(); - if(eFilamentAction==e_FILAMENT_ACTION_autoLoad) - eFilamentAction=e_FILAMENT_ACTION_none; // i.e. non-autoLoad + if(eFilamentAction==FilamentAction::AutoLoad) + eFilamentAction=FilamentAction::None; // i.e. non-autoLoad } } } @@ -2696,8 +2514,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==FilamentAction::AutoLoad) + eFilamentAction=FilamentAction::None; // i.e. non-autoLoad } void mFilamentMenu() @@ -2728,7 +2546,7 @@ if(0) enquecommand_P(PSTR("M702")); // unload filament } else { - eFilamentAction=e_FILAMENT_ACTION_unLoad; + eFilamentAction=FilamentAction::UnLoad; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -2769,12 +2587,12 @@ void lcd_change_success() { } static void lcd_loading_progress_bar(uint16_t loading_time_ms) { - - for (int i = 0; i < 20; i++) { + + for (uint_least8_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 (uint_least8_t j = 0; j < 5; j++) { delay_keep_alive(loading_time_ms / 100); } } @@ -2880,10 +2698,12 @@ void lcd_alright() { if (cursor_pos > 3) { cursor_pos = 3; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); } if (cursor_pos < 1) { cursor_pos = 1; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); } lcd_set_cursor(0, 1); lcd_print(" "); @@ -2894,6 +2714,7 @@ void lcd_alright() { lcd_set_cursor(0, cursor_pos); lcd_print(">"); enc_dif = lcd_encoder_diff; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); _delay(100); } @@ -2901,7 +2722,7 @@ void lcd_alright() { if (lcd_clicked()) { - + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); lcd_change_fil_state = cursor_pos; _delay(500); @@ -2955,7 +2776,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 = CustomMsg::FilamentLoading; loading_flag = true; enquecommand_P(PSTR("M701")); //load filament SERIAL_ECHOLN("Loading filament"); @@ -2963,7 +2784,7 @@ if(0) } else { - eFilamentAction=e_FILAMENT_ACTION_Load; + eFilamentAction=FilamentAction::Load; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -3008,18 +2829,13 @@ void lcd_menu_statistics() const int _m = (_t - (_h * 3600ul)) / 60ul; const int _s = _t - ((_h * 3600ul) + (_m * 60ul)); + lcd_clear(); lcd_printf_P(_N( - ESC_2J - "%S:" - ESC_H(6,1) "%8.2fm \n" - "%S :" - ESC_H(8,3) "%2dh %02dm %02ds" - ), - _i("Filament used"), - _met, - _i("Print time"), - _h, _m, _s - ); + "%S:\n" + "%8.2fm\n" + "%S:\n" + "%2dh %02dm %02ds" + ),_i("Filament used"), _met, _i("Print time"), _h, _m, _s); menu_back_if_clicked_fb(); } else @@ -3035,18 +2851,13 @@ void lcd_menu_statistics() _hours = (_time - (_days * 1440)) / 60; _minutes = _time - ((_days * 1440) + (_hours * 60)); + lcd_clear(); lcd_printf_P(_N( - ESC_2J - "%S :" - ESC_H(9,1) "%8.2f m\n" - "%S :\n" - "%7ldd :%2hhdh :%02hhd m" - ), - _i("Total filament"), - _filament_m, - _i("Total print time"), - _days, _hours, _minutes - ); + "%S:\n" + "%8.2fm\n" + "%S:\n" + "%7ldd :%2hhdh :%02hhdm" + ), _i("Total filament"), _filament_m, _i("Total print time"), _days, _hours, _minutes); KEEPALIVE_STATE(PAUSED_FOR_USER); while (!lcd_clicked()) { @@ -3144,8 +2955,8 @@ static void lcd_menu_xyz_y_min() //---------------------- float distanceMin[2]; count_xyz_details(distanceMin); + lcd_home(); lcd_printf_P(_N( - ESC_H(0,0) "%S:\n" "%S\n" "%S:\n" @@ -3181,8 +2992,8 @@ static void lcd_menu_xyz_skew() //|Severe skew: 0.25d| //---------------------- float angleDiff = eeprom_read_float((float*)(EEPROM_XYZ_CAL_SKEW)); + lcd_home(); lcd_printf_P(_N( - ESC_H(0,0) "%S:\n" "%S\n" "%S: %5.2f\x01\n" @@ -3193,10 +3004,14 @@ static void lcd_menu_xyz_skew() _i("Slight skew"), _deg(bed_skew_angle_mild), _i("Severe skew"), _deg(bed_skew_angle_extreme) ); - if (angleDiff < 100) - lcd_printf_P(_N(ESC_H(15,0)"%4.2f\x01"), _deg(angleDiff)); - else - lcd_puts_P(_N(ESC_H(15,0)"N/A")); + if (angleDiff < 100){ + lcd_set_cursor(15,0); + lcd_printf_P(_N("%4.2f\x01"), _deg(angleDiff)); + } + else{ + lcd_set_cursor(15,0); + lcd_puts_P(_N("N/A")); + } if (lcd_clicked()) menu_goto(lcd_menu_xyz_offset, 0, true, true); } @@ -3216,7 +3031,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 (uint_least8_t i = 0; i < 2; i++) { lcd_puts_at_P(11, i + 2, PSTR("")); lcd_print(cntr[i]); @@ -3263,13 +3078,13 @@ static void lcd_move_z() { * other value leads to storing Z_AXIS * @param msg text to be displayed */ -static void _lcd_babystep(int axis, const char *msg) +static void lcd_babystep_z() { typedef struct - { // 19bytes total - int8_t status; // 1byte - int babystepMem[3]; // 6bytes - float babystepMemMM[3]; // 12bytes + { + int8_t status; + int16_t babystepMemZ; + float babystepMemMMZ; } _menu_data_t; static_assert(sizeof(menu_data)>= sizeof(_menu_data_t),"_menu_data_t doesn't fit into menu_data"); _menu_data_t* _md = (_menu_data_t*)&(menu_data[0]); @@ -3279,18 +3094,20 @@ static void _lcd_babystep(int axis, const char *msg) // Initialize its status. _md->status = 1; check_babystep(); - - EEPROM_read_B(EEPROM_BABYSTEP_X, &_md->babystepMem[0]); - EEPROM_read_B(EEPROM_BABYSTEP_Y, &_md->babystepMem[1]); - EEPROM_read_B(EEPROM_BABYSTEP_Z, &_md->babystepMem[2]); + + if(!is_sheet_initialized(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))){ + _md->babystepMemZ = 0; + } + else{ + _md->babystepMemZ = eeprom_read_word(reinterpret_cast(&(EEPROM_Sheets_base-> + s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset))); + } // same logic as in babystep_load if (calibration_status() >= CALIBRATION_STATUS_LIVE_ADJUST) - _md->babystepMem[2] = 0; + _md->babystepMemZ = 0; - _md->babystepMemMM[0] = _md->babystepMem[0]/cs.axis_steps_per_unit[X_AXIS]; - _md->babystepMemMM[1] = _md->babystepMem[1]/cs.axis_steps_per_unit[Y_AXIS]; - _md->babystepMemMM[2] = _md->babystepMem[2]/cs.axis_steps_per_unit[Z_AXIS]; + _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS]; lcd_draw_update = 1; //SERIAL_ECHO("Z baby step: "); //SERIAL_ECHO(_md->babystepMem[2]); @@ -3301,46 +3118,49 @@ static void _lcd_babystep(int axis, const char *msg) if (lcd_encoder != 0) { if (homing_flag) lcd_encoder = 0; - _md->babystepMem[axis] += (int)lcd_encoder; - if (axis == 2) - { - if (_md->babystepMem[axis] < Z_BABYSTEP_MIN) _md->babystepMem[axis] = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm - else if (_md->babystepMem[axis] > Z_BABYSTEP_MAX) _md->babystepMem[axis] = Z_BABYSTEP_MAX; //0 - else - { - CRITICAL_SECTION_START - babystepsTodo[axis] += (int)lcd_encoder; - CRITICAL_SECTION_END - } - } - _md->babystepMemMM[axis] = _md->babystepMem[axis]/cs.axis_steps_per_unit[axis]; + _md->babystepMemZ += (int)lcd_encoder; + + if (_md->babystepMemZ < Z_BABYSTEP_MIN) _md->babystepMemZ = Z_BABYSTEP_MIN; //-3999 -> -9.99 mm + else if (_md->babystepMemZ > Z_BABYSTEP_MAX) _md->babystepMemZ = Z_BABYSTEP_MAX; //0 + else + { + CRITICAL_SECTION_START + babystepsTodo[Z_AXIS] += (int)lcd_encoder; + CRITICAL_SECTION_END + } + + _md->babystepMemMMZ = _md->babystepMemZ/cs.axis_steps_per_unit[Z_AXIS]; _delay(50); lcd_encoder = 0; lcd_draw_update = 1; } if (lcd_draw_update) { + SheetFormatBuffer buffer; + menu_format_sheet_E(EEPROM_Sheets_base->s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))], buffer); + lcd_set_cursor(0, 0); + lcd_print(buffer.c); lcd_set_cursor(0, 1); - menu_draw_float13(msg, _md->babystepMemMM[axis]); + menu_draw_float13(_i("Adjusting Z:"), _md->babystepMemMMZ); ////MSG_BABYSTEPPING_Z c=15 Beware: must include the ':' as its last character } if (LCD_CLICKED || menu_leaving) { // Only update the EEPROM when leaving the menu. - EEPROM_save_B( - (axis == X_AXIS) ? EEPROM_BABYSTEP_X : ((axis == Y_AXIS) ? EEPROM_BABYSTEP_Y : EEPROM_BABYSTEP_Z), - &_md->babystepMem[axis]); - if(Z_AXIS == axis) calibration_status_store(CALIBRATION_STATUS_CALIBRATED); + eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base-> + s[(eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet)))].z_offset)), + _md->babystepMemZ); + eeprom_update_byte(&(EEPROM_Sheets_base->s[(eeprom_read_byte( + &(EEPROM_Sheets_base->active_sheet)))].bed_temp), + target_temperature_bed); + eeprom_update_byte(&(EEPROM_Sheets_base->s[(eeprom_read_byte( + &(EEPROM_Sheets_base->active_sheet)))].pinda_temp), + current_temperature_pinda); + calibration_status_store(CALIBRATION_STATUS_CALIBRATED); } if (LCD_CLICKED) menu_back(); } -static void lcd_babystep_z() -{ - _lcd_babystep(Z_AXIS, (_i("Adjusting Z:")));////MSG_BABYSTEPPING_Z c=15 Beware: must include the ':' as its last character -} - - typedef struct { // 12bytes + 9bytes = 21bytes total menu_data_edit_t reserved; //12 bytes reserved for number editing functions @@ -3412,7 +3232,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::PidExtruder; lcd_return_to_status(); lcd_update(2); } @@ -3858,20 +3678,24 @@ int8_t lcd_show_multiscreen_message_two_choices_and_wait_P(const char *msg, bool lcd_set_cursor(7, 3); lcd_puts_P((PSTR(">"))); yes = false; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); } else if (enc_dif > lcd_encoder_diff && !yes) { lcd_puts_P((PSTR(">"))); lcd_set_cursor(7, 3); lcd_puts_P((PSTR(" "))); yes = true; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); } enc_dif = lcd_encoder_diff; } else { + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); break; //turning knob skips waiting loop } } if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); if (msg_next == NULL) { //KEEPALIVE_STATE(IN_HANDLER); lcd_set_custom_characters(); @@ -3944,16 +3768,20 @@ int8_t lcd_show_fullscreen_message_yes_no_and_wait_P(const char *msg, bool allow lcd_set_cursor(0, 3); lcd_puts_P((PSTR(">"))); yes = false; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); + } else if (enc_dif > lcd_encoder_diff && !yes) { lcd_puts_P((PSTR(">"))); lcd_set_cursor(0, 3); lcd_puts_P((PSTR(" "))); yes = true; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); } enc_dif = lcd_encoder_diff; } if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); KEEPALIVE_STATE(IN_HANDLER); return yes; } @@ -4014,7 +3842,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 = CustomMsg::Status; disable_x(); disable_y(); disable_z(); @@ -4132,6 +3960,20 @@ 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(); +} + +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; @@ -4141,113 +3983,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; + { + prusa_statistics_case0(15); } else if (isPrintPaused || card.paused) { - SERIAL_ECHO("{"); - prusa_stat_printerstatus(14); - prusa_stat_farm_number(); - prusa_stat_printinfo(); - SERIAL_ECHOLN("}"); - status_number = 14; + prusa_statistics_case0(14); } - else if (IS_SD_PRINTING) + 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; + prusa_statistics_case0(4); } else { SERIAL_ECHO("{"); prusa_stat_printerstatus(1); prusa_stat_farm_number(); - SERIAL_ECHOLN("}"); + prusa_stat_diameter(); status_number = 1; } 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) + 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; @@ -4255,49 +4077,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 @@ -4305,11 +4116,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('}'); } @@ -4317,13 +4128,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(']'); } static void prusa_stat_temperatures() @@ -4336,7 +4153,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() @@ -4360,7 +4177,8 @@ static void prusa_stat_printinfo() } SERIAL_ECHO("][FWR:"); SERIAL_ECHO(FW_VERSION); - SERIAL_ECHO("]"); + SERIAL_ECHO(']'); + prusa_stat_diameter(); } /* @@ -4525,7 +4343,8 @@ static void lcd_crash_mode_info() static uint32_t tim = 0; if ((tim + 1000) < _millis()) { - fputs_P(_i("\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 + lcd_clear(); + fputs_P(_i("Crash detection can\nbe turned on only in\nNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 tim = _millis(); } menu_back_if_clicked(); @@ -4537,7 +4356,8 @@ static void lcd_crash_mode_info2() static uint32_t tim = 0; if ((tim + 1000) < _millis()) { - fputs_P(_i("\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 + lcd_clear(); + fputs_P(_i("WARNING:\nCrash detection\ndisabled in\nStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 tim = _millis(); } menu_back_if_clicked(); @@ -4635,7 +4455,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::Layer1Cal)) menu_goto(lcd_tune_menu, 9, true, true); else menu_goto(lcd_settings_menu, 9, true, true); } @@ -4866,25 +4686,26 @@ void lcd_toshiba_flash_air_compatibility_toggle() void lcd_v2_calibration() { + eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet); if (mmu_enabled) { const uint8_t filament = choose_menu_P(_i("Select PLA filament:"),_T(MSG_FILAMENT),_i("Cancel")); ////c=20 r=1 ////c=19 r=1 if (filament < 5) { lcd_commands_step = 20 + filament; - lcd_commands_type = LCD_COMMAND_V2_CAL; + lcd_commands_type = LcdCommands::Layer1Cal; } } 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::Layer1Cal; } 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 (uint_least8_t i = 0; i < 20; i++) { //wait max. 2s delay_keep_alive(100); if (lcd_clicked()) { break; @@ -4977,6 +4798,7 @@ static void lcd_wizard_load() if (mmu_enabled) { lcd_show_fullscreen_message_and_wait_P(_i("Please insert PLA filament to the first tube of MMU, then press the knob to load it."));////c=20 r=8 + tmp_extruder = 0; } else { @@ -5031,9 +4853,21 @@ void lcd_wizard(WizState state) int wizard_event; const char *msg = NULL; while (!end) { - printf_P(PSTR("Wizard state: %d"), state); + printf_P(PSTR("Wizard state: %d\n"), state); switch (state) { case S::Run: //Run wizard? + + // 2019-08-07 brutal hack - solving the "viper" situation. + // It is caused by the fact, that tmc2130_st_isr makes a crash detection before the printers really starts. + // And thus it calles stop_and_save_print_to_ram which sets the saved_printing flag. + // Having this flag set during normal printing is lethal - mesh_plan_buffer_line exist in the middle of planning long travels + // which results in distorted print. + // This primarily happens when the printer is new and parked in 0,0 + // So any new printer will fail the first layer calibration unless being reset or the Stop function gets called. + // We really must find a way to prevent the crash from happening before the printer is started - that would be the correct solution. + // Btw. the flag may even trigger the viper situation on normal start this way and the user won't be able to find out why. + saved_printing = false; + wizard_active = true; wizard_event = lcd_show_multiscreen_message_yes_no_and_wait_P(_i("Hi, I am your Original Prusa i3 printer. Would you like me to guide you through the setup process?"), false, true);////MSG_WIZARD_WELCOME c=20 r=7 if (wizard_event) { @@ -5139,7 +4973,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::Layer1Cal; lcd_return_to_status(); end = true; break; @@ -5460,8 +5294,8 @@ do\ case e_SOUND_MODE_SILENT:\ MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set);\ break;\ - case e_SOUND_MODE_MUTE:\ - MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set);\ + case e_SOUND_MODE_BLIND:\ + MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_BLIND),lcd_sound_state_set);\ break;\ default:\ MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set);\ @@ -5469,6 +5303,254 @@ do\ }\ while (0) +//-// +static void lcd_check_mode_set(void) +{ +switch(oCheckMode) + { + case ClCheckMode::_None: + oCheckMode=ClCheckMode::_Warn; + break; + case ClCheckMode::_Warn: + oCheckMode=ClCheckMode::_Strict; + break; + case ClCheckMode::_Strict: + oCheckMode=ClCheckMode::_None; + break; + default: + oCheckMode=ClCheckMode::_None; + } +eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode); +} + +#define SETTINGS_MODE \ +do\ +{\ + switch(oCheckMode)\ + {\ + case ClCheckMode::_None:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle [none]"),lcd_check_mode_set);\ + break;\ + case ClCheckMode::_Warn:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle [warn]"),lcd_check_mode_set);\ + break;\ + case ClCheckMode::_Strict:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle [strict]"),lcd_check_mode_set);\ + break;\ + default:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle [none]"),lcd_check_mode_set);\ + }\ +}\ +while (0) + +static void lcd_nozzle_diameter_set(void) +{ +uint16_t nDiameter; + +switch(oNozzleDiameter) + { + case ClNozzleDiameter::_Diameter_250: + oNozzleDiameter=ClNozzleDiameter::_Diameter_400; + nDiameter=400; + break; + case ClNozzleDiameter::_Diameter_400: + oNozzleDiameter=ClNozzleDiameter::_Diameter_600; + nDiameter=600; + break; + case ClNozzleDiameter::_Diameter_600: + oNozzleDiameter=ClNozzleDiameter::_Diameter_250; + nDiameter=250; + break; + default: + oNozzleDiameter=ClNozzleDiameter::_Diameter_400; + nDiameter=400; + } +eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter); +eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter); +} + +#define SETTINGS_NOZZLE \ +do\ +{\ + switch(oNozzleDiameter)\ + {\ + case ClNozzleDiameter::_Diameter_250:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle d. [0.25]"),lcd_nozzle_diameter_set);\ + break;\ + case ClNozzleDiameter::_Diameter_400:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle d. [0.40]"),lcd_nozzle_diameter_set);\ + break;\ + case ClNozzleDiameter::_Diameter_600:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle d. [0.60]"),lcd_nozzle_diameter_set);\ + break;\ + default:\ + MENU_ITEM_FUNCTION_P(_i("Nozzle d. [0.40]"),lcd_nozzle_diameter_set);\ + }\ +}\ +while (0) + +static void lcd_check_model_set(void) +{ +switch(oCheckModel) + { + case ClCheckModel::_None: + oCheckModel=ClCheckModel::_Warn; + break; + case ClCheckModel::_Warn: + oCheckModel=ClCheckModel::_Strict; + break; + case ClCheckModel::_Strict: + oCheckModel=ClCheckModel::_None; + break; + default: + oCheckModel=ClCheckModel::_None; + } +eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel); +} + +#define SETTINGS_MODEL \ +do\ +{\ + switch(oCheckModel)\ + {\ + case ClCheckModel::_None:\ + MENU_ITEM_FUNCTION_P(_i("Model [none]"),lcd_check_model_set);\ + break;\ + case ClCheckModel::_Warn:\ + MENU_ITEM_FUNCTION_P(_i("Model [warn]"),lcd_check_model_set);\ + break;\ + case ClCheckModel::_Strict:\ + MENU_ITEM_FUNCTION_P(_i("Model [strict]"),lcd_check_model_set);\ + break;\ + default:\ + MENU_ITEM_FUNCTION_P(_i("Model [none]"),lcd_check_model_set);\ + }\ +}\ +while (0) + +static void lcd_check_version_set(void) +{ +switch(oCheckVersion) + { + case ClCheckVersion::_None: + oCheckVersion=ClCheckVersion::_Warn; + break; + case ClCheckVersion::_Warn: + oCheckVersion=ClCheckVersion::_Strict; + break; + case ClCheckVersion::_Strict: + oCheckVersion=ClCheckVersion::_None; + break; + default: + oCheckVersion=ClCheckVersion::_None; + } +eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion); +} + +#define SETTINGS_VERSION \ +do\ +{\ + switch(oCheckVersion)\ + {\ + case ClCheckVersion::_None:\ + MENU_ITEM_FUNCTION_P(_i("Firmware [none]"),lcd_check_version_set);\ + break;\ + case ClCheckVersion::_Warn:\ + MENU_ITEM_FUNCTION_P(_i("Firmware [warn]"),lcd_check_version_set);\ + break;\ + case ClCheckVersion::_Strict:\ + MENU_ITEM_FUNCTION_P(_i("Firmware [strict]"),lcd_check_version_set);\ + break;\ + default:\ + MENU_ITEM_FUNCTION_P(_i("Firmware [none]"),lcd_check_version_set);\ + }\ +}\ +while (0) + +static void lcd_check_gcode_set(void) +{ +switch(oCheckGcode) + { + case ClCheckGcode::_None: + oCheckGcode=ClCheckGcode::_Warn; + break; + case ClCheckGcode::_Warn: + oCheckGcode=ClCheckGcode::_Strict; + break; + case ClCheckGcode::_Strict: + oCheckGcode=ClCheckGcode::_None; + break; + default: + oCheckGcode=ClCheckGcode::_None; + } +eeprom_update_byte((uint8_t*)EEPROM_CHECK_GCODE,(uint8_t)oCheckGcode); +} + +#define SETTINGS_GCODE \ +do\ +{\ + switch(oCheckGcode)\ + {\ + case ClCheckGcode::_None:\ + MENU_ITEM_FUNCTION_P(_i("Gcode [none]"),lcd_check_gcode_set);\ + break;\ + case ClCheckGcode::_Warn:\ + MENU_ITEM_FUNCTION_P(_i("Gcode [warn]"),lcd_check_gcode_set);\ + break;\ + case ClCheckGcode::_Strict:\ + MENU_ITEM_FUNCTION_P(_i("Gcode [strict]"),lcd_check_gcode_set);\ + break;\ + default:\ + MENU_ITEM_FUNCTION_P(_i("Gcode [none]"),lcd_check_gcode_set);\ + }\ +}\ +while (0) + +static void lcd_checking_menu(void) +{ +MENU_BEGIN(); +MENU_ITEM_BACK_P(_T(MSG_HW_SETUP)); +SETTINGS_MODE; +SETTINGS_MODEL; +SETTINGS_VERSION; +//-// temporarily disabled +//SETTINGS_GCODE; +MENU_END(); +} + +void lcd_hw_setup_menu(void) // can not be "static" +{ +MENU_BEGIN(); +MENU_ITEM_BACK_P(_T(bSettings?MSG_SETTINGS:MSG_BACK)); // i.e. default menu-item / menu-item after checking mismatch + +//strncpy(buffer,_i("Sheet"),sizeof(buffer)); +//strncpy(buffer,_i(" "),sizeof(buffer)); +//strncpy(buffer,EEPROM_Sheets_base->s[0].name,sizeof(buffer)); + +//const char* menu = EEPROM_Sheets_base->s[0].name.c_str(); + +//const char *b = new char(buffer); +//const char *b = const char *b = new char(buffer);(buffer); +//printf_P(_N("UVLO - end %d\n"), _millis() - time_start); +//SERIAL_ECHOPGM(buffer); +//SERIAL_ECHOPGM(reinterpret_cast(buffer)); +//SERIAL_ECHOPGM("lakdjushasdjaljsdakjsdn"); +//char* p = &buffer[0]; + +//MENU_ITEM_SUBMENU_P(reinterpret_cast(p),lcd_sheet_menu); + +//delete(b); + +MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[0], lcd_select_sheet_0_menu); +MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[1], lcd_select_sheet_1_menu); +MENU_ITEM_SUBMENU_E(EEPROM_Sheets_base->s[2], lcd_select_sheet_2_menu); + +SETTINGS_NOZZLE; +MENU_ITEM_SUBMENU_P(_i("Checks"), lcd_checking_menu); + +MENU_END(); +} + static void lcd_settings_menu() { EEPROM_read(EEPROM_SILENT, (uint8_t*)&SilentModeMenu, sizeof(SilentModeMenu)); @@ -5493,6 +5575,13 @@ static void lcd_settings_menu() MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1 SETTINGS_SILENT_MODE; + + if(!farm_mode) + { + bSettings=true; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function + MENU_ITEM_SUBMENU_P(_i("HW Setup"), lcd_hw_setup_menu);////MSG_HW_SETUP + } + SETTINGS_MMU_MODE; MENU_ITEM_SUBMENU_P(_i("Mesh bed leveling"), lcd_mesh_bed_leveling_settings);////MSG_MBL_SETTINGS c=18 r=1 @@ -5566,7 +5655,7 @@ static void lcd_calibration_menu() if (!isPrintPaused) { MENU_ITEM_FUNCTION_P(_i("Wizard"), lcd_wizard);////MSG_WIZARD c=17 r=1 - MENU_ITEM_SUBMENU_P(_i("First layer cal."), lcd_v2_calibration);////MSG_V2_CALIBRATION c=17 r=1 + MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_v2_calibration); MENU_ITEM_GCODE_P(_T(MSG_AUTO_HOME), PSTR("G28 W")); MENU_ITEM_FUNCTION_P(_i("Selftest "), lcd_selftest_v);////MSG_SELFTEST #ifdef MK1BP @@ -5611,7 +5700,7 @@ void bowden_menu() { lcd_clear(); lcd_set_cursor(0, 0); lcd_print(">"); - for (int i = 0; i < 4; i++) { + for (uint_least8_t i = 0; i < 4; i++) { lcd_set_cursor(1, i); lcd_print("Extruder "); lcd_print(i); @@ -5639,10 +5728,12 @@ void bowden_menu() { if (cursor_pos > 3) { cursor_pos = 3; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); } if (cursor_pos < 0) { cursor_pos = 0; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); } lcd_set_cursor(0, 0); @@ -5655,13 +5746,13 @@ void bowden_menu() { lcd_print(" "); lcd_set_cursor(0, cursor_pos); lcd_print(">"); - + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); enc_dif = lcd_encoder_diff; _delay(100); } if (lcd_clicked()) { - + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); lcd_clear(); while (1) { @@ -5692,6 +5783,7 @@ void bowden_menu() { } _delay(100); if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); EEPROM_save_B(EEPROM_BOWDEN_LENGTH + cursor_pos * 2, &bowden_length[cursor_pos]); if (lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Continue with another bowden?"))) { lcd_update_enable(true); @@ -5699,7 +5791,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 (uint_least8_t i = 0; i < 4; i++) { lcd_set_cursor(1, i); lcd_print("Extruder "); lcd_print(i); @@ -5737,8 +5829,14 @@ static char snmm_stop_print_menu() { //menu for choosing which filaments will be if ((abs(enc_dif - lcd_encoder_diff)) > 1) { if (enc_dif > lcd_encoder_diff) cursor_pos--; if (enc_dif < lcd_encoder_diff) cursor_pos++; - if (cursor_pos > 3) cursor_pos = 3; - if (cursor_pos < 1) cursor_pos = 1; + if (cursor_pos > 3) { + cursor_pos = 3; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); + } + if (cursor_pos < 1){ + cursor_pos = 1; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); + } lcd_set_cursor(0, 1); lcd_print(" "); @@ -5749,10 +5847,12 @@ static char snmm_stop_print_menu() { //menu for choosing which filaments will be lcd_set_cursor(0, cursor_pos); lcd_print(">"); enc_dif = lcd_encoder_diff; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); _delay(100); } } if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); KEEPALIVE_STATE(IN_HANDLER); return(cursor_pos - 1); } @@ -5804,7 +5904,8 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite } if (cursor_pos > 3) - { + { + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); cursor_pos = 3; if (first < items_no - 3) { @@ -5815,6 +5916,7 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite if (cursor_pos < 1) { + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); cursor_pos = 1; if (first > 0) { @@ -5826,14 +5928,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 uint_least8_t ordinary_items = (last_item&&last_visible)?2:3; - for (int i = 0; i < ordinary_items; i++) + for (uint_least8_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 (uint_least8_t i = 0; i < ordinary_items; i++) { lcd_set_cursor(2 + item_len, i+1); lcd_print(first + i + 1); @@ -5849,11 +5951,12 @@ uint8_t choose_menu_P(const char *header, const char *item, const char *last_ite lcd_print(" "); lcd_set_cursor(0, cursor_pos); lcd_print(">"); - + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); _delay(100); if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); KEEPALIVE_STATE(IN_HANDLER); lcd_encoder_diff = 0; return(cursor_pos + first - 1); @@ -5887,7 +5990,7 @@ char reset_menu() { lcd_consume_click(); while (1) { - for (int i = 0; i < 4; i++) { + for (uint_least8_t i = 0; i < 4; i++) { lcd_set_cursor(1, i); lcd_print(item[first + i]); } @@ -5908,6 +6011,7 @@ char reset_menu() { if (cursor_pos > 3) { cursor_pos = 3; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); if (first < items_no - 4) { first++; lcd_clear(); @@ -5916,6 +6020,7 @@ char reset_menu() { if (cursor_pos < 0) { cursor_pos = 0; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); if (first > 0) { first--; lcd_clear(); @@ -5931,6 +6036,7 @@ char reset_menu() { lcd_print(" "); lcd_set_cursor(0, cursor_pos); lcd_print(">"); + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); enc_dif = lcd_encoder_diff; _delay(100); } @@ -5938,6 +6044,7 @@ char reset_menu() { } if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); return(cursor_pos + first); } @@ -5992,7 +6099,7 @@ static void mmu_load_to_nozzle_menu() } else { - eFilamentAction = e_FILAMENT_ACTION_mmuLoad; + eFilamentAction = FilamentAction::MmuLoad; bFilamentFirstRun = false; if (target_temperature[0] >= EXTRUDE_MINTEMP) { @@ -6024,7 +6131,7 @@ static void mmu_fil_eject_menu() } else { - eFilamentAction = e_FILAMENT_ACTION_mmuEject; + eFilamentAction = FilamentAction::MmuEject; bFilamentFirstRun = false; if (target_temperature[0] >= EXTRUDE_MINTEMP) { @@ -6052,7 +6159,7 @@ static void mmu_cut_filament_menu() } else { - eFilamentAction=e_FILAMENT_ACTION_mmuCut; + eFilamentAction=FilamentAction::MmuCut; bFilamentFirstRun=false; if(target_temperature[0]>=EXTRUDE_MINTEMP) { @@ -6097,7 +6204,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 = CustomMsg::FilamentLoading; lcd_setstatuspgm(_T(MSG_UNLOADING_FILAMENT)); // extr_unload2(); @@ -6132,7 +6239,7 @@ void unload_filament() lcd_update_enable(true); lcd_setstatuspgm(_T(WELCOME_MSG)); - custom_message_type = CUSTOM_MSG_TYPE_STATUS; + custom_message_type = CustomMsg::Status; } @@ -6213,7 +6320,7 @@ unsigned char lcd_choose_color() { item[0] = "Orange"; item[1] = "Black"; //----------------------------------------------------- - unsigned char active_rows; + uint_least8_t active_rows; static int first = 0; int enc_dif = 0; unsigned char cursor_pos = 1; @@ -6226,7 +6333,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 (uint_least8_t i = 0; i < active_rows; i++) { lcd_set_cursor(1, i+1); lcd_print(item[first + i]); } @@ -6246,6 +6353,7 @@ unsigned char lcd_choose_color() { if (cursor_pos > active_rows) { cursor_pos = active_rows; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); if (first < items_no - active_rows) { first++; lcd_clear(); @@ -6254,6 +6362,7 @@ unsigned char lcd_choose_color() { if (cursor_pos < 1) { cursor_pos = 1; + Sound_MakeSound(e_SOUND_TYPE_BlindAlert); if (first > 0) { first--; lcd_clear(); @@ -6267,12 +6376,14 @@ unsigned char lcd_choose_color() { lcd_print(" "); lcd_set_cursor(0, cursor_pos); lcd_print(">"); + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); enc_dif = lcd_encoder_diff; _delay(100); } if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); switch(cursor_pos + first - 1) { case 0: return 1; break; case 1: return 0; break; @@ -6332,10 +6443,11 @@ void lcd_confirm_print() } if (lcd_clicked()) { + filament_type = FARM_FILAMENT_COLOR_NONE; if (cursor_pos == 1) { _ret = 1; - filament_type = lcd_choose_color(); +// filament_type = lcd_choose_color(); prusa_statistics(4, filament_type); no_response = true; //we need confirmation by recieving PRUSA thx important_status = 4; @@ -6345,7 +6457,7 @@ void lcd_confirm_print() if (cursor_pos == 2) { _ret = 2; - filament_type = lcd_choose_color(); +// filament_type = lcd_choose_color(); prusa_statistics(5, filament_type); no_response = true; //we need confirmation by recieving PRUSA thx important_status = 5; @@ -6389,6 +6501,128 @@ void lcd_resume_print() isPrintPaused = false; } +static void change_sheet() +{ + eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), selected_sheet); + menu_back(3); +} + +static void change_sheet_from_menu(){ + uint8_t next_sheet = eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))+1; + while(true){ + if(next_sheet > 2) next_sheet = 0; + if(is_sheet_initialized(next_sheet)){ + eeprom_update_byte(&(EEPROM_Sheets_base->active_sheet), next_sheet); + selected_sheet = next_sheet; + break; + } + else if (next_sheet == selected_sheet){ + break; + } + else{ + next_sheet++; + } + } + menu_back(); +} + +static void lcd_select_sheet_0_menu() +{ + selected_sheet = 0; + lcd_sheet_menu(); +} +static void lcd_select_sheet_1_menu() +{ + selected_sheet = 1; + lcd_sheet_menu(); +} +static void lcd_select_sheet_2_menu() +{ + selected_sheet = 2; + lcd_sheet_menu(); +} + +static void lcd_rename_sheet_menu() +{ + struct MenuData + { + bool initialized; + uint8_t selected; + char name[sizeof(Sheet::name)]; + }; + static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data"); + MenuData* menuData = (MenuData*)&(menu_data[0]); + + if (!menuData->initialized) + { + eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name)); + lcd_encoder = menuData->name[0]; + menuData->initialized = true; + } + if (lcd_encoder < '\x20') lcd_encoder = '\x20'; + if (lcd_encoder > '\x7F') lcd_encoder = '\x7F'; + + menuData->name[menuData->selected] = lcd_encoder; + lcd_set_cursor(0,0); + for (uint_least8_t i = 0; i < sizeof(Sheet::name); ++i) + { + lcd_putc(menuData->name[i]); + } + lcd_set_cursor(menuData->selected, 1); + lcd_putc('^'); + if (lcd_clicked()) + { + if ((menuData->selected + 1u) < sizeof(Sheet::name)) + { + lcd_encoder = menuData->name[++(menuData->selected)]; + } + else + { + eeprom_update_block(menuData->name, + EEPROM_Sheets_base->s[selected_sheet].name, + sizeof(Sheet::name)); + menu_back(); + } + } +} + +static void lcd_reset_sheet() +{ + struct MenuData + { + bool initialized; + uint8_t selected; + char name[sizeof(Sheet::name)]; + }; + static_assert(sizeof(menu_data)>= sizeof(MenuData),"MenuData doesn't fit into menu_data"); + MenuData* menuData = (MenuData*)&(menu_data[0]); + eeprom_read_block(menuData->name, EEPROM_Sheets_base->s[selected_sheet].name, sizeof(Sheet::name)); + + menuData->initialized = false; + strcpy_P(menuData->name, (char *)pgm_read_word(&(defaultSheetNames[selected_sheet]))); + + + eeprom_update_word(reinterpret_cast(&(EEPROM_Sheets_base->s[selected_sheet].z_offset)),0xffff); + eeprom_update_block(menuData->name,EEPROM_Sheets_base->s[selected_sheet].name,sizeof(Sheet::name)); + menu_back(2); +} + +static void lcd_sheet_menu() +{ + MENU_BEGIN(); + MENU_ITEM_BACK_P(_T(MSG_HW_SETUP)); + + if(is_sheet_initialized(selected_sheet)){ + MENU_ITEM_SUBMENU_P(_i("Select"), change_sheet); //// c=18 + } + + MENU_ITEM_SUBMENU_P(_T(MSG_V2_CALIBRATION), lcd_v2_calibration); + MENU_ITEM_SUBMENU_P(_i("Rename"), lcd_rename_sheet_menu); //// c=18 + MENU_ITEM_SUBMENU_P(_i("Reset"), lcd_reset_sheet); //// c=18 + + MENU_END(); +} + static void lcd_main_menu() { @@ -6410,63 +6644,14 @@ static void lcd_main_menu() MENU_ITEM_FUNCTION_P(PSTR("recover print"), recover_print); MENU_ITEM_FUNCTION_P(PSTR("power panic"), uvlo_); #endif //TMC2130_DEBUG - - /* if (farm_mode && !IS_SD_PRINTING ) - { - - int tempScrool = 0; - if (lcd_draw_update == 0 && LCD_CLICKED == 0) - //_delay(100); - return; // nothing to do (so don't thrash the SD card) - uint16_t fileCnt = card.getnrfilenames(); - - card.getWorkDirName(); - if (card.filename[0] == '/') - { -#if SDCARDDETECT == -1 - MENU_ITEM_FUNCTION_P(_T(MSG_REFRESH), lcd_sd_refresh); -#endif - } else { - MENU_ITEM_FUNCTION_P(PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); - } - - for (uint16_t i = 0; i < fileCnt; i++) - { - if (menu_item == menu_line) - { -#ifndef SDCARD_RATHERRECENTFIRST - card.getfilename(i); -#else - card.getfilename(fileCnt - 1 - i); -#endif - if (card.filenameIsDir) - { - MENU_ITEM_SDDIR(_T(MSG_CARD_MENU), card.filename, card.longFilename); - } else { - - MENU_ITEM_SDFILE(_T(MSG_CARD_MENU), card.filename, card.longFilename); - - - - - } - } else { - MENU_ITEM_DUMMY(); - } - } - - MENU_ITEM_BACK_P(PSTR("- - - - - - - - -")); - - - }*/ - 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::Layer1Cal)) && (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::Layer1Cal)) { MENU_ITEM_SUBMENU_P(_i("Tune"), lcd_tune_menu);////MSG_TUNE } else @@ -6474,8 +6659,10 @@ static void lcd_main_menu() MENU_ITEM_SUBMENU_P(_i("Preheat"), lcd_preheat_menu);////MSG_PREHEAT } + + #ifdef SDSUPPORT - if (card.cardOK || lcd_commands_type == LCD_COMMAND_V2_CAL) + if (card.cardOK || lcd_commands_type == LcdCommands::Layer1Cal) { if (card.isFileOpen()) { @@ -6498,12 +6685,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::Layer1Cal && 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::Layer1Cal)) { //if (farm_mode) MENU_ITEM_SUBMENU_P(MSG_FARM_CARD_MENU, lcd_farm_sdcard_menu); /*else*/ { @@ -6527,7 +6714,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::Layer1Cal)) { if (farm_mode) { @@ -6571,7 +6758,15 @@ static void lcd_main_menu() } - if (!is_usb_printing && (lcd_commands_type != LCD_COMMAND_V2_CAL)) + if(!isPrintPaused && !IS_SD_PRINTING && !is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) + { + if (!farm_mode) + { + MENU_ITEM_SUBMENU_SELECT_SHEET_E(EEPROM_Sheets_base->s[eeprom_read_byte(&(EEPROM_Sheets_base->active_sheet))], change_sheet_from_menu); + } + } + + if (!is_usb_printing && (lcd_commands_type != LcdCommands::Layer1Cal)) { MENU_ITEM_SUBMENU_P(_i("Statistics "), lcd_menu_statistics);////MSG_STATISTICS } @@ -6592,11 +6787,7 @@ static void lcd_main_menu() } void stack_error() { - SET_OUTPUT(BEEPER); -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)||(eSoundMode==e_SOUND_MODE_SILENT)) - WRITE(BEEPER, HIGH); - _delay(1000); - WRITE(BEEPER, LOW); + Sound_MakeCustom(1000,0,true); lcd_display_message_fullscreen_P(_i("Error - static memory has been overwritten"));////MSG_STACK_ERROR c=20 r=4 //err_triggered = 1; while (1) delay_keep_alive(1000); @@ -6626,8 +6817,8 @@ void stepper_timer_overflow() { static void lcd_colorprint_change() { enquecommand_P(PSTR("M600")); - - custom_message_type = CUSTOM_MSG_TYPE_F_LOAD; //just print status message + + custom_message_type = CustomMsg::FilamentLoading; //just print status message lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS)); lcd_return_to_status(); lcd_draw_update = 3; @@ -6688,6 +6879,14 @@ static void lcd_tune_menu() SETTINGS_CUTTER; + if(farm_mode) + { + if (fans_check_enabled == true) + MENU_ITEM_FUNCTION_P(_i("Fans check [on]"), lcd_set_fan_check);////MSG_FANS_CHECK_ON c=17 r=1 + else + MENU_ITEM_FUNCTION_P(_i("Fans check [off]"), lcd_set_fan_check);////MSG_FANS_CHECK_OFF c=17 r=1 + } + #ifdef TMC2130 if(!farm_mode) { @@ -6723,8 +6922,8 @@ static void lcd_tune_menu() case e_SOUND_MODE_SILENT: MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_SILENT),lcd_sound_state_set); break; - case e_SOUND_MODE_MUTE: - MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_MUTE),lcd_sound_state_set); + case e_SOUND_MODE_BLIND: + MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_BLIND),lcd_sound_state_set); break; default: MENU_ITEM_FUNCTION_P(_i(MSG_SOUND_MODE_LOUD),lcd_sound_state_set); @@ -6831,6 +7030,11 @@ static void lcd_sd_updir() void lcd_print_stop() { +//-// + if(!card.sdprinting) + { + SERIAL_ECHOLNPGM("// action:cancel"); // for Octoprint + } saved_printing = false; cancel_heatup = true; #ifdef MESH_BED_LEVELING @@ -6856,7 +7060,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::StopPrint; // Turn off the print fan SET_OUTPUT(FAN_PIN); WRITE(FAN_PIN, 0); @@ -6883,6 +7087,7 @@ void lcd_sdcard_stop() if (lcd_clicked()) { + Sound_MakeSound(e_SOUND_TYPE_ButtonEcho); if ((int32_t)lcd_encoder == 1) { lcd_return_to_status(); @@ -6969,13 +7174,13 @@ bool lcd_selftest() _delay(2000); KEEPALIVE_STATE(IN_HANDLER); - _progress = lcd_selftest_screen(testScreen::extruderFan, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(TestScreen::ExtruderFan, _progress, 3, true, 2000); #if (defined(FANCHECK) && defined(TACH_0)) switch (lcd_selftest_fan_auto(0)){ // check extruder Fan - case FanCheck::extruderFan: + case FanCheck::ExtruderFan: _result = false; break; - case FanCheck::swappedFan: + case FanCheck::SwappedFan: _swapped_fan = true; // no break default: @@ -6987,18 +7192,18 @@ bool lcd_selftest() #endif //defined(TACH_0) if (!_result) { - lcd_selftest_error(TestError::extruderFan, "", ""); + lcd_selftest_error(TestError::ExtruderFan, "", ""); } if (_result) { - _progress = lcd_selftest_screen(testScreen::printFan, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(TestScreen::PrintFan, _progress, 3, true, 2000); #if (defined(FANCHECK) && defined(TACH_1)) switch (lcd_selftest_fan_auto(1)){ // check print fan - case FanCheck::printFan: + case FanCheck::PrintFan: _result = false; break; - case FanCheck::swappedFan: + case FanCheck::SwappedFan: _swapped_fan = true; // no break default: @@ -7010,7 +7215,7 @@ bool lcd_selftest() #endif //defined(TACH_1) if (!_result) { - lcd_selftest_error(TestError::printFan, "", ""); //print fan not spinning + lcd_selftest_error(TestError::PrintFan, "", ""); //print fan not spinning } } @@ -7021,18 +7226,18 @@ bool lcd_selftest() //print fan is stil turned on; check that it is spinning _result = lcd_selftest_manual_fan_check(1, false, true); if (!_result){ - lcd_selftest_error(TestError::printFan, "", ""); + lcd_selftest_error(TestError::PrintFan, "", ""); } } else { // fans are swapped - lcd_selftest_error(TestError::swappedFan, "", ""); + lcd_selftest_error(TestError::SwappedFan, "", ""); } } if (_result) { - _progress = lcd_selftest_screen(testScreen::fansOk, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(TestScreen::FansOk, _progress, 3, true, 2000); #ifndef TMC2130 _result = lcd_selfcheck_endstops(); #else @@ -7043,7 +7248,7 @@ bool lcd_selftest() if (_result) { //current_position[Z_AXIS] += 15; //move Z axis higher to avoid false triggering of Z end stop in case that we are very low - just above heatbed - _progress = lcd_selftest_screen(testScreen::axisX, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 2000); #ifdef TMC2130 _result = lcd_selfcheck_axis_sg(X_AXIS); #else @@ -7056,7 +7261,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(testScreen::axisX, _progress, 3, true, 0); + _progress = lcd_selftest_screen(TestScreen::AxisX, _progress, 3, true, 0); #ifndef TMC2130 _result = lcd_selfcheck_pulleys(X_AXIS); @@ -7066,7 +7271,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(testScreen::axisY, _progress, 3, true, 1500); + _progress = lcd_selftest_screen(TestScreen::AxisY, _progress, 3, true, 1500); #ifdef TMC2130 _result = lcd_selfcheck_axis_sg(Y_AXIS); #else @@ -7076,7 +7281,7 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(testScreen::axisZ, _progress, 3, true, 0); + _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 0); #ifndef TMC2130 _result = lcd_selfcheck_pulleys(Y_AXIS); #endif // TMC2130 @@ -7097,7 +7302,7 @@ bool lcd_selftest() current_position[Z_AXIS] = current_position[Z_AXIS] + 10; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder); st_synchronize(); - _progress = lcd_selftest_screen(testScreen::axisZ, _progress, 3, true, 1500); + _progress = lcd_selftest_screen(TestScreen::AxisZ, _progress, 3, true, 1500); _result = lcd_selfcheck_axis(2, Z_MAX_POS); if (eeprom_read_byte((uint8_t*)EEPROM_WIZARD_ACTIVE) != 1) { enquecommand_P(PSTR("G28 W")); @@ -7111,11 +7316,11 @@ bool lcd_selftest() current_position[Z_AXIS] = current_position[Z_AXIS] + 10; plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder); st_synchronize(); - _progress = lcd_selftest_screen(testScreen::home, 0, 2, true, 0); + _progress = lcd_selftest_screen(TestScreen::Home, 0, 2, true, 0); bool bres = tmc2130_home_calibrate(X_AXIS); - _progress = lcd_selftest_screen(testScreen::home, 1, 2, true, 0); + _progress = lcd_selftest_screen(TestScreen::Home, 1, 2, true, 0); bres &= tmc2130_home_calibrate(Y_AXIS); - _progress = lcd_selftest_screen(testScreen::home, 2, 2, true, 0); + _progress = lcd_selftest_screen(TestScreen::Home, 2, 2, true, 0); if (bres) eeprom_update_byte((uint8_t*)EEPROM_TMC2130_HOME_ENABLED, 1); _result = bres; @@ -7124,18 +7329,18 @@ bool lcd_selftest() if (_result) { - _progress = lcd_selftest_screen(testScreen::bed, _progress, 3, true, 2000); + _progress = lcd_selftest_screen(TestScreen::Bed, _progress, 3, true, 2000); _result = lcd_selfcheck_check_heater(true); } if (_result) { - _progress = lcd_selftest_screen(testScreen::hotend, _progress, 3, true, 1000); + _progress = lcd_selftest_screen(TestScreen::Hotend, _progress, 3, true, 1000); _result = lcd_selfcheck_check_heater(false); } if (_result) { - _progress = lcd_selftest_screen(testScreen::hotendOk, _progress, 3, true, 2000); //nozzle ok + _progress = lcd_selftest_screen(TestScreen::HotendOk, _progress, 3, true, 2000); //nozzle ok } #ifdef FILAMENT_SENSOR if (_result) @@ -7143,20 +7348,20 @@ bool lcd_selftest() if (mmu_enabled) { - _progress = lcd_selftest_screen(testScreen::fsensor, _progress, 3, true, 2000); //check filaments sensor + _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor _result = selftest_irsensor(); if (_result) { - _progress = lcd_selftest_screen(testScreen::fsensorOk, _progress, 3, true, 2000); //fil sensor OK + _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK } } else { #ifdef PAT9125 - _progress = lcd_selftest_screen(testScreen::fsensor, _progress, 3, true, 2000); //check filaments sensor + _progress = lcd_selftest_screen(TestScreen::Fsensor, _progress, 3, true, 2000); //check filaments sensor _result = lcd_selftest_fsensor(); if (_result) { - _progress = lcd_selftest_screen(testScreen::fsensorOk, _progress, 3, true, 2000); //fil sensor OK + _progress = lcd_selftest_screen(TestScreen::FsensorOk, _progress, 3, true, 2000); //fil sensor OK } #endif //PAT9125 } @@ -7164,11 +7369,11 @@ bool lcd_selftest() #endif //FILAMENT_SENSOR if (_result) { - _progress = lcd_selftest_screen(testScreen::allCorrect, _progress, 3, true, 5000); //all correct + _progress = lcd_selftest_screen(TestScreen::AllCorrect, _progress, 3, true, 5000); //all correct } else { - _progress = lcd_selftest_screen(testScreen::failed, _progress, 3, true, 5000); + _progress = lcd_selftest_screen(TestScreen::Failed, _progress, 3, true, 5000); } lcd_reset_alert_level(); enquecommand_P(PSTR("M84")); @@ -7271,7 +7476,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(uint_least8_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); @@ -7282,7 +7487,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(TestError::axis, _error_1, ""); + lcd_selftest_error(TestError::Axis, _error_1, ""); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -7300,7 +7505,7 @@ static bool lcd_selfcheck_axis_sg(unsigned char axis) { if (axis == Y_AXIS) _error_1 = "Y"; if (axis == Z_AXIS) _error_1 = "Z"; - lcd_selftest_error(TestError::pulley, _error_1, ""); + lcd_selftest_error(TestError::Pulley, _error_1, ""); current_position[axis] = 0; plan_set_position(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[E_AXIS]); reset_crash_det(axis); @@ -7375,7 +7580,7 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) } else { - _progress = lcd_selftest_screen(static_cast(static_cast(testScreen::axisX) + _axis), _progress, 3, false, 0); + _progress = lcd_selftest_screen(static_cast(static_cast(TestScreen::AxisX) + _axis), _progress, 3, false, 0); _lcd_refresh = 0; } @@ -7407,11 +7612,11 @@ static bool lcd_selfcheck_axis(int _axis, int _travel) if (_travel_done >= _travel) { - lcd_selftest_error(TestError::endstop, _error_1, _error_2); + lcd_selftest_error(TestError::Endstop, _error_1, _error_2); } else { - lcd_selftest_error(TestError::motor, _error_1, _error_2); + lcd_selftest_error(TestError::Motor, _error_1, _error_2); } } @@ -7451,7 +7656,7 @@ static bool lcd_selfcheck_pulleys(int axis) st_synchronize(); if (((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) || ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1)) { - lcd_selftest_error(TestError::pulley, (axis == 0) ? "X" : "Y", ""); + lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", ""); return(false); } } @@ -7469,7 +7674,7 @@ static bool lcd_selfcheck_pulleys(int axis) return(true); } else { - lcd_selftest_error(TestError::pulley, (axis == 0) ? "X" : "Y", ""); + lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", ""); return(false); } } @@ -7478,7 +7683,7 @@ static bool lcd_selfcheck_pulleys(int axis) plan_buffer_line(current_position[X_AXIS], current_position[Y_AXIS], current_position[Z_AXIS], current_position[3], manual_feedrate[0] / 60, active_extruder); st_synchronize(); if (_millis() > timeout_counter) { - lcd_selftest_error(TestError::pulley, (axis == 0) ? "X" : "Y", ""); + lcd_selftest_error(TestError::Pulley, (axis == 0) ? "X" : "Y", ""); return(false); } } @@ -7511,7 +7716,7 @@ static bool lcd_selfcheck_endstops() if ((READ(X_MIN_PIN) ^ X_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "X"); if ((READ(Y_MIN_PIN) ^ Y_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Y"); if ((READ(Z_MIN_PIN) ^ Z_MIN_ENDSTOP_INVERTING) == 1) strcat(_error, "Z"); - lcd_selftest_error(TestError::endstops, _error, ""); + lcd_selftest_error(TestError::Endstops, _error, ""); } manage_heater(); manage_inactivity(true); @@ -7542,7 +7747,7 @@ static bool lcd_selfcheck_check_heater(bool _isbed) manage_heater(); manage_inactivity(true); - _progress = (_isbed) ? lcd_selftest_screen(testScreen::bed, _progress, 2, false, 400) : lcd_selftest_screen(testScreen::hotend, _progress, 2, false, 400); + _progress = (_isbed) ? lcd_selftest_screen(TestScreen::Bed, _progress, 2, false, 400) : lcd_selftest_screen(TestScreen::Hotend, _progress, 2, false, 400); /*if (_isbed) { MYSERIAL.print("Bed temp:"); MYSERIAL.println(degBed()); @@ -7577,12 +7782,12 @@ static bool lcd_selfcheck_check_heater(bool _isbed) } else { - lcd_selftest_error(TestError::heater, "", ""); + lcd_selftest_error(TestError::Heater, "", ""); } } else { - lcd_selftest_error(TestError::bed, "", ""); + lcd_selftest_error(TestError::Bed, "", ""); } manage_heater(); @@ -7609,19 +7814,19 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const switch (testError) { - case TestError::heater: + case TestError::Heater: lcd_set_cursor(0, 2); lcd_puts_P(_i("Heater/Thermistor"));////MSG_SELFTEST_HEATERTHERMISTOR lcd_set_cursor(0, 3); lcd_puts_P(_i("Not connected"));////MSG_SELFTEST_NOTCONNECTED break; - case TestError::bed: + case TestError::Bed: lcd_set_cursor(0, 2); lcd_puts_P(_i("Bed / Heater"));////MSG_SELFTEST_BEDHEATER lcd_set_cursor(0, 3); lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR)); break; - case TestError::endstops: + case TestError::Endstops: lcd_set_cursor(0, 2); lcd_puts_P(_i("Endstops"));////MSG_SELFTEST_ENDSTOPS lcd_set_cursor(0, 3); @@ -7629,7 +7834,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(17, 3); lcd_print(_error_1); break; - case TestError::motor: + case TestError::Motor: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_MOTOR)); lcd_set_cursor(18, 2); @@ -7639,7 +7844,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(18, 3); lcd_print(_error_2); break; - case TestError::endstop: + case TestError::Endstop: lcd_set_cursor(0, 2); lcd_puts_P(_i("Endstop not hit"));////MSG_SELFTEST_ENDSTOP_NOTHIT c=20 r=1 lcd_set_cursor(0, 3); @@ -7647,7 +7852,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case TestError::printFan: + case TestError::PrintFan: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_COOLING_FAN)); lcd_set_cursor(0, 3); @@ -7655,7 +7860,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case TestError::extruderFan: + case TestError::ExtruderFan: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_EXTRUDER_FAN)); lcd_set_cursor(0, 3); @@ -7663,7 +7868,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case TestError::pulley: + case TestError::Pulley: lcd_set_cursor(0, 2); lcd_puts_P(_i("Loose pulley"));////MSG_LOOSE_PULLEY c=20 r=1 lcd_set_cursor(0, 3); @@ -7671,7 +7876,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case TestError::axis: + case TestError::Axis: lcd_set_cursor(0, 2); lcd_puts_P(_i("Axis length"));////MSG_SELFTEST_AXIS_LENGTH lcd_set_cursor(0, 3); @@ -7679,7 +7884,7 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case TestError::swappedFan: + case TestError::SwappedFan: lcd_set_cursor(0, 2); lcd_puts_P(_i("Front/left fans"));////MSG_SELFTEST_FANS lcd_set_cursor(0, 3); @@ -7687,13 +7892,13 @@ static void lcd_selftest_error(TestError testError, const char *_error_1, const lcd_set_cursor(18, 3); lcd_print(_error_1); break; - case TestError::wiringFsensor: + case TestError::WiringFsensor: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_FILAMENT_SENSOR)); lcd_set_cursor(0, 3); lcd_puts_P(_T(MSG_SELFTEST_WIRINGERROR)); break; - case TestError::triggeringFsensor: + case TestError::TriggeringFsensor: lcd_set_cursor(0, 2); lcd_puts_P(_T(MSG_SELFTEST_FILAMENT_SENSOR)); lcd_set_cursor(0, 3); @@ -7722,7 +7927,7 @@ static bool lcd_selftest_fsensor(void) fsensor_init(); if (fsensor_not_responding) { - lcd_selftest_error(TestError::wiringFsensor, "", ""); + lcd_selftest_error(TestError::WiringFsensor, "", ""); } return (!fsensor_not_responding); } @@ -7760,23 +7965,23 @@ static bool selftest_irsensor() TempBackup tempBackup; setTargetHotend(ABS_PREHEAT_HOTEND_TEMP,active_extruder); mmu_wait_for_heater_blocking(); - progress = lcd_selftest_screen(testScreen::fsensor, 0, 1, true, 0); + progress = lcd_selftest_screen(TestScreen::Fsensor, 0, 1, true, 0); mmu_filament_ramming(); } - progress = lcd_selftest_screen(testScreen::fsensor, progress, 1, true, 0); + progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0); mmu_command(MmuCmd::U0); manage_response(false, false); for(uint_least8_t i = 0; i < 200; ++i) { - if (0 == (i % 32)) progress = lcd_selftest_screen(testScreen::fsensor, progress, 1, true, 0); + if (0 == (i % 32)) progress = lcd_selftest_screen(TestScreen::Fsensor, progress, 1, true, 0); mmu_load_step(false); while (blocks_queued()) { if (PIN_GET(IR_SENSOR_PIN) == 0) { - lcd_selftest_error(TestError::triggeringFsensor, "", ""); + lcd_selftest_error(TestError::TriggeringFsensor, "", ""); return false; } #ifdef TMC2130 @@ -7921,11 +8126,11 @@ static FanCheck lcd_selftest_fan_auto(int _fan) printf_P(PSTR("Extr fan speed: %d \n"), fan_speed[0]); if (!fan_speed[0]) { - return FanCheck::extruderFan; + return FanCheck::ExtruderFan; } #ifdef FAN_SOFT_PWM else if (fan_speed[0] > 50 ) { // printerFan is faster - return FanCheck::swappedFan; + return FanCheck::SwappedFan; } break; #endif @@ -7960,7 +8165,7 @@ static FanCheck lcd_selftest_fan_auto(int _fan) printf_P(PSTR("Print fan speed: %d \n"), fan_speed[1]); printf_P(PSTR("Extr fan speed: %d \n"), fan_speed[0]); if (!fan_speed[1]) { - return FanCheck::printFan; + return FanCheck::PrintFan; } #ifdef FAN_SOFT_PWM @@ -7979,23 +8184,23 @@ static FanCheck lcd_selftest_fan_auto(int _fan) // noctua speed is between 17 and 24, turbine more then 30 if (fan_speed[1] < 30) { - return FanCheck::swappedFan; + return FanCheck::SwappedFan; } #else // fan is spinning, but measured RPM are too low for print fan, it must // be left extruder fan else if (fan_speed[1] < 34) { - return FanCheck::swappedFan; + return FanCheck::SwappedFan; } #endif //FAN_SOFT_PWM break; } - return FanCheck::success; + return FanCheck::Success; } #endif //FANCHECK -static int lcd_selftest_screen(testScreen screen, int _progress, int _progress_scale, bool _clear, int _delay) +static int lcd_selftest_screen(TestScreen screen, int _progress, int _progress_scale, bool _clear, int _delay) { lcd_update_enable(false); @@ -8007,58 +8212,58 @@ static int lcd_selftest_screen(testScreen screen, int _progress, int _progress_s lcd_set_cursor(0, 0); - if (screen == testScreen::extruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN)); - if (screen == testScreen::printFan) lcd_puts_P(_T(MSG_SELFTEST_FAN)); - if (screen == testScreen::fansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN)); - if (screen == testScreen::endStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 - if (screen == testScreen::axisX) lcd_puts_P(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 - if (screen == testScreen::axisY) lcd_puts_P(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 - if (screen == testScreen::axisZ) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 - if (screen == testScreen::bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED)); - if (screen == testScreen::hotend - || screen == testScreen::hotendOk) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 - if (screen == testScreen::fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); - if (screen == testScreen::fsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); - if (screen == testScreen::allCorrect) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 - if (screen == testScreen::failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED)); - if (screen == testScreen::home) lcd_puts_P(_i("Calibrating home"));////c=20 r=1 + if (screen == TestScreen::ExtruderFan) lcd_puts_P(_T(MSG_SELFTEST_FAN)); + if (screen == TestScreen::PrintFan) lcd_puts_P(_T(MSG_SELFTEST_FAN)); + if (screen == TestScreen::FansOk) lcd_puts_P(_T(MSG_SELFTEST_FAN)); + if (screen == TestScreen::EndStops) lcd_puts_P(_i("Checking endstops"));////MSG_SELFTEST_CHECK_ENDSTOPS c=20 + if (screen == TestScreen::AxisX) lcd_puts_P(_i("Checking X axis "));////MSG_SELFTEST_CHECK_X c=20 + if (screen == TestScreen::AxisY) lcd_puts_P(_i("Checking Y axis "));////MSG_SELFTEST_CHECK_Y c=20 + if (screen == TestScreen::AxisZ) lcd_puts_P(_i("Checking Z axis "));////MSG_SELFTEST_CHECK_Z c=20 + if (screen == TestScreen::Bed) lcd_puts_P(_T(MSG_SELFTEST_CHECK_BED)); + if (screen == TestScreen::Hotend + || screen == TestScreen::HotendOk) lcd_puts_P(_i("Checking hotend "));////MSG_SELFTEST_CHECK_HOTEND c=20 + if (screen == TestScreen::Fsensor) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); + if (screen == TestScreen::FsensorOk) lcd_puts_P(_T(MSG_SELFTEST_CHECK_FSENSOR)); + if (screen == TestScreen::AllCorrect) lcd_puts_P(_i("All correct "));////MSG_SELFTEST_CHECK_ALLCORRECT c=20 + if (screen == TestScreen::Failed) lcd_puts_P(_T(MSG_SELFTEST_FAILED)); + if (screen == TestScreen::Home) lcd_puts_P(_i("Calibrating home"));////c=20 r=1 lcd_set_cursor(0, 1); lcd_puts_P(separator); - if ((screen >= testScreen::extruderFan) && (screen <= testScreen::fansOk)) + if ((screen >= TestScreen::ExtruderFan) && (screen <= TestScreen::FansOk)) { //SERIAL_ECHOLNPGM("Fan test"); lcd_puts_at_P(0, 2, _i("Extruder fan:"));////MSG_SELFTEST_EXTRUDER_FAN_SPEED c=18 lcd_set_cursor(18, 2); - (screen < testScreen::printFan) ? lcd_print(_indicator) : lcd_print("OK"); + (screen < TestScreen::PrintFan) ? lcd_print(_indicator) : lcd_print("OK"); lcd_puts_at_P(0, 3, _i("Print fan:"));////MSG_SELFTEST_PRINT_FAN_SPEED c=18 lcd_set_cursor(18, 3); - (screen < testScreen::fansOk) ? lcd_print(_indicator) : lcd_print("OK"); + (screen < TestScreen::FansOk) ? lcd_print(_indicator) : lcd_print("OK"); } - else if (screen >= testScreen::fsensor && screen <= testScreen::fsensorOk) + else if (screen >= TestScreen::Fsensor && screen <= TestScreen::FsensorOk) { lcd_puts_at_P(0, 2, _T(MSG_SELFTEST_FILAMENT_SENSOR)); lcd_putc(':'); lcd_set_cursor(18, 2); - (screen == testScreen::fsensor) ? lcd_print(_indicator) : lcd_print("OK"); + (screen == TestScreen::Fsensor) ? lcd_print(_indicator) : lcd_print("OK"); } - else if (screen < testScreen::fsensor) + else if (screen < TestScreen::Fsensor) { //SERIAL_ECHOLNPGM("Other tests"); - testScreen _step_block = testScreen::axisX; + TestScreen _step_block = TestScreen::AxisX; lcd_selftest_screen_step(2, 2, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "X", _indicator); - _step_block = testScreen::axisY; + _step_block = TestScreen::AxisY; lcd_selftest_screen_step(2, 8, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Y", _indicator); - _step_block = testScreen::axisZ; + _step_block = TestScreen::AxisZ; lcd_selftest_screen_step(2, 14, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Z", _indicator); - _step_block = testScreen::bed; + _step_block = TestScreen::Bed; lcd_selftest_screen_step(3, 0, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Bed", _indicator); - _step_block = testScreen::hotend; + _step_block = TestScreen::Hotend; lcd_selftest_screen_step(3, 9, ((screen == _step_block) ? 1 : (screen < _step_block) ? 0 : 2), "Hotend", _indicator); } @@ -8135,8 +8340,8 @@ 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++) { - if (strcmp((cmd + i + 4), end) == 0) { + for (uint_least8_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'); break; @@ -8149,8 +8354,8 @@ static void menu_action_sdfile(const char* filename) uint8_t depth = (uint8_t)card.getWorkDirDepth(); 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 (uint_least8_t i = 0; i < depth; i++) { + for (uint_least8_t j = 0; j < 8; j++) { eeprom_write_byte((uint8_t*)EEPROM_DIRS + j + 8 * i, dir_names[i][j]); } } @@ -8399,6 +8604,7 @@ void menu_lcd_lcdupdate_func(void) if (lcd_draw_update == 0) lcd_draw_update = 1; lcd_encoder += lcd_encoder_diff / ENCODER_PULSES_PER_STEP; + Sound_MakeSound(e_SOUND_TYPE_EncoderMove); lcd_encoder_diff = 0; lcd_timeoutToStatus.start(); } @@ -8429,5 +8635,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::Layer1Cal) lcd_commands(); } diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h old mode 100644 new mode 100755 index 665c1233f..2c57c9443 --- a/Firmware/ultralcd.h +++ b/Firmware/ultralcd.h @@ -7,9 +7,6 @@ #include "menu.h" #include "mesh_bed_calibration.h" -extern int lcd_puts_P(const char* str); -extern int lcd_printf_P(const char* format, ...); - extern void menu_lcd_longpress_func(void); extern void menu_lcd_charsetup_func(void); extern void menu_lcd_lcdupdate_func(void); @@ -89,31 +86,37 @@ extern void lcd_diag_show_end_stops(); // To be used in lcd_commands_type. -#define LCD_COMMAND_IDLE 0 -#define LCD_COMMAND_LOAD_FILAMENT 1 -#define LCD_COMMAND_STOP_PRINT 2 -#define LCD_COMMAND_FARM_MODE_CONFIRM 4 -#define LCD_COMMAND_LONG_PAUSE 5 -#define LCD_COMMAND_PID_EXTRUDER 7 -#define LCD_COMMAND_V2_CAL 8 +enum class LcdCommands : uint_least8_t +{ + Idle, + LoadFilament, + StopPrint, + FarmModeConfirm, + LongPause, + PidExtruder, + Layer1Cal, +}; -extern int lcd_commands_type; +extern LcdCommands lcd_commands_type; extern int8_t FSensorStateMenu; -#define CUSTOM_MSG_TYPE_STATUS 0 // status message from lcd_status_message variable -#define CUSTOM_MSG_TYPE_MESHBL 1 // Mesh bed leveling in progress -#define CUSTOM_MSG_TYPE_F_LOAD 2 // Loading filament in progress -#define CUSTOM_MSG_TYPE_PIDCAL 3 // PID tuning in progress -#define CUSTOM_MSG_TYPE_TEMCAL 4 // PINDA temp calibration -#define CUSTOM_MSG_TYPE_TEMPRE 5 // Temp compensation preheat +enum class CustomMsg : uint_least8_t +{ + Status, //!< status message from lcd_status_message variable + MeshBedLeveling, //!< Mesh bed leveling in progress + FilamentLoading, //!< Loading filament in progress + PidCal, //!< PID tuning in progress + TempCal, //!< PINDA temperature calibration + TempCompPreheat, //!< Temperature compensation preheat +}; -extern unsigned int custom_message_type; +extern CustomMsg custom_message_type; extern unsigned int custom_message_state; extern uint8_t farm_mode; extern int farm_no; extern int farm_timer; -extern int farm_status; +extern uint8_t farm_status; #ifdef TMC2130 #define SILENT_MODE_NORMAL 0 @@ -137,6 +140,10 @@ void lcd_ignore_click(bool b=true); void lcd_commands(); +extern bool bSettings; // flag (i.e. 'fake parameter') for 'lcd_hw_setup_menu()' function +void lcd_hw_setup_menu(void); // NOT static due to using inside "util" module ("nozzle_diameter_check()") + + void change_extr(int extr); #ifdef SNMM @@ -145,18 +152,19 @@ void extr_unload_used(); #endif //SNMM void extr_unload(); -typedef enum +enum class FilamentAction : uint_least8_t { - e_FILAMENT_ACTION_none, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state) - e_FILAMENT_ACTION_Load, - e_FILAMENT_ACTION_autoLoad, - e_FILAMENT_ACTION_unLoad, - e_FILAMENT_ACTION_mmuLoad, - e_FILAMENT_ACTION_mmuUnLoad, - e_FILAMENT_ACTION_mmuEject, - e_FILAMENT_ACTION_mmuCut, -} eFILAMENT_ACTION; -extern eFILAMENT_ACTION eFilamentAction; + None, //!< 'none' state is used as flag for (filament) autoLoad (i.e. opposite for 'autoLoad' state) + Load, + AutoLoad, + UnLoad, + MmuLoad, + MmuUnLoad, + MmuEject, + MmuCut, +}; + +extern FilamentAction eFilamentAction; extern bool bFilamentFirstRun; extern bool bFilamentPreheatState; extern bool bFilamentAction; diff --git a/Firmware/util.cpp b/Firmware/util.cpp index 18df92f62..aa1a624da 100644 --- a/Firmware/util.cpp +++ b/Firmware/util.cpp @@ -27,7 +27,7 @@ const char STR_REVISION_RC [] PROGMEM = "rc"; inline bool is_whitespace_or_nl(char c) { - return c == ' ' || c == '\t' || c == '\n' || c == 'r'; + return c == ' ' || c == '\t' || c == '\n' || c == '\r'; } inline bool is_whitespace_or_nl_or_eol(char c) @@ -295,16 +295,10 @@ bool show_upgrade_dialog_if_version_newer(const char *version_string) for (const char *c = version_string; ! is_whitespace_or_nl_or_eol(*c); ++ c) lcd_putc(*c); lcd_puts_at_P(0, 3, _i("Please upgrade."));////MSG_NEW_FIRMWARE_PLEASE_UPGRADE c=20 -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - _tone(BEEPER, 1000); - delay_keep_alive(50); - _noTone(BEEPER); + Sound_MakeCustom(50,1000,false); delay_keep_alive(500); -if((eSoundMode==e_SOUND_MODE_LOUD)||(eSoundMode==e_SOUND_MODE_ONCE)) - _tone(BEEPER, 1000); - delay_keep_alive(50); - _noTone(BEEPER); - lcd_wait_for_click(); + Sound_MakeCustom(50,1000,false); + lcd_wait_for_click_delay(30); lcd_update_enable(true); lcd_clear(); lcd_update(0); @@ -327,3 +321,282 @@ void update_current_firmware_version_to_eeprom() eeprom_update_word((uint16_t*)EEPROM_FIRMWARE_VERSION_FLAVOR, ver_current[3]); } } + + +//-// +#define MSG_PRINT_CHECKING_FAILED_TIMEOUT 30 + +ClNozzleDiameter oNozzleDiameter=ClNozzleDiameter::_Diameter_400; +ClCheckMode oCheckMode=ClCheckMode::_None; +ClCheckModel oCheckModel=ClCheckModel::_None; +ClCheckVersion oCheckVersion=ClCheckVersion::_None; +ClCheckGcode oCheckGcode=ClCheckGcode::_None; + +void fCheckModeInit() +{ +oCheckMode=(ClCheckMode)eeprom_read_byte((uint8_t*)EEPROM_CHECK_MODE); +if(oCheckMode==ClCheckMode::_Undef) + { + oCheckMode=ClCheckMode::_Warn; + eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODE,(uint8_t)oCheckMode); + } +if(farm_mode) + oCheckMode=ClCheckMode::_Strict; +oNozzleDiameter=(ClNozzleDiameter)eeprom_read_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER); +if((oNozzleDiameter==ClNozzleDiameter::_Diameter_Undef)&& !farm_mode) + { + oNozzleDiameter=ClNozzleDiameter::_Diameter_400; + eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)oNozzleDiameter); + eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,400); + } +oCheckModel=(ClCheckModel)eeprom_read_byte((uint8_t*)EEPROM_CHECK_MODEL); +if(oCheckModel==ClCheckModel::_Undef) + { + oCheckModel=ClCheckModel::_Warn; + eeprom_update_byte((uint8_t*)EEPROM_CHECK_MODEL,(uint8_t)oCheckModel); + } +oCheckVersion=(ClCheckVersion)eeprom_read_byte((uint8_t*)EEPROM_CHECK_VERSION); +if(oCheckVersion==ClCheckVersion::_Undef) + { + oCheckVersion=ClCheckVersion::_Warn; + eeprom_update_byte((uint8_t*)EEPROM_CHECK_VERSION,(uint8_t)oCheckVersion); + } +oCheckGcode=(ClCheckGcode)eeprom_read_byte((uint8_t*)EEPROM_CHECK_GCODE); +if(oCheckGcode==ClCheckGcode::_Undef) + { + oCheckGcode=ClCheckGcode::_Warn; + eeprom_update_byte((uint8_t*)EEPROM_CHECK_GCODE,(uint8_t)oCheckGcode); + } +} + +void nozzle_diameter_check(uint16_t nDiameter) +{ +uint16_t nDiameter_um; + +if(oCheckMode==ClCheckMode::_None) + return; +nDiameter_um=eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM); +if(nDiameter==nDiameter_um) + return; +//SERIAL_ECHO_START; +//SERIAL_ECHOLNPGM("Printer nozzle diameter differs from the G-code ..."); +//SERIAL_ECHOPGM("actual : "); +//SERIAL_ECHOLN((float)(nDiameter_um/1000.0)); +//SERIAL_ECHOPGM("expected: "); +//SERIAL_ECHOLN((float)(nDiameter/1000.0)); +switch(oCheckMode) + { + case ClCheckMode::_Warn: +// lcd_show_fullscreen_message_and_wait_P(_i("Printer nozzle diameter differs from the G-code. Continue?")); +lcd_display_message_fullscreen_P(_i("Printer nozzle diameter differs from the G-code. Continue?")); +lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT); +//???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery +lcd_update_enable(true); // display / status-line recovery + break; + case ClCheckMode::_Strict: + lcd_show_fullscreen_message_and_wait_P(_i("Printer nozzle diameter differs from the G-code. Please check the value in settings. Print cancelled.")); + lcd_print_stop(); + break; + case ClCheckMode::_None: + case ClCheckMode::_Undef: + break; + } +if(!farm_mode) + { + bSettings=false; // flag ('fake parameter') for 'lcd_hw_setup_menu()' function + menu_submenu(lcd_hw_setup_menu); + } +} + +void printer_model_check(uint16_t nPrinterModel) +{ +if(oCheckModel==ClCheckModel::_None) + return; +if(nPrinterModel==nPrinterType) + return; +//SERIAL_ECHO_START; +//SERIAL_ECHOLNPGM("Printer model differs from the G-code ..."); +//SERIAL_ECHOPGM("actual : "); +//SERIAL_ECHOLN(nPrinterType); +//SERIAL_ECHOPGM("expected: "); +//SERIAL_ECHOLN(nPrinterModel); +switch(oCheckModel) + { + case ClCheckModel::_Warn: +// lcd_show_fullscreen_message_and_wait_P(_i("Printer model differs from the G-code. Continue?")); +lcd_display_message_fullscreen_P(_i("G-code sliced for a different printer type. Continue?")); +lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT); +//???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery +lcd_update_enable(true); // display / status-line recovery + break; + case ClCheckModel::_Strict: + lcd_show_fullscreen_message_and_wait_P(_i("G-code sliced for a different printer type. Please re-slice the model again. Print cancelled.")); + lcd_print_stop(); + break; + case ClCheckModel::_None: + case ClCheckModel::_Undef: + break; + } +} + +uint8_t mCompareValue(uint16_t nX,uint16_t nY) +{ +if(nX>nY) + return((uint8_t)ClCompareValue::_Greater); +if(nX cmdqueue ??? +#define PRINTER_NAME_LENGTH ((sizeof(PRINTER_MMU_NAME)>sizeof(PRINTER_NAME))?(sizeof(PRINTER_MMU_NAME)-1):(sizeof(PRINTER_NAME)-1)) +#define GCODE_DELIMITER '"' +#define ELLIPSIS "..." + +char* code_string(char* pStr,size_t* nLength) +{ +char* pStrBegin; +char* pStrEnd; + +pStrBegin=strchr(pStr,GCODE_DELIMITER); +if(!pStrBegin) + return(NULL); +pStrBegin++; +pStrEnd=strchr(pStrBegin,GCODE_DELIMITER); +if(!pStrEnd) + return(NULL); +*nLength=pStrEnd-pStrBegin; +return(pStrBegin); +} + +void printer_smodel_check(char* pStrPos) +{ +char* pResult; +size_t nLength,nPrinterNameLength; +bool bCheckOK; +char sPrinterName[PRINTER_NAME_LENGTH+sizeof(ELLIPSIS)-1+1]=""; + +nPrinterNameLength=strlen_P(::sPrinterName); +pResult=code_string(pStrPos,&nLength); +if(pResult!=NULL) + { + strlcpy(sPrinterName,pResult,min(nPrinterNameLength,nLength)+1); + if(nLength>nPrinterNameLength) + strcat(sPrinterName,ELLIPSIS); + bCheckOK=(nLength==nPrinterNameLength); + if(bCheckOK&&(!strncasecmp_P(pResult,::sPrinterName,nLength))) // i.e. string compare execute only if lengths are same + return; + } +//SERIAL_ECHO_START; +//SERIAL_ECHOLNPGM("Printer model differs from the G-code ..."); +//SERIAL_ECHOPGM("actual : \""); +//serialprintPGM(::sPrinterName); +//SERIAL_ECHOLNPGM("\""); +//SERIAL_ECHOPGM("expected: \""); +////SERIAL_ECHO(sPrinterName); +//SERIAL_ECHOLNPGM("\""); +switch(oCheckModel) + { + case ClCheckModel::_Warn: +// lcd_show_fullscreen_message_and_wait_P(_i("Printer model differs from the G-code. Continue?")); +lcd_display_message_fullscreen_P(_i("G-code sliced for a different printer type. Continue?")); +lcd_wait_for_click_delay(MSG_PRINT_CHECKING_FAILED_TIMEOUT); +//???custom_message_type=CUSTOM_MSG_TYPE_STATUS; // display / status-line recovery +lcd_update_enable(true); // display / status-line recovery + break; + case ClCheckModel::_Strict: + lcd_show_fullscreen_message_and_wait_P(_i("G-code sliced for a different printer type. Please re-slice the model again. Print cancelled.")); + lcd_print_stop(); + break; + case ClCheckModel::_None: + case ClCheckModel::_Undef: + break; + } +} + +void fSetMmuMode(bool bMMu) +{ +if(bMMu) + { + nPrinterType=pgm_read_word(&_nPrinterMmuType); + sPrinterName=_sPrinterMmuName; + } +else { + nPrinterType=pgm_read_word(&_nPrinterType); + sPrinterName=_sPrinterName; + } +} diff --git a/Firmware/util.h b/Firmware/util.h index 7cbcb027b..a9bbcb1d6 100644 --- a/Firmware/util.h +++ b/Firmware/util.h @@ -33,4 +33,78 @@ inline void eeprom_update_int8(unsigned char* addr, int8_t v) { eeprom_update_byte(addr, *reinterpret_cast(&v)); } + +//-// +enum class ClPrintChecking:uint_least8_t +{ + _Nozzle=1, + _Model=2, + _Smodel=3, + _Version=4, + _Gcode=5 +}; + +enum class ClNozzleDiameter:uint_least8_t +{ + _Diameter_250=25, + _Diameter_400=40, + _Diameter_600=60, + _Diameter_Undef=EEPROM_EMPTY_VALUE +}; + +enum class ClCheckMode:uint_least8_t +{ + _None, + _Warn, + _Strict, + _Undef=EEPROM_EMPTY_VALUE +}; + +enum class ClCheckModel:uint_least8_t +{ + _None, + _Warn, + _Strict, + _Undef=EEPROM_EMPTY_VALUE +}; + +enum class ClCheckVersion:uint_least8_t +{ + _None, + _Warn, + _Strict, + _Undef=EEPROM_EMPTY_VALUE +}; + +enum class ClCheckGcode:uint_least8_t +{ + _None, + _Warn, + _Strict, + _Undef=EEPROM_EMPTY_VALUE +}; + +#define COMPARE_VALUE_EQUAL (((uint8_t)ClCompareValue::_Equal<<6)+((uint8_t)ClCompareValue::_Equal<<4)+((uint8_t)ClCompareValue::_Equal<<2)+((uint8_t)ClCompareValue::_Equal)) +enum class ClCompareValue:uint_least8_t +{ + _Less=0, + _Equal=1, + _Greater=2 +}; + +extern ClNozzleDiameter oNozzleDiameter; +extern ClCheckMode oCheckMode; +extern ClCheckModel oCheckModel; +extern ClCheckVersion oCheckVersion; +extern ClCheckGcode oCheckGcode; + +void fCheckModeInit(); +void nozzle_diameter_check(uint16_t nDiameter); +void printer_model_check(uint16_t nPrinterModel); +void printer_smodel_check(char* pStrPos); +void fw_version_check(const char *pVersion); +void gcode_level_check(uint16_t nGcodeLevel); + +void fSetMmuMode(bool bMMu); + #endif /* UTIL_H */ diff --git a/Firmware/variants/1_75mm_MK2-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK2-RAMBo10a-E3Dv6full.h index 7021d1077..442e8b944 100644 --- a/Firmware/variants/1_75mm_MK2-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK2-RAMBo10a-E3Dv6full.h @@ -2,12 +2,16 @@ #define CONFIGURATION_PRUSA_H #include +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK2 +#define PRINTER_NAME PRINTER_MK2_NAME +#define PRINTER_MMU_TYPE PRINTER_MK2 // dummy item (due to successfully compilation / building only) +#define PRINTER_MMU_NAME PRINTER_MK2_NAME // dummy item (due to successfully compilation / building only) #define FILAMENT_SIZE "1_75mm_MK2" #define NOZZLE_TYPE "E3Dv6full" @@ -315,7 +319,7 @@ PREHEAT SETTINGS *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 40 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 @@ -438,6 +442,7 @@ THERMISTORS SETTINGS // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) #define M600_TIMEOUT 600 //seconds diff --git a/Firmware/variants/1_75mm_MK2-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK2-RAMBo13a-E3Dv6full.h index b7a66903a..44fee01ec 100644 --- a/Firmware/variants/1_75mm_MK2-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK2-RAMBo13a-E3Dv6full.h @@ -2,12 +2,16 @@ #define CONFIGURATION_PRUSA_H #include +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK2 +#define PRINTER_NAME PRINTER_MK2_NAME +#define PRINTER_MMU_TYPE PRINTER_MK2 // dummy item (due to successfully compilation / building only) +#define PRINTER_MMU_NAME PRINTER_MK2_NAME // dummy item (due to successfully compilation / building only) #define FILAMENT_SIZE "1_75mm_MK2" #define NOZZLE_TYPE "E3Dv6full" @@ -314,7 +318,7 @@ PREHEAT SETTINGS *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 40 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 @@ -437,6 +441,7 @@ THERMISTORS SETTINGS // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) #define M600_TIMEOUT 600 //seconds diff --git a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h index f1d2c785c..a979503ae 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo10a-E3Dv6full.h @@ -2,12 +2,16 @@ #define CONFIGURATION_PRUSA_H #include +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK25 +#define PRINTER_NAME PRINTER_MK25_NAME +#define PRINTER_MMU_TYPE PRINTER_MK25_MMU2 +#define PRINTER_MMU_NAME PRINTER_MK25_MMU2_NAME #define FILAMENT_SIZE "1_75mm_MK25" #define NOZZLE_TYPE "E3Dv6full" @@ -112,6 +116,7 @@ // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) // Filament sensor #define FILAMENT_SENSOR @@ -371,7 +376,7 @@ *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 40 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 diff --git a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h index ac21da414..bb897fd74 100644 --- a/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25-RAMBo13a-E3Dv6full.h @@ -2,12 +2,16 @@ #define CONFIGURATION_PRUSA_H #include +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK25 +#define PRINTER_NAME PRINTER_MK25_NAME +#define PRINTER_MMU_TYPE PRINTER_MK25_MMU2 +#define PRINTER_MMU_NAME PRINTER_MK25_MMU2_NAME #define FILAMENT_SIZE "1_75mm_MK25" #define NOZZLE_TYPE "E3Dv6full" @@ -113,6 +117,7 @@ // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) // Filament sensor #define FILAMENT_SENSOR @@ -372,7 +377,7 @@ *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 40 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 diff --git a/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h index c6fa56e95..8425dfd72 100644 --- a/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25S-RAMBo10a-E3Dv6full.h @@ -2,12 +2,16 @@ #define CONFIGURATION_PRUSA_H #include +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK25S +#define PRINTER_NAME PRINTER_MK25S_NAME +#define PRINTER_MMU_TYPE PRINTER_MK25S_MMU2 +#define PRINTER_MMU_NAME PRINTER_MK25S_MMU2_NAME #define FILAMENT_SIZE "1_75mm_MK25S" #define NOZZLE_TYPE "E3Dv6full" @@ -112,6 +116,7 @@ // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) // Filament sensor #define FILAMENT_SENSOR @@ -371,7 +376,7 @@ *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 40 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 diff --git a/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h b/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h index 24f624cd6..525c2206f 100644 --- a/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK25S-RAMBo13a-E3Dv6full.h @@ -2,12 +2,16 @@ #define CONFIGURATION_PRUSA_H #include +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK25S +#define PRINTER_NAME PRINTER_MK25S_NAME +#define PRINTER_MMU_TYPE PRINTER_MK25S_MMU2 +#define PRINTER_MMU_NAME PRINTER_MK25S_MMU2_NAME #define FILAMENT_SIZE "1_75mm_MK25" #define NOZZLE_TYPE "E3Dv6full" @@ -113,6 +117,7 @@ // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) // Filament sensor #define FILAMENT_SENSOR @@ -372,7 +377,7 @@ *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 40 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 diff --git a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h index 7ddc76b3e..b3828ce53 100644 --- a/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h @@ -2,12 +2,17 @@ #define CONFIGURATION_PRUSA_H #include +//-// +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK3 +#define PRINTER_NAME PRINTER_MK3_NAME +#define PRINTER_MMU_TYPE PRINTER_MK3_MMU2 +#define PRINTER_MMU_NAME PRINTER_MK3_MMU2_NAME #define FILAMENT_SIZE "1_75mm_MK3" #define NOZZLE_TYPE "E3Dv6full" @@ -131,6 +136,7 @@ // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) // Filament sensor #define FILAMENT_SENSOR @@ -480,7 +486,7 @@ *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 60 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 diff --git a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h index 81c8788ca..5f1009a50 100644 --- a/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h +++ b/Firmware/variants/1_75mm_MK3S-EINSy10a-E3Dv6full.h @@ -2,12 +2,16 @@ #define CONFIGURATION_PRUSA_H #include +#include "printers.h" /*------------------------------------ GENERAL SETTINGS *------------------------------------*/ // Printer revision #define PRINTER_TYPE PRINTER_MK3S +#define PRINTER_NAME PRINTER_MK3S_NAME +#define PRINTER_MMU_TYPE PRINTER_MK3S_MMU2 +#define PRINTER_MMU_NAME PRINTER_MK3S_MMU2_NAME #define FILAMENT_SIZE "1_75mm_MK3" #define NOZZLE_TYPE "E3Dv6full" @@ -22,6 +26,9 @@ #define STEEL_SHEET #define HAS_SECOND_SERIAL_PORT +// PSU +#define PSU_Delta // uncomment if DeltaElectronics PSU installed + // Uncomment the below for the E3D PT100 temperature sensor (with or without PT100 Amplifier) //#define E3D_PT100_EXTRUDER_WITH_AMP @@ -131,6 +138,7 @@ // Safety timer #define SAFETYTIMER #define DEFAULT_SAFETYTIMER_TIME_MINS 30 +#define FARM_DEFAULT_SAFETYTIMER_TIME_ms (45*60*1000ul) // Filament sensor #define FILAMENT_SENSOR @@ -480,7 +488,7 @@ *------------------------------------*/ #define FARM_PREHEAT_HOTEND_TEMP 250 -#define FARM_PREHEAT_HPB_TEMP 60 +#define FARM_PREHEAT_HPB_TEMP 80 #define FARM_PREHEAT_FAN_SPEED 0 #define PLA_PREHEAT_HOTEND_TEMP 215 diff --git a/PF-build.sh b/PF-build.sh index a7cc25a9e..fb3b51a10 100755 --- a/PF-build.sh +++ b/PF-build.sh @@ -2,6 +2,7 @@ # This bash script is used to compile automatically the Prusa firmware with a dedicated build environment and settings # # Supported OS: Windows 10, Linux64 bit +# Beta OS: Linux32 bit # # Linux: # @@ -10,9 +11,12 @@ # # Linux Subsystem Ubuntu # 1. Follow these instructions -# 2. Open Ubuntu bash and get latest updates with 'apt-get upgate' +# 2. Open Ubuntu bash and get latest updates with 'apt-get update' # 3. Install zip with 'apt-get install zip' -# 4. Add at top of ~/.bashrc following lines by using 'sudo nano ~/.bashrc' +# 4. Install python3 with 'apt-get install python3' +# 5. Add command 'ln -sf /usr/bin/python3.5 /usr/bin/python' to link python3 to python. +# Donnot istall 'python' as python 2.x has end of life see https://pythonclock.org/ +# 6. Add at top of ~/.bashrc following lines by using 'sudo nano ~/.bashrc' # # export OS="Linux" # export JAVA_TOOL_OPTIONS="-Djava.net.preferIPv4Stack=true" @@ -44,11 +48,19 @@ # gussner@WIN01 MINGW64 /d/Data/Prusa-Firmware # FW351-Build1778-1_75mm_MK25-RAMBo13a-E3Dv6full.hex # -# Version: 1.0.1-Build_8 +# Why make Arduino IDE portable? +# To have a distinguished Prusa Firmware build environment I decided to use Arduino IDE in portable mode. +# - Changes made to other Arduino instances do not change anything in this build environment. +# By default Arduino IDE uses "users" and shared library folders which is useful as soon you update the Software. +# But in this case we need a stable and defined build environment, so keep it separated it kind of important. +# Some may argue that this is only used by a script, BUT as soon someone accidentally or on purpose starts Arduino IDE +# it will use the default Arduino IDE folders and so can corrupt the build environment. +# +# Version: 1.0.6-Build_9 # Change log: # 12 Jan 2019, 3d-gussner, Fixed "compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" in 'platform.txt' # 16 Jan 2019, 3d-gussner, Build_2, Added development check to modify 'Configuration.h' to prevent unwanted LCD messages that Firmware is unknown -# 17 Jan 2019, 3d-gussner, Build_3, Check for OS Windows or Linux and use the right build enviroment +# 17 Jan 2019, 3d-gussner, Build_3, Check for OS Windows or Linux and use the right build environment # 10 Feb 2019, ropaha, Pull Request, Select variant from list while using build.sh # 10 Feb 2019, ropaha, change FW_DEV_VERSION automatically depending on FW_VERSION RC/BETA/ALPHA # 10 Feb 2019, 3d-gussner, 1st tests with english only @@ -76,108 +88,320 @@ # $2 = multi language OR english only [ALL/EN_ONLY] # $3 = development status [GOLD/RC/BETA/ALPHA/DEVEL/DEBUG] # If one argument is wrong a list of valid one will be shown -# 13 Mar 2019, 3d-gussner, MKbel updated the linux build enviromentto version 1.0.2 with an Fix maximum firmware flash size. +# 13 Mar 2019, 3d-gussner, MKbel updated the linux build environment to version 1.0.2 with an Fix maximum firmware flash size. # So did I +# 11 Jul 2019, deliopoulos,Updated to v1.0.6 as Prusa needs a new board definition for Firmware 3.8.x86_64 +# - Splitted the Download of Windows Arduino IDE 1.8.5 and Prusa specific part +# --> less download volume needed and saves some time +# +# 13 Jul 2019, deliopoulos,Splitting of Ardunio IDE and Prusa parts also for Linux64 +# 13 Jul 2019, 3d-gussner, Added Linux 32-bit version (untested yet) +# MacOS could be added in future if needs +# 14 Jul 2019, 3d-gussner, Update preferences and make it really portable +# 15 Jul 2019, 3d-gussner, New PF-build-env gihub branch +# 16 Jul 2019, 3d-gussner, New Arduino_boards github fork +# 17 Jul 2019, 3d-gussner, Final tests under Windows 10 and Linux Subsystem for Windows +# 18 Jul 2019, 3d-gussner, Added python check +# 18 Jul 2019, deliopoulos, No need more for changing 'platform.txt' file as it comes with the Arduino Boards. +# 18 Jul 2019, deliopoulos, Modified 'PF_BUILD_FILE_URL' to use 'BUILD_ENV' variable +# 22 Jul 2019, 3d-gussner, Modiffied checks to check folder and/or installation output exists. +# 22 Jul 2019, 3d-gussner, Added check if Arduino IDE 1.8.5 boards have been updated +# 22 Jul 2019, 3d-gussner, Changed exit numbers 1-13 for prepare build env 21-28 for prepare compiling 31-36 compiling +# 22 Jul 2019, 3d-gussner, Changed BOARD_URL to DRracers respository after he pulled my PR https://github.com/DRracer/Arduino_Boards/pull/1 +# 23 Jul 2019, 3d-gussner, Changed Build-env path to "PF-build-dl" as requested in PR https://github.com/prusa3d/Prusa-Firmware/pull/2028 +# Changed Hex-files folder to PF-build-hex as requested in PR +# 23 Jul 2019, 3d-gussner, Added Finding OS version routine so supporting new OS should get easier +# 26 Jul 2019, 3d-gussner, Change JSON repository to prusa3d after PR https://github.com/prusa3d/Arduino_Boards/pull/1 was merged +#### Start check if OSTYPE is supported +OS_FOUND=$( command -v uname) -###Check if OSTYPE is supported -if [ $OSTYPE == "msys" ]; then +case $( "${OS_FOUND}" | tr '[:upper:]' '[:lower:]') in + linux*) + TARGET_OS="linux" + ;; + msys*|cygwin*|mingw*) + # or possible 'bash on windows' + TARGET_OS='windows' + ;; + nt|win*) + TARGET_OS='windows' + ;; + *) + TARGET_OS='unknown' + ;; +esac +# Windows +if [ $TARGET_OS == "windows" ]; then if [ $(uname -m) == "x86_64" ]; then echo "$(tput setaf 2)Windows 64-bit found$(tput sgr0)" + Processor="64" + elif [ $(uname -m) == "i386" ]; then + echo "$(tput setaf 2)Windows 32-bit found$(tput sgr0)" + Processor="32" + else + echo "$(tput setaf 1)Unsupported OS: Windows $(uname -m)" + echo "Please refer to the notes of build.sh$(tput sgr0)" + exit 1 fi -elif [ $OSTYPE == "linux-gnu" ]; then +# Linux +elif [ $TARGET_OS == "linux" ]; then if [ $(uname -m) == "x86_64" ]; then echo "$(tput setaf 2)Linux 64-bit found$(tput sgr0)" + Processor="64" + elif [[ $(uname -m) == "i386" || $(uname -m) == "i686" ]]; then + echo "$(tput setaf 2)Linux 32-bit found$(tput sgr0)" + Processor="32" + else + echo "$(tput setaf 1)Unsupported OS: Linux $(uname -m)" + echo "Please refer to the notes of build.sh$(tput sgr0)" + exit 1 fi else echo "$(tput setaf 1)This script doesn't support your Operating system!" echo "Please use Linux 64-bit or Windows 10 64-bit with Linux subsystem / git-bash" echo "Read the notes of build.sh$(tput sgr0)" - exit + exit 1 fi sleep 2 -###Prepare bash enviroment and check if wget and zip are available +#### End check if OSTYPE is supported + +#### Prepare bash environment and check if wget, zip and other needed things are available +# Check wget if ! type wget > /dev/null; then echo "$(tput setaf 1)Missing 'wget' which is important to run this script" echo "Please follow these instructions https://gist.github.com/evanwill/0207876c3243bbb6863e65ec5dc3f058 to install wget$(tput sgr0)" - exit + exit 2 fi + +# Check for zip if ! type zip > /dev/null; then - if [ $OSTYPE == "msys" ]; then + if [ $TARGET_OS == "windows" ]; then echo "$(tput setaf 1)Missing 'zip' which is important to run this script" echo "Download and install 7z-zip from its official website https://www.7-zip.org/" echo "By default, it is installed under the directory /c/Program Files/7-Zip in Windows 10 as my case." echo "Run git Bash under Administrator privilege and" echo "navigate to the directory /c/Program Files/Git/mingw64/bin," echo "you can run the command $(tput setaf 2)ln -s /c/Program Files/7-Zip/7z.exe zip.exe$(tput sgr0)" - exit - elif [ $OSTYPE == "linux-gnu" ]; then + exit 3 + elif [ $TARGET_OS == "linux" ]; then echo "$(tput setaf 1)Missing 'zip' which is important to run this script" echo "install it with the command $(tput setaf 2)'sudo apt-get install zip'$(tput sgr0)" - exit + exit 3 + fi +fi +# Check python ... needed during language build +if ! type python > /dev/null; then + if [ $TARGET_OS == "windows" ]; then + echo "$(tput setaf 1)Missing 'python' which is important to run this script" + exit 4 + elif [ $TARGET_OS == "linux" ]; then + echo "$(tput setaf 1)Missing 'python' which is important to run this script" + echo "As Python 2.x will not be maintained from 2020 please," + echo "install it with the command $(tput setaf 2)'sudo apt-get install python3'." + echo "Check which version of Python3 has been installed using 'ls /usr/bin/python3*'" + echo "Use 'sudo ln -sf /usr/bin/python3.x /usr/bin/python' (where 'x' is your version number) to make it default.$(tput sgr0)" + exit 4 fi fi -###End prepare bash enviroment -BUILD_ENV="1.0.2" +#### End prepare bash environment + + +#### Set build environment +ARDUINO_ENV="1.8.5" +BUILD_ENV="1.0.6" +BOARD="PrusaResearchRambo" +BOARD_VERSION="1.0.1" +BOARD_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json" +BOARD_FILENAME="prusa3drambo" +BOARD_FILE_URL="https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/prusa3drambo-1.0.1.tar.bz2" +PF_BUILD_FILE_URL="https://github.com/3d-gussner/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-$BUILD_ENV.zip" +LIB="PrusaLibrary" SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" # List few useful data echo -echo "Script path:" $SCRIPT_PATH -echo "OS :" $OS -echo "OS type :" $OSTYPE +echo "Script path :" $SCRIPT_PATH +echo "OS :" $OS +echo "OS type :" $TARGET_OS +echo "" +echo "Ardunio IDE :" $ARDUINO_ENV +echo "Build env :" $BUILD_ENV +echo "Board :" $BOARD +echo "Specific Lib:" $LIB echo "" -#### Start prepare building +#### Start prepare building environment #Check if build exists and creates it if not -if [ ! -d "../build-env" ]; then - mkdir ../build-env || exit 2 +if [ ! -d "../PF-build-dl" ]; then + mkdir ../PF-build-dl || exit 5 fi -cd ../build-env || exit 3 +cd ../PF-build-dl || exit 6 +BUILD_ENV_PATH="$( cd "$(dirname "$0")" ; pwd -P )" # Check if PF-build-env- exists and downloads + creates it if not -# The build enviroment is based on the Arduino IDE 1.8.5 portal version with some changes +# The build environment is based on the supported Arduino IDE portable version with some changes if [ ! -d "../PF-build-env-$BUILD_ENV" ]; then echo "$(tput setaf 6)PF-build-env-$BUILD_ENV is missing ... creating it now for you$(tput sgr 0)" mkdir ../PF-build-env-$BUILD_ENV sleep 5 fi -if [ $OSTYPE == "msys" ]; then - if [ ! -f "PF-build-env-Win-$BUILD_ENV.zip" ]; then - echo "$(tput setaf 6)Downloading Windows build environment...$(tput setaf 2)" +# Download and extract supported Arduino IDE depending on OS +# Windows +if [ $TARGET_OS == "windows" ]; then + if [ ! -f "arduino-$ARDUINO_ENV-windows.zip" ]; then + echo "$(tput setaf 6)Downloading Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)" sleep 2 - wget https://github.com/3d-gussner/PF-build-env/releases/download/Win-$BUILD_ENV/PF-build-env-Win-$BUILD_ENV.zip || exit 4 - #cp -f ../../PF-build-env/PF-build-env-Win-$BUILD_ENV.zip PF-build-env-Win-$BUILD_ENV.zip || exit4 + wget https://downloads.arduino.cc/arduino-$ARDUINO_ENV-windows.zip || exit 7 echo "$(tput sgr 0)" fi - if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then - echo "$(tput setaf 6)Unzipping Windows build environment...$(tput setaf 2)" + if [ ! -d "../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor" ]; then + echo "$(tput setaf 6)Unzipping Windows 32/64-bit Arduino IDE portable...$(tput setaf 2)" sleep 2 - unzip PF-build-env-Win-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4 + unzip arduino-$ARDUINO_ENV-windows.zip -d ../PF-build-env-$BUILD_ENV || exit 7 + mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor + echo "# arduino-$ARDUINO_ENV-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$TARGET_OS-$Processor echo "$(tput sgr0)" fi +fi +# Linux +if [ $TARGET_OS == "linux" ]; then +# 32 or 64 bit version + if [ ! -f "arduino-$ARDUINO_ENV-linux$Processor.tar.xz" ]; then + echo "$(tput setaf 6)Downloading Linux $Processor Arduino IDE portable...$(tput setaf 2)" + sleep 2 + wget --no-check-certificate https://downloads.arduino.cc/arduino-$ARDUINO_ENV-linux$Processor.tar.xz || exit 8 + echo "$(tput sgr 0)" + fi + if [[ ! -d "../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor" && ! -e "../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$TARGET_OS-$Processor.txt" ]]; then + echo "$(tput setaf 6)Unzipping Linux $Processor Arduino IDE portable...$(tput setaf 2)" + sleep 2 + tar -xvf arduino-$ARDUINO_ENV-linux$Processor.tar.xz -C ../PF-build-env-$BUILD_ENV/ || exit 8 + mv ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor + echo "# arduino-$ARDUINO_ENV-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/arduino-$ARDUINO_ENV-$TARGET_OS-$Processor.txt + echo "$(tput sgr0)" + fi +fi +# Make Arduino IDE portable +if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/ ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/ +fi + +if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/ ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable +fi +if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/output/ ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/output +fi +if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/ ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages +fi +if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/sketchbook/ ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/sketchbook +fi +if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/sketchbook/libraries/ ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/sketchbook/libraries +fi +if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/staging/ ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/staging +fi + +# Change Arduino IDE preferences +if [ ! -e ../PF-build-env-$BUILD_ENV/Preferences-$TARGET_OS-$Processor.txt ]; then + echo "$(tput setaf 6)Setting $TARGET_OS-$Processor Arduino IDE preferences for portable GUI usage...$(tput setaf 2)" + sleep 2 + echo "update.check" + sed -i 's/update.check = true/update.check = false/g' ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/lib/preferences.txt + echo "board" + sed -i 's/board = uno/board = rambo/g' ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/lib/preferences.txt + echo "editor.linenumbers" + sed -i 's/editor.linenumbers = false/editor.linenumbers = true/g' ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/lib/preferences.txt + echo "boardsmanager.additional.urls" + echo "boardsmanager.additional.urls=$BOARD_URL" >>../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/lib/preferences.txt + echo "build.verbose=true" >>../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/lib/preferences.txt + echo "compiler.cache_core=false" >>../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/lib/preferences.txt + echo "compiler.warning_level=all" >>../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/lib/preferences.txt + echo "# Preferences-$TARGET_OS-$Processor" >> ../PF-build-env-$BUILD_ENV/Preferences-$TARGET_OS-$Processor.txt + echo "$(tput sgr0)" +fi + +# Download and extract Prusa Firmware related parts +# Download and extract PrusaResearchRambo board +if [ ! -f "$BOARD_FILENAME-$BOARD_VERSION.tar.bz2" ]; then + echo "$(tput setaf 6)Downloading Prusa Research AVR MK3 RAMBo EINSy build environment...$(tput setaf 2)" + sleep 2 + wget $BOARD_FILE_URL || exit 9 +fi +if [[ ! -d "../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD/hardware/avr/$BOARD_VERSION" || ! -e "../PF-build-env-$BUILD_ENV/$BOARD_FILENAME-$BOARD_VERSION-$TARGET_OS-$Processor.txt" ]]; then + echo "$(tput setaf 6)Unzipping $BOARD Arduino IDE portable...$(tput setaf 2)" + sleep 2 + tar -xvf $BOARD_FILENAME-$BOARD_VERSION.tar.bz2 -C ../PF-build-env-$BUILD_ENV/ || exit 10 + if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD + fi + if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD + fi + if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD/hardware ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD/hardware + fi + if [ ! -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD/hardware/avr ]; then + mkdir ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD/hardware/avr + fi + mv ../PF-build-env-$BUILD_ENV/$BOARD_FILENAME-$BOARD_VERSION ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/$BOARD/hardware/avr/$BOARD_VERSION + echo "# $BOARD_FILENAME-$BOARD_VERSION" >> ../PF-build-env-$BUILD_ENV/$BOARD_FILENAME-$BOARD_VERSION-$TARGET_OS-$Processor.txt + echo "$(tput sgr 0)" +fi + +# Download and extract Prusa Firmware specific library files +if [ ! -f "PF-build-env-$BUILD_ENV.zip" ]; then + echo "$(tput setaf 6)Downloading Prusa Firmware build environment...$(tput setaf 2)" + sleep 2 + wget $PF_BUILD_FILE_URL || exit 11 + echo "$(tput sgr 0)" +fi +if [ ! -e "../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$TARGET_OS-$Processor.txt" ]; then + echo "$(tput setaf 6)Unzipping Prusa Firmware build environment...$(tput setaf 2)" + sleep 2 + unzip -o PF-build-env-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor || exit 12 + echo "# PF-build-env-$TARGET_OS-$Processor-$BUILD_ENV" >> ../PF-build-env-$BUILD_ENV/PF-build-env-$BUILD_ENV-$TARGET_OS-$Processor.txt + echo "$(tput sgr0)" fi -if [ $OSTYPE == "linux-gnu" ]; then - if [ ! -f "PF-build-env-Linux64-$BUILD_ENV.zip" ]; then - echo "$(tput setaf 6)Downloading Linux 64 build environment...$(tput setaf 2)" - sleep 2 - wget https://github.com/mkbel/PF-build-env/releases/download/$BUILD_ENV/PF-build-env-Linux64-$BUILD_ENV.zip || exit 3 - echo "$(tput sgr0)" - fi - - if [ ! -d "../PF-build-env-$BUILD_ENV/$OSTYPE" ]; then - echo "$(tput setaf 6)Unzipping Linux build enviroment...$(tput setaf 2)" - sleep 2 - unzip PF-build-env-Linux64-$BUILD_ENV.zip -d ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 4 - echo "$(tput sgr0)" - fi +# Check if User updated Arduino IDE 1.8.5 boardsmanager and tools +if [ -d "../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/arduino/tools" ]; then + echo "$(tput setaf 6)Arduino IDE boards / tools have been manually updated...$" + echo "Please don't update the 'Arduino AVR boards' as this will prevent running this script (tput setaf 2)" + sleep 2 +fi +if [ -d "../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2" ]; then + echo "$(tput setaf 6)PrusaReasearch compatible tools have been manually updated...$(tput setaf 2)" + sleep 2 + echo "$(tput setaf 6)Copying Prusa Firmware build environment to manually updated boards / tools...$(tput setaf 2)" + sleep 2 + cp -f ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/hardware/tools/avr/avr/lib/ldscripts/avr6.xn ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.4-arduino2/avr/lib/ldscripts/avr6.xn + echo "# PF-build-env-portable-$TARGET_OS-$Processor-$BUILD_ENV" >> ../PF-build-env-$BUILD_ENV/PF-build-env-portable-$BUILD_ENV-$TARGET_OS-$Processor.txt + echo "$(tput sgr0)" +fi +if [ -d "../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor/portable/packages/arduino/tools/avr-gcc/5.4.0-atmel3.6.1-arduino2" ]; then + echo "$(tput setaf 1)Arduino IDE tools have been updated manually to a non supported version!!!" + echo "Delete ../PF-build-env-$BUILD_ENV and start the script again" + echo "Script will not continue until this have been fixed $(tput setaf 2)" + sleep 2 + echo "$(tput sgr0)" + exit 13 fi + + +#### End prepare building + + +#### Start cd $SCRIPT_PATH # First argument defines which variant of the Prusa Firmware will be compiled @@ -201,7 +425,7 @@ if [ -z "$1" ] ; then ;; "Quit") echo "You chose to stop" - exit 1 + exit ;; *) echo "$(tput setaf 1)This is not a valid variant$(tput sgr0)" @@ -215,7 +439,7 @@ else echo "$(tput setaf 1)$1 could not be found in Firmware/variants please choose a valid one$(tput setaf 2)" ls -1 $SCRIPT_PATH/Firmware/variants/*.h | xargs -n1 basename echo "$(tput sgr0)" - exit + exit 21 fi fi @@ -250,7 +474,7 @@ else else echo "$(tput setaf 1)Language argument is wrong!$(tput sgr0)" echo "Only $(tput setaf 2)'ALL'$(tput sgr0) or $(tput setaf 2)'EN_ONLY'$(tput sgr0) are allowed as 2nd argument!" - exit + exit 22 fi fi #Check if DEV_STATUS is selected via argument 3 @@ -260,23 +484,23 @@ if [ ! -z "$3" ] ; then else echo "$(tput setaf 1)Development argument is wrong!$(tput sgr0)" echo "Only $(tput setaf 2)'GOLD', 'RC', 'BETA', 'ALPHA', 'DEVEL' or 'DEBUG'$(tput sgr0) are allowed as 3rd argument!$(tput sgr0)" - exit + exit 23 fi fi #Set BUILD_ENV_PATH -cd ../PF-build-env-$BUILD_ENV/$OSTYPE || exit 5 +cd ../PF-build-env-$BUILD_ENV/$TARGET_OS-$Processor || exit 24 BUILD_ENV_PATH="$( pwd -P )" cd ../.. #Checkif BUILD_PATH exists and if not creates it if [ ! -d "Prusa-Firmware-build" ]; then - mkdir Prusa-Firmware-build || exit 6 + mkdir Prusa-Firmware-build || exit 25 fi #Set the BUILD_PATH for Arduino IDE -cd Prusa-Firmware-build || exit 7 +cd Prusa-Firmware-build || exit 26 BUILD_PATH="$( pwd -P )" for v in ${VARIANTS[*]} @@ -328,10 +552,10 @@ do DEV_STATUS=$DEV_STATUS_SELECTED fi #Prepare hex files folders - if [ ! -d "$SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then - mkdir -p $SCRIPT_PATH/../Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD || exit 10 + if [ ! -d "$SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD" ]; then + mkdir -p $SCRIPT_PATH/../PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD || exit 27 fi - OUTPUT_FOLDER="Hex-files/FW$FW-Build$BUILD/$MOTHERBOARD" + OUTPUT_FOLDER="PF-build-hex/FW$FW-Build$BUILD/$MOTHERBOARD" #Check if exactly the same hexfile already exists if [[ -f "$SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex" && "$LANGUAGES" == "ALL" ]]; then @@ -366,11 +590,11 @@ do #Prepare Firmware to be compiled by copying variant as Configuration_prusa.h if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then - cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11 + cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 28 else echo "$(tput setaf 6)Configuration_prusa.h already exist it will be overwritten in 10 seconds by the chosen variant.$(tput sgr 0)" read -t 10 -p "Press Enter to continue..." - cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 11 + cp -f $SCRIPT_PATH/Firmware/variants/$VARIANT.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 28 fi #Prepare Configuration.h to use the correct FW_DEV_VERSION to prevent LCD messages when connecting with OctoPrint @@ -391,22 +615,9 @@ do fi #Check if compiler flags are set to Prusa specific needs for the rambo board. - if [ $OSTYPE == "msys" ]; then - RAMBO_PLATFORM_FILE="rambo/hardware/avr/1.0.1/platform.txt" - COMP_FLAGS="compiler.c.elf.flags={compiler.warning_flags} -Os -g -flto -fuse-linker-plugin -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections" - CHECK_FLAGS=$(grep --max-count=1 "$COMP_FLAGS" $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE) - if [ -z "$CHECK_FLAGS" ]; then - echo "Compiler flags not found, adding flags" - if [ ! -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck ]; then - echo "making a backup" - ls -1 $BUILD_ENV_PATH/portable/packages/rambo/hardware/avr/1.0.1/ - cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck - fi - echo $COMP_FLAGS >> $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE - else - echo "Compiler flags are set in rambo platform.txt" $CHECK_FLAGS - fi - fi +# if [ $TARGET_OS == "windows" ]; then +# RAMBO_PLATFORM_FILE="PrusaResearchRambo/avr/platform.txt" +# fi #### End of Prepare building @@ -414,37 +625,28 @@ do export ARDUINO=$BUILD_ENV_PATH #echo $BUILD_ENV_PATH - export BUILDER=$ARDUINO/arduino-builder + #export BUILDER=$ARDUINO/arduino-builder echo #read -t 5 -p "Press Enter..." echo - if [ $OSTYPE == "msys" ]; then - echo "Start to build Prusa Firmware under Windows..." - echo "Using variant $VARIANT$(tput setaf 3)" - sleep 2 - #$BUILDER -dump-prefs -logger=machine -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=none -quiet $SCRIPT_PATH/Firmware/Firmware.ino || exit 12 - #$BUILDER -compile -logger=machine -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=none -quiet $SCRIPT_PATH/Firmware/Firmware.ino || exit 13 - $BUILDER -compile -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=rambo:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=default $SCRIPT_PATH/Firmware/Firmware.ino || exit 14 - echo "$(tput sgr 0)" - fi - if [ $OSTYPE == "linux-gnu" ] ; then - echo "Start to build Prusa Firmware under Linux 64..." - echo "Using variant $VARIANT$(tput setaf 3)" - sleep 2 - $BUILD_ENV_PATH/arduino $SCRIPT_PATH/Firmware/Firmware.ino --verify --board rambo:avr:rambo --pref build.path=$BUILD_PATH || exit 14 - echo "$(tput sgr 0)" - fi + echo "Start to build Prusa Firmware ..." + echo "Using variant $VARIANT$(tput setaf 3)" + sleep 2 + #$BUILD_ENV_PATH/arduino-builder -dump-prefs -debug-level 10 -compile -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=$BOARD:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=all $SCRIPT_PATH/Firmware/Firmware.ino || exit 14 + $BUILD_ENV_PATH/arduino-builder -compile -hardware $ARDUINO/hardware -hardware $ARDUINO/portable/packages -tools $ARDUINO/tools-builder -tools $ARDUINO/hardware/tools/avr -tools $ARDUINO/portable/packages -built-in-libraries $ARDUINO/libraries -libraries $ARDUINO/portable/sketchbook/libraries -fqbn=$BOARD:avr:rambo -ide-version=10805 -build-path=$BUILD_PATH -warnings=all $SCRIPT_PATH/Firmware/Firmware.ino || exit 14 + echo "$(tput sgr 0)" if [ $LANGUAGES == "ALL" ]; then echo "$(tput setaf 2)" + echo "Building multi language firmware" $MULTI_LANGUAGE_CHECK echo "$(tput sgr 0)" sleep 2 cd $SCRIPT_PATH/lang echo "$(tput setaf 3)" - ./config.sh || exit 15 + ./config.sh || exit 31 echo "$(tput sgr 0)" # Check if previous languages and firmware build exist and if so clean them up if [ -f "lang_en.tmp" ]; then @@ -465,43 +667,43 @@ do fi # build languages echo "$(tput setaf 3)" - ./lang-build.sh || exit 16 + ./lang-build.sh || exit 32 # Combine compiled firmware with languages - ./fw-build.sh || exit 17 + ./fw-build.sh || exit 33 echo "$(tput sgr 0)" # Check if the motherboard is an EINSY and if so only one hex file will generated MOTHERBOARD=$(grep --max-count=1 "\bMOTHERBOARD\b" $SCRIPT_PATH/Firmware/variants/$VARIANT.h | sed -e's/ */ /g' |cut -d ' ' -f3) # If the motherboard is an EINSY just copy one hexfile if [ "$MOTHERBOARD" = "BOARD_EINSY_1_0a" ]; then - echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to Hex-files folder$(tput sgr 0)" + echo "$(tput setaf 2)Copying multi language firmware for MK3/Einsy board to PF-build-hex folder$(tput sgr 0)" cp -f firmware.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.hex else - echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to Hex-files folder$(tput sgr 0)" + echo "$(tput setaf 2)Zip multi language firmware for MK2.5/miniRAMbo board to PF-build-hex folder$(tput sgr 0)" cp -f firmware_cz.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-cz.hex cp -f firmware_de.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-de.hex cp -f firmware_es.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-es.hex cp -f firmware_fr.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-fr.hex cp -f firmware_it.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-it.hex cp -f firmware_pl.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-pl.hex - if [ $OSTYPE == "msys" ]; then + if [ $TARGET_OS == "windows" ]; then zip a $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex rm $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex - elif [ $OSTYPE == "linux-gnu" ]; then + elif [ $TARGET_OS == "linux" ]; then zip -m -j ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT.zip ../../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-??.hex fi fi # Cleanup after build echo "$(tput setaf 3)" - ./fw-clean.sh || exit 18 - ./lang-clean.sh || exit 19 + ./fw-clean.sh || exit 34 + ./lang-clean.sh || exit 35 echo "$(tput sgr 0)" else - echo "$(tput setaf 2)Copying English only firmware to Hex-files folder$(tput sgr 0)" - cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex || exit 20 + echo "$(tput setaf 2)Copying English only firmware to PF-build-hex folder$(tput sgr 0)" + cp -f $BUILD_PATH/Firmware.ino.hex $SCRIPT_PATH/../$OUTPUT_FOLDER/FW$FW-Build$BUILD-$VARIANT-EN_ONLY.hex || exit 34 fi # Cleanup Firmware - rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 17 + rm $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 36 sed -i -- "s/^#define FW_DEV_VERSION FW_VERSION_$DEV_STATUS/#define FW_DEV_VERSION FW_VERSION_UNKNOWN/g" $SCRIPT_PATH/Firmware/Configuration.h sed -i -- 's/^#define FW_REPOSITORY "Prusa3d"/#define FW_REPOSITORY "Unknown"/g' $SCRIPT_PATH/Firmware/Configuration.h echo $MULTI_LANGUAGE_CHECK @@ -511,14 +713,6 @@ do sleep 5 done -# Cleanup compiler flags are set to Prusa specific needs for the rambo board. -#if [ $OSTYPE == "msys" ]; then -# echo " " -# echo "Restore Windows platform.txt" -# echo " " -# cp -f $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE.bck $BUILD_ENV_PATH/portable/packages/$RAMBO_PLATFORM_FILE -#fi - # Switch to hex path and list build files cd $SCRIPT_PATH cd .. diff --git a/README.md b/README.md index f86389613..dc8379f85 100644 --- a/README.md +++ b/README.md @@ -14,75 +14,73 @@ # Build ## Linux -Run shell script build.sh to build for MK3 and flash with Sli3er. -If you have different printel 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. +_Note: Multi language build is not supported._ + #### 1. Development environment preparation - a. install `"Arduino Software IDE"` for your preferred operating system -`https://www.arduino.cc -> Software->Downloads` -it is recommended to use version `"1.8.5"`, as it is used on out build server to produce official builds. -_note: in the case of persistent compilation problems, check the version of the currently used C/C++ compiler (GCC) - should be `4.8.1`; version can be verified by entering the command -`avr-gcc --version` -if you are not sure where the file is placed (depends on how `"Arduino Software IDE"` was installed), you can use the search feature within the file system_ -_note: name collision for `"LiquidCrystal"` library known from previous versions is now obsolete (so there is no need to delete or rename original file/-s)_ +**a.** Install `"Arduino Software IDE"` from the official website `https://www.arduino.cc -> Software->Downloads` + + _It is recommended to use version `"1.8.5"`, as it is used on out build server to produce official builds._ - b. add (`UltiMachine`) `RAMBo` board into the list of Arduino target boards -`File->Preferences->Settings` -into text field `"Additional Boards Manager URLs"` -type location -`"https://raw.githubusercontent.com/ultimachine/ArduinoAddons/master/package_ultimachine_index.json"` -or you can 'manually' modify the item -`"boardsmanager.additional.urls=....."` -at the file `"preferences.txt"` (this parameter allows you to write a comma-separated list of addresses) -_note: you can find location of this file on your disk by following way: -`File->Preferences->Settings` (`"More preferences can be edited in file ..."`)_ -than do it -`Tools->Board->BoardsManager` -from viewed list select an item `"RAMBo"` (will probably be labeled as `"RepRap Arduino-compatible Mother Board (RAMBo) by UltiMachine"` -_note: select this item for any variant of board used in printers `'Prusa i3 MKx'`, that is for `RAMBo-mini x.y` and `EINSy x.y` to_ -'clicking' the item will display the installation button; select choice `"1.0.1"` from the list(last known version as of the date of issue of this document) -_(after installation, the item is labeled as `"INSTALLED"` and can then be used for target board selection)_ +**b.** Setup Arduino to use Prusa Rambo board definition - c. modify platform.txt to enable float printf support: -add "-Wl,-u,vfprintf -lprintf_flt -lm" to "compiler.c.elf.flags=" before existing flag "-Wl,--gc-sections" -example: -`"compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections"` -The file can be found in Arduino instalation directory, or after Arduino has been updated at: -"C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\avr\(version)" -If you can locate the file in both places, file from user profile is probably used. +* Open Arduino and navigate to File -> Preferences -> Settings +* To the text field `"Additional Boards Manager URLSs"` add `https://raw.githubusercontent.com/prusa3d/Arduino_Boards/master/IDE_Board_Manager/package_prusa3d_index.json` +* Open Board manager (`Tools->Board->Board manager`), and install `Prusa Research AVR MK3 RAMBo EINSy board` + +**c.** Modify compiler flags in `platform.txt` file + +* The platform.txt file can be found in Arduino instalation directory, or after Arduino has been updated at: `"C:\Users\(user)\AppData\Local\Arduino15\packages\arduino\hardware\avr\(version)"` If you can locate the file in both places, file from user profile is probably used. + +* Add `"-Wl,-u,vfprintf -lprintf_flt -lm"` to `"compiler.c.elf.flags="` before existing flag "-Wl,--gc-sections" + + For example: `"compiler.c.elf.flags=-w -Os -Wl,-u,vfprintf -lprintf_flt -lm -Wl,--gc-sections"` + +_Notes:_ + + +_In the case of persistent compilation problems, check the version of the currently used C/C++ compiler (GCC) - should be at leas `4.8.1`; +If you are not sure where the file is placed (depends on how `"Arduino Software IDE"` was installed), you can use the search feature within the file system_ + +_Name collision for `"LiquidCrystal"` library known from previous versions is now obsolete (so there is no need to delete or rename original file/-s)_ #### 2. Source code compilation -a. place the source codes corresponding to your printer model obtained from the repository into the selected directory on your disk -`https://github.com/prusa3d/Prusa-Firmware/` +**a.** Clone this repository`https://github.com/prusa3d/Prusa-Firmware/` to your local drive. -b. In the subdirectory `"Firmware/variants/"` select the configuration file (`.h`) corresponding to your printer model, make copy named `"Configuration_prusa.h"` (or make simple renaming) and copy it into `"Firmware/"` directory. +**b.** In the subdirectory `"Firmware/variants/"` select the configuration file (`.h`) corresponding to your printer model, make copy named `"Configuration_prusa.h"` (or make simple renaming) and copy it into `"Firmware/"` directory. -c. In file `"Firmware/config.h"` set LANG_MODE to 0. +**c.** In file `"Firmware/config.h"` set LANG_MODE to 0. -run `"Arduino IDE"`; select the file `"Firmware.ino"` from the subdirectory `"Firmware/"` at the location, where you placed the source codes -`File->Open` -make the desired code customizations; **all changes are on your own risk!** +**d.** Run `"Arduino IDE"`; select the file `"Firmware.ino"` from the subdirectory `"Firmware/"` at the location, where you placed the source code `File->Open` Make the desired code customizations; **all changes are on your own risk!** -select the target board `"RAMBo"` -`Tools->Board->RAMBo` -_note: it is not possible to use any of the variants `"Arduino Mega …"`, even though it is the same MCU_ +**e.** Select the target board `"Tools->Board->PrusaResearch Einsy RAMBo"` -run the compilation -`Sketch->Verify/Compile` +**f.** Run the compilation `Sketch->Verify/Compile` -upload the result code into the connected printer -`Sketch->Upload` +**g.** Upload the result code into the connected printer `Sketch->Upload` -or you can also save the output code to the file (in so called `HEX`-format) `"Firmware.ino.rambo.hex"`: -`Sketch->ExportCompiledBinary` -and then upload it to the printer using the program `"FirmwareUpdater"` +* or you can also save the output code to the file (in so called `HEX`-format) `"Firmware.ino.rambo.hex"`: `Sketch->ExportCompiledBinary` and then upload it to the printer using the program `"FirmwareUpdater"` _note: this file is created in the directory `"Firmware/"`_ ### Using Linux subsystem under Windows 10 64-bit @@ -139,14 +137,12 @@ _notes: Script and instructions contributed by 3d-gussner. Use at your own risk. # 3. Automated tests ## Prerequisites -c++11 compiler e.g. g++ 6.3.1 - -cmake - -build system - ninja or gnu make +* c++11 compiler e.g. g++ 6.3.1 +* cmake +* build system - ninja or gnu make ## Building -Create folder where you want to build tests. +Create a folder where you want to build tests. Example: diff --git a/Tests/PrusaStatistics_test.cpp b/Tests/PrusaStatistics_test.cpp new file mode 100644 index 000000000..3c15899ab --- /dev/null +++ b/Tests/PrusaStatistics_test.cpp @@ -0,0 +1,799 @@ +/** + * @file + * @author Marek Kuhn + */ + +// For now the functions are just COPIED (lots of depencendies in ultralcd.h) + +#include "catch.hpp" +#include + +static bool VERBOSE_MODE = false; // If true - output additional info to std:cout + +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;} + +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; + +static int target_temperature[1]; +static int current_temperature[1]; +static int target_temperature_bed; +static int current_temperature_bed; + +static uint16_t nozzle_diameter; +static uint16_t* EEPROM_NOZZLE_DIAMETER_uM; + +static std::string FW_VERSION; + +struct Card { + int paused = 0; + int percentDone(){ return 50; } +}; + +static Card 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"; + + 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 +static 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); + } + void println(){ + SERIAL_ECHO("\n"); + } +}; + +static MySerial 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; +#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 || 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; + } + 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 || loading_flag) + { + 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; + } + +} +} + +// Copy of 3.8 version of functions +namespace new_code +{ + +// Mocking Serial line +static 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); + SERIAL_BUFFER += "\n"; +} + +void SERIAL_RESET(){ + SERIAL_BUFFER.clear(); +} + +struct MySerial { + void print(int i){ + SERIAL_ECHO(i); + } + void println(){ + SERIAL_ECHO("\n"); + } +}; + +static MySerial 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_err(char c){ + SERIAL_ECHO("{[ERR:"); + SERIAL_ECHO(c); + SERIAL_ECHO(']'); + 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 + return; +#endif //DEBUG_DISABLE_PRUSA_STATISTICS + switch (_message) + { + + case 0: // default message + if (busy_state == PAUSED_FOR_USER) + { + prusa_statistics_case0(15); + } + else if (isPrintPaused || card.paused) + { + prusa_statistics_case0(14); + } + else if (IS_SD_PRINTING || loading_flag) + { + prusa_statistics_case0(4); + } + else + { + SERIAL_ECHO("{"); + prusa_stat_printerstatus(1); + prusa_stat_farm_number(); + prusa_stat_diameter(); + status_number = 1; + } + 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; + 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(); + } + + if(VERBOSE_MODE){ + 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]") +{ + 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 shown", "[prusa_stats]") +{ + SERIALS_RESET(); + setup_mockups(); + + 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]") +{ + SERIALS_RESET(); + setup_mockups(); + + old_code::prusa_stat_temperatures(); + new_code::prusa_stat_temperatures(); + + 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++){ + + if(VERBOSE_MODE){ + 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(); + } + } + } +} diff --git a/build.sh b/build.sh index 12005a247..907b1e037 100755 --- a/build.sh +++ b/build.sh @@ -1,5 +1,5 @@ #!/bin/bash -BUILD_ENV="1.0.2" +BUILD_ENV="1.0.6" SCRIPT_PATH="$( cd "$(dirname "$0")" ; pwd -P )" if [ ! -d "build-env" ]; then @@ -31,7 +31,7 @@ if [ ! -f "$SCRIPT_PATH/Firmware/Configuration_prusa.h" ]; then cp $SCRIPT_PATH/Firmware/variants/1_75mm_MK3-EINSy10a-E3Dv6full.h $SCRIPT_PATH/Firmware/Configuration_prusa.h || exit 8 fi -$BUILD_ENV_PATH/arduino $SCRIPT_PATH/Firmware/Firmware.ino --verify --board rambo:avr:rambo --pref build.path=$BUILD_PATH --pref compiler.warning_level=all || exit 9 +$BUILD_ENV_PATH/arduino $SCRIPT_PATH/Firmware/Firmware.ino --verify --board PrusaResearchRambo:avr:rambo --pref build.path=$BUILD_PATH --pref compiler.warning_level=all || exit 9 export ARDUINO=$BUILD_ENV_PATH diff --git a/lang/fw-build.sh b/lang/fw-build.sh index a6ac58792..98187bef7 100755 --- a/lang/fw-build.sh +++ b/lang/fw-build.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # postbuild.sh - multi-language support script # Generate binary with secondary language. diff --git a/lang/fw-clean.sh b/lang/fw-clean.sh index df7e4962a..2acd4d18e 100755 --- a/lang/fw-clean.sh +++ b/lang/fw-clean.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # fw-clean.sh - multi-language support script # Remove all firmware output files from lang folder. diff --git a/lang/lang-add.sh b/lang/lang-add.sh index d33eacd96..f8031e19d 100755 --- a/lang/lang-add.sh +++ b/lang/lang-add.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # lang-add.sh - multi-language support script # add new texts from list (lang_add.txt) to all dictionary files diff --git a/lang/lang-build.sh b/lang/lang-build.sh index e528ff94d..b8c2476eb 100755 --- a/lang/lang-build.sh +++ b/lang/lang-build.sh @@ -82,7 +82,7 @@ generate_binary() rm -f lang_$1.dat LNG=$1 #check lang dictionary - /usr/bin/env python lang-check.py $1 + /usr/bin/env python lang-check.py $1 --no-warning #create lang_xx.tmp - different processing for 'en' language if [ "$1" = "en" ]; then #remove comments and empty lines diff --git a/lang/lang-check.py b/lang/lang-check.py index 6b918df81..f592798e6 100644 --- a/lang/lang-check.py +++ b/lang/lang-check.py @@ -38,7 +38,7 @@ def parse_txt(lang, no_warning): if rows is None: rows = 1 - if len(translation) > cols*rows: + if len(translation)-2 > cols*rows: stderr.write( "[E]: Text %s is longer then definiton on line %d\n" % (translation, lines)) @@ -56,7 +56,7 @@ def main(): usage="$(prog)s lang") parser.add_argument( "lang", nargs='?', default="en", type=str, - help="Check lang file (en|cs|de|es|fr|it)") + help="Check lang file (en|cs|de|es|fr|it|pl)") parser.add_argument( "--no-warning", action="store_true", help="Disable warnings") diff --git a/lang/lang-check.sh b/lang/lang-check.sh index 3d73d4602..c363cdc00 100755 --- a/lang/lang-check.sh +++ b/lang/lang-check.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # lang_check.sh - multi-language support script # check lang_xx.bin (language binary file) diff --git a/lang/lang_en.txt b/lang/lang_en.txt index b8ea25d0c..2da37fc06 100755 --- a/lang/lang_en.txt +++ b/lang/lang_en.txt @@ -8,10 +8,10 @@ "[0;0] point offset" #MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 -"\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode" +"Crash detection can\x0abe turned on only in\x0aNormal mode" #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 -"\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode" +"WARNING:\x0aCrash detection\x0adisabled in\x0aStealth mode" # ">Cancel" diff --git a/lang/lang_en_cz.txt b/lang/lang_en_cz.txt index 027d04097..ed682e812 100755 --- a/lang/lang_en_cz.txt +++ b/lang/lang_en_cz.txt @@ -11,12 +11,12 @@ "[0;0] odsazeni bodu" #MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 -"\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode" -"\x1b[2JCrash detekce muze\x1b[1;0Hbyt zapnuta pouze v\x1b[2;0HNormal modu" +"Crash detection can\x0abe turned on only in\x0aNormal mode" +"Crash detekce muze\x0abyt zapnuta pouze v\x0aNormal modu" #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 -"\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode" -"\x1b[2JPOZOR:\x1b[1;0HCrash detekce\x1b[2;0Hdeaktivovana ve\x1b[3;0HStealth modu" +"WARNING:\x0aCrash detection\x0adisabled in\x0aStealth mode" +"POZOR:\x0aCrash detekce\x0adeaktivovana ve\x0aStealth modu" # ">Cancel" @@ -828,7 +828,7 @@ # "Press the knob" -"Stisknete hl. tlacitko" +"Stisknete tlacitko" #MSG_PRINT_PAUSED c=20 r=1 "Print paused" diff --git a/lang/lang_en_de.txt b/lang/lang_en_de.txt index c4c80d937..cb73f8f26 100755 --- a/lang/lang_en_de.txt +++ b/lang/lang_en_de.txt @@ -11,12 +11,12 @@ "[0;0] Punktversatz" #MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 -"\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode" -"\x1b[2JCrash Erkennung kann\x1b[1;0Hnur im Modus Normal\x1b[2;0Hgenutzt werden" +"Crash detection can\x0abe turned on only in\x0aNormal mode" +"Crash Erkennung kann\x0anur im Modus Normal\x0agenutzt werden" #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 -"\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode" -"\x1b[2JWARNUNG:\x1b[1;0HCrash Erkennung\x1b[2;0Hdeaktiviert im\x1b[3;0HStealth Modus" +"WARNING:\x0aCrash detection\x0adisabled in\x0aStealth mode" +"WARNUNG:\x0aCrash Erkennung\x0adeaktiviert im\x0aStealth Modus" # ">Cancel" @@ -936,7 +936,7 @@ #MSG_SELFTEST_FAILED c=20 "Selftest failed " -"Selbsttest misslung " +"Selbsttest misslang " #MSG_FORCE_SELFTEST c=20 r=8 "Selftest will be run to calibrate accurate sensorless rehoming." diff --git a/lang/lang_en_es.txt b/lang/lang_en_es.txt index 2f4dc2516..a48da96f5 100755 --- a/lang/lang_en_es.txt +++ b/lang/lang_en_es.txt @@ -11,12 +11,12 @@ "[0;0] punto offset" #MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 -"\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode" -"\x1b[2JDec. choque\x1b[1;0Hpuede ser activada solo en\x1b[2;0HModo normal" +"Crash detection can\x0abe turned on only in\x0aNormal mode" +"Dec. choque puede\x0aser activada solo en\x0aModo normal" #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 -"\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode" -"\x1b[2JATENCION:\x1b[1;0HDec. choque\x1b[2;0Hdesactivada en\x1b[3;0HModo silencio" +"WARNING:\x0aCrash detection\x0adisabled in\x0aStealth mode" +"ATENCION:\x0aDec. choque\x0adesactivada en\x0aModo silencio" # ">Cancel" diff --git a/lang/lang_en_fr.txt b/lang/lang_en_fr.txt index dfb0dd851..320b91d9e 100755 --- a/lang/lang_en_fr.txt +++ b/lang/lang_en_fr.txt @@ -11,12 +11,12 @@ "Offset point [0;0]" #MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 -"\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode" -"\x1b[2JLa detection de crash peut etre\x1b[1;0Hactive seulement\x1b[2;0Hen mode Normal" +"Crash detection can\x0abe turned on only in\x0aNormal mode" +"La detection de\x0acrash peut etre\x0aactive seulement en\x0amode Normal" #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 -"\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode" -"\x1b[2JATTENTION :\x1b[1;0HDetection de crash\x1b[2;0H desactivee en\x1b[3;0Hmode Furtif" +"WARNING:\x0aCrash detection\x0adisabled in\x0aStealth mode" +"ATTENTION:\x0aDetection de crash\x0adesactivee en\x0amode Furtif" # ">Cancel" diff --git a/lang/lang_en_it.txt b/lang/lang_en_it.txt index 9637777f0..0b82c587f 100755 --- a/lang/lang_en_it.txt +++ b/lang/lang_en_it.txt @@ -11,12 +11,12 @@ "[0;0] punto offset" #MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 -"\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode" -"\x1b[2JRilev. impatto\x1b[1;0Hattivabile solo\x1b[2;0Hin Modalita normale" +"Crash detection can\x0abe turned on only in\x0aNormal mode" +"Rilev. impatto\x0aattivabile solo\x0ain Modalita normale" #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 -"\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode" -"\x1b[2JATTENZIONE:\x1b[1;0HRilev. impatto\x1b[2;0Hdisattivato in\x1b[3;0HModalita silenziosa" +"WARNING:\x0aCrash detection disabled in Stealth mode" +"ATTENZIONE:\x0aRilev. impatto\x0adisattivato in\x0aModalita silenziosa" # ">Cancel" diff --git a/lang/lang_en_pl.txt b/lang/lang_en_pl.txt index fe422cc37..47e0fbb06 100755 --- a/lang/lang_en_pl.txt +++ b/lang/lang_en_pl.txt @@ -11,12 +11,12 @@ "[0;0] przesuniecie punktu" #MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4 -"\x1b[2JCrash detection can\x1b[1;0Hbe turned on only in\x1b[2;0HNormal mode" -"\x1b[2JWykrywanie zderzen moze\x1b[1;0Hbyc wlaczone tylko w\x1b[2;0Htrybie Normalnym" +"Crash detection can\x0abe turned on only in\x0aNormal mode" +"Wykrywanie zderzen\x0amoze byc wlaczone\x0atylko w\x0atrybie Normalnym" #MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4 -"\x1b[2JWARNING:\x1b[1;0HCrash detection\x1b[2;0Hdisabled in\x1b[3;0HStealth mode" -"\x1b[2JUWAGA:\x1b[1;0HWykrywanie zderzen\x1b[2;0Hwylaczone w\x1b[3;0Htrybie Stealth" +"WARNING:\x0aCrash detection\x0adisabled in\x0aStealth mode" +"UWAGA:\x0aWykrywanie zderzen\x0awylaczone w\x0atrybie Stealth" # ">Cancel" diff --git a/lang/progmem.sh b/lang/progmem.sh index 3e413025a..53993b280 100755 --- a/lang/progmem.sh +++ b/lang/progmem.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # progmem.sh - multi-language support script # Examine content of progmem sections (default is progmem1). @@ -104,6 +104,7 @@ cat $PROGMEM.chr | \ sed 's/\\x1b/\\\\\\x1b/g;' | \ sed 's/\\x01/\\\\\\x01/g;' | \ sed 's/\\xf8/\\\\\\xf8/g;' | \ + sed 's/\\x0a/\\\\\\x0a/g;' | \ sed 's/\\x00$/\n/;s/^/\"/;s/$/\"\\/'; \ ) | sh > $PROGMEM.var