mirror of
https://github.com/bdring/Grbl_Esp32.git
synced 2025-09-02 10:53:01 +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() {
|
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) {
|
for (size_t i = 0; i < MAX_NUMBER_GANGED; ++i) {
|
||||||
if (_gangs[i] == nullptr) {
|
if (_gangs[i] == nullptr) {
|
||||||
_gangs[i] = new Gang(_axis, i);
|
_gangs[i] = new Gang(_axis, i);
|
||||||
|
@@ -25,6 +25,12 @@ namespace Machine {
|
|||||||
_allLimitPin = new LimitPin(_allPin, _axis, _gang, 0, _hardLimits);
|
_allLimitPin = new LimitPin(_allPin, _axis, _gang, 0, _hardLimits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Endstops::expandLimitMasks() {
|
||||||
|
_negLimitPin->expandMask();
|
||||||
|
_posLimitPin->expandMask();
|
||||||
|
_allLimitPin->expandMask();
|
||||||
|
}
|
||||||
|
|
||||||
void Endstops::init() {
|
void Endstops::init() {
|
||||||
_negLimitPin->init();
|
_negLimitPin->init();
|
||||||
_posLimitPin->init();
|
_posLimitPin->init();
|
||||||
|
@@ -40,6 +40,8 @@ namespace Machine {
|
|||||||
|
|
||||||
void init();
|
void init();
|
||||||
|
|
||||||
|
void expandLimitMasks();
|
||||||
|
|
||||||
// Configuration system helpers:
|
// Configuration system helpers:
|
||||||
void validate() const override;
|
void validate() const override;
|
||||||
void group(Configuration::HandlerBase& handler) 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() {
|
void LimitPin::init() {
|
||||||
if (_pin.undefined()) {
|
if (_pin.undefined()) {
|
||||||
return;
|
return;
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../Pin.h"
|
#include "../Pin.h"
|
||||||
|
#include "../System.h" // MotorMask
|
||||||
|
|
||||||
#include <esp_attr.h> // IRAM_ATTR
|
#include <esp_attr.h> // IRAM_ATTR
|
||||||
|
|
||||||
@@ -11,14 +12,14 @@ namespace Machine {
|
|||||||
int _gang;
|
int _gang;
|
||||||
|
|
||||||
bool _value = 0;
|
bool _value = 0;
|
||||||
uint32_t _bitmask = 0;
|
MotorMask _bitmask = 0;
|
||||||
|
|
||||||
// _pHardLimits is a reference so the shared variable at the
|
// _pHardLimits is a reference so the shared variable at the
|
||||||
// Endstops level can be changed at runtime to control the
|
// Endstops level can be changed at runtime to control the
|
||||||
// limit behavior dynamically.
|
// limit behavior dynamically.
|
||||||
bool& _pHardLimits;
|
bool& _pHardLimits;
|
||||||
volatile uint32_t* _posLimits = nullptr;
|
volatile MotorMask* _posLimits = nullptr;
|
||||||
volatile uint32_t* _negLimits = nullptr;
|
volatile MotorMask* _negLimits = nullptr;
|
||||||
|
|
||||||
void IRAM_ATTR handleISR();
|
void IRAM_ATTR handleISR();
|
||||||
|
|
||||||
@@ -32,6 +33,8 @@ namespace Machine {
|
|||||||
void init();
|
void init();
|
||||||
bool get() { return _value; }
|
bool get() { return _value; }
|
||||||
|
|
||||||
|
void expandMask();
|
||||||
|
|
||||||
~LimitPin();
|
~LimitPin();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user