Skip to content

Commit

Permalink
Merge pull request #1063 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Nov 8, 2023
2 parents c19700c + f5508af commit 0222615
Show file tree
Hide file tree
Showing 23 changed files with 127 additions and 54 deletions.
2 changes: 2 additions & 0 deletions FluidNC/src/Configuration/JsonGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ namespace Configuration {
{
_encoder.begin_object();
_encoder.member("False", 0);
_encoder.end_object();
_encoder.begin_object();
_encoder.member("True", 1);
_encoder.end_object();
}
Expand Down
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
5 changes: 5 additions & 0 deletions FluidNC/src/Machine/Axes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ namespace Machine {
}

_sharedStepperDisable.synchronousWrite(disable);

if (!disable && config->_stepping->_disableDelayUsecs) { // wait for the enable delay
log_debug("enable delay:" << config->_stepping->_disableDelayUsecs);
delay_us(config->_stepping->_disableDelayUsecs);
}
}

// Put the motors in the given axes into homing mode, returning a
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Machine/Axis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace Machine {
m->init();
}
}
if (_homing->_cycle) {
if (_homing && _homing->_cycle != Machine::Homing::set_mpos_only) {
_homing->init();
set_bitnum(Axes::homingMask, _axis);
}
Expand Down
22 changes: 12 additions & 10 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 @@ -53,10 +50,15 @@ Cmd findOverride(std::string name) {
return it == overrideCodes.end() ? Cmd::None : it->second;
}

bool Macro::run() {
bool Macro::run() { // return true if the macro was run
const std::string& s = _gcode;
if (_gcode == "") {
return true;
return false;
}

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

log_info("Running macro " << _name << ": " << _gcode);
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
16 changes: 16 additions & 0 deletions FluidNC/src/OLED.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,18 @@ void OLED::parse_BT() {
delay_ms(_radio_delay);
}

void OLED::parse_WebUI() {
size_t start = strlen("[MSG:INFO: WebUI: Request from ");
std::string ipaddr = _report.substr(start, _report.size() - start - 1);

_oled->clear();
auto fh = font_height(ArialMT_Plain_10);
wrapped_draw_string(0, "WebUI from", ArialMT_Plain_10);
wrapped_draw_string(fh * 2, ipaddr, ArialMT_Plain_10);
_oled->display();
delay_ms(_radio_delay);
}

void OLED::parse_report() {
if (_report.length() == 0) {
return;
Expand Down Expand Up @@ -467,6 +479,10 @@ void OLED::parse_report() {
parse_BT();
return;
}
if (_report.rfind("[MSG:INFO: WebUI: Request from ", 0) == 0) {
parse_WebUI();
return;
}
}

// This is how the OLED driver receives channel data
Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/OLED.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class OLED : public Channel, public Configuration::Configurable {
void parse_IP();
void parse_AP();
void parse_BT();
void parse_WebUI();

void parse_axes(std::string s, float* axes);
void parse_numbers(std::string s, float* nums, int maxnums);
Expand Down
6 changes: 5 additions & 1 deletion FluidNC/src/ProcessSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
// WU Readable and writable as user and admin
// WA Readable as user and admin, writable as admin

static Error fakeMaxSpindleSpeed(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out);

// If authentication is disabled, auth_level will be LEVEL_ADMIN
static bool auth_failed(Word* w, const char* value, WebUI::AuthenticationLevel auth_level) {
permissions_t permissions = w->getPermissions();
Expand Down Expand Up @@ -193,6 +195,8 @@ static void show_settings(Channel& out, type_t type) {
show_setting(s->getGrblName(), s->getCompatibleValue(), NULL, out);
}
}
// need this per issue #1036
fakeMaxSpindleSpeed(NULL, WebUI::AuthenticationLevel::LEVEL_ADMIN, out);
}
static Error report_normal_settings(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
show_settings(out, GRBL); // GRBL non-axis settings
Expand Down Expand Up @@ -687,7 +691,7 @@ static Error dump_config(const char* value, WebUI::AuthenticationLevel auth_leve

static Error fakeMaxSpindleSpeed(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) {
if (!value) {
log_to(out, "$30=", spindle->maxSpeed())
log_to(out, "$30=", spindle->maxSpeed());
}
return Error::Ok;
}
Expand Down
8 changes: 8 additions & 0 deletions FluidNC/src/Spindles/Spindle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ namespace Spindles {
_speeds.push_back({ max, 100.0f });
}

uint32_t Spindle::maxSpeed() {
if (_speeds.size() == 0) {
return 0;
} else {
return _speeds[_speeds.size() - 1].speed;
}
}

uint32_t IRAM_ATTR Spindle::mapSpeed(SpindleSpeed speed) {
if (_speeds.size() == 0) {
return 0;
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Spindles/Spindle.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Spindles {

bool _defaultedSpeeds;
uint32_t offSpeed() { return _speeds[0].offset; }
uint32_t maxSpeed() { return _speeds[_speeds.size() - 1].speed; }
uint32_t maxSpeed();
uint32_t mapSpeed(SpindleSpeed speed);
void setupSpeeds(uint32_t max_dev_speed);
void shelfSpeeds(SpindleSpeed min, SpindleSpeed max);
Expand Down
29 changes: 25 additions & 4 deletions FluidNC/src/Spindles/VFDSpindle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
*/
#include "VFDSpindle.h"

#include "../Machine/MachineConfig.h"
#include "../MotionControl.h" // mc_critical
#include "../Protocol.h" // rtAlarm
#include "../Report.h" // hex message
#include "src/Machine/MachineConfig.h"
#include "src/MotionControl.h" // mc_critical
#include "src/Protocol.h" // rtAlarm
#include "src/Report.h" // hex message
#include "src/Configuration/HandlerType.h"

#include <freertos/task.h>
#include <freertos/queue.h>
Expand Down Expand Up @@ -474,4 +475,24 @@ namespace Spindles {

return crc;
}
void VFD::validate() {
Spindle::validate();
Assert(_uart != nullptr || _uart_num != -1, "VFD: missing UART configuration");
}

void VFD::group(Configuration::HandlerBase& handler) {
if (handler.handlerType() == Configuration::HandlerType::Generator) {
if (_uart_num == -1) {
handler.section("uart", _uart, 1);
} else {
handler.item("uart_num", _uart_num);
}
} else {
handler.section("uart", _uart, 1);
handler.item("uart_num", _uart_num);
}
handler.item("modbus_id", _modbus_id, 0, 247); // per https://modbus.org/docs/PI_MBUS_300.pdf

Spindle::group(handler);
}
}
15 changes: 2 additions & 13 deletions FluidNC/src/Spindles/VFDSpindle.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,8 @@ namespace Spindles {
SpindleSpeed _slop;

// Configuration handlers:
void validate() override {
Spindle::validate();
Assert(_uart != nullptr || _uart_num != -1, "VFD: missing UART configuration");
Assert(!(_uart != nullptr && _uart_num != -1), "VFD: conflicting UART configuration");
}

void group(Configuration::HandlerBase& handler) override {
handler.section("uart", _uart, 1);
handler.item("uart_num", _uart_num);
handler.item("modbus_id", _modbus_id, 0, 247); // per https://modbus.org/docs/PI_MBUS_300.pdf

Spindle::group(handler);
}
void validate() override;
void group(Configuration::HandlerBase& handler) override;

virtual ~VFD() {}
};
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Stepping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace Machine {
handler.item("idle_ms", _idleMsecs, 0, 10000000); // full range
handler.item("pulse_us", _pulseUsecs, 0, 30);
handler.item("dir_delay_us", _directionDelayUsecs, 0, 10);
handler.item("disable_delay_us", _disableDelayUsecs, 0, 10);
handler.item("disable_delay_us", _disableDelayUsecs, 0, 1000000); // max 1 second
handler.item("segments", _segments, 6, 20);
}

Expand Down
10 changes: 10 additions & 0 deletions FluidNC/src/WebUI/JSONEncoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,16 @@ namespace WebUI {
add(']');
}

// Begins the creation of a member whose value is an object.
// Call end_object() to close the member
void JSONencoder::begin_member_object(const char* tag) {
comma_line();
quoted(tag);
add(':');
add('{');
inc_level();
}

// Starts an object with {.
// If you need a named object you must call begin_member() first.
void JSONencoder::begin_object() {
Expand Down
10 changes: 6 additions & 4 deletions FluidNC/src/WebUI/JSONEncoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace WebUI {
void indent();
void line();

// begin_member() starts the creation of a member.
void begin_member(const char* tag);

std::string linebuf;

std::string* _str = nullptr;
Expand Down Expand Up @@ -58,10 +61,9 @@ namespace WebUI {
// end_object() closes the object with }
void end_object();

// begin_member() starts the creation of a member.
// The only case where you need to use it directly
// is when you want a member whose value is an object.
void begin_member(const char* tag);
// Begins the creation of a member whose value is an object.
// Call end_object() to close the member
void begin_member_object(const char* tag);

// The begin_webui() methods are specific to Esp3D_WebUI
// WebUI sends JSON objects to the UI to generate configuration
Expand Down
6 changes: 4 additions & 2 deletions FluidNC/src/WebUI/TelnetServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#ifdef ENABLE_WIFI

namespace WebUI {
TelnetServer telnetServer __attribute__((init_priority(107))) ;
TelnetServer telnetServer __attribute__((init_priority(107)));
}

# include "WifiServices.h"
Expand Down Expand Up @@ -50,7 +50,9 @@ namespace WebUI {
_setupdone = true;

//add mDNS
MDNS.addService("telnet", "tcp", _port);
if (WebUI::wifi_sta_ssdp->get()) {
MDNS.addService("telnet", "tcp", _port);
}

return no_error;
}
Expand Down
7 changes: 4 additions & 3 deletions FluidNC/src/WebUI/WebServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace WebUI {

static const char LOCATION_HEADER[] = "Location";

Web_Server webServer __attribute__((init_priority(108))) ;
Web_Server webServer __attribute__((init_priority(108)));
bool Web_Server::_setupdone = false;
uint16_t Web_Server::_port = 0;

Expand Down Expand Up @@ -159,7 +159,7 @@ namespace WebUI {
}

//SSDP service presentation
if (WiFi.getMode() == WIFI_STA) {
if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get()) {
_webserver->on("/description.xml", HTTP_GET, handle_SSDP);
//Add specific for SSDP
SSDP.setSchemaURL("description.xml");
Expand All @@ -185,7 +185,7 @@ namespace WebUI {
_webserver->begin();

//add mDNS
if (WiFi.getMode() == WIFI_STA) {
if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get()) {
MDNS.addService("http", "tcp", _port);
}

Expand Down Expand Up @@ -329,6 +329,7 @@ namespace WebUI {
void Web_Server::send404Page() { sendWithOurAddress(PAGE_404, 404); }

void Web_Server::handle_root() {
log_info("WebUI: Request from " << _webserver->client().remoteIP());
if (!(_webserver->hasArg("forcefallback") && _webserver->arg("forcefallback") == "yes")) {
if (myStreamFile("index.html")) {
return;
Expand Down
Loading

0 comments on commit 0222615

Please sign in to comment.