mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-08-31 10:01:48 +02:00
Spread bitmask if only one rail of a gang has a limit
This commit is contained in:
@@ -27,6 +27,19 @@ namespace Machine {
|
||||
}
|
||||
|
||||
void Axis::afterParse() {
|
||||
bool hasMotor0 = _gangs[0] && _gangs[0]->_motor;
|
||||
bool hasMotor1 = _gangs[1] && _gangs[1]->_motor;
|
||||
bool hasLimit0 = _gangs[0] && _gangs[0]->_endstops;
|
||||
bool hasLimit1 = _gangs[1] && _gangs[1]->_endstops;
|
||||
|
||||
// Fix the masks if both motors are present but there is exactly one limit setup
|
||||
bool fixLimitMasks = hasMotor0 && hasMotor1 && (hasLimit0 ^ hasLimit1);
|
||||
if (fixLimitMasks) {
|
||||
// Since there is exactly one endstop,
|
||||
// hasLimit1 is 0 if endstop0 is present, 1 if endstop 1 is present
|
||||
_gangs[hasLimit1]->_endstops->expandLimitMasks();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < MAX_NUMBER_GANGED; ++i) {
|
||||
if (_gangs[i] == nullptr) {
|
||||
_gangs[i] = new Gang(_axis, i);
|
||||
|
@@ -25,6 +25,12 @@ namespace Machine {
|
||||
_allLimitPin = new LimitPin(_allPin, _axis, _gang, 0, _hardLimits);
|
||||
}
|
||||
|
||||
void Endstops::expandLimitMasks() {
|
||||
_negLimitPin->expandMask();
|
||||
_posLimitPin->expandMask();
|
||||
_allLimitPin->expandMask();
|
||||
}
|
||||
|
||||
void Endstops::init() {
|
||||
_negLimitPin->init();
|
||||
_posLimitPin->init();
|
||||
|
@@ -40,6 +40,8 @@ namespace Machine {
|
||||
|
||||
void init();
|
||||
|
||||
void expandLimitMasks();
|
||||
|
||||
// Configuration system helpers:
|
||||
void validate() const override;
|
||||
void group(Configuration::HandlerBase& handler) override;
|
||||
|
@@ -98,6 +98,12 @@ namespace Machine {
|
||||
}
|
||||
}
|
||||
|
||||
// Turn a one-motor mask into a both-motors mask
|
||||
void LimitPin::expandMask() {
|
||||
_bitmask |= _bitmask >> 16;
|
||||
_bitmask |= _bitmask << 16;
|
||||
}
|
||||
|
||||
void LimitPin::init() {
|
||||
if (_pin.undefined()) {
|
||||
return;
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "../Pin.h"
|
||||
#include "../System.h" // MotorMask
|
||||
|
||||
#include <esp_attr.h> // IRAM_ATTR
|
||||
|
||||
@@ -10,15 +11,15 @@ namespace Machine {
|
||||
int _axis;
|
||||
int _gang;
|
||||
|
||||
bool _value = 0;
|
||||
uint32_t _bitmask = 0;
|
||||
bool _value = 0;
|
||||
MotorMask _bitmask = 0;
|
||||
|
||||
// _pHardLimits is a reference so the shared variable at the
|
||||
// Endstops level can be changed at runtime to control the
|
||||
// limit behavior dynamically.
|
||||
bool& _pHardLimits;
|
||||
volatile uint32_t* _posLimits = nullptr;
|
||||
volatile uint32_t* _negLimits = nullptr;
|
||||
bool& _pHardLimits;
|
||||
volatile MotorMask* _posLimits = nullptr;
|
||||
volatile MotorMask* _negLimits = nullptr;
|
||||
|
||||
void IRAM_ATTR handleISR();
|
||||
|
||||
@@ -32,6 +33,8 @@ namespace Machine {
|
||||
void init();
|
||||
bool get() { return _value; }
|
||||
|
||||
void expandMask();
|
||||
|
||||
~LimitPin();
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user