Skip to content

Commit

Permalink
Optimize G80 bed correction argument parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
leptun committed May 5, 2023
1 parent 0f97d5c commit 75d5d56
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions Firmware/Marlin_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2996,7 +2996,7 @@ static void gcode_G80()
babystep_apply(); // Apply Z height correction aka baby stepping before mesh bed leveing gets activated.
bool eeprom_bed_correction_valid = eeprom_read_byte((unsigned char*)EEPROM_BED_CORRECTION_VALID) == 1;
const constexpr uint8_t sides = 4;
int8_t correction[sides] = {0};
int8_t correction[sides];
for (uint8_t i = 0; i < sides; ++i) {
static const char codes[sides] PROGMEM = { 'L', 'R', 'F', 'B' };
static uint8_t *const eep_addresses[sides] PROGMEM = {
Expand All @@ -3005,23 +3005,21 @@ static void gcode_G80()
(uint8_t*)EEPROM_BED_CORRECTION_FRONT,
(uint8_t*)EEPROM_BED_CORRECTION_REAR,
};
if (code_seen(pgm_read_byte(&codes[i])))
{ // Verify value is within allowed range
if (code_seen(pgm_read_byte(&codes[i]))) {
// Verify value is within allowed range
int32_t temp = code_value_long();
if (labs(temp) > BED_ADJUSTMENT_UM_MAX) {
SERIAL_ERROR_START;
SERIAL_ECHOPGM("Excessive bed leveling correction: ");
SERIAL_ECHO(temp);
SERIAL_ECHOLNPGM(" microns");
printf_P(PSTR("%SExcessive bed leveling correction: %li microns\n"), errormagic, temp);
correction[i] = 0;
} else {
// Value is valid, save it
correction[i] = (int8_t)temp;
}
} else if (eeprom_bed_correction_valid)
} else if (eeprom_bed_correction_valid) {
correction[i] = (int8_t)eeprom_read_byte((uint8_t*)pgm_read_ptr(&eep_addresses[i]));
if (correction[i] == 0)
continue;
} else {
correction[i] = 0;
}
}
for (uint8_t row = 0; row < MESH_NUM_Y_POINTS; ++row) {
for (uint8_t col = 0; col < MESH_NUM_X_POINTS; ++col) {
Expand Down

0 comments on commit 75d5d56

Please sign in to comment.