void ConfigurationReader::readRooms(JsonArray& rooms, Actor* actor) {
	char *name;
	Room *room;
	for(JsonArray::iterator it=rooms.begin(); it!=rooms.end(); ++it)
	{
	    JsonObject &jsonRoom = it->asObject();
	    name = jsonRoom[JSON_ROOM_NAME];
	    room = new Room(name);
	    JsonArray& jsonPoints = jsonRoom[JSON_POINTS];
	    readPoints(jsonPoints, room);
	    actor->addRoom(room);
	}
}
Exemple #2
0
static void run_iterator_test() {
  StaticJsonDocument<JSON_ARRAY_SIZE(2)> doc;
  JsonArray array = doc.to<JsonArray>();
  array.add(12);
  array.add(34);

  TIterator it = array.begin();
  TIterator end = array.end();

  REQUIRE(end != it);
  REQUIRE(12 == it->template as<int>());
  REQUIRE(12 == static_cast<int>(*it));
  ++it;
  REQUIRE(end != it);
  REQUIRE(34 == it->template as<int>());
  REQUIRE(34 == static_cast<int>(*it));
  ++it;
  REQUIRE(end == it);
}
Exemple #3
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;
	}


};
void ConfigurationReader::readPoints(JsonArray& points, Room* room) {
	char *name;
	char *type;
	Point *point;
	int ctrPin, btnPin;
	for(JsonArray::iterator it=points.begin(); it!=points.end(); ++it)
	{
	    JsonObject &jsonPoint = it->asObject();
	    name = jsonPoint[JSON_POINT_NAME];
	    type = jsonPoint[JSON_POINT_TYPE];
	    ctrPin = jsonPoint[JSON_POINT_CTRPIN];
	    btnPin = jsonPoint[JSON_POINT_BTNPIN];

	    if (strcmp(type, JSON_POINT_TYPE_LIGHT) == 0) {
	    	point = new LightPoint(ctrPin, btnPin, name);
	    	room->addPoint(point);
	    	point->printDiagnosticInfo();
	    }
	}
}