1
0
mirror of https://github.com/bdring/Grbl_Esp32.git synced 2025-09-01 02:21:46 +02:00

Merge branch 'YamlSettings' of https://github.com/bdring/Grbl_Esp32 into YamlSettings

This commit is contained in:
bdring
2021-06-11 11:54:01 -05:00
6 changed files with 57 additions and 27 deletions

View File

@@ -115,9 +115,7 @@ namespace Configuration {
void JsonGenerator::item(const char* name, IPAddress& value) {
enter(name);
#ifdef LATER
// Encode IP address
#endif
_encoder.begin_webui(name, _currentPath, "A", value.toString().c_str());
_encoder.end_object();
leave();
}

View File

@@ -99,6 +99,13 @@ namespace WebUI {
grbl_send(_client, data);
}
void ESPResponseStream::print(const char data) {
char text[2];
text[0] = data;
text[1] = '\0';
print(text);
}
void ESPResponseStream::flush() {
#if defined(ENABLE_HTTP) && defined(ENABLE_WIFI)
if (_webserver) {

View File

@@ -33,6 +33,7 @@ namespace WebUI {
ESPResponseStream(uint8_t client, bool byid = true);
ESPResponseStream();
void print(const char data);
void print(const char* data);
void println(const char* data);
void flush();

View File

@@ -5,12 +5,24 @@
#include "JSONEncoder.h"
namespace WebUI {
// Constructor that supplies a default falue for "pretty"
JSONencoder::JSONencoder() : JSONencoder(false) {}
// Constructor. If _pretty is true, newlines are
// inserted into the JSON string for easy reading.
JSONencoder::JSONencoder(bool pretty, ESPResponseStream* s) : pretty(pretty), level(0), str(""), stream(s) { count[level] = 0; }
// Constructor. If _pretty is true, newlines are
// inserted into the JSON string for easy reading.
JSONencoder::JSONencoder(bool pretty) : pretty(pretty), level(0), str("") { count[level] = 0; }
JSONencoder::JSONencoder(bool pretty) : JSONencoder(pretty, nullptr) {}
// Constructor that supplies a default falue for "pretty"
JSONencoder::JSONencoder() : JSONencoder(false) {}
void JSONencoder::add(char c) {
if (stream) {
stream->print(c);
} else {
str += c;
}
}
// Private function to add commas between
// elements as needed, omitting the comma
@@ -38,7 +50,11 @@ namespace WebUI {
// Private function to add a name enclosed with quotes.
void JSONencoder::quoted(const char* s) {
add('"');
str.concat(s);
if (stream) {
stream->print(s);
} else {
str.concat(s);
}
add('"');
}
@@ -109,9 +125,7 @@ namespace WebUI {
// Ends an object with }.
void JSONencoder::end_object() {
dec_level();
if (count[level + 1] > 1) {
line();
}
line();
add('}');
}

View File

@@ -1,5 +1,7 @@
#pragma once
#include "ESPResponse.h"
// Class for creating JSON-encoded strings.
namespace WebUI {
@@ -7,17 +9,18 @@ namespace WebUI {
private:
static const int MAX_JSON_LEVEL = 16;
bool pretty;
int level;
String str;
int count[MAX_JSON_LEVEL];
void add(char c) { str += c; }
void comma_line();
void comma();
void quoted(const char* s);
void inc_level();
void dec_level();
void line();
bool pretty;
int level;
String str;
int count[MAX_JSON_LEVEL];
void add(char c);
void comma_line();
void comma();
void quoted(const char* s);
void inc_level();
void dec_level();
void line();
ESPResponseStream* stream;
public:
// If you don't set _pretty it defaults to false
@@ -26,6 +29,9 @@ namespace WebUI {
// Constructor; set _pretty true for pretty printing
JSONencoder(bool pretty);
// Constructor; set _pretty true for pretty printing
JSONencoder(bool pretty, ESPResponseStream* s);
// begin() starts the encoding process.
void begin();

View File

@@ -564,7 +564,7 @@ namespace WebUI {
#ifdef ENABLE_WIFI
static Error listAPs(char* parameter, AuthenticationLevel auth_level) { // ESP410
JSONencoder j(espresponse->client() != CLIENT_WEBUI);
JSONencoder j(espresponse->client() != CLIENT_WEBUI, espresponse);
j.begin();
j.begin_array("AP_LIST");
// An initial async scanNetworks was issued at startup, so there
@@ -595,7 +595,7 @@ namespace WebUI {
break;
}
j.end_array();
webPrint(j.end());
j.end();
if (espresponse->client() != CLIENT_WEBUI) {
espresponse->println("");
}
@@ -620,14 +620,18 @@ namespace WebUI {
}
static Error listSettings(char* parameter, AuthenticationLevel auth_level) { // ESP400
JSONencoder j(espresponse->client() != CLIENT_WEBUI);
JSONencoder j(espresponse->client() != CLIENT_WEBUI, espresponse);
j.begin();
j.begin_array("EEPROM");
Configuration::JsonGenerator gen(j);
config->group(gen);
j.end_array();
webPrint(j.end());
j.end();
if (espresponse->client() != CLIENT_WEBUI) {
espresponse->println("");
}
return Error::Ok;
}
@@ -829,7 +833,7 @@ namespace WebUI {
}
static Error listLocalFilesJSON(char* parameter, AuthenticationLevel auth_level) { // No ESP command
JSONencoder j(espresponse->client() != CLIENT_WEBUI);
JSONencoder j(espresponse->client() != CLIENT_WEBUI, espresponse);
j.begin();
j.begin_array("files");
listDirJSON(SPIFFS, "/", 4, &j);
@@ -837,7 +841,7 @@ namespace WebUI {
j.member("total", SPIFFS.totalBytes());
j.member("used", SPIFFS.usedBytes());
j.member("occupation", String(100 * SPIFFS.usedBytes() / SPIFFS.totalBytes()));
webPrint(j.end());
j.end();
if (espresponse->client() != CLIENT_WEBUI) {
webPrintln("");
}