Browse Source

farm mode: detection if printer is connected to monitoring, PRN1 sends also farm number

PavelSindler 8 years ago
parent
commit
608717d110

+ 1 - 1
Firmware/Configuration.h

@@ -5,7 +5,7 @@
 #include "Configuration_prusa.h"
 
 // Firmware version
-#define FW_version "3.0.10-4"
+#define FW_version "3.0.10-5"
 
 #define FW_PRUSA3D_MAGIC "PRUSA3DFW"
 #define FW_PRUSA3D_MAGIC_LEN 10

+ 2 - 1
Firmware/Marlin.h

@@ -108,7 +108,7 @@ FORCE_INLINE void serialprintPGM(const char *str)
   }
 }
 
-
+bool is_buffer_empty();
 void get_command();
 void process_commands();
 void ramming();
@@ -297,6 +297,7 @@ extern unsigned int heating_status_counter;
 extern bool custom_message;
 extern unsigned int custom_message_type;
 extern unsigned int custom_message_state;
+extern unsigned long PingTime;
 
 
 // Handling multiple extruders pins

+ 9 - 2
Firmware/Marlin_main.cpp

@@ -803,6 +803,11 @@ void repeatcommand_front()
     cmdbuffer_front_already_processed = true;
 } 
 
+bool is_buffer_empty()
+{
+	if (buflen == 0) return true;
+	else return false;
+}
 
 void setup_killpin()
 {
@@ -1954,10 +1959,10 @@ void process_commands()
   int8_t SilentMode;
 #endif
   if(code_seen("PRUSA")){
-		if (code_seen("Ping")) {
+		if (code_seen("Ping")) {  //PRUSA Ping
 			if (farm_mode) {
 				PingTime = millis();
-				MYSERIAL.print(farm_no); MYSERIAL.println(" : OK");
+				MYSERIAL.print(farm_no); MYSERIAL.println(": OK");
 			}	  
 		}
 		else if (code_seen("PRN")) {
@@ -3110,11 +3115,13 @@ void process_commands()
 
 	case 98: //activate farm mode
 		farm_mode = 1;
+		PingTime = millis();
 		eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
 		break;
 
 	case 99: //deactivate farm mode
 		farm_mode = 0;
+		lcd_printer_connected();
 		eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
 		break;
 

+ 5 - 0
Firmware/language_all.cpp

@@ -1806,6 +1806,11 @@ const char * const MSG_PRESS_LANG_TABLE[LANG_NUM] PROGMEM = {
 	MSG_PRESS_DE
 };
 
+const char MSG_PRINTER_DISCONNECTED_EN[] PROGMEM = "Printer disconnected";
+const char * const MSG_PRINTER_DISCONNECTED_LANG_TABLE[1] PROGMEM = {
+	MSG_PRINTER_DISCONNECTED_EN
+};
+
 const char MSG_PRINT_ABORTED_EN[] PROGMEM = "Print aborted";
 const char MSG_PRINT_ABORTED_CZ[] PROGMEM = "Tisk prerusen";
 const char MSG_PRINT_ABORTED_IT[] PROGMEM = "Stampa abortita";

+ 2 - 0
Firmware/language_all.h

@@ -357,6 +357,8 @@ extern const char* const MSG_PREHEAT_NOZZLE_LANG_TABLE[LANG_NUM];
 #define MSG_PREHEAT_NOZZLE LANG_TABLE_SELECT(MSG_PREHEAT_NOZZLE_LANG_TABLE)
 extern const char* const MSG_PRESS_LANG_TABLE[LANG_NUM];
 #define MSG_PRESS LANG_TABLE_SELECT(MSG_PRESS_LANG_TABLE)
+extern const char* const MSG_PRINTER_DISCONNECTED_LANG_TABLE[1];
+#define MSG_PRINTER_DISCONNECTED LANG_TABLE_SELECT_EXPLICIT(MSG_PRINTER_DISCONNECTED_LANG_TABLE, 0)
 extern const char* const MSG_PRINT_ABORTED_LANG_TABLE[LANG_NUM];
 #define MSG_PRINT_ABORTED LANG_TABLE_SELECT(MSG_PRINT_ABORTED_LANG_TABLE)
 extern const char* const MSG_PRUSA3D_LANG_TABLE[LANG_NUM];

+ 1 - 0
Firmware/language_en.h

@@ -265,3 +265,4 @@
 #define MSG_MENU_CALIBRATION									"Calibration"
 #define MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_OFF					"SD card [normal]"
 #define MSG_TOSHIBA_FLASH_AIR_COMPATIBILITY_ON					"SD card [FlshAir]"
+#define MSG_PRINTER_DISCONNECTED								"Printer disconnected"

+ 45 - 6
Firmware/ultralcd.cpp

@@ -103,7 +103,8 @@ uint8_t farm_mode = 0;
 int farm_no = 0;
 int farm_timer = 30;
 int farm_status = 0;
-
+unsigned long allert_timer = millis();
+bool printer_connected = true;
 
 
 bool menuExiting = false;
@@ -491,6 +492,12 @@ static void lcd_status_screen()
   else if (feedmultiply > 999)
     feedmultiply = 999;
 #endif //ULTIPANEL
+
+  if (farm_mode && !printer_connected) {
+	  lcd.setCursor(0, 3);
+	  lcd_printPGM(MSG_PRINTER_DISCONNECTED);
+  }
+
 }
 
 #ifdef ULTIPANEL
@@ -1893,6 +1900,9 @@ void prusa_statistics(int _message) {
 			SERIAL_ECHO("{");
 			prusa_stat_printerstatus(1);
 			status_number = 1;
+			SERIAL_ECHO("[PFN:");
+			SERIAL_ECHO(farm_no);
+			SERIAL_ECHO("]");
 			SERIAL_ECHOLN("}");
 		}
 		break;
@@ -2686,8 +2696,7 @@ char reset_menu() {
 static void lcd_disable_farm_mode() {
 	int8_t disable = lcd_show_fullscreen_message_yes_no_and_wait_P(PSTR("Disable farm mode?"), true, false); //allow timeouting, default no
 	if (disable) {
-		farm_mode = 0;
-		eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
+		enquecommand_P(PSTR("G99"));
 		lcd_return_to_status();
 	}
 	else {
@@ -2698,6 +2707,20 @@ static void lcd_disable_farm_mode() {
 	
 }
 
+static void lcd_ping_allert() {
+	if ((abs(millis() - allert_timer)*0.001) > PING_ALLERT_PERIOD) {
+		allert_timer = millis();
+		SET_OUTPUT(BEEPER);
+		for (int i = 0; i < 2; i++) {
+			WRITE(BEEPER, HIGH);
+			delay(50);
+			WRITE(BEEPER, LOW);
+			delay(100);
+		}
+	}
+
+};
+
 
 #ifdef SNMM
 
@@ -4473,11 +4496,27 @@ void lcd_update(uint8_t lcdDrawUpdateOverride)
 	  lcd_next_update_millis = millis() + LCD_UPDATE_INTERVAL;
 	  }
 	if (!SdFatUtil::test_stack_integrity()) stack_error();
-	if (farm_mode && ((millis() - PingTime) > PING_TIME * 1000)) {
-		// beep once per minute
-	}
+	lcd_ping(); //check that we have received ping command if we are in farm mode
 }
 
+void lcd_printer_connected() {
+	printer_connected = true;
+}
+
+void lcd_ping() {
+	if (farm_mode) {
+		bool empty = is_buffer_empty();
+		if ((millis() - PingTime) * 0.001 > (empty ? PING_TIME : PING_TIME_LONG)) { //if commands buffer is empty use shorter time period
+																							  //if there are comamnds in buffer, some long gcodes can delay execution of ping command
+																							  //therefore longer period is used
+			printer_connected = false;
+			lcd_ping_allert();
+		}
+		else {
+			lcd_printer_connected();
+		}
+	}
+}
 void lcd_ignore_click(bool b)
 {
   ignore_click = b;

+ 3 - 0
Firmware/ultralcd.h

@@ -215,6 +215,9 @@ static void extr_unload_3();
 static void lcd_disable_farm_mode();
 
 void stack_error();
+static void lcd_ping_allert();
+void lcd_printer_connected();
+void lcd_ping();
 
 void lcd_calibrate_extruder();
 void lcd_farm_sdcard_menu();