Skip to content

Commit

Permalink
Merge pull request #1042 from bdring/ReFixMacros
Browse files Browse the repository at this point in the history
Reinstated a macro fix that got lost in a git mixup
  • Loading branch information
MitchBradley authored Oct 10, 2023
2 parents 989cd58 + 2da13de commit 7737730
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
1 change: 1 addition & 0 deletions FluidNC/src/Error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ std::map<Error, const char*> ErrorNames = {
{ Error::AuthenticationFailed, "Authentication failed!" },
{ Error::Eol, "End of line" },
{ Error::Eof, "End of file" },
{ Error::Reset, "System Reset" },
{ Error::AnotherInterfaceBusy, "Another interface is busy" },
{ Error::BadPinSpecification, "Bad Pin Specification" },
{ Error::JogCancelled, "Jog Cancelled" },
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/Error.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ enum class Error : uint8_t {
AuthenticationFailed = 110,
Eol = 111,
Eof = 112, // Not necessarily an error
Reset = 113,
AnotherInterfaceBusy = 120,
JogCancelled = 130,
BadPinSpecification = 150,
Expand Down
3 changes: 3 additions & 0 deletions FluidNC/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,9 @@ Error gc_execute_line(char* line) {
// As far as the parser is concerned, the position is now == target. In reality the
// motion control system might still be processing the action and the real tool position
// in any intermediate location.
if (sys.abort) {
return Error::Reset;
}
if (gc_update_pos == GCUpdatePos::Target) {
copyAxes(gc_state.position, gc_block.values.xyz);
} else if (gc_update_pos == GCUpdatePos::System) {
Expand Down
18 changes: 10 additions & 8 deletions FluidNC/src/Machine/Macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,14 @@
#include "src/System.h" // sys
#include "src/Machine/MachineConfig.h" // config

Macro::Macro(const char* name) : _name(name) {}

void MacroEvent::run(void* arg) {
int n = int(arg);
if (sys.state != State::Idle) {
log_error("Macro can only be used in idle state");
return;
}
config->_macros->_macro[n].run();
config->_macros->_macro[_num].run();
}

Macro Macros::_startup_line[n_startup_lines] = { { "startup_line0" }, { "startup_line1" } };
Macro Macros::_macro[n_macros] = { { "macro0" }, { "macro1" }, { "macro2" }, { "macro3" } };
Macro Macros::_startup_line[n_startup_lines] = { "startup_line0", "startup_line1" };
Macro Macros::_macro[n_macros] = { "macro0", "macro1", "macro2", "macro3" };
Macro Macros::_after_homing = { "after_homing" };
Macro Macros::_after_reset = { "after_reset" };
Macro Macros::_after_unlock = { "after_unlock" };
Expand Down Expand Up @@ -54,6 +51,11 @@ Cmd findOverride(std::string name) {
}

bool Macro::run() {
if (sys.state != State::Idle) {
log_error("Macro can only be used in idle state");
return false;
}

const std::string& s = _gcode;
if (_gcode == "") {
return true;
Expand Down
22 changes: 11 additions & 11 deletions FluidNC/src/Machine/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ namespace Machine {
class Macro {
public:
std::string _gcode;
std::string _name;
Macro(const char* name) : _name(name) {}
const char* _name;
Macro(const char* name);
bool run();
};

Expand All @@ -50,15 +50,15 @@ namespace Machine {
// TODO: We could validate the startup lines

void group(Configuration::HandlerBase& handler) override {
handler.item(_startup_line[0]._name.c_str(), _startup_line[0]._gcode);
handler.item(_startup_line[1]._name.c_str(), _startup_line[1]._gcode);
handler.item(_macro[0]._name.c_str(), _macro[0]._gcode);
handler.item(_macro[1]._name.c_str(), _macro[1]._gcode);
handler.item(_macro[2]._name.c_str(), _macro[2]._gcode);
handler.item(_macro[3]._name.c_str(), _macro[3]._gcode);
handler.item(_after_homing._name.c_str(), _after_homing._gcode);
handler.item(_after_reset._name.c_str(), _after_reset._gcode);
handler.item(_after_unlock._name.c_str(), _after_unlock._gcode);
handler.item(_startup_line[0]._name, _startup_line[0]._gcode);
handler.item(_startup_line[1]._name, _startup_line[1]._gcode);
handler.item(_macro[0]._name, _macro[0]._gcode);
handler.item(_macro[1]._name, _macro[1]._gcode);
handler.item(_macro[2]._name, _macro[2]._gcode);
handler.item(_macro[3]._name, _macro[3]._gcode);
handler.item(_after_homing._name, _after_homing._gcode);
handler.item(_after_reset._name, _after_reset._gcode);
handler.item(_after_unlock._name, _after_unlock._gcode);
}

~Macros() {}
Expand Down

0 comments on commit 7737730

Please sign in to comment.