From 3afe6d09e28822f0cf58b47e0236d0e982ac987c Mon Sep 17 00:00:00 2001 From: Aaron Yourk Date: Sat, 31 Dec 2016 16:24:33 -0700 Subject: [PATCH] Rebase to upstream changes. --- Firmware/Marlin_main.cpp | 126 ++++++++++++++++++++++++++++++++++----- Firmware/stepper.cpp | 2 +- Firmware/ultralcd.cpp | 56 ++++++++++++++++- 3 files changed, 167 insertions(+), 17 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 7d276cd8..9891d3c2 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -874,6 +874,88 @@ static void lcd_language_menu(); enum MeshLevelingState { MeshReport, MeshStart, MeshNext, MeshSet }; #endif + +// Factory reset function +// This function is used to erase parts or whole EEPROM memory which is used for storing calibration and and so on. +// Level input parameter sets depth of reset +// Quiet parameter masks all waitings for user interact. +int er_progress = 0; +void factory_reset(char level, bool quiet) +{ + + switch (level) { + + // Level 0: erase everything, whole EEPROM will be set to 0xFF + case 0: + + lcd_print_at_PGM(1,2,PSTR("ERASING all data")); + + WRITE(BEEPER, HIGH); + _delay_ms(100); + WRITE(BEEPER, LOW); + _delay_ms(100); + WRITE(BEEPER, HIGH); + _delay_ms(100); + WRITE(BEEPER, LOW); + _delay_ms(200); + + er_progress = 0; + lcd_print_at_PGM(3,3,PSTR(" ")); + lcd_implementation_print_at(3,3, er_progress); + + // Erase EEPROM + for (int i = 0; i < 4096; i++) { + eeprom_write_byte((uint8_t*)i, 0xFF); + + if (i % 41 == 0) { + er_progress++; + lcd_print_at_PGM(3,3,PSTR(" ")); + lcd_implementation_print_at(3,3, er_progress); + lcd_printPGM(PSTR("%")); + } + + } + + + break; + + + // Level 1: Language reset + case 1: + WRITE(BEEPER, HIGH); + _delay_ms(100); + WRITE(BEEPER, LOW); + + lcd_force_language_selection(); + break; + + + // Level 2: Prepare for shipping + case 2: + lcd_print_at_PGM(1,2,PSTR("Shipping prep")); + + // Force language selection at the next boot up. + lcd_force_language_selection(); + // Force the "Follow calibration flow" message at the next boot up. + calibration_status_store(CALIBRATION_STATUS_Z_CALIBRATION); + farm_no = 0; + EEPROM_save_B(EEPROM_FARM_MODE, &farm_no); + farm_mode = false; + + WRITE(BEEPER, HIGH); + _delay_ms(100); + WRITE(BEEPER, LOW); + + break; + + default: + break; + } + + +} + + // "Setup" function is called by the Arduino framework on startup. // Before startup, the Timers-functions (PWM)/Analog RW and HardwareSerial provided by the Arduino-code // are initialized by the main() routine provided by the Arduino framework. @@ -948,21 +1030,33 @@ void setup() _delay_ms(1000); if (!READ(BTN_ENC)) { + lcd_implementation_clear(); + lcd_printPGM(PSTR("Factory RESET")); + SET_OUTPUT(BEEPER); WRITE(BEEPER, HIGH); + + while (!READ(BTN_ENC)); + + WRITE(BEEPER, LOW); + + - // Force language selection at the next boot up. - lcd_force_language_selection(); - // Force the "Follow calibration flow" message at the next boot up. - calibration_status_store(CALIBRATION_STATUS_Z_CALIBRATION); - farm_no = 0; - EEPROM_save_B(EEPROM_FARM_MODE, &farm_no); - farm_mode = false; - - while (!READ(BTN_ENC)); - - WRITE(BEEPER, LOW); - + _delay_ms(2000); + if (!READ(BTN_ENC)) + { + + factory_reset(0,false); + } + else + { + factory_reset(2,false); + + } + + _delay_ms(2000); + +/* #ifdef MESH_BED_LEVELING _delay_ms(2000); @@ -989,8 +1083,8 @@ void setup() _delay_ms(100); WRITE(BEEPER, LOW); } -#endif // mesh - +#endif // mesh */ + } } else @@ -1806,6 +1900,10 @@ void process_commands() // Kick farm link timer kicktime = millis(); + } else if(code_seen("FR")) { + // Factory full reset + factory_reset(0,true); + } //else if (code_seen('Cal')) { // lcd_calibration(); diff --git a/Firmware/stepper.cpp b/Firmware/stepper.cpp index 783299b9..919c5591 100644 --- a/Firmware/stepper.cpp +++ b/Firmware/stepper.cpp @@ -1017,7 +1017,7 @@ void digipot_init() //Initialize Digipot Motor Current pinMode(MOTOR_CURRENT_PWM_XY_PIN, OUTPUT); pinMode(MOTOR_CURRENT_PWM_Z_PIN, OUTPUT); pinMode(MOTOR_CURRENT_PWM_E_PIN, OUTPUT); - if(SilentMode == 0){ + if((SilentMode == 0) || (farm_mode) ){ motor_current_setting[0] = motor_current_setting_loud[0]; motor_current_setting[1] = motor_current_setting_loud[1]; diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 63d0ac71..f8553881 100644 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -25,6 +25,8 @@ extern int lcd_change_fil_state; //Function pointer to menu functions. typedef void (*menuFunc_t)(); +static void lcd_sd_updir(); + struct EditMenuParentState { //prevMenu and prevEncoderPosition are used to store the previous menu location when editing settings. @@ -2155,7 +2157,7 @@ static void lcd_settings_menu() MENU_ITEM(gcode, MSG_DISABLE_STEPPERS, PSTR("M84")); } - if (SilentModeMenu == 0) { + if ((SilentModeMenu == 0) || (farm_mode) ) { MENU_ITEM(function, MSG_SILENT_MODE_OFF, lcd_silent_mode_set); } else { MENU_ITEM(function, MSG_SILENT_MODE_ON, lcd_silent_mode_set); @@ -2518,7 +2520,57 @@ static void lcd_main_menu() MENU_ITEM(back, MSG_WATCH, lcd_status_screen); - + if (farm_mode && !IS_SD_PRINTING ) + { + + int tempScrool = 0; + if (lcdDrawUpdate == 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, MSG_REFRESH, lcd_sd_refresh); +#endif + } else { + MENU_ITEM(function, PSTR(LCD_STR_FOLDER ".."), lcd_sd_updir); + } + + for (uint16_t i = 0; i < fileCnt; i++) + { + if (_menuItemNr == _lineNr) + { +#ifndef SDCARD_RATHERRECENTFIRST + card.getfilename(i); +#else + card.getfilename(fileCnt - 1 - i); +#endif + if (card.filenameIsDir) + { + MENU_ITEM(sddirectory, MSG_CARD_MENU, card.filename, card.longFilename); + } else { + + MENU_ITEM(sdfile, MSG_CARD_MENU, card.filename, card.longFilename); + + + + + } + } else { + MENU_ITEM_DUMMY(); + } + } + + MENU_ITEM(back, PSTR("- - - - - - - - -"), lcd_status_screen); + + + } + + + if ( ( IS_SD_PRINTING || is_usb_printing ) && (current_position[Z_AXIS] < Z_HEIGHT_HIDE_LIVE_ADJUST_MENU) ) { MENU_ITEM(submenu, MSG_BABYSTEP_Z, lcd_babystep_z);//8