From 620de14b107aba88d667ce345deae257ec206a6a Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Wed, 2 Jun 2021 13:29:12 -1000 Subject: [PATCH] Dead code --- Grbl_Esp32/src/Settings.cpp | 147 ------------------------- Grbl_Esp32/src/Settings.h | 62 ----------- Grbl_Esp32/src/SettingsDefinitions.cpp | 5 - Grbl_Esp32/src/WebUI/BTConfig.cpp | 5 +- Grbl_Esp32/src/WebUI/WebSettings.cpp | 114 ++++--------------- Grbl_Esp32/src/WebUI/WebSettings.h | 24 ---- 6 files changed, 28 insertions(+), 329 deletions(-) diff --git a/Grbl_Esp32/src/Settings.cpp b/Grbl_Esp32/src/Settings.cpp index a24ca715..ca5cdd79 100644 --- a/Grbl_Esp32/src/Settings.cpp +++ b/Grbl_Esp32/src/Settings.cpp @@ -375,155 +375,8 @@ void EnumSetting::addWebui(WebUI::JSONencoder* j) { j->end_object(); } -FlagSetting::FlagSetting(const char* description, - type_t type, - permissions_t permissions, - const char* grblName, - const char* name, - bool defVal, - bool (*checker)(char*) = NULL) : - Setting(description, type, permissions, grblName, name, checker), - _defaultValue(defVal) {} - -void FlagSetting::load() { - esp_err_t err = nvs_get_i8(_handle, _keyName, &_storedValue); - if (err) { - _storedValue = -1; // Neither well-formed false (0) nor true (1) - _currentValue = _defaultValue; - } else { - _currentValue = !!_storedValue; - } -} -void FlagSetting::setDefault() { - _currentValue = _defaultValue; - if (_storedValue != _currentValue) { - nvs_erase_key(_handle, _keyName); - } -} - -Error FlagSetting::setStringValue(char* s) { - s = trim(s); - Error err = check(s); - if (err != Error::Ok) { - return err; - } - _currentValue = (strcasecmp(s, "on") == 0) || (strcasecmp(s, "true") == 0) || (strcasecmp(s, "enabled") == 0) || - (strcasecmp(s, "yes") == 0) || (strcasecmp(s, "1") == 0); - // _storedValue is -1, 0, or 1 - // _currentValue is 0 or 1 - if (_storedValue != (int8_t)_currentValue) { - if (_currentValue == _defaultValue) { - nvs_erase_key(_handle, _keyName); - } else { - if (nvs_set_i8(_handle, _keyName, _currentValue)) { - return Error::NvsSetFailed; - } - _storedValue = _currentValue; - } - } - check(NULL); - return Error::Ok; -} -const char* FlagSetting::getDefaultString() { - return _defaultValue ? "On" : "Off"; -} -const char* FlagSetting::getStringValue() { - return get() ? "On" : "Off"; -} -const char* FlagSetting::getCompatibleValue() { - return get() ? "1" : "0"; -} - #include -IPaddrSetting::IPaddrSetting(const char* description, - type_t type, - permissions_t permissions, - const char* grblName, - const char* name, - uint32_t defVal, - bool (*checker)(char*) = NULL) : - Setting(description, type, permissions, grblName, name, checker) // There are no GRBL IP settings. - , - _defaultValue(defVal), _currentValue(defVal) {} - -IPaddrSetting::IPaddrSetting(const char* description, - type_t type, - permissions_t permissions, - const char* grblName, - const char* name, - const char* defVal, - bool (*checker)(char*) = NULL) : - Setting(description, type, permissions, grblName, name, checker) { - IPAddress ipaddr; - if (ipaddr.fromString(defVal)) { - _defaultValue = ipaddr; - _currentValue = _defaultValue; - } else { - throw std::runtime_error("Bad IPaddr default"); - } -} - -void IPaddrSetting::load() { - esp_err_t err = nvs_get_i32(_handle, _keyName, (int32_t*)&_storedValue); - if (err) { - _storedValue = 0x000000ff; // Unreasonable value for any IP thing - _currentValue = _defaultValue; - } else { - _currentValue = _storedValue; - } -} - -void IPaddrSetting::setDefault() { - _currentValue = _defaultValue; - if (_storedValue != _currentValue) { - nvs_erase_key(_handle, _keyName); - } -} - -Error IPaddrSetting::setStringValue(char* s) { - s = trim(s); - Error err = check(s); - if (err != Error::Ok) { - return err; - } - IPAddress ipaddr; - if (!ipaddr.fromString(s)) { - return Error::InvalidValue; - } - _currentValue = ipaddr; - if (_storedValue != _currentValue) { - if (_currentValue == _defaultValue) { - nvs_erase_key(_handle, _keyName); - } else { - if (nvs_set_i32(_handle, _keyName, (int32_t)_currentValue)) { - return Error::NvsSetFailed; - } - _storedValue = _currentValue; - } - } - check(NULL); - return Error::Ok; -} - -const char* IPaddrSetting::getDefaultString() { - static String s; - s = IPAddress(_defaultValue).toString(); - return s.c_str(); -} -const char* IPaddrSetting::getStringValue() { - static String s; - s = IPAddress(get()).toString(); - return s.c_str(); -} - -void IPaddrSetting::addWebui(WebUI::JSONencoder* j) { - if (getDescription()) { - j->begin_webui(getName(), getDescription(), "A", getStringValue()); - j->end_object(); - } -} - Error GrblCommand::action(char* value, WebUI::AuthenticationLevel auth_level, WebUI::ESPResponseStream* out) { if (_cmdChecker && _cmdChecker()) { return Error::IdleError; diff --git a/Grbl_Esp32/src/Settings.h b/Grbl_Esp32/src/Settings.h index ddd51226..b7593792 100644 --- a/Grbl_Esp32/src/Settings.h +++ b/Grbl_Esp32/src/Settings.h @@ -300,68 +300,6 @@ public: int8_t get() { return _currentValue; } }; -class FlagSetting : public Setting { -private: - bool _defaultValue; - int8_t _storedValue; - bool _currentValue; - -public: - FlagSetting(const char* description, - type_t type, - permissions_t permissions, - const char* grblName, - const char* name, - bool defVal, - bool (*checker)(char*)); - FlagSetting(type_t type, permissions_t permissions, const char* grblName, const char* name, bool defVal, bool (*checker)(char*) = NULL) : - FlagSetting(NULL, type, permissions, grblName, name, defVal, checker) {} - - void load(); - void setDefault(); - // There are no Flag settings in WebUI - // The booleans are expressed as Enums - void addWebui(WebUI::JSONencoder*) {} - Error setStringValue(char* value); - const char* getCompatibleValue(); - const char* getStringValue(); - const char* getDefaultString(); - - bool get() { return _currentValue; } -}; - -class IPaddrSetting : public Setting { -private: - uint32_t _defaultValue; - uint32_t _currentValue; - uint32_t _storedValue; - -public: - IPaddrSetting(const char* description, - type_t type, - permissions_t permissions, - const char* grblName, - const char* name, - uint32_t defVal, - bool (*checker)(char*)); - IPaddrSetting(const char* description, - type_t type, - permissions_t permissions, - const char* grblName, - const char* name, - const char* defVal, - bool (*checker)(char*)); - - void load(); - void setDefault(); - void addWebui(WebUI::JSONencoder*); - Error setStringValue(char* value); - const char* getStringValue(); - const char* getDefaultString(); - - uint32_t get() { return _currentValue; } -}; - extern bool idleOrJog(); extern bool idleOrAlarm(); extern bool anyState(); diff --git a/Grbl_Esp32/src/SettingsDefinitions.cpp b/Grbl_Esp32/src/SettingsDefinitions.cpp index 27bbe221..18fa7107 100644 --- a/Grbl_Esp32/src/SettingsDefinitions.cpp +++ b/Grbl_Esp32/src/SettingsDefinitions.cpp @@ -64,11 +64,6 @@ void make_settings() { // GRBL Numbered Settings build_info = new StringSetting(EXTENDED, WG, NULL, "Firmware/Build", ""); - // TODO: These affect the sender communication protocol so they - // need to be be available as $ commands - // verbose_errors = new FlagSetting(EXTENDED, WG, NULL, "Errors/Verbose", DEFAULT_VERBOSE_ERRORS); - // report_inches = new FlagSetting(GRBL, WG, "13", "Report/Inches", DEFAULT_REPORT_INCHES); - status_mask = new IntSetting(GRBL, WG, "10", "Report/Status", DEFAULT_STATUS_REPORT_MASK, 0, 3); user_macro3 = new StringSetting(EXTENDED, WG, NULL, "User/Macro3", DEFAULT_USER_MACRO3); diff --git a/Grbl_Esp32/src/WebUI/BTConfig.cpp b/Grbl_Esp32/src/WebUI/BTConfig.cpp index e6ca8945..b4dfcc79 100644 --- a/Grbl_Esp32/src/WebUI/BTConfig.cpp +++ b/Grbl_Esp32/src/WebUI/BTConfig.cpp @@ -136,7 +136,10 @@ namespace WebUI { * Reset ESP */ void BTConfig::reset_settings() { - wifi_radio_mode->setDefault(); +#ifdef LATER + // Implement this in YAML land + // was wifi_radio_mode->setDefault(); +#endif grbl_send(CLIENT_ALL, "[MSG:BT reset done]\r\n"); } diff --git a/Grbl_Esp32/src/WebUI/WebSettings.cpp b/Grbl_Esp32/src/WebUI/WebSettings.cpp index 1c643366..2114649b 100644 --- a/Grbl_Esp32/src/WebUI/WebSettings.cpp +++ b/Grbl_Esp32/src/WebUI/WebSettings.cpp @@ -40,51 +40,8 @@ namespace WebUI { #ifdef ENABLE_WIFI - StringSetting* wifi_sta_ssid; StringSetting* wifi_sta_password; - - EnumSetting* wifi_sta_mode; - IPaddrSetting* wifi_sta_ip; - IPaddrSetting* wifi_sta_gateway; - IPaddrSetting* wifi_sta_netmask; - - StringSetting* wifi_ap_ssid; StringSetting* wifi_ap_password; - - IPaddrSetting* wifi_ap_ip; - - IntSetting* wifi_ap_channel; - - StringSetting* wifi_hostname; - EnumSetting* http_enable; - IntSetting* http_port; - EnumSetting* telnet_enable; - IntSetting* telnet_port; - - typedef std::map enum_opt_t; - - enum_opt_t staModeOptions = { - { "DHCP", DHCP_MODE }, - { "Static", STATIC_MODE }, - }; -#endif - -#ifdef WIFI_OR_BLUETOOTH - EnumSetting* wifi_radio_mode; - enum_opt_t radioOptions = { - { "None", ESP_RADIO_OFF }, - { "STA", ESP_WIFI_STA }, - { "AP", ESP_WIFI_AP }, - { "BT", ESP_BT }, - }; - enum_opt_t radioEnabledOptions = { - { "NONE", ESP_RADIO_OFF }, -# ifdef ENABLE_WIFI - { "STA", ESP_WIFI_STA }, - { "AP", ESP_WIFI_AP }, -# endif - { "BT", ESP_BT }, - }; #endif #ifdef ENABLE_NOTIFICATIONS @@ -202,6 +159,10 @@ namespace WebUI { webPrint(s2); webPrint(s3); } + static void webPrint(const char* s, IPAddress ip) { + webPrint(s); + webPrint(ip.toString().c_str()); + } static void webPrintln(const char* s) { webPrint(s); webPrint("\r\n"); @@ -946,17 +907,17 @@ namespace WebUI { return Error::Ok; } - //On + //On #ifdef WIFI_OR_BLUETOOTH if (hasWiFi()) { -#if !defined(ENABLE_WIFI) +# if !defined(ENABLE_WIFI) webPrintln("WiFi is not enabled!"); return Error::WifiFailBegin; -#else +# else wifi_config.begin(); return Error::Ok; -#endif +# endif } else if (hasBluetooth()) { if (hasBluetooth()) { webPrintln("Bluetooth is not enabled!"); @@ -981,9 +942,17 @@ namespace WebUI { static Error showSetStaParams(char* parameter, AuthenticationLevel auth_level) { // ESP103 if (*parameter == '\0') { - webPrint("IP:", wifi_sta_ip->getStringValue()); - webPrint(" GW:", wifi_sta_gateway->getStringValue()); - webPrintln(" MSK:", wifi_sta_netmask->getStringValue()); + auto sta = config->_comms->_staConfig; + if (sta) { + webPrint("IP:", IPAddress(sta->_ipAddress)); + webPrint(" GW:", IPAddress(sta->_gateway)); + webPrintln(" MSK:", IPAddress(sta->_netmask)); + } else { + const char* none = ""; + webPrint("IP:", none); + webPrint(" GW:", none); + webPrintln(" MSK:", none); + } return Error::Ok; } if (!split_params(parameter)) { @@ -993,6 +962,8 @@ namespace WebUI { char* netmask = get_param("MSK", false); char* ip = get_param("IP", false); +# ifdef LATER + // Needs to be converted to YAML land Error err = wifi_sta_ip->setStringValue(ip); if (err == Error::Ok) { err = wifi_sta_netmask->setStringValue(netmask); @@ -1000,6 +971,9 @@ namespace WebUI { if (err == Error::Ok) { err = wifi_sta_gateway->setStringValue(gateway); } +# else + Error err = Error::SettingDisabled; +# endif return err; } #endif @@ -1143,30 +1117,6 @@ namespace WebUI { &COMMANDS::isLocalPasswordValid); #endif -#ifdef WIFI_OR_BLUETOOTH - // user+ to get, admin to set - wifi_radio_mode = new EnumSetting("Radio mode", WEBSET, WA, "ESP110", "Radio/Mode", DEFAULT_RADIO_MODE, &radioEnabledOptions, NULL); -#endif - -#ifdef ENABLE_WIFI - telnet_port = new IntSetting( - "Telnet Port", WEBSET, WA, "ESP131", "Telnet/Port", DEFAULT_TELNETSERVER_PORT, MIN_TELNET_PORT, MAX_TELNET_PORT, NULL); - telnet_enable = new EnumSetting("Telnet Enable", WEBSET, WA, "ESP130", "Telnet/Enable", DEFAULT_TELNET_STATE, &onoffOptions, NULL); - http_port = - new IntSetting("HTTP Port", WEBSET, WA, "ESP121", "Http/Port", DEFAULT_WEBSERVER_PORT, MIN_HTTP_PORT, MAX_HTTP_PORT, NULL); - http_enable = new EnumSetting("HTTP Enable", WEBSET, WA, "ESP120", "Http/Enable", DEFAULT_HTTP_STATE, &onoffOptions, NULL); - wifi_hostname = new StringSetting("Hostname", - WEBSET, - WA, - "ESP112", - "System/Hostname", - DEFAULT_HOSTNAME, - MIN_HOSTNAME_LENGTH, - MAX_HOSTNAME_LENGTH, - (bool (*)(char*))WiFiConfig::isHostnameValid); - wifi_ap_channel = - new IntSetting("AP Channel", WEBSET, WA, "ESP108", "AP/Channel", DEFAULT_AP_CHANNEL, MIN_CHANNEL, MAX_CHANNEL, NULL); - wifi_ap_ip = new IPaddrSetting("AP Static IP", WEBSET, WA, "ESP107", "AP/IP", DEFAULT_AP_IP, NULL); // no get, admin to set wifi_ap_password = new StringSetting("AP Password", WEBSET, @@ -1177,12 +1127,6 @@ namespace WebUI { MIN_PASSWORD_LENGTH, 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, (bool (*)(char*))WiFiConfig::isSSIDValid); - 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); - wifi_sta_mode = new EnumSetting("Station IP Mode", WEBSET, WA, "ESP102", "Sta/IPMode", DEFAULT_STA_IP_MODE, &staModeOptions, NULL); // no get, admin to set wifi_sta_password = new StringSetting("Station Password", WEBSET, @@ -1193,15 +1137,5 @@ namespace WebUI { MIN_PASSWORD_LENGTH, MAX_PASSWORD_LENGTH, (bool (*)(char*))WiFiConfig::isPasswordValid); - wifi_sta_ssid = new StringSetting("Station SSID", - WEBSET, - WA, - "ESP100", - "Sta/SSID", - DEFAULT_STA_SSID, - MIN_SSID_LENGTH, - MAX_SSID_LENGTH, - (bool (*)(char*))WiFiConfig::isSSIDValid); -#endif } } diff --git a/Grbl_Esp32/src/WebUI/WebSettings.h b/Grbl_Esp32/src/WebUI/WebSettings.h index 74896d74..719f42c3 100644 --- a/Grbl_Esp32/src/WebUI/WebSettings.h +++ b/Grbl_Esp32/src/WebUI/WebSettings.h @@ -21,33 +21,9 @@ */ namespace WebUI { - extern StringSetting* wifi_sta_ssid; extern StringSetting* wifi_sta_password; - -#ifdef ENABLE_WIFI - extern EnumSetting* wifi_sta_mode; - extern IPaddrSetting* wifi_sta_ip; - extern IPaddrSetting* wifi_sta_gateway; - extern IPaddrSetting* wifi_sta_netmask; - - extern StringSetting* wifi_ap_ssid; extern StringSetting* wifi_ap_password; - extern IPaddrSetting* wifi_ap_ip; - - extern IntSetting* wifi_ap_channel; - - extern StringSetting* wifi_hostname; - extern EnumSetting* http_enable; - extern IntSetting* http_port; - extern EnumSetting* telnet_enable; - extern IntSetting* telnet_port; -#endif - -#ifdef WIFI_OR_BLUETOOTH - extern EnumSetting* wifi_radio_mode; -#endif - #ifdef ENABLE_AUTHENTICATION extern StringSetting* user_password; extern StringSetting* admin_password;