refactor
authorJim Morris <morris@wolfman.com>
Sun, 28 Feb 2016 09:37:56 +0000 (01:37 -0800)
committerJim Morris <morris@wolfman.com>
Sun, 28 Feb 2016 09:37:56 +0000 (01:37 -0800)
src/modules/tools/endstops/Endstops.cpp
src/modules/tools/rotarydeltacalibration/RotaryDeltaCalibration.cpp
src/modules/tools/rotarydeltacalibration/RotaryDeltaCalibration.h

index 4cd6cf5..7edde4a 100644 (file)
@@ -831,7 +831,7 @@ void Endstops::on_gcode_received(void *argument)
             break;
 
             case 206: // M206 - set homing offset
-                if(is_rdelta) break; // RotaryDeltaCalibration module will handle this
+                if(is_rdelta) return; // RotaryDeltaCalibration module will handle this
 
                 if (gcode->has_letter('X')) home_offset[0] = gcode->get_value('X');
                 if (gcode->has_letter('Y')) home_offset[1] = gcode->get_value('Y');
@@ -840,7 +840,8 @@ void Endstops::on_gcode_received(void *argument)
                 break;
 
             case 306: // set homing offset based on current position
-                if(is_rdelta) break; // RotaryDeltaCalibration module will handle this
+                if(is_rdelta) return; // RotaryDeltaCalibration module will handle this
+
                 set_homing_offset(gcode);
                 break;
 
index 610fd2f..2df75e4 100644 (file)
@@ -27,6 +27,13 @@ void RotaryDeltaCalibration::on_module_loaded()
     register_for_event(ON_GCODE_RECEIVED);
 }
 
+float *RotaryDeltaCalibration::get_homing_offset()
+{
+    float *theta_offset; // points to theta offset in Endstop module
+    bool ok = PublicData::get_value( endstops_checksum, home_offset_checksum, &theta_offset );
+    return ok ? theta_offset : nullptr;
+}
+
 void RotaryDeltaCalibration::on_gcode_received(void *argument)
 {
     Gcode *gcode = static_cast<Gcode *>(argument);
@@ -34,9 +41,8 @@ void RotaryDeltaCalibration::on_gcode_received(void *argument)
     if( gcode->has_m) {
         switch( gcode->m ) {
             case 206: {
-                float *theta_offset; // points to theta offset in Endstop module
-                bool ok = PublicData::get_value( endstops_checksum, home_offset_checksum, &theta_offset );
-                if (!ok) {
+                float *theta_offset= get_homing_offset(); // points to theta offset in Endstop module
+                if (theta_offset == nullptr) {
                     gcode->stream->printf("error:no endstop module found\n");
                     return;
                 }
@@ -73,9 +79,8 @@ void RotaryDeltaCalibration::on_gcode_received(void *argument)
                     }
                 }
 
-                float *theta_offset; // points to theta offset in Endstop module
-                bool ok = PublicData::get_value( endstops_checksum, home_offset_checksum, &theta_offset );
-                if (!ok) {
+                float *theta_offset= get_homing_offset(); // points to theta offset in Endstop module
+                if (theta_offset == nullptr) {
                     gcode->stream->printf("error:no endstop module found\n");
                     return;
                 }