Apply Marlin coding standards to MBL class

This commit is contained in:
Scott Lahteine 2016-06-03 21:31:38 -07:00
parent c06de0f097
commit c2362c1b3c
6 changed files with 28 additions and 26 deletions

View File

@ -2645,14 +2645,14 @@ inline void gcode_G28() {
*/
#if ENABLED(MESH_BED_LEVELING)
float pre_home_z = MESH_HOME_SEARCH_Z;
if (mbl.is_active()) {
if (mbl.active()) {
// Save known Z position if already homed
if (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) {
pre_home_z = current_position[Z_AXIS];
pre_home_z += mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
current_position[Y_AXIS] - home_offset[Y_AXIS]);
}
mbl.is_active(false);
mbl.set_active(false);
}
#endif
@ -2957,7 +2957,7 @@ inline void gcode_G28() {
if (home_all_axis || (axis_homed[X_AXIS] && axis_homed[Y_AXIS] && homeZ)) {
current_position[Z_AXIS] = MESH_HOME_SEARCH_Z;
sync_plan_position();
mbl.is_active(true);
mbl.set_active(true);
#if ENABLED(MESH_G28_REST_ORIGIN)
current_position[Z_AXIS] = 0.0;
set_destination_to_current();
@ -2973,7 +2973,7 @@ inline void gcode_G28() {
else if ((axis_homed[X_AXIS] && axis_homed[Y_AXIS] && axis_homed[Z_AXIS]) && (homeX || homeY)) {
current_position[Z_AXIS] = pre_home_z;
sync_plan_position();
mbl.is_active(true);
mbl.set_active(true);
current_position[Z_AXIS] = pre_home_z -
mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
current_position[Y_AXIS] - home_offset[Y_AXIS]);
@ -3060,7 +3060,7 @@ inline void gcode_G28() {
case MeshReport:
if (mbl.has_mesh()) {
SERIAL_PROTOCOLPGM("State: ");
if (mbl.is_active())
if (mbl.active())
SERIAL_PROTOCOLPGM("On");
else
SERIAL_PROTOCOLPGM("Off");
@ -3125,7 +3125,7 @@ inline void gcode_G28() {
// After recording the last point, activate the mbl and home
SERIAL_PROTOCOLLNPGM("Mesh probing done.");
probe_point = -1;
mbl.has_mesh(true);
mbl.set_has_mesh(true);
enqueue_and_echo_commands_P(PSTR("G28"));
}
break;
@ -3175,7 +3175,7 @@ inline void gcode_G28() {
break;
case MeshReset:
if (mbl.is_active()) {
if (mbl.active()) {
current_position[Z_AXIS] +=
mbl.get_z(current_position[X_AXIS] - home_offset[X_AXIS],
current_position[Y_AXIS] - home_offset[Y_AXIS]) - MESH_HOME_SEARCH_Z;
@ -5982,7 +5982,7 @@ inline void gcode_M410() {
/**
* M420: Enable/Disable Mesh Bed Leveling
*/
inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.has_mesh(!!code_value_short()); }
inline void gcode_M420() { if (code_seen('S') && code_has_value()) mbl.set_has_mesh(!!code_value_short()); }
/**
* M421: Set a single Mesh Bed Leveling Z coordinate
@ -7373,7 +7373,7 @@ void clamp_to_software_endstops(float target[3]) {
// This function is used to split lines on mesh borders so each segment is only part of one mesh area
void mesh_buffer_line(float x, float y, float z, const float e, float feed_rate, const uint8_t& extruder, uint8_t x_splits = 0xff, uint8_t y_splits = 0xff) {
if (!mbl.is_active()) {
if (!mbl.active()) {
planner.buffer_line(x, y, z, e, feed_rate, extruder);
set_current_to_destination();
return;

View File

@ -58,8 +58,8 @@
* 188 M206 XYZ home_offset (float x3)
*
* Mesh bed leveling:
* 200 M420 S status (0 = empty, 1 = has mesh numbers)
* 201 z_offset (float) (added in V23)
* 200 M420 S status (uint8)
* 201 z_offset (float)
* 205 mesh_num_x (uint8 as set in firmware)
* 206 mesh_num_y (uint8 as set in firmware)
* 207 G29 S3 XYZ z_values[][] (float x9, by default)
@ -187,21 +187,21 @@ void Config_StoreSettings() {
EEPROM_WRITE_VAR(i, planner.max_e_jerk);
EEPROM_WRITE_VAR(i, home_offset);
uint8_t dummy_uint8 = 0;
uint8_t mesh_num_x = 3;
uint8_t mesh_num_y = 3;
#if ENABLED(MESH_BED_LEVELING)
// Compile time test that sizeof(mbl.z_values) is as expected
typedef char c_assert[(sizeof(mbl.z_values) == (MESH_NUM_X_POINTS) * (MESH_NUM_Y_POINTS) * sizeof(dummy)) ? 1 : -1];
mesh_num_x = MESH_NUM_X_POINTS;
mesh_num_y = MESH_NUM_Y_POINTS;
dummy_uint8 = mbl.status & 0x01; // Do not save 'is active'
uint8_t mesh_num_x = MESH_NUM_X_POINTS,
mesh_num_y = MESH_NUM_Y_POINTS,
dummy_uint8 = mbl.status & _BV(MBL_STATUS_HAS_MESH_BIT);
EEPROM_WRITE_VAR(i, dummy_uint8);
EEPROM_WRITE_VAR(i, mbl.z_offset);
EEPROM_WRITE_VAR(i, mesh_num_x);
EEPROM_WRITE_VAR(i, mesh_num_y);
EEPROM_WRITE_VAR(i, mbl.z_values);
#else
uint8_t mesh_num_x = 3,
mesh_num_y = 3,
dummy_uint8 = 0;
dummy = 0.0f;
EEPROM_WRITE_VAR(i, dummy_uint8);
EEPROM_WRITE_VAR(i, dummy);

View File

@ -29,7 +29,7 @@
mesh_bed_leveling::mesh_bed_leveling() { reset(); }
void mesh_bed_leveling::reset() {
status = 0;
status = MBL_STATUS_NONE;
z_offset = 0;
for (int8_t y = MESH_NUM_Y_POINTS; y--;)
for (int8_t x = MESH_NUM_X_POINTS; x--;)

View File

@ -24,12 +24,14 @@
#if ENABLED(MESH_BED_LEVELING)
enum MBLStatus { MBL_STATUS_NONE = 0, MBL_STATUS_HAS_MESH_BIT = 0, MBL_STATUS_ACTIVE_BIT = 1 };
#define MESH_X_DIST ((MESH_MAX_X - (MESH_MIN_X))/(MESH_NUM_X_POINTS - 1))
#define MESH_Y_DIST ((MESH_MAX_Y - (MESH_MIN_Y))/(MESH_NUM_Y_POINTS - 1))
class mesh_bed_leveling {
public:
uint8_t status; // Bit 0 = has mesh numbers, Bit 1 = compensation active
uint8_t status; // Has Mesh and Is Active bits
float z_offset;
float z_values[MESH_NUM_Y_POINTS][MESH_NUM_X_POINTS];
@ -41,10 +43,10 @@
static FORCE_INLINE float get_probe_y(int8_t i) { return MESH_MIN_Y + (MESH_Y_DIST) * i; }
void set_z(const int8_t px, const int8_t py, const float z) { z_values[py][px] = z; }
bool has_mesh() { return TEST(status, 0); }
void has_mesh(bool onOff) { if (onOff) SBI(status, 0); else CBI(status, 0); }
bool is_active() { return TEST(status, 1); }
void is_active(bool onOff) { if (onOff) SBI(status, 1); else CBI(status, 1); }
bool active() { return TEST(status, MBL_STATUS_ACTIVE_BIT); }
void set_active(bool onOff) { if (onOff) SBI(status, MBL_STATUS_ACTIVE_BIT); else CBI(status, MBL_STATUS_ACTIVE_BIT); }
bool has_mesh() { return TEST(status, MBL_STATUS_HAS_MESH_BIT); }
void set_has_mesh(bool onOff) { if (onOff) SBI(status, MBL_STATUS_HAS_MESH_BIT); else CBI(status, MBL_STATUS_HAS_MESH_BIT); }
inline void zigzag(int8_t index, int8_t &px, int8_t &py) {
px = index % (MESH_NUM_X_POINTS);

View File

@ -539,7 +539,7 @@ void Planner::check_axes_activity() {
while (block_buffer_tail == next_buffer_head) idle();
#if ENABLED(MESH_BED_LEVELING)
if (mbl.is_active())
if (mbl.active())
z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
#elif ENABLED(AUTO_BED_LEVELING_FEATURE)
apply_rotation_xyz(bed_level_matrix, x, y, z);
@ -1121,7 +1121,7 @@ void Planner::check_axes_activity() {
#endif // AUTO_BED_LEVELING_FEATURE || MESH_BED_LEVELING
{
#if ENABLED(MESH_BED_LEVELING)
if (mbl.is_active())
if (mbl.active())
z += mbl.get_z(x - home_offset[X_AXIS], y - home_offset[Y_AXIS]);
#elif ENABLED(AUTO_BED_LEVELING_FEATURE)
apply_rotation_xyz(bed_level_matrix, x, y, z);

View File

@ -970,7 +970,7 @@ void lcd_cooldown() {
line_to_current(Z_AXIS);
stepper.synchronize();
mbl.has_mesh(true);
mbl.set_has_mesh(true);
enqueue_and_echo_commands_P(PSTR("G28"));
lcd_return_to_status();
//LCD_MESSAGEPGM(MSG_LEVEL_BED_DONE);