Browse Source

Fix BACKLASH_COMPENSATION compiler issues (#15307)

Jason Smith 5 years ago
parent
commit
514223f960
3 changed files with 23 additions and 30 deletions
  1. 3
    10
      Marlin/src/feature/backlash.h
  2. 10
    2
      Marlin/src/inc/SanityCheck.h
  3. 10
    18
      Marlin/src/module/configuration_store.cpp

+ 3
- 10
Marlin/src/feature/backlash.h View File

@@ -28,28 +28,21 @@ constexpr uint8_t all_on = 0xFF, all_off = 0x00;
28 28
 
29 29
 class Backlash {
30 30
 public:
31
-  #ifdef BACKLASH_DISTANCE_MM
32
-    #if ENABLED(BACKLASH_GCODE)
33
-      static float distance_mm[XYZ];
34
-    #else
35
-      static const float distance_mm[XYZ];
36
-      //static constexpr float distance_mm[XYZ] = BACKLASH_DISTANCE_MM; // compiler barks at this
37
-    #endif
38
-  #endif
39 31
   #if ENABLED(BACKLASH_GCODE)
32
+    static float distance_mm[XYZ];
40 33
     static uint8_t correction;
41 34
     #ifdef BACKLASH_SMOOTHING_MM
42 35
       static float smoothing_mm;
43 36
     #endif
37
+
44 38
     static inline void set_correction(const float &v) { correction = _MAX(0, _MIN(1.0, v)) * all_on; }
45 39
     static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
46 40
   #else
47 41
     static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
42
+    static const float distance_mm[XYZ];
48 43
     #ifdef BACKLASH_SMOOTHING_MM
49 44
       static constexpr float smoothing_mm = BACKLASH_SMOOTHING_MM;
50 45
     #endif
51
-    static inline void set_correction(float) { }
52
-    static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
53 46
   #endif
54 47
 
55 48
   #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)

+ 10
- 2
Marlin/src/inc/SanityCheck.h View File

@@ -2324,8 +2324,16 @@ static_assert(   _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
2324 2324
   #endif
2325 2325
 #endif
2326 2326
 
2327
-#if ENABLED(BACKLASH_COMPENSATION) && IS_CORE
2328
-  #error "BACKLASH_COMPENSATION is incompatible with CORE kinematics."
2327
+#if ENABLED(BACKLASH_COMPENSATION)
2328
+  #if IS_CORE
2329
+    #error "BACKLASH_COMPENSATION is incompatible with CORE kinematics."
2330
+  #endif
2331
+  #ifndef BACKLASH_DISTANCE_MM
2332
+    #error "BACKLASH_COMPENSATION requires BACKLASH_DISTANCE_MM"
2333
+  #endif
2334
+  #ifndef BACKLASH_CORRECTION
2335
+    #error "BACKLASH_COMPENSATION requires BACKLASH_CORRECTION"
2336
+  #endif
2329 2337
 #endif
2330 2338
 
2331 2339
 #if ENABLED(GRADIENT_MIX) && MIXING_VIRTUAL_TOOLS < 2

+ 10
- 18
Marlin/src/module/configuration_store.cpp View File

@@ -1189,17 +1189,14 @@ void MarlinSettings::postprocess() {
1189 1189
     // Backlash Compensation
1190 1190
     //
1191 1191
     {
1192
-      #ifdef BACKLASH_DISTANCE_MM
1192
+      #if ENABLED(BACKLASH_GCODE)
1193 1193
         const float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
1194
-      #else
1195
-        const float backlash_distance_mm[XYZ] = { 0 };
1196
-      #endif
1197
-      #if ENABLED(BACKLASH_COMPENSATION)
1198 1194
         const uint8_t &backlash_correction = backlash.correction;
1199 1195
       #else
1196
+        const float backlash_distance_mm[XYZ] = { 0 };
1200 1197
         const uint8_t backlash_correction = 0;
1201 1198
       #endif
1202
-      #ifdef BACKLASH_SMOOTHING_MM
1199
+      #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
1203 1200
         const float &backlash_smoothing_mm = backlash.smoothing_mm;
1204 1201
       #else
1205 1202
         const float backlash_smoothing_mm = 3;
@@ -1992,17 +1989,14 @@ void MarlinSettings::postprocess() {
1992 1989
       // Backlash Compensation
1993 1990
       //
1994 1991
       {
1995
-        #ifdef BACKLASH_DISTANCE_MM
1992
+        #if ENABLED(BACKLASH_GCODE)
1996 1993
           float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
1997
-        #else
1998
-          float backlash_distance_mm[XYZ];
1999
-        #endif
2000
-        #if ENABLED(BACKLASH_COMPENSATION)
2001 1994
           uint8_t &backlash_correction = backlash.correction;
2002 1995
         #else
1996
+          float backlash_distance_mm[XYZ];
2003 1997
           uint8_t backlash_correction;
2004 1998
         #endif
2005
-        #ifdef BACKLASH_SMOOTHING_MM
1999
+        #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
2006 2000
           float &backlash_smoothing_mm = backlash.smoothing_mm;
2007 2001
         #else
2008 2002
           float backlash_smoothing_mm;
@@ -2293,12 +2287,10 @@ void MarlinSettings::reset() {
2293 2287
 
2294 2288
   #if ENABLED(BACKLASH_GCODE)
2295 2289
     backlash.correction = (BACKLASH_CORRECTION) * 255;
2296
-    #ifdef BACKLASH_DISTANCE_MM
2297
-      constexpr float tmp[XYZ] = BACKLASH_DISTANCE_MM;
2298
-      backlash.distance_mm[X_AXIS] = tmp[X_AXIS];
2299
-      backlash.distance_mm[Y_AXIS] = tmp[Y_AXIS];
2300
-      backlash.distance_mm[Z_AXIS] = tmp[Z_AXIS];
2301
-    #endif
2290
+    constexpr float tmp[XYZ] = BACKLASH_DISTANCE_MM;
2291
+    backlash.distance_mm[X_AXIS] = tmp[X_AXIS];
2292
+    backlash.distance_mm[Y_AXIS] = tmp[Y_AXIS];
2293
+    backlash.distance_mm[Z_AXIS] = tmp[Z_AXIS];
2302 2294
     #ifdef BACKLASH_SMOOTHING_MM
2303 2295
       backlash.smoothing_mm = BACKLASH_SMOOTHING_MM;
2304 2296
     #endif

Loading…
Cancel
Save