Skip to content

Commit

Permalink
Startup lines behave like other macros, with a log_info message
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Aug 3, 2023
1 parent 0495d9c commit 2f02a9f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
1 change: 1 addition & 0 deletions FluidNC/src/Machine/Macros.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ bool Macros::run_macro(const std::string& s) {
return true;
}

log_info("Running macro: " << s);
char c;
for (int i = 0; i < s.length(); i++) {
c = s[i];
Expand Down
16 changes: 1 addition & 15 deletions FluidNC/src/Machine/Macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,17 @@ namespace Machine {
static const int n_macros = 4;

private:
static std::string _startup_line[n_startup_lines];
static std::string _macro[n_macros];

public:
static std::string _startup_line[n_startup_lines];
static std::string _post_homing_line;

Macros() = default;

bool run_macro(size_t index);
bool run_macro(const std::string& s);

std::string startup_line(size_t index) {
if (index >= n_startup_lines) {
return "";
}
auto s = _startup_line[index];
if (s == "") {
return s;
}
// & is a proxy for newlines in startup lines, because you cannot
// enter a newline directly in a config file string value.
std::replace(s.begin(), s.end(), '&', '\n');
return s + "\n";
}

// Configuration helpers:

// TODO: We could validate the startup lines
Expand Down
11 changes: 7 additions & 4 deletions FluidNC/src/ProcessSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,9 @@ static Error get_report_build_info(const char* value, WebUI::AuthenticationLevel
}
return Error::InvalidStatement;
}
static Error report_startup_lines(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
static Error show_startup_lines(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
for (int i = 0; i < config->_macros->n_startup_lines; i++) {
log_to(out, "$N", i << "=" << config->_macros->startup_line(i));
log_to(out, "$N", i << "=" << config->_macros->_startup_line[i]);
}
return Error::Ok;
}
Expand Down Expand Up @@ -798,7 +798,7 @@ void make_user_commands() {

new UserCommand("SLP", "System/Sleep", go_to_sleep, notIdleOrAlarm);
new UserCommand("I", "Build/Info", get_report_build_info, notIdleOrAlarm);
new UserCommand("N", "GCode/StartupLines", report_startup_lines, notIdleOrAlarm);
new UserCommand("N", "GCode/StartupLines", show_startup_lines, notIdleOrAlarm);
new UserCommand("RST", "Settings/Restore", restore_settings, notIdleOrAlarm, WA);

new UserCommand("Heap", "Heap/Show", showHeap, anyState);
Expand Down Expand Up @@ -993,8 +993,10 @@ void settings_execute_startup() {
}
Error status_code;
for (int i = 0; i < config->_macros->n_startup_lines; i++) {
auto str = config->_macros->startup_line(i);
auto str = config->_macros->_startup_line[i];
if (str.length()) {
config->_macros->run_macro(str);
#if 0
// We have to copy this to a mutable array because
// gc_execute_line modifies the line while parsing.
char gcline[256];
Expand All @@ -1004,6 +1006,7 @@ void settings_execute_startup() {
if (status_code != Error::Ok) {
log_error("Startup line: " << errorString(status_code));
}
#endif
}
}
}
Expand Down

0 comments on commit 2f02a9f

Please sign in to comment.