Explorar el Código

merge unit test and upstream changes

DRracer hace 4 años
padre
commit
255db28684
Se han modificado 5 ficheros con 849 adiciones y 51 borrados
  1. 1 0
      CMakeLists.txt
  2. 1 0
      Firmware/Marlin.h
  3. 8 0
      Firmware/Marlin_main.cpp
  4. 62 51
      Firmware/ultralcd.cpp
  5. 777 0
      Tests/PrusaStatistics_test.cpp

+ 1 - 0
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
 )

+ 1 - 0
Firmware/Marlin.h

@@ -386,6 +386,7 @@ extern LongTimer safetyTimer;
 
 #define PRINT_PERCENT_DONE_INIT   0xff
 #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

+ 8 - 0
Firmware/Marlin_main.cpp

@@ -8327,7 +8327,11 @@ 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;
+<<<<<<< HEAD
 	custom_message_type = CustomMsg::MeshBedLeveling;
+=======
+	custom_message_type = CustomMsgTypes::MESHBL;
+>>>>>>> origin/code-size-reduction
 	custom_message_state = (x_points_num * y_points_num) + 10;
 	lcd_update(1);
 
@@ -8525,7 +8529,11 @@ 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;
+<<<<<<< HEAD
 	custom_message_type = CustomMsg::MeshBedLeveling;
+=======
+	custom_message_type = CustomMsgTypes::MESHBL;
+>>>>>>> origin/code-size-reduction
 	custom_message_state = (x_points_num * y_points_num) + 10;
 	lcd_update(1);
 

+ 62 - 51
Firmware/ultralcd.cpp

@@ -1065,7 +1065,7 @@ static void lcd_status_screen()
 }
 
 void lcd_commands()
-{	
+{
 	if (lcd_commands_type == LcdCommands::LongPause)
 	{
 		if (!blocks_queued() && !homing_flag)
@@ -1449,9 +1449,9 @@ void lcd_commands()
                     lcd_wizard(WizState::RepeatLay1Cal);
                 }
                 break;
-            }
-        }
-	}
+		}
+			}
+		}
 
 #endif // not SNMM
 
@@ -1771,8 +1771,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"
 	 ),
@@ -1833,8 +1833,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();
 }
 
@@ -1850,8 +1850,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();
 }
 
@@ -1869,8 +1869,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();
 }
 
@@ -1887,8 +1887,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();
 }
 
@@ -1929,7 +1929,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
@@ -1953,7 +1954,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();
@@ -1964,11 +1966,12 @@ 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();
@@ -1984,7 +1987,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
@@ -1992,7 +1996,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
@@ -2575,7 +2580,7 @@ void lcd_change_success() {
 }
 
 static void lcd_loading_progress_bar(uint16_t loading_time_ms) { 
-	
+
 	for (uint_least8_t i = 0; i < 20; i++) {
 		lcd_set_cursor(i, 3);
 		lcd_print(".");
@@ -2817,18 +2822,14 @@ 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
@@ -2844,18 +2845,14 @@ 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"
+			"%8.2fm\n"
 		  "%S :\n"
 		  "%7ldd :%2hhdh :%02hhd m"
-		 ),
-		 _i("Total filament"),
-		 _filament_m,
-		 _i("Total print time"),
-		 _days, _hours, _minutes
-		);
+		), _i("Total filament"), _filament_m, _i("Total print time"), _days, _hours, _minutes);
+
 		KEEPALIVE_STATE(PAUSED_FOR_USER);
 		while (!lcd_clicked())
 		{
@@ -2953,8 +2950,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"
@@ -2990,8 +2987,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"
@@ -3002,10 +2999,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);
 }
@@ -4330,7 +4331,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\rbe turned on only in\rNormal mode"), lcdout);////MSG_CRASH_DET_ONLY_IN_NORMAL c=20 r=4
 		tim = _millis();
 	}
     menu_back_if_clicked();
@@ -4342,7 +4344,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:\rCrash detection\rdisabled in\rStealth mode"), lcdout);////MSG_CRASH_DET_STEALTH_FORCE_OFF c=20 r=4
 		tim = _millis();
 	}
     menu_back_if_clicked();
@@ -6432,6 +6435,7 @@ static void lcd_test_menu()
 void lcd_resume_print()
 {
     lcd_return_to_status();
+		lcd_reset_alert_level();
     lcd_setstatuspgm(_T(MSG_RESUMING_PRINT));
     lcd_reset_alert_level(); //for fan speed error
     restore_print_from_ram_and_continue(0.0);
@@ -6579,7 +6583,14 @@ static void lcd_main_menu()
 			}
 			else
 			{
+				#ifdef FANCHECK
+					checkFanSpeed(); //Check manually to get most recent fan speed status
+					if(fan_check_error == EFCE_OK)
+							MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT
+				#else
 			    MENU_ITEM_SUBMENU_P(_i("Resume print"), lcd_resume_print);////MSG_RESUME_PRINT
+				#endif
+
 			}
 			MENU_ITEM_SUBMENU_P(_T(MSG_STOP_PRINT), lcd_sdcard_stop);
 		}
@@ -6710,7 +6721,7 @@ void stepper_timer_overflow() {
 static void lcd_colorprint_change() {
 	
 	enquecommand_P(PSTR("M600"));
-	
+
 	custom_message_type = CustomMsg::FilamentLoading; //just print status message
 	lcd_setstatuspgm(_T(MSG_FINISHING_MOVEMENTS));
 	lcd_return_to_status();
@@ -8235,7 +8246,7 @@ static void menu_action_sdfile(const char* filename)
 
   //we are storing just first 8 characters of 8.3 filename assuming that extension is always ".gco"
   for (uint_least8_t i = 0; i < 8; i++) {
-	  if (strcmp((cmd + i + 4), end) == 0) { 
+	  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;

+ 777 - 0
Tests/PrusaStatistics_test.cpp

@@ -0,0 +1,777 @@
+/**
+ * @file
+ * @author Marek Kuhn
+ */
+
+// For now the functions are just COPIED (lots of depencendies in ultralcd.h)
+
+#include "catch.hpp"
+#include <iostream>
+
+
+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;}
+
+int farm_no;
+int busy_state;
+int PAUSED_FOR_USER;
+int status_number;
+int total_filament_used;
+int feedmultiply;
+int longFilenameOLD;
+int starttime;
+int isPrintPaused;
+int IS_SD_PRINTING;
+int farm_status;
+int farm_timer;
+int loading_flag;
+
+int target_temperature[1];
+int current_temperature[1];
+int target_temperature_bed;
+int current_temperature_bed;
+
+uint16_t nozzle_diameter;
+uint16_t* EEPROM_NOZZLE_DIAMETER_uM;
+
+std::string FW_VERSION;
+
+struct Card {
+	int paused = 0;
+	int percentDone(){ return 50; }
+} 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
+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);
+	}
+} 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
+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);
+	}
+} 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(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) 
+		{   
+			status_number = 15;
+		}
+		else if (isPrintPaused || card.paused) 
+		{
+			status_number = 14;
+		}
+		else if (IS_SD_PRINTING || loading_flag)
+		{
+			status_number = 4;
+		}
+		else
+		{
+			status_number = 1;
+		}
+		SERIAL_ECHO('{');
+		prusa_stat_printerstatus(status_number);
+		prusa_stat_farm_number();
+		prusa_stat_printinfo();
+		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;
+		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();
+		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();
+	}
+
+	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++){
+		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();
+			}
+		}
+	}
+}