Browse Source

Within applied to UBL

pull/1/head
Scott Lahteine 8 years ago
parent
commit
b19a15fa7f
  1. 20
      Marlin/G26_Mesh_Validation_Tool.cpp
  2. 14
      Marlin/SanityCheck.h
  3. 4
      Marlin/UBL.h
  4. 4
      Marlin/UBL_Bed_Leveling.cpp
  5. 32
      Marlin/UBL_G29.cpp

20
Marlin/G26_Mesh_Validation_Tool.cpp

@ -267,7 +267,7 @@
#endif
// TODO: Change this to use `position_is_reachable`
if (circle_x < (X_MIN_POS) || circle_x > (X_MAX_POS) || circle_y < (Y_MIN_POS) || circle_y > (Y_MAX_POS)) {
if (!WITHIN(circle_x, X_MIN_POS, X_MAX_POS) || !WITHIN(circle_y, Y_MIN_POS, Y_MAX_POS)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to print off the bed.");
goto LEAVE;
@ -638,7 +638,7 @@
if (code_seen('B')) {
bed_temp = code_value_float();
if (bed_temp < 15.0 || bed_temp > 140.0) {
if (!WITHIN(bed_temp, 15.0, 140.0)) {
SERIAL_PROTOCOLLNPGM("?Specified bed temperature not plausible.");
return UBL_ERR;
}
@ -648,7 +648,7 @@
if (code_seen('L')) {
layer_height = code_value_float();
if (layer_height < 0.0 || layer_height > 2.0) {
if (!WITHIN(layer_height, 0.0, 2.0)) {
SERIAL_PROTOCOLLNPGM("?Specified layer height not plausible.");
return UBL_ERR;
}
@ -657,7 +657,7 @@
if (code_seen('Q')) {
if (code_has_value()) {
retraction_multiplier = code_value_float();
if (retraction_multiplier < 0.05 || retraction_multiplier > 15.0) {
if (!WITHIN(retraction_multiplier, 0.05, 15.0)) {
SERIAL_PROTOCOLLNPGM("?Specified Retraction Multiplier not plausible.");
return UBL_ERR;
}
@ -670,7 +670,7 @@
if (code_seen('N')) {
nozzle = code_value_float();
if (nozzle < 0.1 || nozzle > 1.0) {
if (!WITHIN(nozzle, 0.1, 1.0)) {
SERIAL_PROTOCOLLNPGM("?Specified nozzle size not plausible.");
return UBL_ERR;
}
@ -687,7 +687,7 @@
else {
prime_flag++;
prime_length = code_value_float();
if (prime_length < 0.0 || prime_length > 25.0) {
if (!WITHIN(prime_length, 0.0, 25.0)) {
SERIAL_PROTOCOLLNPGM("?Specified prime length not plausible.");
return UBL_ERR;
}
@ -696,7 +696,7 @@
if (code_seen('F')) {
filament_diameter = code_value_float();
if (filament_diameter < 1.0 || filament_diameter > 4.0) {
if (!WITHIN(filament_diameter, 1.0, 4.0)) {
SERIAL_PROTOCOLLNPGM("?Specified filament size not plausible.");
return UBL_ERR;
}
@ -709,7 +709,7 @@
if (code_seen('H')) {
hotend_temp = code_value_float();
if (hotend_temp < 165.0 || hotend_temp > 280.0) {
if (!WITHIN(hotend_temp, 165.0, 280.0)) {
SERIAL_PROTOCOLLNPGM("?Specified nozzle temperature not plausible.");
return UBL_ERR;
}
@ -725,7 +725,7 @@
if (code_seen('X')) {
x_pos = code_value_float();
if (x_pos < X_MIN_POS || x_pos > X_MAX_POS) {
if (!WITHIN(x_pos, X_MIN_POS, X_MAX_POS)) {
SERIAL_PROTOCOLLNPGM("?Specified X coordinate not plausible.");
return UBL_ERR;
}
@ -734,7 +734,7 @@
if (code_seen('Y')) {
y_pos = code_value_float();
if (y_pos < Y_MIN_POS || y_pos > Y_MAX_POS) {
if (!WITHIN(y_pos, Y_MIN_POS, Y_MAX_POS)) {
SERIAL_PROTOCOLLNPGM("?Specified Y coordinate not plausible.");
return UBL_ERR;
}

14
Marlin/SanityCheck.h

@ -598,19 +598,19 @@ static_assert(1 >= 0
#elif ENABLED(AUTO_BED_LEVELING_UBL)
#if DISABLED(EEPROM_SETTINGS)
#error "AUTO_BED_LEVELING_UBL requires EEPROM_SETTINGS. Please update your configuration."
#elif UBL_MESH_NUM_X_POINTS < 3 || UBL_MESH_NUM_X_POINTS > 15 || UBL_MESH_NUM_Y_POINTS < 3 || UBL_MESH_NUM_Y_POINTS > 15
#elif !WITHIN(UBL_MESH_NUM_X_POINTS, 3, 15) || !WITHIN(UBL_MESH_NUM_Y_POINTS, 3, 15)
#error "UBL_MESH_NUM_[XY]_POINTS must be a whole number between 3 and 15."
#elif UBL_PROBE_PT_1_X < MIN_PROBE_X || UBL_PROBE_PT_1_X > MAX_PROBE_X
#elif !WITHIN(UBL_PROBE_PT_1_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given UBL_PROBE_PT_1_X can't be reached by the Z probe."
#elif UBL_PROBE_PT_2_X < MIN_PROBE_X || UBL_PROBE_PT_2_X > MAX_PROBE_X
#elif !WITHIN(UBL_PROBE_PT_2_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given UBL_PROBE_PT_2_X can't be reached by the Z probe."
#elif UBL_PROBE_PT_3_X < MIN_PROBE_X || UBL_PROBE_PT_3_X > MAX_PROBE_X
#elif !WITHIN(UBL_PROBE_PT_3_X, MIN_PROBE_X, MAX_PROBE_X)
#error "The given UBL_PROBE_PT_3_X can't be reached by the Z probe."
#elif UBL_PROBE_PT_1_Y < MIN_PROBE_Y || UBL_PROBE_PT_1_Y > MAX_PROBE_Y
#elif !WITHIN(UBL_PROBE_PT_1_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given UBL_PROBE_PT_1_Y can't be reached by the Z probe."
#elif UBL_PROBE_PT_2_Y < MIN_PROBE_Y || UBL_PROBE_PT_2_Y > MAX_PROBE_Y
#elif !WITHIN(UBL_PROBE_PT_2_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given UBL_PROBE_PT_2_Y can't be reached by the Z probe."
#elif UBL_PROBE_PT_3_Y < MIN_PROBE_Y || UBL_PROBE_PT_3_Y > MAX_PROBE_Y
#elif !WITHIN(UBL_PROBE_PT_3_Y, MIN_PROBE_Y, MAX_PROBE_Y)
#error "The given UBL_PROBE_PT_3_Y can't be reached by the Z probe."
#endif
#else // AUTO_BED_LEVELING_3POINT

4
Marlin/UBL.h

@ -169,12 +169,12 @@
static int8_t find_closest_x_index(const float &x) {
const int8_t px = (x - (UBL_MESH_MIN_X) + (MESH_X_DIST) * 0.5) * (1.0 / (MESH_X_DIST));
return (px >= 0 && px < (UBL_MESH_NUM_X_POINTS)) ? px : -1;
return WITHIN(px, 0, UBL_MESH_NUM_X_POINTS - 1) ? px : -1;
}
static int8_t find_closest_y_index(const float &y) {
const int8_t py = (y - (UBL_MESH_MIN_Y) + (MESH_Y_DIST) * 0.5) * (1.0 / (MESH_Y_DIST));
return (py >= 0 && py < (UBL_MESH_NUM_Y_POINTS)) ? py : -1;
return WITHIN(py, 0, UBL_MESH_NUM_Y_POINTS - 1) ? py : -1;
}
/**

4
Marlin/UBL_Bed_Leveling.cpp

@ -118,7 +118,7 @@
return;
}
if (m < 0 || m >= j || eeprom_start <= 0) {
if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
return;
}
@ -133,7 +133,7 @@
void unified_bed_leveling::store_mesh(const int16_t m) {
int16_t j = (UBL_LAST_EEPROM_INDEX - eeprom_start) / sizeof(z_values);
if (m < 0 || m >= j || eeprom_start <= 0) {
if (!WITHIN(m, 0, j - 1) || eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available to load mesh.\n");
SERIAL_PROTOCOL(m);
SERIAL_PROTOCOLLNPGM(" mesh slots available.\n");

32
Marlin/UBL_G29.cpp

@ -341,7 +341,7 @@
if (code_seen('Q')) {
const int test_pattern = code_has_value() ? code_value_int() : -1;
if (test_pattern < 0 || test_pattern > 2) {
if (!WITHIN(test_pattern, 0, 2)) {
SERIAL_PROTOCOLLNPGM("Invalid test_pattern value. (0-2)\n");
return;
}
@ -374,7 +374,7 @@
/*
if (code_seen('U')) {
unlevel_value = code_value_int();
//if (unlevel_value < 0 || unlevel_value > 7) {
//if (!WITHIN(unlevel_value, 0, 7)) {
// SERIAL_PROTOCOLLNPGM("Invalid Unlevel value. (0-4)\n");
// return;
//}
@ -383,7 +383,7 @@
if (code_seen('P')) {
phase_value = code_value_int();
if (phase_value < 0 || phase_value > 7) {
if (!WITHIN(phase_value, 0, 7)) {
SERIAL_PROTOCOLLNPGM("Invalid Phase value. (0-4)\n");
return;
}
@ -566,7 +566,7 @@
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return;
}
@ -600,7 +600,7 @@
const int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(ubl.z_values);
if (storage_slot < 0 || storage_slot >= j || ubl.eeprom_start <= 0) {
if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
SERIAL_PROTOCOLLNPAIR("?Use 0 to ", j - 1);
goto LEAVE;
@ -760,7 +760,7 @@
rawy = ubl.mesh_index_to_ypos[location.y_index];
// TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
if (rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y)) {
if (!WITHIN(rawx, MIN_PROBE_X, MAX_PROBE_X) || !WITHIN(rawy, MIN_PROBE_Y, MAX_PROBE_Y)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
ubl.has_control_of_lcd_panel = false;
@ -910,7 +910,7 @@
rawy = ubl.mesh_index_to_ypos[location.y_index];
// TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) {
if (!WITHIN(rawx, X_MIN_POS, X_MAX_POS) || !WITHIN(rawy, Y_MIN_POS, Y_MAX_POS)) {
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to probe off the bed.");
ubl.has_control_of_lcd_panel = false;
@ -982,21 +982,21 @@
#endif
g29_verbose_level = code_seen('V') ? code_value_int() : 0;
if (g29_verbose_level < 0 || g29_verbose_level > 4) {
if (!WITHIN(g29_verbose_level, 0, 4)) {
SERIAL_PROTOCOLLNPGM("Invalid Verbose Level specified. (0-4)\n");
return UBL_ERR;
}
x_flag = code_seen('X') && code_has_value();
x_pos = x_flag ? code_value_float() : current_position[X_AXIS];
if (x_pos < LOGICAL_X_POSITION(X_MIN_POS) || x_pos > LOGICAL_X_POSITION(X_MAX_POS)) {
if (!WITHIN(RAW_X_POSITION(x_pos), X_MIN_POS, X_MAX_POS)) {
SERIAL_PROTOCOLLNPGM("Invalid X location specified.\n");
return UBL_ERR;
}
y_flag = code_seen('Y') && code_has_value();
y_pos = y_flag ? code_value_float() : current_position[Y_AXIS];
if (y_pos < LOGICAL_Y_POSITION(Y_MIN_POS) || y_pos > LOGICAL_Y_POSITION(Y_MAX_POS)) {
if (!WITHIN(RAW_Y_POSITION(y_pos), Y_MIN_POS, Y_MAX_POS)) {
SERIAL_PROTOCOLLNPGM("Invalid Y location specified.\n");
return UBL_ERR;
}
@ -1024,7 +1024,7 @@
#if ENABLED(ENABLE_LEVELING_FADE_HEIGHT)
if (code_seen('F') && code_has_value()) {
const float fh = code_value_float();
if (fh < 0.0 || fh > 100.0) {
if (!WITHIN(fh, 0.0, 100.0)) {
SERIAL_PROTOCOLLNPGM("?Bed Level Correction Fade Height Not Plausible.\n");
return UBL_ERR;
}
@ -1041,7 +1041,7 @@
}
map_type = code_seen('O') && code_has_value() ? code_value_int() : 0;
if (map_type < 0 || map_type > 1) {
if (!WITHIN(map_type, 0, 1)) {
SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
return UBL_ERR;
}
@ -1049,7 +1049,7 @@
/*
if (code_seen('M')) { // Check if a map type was specified
map_type = code_has_value() ? code_value_int() : 0;
if (map_type < 0 || map_type > 1) {
if (!WITHIN(map_type, 0, 1)) {
SERIAL_PROTOCOLLNPGM("Invalid map type.\n");
return UBL_ERR;
}
@ -1249,7 +1249,7 @@
int16_t j = (UBL_LAST_EEPROM_INDEX - ubl.eeprom_start) / sizeof(tmp_z_values);
if (storage_slot < 0 || storage_slot > j || ubl.eeprom_start <= 0) {
if (!WITHIN(storage_slot, 0, j - 1) || ubl.eeprom_start <= 0) {
SERIAL_PROTOCOLLNPGM("?EEPROM storage not available for use.\n");
return;
}
@ -1296,7 +1296,7 @@
// Prune them from the list and ignore them till the next Phase (manual nozzle probing).
if (probe_as_reference &&
(rawx < (MIN_PROBE_X) || rawx > (MAX_PROBE_X) || rawy < (MIN_PROBE_Y) || rawy > (MAX_PROBE_Y))
(!WITHIN(rawx, MIN_PROBE_X, MAX_PROBE_X) || !WITHIN(rawy, MIN_PROBE_Y, MAX_PROBE_Y))
) continue;
// Unreachable. Check if it's the closest location to the nozzle.
@ -1360,7 +1360,7 @@
rawy = ubl.mesh_index_to_ypos[location.y_index];
// TODO: Change to use `position_is_reachable` (for SCARA-compatibility)
if (rawx < (X_MIN_POS) || rawx > (X_MAX_POS) || rawy < (Y_MIN_POS) || rawy > (Y_MAX_POS)) { // In theory, we don't need this check.
if (!WITHIN(rawx, X_MIN_POS, X_MAX_POS) || !WITHIN(rawy, Y_MIN_POS, Y_MAX_POS)) { // In theory, we don't need this check.
SERIAL_ERROR_START;
SERIAL_ERRORLNPGM("Attempt to edit off the bed."); // This really can't happen, but do the check for now
ubl.has_control_of_lcd_panel = false;

Loading…
Cancel
Save