1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 10:23:19 +02:00

Move the pinReportStarted logic into Report.cpp

This commit is contained in:
Mitch Bradley
2021-05-25 08:11:31 -10:00
parent 6bd74b3585
commit 44c02e7e5b
5 changed files with 24 additions and 21 deletions

View File

@@ -52,7 +52,7 @@ public:
void handle(Configuration::HandlerBase& handler) override;
bool system_check_safety_door_ajar();
void report(char* status, bool& pinReportStarted);
void report(char* status);
~Control() = default;
};

View File

@@ -23,15 +23,9 @@ void ControlPin::init() {
}
}
void ControlPin::report(char* status, bool& pinReportStarted) {
void ControlPin::report(char* status) {
if (!_pin.undefined()) {
if (!pinReportStarted) {
strcat(status, "|Pn:");
pinReportStarted = true;
}
size_t pos = strlen(status);
status[pos] = letter();
status[pos + 1] = '\0';
addPinReport(status, _letter);
}
}

View File

@@ -28,7 +28,7 @@ public:
// char invertBitNum() { return _invertBitNum; }
char letter() { return _letter; }
void report(char* status, bool& pinReportStarted);
void report(char* status);
~ControlPin();
};

View File

@@ -578,11 +578,7 @@ void report_echo_line_received(char* line, uint8_t client) {
// float wco = returns the work coordinate offset
// bool wpos = true for work position compensation
void addPinReport(char* status, char pinLetter, bool& pinReportStarted) {
if (!pinReportStarted) {
strcat(status, "|Pn:");
pinReportStarted = true;
}
void addPinReport(char* status, char pinLetter) {
size_t pos = strlen(status);
status[pos] = pinLetter;
status[pos + 1] = '\0';
@@ -653,22 +649,33 @@ void report_realtime_status(uint8_t client) {
strcat(status, temp);
#endif
#ifdef REPORT_FIELD_PIN_STATE
AxisMask lim_pin_state = limits_get_state();
bool prb_pin_state = config->_probe->get_state();
bool pinReportStarted = false;
AxisMask lim_pin_state = limits_get_state();
bool prb_pin_state = config->_probe->get_state();
const char* pinReportPrefix = "|Pn:";
// Remember the current length so we know whether something was added
size_t saved_length = strlen(status);
strcat(status, pinReportPrefix);
if (prb_pin_state) {
addPinReport(status, 'P', pinReportStarted);
addPinReport(status, 'P');
}
if (lim_pin_state) {
auto n_axis = config->_axes->_numberAxis;
for (int i = 0; i < n_axis; i++) {
if (bit_istrue(lim_pin_state, bit(i))) {
addPinReport(status, "XYZABC"[i], pinReportStarted);
addPinReport(status, "XYZABC"[i]);
}
}
}
config->_control->report(status, pinReportStarted);
config->_control->report(status);
if (strlen(status) == (saved_length + strlen(pinReportPrefix))) {
// Erase the "|Pn:" prefix because there is nothing after it
status[saved_length] = '\0';
}
#endif
#ifdef REPORT_FIELD_WORK_COORD_OFFSET

View File

@@ -126,3 +126,5 @@ void reportTaskStackSize(UBaseType_t& saved);
char* report_state_text();
float* get_wco();
void mpos_to_wpos(float* position);
void addPinReport(char* status, char pinLetter);