Merge remote-tracking branch 'upstream/MK3' into fix_longpress_isr

This commit is contained in:
Yuri D'Elia 2021-06-21 11:51:45 +02:00
commit edde002cdc
13 changed files with 143 additions and 103 deletions

View file

@ -454,10 +454,13 @@ static void print_time_remaining_init();
static void wait_for_heater(long codenum, uint8_t extruder);
static void gcode_G28(bool home_x_axis, bool home_y_axis, bool home_z_axis);
static void gcode_M105(uint8_t extruder);
#ifndef PINDA_THERMISTOR
static void temp_compensation_start();
static void temp_compensation_apply();
#endif
static bool get_PRUSA_SN(char* SN);
static uint8_t get_PRUSA_SN(char* SN);
uint16_t gcode_in_progress = 0;
uint16_t mcode_in_progress = 0;
@ -741,7 +744,7 @@ static void factory_reset(char level)
case 2: // Level 2: Prepare for shipping
factory_reset_stats();
// [[fallthrough]] // there is no break intentionally
// FALLTHRU
case 3: // Level 3: Preparation after being serviced
// Force language selection at the next boot up.
@ -1071,18 +1074,21 @@ void setup()
}
#endif //TMC2130
//saved EEPROM SN is not valid. Try to retrieve it.
//SN is valid only if it is NULL terminated. Any other character means either uninitialized or corrupted
if (eeprom_read_byte((uint8_t*)EEPROM_PRUSA_SN + 19))
//Check for valid SN in EEPROM. Try to retrieve it in case it's invalid.
//SN is valid only if it is NULL terminated and starts with "CZPX".
{
char SN[20];
if (get_PRUSA_SN(SN))
eeprom_read_block(SN, (uint8_t*)EEPROM_PRUSA_SN, 20);
if (SN[19] || strncmp_P(SN, PSTR("CZPX"), 4))
{
eeprom_update_block(SN, (uint8_t*)EEPROM_PRUSA_SN, 20);
puts_P(PSTR("SN updated"));
if (!get_PRUSA_SN(SN))
{
eeprom_update_block(SN, (uint8_t*)EEPROM_PRUSA_SN, 20);
puts_P(PSTR("SN updated"));
}
else
puts_P(PSTR("SN update failed"));
}
else
puts_P(PSTR("SN update failed"));
}
@ -1727,6 +1733,32 @@ void serial_read_stream() {
}
}
/**
* Output autoreport values according to features requested in M155
*/
#if defined(AUTO_REPORT)
static void host_autoreport()
{
if (autoReportFeatures.TimerExpired())
{
if(autoReportFeatures.Temp()){
gcode_M105(active_extruder);
}
if(autoReportFeatures.Pos()){
gcode_M114();
}
#if defined(AUTO_REPORT) && (defined(FANCHECK) && (((defined(TACH_0) && (TACH_0 >-1)) || (defined(TACH_1) && (TACH_1 > -1)))))
if(autoReportFeatures.Fans()){
gcode_M123();
}
#endif //AUTO_REPORT and (FANCHECK and TACH_0 or TACH_1)
autoReportFeatures.TimerStart();
}
}
#endif //AUTO_REPORT
/**
* Output a "busy" message at regular intervals
* while the machine is not accepting commands.
@ -1738,27 +1770,6 @@ void host_keepalive() {
if (farm_mode) return;
long ms = _millis();
#if defined(AUTO_REPORT)
{
if (autoReportFeatures.TimerExpired())
{
if(autoReportFeatures.Temp()){
gcode_M105(active_extruder);
}
if(autoReportFeatures.Pos()){
gcode_M114();
}
#if defined(AUTO_REPORT) && (defined(FANCHECK) && (((defined(TACH_0) && (TACH_0 >-1)) || (defined(TACH_1) && (TACH_1 > -1)))))
if(autoReportFeatures.Fans()){
gcode_M123();
}
#endif //AUTO_REPORT and (FANCHECK and TACH_0 or TACH_1)
autoReportFeatures.TimerStart();
}
}
#endif //AUTO_REPORT
if (host_keepalive_interval && busy_state != NOT_BUSY) {
if ((ms - prev_busy_signal_ms) < (long)(1000L * host_keepalive_interval)) return;
switch (busy_state) {
@ -3493,11 +3504,13 @@ bool gcode_M45(bool onlyZ, int8_t verbosity_level)
bool result = sample_mesh_and_store_reference();
if (result)
{
if (calibration_status() == CALIBRATION_STATUS_Z_CALIBRATION)
// Shipped, the nozzle height has been set already. The user can start printing now.
calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
final_result = true;
// babystep_apply();
if (calibration_status() == CALIBRATION_STATUS_Z_CALIBRATION)
{
// Shipped, the nozzle height has been set already. The user can start printing now.
calibration_status_store(CALIBRATION_STATUS_CALIBRATED);
}
final_result = true;
// babystep_apply();
}
}
else
@ -3823,33 +3836,47 @@ void gcode_M701()
*
* Send command ;S to serial port 0 to retrieve serial number stored in 32U2 processor,
* reply is stored in *SN.
* Operation takes typically 23 ms. If the retransmit is not finished until 100 ms,
* it is interrupted, so less, or no characters are retransmitted, the function returns false
* Operation takes typically 23 ms. If no valid SN can be retrieved within the 250ms window, the function aborts
* and returns a general failure flag.
* The command will fail if the 32U2 processor is unpowered via USB since it is isolated from the rest of the electronics.
* In that case the value that is stored in the EEPROM should be used instead.
*
* @return 1 on success
* @return 0 on general failure
* @return 0 on success
* @return 1 on general failure
*/
static bool get_PRUSA_SN(char* SN)
static uint8_t get_PRUSA_SN(char* SN)
{
uint8_t selectedSerialPort_bak = selectedSerialPort;
selectedSerialPort = 0;
SERIAL_ECHOLNRPGM(PSTR(";S"));
uint8_t numbersRead = 0;
uint8_t rxIndex;
bool SN_valid = false;
ShortTimer timeout;
timeout.start();
while (numbersRead < 19) {
if (MSerial.available() > 0) {
SN[numbersRead] = MSerial.read();
numbersRead++;
selectedSerialPort = 0;
timeout.start();
while (!SN_valid)
{
rxIndex = 0;
_delay(50);
MYSERIAL.flush(); //clear RX buffer
SERIAL_ECHOLNRPGM(PSTR(";S"));
while (rxIndex < 19)
{
if (timeout.expired(250u))
goto exit;
if (MYSERIAL.available() > 0)
{
SN[rxIndex] = MYSERIAL.read();
rxIndex++;
}
}
if (timeout.expired(100u)) break;
SN[rxIndex] = 0;
// printf_P(PSTR("SN:%s\n"), SN);
SN_valid = (strncmp_P(SN, PSTR("CZPX"), 4) == 0);
}
SN[numbersRead] = 0;
exit:
selectedSerialPort = selectedSerialPort_bak;
return (numbersRead == 19);
return !SN_valid;
}
//! Detection of faulty RAMBo 1.1b boards equipped with bigger capacitors
//! at the TACH_1 pin, which causes bad detection of print fan speed.
@ -8841,7 +8868,7 @@ Sigma_Exit:
bool load_to_nozzle = false;
for (index = 1; *(strchr_pointer + index) == ' ' || *(strchr_pointer + index) == '\t'; index++);
*(strchr_pointer + index) = tolower(*(strchr_pointer + index));
*(strchr_pointer + index) = tolower(*(strchr_pointer + index));
if ((*(strchr_pointer + index) < '0' || *(strchr_pointer + index) > '4') && *(strchr_pointer + index) != '?' && *(strchr_pointer + index) != 'x' && *(strchr_pointer + index) != 'c') {
SERIAL_ECHOLNPGM("Invalid T code.");
@ -9912,6 +9939,11 @@ if(0)
lcd_longpress_trigger = 0;
}
}
#if defined(AUTO_REPORT)
host_autoreport();
#endif //AUTO_REPORT
host_keepalive();
}
void kill(const char *full_screen_message, unsigned char id)