From 9c3e0aab36c55ae9983d3442ae26491f2a87149d Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Thu, 26 Apr 2018 18:55:08 +0200 Subject: [PATCH 1/3] M861 update: use signed values --- Firmware/Marlin_main.cpp | 57 +++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 1102e1114..a36843710 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1270,13 +1270,9 @@ void setup() if (eeprom_read_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA) == 255) { //eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0); eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 0, 0); //40C - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 1, 0); //45C - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 2, 0); //50C - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 3, 0); //55C - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 4, 0); //60C - - eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0); + int16_t z_shift = 0; + for (uint8_t i = 0; i < 5; i++) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); + eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0); temp_cal_active = false; } if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 255) { @@ -6332,14 +6328,15 @@ Sigma_Exit: break; } case 861: // M861 - Set/Read PINDA temperature compensation offsets - if (code_seen('?')) { // ? - Print out current EEPRO offset values + if (code_seen('?')) { // ? - Print out current EEPROM offset values uint8_t cal_status = calibration_status_pinda(); - cal_status ? SERIAL_PROTOCOLLN("PINDA cal status: 1") : SERIAL_PROTOCOLLN("PINDA cal status: 0"); + int16_t usteps = 0; + int16_t z_shift = 0; + cal_status ? SERIAL_PROTOCOLLN("PINDA cal status: 1") : SERIAL_PROTOCOLLN("PINDA cal status: 0"); SERIAL_PROTOCOLLN("index, temp, ustep, um"); - for (uint8_t i = 0; i < 6; i++) + for (uint8_t i = 0; i < 6; i++) { - uint16_t usteps = 0; - if (i > 0) usteps = eeprom_read_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + (i - 1)); + if(i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i-1) * 2, &usteps); float mm = ((float)usteps) / axis_steps_per_unit[Z_AXIS]; i == 0 ? SERIAL_PROTOCOLPGM("n/a") : SERIAL_PROTOCOL(i - 1); SERIAL_PROTOCOLPGM(", "); @@ -6351,36 +6348,36 @@ Sigma_Exit: SERIAL_PROTOCOLLN(""); } } - else if (code_seen('!')) { // ! - Set factory default values - eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 0, 8); //40C - 20um - 8usteps - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 1, 24); //45C - 60um - 24usteps - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 2, 48); //50C - 120um - 48usteps - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 3, 80); //55C - 200um - 80usteps - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 4, 120); //60C - 300um - 120usteps - SERIAL_PROTOCOLLN("factory restored"); - } + else if (code_seen('!')) { // ! - Set factory default values + eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); + z_shift = 8; //40C - 20um - 8usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT, &z_shift); + z_shift = 24; //45C - 60um - 24usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 2, &z_shift); + z_shift = 48; //50C - 120um - 48usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 4, &z_shift); + z_shift = 80; //55C - 200um - 80usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 6, &z_shift); + z_shift = 120; //60C - 300um - 120usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 8, &z_shift); + SERIAL_PROTOCOLLN("factory restored"); + } else if (code_seen('Z')) { // Z - Set all values to 0 (effectively disabling PINDA temperature compensation) eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 0, 0); - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 1, 0); - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 2, 0); - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 3, 0); - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + 4, 0); + for (uint8_t i = 0; i < 5; i++) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); SERIAL_PROTOCOLLN("zerorized"); } else if (code_seen('S')) { // Sxxx Iyyy - Set compensation ustep value S for compensation table index I - uint16_t usteps = code_value(); + usteps = code_value(); if (code_seen('I')) { byte index = code_value(); if ((index >= 0) && (index < 5)) { - eeprom_write_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + index, usteps); + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + index * 2, &usteps); SERIAL_PROTOCOLLN("OK"); SERIAL_PROTOCOLLN("index, temp, ustep, um"); for (uint8_t i = 0; i < 6; i++) { - uint16_t usteps = 0; - if (i > 0) usteps = eeprom_read_word(((uint16_t*)EEPROM_PROBE_TEMP_SHIFT) + (i - 1)); + if (i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i - 1) * 2, &usteps); float mm = ((float)usteps) / axis_steps_per_unit[Z_AXIS]; i == 0 ? SERIAL_PROTOCOLPGM("n/a") : SERIAL_PROTOCOL(i - 1); SERIAL_PROTOCOLPGM(", "); From 2dd0d84845876e1b6e3d3eeee04ba8ad6491343a Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Thu, 26 Apr 2018 19:14:28 +0200 Subject: [PATCH 2/3] M861: usteps and z_shift variables correction --- Firmware/Marlin_main.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a36843710..a7ee593d3 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -6328,10 +6328,9 @@ Sigma_Exit: break; } case 861: // M861 - Set/Read PINDA temperature compensation offsets - if (code_seen('?')) { // ? - Print out current EEPROM offset values + if (code_seen('?')) { // ? - Print out current EEPROM offset values uint8_t cal_status = calibration_status_pinda(); int16_t usteps = 0; - int16_t z_shift = 0; cal_status ? SERIAL_PROTOCOLLN("PINDA cal status: 1") : SERIAL_PROTOCOLLN("PINDA cal status: 0"); SERIAL_PROTOCOLLN("index, temp, ustep, um"); for (uint8_t i = 0; i < 6; i++) @@ -6350,7 +6349,7 @@ Sigma_Exit: } else if (code_seen('!')) { // ! - Set factory default values eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - z_shift = 8; //40C - 20um - 8usteps + int16_t z_shift = 8; //40C - 20um - 8usteps EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT, &z_shift); z_shift = 24; //45C - 60um - 24usteps EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 2, &z_shift); @@ -6364,11 +6363,12 @@ Sigma_Exit: } else if (code_seen('Z')) { // Z - Set all values to 0 (effectively disabling PINDA temperature compensation) eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); + int16_t z_shift = 0; for (uint8_t i = 0; i < 5; i++) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); SERIAL_PROTOCOLLN("zerorized"); } else if (code_seen('S')) { // Sxxx Iyyy - Set compensation ustep value S for compensation table index I - usteps = code_value(); + int16_t usteps = code_value(); if (code_seen('I')) { byte index = code_value(); if ((index >= 0) && (index < 5)) { From e7cf68e038aed4301d1b786b60101975145eb8f7 Mon Sep 17 00:00:00 2001 From: PavelSindler Date: Thu, 26 Apr 2018 19:27:07 +0200 Subject: [PATCH 3/3] whitespace --- Firmware/Marlin_main.cpp | 52 ++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index a7ee593d3..7eec062bf 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1270,9 +1270,9 @@ void setup() if (eeprom_read_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA) == 255) { //eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 0); eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - int16_t z_shift = 0; - for (uint8_t i = 0; i < 5; i++) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); - eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0); + int16_t z_shift = 0; + for (uint8_t i = 0; i < 5; i++) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); + eeprom_write_byte((uint8_t*)EEPROM_TEMP_CAL_ACTIVE, 0); temp_cal_active = false; } if (eeprom_read_byte((uint8_t*)EEPROM_UVLO) == 255) { @@ -6328,14 +6328,14 @@ Sigma_Exit: break; } case 861: // M861 - Set/Read PINDA temperature compensation offsets - if (code_seen('?')) { // ? - Print out current EEPROM offset values + if (code_seen('?')) { // ? - Print out current EEPROM offset values uint8_t cal_status = calibration_status_pinda(); - int16_t usteps = 0; - cal_status ? SERIAL_PROTOCOLLN("PINDA cal status: 1") : SERIAL_PROTOCOLLN("PINDA cal status: 0"); + int16_t usteps = 0; + cal_status ? SERIAL_PROTOCOLLN("PINDA cal status: 1") : SERIAL_PROTOCOLLN("PINDA cal status: 0"); SERIAL_PROTOCOLLN("index, temp, ustep, um"); - for (uint8_t i = 0; i < 6; i++) + for (uint8_t i = 0; i < 6; i++) { - if(i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i-1) * 2, &usteps); + if(i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i-1) * 2, &usteps); float mm = ((float)usteps) / axis_steps_per_unit[Z_AXIS]; i == 0 ? SERIAL_PROTOCOLPGM("n/a") : SERIAL_PROTOCOL(i - 1); SERIAL_PROTOCOLPGM(", "); @@ -6347,24 +6347,24 @@ Sigma_Exit: SERIAL_PROTOCOLLN(""); } } - else if (code_seen('!')) { // ! - Set factory default values - eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - int16_t z_shift = 8; //40C - 20um - 8usteps - EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT, &z_shift); - z_shift = 24; //45C - 60um - 24usteps - EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 2, &z_shift); - z_shift = 48; //50C - 120um - 48usteps - EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 4, &z_shift); - z_shift = 80; //55C - 200um - 80usteps - EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 6, &z_shift); - z_shift = 120; //60C - 300um - 120usteps - EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 8, &z_shift); - SERIAL_PROTOCOLLN("factory restored"); - } + else if (code_seen('!')) { // ! - Set factory default values + eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); + int16_t z_shift = 8; //40C - 20um - 8usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT, &z_shift); + z_shift = 24; //45C - 60um - 24usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 2, &z_shift); + z_shift = 48; //50C - 120um - 48usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 4, &z_shift); + z_shift = 80; //55C - 200um - 80usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 6, &z_shift); + z_shift = 120; //60C - 300um - 120usteps + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + 8, &z_shift); + SERIAL_PROTOCOLLN("factory restored"); + } else if (code_seen('Z')) { // Z - Set all values to 0 (effectively disabling PINDA temperature compensation) eeprom_write_byte((uint8_t*)EEPROM_CALIBRATION_STATUS_PINDA, 1); - int16_t z_shift = 0; - for (uint8_t i = 0; i < 5; i++) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); + int16_t z_shift = 0; + for (uint8_t i = 0; i < 5; i++) EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + i * 2, &z_shift); SERIAL_PROTOCOLLN("zerorized"); } else if (code_seen('S')) { // Sxxx Iyyy - Set compensation ustep value S for compensation table index I @@ -6372,12 +6372,12 @@ Sigma_Exit: if (code_seen('I')) { byte index = code_value(); if ((index >= 0) && (index < 5)) { - EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + index * 2, &usteps); + EEPROM_save_B(EEPROM_PROBE_TEMP_SHIFT + index * 2, &usteps); SERIAL_PROTOCOLLN("OK"); SERIAL_PROTOCOLLN("index, temp, ustep, um"); for (uint8_t i = 0; i < 6; i++) { - if (i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i - 1) * 2, &usteps); + if (i>0) EEPROM_read_B(EEPROM_PROBE_TEMP_SHIFT + (i - 1) * 2, &usteps); float mm = ((float)usteps) / axis_steps_per_unit[Z_AXIS]; i == 0 ? SERIAL_PROTOCOLPGM("n/a") : SERIAL_PROTOCOL(i - 1); SERIAL_PROTOCOLPGM(", ");