From 44d0c3eca0a7b5d060d9e7d1443778e36dc7b4c1 Mon Sep 17 00:00:00 2001 From: Mitch Bradley Date: Sun, 1 Aug 2021 10:23:37 -1000 Subject: [PATCH] Fixed WebUI settings problems - floats and sets. --- Grbl_Esp32/src/Configuration/JsonGenerator.cpp | 7 +++++-- Grbl_Esp32/src/Configuration/RuntimeSetting.cpp | 6 ++++-- Grbl_Esp32/src/WebUI/JSONEncoder.cpp | 16 +++++++++------- Grbl_Esp32/src/WebUI/JSONEncoder.h | 6 +++--- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/Grbl_Esp32/src/Configuration/JsonGenerator.cpp b/Grbl_Esp32/src/Configuration/JsonGenerator.cpp index fbea1d01..5fc4d22b 100644 --- a/Grbl_Esp32/src/Configuration/JsonGenerator.cpp +++ b/Grbl_Esp32/src/Configuration/JsonGenerator.cpp @@ -89,8 +89,11 @@ namespace Configuration { } void JsonGenerator::item(const char* name, float& value, float minValue, float maxValue) { - int n = int(value * 1000); - item(name, n, int(minValue * 1000), int(maxValue * 1000)); + enter(name); + // WebUI does not explicitly recognize the R type, but nevertheless handles it correctly. + _encoder.begin_webui(name, _currentPath, "R", String(value, 3).c_str()); + _encoder.end_object(); + leave(); } void JsonGenerator::item(const char* name, std::vector& value) {} diff --git a/Grbl_Esp32/src/Configuration/RuntimeSetting.cpp b/Grbl_Esp32/src/Configuration/RuntimeSetting.cpp index ab3bfdc9..cca93f3d 100644 --- a/Grbl_Esp32/src/Configuration/RuntimeSetting.cpp +++ b/Grbl_Esp32/src/Configuration/RuntimeSetting.cpp @@ -24,8 +24,10 @@ #include namespace Configuration { - RuntimeSetting::RuntimeSetting(const char* key, const char* value, WebUI::ESPResponseStream* out) : - setting_(key), start_(key), newValue_(value), out_(out) { + RuntimeSetting::RuntimeSetting(const char* key, const char* value, WebUI::ESPResponseStream* out) : newValue_(value), out_(out) { + // Remove leading '/' if it is present + setting_ = (*key == '/') ? key + 1 : key; + start_ = setting_; // Read fence for config. Shouldn't be necessary, but better safe than sorry. std::atomic_thread_fence(std::memory_order::memory_order_seq_cst); } diff --git a/Grbl_Esp32/src/WebUI/JSONEncoder.cpp b/Grbl_Esp32/src/WebUI/JSONEncoder.cpp index bfa90312..27211b9a 100644 --- a/Grbl_Esp32/src/WebUI/JSONEncoder.cpp +++ b/Grbl_Esp32/src/WebUI/JSONEncoder.cpp @@ -144,25 +144,27 @@ namespace WebUI { // Creates an Esp32_WebUI configuration item specification from // a value passed in as a C-style string. - void JSONencoder::begin_webui(const char* p, const char* help, const char* type, const char* val) { + void JSONencoder::begin_webui(const char* brief, const char* full, const char* type, const char* val) { begin_object(); member("F", "network"); - member("P", p); - member("H", help); + // We must pass the full path as the P parameter because that is + // what WebUI sends back to us when setting a new value. + member("P", full); + member("H", full); member("T", type); member("V", val); } // Creates an Esp32_WebUI configuration item specification from // an integer value. - void JSONencoder::begin_webui(const char* p, const char* help, const char* type, int val) { - begin_webui(p, help, type, String(val).c_str()); + void JSONencoder::begin_webui(const char* brief, const char* full, const char* type, int val) { + begin_webui(brief, full, type, String(val).c_str()); } // Creates an Esp32_WebUI configuration item specification from // a C-style string value, with additional min and max arguments. - void JSONencoder::begin_webui(const char* p, const char* help, const char* type, const char* val, int min, int max) { - begin_webui(p, help, type, val); + void JSONencoder::begin_webui(const char* brief, const char* full, const char* type, const char* val, int min, int max) { + begin_webui(brief, full, type, val); member("S", max); member("M", min); } diff --git a/Grbl_Esp32/src/WebUI/JSONEncoder.h b/Grbl_Esp32/src/WebUI/JSONEncoder.h index 8b34bd86..794394a7 100644 --- a/Grbl_Esp32/src/WebUI/JSONEncoder.h +++ b/Grbl_Esp32/src/WebUI/JSONEncoder.h @@ -83,8 +83,8 @@ namespace WebUI { // S => 0 .. 255 // A => 7 .. 15 (0.0.0.0 .. 255.255.255.255) // I => 0 .. 2^31-1 - void begin_webui(const char* p, const char* help, const char* type, const char* val); - void begin_webui(const char* p, const char* help, const char* type, const int val); - void begin_webui(const char* p, const char* help, const char* type, const char* val, int min, int max); + void begin_webui(const char* brief, const char* full, const char* type, const char* val); + void begin_webui(const char* brief, const char* full, const char* type, const int val); + void begin_webui(const char* brief, const char* full, const char* type, const char* val, int min, int max); }; }