Fix BACKLASH_COMPENSATION compiler issues (#15307)

This commit is contained in:
Jason Smith 2019-09-19 22:48:41 -07:00 committed by Scott Lahteine
parent 1452e41ead
commit 514223f960
3 changed files with 23 additions and 30 deletions

View File

@ -28,28 +28,21 @@ constexpr uint8_t all_on = 0xFF, all_off = 0x00;
class Backlash { class Backlash {
public: public:
#ifdef BACKLASH_DISTANCE_MM
#if ENABLED(BACKLASH_GCODE) #if ENABLED(BACKLASH_GCODE)
static float distance_mm[XYZ]; static float distance_mm[XYZ];
#else
static const float distance_mm[XYZ];
//static constexpr float distance_mm[XYZ] = BACKLASH_DISTANCE_MM; // compiler barks at this
#endif
#endif
#if ENABLED(BACKLASH_GCODE)
static uint8_t correction; static uint8_t correction;
#ifdef BACKLASH_SMOOTHING_MM #ifdef BACKLASH_SMOOTHING_MM
static float smoothing_mm; static float smoothing_mm;
#endif #endif
static inline void set_correction(const float &v) { correction = _MAX(0, _MIN(1.0, v)) * all_on; } static inline void set_correction(const float &v) { correction = _MAX(0, _MIN(1.0, v)) * all_on; }
static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; } static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
#else #else
static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF; static constexpr uint8_t correction = (BACKLASH_CORRECTION) * 0xFF;
static const float distance_mm[XYZ];
#ifdef BACKLASH_SMOOTHING_MM #ifdef BACKLASH_SMOOTHING_MM
static constexpr float smoothing_mm = BACKLASH_SMOOTHING_MM; static constexpr float smoothing_mm = BACKLASH_SMOOTHING_MM;
#endif #endif
static inline void set_correction(float) { }
static inline float get_correction() { return float(ui8_to_percent(correction)) / 100.0f; }
#endif #endif
#if ENABLED(MEASURE_BACKLASH_WHEN_PROBING) #if ENABLED(MEASURE_BACKLASH_WHEN_PROBING)

View File

@ -2324,8 +2324,16 @@ static_assert( _ARR_TEST(3,0) && _ARR_TEST(3,1) && _ARR_TEST(3,2)
#endif #endif
#endif #endif
#if ENABLED(BACKLASH_COMPENSATION) && IS_CORE #if ENABLED(BACKLASH_COMPENSATION)
#if IS_CORE
#error "BACKLASH_COMPENSATION is incompatible with CORE kinematics." #error "BACKLASH_COMPENSATION is incompatible with CORE kinematics."
#endif
#ifndef BACKLASH_DISTANCE_MM
#error "BACKLASH_COMPENSATION requires BACKLASH_DISTANCE_MM"
#endif
#ifndef BACKLASH_CORRECTION
#error "BACKLASH_COMPENSATION requires BACKLASH_CORRECTION"
#endif
#endif #endif
#if ENABLED(GRADIENT_MIX) && MIXING_VIRTUAL_TOOLS < 2 #if ENABLED(GRADIENT_MIX) && MIXING_VIRTUAL_TOOLS < 2

View File

@ -1189,17 +1189,14 @@ void MarlinSettings::postprocess() {
// Backlash Compensation // Backlash Compensation
// //
{ {
#ifdef BACKLASH_DISTANCE_MM #if ENABLED(BACKLASH_GCODE)
const float (&backlash_distance_mm)[XYZ] = backlash.distance_mm; const float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
#else
const float backlash_distance_mm[XYZ] = { 0 };
#endif
#if ENABLED(BACKLASH_COMPENSATION)
const uint8_t &backlash_correction = backlash.correction; const uint8_t &backlash_correction = backlash.correction;
#else #else
const float backlash_distance_mm[XYZ] = { 0 };
const uint8_t backlash_correction = 0; const uint8_t backlash_correction = 0;
#endif #endif
#ifdef BACKLASH_SMOOTHING_MM #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
const float &backlash_smoothing_mm = backlash.smoothing_mm; const float &backlash_smoothing_mm = backlash.smoothing_mm;
#else #else
const float backlash_smoothing_mm = 3; const float backlash_smoothing_mm = 3;
@ -1992,17 +1989,14 @@ void MarlinSettings::postprocess() {
// Backlash Compensation // Backlash Compensation
// //
{ {
#ifdef BACKLASH_DISTANCE_MM #if ENABLED(BACKLASH_GCODE)
float (&backlash_distance_mm)[XYZ] = backlash.distance_mm; float (&backlash_distance_mm)[XYZ] = backlash.distance_mm;
#else
float backlash_distance_mm[XYZ];
#endif
#if ENABLED(BACKLASH_COMPENSATION)
uint8_t &backlash_correction = backlash.correction; uint8_t &backlash_correction = backlash.correction;
#else #else
float backlash_distance_mm[XYZ];
uint8_t backlash_correction; uint8_t backlash_correction;
#endif #endif
#ifdef BACKLASH_SMOOTHING_MM #if ENABLED(BACKLASH_GCODE) && defined(BACKLASH_SMOOTHING_MM)
float &backlash_smoothing_mm = backlash.smoothing_mm; float &backlash_smoothing_mm = backlash.smoothing_mm;
#else #else
float backlash_smoothing_mm; float backlash_smoothing_mm;
@ -2293,12 +2287,10 @@ void MarlinSettings::reset() {
#if ENABLED(BACKLASH_GCODE) #if ENABLED(BACKLASH_GCODE)
backlash.correction = (BACKLASH_CORRECTION) * 255; backlash.correction = (BACKLASH_CORRECTION) * 255;
#ifdef BACKLASH_DISTANCE_MM
constexpr float tmp[XYZ] = BACKLASH_DISTANCE_MM; constexpr float tmp[XYZ] = BACKLASH_DISTANCE_MM;
backlash.distance_mm[X_AXIS] = tmp[X_AXIS]; backlash.distance_mm[X_AXIS] = tmp[X_AXIS];
backlash.distance_mm[Y_AXIS] = tmp[Y_AXIS]; backlash.distance_mm[Y_AXIS] = tmp[Y_AXIS];
backlash.distance_mm[Z_AXIS] = tmp[Z_AXIS]; backlash.distance_mm[Z_AXIS] = tmp[Z_AXIS];
#endif
#ifdef BACKLASH_SMOOTHING_MM #ifdef BACKLASH_SMOOTHING_MM
backlash.smoothing_mm = BACKLASH_SMOOTHING_MM; backlash.smoothing_mm = BACKLASH_SMOOTHING_MM;
#endif #endif