void setup()
{
  // Initialize pin modes: set pin 0, 1 and 2 to outputs.
  DDRB = 0b00000111;
  PRR = _BV(PRADC); // Turn off the ADC
  checkAndInitialize();
  if(PINB & SWITCH){
    // Enter the rather complex color observation mode, write the new ones out to the EPROM.
    observe_color();
    writeColor(red, (uint8_t*) RED_BASE);
    writeColor(green, (uint8_t*) GREEN_BASE);
    writeColor(blue, (uint8_t*) BLUE_BASE);
  }else{// Read the old values from the eeprom, initializing it if needed.
    red   = readColor((uint8_t*) RED_BASE);
    green = readColor((uint8_t*) GREEN_BASE);
    blue  = readColor((uint8_t*) BLUE_BASE);
  }
  /* Setup timer0 to fire an interrupt every 75 cycles, the enter an infinite loop.
     All the work is done on the interrupts - once we've figured out what colors to use, the
     device simply has to PWM them until it's shutoff.
     Based on Atmel's "AVR136: Low-jitter Multi-channel Software PWM" */
  cli(); // This is probably not needed. Disable interrupts.
  /* Interesting design: before altering any other bits in CLKPR, CLKPCE must be set.
     The processor then resets CLKPCE within four cycles. After we've enabled updating
     CLKPR, set the clock speed to its maximum. */
  CLKPR = _BV(CLKPCE);
  CLKPR = 0;
  TCCR0B = _BV(CS00);  // No prescaler
  TCCR0A = _BV(WGM01);// Clear the timer on compare
  OCR0A = 75;
  TIMSK |= _BV(OCIE0A);// interrupt on compare with register A, which just happens to be 75. 
  sei(); // Turn everything on, and loop!
  while(1);
}
Exemplo n.º 2
0
Material ModelFactory::readMaterial()
{
    Material material;
    bool eof;
    std::string current = readerMtl->readWord(eof);
    while (!eof)
    {
        if (strcmp("Ns", current.data()) == 0)
            material.setNs(readerMtl->readFloat(eof));
        else if (strcmp("Ni", current.data()) == 0)
            material.setNi(readerMtl->readFloat(eof));
        else if (strcmp("Ka", current.data()) == 0)
            material.setKa(readColor());
        else if (strcmp("Kd", current.data()) == 0)
            material.setKd(readColor());
        else if (strcmp("Ks", current.data()) == 0)
            material.setKs(readColor());
        else if (strcmp("Ke", current.data()) == 0)
            material.setKe(readColor());
        else if (strcmp("d", current.data()) == 0)
            material.setD(readerMtl->readFloat(eof));
        else if (strcmp("illum", current.data()) == 0)
            material.setIllum(readerMtl->readInt(eof));
        current = readerMtl->readWord(eof);
    }
    return material;
}
Exemplo n.º 3
0
void JsonFileReader::readShape(Shape *s, const QJsonObject &obj)
{
    s->setPosition(readPoint(obj["Position"].toObject()));
    s->setFillColor(readColor(obj["FillColor"].toObject()));
    s->setLineColor(readColor(obj["LineColor"].toObject()));
    s->setLineThickness(obj["LineThickness"].toInt());
}
int ScriptParser::selectcolorCommand()
{
    const char *buf = script_h.readStr();
    readColor( &sentence_font.on_color, buf );

    buf = script_h.readStr();
    readColor( &sentence_font.off_color, buf );
    
    return RET_CONTINUE;
}
int ScriptParser::menuselectcolorCommand()
{
    const char *buf = script_h.readStr();
    readColor( &menu_font.on_color, buf );

    buf = script_h.readStr();
    readColor( &menu_font.off_color, buf );
    
    buf = script_h.readStr();
    readColor( &menu_font.nofile_color, buf );
    
    return RET_CONTINUE;
}
Exemplo n.º 6
0
void setup() {
  Serial.begin(9600);
  calibrateAll();
  leftServo.attach(9, 1300, 1700);
  rightServo.attach(10, 1300, 1700);
  while(!finishLine){
    driveStraight(10, 50);
    readColor();
  }
  
  turnLeftInDegrees(90);
  driveInInches(36);
  
  for(int i = 0; i < 12; i++){
    turnRightInDegrees(90);
    driveInInches(3);
    turnRightInDegrees(90);
    driveInInches(72);
    turnLeftInDegrees(90);
    driveInInches(3);
    turnLeftInDegrees(90);
    driveInInches(72);
  }
  
  
}
Exemplo n.º 7
0
void loadPointLight(FILE *inFP, entity_t *ent, char *token){
    char *attributes[] = {"color","brightness","center",NULL};
    int ndx;
    
    assert(ent->magic == ENTITY_T);
    pointlight_t *pointlight = ent->entDerived;
    assert(pointlight->magic == POINTLIGHT_T);
    
    ndx = getindex(token,attributes);
    
    switch(ndx) {
        case 0:
            pointlight->color = readColor(inFP, "Could not read light color");
            break;
        case 1:
            pointlight->brightness = readDouble(inFP, "Could not read light brightness");
            break;
        case 2:
            pointlight->center = readTuple(inFP, "Could not read light center");
            break;
        default:
            loadEntity(inFP, ent, token);
            break;
        }
}
Exemplo n.º 8
0
void ToolFill::floodFill(std::vector<glm::vec2>& points, sf::Vector2u size, glm::vec2 pos, glm::vec4 col)
{
    if (pos.y < 0 || pos.y >= size.y || pos.x < 0 || pos.x >= size.x)
    	return;

    std::stack<glm::vec2> stack;
    std::unordered_set<glm::vec2> found;

    stack.push(pos);
    while (!stack.empty())
    {
    	glm::vec2 p = stack.top();
    	stack.pop();
    	int x = p.x;
    	int y = p.y;
    	if (y < 0 || y >= size.y || x < 0 || x >= size.x || found.find(p) != found.end())
    		continue;
    	glm::vec4 val = readColor(size, x, y);
    	if (val == col)
    	{
    		found.emplace(p);
    		stack.push({x + 1, y});
    		stack.push({x - 1, y});
    		stack.push({x, y + 1});
    		stack.push({x, y - 1});
    	}
    }

    for (glm::vec2 p : found)
    {
        points.push_back(p);
    }
}
Exemplo n.º 9
0
void WaveEdit::readConfiguration(MusECore::Xml& xml)
      {
      for (;;) {
            MusECore::Xml::Token token = xml.parse();
            const QString& tag = xml.s1();
            switch (token) {
                  case MusECore::Xml::TagStart:
                        if (tag == "bgcolor")
                              MusEGlobal::config.waveEditBackgroundColor = readColor(xml);
                        else if (tag == "raster")
                              _rasterInit = xml.parseInt();
                        else if (tag == "colormode")
                              colorModeInit = xml.parseInt();
                        else if (tag == "topwin")
                              TopWin::readConfiguration(WAVE, xml);
                        else
                              xml.unknown("WaveEdit");
                        break;
                  case MusECore::Xml::TagEnd:
                        if (tag == "waveedit")
                              return;
                  default:
                        break;
                  case MusECore::Xml::Error:
                  case MusECore::Xml::End:
                        return;
                  }
            }
      }
Exemplo n.º 10
0
int ScriptParser::lookbackcolorCommand()
{
    const char *buf = script_h.readStr();
    readColor( &lookback_color, buf );

    return RET_CONTINUE;
}
Exemplo n.º 11
0
bool Model::LoadModel(char* obj_file, char* color_file)
{
	model = glmReadOBJ(obj_file);
	if(!model)
		return false;

	//normal
	if( ! model->normals )
	{
		glmFacetNormals(model);
		glmVertexNormals(model, 90.0);

		assert(model->numnormals == model->numvertices);
	}

	//bbox
	bbox = new BBox();
	float dim[3];
	float center[3];
	glmDimensions(model, dim);
	glmCenter(model, center);
	for(int i = 0; i < 3; i++)
	{
		bbox->min[i] = center[i] - dim[i] / 2.0;
		bbox->max[i] = center[i] + dim[i] / 2.0;
	}

	//color
	return readColor(color_file);
}
Exemplo n.º 12
0
static inline bool readVizAttribute(
	GraphAttributes &GA,
	edge e,
	const pugi::xml_node tag)
{
	const long attrs = GA.attributes();

	if(string(tag.name()) == "viz:color") {
		if(attrs & GraphAttributes::edgeStyle) {
			return readColor(GA.strokeColor(e), tag);
		}
	} else if(string(tag.name()) == "viz:thickness") {
		auto thickAttr = tag.attribute("value");
		if(!thickAttr) {
			GraphIO::logger.lout() << "Missing \"value\" on thickness tag." << std::endl;
			return false;
		}

		if(attrs & GraphAttributes::edgeDoubleWeight) {
			GA.doubleWeight(e) = thickAttr.as_double();
		} else if(attrs & GraphAttributes::edgeIntWeight) {
			GA.intWeight(e) = thickAttr.as_int();
		}
	} else if(string(tag.name()) == "viz:shape") {
		// Values: solid, dotted, dashed, double. Not supported in OGDF.
	} else {
		GraphIO::logger.lout() << "Incorrect tag \"" << tag.name() << "\"." << std::endl;
		return false;
	}

	return true;
}
Exemplo n.º 13
0
void Reader::readShape(){
	shape = new Shape;
	readVertices();
	readColor();
	readFaces();
	model->addShape(shape);
}
Material SceneSettingReader::readMaterial()
{
    settings_.beginGroup("material");
    settings_.beginGroup("diffuse");
    const Color diffuse = readColor();
    settings_.endGroup();
    settings_.beginGroup("specular");
    const Color specular = readColor();
    settings_.endGroup();
    settings_.beginGroup("ambient");
    const Color ambient = readColor();
    settings_.endGroup();
    const double shininess = settings_.value("shininess").toDouble();
    settings_.endGroup();
    return Material(specular, diffuse, ambient, shininess);
}
Exemplo n.º 15
0
static inline bool readVizAttribute(
	GraphAttributes &GA,
	node v,
	const pugi::xml_node tag)
{
	const long attrs = GA.attributes();

	if(string(tag.name()) == "viz:position") {
		if(attrs & GraphAttributes::nodeGraphics) {
			pugi::xml_attribute xAttr = tag.attribute("x");
			pugi::xml_attribute yAttr = tag.attribute("y");
			pugi::xml_attribute zAttr = tag.attribute("z");

			if(!xAttr || !yAttr) {
				GraphIO::logger.lout() << "Missing \"x\" or \"y\" in position tag." << std::endl;
				return false;
			}

			GA.x(v) = xAttr.as_int();
			GA.y(v) = yAttr.as_int();

			// z attribute is optional and avaliable only in \a threeD mode
			GA.y(v) = yAttr.as_int();
			if (zAttr && (attrs & GraphAttributes::threeD)) {
				GA.z(v) = zAttr.as_int();
			}
		}
	} else if(string(tag.name()) == "viz:size") {
		if(attrs & GraphAttributes::nodeGraphics) {
			pugi::xml_attribute valueAttr = tag.attribute("value");
			if (!valueAttr) {
				GraphIO::logger.lout() << "\"size\" attribute is missing a value." << std::endl;
				return false;
			}

			double size = valueAttr.as_double();
			GA.width(v) = size * LayoutStandards::defaultNodeWidth();
			GA.height(v) = size * LayoutStandards::defaultNodeHeight();
		}
	} else if(string(tag.name()) == "viz:shape") {
		if(attrs & GraphAttributes::nodeGraphics) {
			pugi::xml_attribute valueAttr = tag.attribute("value");
			if(!valueAttr) {
				GraphIO::logger.lout() << "\"shape\" attribute is missing a value." << std::endl;
				return false;
			}

			GA.shape(v) = toShape(valueAttr.value());
		}
	} else if(string(tag.name()) == "viz:color") {
		if(attrs & GraphAttributes::nodeStyle) {
			return readColor(GA.fillColor(v), tag);
		}
	} else {
		GraphIO::logger.lout() << "Incorrect tag: \"" << tag.name() << "\"." << std::endl;
		return false;
	}

	return true;
}
Exemplo n.º 16
0
bool TextLine::readProperties(const QDomElement& e)
      {
      const QString& tag(e.tagName());
      const QString& text(e.text());

      if (tag == "beginHookHeight") {
            _beginHookHeight = Spatium(text.toDouble());
            _beginHook = true;
            }
      else if (tag == "beginHookType")
            _beginHookType = HookType(text.toInt());
      else if (tag == "endHookHeight" || tag == "hookHeight") { // hookHeight is obsolete
            _endHookHeight = Spatium(text.toDouble());
            _endHook = true;
            }
      else if (tag == "endHookType")
            _endHookType = HookType(text.toInt());
      else if (tag == "hookUp")           // obsolete
            _endHookHeight *= qreal(-1.0);
      else if (tag == "beginSymbol" || tag == "symbol")     // "symbol" is obsolete
            _beginSymbol = text[0].isNumber() ? SymId(text.toInt()) : Sym::name2id(text);
      else if (tag == "continueSymbol")
            _continueSymbol = text[0].isNumber() ? SymId(text.toInt()) : Sym::name2id(text);
      else if (tag == "endSymbol")
            _endSymbol = text[0].isNumber() ? SymId(text.toInt()) : Sym::name2id(text);
      else if (tag == "beginSymbolOffset")
            _beginSymbolOffset = readPoint(e);
      else if (tag == "continueSymbolOffset")
            _continueSymbolOffset = readPoint(e);
      else if (tag == "endSymbolOffset")
            _endSymbolOffset = readPoint(e);
      else if (tag == "lineWidth")
            _lineWidth = Spatium(text.toDouble());
      else if (tag == "lineStyle")
            _lineStyle = Qt::PenStyle(text.toInt());
      else if (tag == "beginTextPlace")
            _beginTextPlace = readPlacement(e);
      else if (tag == "continueTextPlace")
            _continueTextPlace = readPlacement(e);
      else if (tag == "lineColor")
            _lineColor = readColor(e);
      else if (tag == "beginText") {
            _beginText = new Text(score());
            _beginText->setParent(this);
            _beginText->read(e);
            }
      else if (tag == "continueText") {
            _continueText = new Text(score());
            _continueText->setParent(this);
            _continueText->read(e);
            }
      else if (!SLine::readProperties(e)) {
            qDebug(" ==readSLineProps: failed");
            return false;
            }
      return true;
      }
Exemplo n.º 17
0
static gfxcolor_t read_color(reader_t*r, state_t*state, U8 id, U8 flags)
{
    assert(id>=0 && id<16);
    if(flags&FLAG_SAME_AS_LAST)
	return state->last_color[id];
    gfxcolor_t c = readColor(r, state);
    state->last_color[id] = c;
    return c;
}
std::list<Light> SceneSettingReader::readLights()
{
    std::list<Light> lights;
    settings_.beginGroup(LIGHTS_GROUP);
    const int size = settings_.beginReadArray("lights");
    for (int i = 0; i < size; ++i)
    {
        settings_.setArrayIndex(i);
        settings_.beginGroup("diffuse");
        const Color diffuse = readColor();
        settings_.endGroup();
        settings_.beginGroup("specular");
        const Color specular = readColor();
        settings_.endGroup();
        lights.push_back(Light(readPoint(), diffuse, specular));
    }
    settings_.endArray();
    settings_.endGroup();
    return lights;
}
Exemplo n.º 19
0
Line *JsonFileReader::readLine(const QJsonObject &l)
{
    Line *line = new Line();

    line->setP1(readPoint(l["P1"].toObject()));
    line->setP2(readPoint(l["P2"].toObject()));
    line->setLineThickness(l["LineThickness"].toInt());
    line->setLineColor(readColor(l["LineColor"].toObject()));

    return line;
}
Exemplo n.º 20
0
void WorldInfo::init() {
  QJsonArray json = load(":/res/tiles.json");
  for (int i = 0; i < json.size(); i++) {
    QJsonObject const &obj = json[i].toObject();
    quint16 id = obj["id"].toInt();
    tiles[id] = QSharedPointer<TileInfo>(new TileInfo(obj));
  }
  json = load(":/res/walls.json");
  for (auto const &item : json) {
    QJsonObject const &obj = item.toObject();
    quint16 id = obj["id"].toInt();
    walls[id] = QSharedPointer<WallInfo>(new WallInfo(id, obj));
  }
  json = load(":/res/prefixes.json");
  for (auto const &item : json) {
    QJsonObject const &obj = item.toObject();
    quint16 id = obj["id"].toInt();
    prefixes[id] = obj["name"].toString();
  }
  json = load(":/res/items.json");
  for (auto const &item : json) {
    QJsonObject const &obj = item.toObject();
    quint16 id = obj["id"].toInt();
    items[id] = obj["name"].toString();
  }
  json = load(":/res/npcs.json");
  for (auto const &item : json) {
    QJsonObject const &obj = item.toObject();
    if (obj.contains("banner"))
      npcsByBanner[obj["banner"].toInt()] = QSharedPointer<NPC>(new NPC(obj));
    else if (!npcsByName.contains(obj["name"].toString()))
      npcsByName[obj["name"].toString()] = QSharedPointer<NPC>(new NPC(obj));
  }
  json = load(":/res/globals.json");
  for (auto const &item : json) {
    QJsonObject const &obj = item.toObject();
    QString kind = obj["id"].toString();
    quint32 color = readColor(obj["color"].toString());
    if (kind == "sky")
      sky = color;
    else if (kind == "earth")
      earth = color;
    else if (kind == "rock")
      rock = color;
    else if (kind == "hell")
      hell = color;
    else if (kind == "water")
      water = color;
    else if (kind == "lava")
      lava = color;
    else if (kind == "honey")
      honey = color;
  }
}
Exemplo n.º 21
0
void setup(){
  Serial.begin(9600);
  calibrateAll();
  leftServo.attach(9, 1300, 1700);
  rightServo.attach(10, 1300, 1700);
  while(!finishLine){
    driveStraight(10, 50);
    readColor();
  }
  
  turnLeftInDegrees(90);
  driveInInches(36);
  for(int i = 0; i < 12; i++){
    turnRightInDegrees(90);
    for(int i = 0; i < 30; i++){
      if(reading >= yellowMin && reading <= yellowMax){
        foundGold = true;
      }
      if(!foundGold){
        driveInInches(0.1);
      }
    }
    turnRightInDegrees(90);
    for(int i = 0; i < 720; i++){
      if(reading >= yellowMin && reading <= yellowMax){
        foundGold = true;
      }
      if(!foundGold){
        driveInInches(0.1);
      }
    }
    turnLeftInDegrees(90);
    for(int i = 0; i < 30; i++){
      if(reading >= yellowMin && reading <= yellowMax){
        foundGold = true;
      }
      if(!foundGold){
        driveInInches(0.1);
      }
    }
    turnLeftInDegrees(90);
    for(int i = 0; i < 720; i++){
      if(reading >= yellowMin && reading <= yellowMax){
        foundGold = true;
      }
      if(!foundGold){
        driveInInches(0.1);
      }
    }
  }
  
  
}
Exemplo n.º 22
0
bool ToolFill::mousePressed(ListenerContext<sf::Event::MouseButtonEvent> ctx)
{
    sf::Vector2u size = ctx.getUI()->getEngine()->getSize();
    glm::vec4 col = readColor(size, ctx.event.x, ctx.event.y);
    glm::vec4 newCol = ctx.getUI()->getSelectedColor();

    if (col == newCol) return false;

    glBindFramebuffer(GL_FRAMEBUFFER, GraphicsEngine::fbo);
    std::vector<glm::vec2> points;
    floodFill(points, size, {ctx.event.x, ctx.event.y}, col);
    ctx.getUI()->getEngine()->addObject(new PointBlob(newCol, points));
    glBindFramebuffer(GL_FRAMEBUFFER, 0);

    return true;
}
Exemplo n.º 23
0
/** loadSceneObj **/
void loadSceneObj(FILE *inFP, entity_t *ent) 
{
   /* Attributes recognized by loadSceneObj */
   char *attributes[] = {"color", "diffuse", "reflective", NULL};
   int ndx;    /* Index from attributes array that matches attribute */

   char attribute[25];
   assert(ent->magic == ENTITY_T);
   sobj_t *obj = ent->entDerived;     /* Pointer to object's sobj_t  */
   assert(obj->magic == SCENEOBJ_T);

   fscanf(inFP, "%s", attribute);
   while(attribute[0] != ';')
   {
      /* Get the index of the attribute */
      ndx = getindex(attribute, attributes);

      /* Process the attribute */
      switch (ndx) {
      case 0:
         /** color  attribute **/
         obj->color = readColor(inFP, "Could not read color values");
         break;

      case 1:
         /** diffuse attribute **/
         obj->diffuse = vec_read(inFP, "Could not read diffuse values");
         break;

      case 2:
         /** reflective attribute **/
         obj->reflective = vec_read(inFP, 
             "Could not read reflective vaules");
         break;

      default:
         fprintf(stderr, "bad sceneobj attribute; exiting\n");
         exit(1);
      }

      fscanf(inFP, "%s", attribute);
   }

}
Exemplo n.º 24
0
static gfxgradient_t* readGradient(reader_t*r, state_t*state)
{
    gfxgradient_t*start = 0, *pos = 0;
    while(1) {
	U8 op = reader_readU8(r);
	if(!op)
	    break;
	gfxgradient_t*g = (gfxgradient_t*)rfx_calloc(sizeof(gfxgradient_t));
	if(!start) {
	    start = pos = g;
	} else {
	    pos->next = g;
	    pos = g;
	}
	g->color = readColor(r, state);
	g->pos = reader_readFloat(r);
    }
    return start;
}
static QPen readSimplePen (QDataStream &instream) {
	QColor col = readColor (instream);
	double lwd;
	qint32 lty;
	instream >> lwd >> lty;
	if (!col.isValid () || (lty == -1L)) return QPen (Qt::NoPen);

	lwd = qMax (1.0001, lwd);	// minimum 1 px (+rounding margin!) as in X11 device
	QPen ret;
	if (lty != 0) {	// solid
		QVector<qreal> dashes;
		quint32 nlty = lty;
		for (int i = 0; i < 8; ++i) {
			if (!nlty) break;
			quint8 j = nlty & 0xF;
			dashes.append (j * lwd * 96/72 + .5);	// 96/72: value taken from X11 device
			nlty >>= 4;
		}
		if (!dashes.isEmpty ()) ret.setDashPattern (dashes);
	}
Exemplo n.º 26
0
int ScriptParser::menusetwindowCommand()
{
    menu_font.ttf_font        = NULL;
    menu_font.font_size_xy[0] = script_h.readInt();
    menu_font.font_size_xy[1] = script_h.readInt();
    menu_font.pitch_xy[0]     = script_h.readInt() + menu_font.font_size_xy[0];
    menu_font.pitch_xy[1]     = script_h.readInt() + menu_font.font_size_xy[1];
    menu_font.is_bold         = script_h.readInt()?true:false;
    menu_font.is_shadow       = script_h.readInt()?true:false;

    const char *buf = script_h.readStr();
    if ( strlen(buf) ){ // Comma may or may not be appeared in this case.
        readColor( &menu_font.window_color, buf );
    }
    else{
        menu_font.window_color[0] = menu_font.window_color[1] = menu_font.window_color[2] = 0x99;
    }

    return RET_CONTINUE;
}
Exemplo n.º 27
0
TileInfo::TileInfo(const QJsonObject &json) {
  name = json["name"].toString();
  color = json.contains("color") ? readColor(json["color"].toString()) : 0;
  lightR = json.contains("r") ? json["r"].toDouble(0.0) : 0.0;
  lightG = json.contains("g") ? json["g"].toDouble(0.0) : 0.0;
  lightB = json.contains("b") ? json["b"].toDouble(0.0) : 0.0;
  mask = json["flags"].toInt(0);
  solid = mask & 1;
  transparent = mask & 2;
  dirt = mask & 4;
  stone = mask & 8;
  grass = mask & 16;
  pile = mask & 32;
  flip = mask & 64;
  brick = mask & 128;
  // moss = mask & 256;
  merge = mask & 512;
  large = mask & 1024;
  isHilighting = false;

  QString b = json["blend"].toString();
  int offset = 0;
  while (offset < b.length())
    blends.append(parseMB(b, true, &offset));

  QString m = json["merge"].toString();
  offset = 0;
  while (offset < m.length())
    blends.append(parseMB(m, false, &offset));

  width = json["w"].toInt(18);
  height = json["h"].toInt(18);
  skipy = json["skipy"].toInt(0);
  toppad = json["toppad"].toInt(0);
  if (json.contains("var")) {
    for (auto const &item : json["var"].toArray()) {
      QJsonObject const &obj = item.toObject();
      variants.append(QSharedPointer<TileInfo>(new TileInfo(obj, *this)));
    }
  }
}
Exemplo n.º 28
0
void Sorter::periodic(ControllerData ctrl)
{
  if(CTRL_ROBOT_RED){
    robotColor = red;
  }
  if(CTRL_ROBOT_GREEN){
    robotColor = green;
  }
  if(CTRL_ROBOT_WHITE){
    robotColor = white;
  }
  if(CTRL_ROBOT_YELLOW){
    robotColor = yellow;
  }
  switch(state){
  case neutral:
    if(golfballClose()){
      if(readColor() == robotColor){
        sorterServo.write(SORTER_ACCEPT_POSN);
        state = accept;
      }else{
        sorterServo.write(SORTER_REJECT_POSN);
        state = reject;
      }
    }
    break;
  case accept:
    if(millis() - startSortTime > SORTER_ACCEPT_TIME){
      sorterServo.write(SORTER_NEUTRAL_POSN);
      state = neutral;
    }
    break;
  case reject:
    if(millis() - startSortTime > SORTER_REJECT_TIME){
      sorterServo.write(SORTER_NEUTRAL_POSN);
      state = neutral;
    }
    break;
  }
}
Exemplo n.º 29
0
TileInfo::TileInfo(const QJsonObject &json, const TileInfo &parent) {
  name = json["name"].toString(parent.name);
  color = json.contains("color") ? readColor(json["color"].toString())
      : parent.color;
  lightR = json["r"].toDouble(parent.lightR);
  lightG = json["g"].toDouble(parent.lightG);
  lightB = json["b"].toDouble(parent.lightB);

  mask = parent.mask;
  isHilighting = false;

  solid = parent.solid;
  transparent = parent.transparent;
  dirt = parent.dirt;
  stone = parent.stone;
  grass = parent.grass;
  pile = parent.pile;
  flip = parent.flip;
  brick = parent.brick;
  merge = parent.merge;
  large = parent.large;

  width = parent.width;
  height = parent.height;
  skipy = parent.skipy;
  toppad = json["toppad"].toInt(parent.toppad);
  u = json["x"].toInt(-1) * width;
  v = json["y"].toInt(-1) * (height + skipy);
  minu = json["minx"].toInt(-1) * width;
  maxu = json["maxx"].toInt(-1) * width;
  minv = json["miny"].toInt(-1) * (height + skipy);
  maxv = json["maxy"].toInt(-1) * (height + skipy);
  if (json.contains("var")) {
    QJsonArray const &arr = json["var"].toArray();
    for (auto const &item : arr) {
      QJsonObject const &obj = item.toObject();
      variants.append(QSharedPointer<TileInfo>(new TileInfo(obj, *this)));
    }
  }
}
void SpecificWorker::readFrame()
{
	openni::Status rc = openni::STATUS_OK;
	openni::VideoStream* streams[] = {&depth, &color};

	int changedIndex = -1;
	while (rc == openni::STATUS_OK)
	{
		rc = openni::OpenNI::waitForAnyStream(streams, 2, &changedIndex, 0);
		if (rc == openni::STATUS_OK)
		{
			switch (changedIndex)
			{
			case 0:
				readDepth(); break;
			case 1:
				readColor(); break;
			default:
				printf("Error in wait\n");
			}
		}
	}
}