Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to use array index operator notation #123

Merged
merged 2 commits into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,8 +492,8 @@ void ConfigManager::handleAPPost() {
if (isJson) {
JsonObject obj = decodeJson(server->arg("plain"));

ssid = obj.getMember("ssid").as<String>();
password = obj.getMember("password").as<String>();
ssid = String((const char*)obj["ssid"]);
password = String((const char*)obj["password"]);
} else {
ssid = server->arg("ssid");
password = server->arg("password");
Expand Down
18 changes: 7 additions & 11 deletions src/ConfigManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ class ConfigParameter : public BaseParameter {
void update(T value) { *ptr = value; }

void fromJson(JsonObject* json) {
if (json->containsKey(name) && json->getMember(name).is<T>()) {
this->update(json->getMember(name).as<T>());
const T value = (*json)[name];
if (value) {
this->update(value);
}
}

void toJson(JsonObject* json) {
// json->set(name, *ptr);
json->getOrAddMember(name).set(*ptr);
}
void toJson(JsonObject* json) { (*json)[name] = *ptr; }

void clearData() {
DebugPrint("Clearing: ");
Expand Down Expand Up @@ -121,15 +119,13 @@ class ConfigStringParameter : public BaseParameter {
}

void fromJson(JsonObject* json) {
if (json->containsKey(name) && json->getMember(name).is<const char*>()) {
const char* value = json->getMember(name).as<const char*>();
const char* value = (*json)[name];
if (value) {
this->update(value);
}
}

void toJson(JsonObject* json) {
json->getOrAddMember(name).set((const char*)ptr);
}
void toJson(JsonObject* json) { (*json)[name] = (const char*)ptr; }

void clearData() {
DebugPrint("Clearing: ");
Expand Down
Loading