PRUSA SN in eeprom

This commit is contained in:
Voinea Dragos 2021-01-14 11:52:22 +02:00
parent b71f1be37a
commit dea3f23a69
2 changed files with 33 additions and 9 deletions

View file

@ -407,6 +407,7 @@ static void gcode_M105(uint8_t extruder);
static void temp_compensation_start();
static void temp_compensation_apply();
static bool get_PRUSA_SN(char* SN);
uint16_t gcode_in_progress = 0;
uint16_t mcode_in_progress = 0;
@ -1075,6 +1076,21 @@ void setup()
if(!(eeprom_read_byte((uint8_t*)EEPROM_FAN_CHECK_ENABLED)))
eeprom_update_byte((unsigned char *)EEPROM_FAN_CHECK_ENABLED,true);
}
if (eeprom_read_byte((uint8_t*)EEPROM_PRUSA_SN + 19)) //saved EEPROM SN is not valid. Try to retrieve it.
{
char SN[20];
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"));
}
#ifndef W25X20CL
SERIAL_PROTOCOLLNPGM("start");
#else
@ -3386,25 +3402,26 @@ void gcode_M701()
*
* Typical format of S/N is:CZPX0917X003XC13518
*
* Command operates only in farm mode, if not in farm mode, "Not in farm mode." is written to MYSERIAL.
*
* Send command ;S to serial port 0 to retrieve serial number stored in 32U2 processor,
* reply is transmitted to serial port 1 character by character.
* reply is transmitted to the selected serial port.
* Operation takes typically 23 ms. If the retransmit is not finished until 100 ms,
* it is interrupted, so less, or no characters are retransmitted, only newline character is send
* in any case.
* 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
*/
static void gcode_PRUSA_SN()
static bool get_PRUSA_SN(char* SN)
{
uint8_t selectedSerialPort_bak = selectedSerialPort;
char SN[20];
selectedSerialPort = 0;
SERIAL_ECHOLNRPGM(PSTR(";S"));
uint8_t numbersRead = 0;
ShortTimer timeout;
timeout.start();
while (numbersRead < (sizeof(SN) - 1)) {
while (numbersRead < 19) {
if (MSerial.available() > 0) {
SN[numbersRead] = MSerial.read();
numbersRead++;
@ -3413,7 +3430,7 @@ static void gcode_PRUSA_SN()
}
SN[numbersRead] = 0;
selectedSerialPort = selectedSerialPort_bak;
SERIAL_ECHOLN(SN);
return (numbersRead == 19);
}
//! Detection of faulty RAMBo 1.1b boards equipped with bigger capacitors
//! at the TACH_1 pin, which causes bad detection of print fan speed.
@ -3950,7 +3967,12 @@ void process_commands()
card.openFile(strchr_pointer+4,false);
} else if (code_seen("SN")) { // PRUSA SN
gcode_PRUSA_SN();
char SN[20];
eeprom_read_block(SN, (uint8_t*)EEPROM_PRUSA_SN, 20);
if (SN[19])
puts_P(PSTR("SN invalid"));
else
puts(SN);
} else if(code_seen("Fir")){ // PRUSA Fir