From f7369e5aa40691e3d16a8414a9c38b4563f1446e Mon Sep 17 00:00:00 2001 From: bdring Date: Wed, 4 Oct 2023 14:22:00 -0500 Subject: [PATCH 01/13] SSDP Fix again after PR1004 got lost I think this was lost when main and devt got out of sync --- FluidNC/src/WebUI/TelnetServer.cpp | 10 ++-- FluidNC/src/WebUI/WebServer.cpp | 38 ++++++++++---- FluidNC/src/WebUI/WifiConfig.cpp | 40 +++++++++++---- FluidNC/src/WebUI/WifiConfig.h | 5 ++ FluidNC/src/WebUI/WifiServices.cpp | 82 ++++++++++++++++-------------- 5 files changed, 112 insertions(+), 63 deletions(-) diff --git a/FluidNC/src/WebUI/TelnetServer.cpp b/FluidNC/src/WebUI/TelnetServer.cpp index f8329f9a2..0abf7d54c 100644 --- a/FluidNC/src/WebUI/TelnetServer.cpp +++ b/FluidNC/src/WebUI/TelnetServer.cpp @@ -9,7 +9,7 @@ #ifdef ENABLE_WIFI namespace WebUI { - TelnetServer telnetServer __attribute__((init_priority(107))) ; + TelnetServer telnetServer __attribute__((init_priority(107))); } # include "WifiServices.h" @@ -50,7 +50,9 @@ namespace WebUI { _setupdone = true; //add mDNS - MDNS.addService("telnet", "tcp", _port); + if (WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) { + MDNS.addService("telnet", "tcp", _port); + } return no_error; } @@ -90,7 +92,9 @@ namespace WebUI { allChannels.registration(tnc); } } - TelnetServer::~TelnetServer() { end(); } + TelnetServer::~TelnetServer() { + end(); + } } #endif diff --git a/FluidNC/src/WebUI/WebServer.cpp b/FluidNC/src/WebUI/WebServer.cpp index 2c0bf3e89..2c2ddf193 100644 --- a/FluidNC/src/WebUI/WebServer.cpp +++ b/FluidNC/src/WebUI/WebServer.cpp @@ -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; @@ -87,7 +87,9 @@ namespace WebUI { &onoffOptions, NULL); } - Web_Server::~Web_Server() { end(); } + Web_Server::~Web_Server() { + end(); + } bool Web_Server::begin() { bool no_error = true; @@ -159,7 +161,7 @@ namespace WebUI { } //SSDP service presentation - if (WiFi.getMode() == WIFI_STA) { + if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) { _webserver->on("/description.xml", HTTP_GET, handle_SSDP); //Add specific for SSDP SSDP.setSchemaURL("description.xml"); @@ -185,7 +187,7 @@ namespace WebUI { _webserver->begin(); //add mDNS - if (WiFi.getMode() == WIFI_STA) { + if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) { MDNS.addService("http", "tcp", _port); } @@ -316,7 +318,9 @@ namespace WebUI { "interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) " "\n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n\n\n\n\n\n"; - void Web_Server::sendCaptivePortal() { sendWithOurAddress(PAGE_CAPTIVE, 200); } + void Web_Server::sendCaptivePortal() { + sendWithOurAddress(PAGE_CAPTIVE, 200); + } //Default 404 page that is sent when a request cannot be satisfied const char PAGE_404[] = @@ -326,7 +330,9 @@ namespace WebUI { "interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) " "\n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n\n\n\n\n\n"; - void Web_Server::send404Page() { sendWithOurAddress(PAGE_404, 404); } + void Web_Server::send404Page() { + sendWithOurAddress(PAGE_404, 404); + } void Web_Server::handle_root() { if (!(_webserver->hasArg("forcefallback") && _webserver->arg("forcefallback") == "yes")) { @@ -752,10 +758,16 @@ namespace WebUI { sendJSON(code, s); } - void Web_Server::sendAuthFailed() { sendStatus(401, "Authentication failed"); } + void Web_Server::sendAuthFailed() { + sendStatus(401, "Authentication failed"); + } - void Web_Server::LocalFSFileupload() { fileUpload(localfsName); } - void Web_Server::SDFileUpload() { fileUpload(sdName); } + void Web_Server::LocalFSFileupload() { + fileUpload(localfsName); + } + void Web_Server::SDFileUpload() { + fileUpload(sdName); + } //Web Update handler void Web_Server::handleUpdate() { @@ -1000,8 +1012,12 @@ namespace WebUI { sendJSON(200, s); } - void Web_Server::handle_direct_SDFileList() { handleFileOps(sdName); } - void Web_Server::handleFileList() { handleFileOps(localfsName); } + void Web_Server::handle_direct_SDFileList() { + handleFileOps(sdName); + } + void Web_Server::handleFileList() { + handleFileOps(localfsName); + } // File upload void Web_Server::uploadStart(const char* filename, size_t filesize, const char* fs) { diff --git a/FluidNC/src/WebUI/WifiConfig.cpp b/FluidNC/src/WebUI/WifiConfig.cpp index 6798fc4f2..49c542e58 100644 --- a/FluidNC/src/WebUI/WifiConfig.cpp +++ b/FluidNC/src/WebUI/WifiConfig.cpp @@ -8,14 +8,14 @@ #include #include -WebUI::WiFiConfig wifi_config __attribute__((init_priority(109))) ; +WebUI::WiFiConfig wifi_config __attribute__((init_priority(109))); #ifdef ENABLE_WIFI # include "../Config.h" # include "../Main.h" -# include "Commands.h" // COMMANDS -# include "WifiServices.h" // wifi_services.start() etc. -# include "WebSettings.h" // split_params(), get_params() +# include "Commands.h" // COMMANDS +# include "WifiServices.h" // wifi_services.start() etc. +# include "WebSettings.h" // split_params(), get_params() # include "WebServer.h" // webServer.port() # include "TelnetServer.h" // telnetServer @@ -114,6 +114,7 @@ namespace WebUI { IPaddrSetting* wifi_sta_ip; IPaddrSetting* wifi_sta_gateway; IPaddrSetting* wifi_sta_netmask; + EnumSetting* wifi_sta_ssdp; StringSetting* wifi_ap_ssid; StringSetting* wifi_ap_password; @@ -139,7 +140,14 @@ namespace WebUI { { "WPA2-ENTERPRISE", WIFI_AUTH_WPA2_ENTERPRISE }, }; - static void print_mac(Channel& out, const char* prefix, const char* mac) { log_to(out, prefix, " (" << mac << ")"); } + enum_opt_t staSsdpModeOptions = { + { "Enable", SSDP_ENABLED }, + { "Disabled", SSDP_DISABLED }, + }; + + static void print_mac(Channel& out, const char* prefix, const char* mac) { + log_to(out, prefix, " (" << mac << ")"); + } static Error showIP(char* parameter, AuthenticationLevel auth_level, Channel& out) { // ESP111 log_to(out, parameter, IP_string(WiFi.getMode() == WIFI_STA ? WiFi.localIP() : WiFi.softAPIP())); @@ -338,7 +346,9 @@ namespace WebUI { MAX_PASSWORD_LENGTH, (bool (*)(char*))WiFiConfig::isPasswordValid); wifi_ap_ssid = new StringSetting("AP SSID", WEBSET, WA, "ESP105", "AP/SSID", DEFAULT_AP_SSID, MIN_SSID_LENGTH, MAX_SSID_LENGTH, NULL); - wifi_ap_country = new EnumSetting("AP regulatory domain", WEBSET, WA, NULL, "AP/Country", WiFiCountry01, &wifiContryOptions, NULL); + wifi_ap_country = new EnumSetting("AP regulatory domain", WEBSET, WA, NULL, "AP/Country", WiFiCountry01, &wifiContryOptions, NULL); + wifi_sta_ssdp = + new EnumSetting("SSDP and mDNS enable", WEBSET, WA, NULL, "Sta/SSDP/Enable", DEFAULT_STA_SSDP_MODE, &onoffOptions, NULL); wifi_sta_netmask = new IPaddrSetting("Station Static Mask", WEBSET, WA, NULL, "Sta/Netmask", DEFAULT_STA_MK, NULL); wifi_sta_gateway = new IPaddrSetting("Station Static Gateway", WEBSET, WA, NULL, "Sta/Gateway", DEFAULT_STA_GW, NULL); wifi_sta_ip = new IPaddrSetting("Station Static IP", WEBSET, WA, NULL, "Sta/IP", DEFAULT_STA_IP, NULL); @@ -777,7 +787,9 @@ namespace WebUI { /** * End WiFi */ - void WiFiConfig::end() { StopWiFi(); } + void WiFiConfig::end() { + StopWiFi(); + } /** * Reset ESP @@ -797,12 +809,16 @@ namespace WebUI { } log_info("WiFi reset done"); } - bool WiFiConfig::isOn() { return !(WiFi.getMode() == WIFI_MODE_NULL); } + bool WiFiConfig::isOn() { + return !(WiFi.getMode() == WIFI_MODE_NULL); + } /** * Handle not critical actions that must be done in sync environment */ - void WiFiConfig::handle() { wifi_services.handle(); } + void WiFiConfig::handle() { + wifi_services.handle(); + } // Used by js/scanwifidlg.js Error WiFiConfig::listAPs(char* parameter, AuthenticationLevel auth_level, Channel& out) { // ESP410 @@ -816,7 +832,7 @@ namespace WebUI { case -2: // Scan not triggered WiFi.scanNetworks(true); // Begin async scan break; - case -1: // Scan in progress + case -1: // Scan in progress break; default: for (int i = 0; i < n; ++i) { @@ -841,6 +857,8 @@ namespace WebUI { return Error::Ok; } - WiFiConfig::~WiFiConfig() { end(); } + WiFiConfig::~WiFiConfig() { + end(); + } } #endif diff --git a/FluidNC/src/WebUI/WifiConfig.h b/FluidNC/src/WebUI/WifiConfig.h index ad818e294..b13a1d0c1 100644 --- a/FluidNC/src/WebUI/WifiConfig.h +++ b/FluidNC/src/WebUI/WifiConfig.h @@ -41,6 +41,9 @@ namespace WebUI { static const int DHCP_MODE = 0; static const int STATIC_MODE = 1; + static const int SSDP_DISABLED = 0; + static const int SSDP_ENABLED = 1; + //defaults values static const char* DEFAULT_HOSTNAME = "fluidnc"; static const char* DEFAULT_STA_SSID = ""; @@ -56,6 +59,7 @@ namespace WebUI { static const int DEFAULT_STA_MIN_SECURITY = WIFI_AUTH_WPA2_PSK; static const int DEFAULT_STA_IP_MODE = DHCP_MODE; + static const int DEFAULT_STA_SSDP_MODE = SSDP_ENABLED; static const char* HIDDEN_PASSWORD = "********"; //boundaries @@ -124,6 +128,7 @@ namespace WebUI { extern IPaddrSetting* wifi_sta_ip; extern IPaddrSetting* wifi_sta_gateway; extern IPaddrSetting* wifi_sta_netmask; + extern EnumSetting* wifi_sta_ssdp; extern StringSetting* wifi_ap_ssid; extern StringSetting* wifi_ap_password; diff --git a/FluidNC/src/WebUI/WifiServices.cpp b/FluidNC/src/WebUI/WifiServices.cpp index d01a002c6..1fa4bd570 100644 --- a/FluidNC/src/WebUI/WifiServices.cpp +++ b/FluidNC/src/WebUI/WifiServices.cpp @@ -10,9 +10,13 @@ namespace WebUI { WiFiServices wifi_services; WiFiServices::WiFiServices() {} - WiFiServices::~WiFiServices() { end(); } + WiFiServices::~WiFiServices() { + end(); + } - bool WiFiServices::begin() { return false; } + bool WiFiServices::begin() { + return false; + } void WiFiServices::end() {} void WiFiServices::handle() {} } @@ -33,7 +37,9 @@ namespace WebUI { WiFiServices wifi_services; WiFiServices::WiFiServices() {} - WiFiServices::~WiFiServices() { end(); } + WiFiServices::~WiFiServices() { + end(); + } bool WiFiServices::begin() { bool no_error = true; @@ -82,49 +88,49 @@ namespace WebUI { }); ArduinoOTA.begin(); //no need in AP mode - if (WiFi.getMode() == WIFI_STA) { + if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) //start mDns const char* h = wifi_hostname->get(); - if (!MDNS.begin(h)) { - log_info("Cannot start mDNS"); - no_error = false; - } else { - log_info("Start mDNS with hostname:http://" << h << ".local/"); - } + if (!MDNS.begin(h)) { + log_info("Cannot start mDNS"); + no_error = false; + } else { + log_info("Start mDNS with hostname:http://" << h << ".local/"); } - webServer.begin(); - telnetServer.begin(); - notificationsService.begin(); - - //be sure we are not is mixed mode in setup - WiFi.scanNetworks(true); - return no_error; } - void WiFiServices::end() { - notificationsService.end(); - telnetServer.end(); - webServer.end(); + webServer.begin(); + telnetServer.begin(); + notificationsService.begin(); - //stop OTA - ArduinoOTA.end(); + //be sure we are not is mixed mode in setup + WiFi.scanNetworks(true); + return no_error; +} +void WiFiServices::end() { + notificationsService.end(); + telnetServer.end(); + webServer.end(); - //Stop mDNS - MDNS.end(); - } + //stop OTA + ArduinoOTA.end(); - void WiFiServices::handle() { - //to avoid mixed mode due to scan network - if (WiFi.getMode() == WIFI_AP_STA) { - // In principle it should be sufficient to check for != WIFI_SCAN_RUNNING, - // but that does not work well. Doing so makes scans in AP mode unreliable. - // Sometimes the first try works, but subsequent scans fail. - if (WiFi.scanComplete() >= 0) { - WiFi.enableSTA(false); - } + //Stop mDNS + MDNS.end(); +} + +void WiFiServices::handle() { + //to avoid mixed mode due to scan network + if (WiFi.getMode() == WIFI_AP_STA) { + // In principle it should be sufficient to check for != WIFI_SCAN_RUNNING, + // but that does not work well. Doing so makes scans in AP mode unreliable. + // Sometimes the first try works, but subsequent scans fail. + if (WiFi.scanComplete() >= 0) { + WiFi.enableSTA(false); } - ArduinoOTA.handle(); - webServer.handle(); - telnetServer.handle(); } + ArduinoOTA.handle(); + webServer.handle(); + telnetServer.handle(); +} } #endif From c8a8545b857fc15471017903288501132eadd650 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Wed, 4 Oct 2023 10:16:45 -1000 Subject: [PATCH 02/13] Fixed missing brace and eliminated unnecessary enum --- FluidNC/src/WebUI/TelnetServer.cpp | 6 +-- FluidNC/src/WebUI/WebServer.cpp | 36 ++++--------- FluidNC/src/WebUI/WifiConfig.cpp | 35 ++++--------- FluidNC/src/WebUI/WifiConfig.h | 5 +- FluidNC/src/WebUI/WifiServices.cpp | 82 ++++++++++++++---------------- 5 files changed, 61 insertions(+), 103 deletions(-) diff --git a/FluidNC/src/WebUI/TelnetServer.cpp b/FluidNC/src/WebUI/TelnetServer.cpp index 0abf7d54c..3d82381e2 100644 --- a/FluidNC/src/WebUI/TelnetServer.cpp +++ b/FluidNC/src/WebUI/TelnetServer.cpp @@ -50,7 +50,7 @@ namespace WebUI { _setupdone = true; //add mDNS - if (WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) { + if (WebUI::wifi_sta_ssdp->get()) { MDNS.addService("telnet", "tcp", _port); } @@ -92,9 +92,7 @@ namespace WebUI { allChannels.registration(tnc); } } - TelnetServer::~TelnetServer() { - end(); - } + TelnetServer::~TelnetServer() { end(); } } #endif diff --git a/FluidNC/src/WebUI/WebServer.cpp b/FluidNC/src/WebUI/WebServer.cpp index 2c2ddf193..224ca3e69 100644 --- a/FluidNC/src/WebUI/WebServer.cpp +++ b/FluidNC/src/WebUI/WebServer.cpp @@ -87,9 +87,7 @@ namespace WebUI { &onoffOptions, NULL); } - Web_Server::~Web_Server() { - end(); - } + Web_Server::~Web_Server() { end(); } bool Web_Server::begin() { bool no_error = true; @@ -161,7 +159,7 @@ namespace WebUI { } //SSDP service presentation - if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) { + 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"); @@ -187,7 +185,7 @@ namespace WebUI { _webserver->begin(); //add mDNS - if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) { + if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get()) { MDNS.addService("http", "tcp", _port); } @@ -318,9 +316,7 @@ namespace WebUI { "interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) " "\n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n\n\n\n\n\n"; - void Web_Server::sendCaptivePortal() { - sendWithOurAddress(PAGE_CAPTIVE, 200); - } + void Web_Server::sendCaptivePortal() { sendWithOurAddress(PAGE_CAPTIVE, 200); } //Default 404 page that is sent when a request cannot be satisfied const char PAGE_404[] = @@ -330,9 +326,7 @@ namespace WebUI { "interval=setInterval(function(){\ni=i+1; \nvar x = document.getElementById(\"prg\"); \nx.value=i; \nif (i>5) " "\n{\nclearInterval(interval);\nwindow.location.href='/';\n}\n},1000);\n\n\n\n\n\n"; - void Web_Server::send404Page() { - sendWithOurAddress(PAGE_404, 404); - } + void Web_Server::send404Page() { sendWithOurAddress(PAGE_404, 404); } void Web_Server::handle_root() { if (!(_webserver->hasArg("forcefallback") && _webserver->arg("forcefallback") == "yes")) { @@ -758,16 +752,10 @@ namespace WebUI { sendJSON(code, s); } - void Web_Server::sendAuthFailed() { - sendStatus(401, "Authentication failed"); - } + void Web_Server::sendAuthFailed() { sendStatus(401, "Authentication failed"); } - void Web_Server::LocalFSFileupload() { - fileUpload(localfsName); - } - void Web_Server::SDFileUpload() { - fileUpload(sdName); - } + void Web_Server::LocalFSFileupload() { fileUpload(localfsName); } + void Web_Server::SDFileUpload() { fileUpload(sdName); } //Web Update handler void Web_Server::handleUpdate() { @@ -1012,12 +1000,8 @@ namespace WebUI { sendJSON(200, s); } - void Web_Server::handle_direct_SDFileList() { - handleFileOps(sdName); - } - void Web_Server::handleFileList() { - handleFileOps(localfsName); - } + void Web_Server::handle_direct_SDFileList() { handleFileOps(sdName); } + void Web_Server::handleFileList() { handleFileOps(localfsName); } // File upload void Web_Server::uploadStart(const char* filename, size_t filesize, const char* fs) { diff --git a/FluidNC/src/WebUI/WifiConfig.cpp b/FluidNC/src/WebUI/WifiConfig.cpp index 49c542e58..7fd4523d4 100644 --- a/FluidNC/src/WebUI/WifiConfig.cpp +++ b/FluidNC/src/WebUI/WifiConfig.cpp @@ -13,9 +13,9 @@ WebUI::WiFiConfig wifi_config __attribute__((init_priority(109))); #ifdef ENABLE_WIFI # include "../Config.h" # include "../Main.h" -# include "Commands.h" // COMMANDS -# include "WifiServices.h" // wifi_services.start() etc. -# include "WebSettings.h" // split_params(), get_params() +# include "Commands.h" // COMMANDS +# include "WifiServices.h" // wifi_services.start() etc. +# include "WebSettings.h" // split_params(), get_params() # include "WebServer.h" // webServer.port() # include "TelnetServer.h" // telnetServer @@ -140,14 +140,7 @@ namespace WebUI { { "WPA2-ENTERPRISE", WIFI_AUTH_WPA2_ENTERPRISE }, }; - enum_opt_t staSsdpModeOptions = { - { "Enable", SSDP_ENABLED }, - { "Disabled", SSDP_DISABLED }, - }; - - static void print_mac(Channel& out, const char* prefix, const char* mac) { - log_to(out, prefix, " (" << mac << ")"); - } + static void print_mac(Channel& out, const char* prefix, const char* mac) { log_to(out, prefix, " (" << mac << ")"); } static Error showIP(char* parameter, AuthenticationLevel auth_level, Channel& out) { // ESP111 log_to(out, parameter, IP_string(WiFi.getMode() == WIFI_STA ? WiFi.localIP() : WiFi.softAPIP())); @@ -348,7 +341,7 @@ namespace WebUI { wifi_ap_ssid = new StringSetting("AP SSID", WEBSET, WA, "ESP105", "AP/SSID", DEFAULT_AP_SSID, MIN_SSID_LENGTH, MAX_SSID_LENGTH, NULL); wifi_ap_country = new EnumSetting("AP regulatory domain", WEBSET, WA, NULL, "AP/Country", WiFiCountry01, &wifiContryOptions, NULL); wifi_sta_ssdp = - new EnumSetting("SSDP and mDNS enable", WEBSET, WA, NULL, "Sta/SSDP/Enable", DEFAULT_STA_SSDP_MODE, &onoffOptions, NULL); + new EnumSetting("SSDP and mDNS enable", WEBSET, WA, NULL, "Sta/SSDP/Enable", DEFAULT_STA_SSDP_ENABLED, &onoffOptions, NULL); wifi_sta_netmask = new IPaddrSetting("Station Static Mask", WEBSET, WA, NULL, "Sta/Netmask", DEFAULT_STA_MK, NULL); wifi_sta_gateway = new IPaddrSetting("Station Static Gateway", WEBSET, WA, NULL, "Sta/Gateway", DEFAULT_STA_GW, NULL); wifi_sta_ip = new IPaddrSetting("Station Static IP", WEBSET, WA, NULL, "Sta/IP", DEFAULT_STA_IP, NULL); @@ -787,9 +780,7 @@ namespace WebUI { /** * End WiFi */ - void WiFiConfig::end() { - StopWiFi(); - } + void WiFiConfig::end() { StopWiFi(); } /** * Reset ESP @@ -809,16 +800,12 @@ namespace WebUI { } log_info("WiFi reset done"); } - bool WiFiConfig::isOn() { - return !(WiFi.getMode() == WIFI_MODE_NULL); - } + bool WiFiConfig::isOn() { return !(WiFi.getMode() == WIFI_MODE_NULL); } /** * Handle not critical actions that must be done in sync environment */ - void WiFiConfig::handle() { - wifi_services.handle(); - } + void WiFiConfig::handle() { wifi_services.handle(); } // Used by js/scanwifidlg.js Error WiFiConfig::listAPs(char* parameter, AuthenticationLevel auth_level, Channel& out) { // ESP410 @@ -832,7 +819,7 @@ namespace WebUI { case -2: // Scan not triggered WiFi.scanNetworks(true); // Begin async scan break; - case -1: // Scan in progress + case -1: // Scan in progress break; default: for (int i = 0; i < n; ++i) { @@ -857,8 +844,6 @@ namespace WebUI { return Error::Ok; } - WiFiConfig::~WiFiConfig() { - end(); - } + WiFiConfig::~WiFiConfig() { end(); } } #endif diff --git a/FluidNC/src/WebUI/WifiConfig.h b/FluidNC/src/WebUI/WifiConfig.h index b13a1d0c1..8ff92f1db 100644 --- a/FluidNC/src/WebUI/WifiConfig.h +++ b/FluidNC/src/WebUI/WifiConfig.h @@ -41,9 +41,6 @@ namespace WebUI { static const int DHCP_MODE = 0; static const int STATIC_MODE = 1; - static const int SSDP_DISABLED = 0; - static const int SSDP_ENABLED = 1; - //defaults values static const char* DEFAULT_HOSTNAME = "fluidnc"; static const char* DEFAULT_STA_SSID = ""; @@ -59,7 +56,7 @@ namespace WebUI { static const int DEFAULT_STA_MIN_SECURITY = WIFI_AUTH_WPA2_PSK; static const int DEFAULT_STA_IP_MODE = DHCP_MODE; - static const int DEFAULT_STA_SSDP_MODE = SSDP_ENABLED; + static const int DEFAULT_STA_SSDP_ENABLED = true; static const char* HIDDEN_PASSWORD = "********"; //boundaries diff --git a/FluidNC/src/WebUI/WifiServices.cpp b/FluidNC/src/WebUI/WifiServices.cpp index 1fa4bd570..0d322abdd 100644 --- a/FluidNC/src/WebUI/WifiServices.cpp +++ b/FluidNC/src/WebUI/WifiServices.cpp @@ -10,13 +10,9 @@ namespace WebUI { WiFiServices wifi_services; WiFiServices::WiFiServices() {} - WiFiServices::~WiFiServices() { - end(); - } + WiFiServices::~WiFiServices() { end(); } - bool WiFiServices::begin() { - return false; - } + bool WiFiServices::begin() { return false; } void WiFiServices::end() {} void WiFiServices::handle() {} } @@ -37,9 +33,7 @@ namespace WebUI { WiFiServices wifi_services; WiFiServices::WiFiServices() {} - WiFiServices::~WiFiServices() { - end(); - } + WiFiServices::~WiFiServices() { end(); } bool WiFiServices::begin() { bool no_error = true; @@ -88,49 +82,49 @@ namespace WebUI { }); ArduinoOTA.begin(); //no need in AP mode - if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get() == SSDP_ENABLED) + if (WiFi.getMode() == WIFI_STA && WebUI::wifi_sta_ssdp->get()) { //start mDns const char* h = wifi_hostname->get(); - if (!MDNS.begin(h)) { - log_info("Cannot start mDNS"); - no_error = false; - } else { - log_info("Start mDNS with hostname:http://" << h << ".local/"); + if (!MDNS.begin(h)) { + log_info("Cannot start mDNS"); + no_error = false; + } else { + log_info("Start mDNS with hostname:http://" << h << ".local/"); + } } - } - webServer.begin(); - telnetServer.begin(); - notificationsService.begin(); + webServer.begin(); + telnetServer.begin(); + notificationsService.begin(); - //be sure we are not is mixed mode in setup - WiFi.scanNetworks(true); - return no_error; -} -void WiFiServices::end() { - notificationsService.end(); - telnetServer.end(); - webServer.end(); + //be sure we are not is mixed mode in setup + WiFi.scanNetworks(true); + return no_error; + } + void WiFiServices::end() { + notificationsService.end(); + telnetServer.end(); + webServer.end(); - //stop OTA - ArduinoOTA.end(); + //stop OTA + ArduinoOTA.end(); - //Stop mDNS - MDNS.end(); -} + //Stop mDNS + MDNS.end(); + } -void WiFiServices::handle() { - //to avoid mixed mode due to scan network - if (WiFi.getMode() == WIFI_AP_STA) { - // In principle it should be sufficient to check for != WIFI_SCAN_RUNNING, - // but that does not work well. Doing so makes scans in AP mode unreliable. - // Sometimes the first try works, but subsequent scans fail. - if (WiFi.scanComplete() >= 0) { - WiFi.enableSTA(false); + void WiFiServices::handle() { + //to avoid mixed mode due to scan network + if (WiFi.getMode() == WIFI_AP_STA) { + // In principle it should be sufficient to check for != WIFI_SCAN_RUNNING, + // but that does not work well. Doing so makes scans in AP mode unreliable. + // Sometimes the first try works, but subsequent scans fail. + if (WiFi.scanComplete() >= 0) { + WiFi.enableSTA(false); + } } + ArduinoOTA.handle(); + webServer.handle(); + telnetServer.handle(); } - ArduinoOTA.handle(); - webServer.handle(); - telnetServer.handle(); -} } #endif From d0ba0959352a53e1cd9346ee4d79c56d207c569a Mon Sep 17 00:00:00 2001 From: bdring Date: Fri, 6 Oct 2023 20:41:59 -0500 Subject: [PATCH 03/13] Fix add $30 to $$ report Also fixed errors when there is no spindle. --- FluidNC/src/ProcessSettings.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/FluidNC/src/ProcessSettings.cpp b/FluidNC/src/ProcessSettings.cpp index 4c2a29dab..047860572 100644 --- a/FluidNC/src/ProcessSettings.cpp +++ b/FluidNC/src/ProcessSettings.cpp @@ -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(); @@ -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 @@ -687,14 +691,22 @@ 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()) + if (spindle != nullptr) { + log_to(out, "$30=0"); + } else { + log_to(out, "$30=", spindle->maxSpeed()); + } } return Error::Ok; } static Error fakeLaserMode(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) { if (!value) { - log_to(out, "$32=", (spindle->isRateAdjusted() ? "1" : "0")); + if (spindle != nullptr) { + log_to(out, "$32=0"); + } else { + log_to(out, "$32=", (spindle->isRateAdjusted() ? "1" : "0")); + } } return Error::Ok; } From 094db49a9b6b30755589b763ad19658ab8f7b5d5 Mon Sep 17 00:00:00 2001 From: bdring Date: Fri, 6 Oct 2023 21:37:18 -0500 Subject: [PATCH 04/13] Fixed .... spindle is never nullptr --- FluidNC/src/ProcessSettings.cpp | 12 ++---------- FluidNC/src/Spindles/Spindle.cpp | 8 ++++++++ FluidNC/src/Spindles/Spindle.h | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/FluidNC/src/ProcessSettings.cpp b/FluidNC/src/ProcessSettings.cpp index 047860572..dbd6d7116 100644 --- a/FluidNC/src/ProcessSettings.cpp +++ b/FluidNC/src/ProcessSettings.cpp @@ -691,22 +691,14 @@ 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) { - if (spindle != nullptr) { - log_to(out, "$30=0"); - } else { - log_to(out, "$30=", spindle->maxSpeed()); - } + log_to(out, "$30=", spindle->maxSpeed()); } return Error::Ok; } static Error fakeLaserMode(const char* value, WebUI::AuthenticationLevel auth_level, Channel& out) { if (!value) { - if (spindle != nullptr) { - log_to(out, "$32=0"); - } else { - log_to(out, "$32=", (spindle->isRateAdjusted() ? "1" : "0")); - } + log_to(out, "$32=", (spindle->isRateAdjusted() ? "1" : "0")); } return Error::Ok; } diff --git a/FluidNC/src/Spindles/Spindle.cpp b/FluidNC/src/Spindles/Spindle.cpp index fa617f8e7..eefc09aea 100644 --- a/FluidNC/src/Spindles/Spindle.cpp +++ b/FluidNC/src/Spindles/Spindle.cpp @@ -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; diff --git a/FluidNC/src/Spindles/Spindle.h b/FluidNC/src/Spindles/Spindle.h index ccf5d3255..ee772a990 100644 --- a/FluidNC/src/Spindles/Spindle.h +++ b/FluidNC/src/Spindles/Spindle.h @@ -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(); // { return _speeds[_speeds.size() - 1].speed; } uint32_t mapSpeed(SpindleSpeed speed); void setupSpeeds(uint32_t max_dev_speed); void shelfSpeeds(SpindleSpeed min, SpindleSpeed max); From 184afd43f0084d79b6a359988aafcd941b304b66 Mon Sep 17 00:00:00 2001 From: bdring Date: Sat, 7 Oct 2023 13:04:33 -0500 Subject: [PATCH 05/13] cleanup --- FluidNC/src/Spindles/Spindle.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FluidNC/src/Spindles/Spindle.h b/FluidNC/src/Spindles/Spindle.h index ee772a990..85e7be5e6 100644 --- a/FluidNC/src/Spindles/Spindle.h +++ b/FluidNC/src/Spindles/Spindle.h @@ -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); From 7ba12439fa7f63c41e01902846c15c19c642cad4 Mon Sep 17 00:00:00 2001 From: Mike Melancon Date: Mon, 9 Oct 2023 16:11:27 -0500 Subject: [PATCH 06/13] Fixed bug in JSONEncoder when trying to create a member whose value is an object --- FluidNC/src/WebUI/JSONEncoder.cpp | 10 ++++++++++ FluidNC/src/WebUI/JSONEncoder.h | 10 ++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/FluidNC/src/WebUI/JSONEncoder.cpp b/FluidNC/src/WebUI/JSONEncoder.cpp index 4c6cc6fa9..68db060cc 100644 --- a/FluidNC/src/WebUI/JSONEncoder.cpp +++ b/FluidNC/src/WebUI/JSONEncoder.cpp @@ -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() { diff --git a/FluidNC/src/WebUI/JSONEncoder.h b/FluidNC/src/WebUI/JSONEncoder.h index 7d8298fc7..e5444ff74 100644 --- a/FluidNC/src/WebUI/JSONEncoder.h +++ b/FluidNC/src/WebUI/JSONEncoder.h @@ -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; @@ -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 From 2da13ded6b4a30b3e7e21d8bc2858b0db0b0fa5a Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Tue, 10 Oct 2023 04:26:58 -1000 Subject: [PATCH 07/13] Reinstated a macro fix that got lost in a git mixup --- FluidNC/src/Error.cpp | 1 + FluidNC/src/Error.h | 1 + FluidNC/src/GCode.cpp | 3 +++ FluidNC/src/Machine/Macros.cpp | 18 ++++++++++-------- FluidNC/src/Machine/Macros.h | 22 +++++++++++----------- 5 files changed, 26 insertions(+), 19 deletions(-) diff --git a/FluidNC/src/Error.cpp b/FluidNC/src/Error.cpp index 7722f3d2c..45de5ab93 100644 --- a/FluidNC/src/Error.cpp +++ b/FluidNC/src/Error.cpp @@ -68,6 +68,7 @@ std::map 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" }, diff --git a/FluidNC/src/Error.h b/FluidNC/src/Error.h index a8387b25e..590c5a816 100644 --- a/FluidNC/src/Error.h +++ b/FluidNC/src/Error.h @@ -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, diff --git a/FluidNC/src/GCode.cpp b/FluidNC/src/GCode.cpp index 3d74db282..1ea5e722a 100644 --- a/FluidNC/src/GCode.cpp +++ b/FluidNC/src/GCode.cpp @@ -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) { diff --git a/FluidNC/src/Machine/Macros.cpp b/FluidNC/src/Machine/Macros.cpp index f58379e73..2f4e529b3 100644 --- a/FluidNC/src/Machine/Macros.cpp +++ b/FluidNC/src/Machine/Macros.cpp @@ -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" }; @@ -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; diff --git a/FluidNC/src/Machine/Macros.h b/FluidNC/src/Machine/Macros.h index a462bc0c6..80358fd01 100644 --- a/FluidNC/src/Machine/Macros.h +++ b/FluidNC/src/Machine/Macros.h @@ -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(); }; @@ -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() {} From 3a5e93a61929b3e2688e18c9d18bc648d5e1ced7 Mon Sep 17 00:00:00 2001 From: Mike Melancon Date: Wed, 11 Oct 2023 17:07:55 -0500 Subject: [PATCH 08/13] Fix Generation of JSON for boolean settings --- FluidNC/src/Configuration/JsonGenerator.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/FluidNC/src/Configuration/JsonGenerator.cpp b/FluidNC/src/Configuration/JsonGenerator.cpp index 54597fc0d..d8b306932 100644 --- a/FluidNC/src/Configuration/JsonGenerator.cpp +++ b/FluidNC/src/Configuration/JsonGenerator.cpp @@ -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(); } From 10c9199613cc32ed1cdad29376158c1d99309725 Mon Sep 17 00:00:00 2001 From: bdring Date: Mon, 16 Oct 2023 12:38:38 -0500 Subject: [PATCH 09/13] possible fix --- FluidNC/src/Machine/Axes.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/FluidNC/src/Machine/Axes.cpp b/FluidNC/src/Machine/Axes.cpp index 06f349f9a..336c4a8dc 100644 --- a/FluidNC/src/Machine/Axes.cpp +++ b/FluidNC/src/Machine/Axes.cpp @@ -65,6 +65,10 @@ namespace Machine { } _sharedStepperDisable.synchronousWrite(disable); + + if (!disable) { // wait for the enable delay + delay_us(config->_stepping->_disableDelayUsecs); + } } // Put the motors in the given axes into homing mode, returning a From 8d9d9529d082b912e075d5cb7c61438559420ad6 Mon Sep 17 00:00:00 2001 From: bdring Date: Mon, 16 Oct 2023 14:14:48 -0500 Subject: [PATCH 10/13] WIP --- FluidNC/src/Machine/Axes.cpp | 5 +++-- FluidNC/src/Stepping.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/FluidNC/src/Machine/Axes.cpp b/FluidNC/src/Machine/Axes.cpp index 336c4a8dc..ae7dc8121 100644 --- a/FluidNC/src/Machine/Axes.cpp +++ b/FluidNC/src/Machine/Axes.cpp @@ -66,9 +66,10 @@ namespace Machine { _sharedStepperDisable.synchronousWrite(disable); - if (!disable) { // wait for the enable delay + 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 diff --git a/FluidNC/src/Stepping.cpp b/FluidNC/src/Stepping.cpp index d677cfd6f..631c47687 100644 --- a/FluidNC/src/Stepping.cpp +++ b/FluidNC/src/Stepping.cpp @@ -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); } From f98ad13060b91918c0b6e0b121755684cf6579e0 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Wed, 25 Oct 2023 10:01:49 -1000 Subject: [PATCH 11/13] Fix #1051 - bad VFD UART validation and generation logic --- FluidNC/src/Spindles/VFDSpindle.cpp | 29 +++++++++++++++++++++++++---- FluidNC/src/Spindles/VFDSpindle.h | 15 ++------------- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/FluidNC/src/Spindles/VFDSpindle.cpp b/FluidNC/src/Spindles/VFDSpindle.cpp index b6055ecb6..9965eb4c4 100644 --- a/FluidNC/src/Spindles/VFDSpindle.cpp +++ b/FluidNC/src/Spindles/VFDSpindle.cpp @@ -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 #include @@ -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); + } } diff --git a/FluidNC/src/Spindles/VFDSpindle.h b/FluidNC/src/Spindles/VFDSpindle.h index d7f0aa816..58169134b 100644 --- a/FluidNC/src/Spindles/VFDSpindle.h +++ b/FluidNC/src/Spindles/VFDSpindle.h @@ -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() {} }; From 594296a2444450c1b07eca9261d115a9b8820b83 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Thu, 2 Nov 2023 08:17:31 -1000 Subject: [PATCH 12/13] New message to indicate an incoming WebUI connection --- FluidNC/src/OLED.cpp | 16 ++++++++++++++++ FluidNC/src/OLED.h | 1 + FluidNC/src/WebUI/WebServer.cpp | 1 + 3 files changed, 18 insertions(+) diff --git a/FluidNC/src/OLED.cpp b/FluidNC/src/OLED.cpp index 886631064..e65eacb7f 100644 --- a/FluidNC/src/OLED.cpp +++ b/FluidNC/src/OLED.cpp @@ -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; @@ -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 diff --git a/FluidNC/src/OLED.h b/FluidNC/src/OLED.h index 25e599696..833b4025a 100644 --- a/FluidNC/src/OLED.h +++ b/FluidNC/src/OLED.h @@ -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); diff --git a/FluidNC/src/WebUI/WebServer.cpp b/FluidNC/src/WebUI/WebServer.cpp index 224ca3e69..e72e533e8 100644 --- a/FluidNC/src/WebUI/WebServer.cpp +++ b/FluidNC/src/WebUI/WebServer.cpp @@ -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; From 3a1810254aa84dc1a513e91e20c0204c9ddcc423 Mon Sep 17 00:00:00 2001 From: bdring Date: Sat, 4 Nov 2023 07:07:57 -0500 Subject: [PATCH 13/13] Cycle 0 and Macro Fixes - Homing cycle 0 was incorrectly running like -1 when run with $H - Eliminated a needless macro error when the macro was empty. --- FluidNC/src/Machine/Axis.cpp | 2 +- FluidNC/src/Machine/Macros.cpp | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/FluidNC/src/Machine/Axis.cpp b/FluidNC/src/Machine/Axis.cpp index 8c78cd6bb..1563d0aac 100644 --- a/FluidNC/src/Machine/Axis.cpp +++ b/FluidNC/src/Machine/Axis.cpp @@ -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); } diff --git a/FluidNC/src/Machine/Macros.cpp b/FluidNC/src/Machine/Macros.cpp index 2f4e529b3..7858aaad9 100644 --- a/FluidNC/src/Machine/Macros.cpp +++ b/FluidNC/src/Machine/Macros.cpp @@ -50,15 +50,15 @@ Cmd findOverride(std::string name) { return it == overrideCodes.end() ? Cmd::None : it->second; } -bool Macro::run() { - if (sys.state != State::Idle) { - log_error("Macro can only be used in idle state"); +bool Macro::run() { // return true if the macro was run + const std::string& s = _gcode; + if (_gcode == "") { return false; } - const std::string& s = _gcode; - if (_gcode == "") { - return true; + if (sys.state != State::Idle) { + log_error("Macro can only be used in idle state"); + return false; } log_info("Running macro " << _name << ": " << _gcode);