Ejemplo n.º 1
0
bool EffectHandler::save(JsonArray& array, uint8_t ID, const char * name)
{
	//Serial.printf("[EffectHandler::save] Effect = %s, ID = %s\n", _name, ID);

	int index = 0;

	for (JsonArray::iterator it = array.begin(); it != array.end(); ++it) {
		// *it contains the JsonVariant which can be casted as usuals
		//const char* value = *it;

		JsonObject& preset = *it;

		if (preset.containsKey("ID")) {

			if ( preset["ID"] == ID) {
				array.removeAt(index) ;
				DebugEffectHandlerf("[EffectHandler::save] preset %u removed\n", ID);
				break; 
			}

		}

		index++;
		// this also works:
		//value = it->as<const char*>();

	}

	JsonObject& current = array.createNestedObject();

	current["ID"] = ID;
	current["name"] = name;
	current["effect"] = _name;

	if (addJson(current)) {
		return true;
	} else {
		return false;
	}


};