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

@ -312,12 +312,7 @@ extern bool homing_flag;
extern bool loading_flag;
extern unsigned long total_filament_used;
void save_statistics(unsigned long _total_filament_used, unsigned long _total_print_time);
extern uint8_t status_number;
extern uint8_t heating_status_counter;
extern unsigned long PingTime;
extern bool no_response;
extern uint8_t important_status;
extern uint8_t saved_filament_type;
extern bool fan_state[2];
extern int fan_edge_counter[2];
@ -474,8 +469,6 @@ void gcode_M701();
#define UVLO !(PINE & (1<<4))
void proc_commands();
void M600_load_filament();
void M600_load_filament_movements();

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;

View file

@ -1,3 +1,429 @@
#include "Prusa_farm.h"
#include "macros.h"
#include "Marlin.h"
#include "cmdqueue.h"
#include "temperature.h"
#include "cardreader.h"
#include "conv2str.h"
#include "util.h"
#include "ultralcd.h"
#include "fsensor.h" //to be converted to Filament_sensor.h...
#ifdef PRUSA_FARM
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
uint8_t farm_mode = 0;
static ShortTimer NcTime;
static uint8_t farm_timer = 8;
static bool printer_connected = true;
static unsigned long PingTime = 0;
static uint8_t status_number = 0;
static bool no_response = false;
static uint8_t important_status;
static void prusa_statistics_err(char c);
static void prusa_stat_printerstatus(uint8_t _status);
static void prusa_stat_farm_number();
static void prusa_stat_diameter();
static void prusa_stat_temperatures();
static void prusa_stat_printinfo();
static void lcd_send_status();
#ifdef FARM_CONNECT_MESSAGE
static void proc_commands();
static void lcd_connect_printer();
#endif //FARM_CONNECT_MESSAGE
static void lcd_ping();
static void prusa_statistics_err(char c) {
SERIAL_ECHOPGM("{[ERR:");
SERIAL_ECHO(c);
SERIAL_ECHO(']');
prusa_stat_farm_number();
}
static void prusa_statistics_case0(uint8_t statnr) {
SERIAL_ECHO('{');
prusa_stat_printerstatus(statnr);
prusa_stat_farm_number();
prusa_stat_printinfo();
}
static void prusa_stat_printerstatus(uint8_t _status) {
SERIAL_ECHOPGM("[PRN:");
SERIAL_ECHO(_status);
SERIAL_ECHO(']');
}
static void prusa_stat_farm_number() {
SERIAL_ECHOPGM("[PFN:0]");
}
static void prusa_stat_diameter() {
SERIAL_ECHOPGM("[DIA:");
SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM));
SERIAL_ECHO(']');
}
static void prusa_stat_temperatures() {
SERIAL_ECHOPGM("[ST0:");
SERIAL_ECHO(target_temperature[0]);
SERIAL_ECHOPGM("][STB:");
SERIAL_ECHO(target_temperature_bed);
SERIAL_ECHOPGM("][AT0:");
SERIAL_ECHO(current_temperature[0]);
SERIAL_ECHOPGM("][ATB:");
SERIAL_ECHO(current_temperature_bed);
SERIAL_ECHO(']');
}
static void prusa_stat_printinfo() {
SERIAL_ECHOPGM("[TFU:");
SERIAL_ECHO(total_filament_used);
SERIAL_ECHOPGM("][PCD:");
SERIAL_ECHO(itostr3(card.percentDone()));
SERIAL_ECHOPGM("][FEM:");
SERIAL_ECHO(itostr3(feedmultiply));
SERIAL_ECHOPGM("][FNM:");
SERIAL_ECHO(card.longFilename[0] ? card.longFilename : card.filename);
SERIAL_ECHOPGM("][TIM:");
if (starttime != 0) {
SERIAL_ECHO(_millis() / 1000 - starttime / 1000);
}
else {
SERIAL_ECHO(0);
}
SERIAL_ECHOPGM("][FWR:");
SERIAL_ECHORPGM(FW_VERSION_STR_P());
SERIAL_ECHO(']');
prusa_stat_diameter();
}
static void lcd_send_status() {
if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) {
//send important status messages periodicaly
prusa_statistics(important_status);
NcTime.start();
#ifdef FARM_CONNECT_MESSAGE
lcd_connect_printer();
#endif //FARM_CONNECT_MESSAGE
}
}
#ifdef FARM_CONNECT_MESSAGE
static void proc_commands() {
if (buflen) {
process_commands();
if (!cmdbuffer_front_already_processed)
cmdqueue_pop_front();
cmdbuffer_front_already_processed = false;
}
}
static void lcd_connect_printer() {
lcd_update_enable(false);
lcd_clear();
int i = 0;
int t = 0;
lcd_puts_at_P(0, 0, PSTR("Connect printer to"));
lcd_puts_at_P(0, 1, PSTR("monitoring or hold"));
lcd_puts_at_P(0, 2, PSTR("the knob to continue"));
while (no_response) {
i++;
t++;
delay_keep_alive(100);
proc_commands();
if (t == 10) {
prusa_statistics(important_status);
t = 0;
}
if (READ(BTN_ENC)) { //if button is not pressed
i = 0;
lcd_puts_at_P(0, 3, PSTR(" "));
}
if (i != 0)
lcd_putc_at((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, LCD_STR_SOLID_BLOCK[0]);
if (i == NC_BUTTON_LONG_PRESS * 10)
no_response = false;
}
lcd_update_enable(true);
lcd_update(2);
}
#endif //FARM_CONNECT_MESSAGE
static void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
if (farm_mode) {
bool empty = cmd_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;
}
else {
printer_connected = true;
}
}
}
void prusa_statistics(uint8_t _message) {
const uint8_t _fil_nr = 0;
if (!farm_mode)
return;
switch (_message) {
case 0: // default message
if (busy_state == PAUSED_FOR_USER) {
prusa_statistics_case0(15);
}
else if (isPrintPaused) {
prusa_statistics_case0(14);
}
else if (IS_SD_PRINTING || loading_flag) {
prusa_statistics_case0(4);
}
else {
SERIAL_ECHO('{');
prusa_stat_printerstatus(1);
prusa_stat_farm_number();
prusa_stat_diameter();
status_number = 1;
}
break;
case 1: // 1 heating
SERIAL_ECHO('{');
prusa_stat_printerstatus(2);
prusa_stat_farm_number();
status_number = 2;
farm_timer = 1;
break;
case 2: // heating done
SERIAL_ECHO('{');
prusa_stat_printerstatus(3);
prusa_stat_farm_number();
SERIAL_ECHOLN('}');
status_number = 3;
farm_timer = 1;
if (IS_SD_PRINTING || loading_flag) {
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_ECHOPGM("{[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_ECHOPGM("{[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_ECHOPGM("{[PRN:8]");
prusa_stat_farm_number();
status_number = 8;
farm_timer = 2;
break;
case 7: // print done - stopped
SERIAL_ECHOPGM("{[PRN:9]");
prusa_stat_farm_number();
status_number = 9;
farm_timer = 2;
break;
case 8: // printer started
SERIAL_ECHOPGM("{[PRN:0]");
prusa_stat_farm_number();
status_number = 0;
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_ECHOPGM("{[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_ECHOPGM("{[PRN:99]");
prusa_stat_temperatures();
prusa_stat_farm_number();
break;
}
SERIAL_ECHOLN('}');
}
void prusa_statistics_update_from_status_screen() {
if (farm_mode) {
farm_timer--;
if (farm_timer < 1) {
farm_timer = 10;
prusa_statistics(0);
}
switch (farm_timer) {
case 8:
prusa_statistics(21);
if(loading_flag)
prusa_statistics(22);
break;
case 5:
if (IS_SD_PRINTING)
prusa_statistics(20);
break;
}
}
}
void prusa_statistics_update_from_lcd_update() {
lcd_ping(); //check that we have received ping command if we are in farm mode
lcd_send_status();
}
void farm_mode_init() {
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
//to be converted to Filament_sensor.h...
//disabled filament autoload (PFW360)
fsensor_autoload_set(false);
#endif //FILAMENT_SENSOR
// ~ FanCheck -> on
eeprom_update_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED, true);
}
}
bool farm_prusa_code_seen() {
if (!farm_mode)
return false;
if (code_seen_P(PSTR("Ping"))) { // PRUSA Ping
PingTime = _millis();
}
else if (code_seen_P(PSTR("PRN"))) { // PRUSA PRN
printf_P(_N("%u"), status_number);
}
else if (code_seen_P(PSTR("thx"))) { // PRUSA thx
no_response = false;
}
else {
return false;
}
return true;
}
void farm_gcode_g98() {
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
}
void farm_gcode_g99() {
farm_mode = 0;
printer_connected = true;
eeprom_update_byte((unsigned char *)EEPROM_FARM_MODE, farm_mode);
lcd_update(2);
fCheckModeInit(); // alternatively invoke printer reset
}
#else //PRUSA_FARM
void prusa_statistics(_UNUSED uint8_t message) {
}
void prusa_statistics_update_from_status_screen() {
}
void prusa_statistics_update_from_lcd_update() {
}
void farm_mode_init() {
}
bool farm_prusa_code_seen() {
return false;
}
void farm_gcode_g98() {
}
void farm_gcode_g99() {
}
#endif //PRUSA_FARM

View file

@ -7,5 +7,12 @@
extern uint8_t farm_mode;
#else
#define farm_mode 0
#error prusa_farm_include_error
#endif
extern void prusa_statistics(uint8_t _message);
extern void prusa_statistics_update_from_status_screen();
extern void prusa_statistics_update_from_lcd_update();
extern void farm_mode_init();
extern bool farm_prusa_code_seen();
extern void farm_gcode_g98();
extern void farm_gcode_g99();

View file

@ -368,16 +368,6 @@ void repeatcommand_front()
cmdbuffer_front_already_processed = true;
}
void proc_commands() {
if (buflen)
{
process_commands();
if (!cmdbuffer_front_already_processed)
cmdqueue_pop_front();
cmdbuffer_front_already_processed = false;
}
}
void get_command()
{
// Test and reserve space for the new command string.

View file

@ -1041,10 +1041,8 @@ static void temp_runaway_stop(bool isPreheat, bool isBed)
SERIAL_ERRORLNPGM(" HOTEND THERMAL RUNAWAY");
}
}
if (farm_mode) {
prusa_statistics(0);
prusa_statistics(isPreheat? 91 : 90);
}
prusa_statistics(0);
prusa_statistics(isPreheat? 91 : 90);
}
ThermalStop();
}
@ -1076,7 +1074,7 @@ static void temp_error_messagepgm(const char* PROGMEM type, uint8_t e = EXTRUDER
static void max_temp_error(uint8_t e) {
if(IsStopped() == false) {
temp_error_messagepgm(PSTR("MAXTEMP"), e);
if (farm_mode) prusa_statistics(93);
prusa_statistics(93);
}
#ifndef BOGUS_TEMPERATURE_FAILSAFE_OVERRIDE
ThermalStop();
@ -1087,7 +1085,7 @@ static void min_temp_error(uint8_t e) {
static const char err[] PROGMEM = "MINTEMP";
if(IsStopped() == false) {
temp_error_messagepgm(err, e);
if (farm_mode) prusa_statistics(92);
prusa_statistics(92);
}
ThermalStop();
}

View file

@ -56,7 +56,6 @@
#include "Prusa_farm.h"
int clock_interval = 0;
static ShortTimer NcTime;
static void lcd_sd_updir();
static void lcd_mesh_bed_leveling_settings();
#ifdef LCD_BL_PIN
@ -82,8 +81,6 @@ CustomMsg custom_message_type = CustomMsg::Status;
uint8_t custom_message_state = 0;
bool isPrintPaused = false;
uint8_t farm_timer = 8;
bool printer_connected = true;
static ShortTimer display_time; //just timer for showing pid finished message on lcd;
static uint16_t pid_temp = DEFAULT_PID_TEMP;
@ -125,11 +122,6 @@ static void lcd_control_temperature_menu();
#ifdef TMC2130
static void lcd_settings_linearity_correction_menu_save();
#endif
static void prusa_stat_printerstatus(uint8_t _status);
static void prusa_stat_farm_number();
static void prusa_stat_diameter();
static void prusa_stat_temperatures();
static void prusa_stat_printinfo();
static void lcd_menu_xyz_y_min();
static void lcd_menu_xyz_skew();
static void lcd_menu_xyz_offset();
@ -249,10 +241,6 @@ static void lcd_cutter_enabled();
static void lcd_sort_type_set();
#endif
static void lcd_babystep_z();
static void lcd_send_status();
#ifdef FARM_CONNECT_MESSAGE
static void lcd_connect_printer();
#endif //FARM_CONNECT_MESSAGE
//! Beware: has side effects - forces lcd_draw_update to 2, which means clear the display
void lcd_finishstatus();
@ -820,27 +808,7 @@ void lcd_status_screen() // NOT static due to using ins
lcdui_print_status_screen();
if (farm_mode)
{
farm_timer--;
if (farm_timer < 1)
{
farm_timer = 10;
prusa_statistics(0);
}
switch (farm_timer)
{
case 8:
prusa_statistics(21);
if(loading_flag)
prusa_statistics(22);
break;
case 5:
if (IS_SD_PRINTING)
prusa_statistics(20);
break;
}
} // end of farm_mode
prusa_statistics_update_from_status_screen();
if (lcd_commands_type != LcdCommands::Idle)
lcd_commands();
@ -3568,321 +3536,6 @@ void lcd_menu_show_sensors_state() // NOT static due to using ins
menu_back_if_clicked();
}
void prusa_statistics_err(char c){
SERIAL_ECHOPGM("{[ERR:");
SERIAL_ECHO(c);
SERIAL_ECHO(']');
prusa_stat_farm_number();
}
static void prusa_statistics_case0(uint8_t statnr){
SERIAL_ECHO('{');
prusa_stat_printerstatus(statnr);
prusa_stat_farm_number();
prusa_stat_printinfo();
}
void prusa_statistics(uint8_t _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)
{
prusa_statistics_case0(15);
}
else if (isPrintPaused)
{
prusa_statistics_case0(14);
}
else if (IS_SD_PRINTING || loading_flag)
{
prusa_statistics_case0(4);
}
else
{
SERIAL_ECHO('{');
prusa_stat_printerstatus(1);
prusa_stat_farm_number();
prusa_stat_diameter();
status_number = 1;
}
break;
case 1: // 1 heating
SERIAL_ECHO('{');
prusa_stat_printerstatus(2);
prusa_stat_farm_number();
status_number = 2;
farm_timer = 1;
break;
case 2: // heating done
SERIAL_ECHO('{');
prusa_stat_printerstatus(3);
prusa_stat_farm_number();
SERIAL_ECHOLN('}');
status_number = 3;
farm_timer = 1;
if (IS_SD_PRINTING || loading_flag)
{
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_ECHOPGM("{[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_ECHOPGM("{[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_ECHOPGM("{[PRN:8]");
prusa_stat_farm_number();
status_number = 8;
farm_timer = 2;
break;
case 7: // print done - stopped
SERIAL_ECHOPGM("{[PRN:9]");
prusa_stat_farm_number();
status_number = 9;
farm_timer = 2;
break;
case 8: // printer started
SERIAL_ECHOPGM("{[PRN:0]");
prusa_stat_farm_number();
status_number = 0;
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_ECHOPGM("{[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_ECHOPGM("{[PRN:99]");
prusa_stat_temperatures();
prusa_stat_farm_number();
break;
}
SERIAL_ECHOLN('}');
}
static void prusa_stat_printerstatus(uint8_t _status)
{
SERIAL_ECHOPGM("[PRN:");
SERIAL_ECHO(_status);
SERIAL_ECHO(']');
}
static void prusa_stat_farm_number() {
SERIAL_ECHOPGM("[PFN:0]");
}
static void prusa_stat_diameter() {
SERIAL_ECHOPGM("[DIA:");
SERIAL_ECHO(eeprom_read_word((uint16_t*)EEPROM_NOZZLE_DIAMETER_uM));
SERIAL_ECHO(']');
}
static void prusa_stat_temperatures()
{
SERIAL_ECHOPGM("[ST0:");
SERIAL_ECHO(target_temperature[0]);
SERIAL_ECHOPGM("][STB:");
SERIAL_ECHO(target_temperature_bed);
SERIAL_ECHOPGM("][AT0:");
SERIAL_ECHO(current_temperature[0]);
SERIAL_ECHOPGM("][ATB:");
SERIAL_ECHO(current_temperature_bed);
SERIAL_ECHO(']');
}
static void prusa_stat_printinfo()
{
SERIAL_ECHOPGM("[TFU:");
SERIAL_ECHO(total_filament_used);
SERIAL_ECHOPGM("][PCD:");
SERIAL_ECHO(itostr3(card.percentDone()));
SERIAL_ECHOPGM("][FEM:");
SERIAL_ECHO(itostr3(feedmultiply));
SERIAL_ECHOPGM("][FNM:");
SERIAL_ECHO(card.longFilename[0] ? card.longFilename : card.filename);
SERIAL_ECHOPGM("][TIM:");
if (starttime != 0)
{
SERIAL_ECHO(_millis() / 1000 - starttime / 1000);
}
else
{
SERIAL_ECHO(0);
}
SERIAL_ECHOPGM("][FWR:");
SERIAL_ECHORPGM(FW_VERSION_STR_P());
SERIAL_ECHO(']');
prusa_stat_diameter();
}
/*
void lcd_pick_babystep(){
int enc_dif = 0;
int cursor_pos = 1;
int fsm = 0;
lcd_clear();
lcd_set_cursor(0, 0);
lcd_puts_P(_i("Pick print"));////MSG_PICK_Z
lcd_set_cursor(3, 2);
lcd_print('1');
lcd_set_cursor(3, 3);
lcd_print('2');
lcd_set_cursor(12, 2);
lcd_print('3');
lcd_set_cursor(12, 3);
lcd_print('4');
lcd_set_cursor(1, 2);
lcd_print('>');
enc_dif = lcd_encoder_diff;
while (fsm == 0) {
manage_heater();
manage_inactivity(true);
if ( abs((enc_dif - lcd_encoder_diff)) > 4 ) {
if ( (abs(enc_dif - lcd_encoder_diff)) > 1 ) {
if (enc_dif > lcd_encoder_diff ) {
cursor_pos --;
}
if (enc_dif < lcd_encoder_diff ) {
cursor_pos ++;
}
if (cursor_pos > 4) {
cursor_pos = 4;
}
if (cursor_pos < 1) {
cursor_pos = 1;
}
lcd_set_cursor(1, 2);
lcd_print(' ');
lcd_set_cursor(1, 3);
lcd_print(' ');
lcd_set_cursor(10, 2);
lcd_print(' ');
lcd_set_cursor(10, 3);
lcd_print(' ');
if (cursor_pos < 3) {
lcd_set_cursor(1, cursor_pos+1);
lcd_print('>');
}else{
lcd_set_cursor(10, cursor_pos-1);
lcd_print('>');
}
enc_dif = lcd_encoder_diff;
_delay(100);
}
}
if (lcd_clicked()) {
fsm = cursor_pos;
int babyStepZ;
babyStepZ = eeprom_read_word((uint16_t*)EEPROM_BABYSTEP_Z0+(fsm-1));
eeprom_update_word((uint16_t*)EEPROM_BABYSTEP_Z, babyStepZ);
calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
_delay(500);
}
};
lcd_clear();
lcd_return_to_status();
}
*/
void lcd_move_menu_axis()
{
MENU_BEGIN();
@ -7910,71 +7563,6 @@ void ultralcd_init()
lcd_encoder_diff = 0;
}
void lcd_printer_connected() {
printer_connected = true;
}
static void lcd_send_status() {
if (farm_mode && no_response && (NcTime.expired(NC_TIME * 1000))) {
//send important status messages periodicaly
prusa_statistics(important_status, saved_filament_type);
NcTime.start();
#ifdef FARM_CONNECT_MESSAGE
lcd_connect_printer();
#endif //FARM_CONNECT_MESSAGE
}
}
#ifdef FARM_CONNECT_MESSAGE
static void lcd_connect_printer() {
lcd_update_enable(false);
lcd_clear();
int i = 0;
int t = 0;
lcd_puts_at_P(0, 0, _i("Connect printer to"));
lcd_puts_at_P(0, 1, _i("monitoring or hold"));
lcd_puts_at_P(0, 2, _i("the knob to continue"));
while (no_response) {
i++;
t++;
delay_keep_alive(100);
proc_commands();
if (t == 10) {
prusa_statistics(important_status, saved_filament_type);
t = 0;
}
if (READ(BTN_ENC)) { //if button is not pressed
i = 0;
lcd_puts_at_P(0, 3, PSTR(" "));
}
if (i!=0) lcd_puts_at_P((i * 20) / (NC_BUTTON_LONG_PRESS * 10), 3, LCD_STR_SOLID_BLOCK[0]);
if (i == NC_BUTTON_LONG_PRESS * 10) {
no_response = false;
}
}
lcd_update_enable(true);
lcd_update(2);
}
#endif //FARM_CONNECT_MESSAGE
void lcd_ping() { //chceck if printer is connected to monitoring when in farm mode
if (farm_mode) {
bool empty = cmd_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;
}
else {
lcd_printer_connected();
}
}
}
void lcd_ignore_click(bool b)
{
ignore_click = b;
@ -8220,8 +7808,7 @@ void menu_lcd_lcdupdate_func(void)
if (lcd_draw_update) lcd_draw_update--;
lcd_next_update_millis = _millis() + LCD_UPDATE_INTERVAL;
}
lcd_ping(); //check that we have received ping command if we are in farm mode
lcd_send_status();
prusa_statistics_update_from_lcd_update();
if (lcd_commands_type == LcdCommands::Layer1Cal) lcd_commands();
}

View file

@ -47,9 +47,7 @@ void lcd_pause_print();
void lcd_pause_usb_print();
void lcd_resume_print();
void lcd_print_stop();
void prusa_statistics(uint8_t _message, uint8_t _col_nr = 0);
void lcd_load_filament_color_check();
//void lcd_mylang();
extern void lcd_belttest();
extern bool lcd_selftest();
@ -187,8 +185,6 @@ void mFilamentItemForce();
void lcd_generic_preheat_menu();
void unload_filament(bool automatic = false);
void lcd_printer_connected();
void lcd_ping();
void lcd_wait_for_heater();
void lcd_wait_for_cool_down();

View file

@ -151,7 +151,6 @@
//#define DEBUG_DISABLE_SWLIMITS //sw limits ignored
//#define DEBUG_DISABLE_LCD_STATUS_LINE //empty four lcd line
//#define DEBUG_DISABLE_PREVENT_EXTRUDER //cold extrusion and long extrusion allowed
//#define DEBUG_DISABLE_PRUSA_STATISTICS //disable prusa_statistics() mesages
//#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3)
//#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3)
//#define DEBUG_DISABLE_FANCHECK //disable fan check (no ISR INT7, check disabled)
@ -494,13 +493,6 @@
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release

View file

@ -152,7 +152,6 @@
//#define DEBUG_DISABLE_SWLIMITS //sw limits ignored
//#define DEBUG_DISABLE_LCD_STATUS_LINE //empty four lcd line
//#define DEBUG_DISABLE_PREVENT_EXTRUDER //cold extrusion and long extrusion allowed
//#define DEBUG_DISABLE_PRUSA_STATISTICS //disable prusa_statistics() mesages
//#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3)
//#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3)
//#define DEBUG_DISABLE_FANCHECK //disable fan check (no ISR INT7, check disabled)
@ -495,13 +494,6 @@
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release

View file

@ -151,7 +151,6 @@
//#define DEBUG_DISABLE_SWLIMITS //sw limits ignored
//#define DEBUG_DISABLE_LCD_STATUS_LINE //empty four lcd line
//#define DEBUG_DISABLE_PREVENT_EXTRUDER //cold extrusion and long extrusion allowed
//#define DEBUG_DISABLE_PRUSA_STATISTICS //disable prusa_statistics() mesages
//#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3)
//#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3)
//#define DEBUG_DISABLE_FANCHECK //disable fan check (no ISR INT7, check disabled)
@ -494,13 +493,6 @@
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release

View file

@ -152,7 +152,6 @@
//#define DEBUG_DISABLE_SWLIMITS //sw limits ignored
//#define DEBUG_DISABLE_LCD_STATUS_LINE //empty four lcd line
//#define DEBUG_DISABLE_PREVENT_EXTRUDER //cold extrusion and long extrusion allowed
//#define DEBUG_DISABLE_PRUSA_STATISTICS //disable prusa_statistics() mesages
//#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3)
//#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3)
//#define DEBUG_DISABLE_FANCHECK //disable fan check (no ISR INT7, check disabled)
@ -495,13 +494,6 @@
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release

View file

@ -193,7 +193,6 @@
//#define DEBUG_DISABLE_SWLIMITS //sw limits ignored
//#define DEBUG_DISABLE_LCD_STATUS_LINE //empty four lcd line
//#define DEBUG_DISABLE_PREVENT_EXTRUDER //cold extrusion and long extrusion allowed
//#define DEBUG_DISABLE_PRUSA_STATISTICS //disable prusa_statistics() mesages
//#define DEBUG_DISABLE_FORCE_SELFTEST //disable force selftest
//#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3)
//#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3)
@ -531,9 +530,6 @@
// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
#endif // PIDTEMPBED
//connect message when communication with monitoring broken
//#define FARM_CONNECT_MESSAGE
/*-----------------------------------
PREHEAT SETTINGS
*------------------------------------*/
@ -653,13 +649,6 @@
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release

View file

@ -195,7 +195,6 @@
//#define DEBUG_DISABLE_SWLIMITS //sw limits ignored
//#define DEBUG_DISABLE_LCD_STATUS_LINE //empty four lcd line
//#define DEBUG_DISABLE_PREVENT_EXTRUDER //cold extrusion and long extrusion allowed
//#define DEBUG_DISABLE_PRUSA_STATISTICS //disable prusa_statistics() mesages
//#define DEBUG_DISABLE_FORCE_SELFTEST //disable force selftest
//#define DEBUG_XSTEP_DUP_PIN 21 //duplicate x-step output to pin 21 (SCL on P3)
//#define DEBUG_YSTEP_DUP_PIN 21 //duplicate y-step output to pin 21 (SCL on P3)
@ -535,9 +534,6 @@
// FIND YOUR OWN: "M303 E-1 C8 S90" to run autotune on the bed at 90 degreesC for 8 cycles.
#endif // PIDTEMPBED
//connect message when communication with monitoring broken
//#define FARM_CONNECT_MESSAGE
/*-----------------------------------
PREHEAT SETTINGS
*------------------------------------*/
@ -657,13 +653,6 @@
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release

View file

@ -419,19 +419,11 @@ THERMISTORS SETTINGS
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release
#define DEFAULT_PID_TEMP 210
#define END_FILE_SECTION 20000 //number of bytes from end of file used for checking if file is complete
// Safety timer

View file

@ -408,19 +408,11 @@ THERMISTORS SETTINGS
#define PINDA_STEP_T 10
#define PINDA_MAX_T 100
#define PING_TIME 60 //time in s
#define PING_TIME_LONG 600 //10 min; used when length of commands buffer > 0 to avoid 0 triggering when dealing with long gcodes
#define PING_ALLERT_PERIOD 60 //time in s
#define NC_TIME 10 //time in s for periodic important status messages sending which needs reponse from monitoring
#define NC_BUTTON_LONG_PRESS 15 //time in s
#define LONG_PRESS_TIME 1000 //time in ms for button long press
#define BUTTON_BLANKING_TIME 200 //time in ms for blanking after button release
#define DEFAULT_PID_TEMP 210
#define END_FILE_SECTION 20000 //number of bytes from end of file used for checking if file is complete
// Safety timer