Browse Source

current feedrate and fan speed stored to eeprom in power panic, number of blocks (linear movements) in planner serve for counting SD card recover position, print fan speed error limit prolonged to 15s

PavelSindler 7 years ago
parent
commit
16fffed52d

+ 2 - 0
Firmware/Configuration.h

@@ -54,6 +54,8 @@
 #define EEPROM_UVLO_CURRENT_POSITION_Z	(EEPROM_FILE_POSITION - 4) //float for current position in Z
 #define EEPROM_UVLO_CURRENT_POSITION_Z	(EEPROM_FILE_POSITION - 4) //float for current position in Z
 #define EEPROM_UVLO_TARGET_HOTEND		(EEPROM_UVLO_CURRENT_POSITION_Z - 1)
 #define EEPROM_UVLO_TARGET_HOTEND		(EEPROM_UVLO_CURRENT_POSITION_Z - 1)
 #define EEPROM_UVLO_TARGET_BED			(EEPROM_UVLO_TARGET_HOTEND - 1)
 #define EEPROM_UVLO_TARGET_BED			(EEPROM_UVLO_TARGET_HOTEND - 1)
+#define EEPROM_UVLO_FEEDRATE			(EEPROM_UVLO_TARGET_BED - 2)
+#define EEPROM_UVLO_FAN_SPEED			(EEPROM_UVLO_FEEDRATE - 1) 
 
 
 
 
 // Currently running firmware, each digit stored as uint16_t.
 // Currently running firmware, each digit stored as uint16_t.

+ 20 - 19
Firmware/Marlin_main.cpp

@@ -6804,16 +6804,17 @@ void uvlo_() {
 		//SERIAL_ECHOLNPGM("UVLO");	
 		//SERIAL_ECHOLNPGM("UVLO");	
 		save_print_to_eeprom();
 		save_print_to_eeprom();
 		float current_position_bckp[2];
 		float current_position_bckp[2];
-
+		int feedrate_bckp = feedrate;
 		current_position_bckp[X_AXIS] = st_get_position_mm(X_AXIS);
 		current_position_bckp[X_AXIS] = st_get_position_mm(X_AXIS);
 		current_position_bckp[Y_AXIS] = st_get_position_mm(Y_AXIS);
 		current_position_bckp[Y_AXIS] = st_get_position_mm(Y_AXIS);
 
 
-
 		eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position_bckp[X_AXIS]);
 		eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0), current_position_bckp[X_AXIS]);
 		eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position_bckp[Y_AXIS]);
 		eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4), current_position_bckp[Y_AXIS]);
 		eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z), current_position[Z_AXIS]);
 		eeprom_update_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z), current_position[Z_AXIS]);
+		EEPROM_save_B(EEPROM_UVLO_FEEDRATE, &feedrate_bckp);
 		eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]);
 		eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND, target_temperature[active_extruder]);
 		eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed);
 		eeprom_update_byte((uint8_t*)EEPROM_UVLO_TARGET_BED, target_temperature_bed);
+		eeprom_update_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED, fanSpeed);
 		disable_x();
 		disable_x();
 		disable_y();
 		disable_y();
 		planner_abort_hard();
 		planner_abort_hard();
@@ -6857,13 +6858,13 @@ ISR(INT4_vect) {
 void save_print_to_eeprom() {
 void save_print_to_eeprom() {
 	//eeprom_update_word((uint16_t*)(EPROM_UVLO_CMD_QUEUE), bufindw - bufindr );
 	//eeprom_update_word((uint16_t*)(EPROM_UVLO_CMD_QUEUE), bufindw - bufindr );
 	//BLOCK_BUFFER_SIZE: max. 16 linear moves in planner buffer
 	//BLOCK_BUFFER_SIZE: max. 16 linear moves in planner buffer
-#define TYP_GCODE_LENGTH 29 //G1 X117.489 Y22.814 E1.46695 + null
+#define TYP_GCODE_LENGTH 30 //G1 X117.489 Y22.814 E1.46695 + cr lf
 	//card.get_sdpos() -> byte currently read from SD card
 	//card.get_sdpos() -> byte currently read from SD card
 	//bufindw -> position in circular buffer where to write
 	//bufindw -> position in circular buffer where to write
 	//bufindr -> position in circular buffer where to read
 	//bufindr -> position in circular buffer where to read
 	//bufflen -> number of lines in buffer -> for each line one special character??
 	//bufflen -> number of lines in buffer -> for each line one special character??
-	//TYP_GCODE_LENGTH* BLOCK_BUFFER_SIZE -> worst case from planner
-	long sd_position = card.get_sdpos() - ((bufindw > bufindr) ? (bufindw - bufindr) : sizeof(cmdbuffer) - bufindr + bufindw) - buflen - TYP_GCODE_LENGTH* BLOCK_BUFFER_SIZE;
+	//number_of_blocks() returns number of linear movements buffered in planner
+	long sd_position = card.get_sdpos() - ((bufindw > bufindr) ? (bufindw - bufindr) : sizeof(cmdbuffer) - bufindr + bufindw) - TYP_GCODE_LENGTH* number_of_blocks();
 	if (sd_position < 0) sd_position = 0;
 	if (sd_position < 0) sd_position = 0;
 	/*SERIAL_ECHOPGM("sd position before correction:");
 	/*SERIAL_ECHOPGM("sd position before correction:");
 	MYSERIAL.println(card.get_sdpos());
 	MYSERIAL.println(card.get_sdpos());
@@ -6886,8 +6887,6 @@ void recover_print() {
 
 
 	target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND);
 	target_temperature[active_extruder] = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_HOTEND);
 	target_temperature_bed = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED);
 	target_temperature_bed = eeprom_read_byte((uint8_t*)EEPROM_UVLO_TARGET_BED);
-	//x_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0));
-	//y_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4));
 	float z_pos = UVLO_Z_AXIS_SHIFT + eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z));
 	float z_pos = UVLO_Z_AXIS_SHIFT + eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION_Z));
 
 
 	SERIAL_ECHOPGM("Target temperature:");
 	SERIAL_ECHOPGM("Target temperature:");
@@ -6912,16 +6911,18 @@ void recover_print() {
 
 
 void restore_print_from_eeprom() {
 void restore_print_from_eeprom() {
 	float x_rec, y_rec;
 	float x_rec, y_rec;
+	int feedrate_rec;
+	uint8_t fan_speed_rec;
 	char cmd[30];
 	char cmd[30];
 	char* c;
 	char* c;
 	char filename[13];
 	char filename[13];
 	char str[5] = ".gco";
 	char str[5] = ".gco";
 	x_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0));
 	x_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 0));
 	y_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4));
 	y_rec = eeprom_read_float((float*)(EEPROM_UVLO_CURRENT_POSITION + 4));
-	//SERIAL_ECHOPGM("X pos read from EEPROM:");
-	//MYSERIAL.println(x_rec);
-	//SERIAL_ECHOPGM("Y pos read from EEPROM:");
-	//MYSERIAL.println(y_rec);
+	fan_speed_rec = eeprom_read_byte((uint8_t*)EEPROM_UVLO_FAN_SPEED);
+	EEPROM_read_B(EEPROM_UVLO_FEEDRATE, &feedrate_rec);
+	SERIAL_ECHOPGM("Feedrate:");
+	MYSERIAL.println(feedrate_rec);
 	for (int i = 0; i < 8; i++) {
 	for (int i = 0; i < 8; i++) {
 		filename[i] = eeprom_read_byte((uint8_t*)EEPROM_FILENAME + i);
 		filename[i] = eeprom_read_byte((uint8_t*)EEPROM_FILENAME + i);
 		
 		
@@ -6939,13 +6940,6 @@ void restore_print_from_eeprom() {
 	MYSERIAL.println(position);
 	MYSERIAL.println(position);
 	enquecommand_P(PSTR("M24")); //M24 - Start SD print
 	enquecommand_P(PSTR("M24")); //M24 - Start SD print
 	sprintf_P(cmd, PSTR("M26 S%lu"), position);
 	sprintf_P(cmd, PSTR("M26 S%lu"), position);
-	
-	//card.setIndex(long(position)); //set from which SD card byte we will start 
-	//if (card.cardOK && code_seen('S')) {
-	//	card.setIndex(code_value_long());
-	//}
-	
-	//delay?
 	enquecommand(cmd);	
 	enquecommand(cmd);	
 	enquecommand_P(PSTR("M83")); //E axis relative mode
 	enquecommand_P(PSTR("M83")); //E axis relative mode
 	strcpy(cmd, "G1 X");
 	strcpy(cmd, "G1 X");
@@ -6954,5 +6948,12 @@ void restore_print_from_eeprom() {
 	strcat(cmd, ftostr32(y_rec));
 	strcat(cmd, ftostr32(y_rec));
 	enquecommand(cmd);
 	enquecommand(cmd);
 	enquecommand_P(PSTR("G1 Z"  STRINGIFY(-UVLO_Z_AXIS_SHIFT)));
 	enquecommand_P(PSTR("G1 Z"  STRINGIFY(-UVLO_Z_AXIS_SHIFT)));
-	enquecommand_P(PSTR("G1 E"  STRINGIFY(DEFAULT_RETRACTION)" F2000"));
+	enquecommand_P(PSTR("G1 E"  STRINGIFY(DEFAULT_RETRACTION)" F480"));
+	enquecommand_P(PSTR("G1 E0.5"));
+	sprintf_P(cmd, PSTR("G1 F%d"), feedrate_rec);
+	enquecommand(cmd);
+	strcpy(cmd, "M106 S");
+	strcat(cmd, itostr3(int(fan_speed_rec)));
+	enquecommand(cmd);
+	
 }
 }

+ 3 - 1
Firmware/planner.cpp

@@ -1215,7 +1215,9 @@ void reset_acceleration_rates()
         axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
         axis_steps_per_sqr_second[i] = max_acceleration_units_per_sq_second[i] * axis_steps_per_unit[i];
         }
         }
 }
 }
-
+unsigned char number_of_blocks() {
+	return (block_buffer_head + BLOCK_BUFFER_SIZE - block_buffer_tail) & (BLOCK_BUFFER_SIZE - 1);
+}
 #ifdef PLANNER_DIAGNOSTICS
 #ifdef PLANNER_DIAGNOSTICS
 uint8_t planner_queue_min()
 uint8_t planner_queue_min()
 {
 {

+ 2 - 0
Firmware/planner.h

@@ -199,6 +199,8 @@ void set_extrude_min_temp(float temp);
 void reset_acceleration_rates();
 void reset_acceleration_rates();
 #endif
 #endif
 
 
+unsigned char number_of_blocks();
+
 // #define PLANNER_DIAGNOSTICS
 // #define PLANNER_DIAGNOSTICS
 #ifdef PLANNER_DIAGNOSTICS
 #ifdef PLANNER_DIAGNOSTICS
 // Diagnostic functions to display planner buffer underflow on the display.
 // Diagnostic functions to display planner buffer underflow on the display.

+ 1 - 1
Firmware/temperature.cpp

@@ -425,7 +425,7 @@ void checkFanSpeed()
 	else fan_speed_errors[1] = 0;
 	else fan_speed_errors[1] = 0;
 
 
 	if (fan_speed_errors[0] > 5) fanSpeedError(0);
 	if (fan_speed_errors[0] > 5) fanSpeedError(0);
-	if (fan_speed_errors[1] > 5) fanSpeedError(1);
+	if (fan_speed_errors[1] > 15) fanSpeedError(1);
 }
 }
 
 
 void fanSpeedError(unsigned char _fan) {
 void fanSpeedError(unsigned char _fan) {

+ 0 - 1
Firmware/ultralcd.cpp

@@ -3684,7 +3684,6 @@ void lcd_confirm_print()
 
 
 }
 }
 
 
-
 static void lcd_main_menu()
 static void lcd_main_menu()
 {
 {