From 608717d11093e166f9574e154c61d1bf9773668a Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Tue, 7 Mar 2017 19:19:13 +0100 Subject: [PATCH] farm mode: detection if printer is connected to monitoring, PRN1 sends also farm number --- Firmware/Configuration.h | 2 +- Firmware/Marlin.h | 3 ++- Firmware/Marlin_main.cpp | 11 +++++++-- Firmware/language_all.cpp | 5 ++++ Firmware/language_all.h | 2 ++ Firmware/language_en.h | 1 + Firmware/ultralcd.cpp | 51 ++++++++++++++++++++++++++++++++++----- Firmware/ultralcd.h | 3 +++ 8 files changed, 68 insertions(+), 10 deletions(-) diff --git a/Firmware/Configuration.h b/Firmware/Configuration.h index 9cbff1a5..372681d7 100644 --- a/Firmware/Configuration.h +++ b/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 diff --git a/Firmware/Marlin.h b/Firmware/Marlin.h index 99c9a5cb..ed981cad 100644 --- a/Firmware/Marlin.h +++ b/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 diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index eba86bdb..a8ccc49c 100644 --- a/Firmware/Marlin_main.cpp +++ b/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; diff --git a/Firmware/language_all.cpp b/Firmware/language_all.cpp index 2a082b31..3cdad48f 100644 --- a/Firmware/language_all.cpp +++ b/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"; diff --git a/Firmware/language_all.h b/Firmware/language_all.h index 0f59fecc..47dde007 100644 --- a/Firmware/language_all.h +++ b/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]; diff --git a/Firmware/language_en.h b/Firmware/language_en.h index 01187b86..f5e881b7 100644 --- a/Firmware/language_en.h +++ b/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" \ No newline at end of file diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index 9ae238d7..a495329c 100644 --- a/Firmware/ultralcd.cpp +++ b/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; diff --git a/Firmware/ultralcd.h b/Firmware/ultralcd.h index 9b65b1e8..76136ff8 100644 --- a/Firmware/ultralcd.h +++ b/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();