Isolate the entire farm and statistics code

This commit is contained in:
Alex Voinea 2022-08-25 13:03:43 +03:00 committed by DRracer
parent 7d597eb8b0
commit bef7b086e3
16 changed files with 472 additions and 607 deletions

View file

@ -162,8 +162,6 @@
CardReader card;
#endif
unsigned long PingTime = _millis();
uint8_t mbl_z_probe_nr = 3; //numer of Z measurements for each point in mesh bed leveling calibration
//used for PINDA temp calibration and pause print
@ -211,8 +209,6 @@ bool mesh_bed_leveling_flag = false;
bool prusa_sd_card_upload = false;
#endif
uint8_t status_number = 0;
unsigned long total_filament_used;
HeatingStatus heating_status;
uint8_t heating_status_counter;
@ -298,10 +294,6 @@ const char errormagic[] PROGMEM = "Error:";
const char echomagic[] PROGMEM = "echo:";
const char G28W0[] PROGMEM = "G28 W0";
bool no_response = false;
uint8_t important_status;
uint8_t saved_filament_type;
// Define some coordinates outside the clamp limits (making them invalid past the parsing stage) so
// that they can be used later for various logical checks
#define X_COORD_INVALID (X_MIN_POS-1)
@ -1101,25 +1093,7 @@ void setup()
setup_killpin();
setup_powerhold();
farm_mode = eeprom_read_byte((uint8_t*)EEPROM_FARM_MODE);
if (farm_mode == 0xFF) {
farm_mode = false; //if farm_mode has not been stored to eeprom yet and farm number is set to zero or EEPROM is fresh, deactivate farm mode
eeprom_update_byte((uint8_t*)EEPROM_FARM_MODE, farm_mode);
} else if (farm_mode) {
no_response = true; //we need confirmation by recieving PRUSA thx
important_status = 8;
prusa_statistics(8);
#ifdef HAS_SECOND_SERIAL_PORT
selectedSerialPort = 1;
#endif //HAS_SECOND_SERIAL_PORT
MYSERIAL.begin(BAUDRATE);
#ifdef FILAMENT_SENSOR
//disabled filament autoload (PFW360)
fsensor_autoload_set(false);
#endif //FILAMENT_SENSOR
// ~ FanCheck -> on
eeprom_update_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED, true);
}
farm_mode_init();
#ifdef TMC2130
if( FarmOrUserECool() ){
@ -1403,11 +1377,9 @@ void setup()
enable_z();
#endif
if (farm_mode) {
// The farm monitoring SW may accidentally expect
// 2 messages of "printer started" to consider a printer working.
prusa_statistics(8);
}
// The farm monitoring SW may accidentally expect
// 2 messages of "printer started" to consider a printer working.
prusa_statistics(8);
// Enable Toshiba FlashAir SD card / WiFi enahanced card.
card.ToshibaFlashAir_enable(eeprom_read_byte((unsigned char*)EEPROM_TOSHIBA_FLASH_AIR_COMPATIBLITY) == 1);
@ -2970,7 +2942,7 @@ static void gcode_G28(bool home_x_axis, long home_x_value, bool home_y_axis, lon
}
#endif
if (farm_mode) { prusa_statistics(20); };
prusa_statistics(20);
st_synchronize();
homing_flag = false;
@ -3680,10 +3652,7 @@ static void gcode_M600(bool automatic, float x_position, float y_position, float
st_synchronize();
float lastpos[4];
if (farm_mode)
{
prusa_statistics(22);
}
prusa_statistics(22);
//First backup current position and settings
int feedmultiplyBckp = feedmultiply;
@ -3807,10 +3776,7 @@ void gcode_M701()
{
printf_P(PSTR("gcode_M701 begin\n"));
if (farm_mode)
{
prusa_statistics(22);
}
prusa_statistics(22);
if (mmu_enabled)
{
@ -4419,13 +4385,12 @@ void process_commands()
Set of internal PRUSA commands
#### Usage
PRUSA [ Ping | PRN | FAN | fn | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | FR ]
PRUSA [ Ping | PRN | FAN | thx | uvlo | MMURES | RESET | fv | M28 | SN | Fir | Rev | Lang | Lz | FR ]
#### Parameters
- `Ping`
- `PRN` - Prints revision of the printer
- `FAN` - Prints fan details
- `fn` - Prints farm no.
- `thx`
- `uvlo`
- `MMURES` - Reset MMU
@ -4443,29 +4408,17 @@ void process_commands()
- `nozzle` - prints nozzle diameter (farm mode only), works like M862.1 P, e.g. `PRUSA nozzle`
*/
if (code_seen_P(PSTR("Ping"))) { // PRUSA Ping
if (farm_mode) {
PingTime = _millis();
}
}
else if (code_seen_P(PSTR("PRN"))) { // PRUSA PRN
printf_P(_N("%u"), status_number);
} else if( code_seen_P(PSTR("FANPINTST"))){
if (farm_prusa_code_seen()) {}
else if( code_seen_P(PSTR("FANPINTST"))) {
gcode_PRUSA_BadRAMBoFanTest();
}else if (code_seen_P(PSTR("FAN"))) { // PRUSA FAN
printf_P(_N("E0:%d RPM\nPRN0:%d RPM\n"), 60*fan_speed[0], 60*fan_speed[1]);
}
else if (code_seen_P(PSTR("thx"))) // PRUSA thx
{
no_response = false;
}
else if (code_seen_P(PSTR("uvlo"))) // PRUSA uvlo
{
eeprom_update_byte((uint8_t*)EEPROM_UVLO,0);
enquecommand_P(PSTR("M24"));
}
}
else if (code_seen_P(PSTR("FAN"))) { // PRUSA FAN
printf_P(_N("E0:%d RPM\nPRN0:%d RPM\n"), 60*fan_speed[0], 60*fan_speed[1]);
}
else if (code_seen_P(PSTR("uvlo"))) { // PRUSA uvlo
eeprom_update_byte((uint8_t*)EEPROM_UVLO,0);
enquecommand_P(PSTR("M24"));
}
else if (code_seen_P(PSTR("MMURES"))) // PRUSA MMURES
{
mmu_reset();
@ -5546,30 +5499,23 @@ eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,0xFFFF);
}
break;
#ifdef PRUSA_FARM
/*!
### G98 - Activate farm mode <a href="https://reprap.org/wiki/G-code#G98:_Activate_farm_mode">G98: Activate farm mode</a>
Enable Prusa-specific Farm functions and g-code.
Enable Prusa-specific Farm functions and g-code.
See Internal Prusa commands.
*/
case 98:
farm_mode = 1;
PingTime = _millis();
eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
SilentModeMenu = SILENT_MODE_OFF;
eeprom_update_byte((unsigned char *)EEPROM_SILENT, SilentModeMenu);
fCheckModeInit(); // alternatively invoke printer reset
break;
case 98:
farm_gcode_g98();
break;
/*! ### G99 - Deactivate farm mode <a href="https://reprap.org/wiki/G-code#G99:_Deactivate_farm_mode">G99: Deactivate farm mode</a>
Disables Prusa-specific Farm functions and g-code.
*/
case 99:
farm_mode = 0;
lcd_printer_connected();
eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
lcd_update(2);
fCheckModeInit(); // alternatively invoke printer reset
break;
Disables Prusa-specific Farm functions and g-code.
*/
case 99:
farm_gcode_g99();
break;
#endif //PRUSA_FARM
default:
printf_P(MSG_UNKNOWN_CODE, 'G', cmdbuffer + bufindr + CMDHDRSIZE);
}
@ -6437,7 +6383,7 @@ Sigma_Exit:
}
LCD_MESSAGERPGM(_T(MSG_HEATING));
heating_status = HeatingStatus::EXTRUDER_HEATING;
if (farm_mode) { prusa_statistics(1); };
prusa_statistics(1);
#ifdef AUTOTEMP
autotemp_enabled=false;
@ -6468,7 +6414,7 @@ Sigma_Exit:
LCD_MESSAGERPGM(_T(MSG_HEATING_COMPLETE));
heating_status = HeatingStatus::EXTRUDER_HEATING_COMPLETE;
if (farm_mode) { prusa_statistics(2); };
prusa_statistics(2);
//starttime=_millis();
previous_millis_cmd.start();
@ -6494,7 +6440,7 @@ Sigma_Exit:
bool CooldownNoWait = false;
LCD_MESSAGERPGM(_T(MSG_BED_HEATING));
heating_status = HeatingStatus::BED_HEATING;
if (farm_mode) { prusa_statistics(1); };
prusa_statistics(1);
if (code_seen('S'))
{
setTargetBed(code_value());
@ -8331,14 +8277,6 @@ Sigma_Exit:
nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um]
nozzle_diameter_check(nDiameter);
}
/*
else if(code_seen('S')&&farm_mode)
{
nDiameter=(uint16_t)(code_value()*1000.0+0.5); // [,um]
eeprom_update_byte((uint8_t*)EEPROM_NOZZLE_DIAMETER,(uint8_t)ClNozzleDiameter::_Diameter_Undef); // for correct synchronization after farm-mode exiting
eeprom_update_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM,nDiameter);
}
*/
else if(code_seen('Q'))
SERIAL_PROTOCOLLN((float)eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM)/1000.0);
break;