diff --git a/FluidNC/src/Machine/Axes.cpp b/FluidNC/src/Machine/Axes.cpp index dd47ddf2e..1b07a42ef 100644 --- a/FluidNC/src/Machine/Axes.cpp +++ b/FluidNC/src/Machine/Axes.cpp @@ -52,6 +52,10 @@ namespace Machine { log_info("Axis " << axisName(axis) << " (" << limitsMinPosition(axis) << "," << limitsMaxPosition(axis) << ")"); a->init(); } + auto homing = a->_homing; + if (homing && !homing->_positiveDirection) { + set_bitnum(Homing::direction_mask, axis); + } } config_motors(); diff --git a/FluidNC/src/Machine/Homing.cpp b/FluidNC/src/Machine/Homing.cpp index 577c6fe2e..2ce3668f0 100644 --- a/FluidNC/src/Machine/Homing.cpp +++ b/FluidNC/src/Machine/Homing.cpp @@ -32,10 +32,11 @@ namespace Machine { const uint32_t MOTOR0 = 0xffff; const uint32_t MOTOR1 = 0xffff0000; - Homing::Phase Homing::_phase = Phase::None; - AxisMask Homing::_cycleAxes = 0; - AxisMask Homing::_phaseAxes = 0; - MotorMask Homing::_cycleMotors = 0; + Homing::Phase Homing::_phase = Phase::None; + AxisMask Homing::_cycleAxes = 0; + AxisMask Homing::_phaseAxes = 0; + AxisMask Homing::direction_mask = 0; + MotorMask Homing::_cycleMotors = 0; MotorMask Homing::_phaseMotors; std::queue Homing::_remainingCycles; uint32_t Homing::_settling_ms; diff --git a/FluidNC/src/Machine/Homing.h b/FluidNC/src/Machine/Homing.h index cf869656a..2113be23c 100644 --- a/FluidNC/src/Machine/Homing.h +++ b/FluidNC/src/Machine/Homing.h @@ -27,6 +27,7 @@ namespace Machine { static uint32_t _runs; static AxisMask unhomed_axes(); + static AxisMask direction_mask; static void set_axis_homed(size_t axis); static void set_axis_unhomed(size_t axis); diff --git a/FluidNC/src/SettingsDefinitions.cpp b/FluidNC/src/SettingsDefinitions.cpp index 262dca128..f17b0450a 100644 --- a/FluidNC/src/SettingsDefinitions.cpp +++ b/FluidNC/src/SettingsDefinitions.cpp @@ -1,6 +1,8 @@ #include "Machine/MachineConfig.h" #include "SettingsDefinitions.h" #include "Config.h" +#include "Stepping.h" +#include "Machine/Homing.h" #include #include @@ -109,7 +111,9 @@ void make_settings() { FLOAT_PROXY("101", "Grbl/Resolution/Y", config._axes->_axis[1]->_stepsPerMm) FLOAT_PROXY("102", "Grbl/Resolution/Z", config._axes->_axis[2]->_stepsPerMm) + INT_PROXY("3", "Grbl/InvertMask", Machine::Stepping::direction_mask) INT_PROXY("20", "Grbl/SoftLimitsEnable", config._axes->_axis[0]->_softLimits) INT_PROXY("21", "Grbl/HardLimitsEnable", config._axes->hasHardLimits()) INT_PROXY("22", "Grbl/HomingCycleEnable", (bool)Axes::homingMask) + INT_PROXY("23", "Grbl/HomingInvertMask", Homing::direction_mask) } diff --git a/FluidNC/src/Stepping.cpp b/FluidNC/src/Stepping.cpp index eb166668d..0dabd99fa 100644 --- a/FluidNC/src/Stepping.cpp +++ b/FluidNC/src/Stepping.cpp @@ -24,6 +24,8 @@ namespace Machine { int Stepping::_engine = RMT_ENGINE; + AxisMask Stepping::direction_mask = 0; + bool Stepping::_switchedStepper = false; size_t Stepping::_segments = 12; @@ -78,6 +80,10 @@ void Stepping::assignMotor(int axis, int motor, int step_pin, bool step_invert, m->dir_invert = dir_invert; m->blocked = false; m->limited = false; + + if (motor == 0 && dir_invert) { + set_bitnum(direction_mask, axis); + } } int Stepping::axis_steps[MAX_N_AXIS] = { 0 }; diff --git a/FluidNC/src/Stepping.h b/FluidNC/src/Stepping.h index fbf7a48ab..dcccf8da9 100644 --- a/FluidNC/src/Stepping.h +++ b/FluidNC/src/Stepping.h @@ -87,6 +87,8 @@ namespace Machine { static uint32_t maxPulsesPerSec(); + static AxisMask direction_mask; + // Timers static void setTimerPeriod(uint32_t timerTicks); static void startTimer();