Example #1
0
bool PinManager::addPin(const std::string& p_pinNumber, const std::string& p_mode)
{
    boost::unordered_map<std::string, boost::shared_ptr<GPIOPin> >::const_iterator it = m_pinsInUse.find(p_pinNumber);
    // not found make a new pin object and insert it.
    if(it == m_pinsInUse.end())
    {
        std::cout << "Inserting pin# " << p_pinNumber << std::endl;
        return insertPin(p_pinNumber, p_mode);
    }
    // pin found can't insert pin it's in use.
    else
    {
        std::cout << "Cannot add pin since it is already in use" << std::endl;
        return false;
    }
}
Example #2
0
/** Carga el componente. El parser llama a esta funcion una vez de
 * haver leido el token "comp" y su nombre
 * Formato de texto plano:
comp "nombre" [x] [y] [w] [h]
...parametros de los derivados... (o nada)
pin "nombre" in/out [idn] [idm]
...
endcomo
 */
bool QComponent::load( FILE *f )
{
  if ( fscanf( f, "%d%d%d%d", &r.a.x, &r.a.y, &r.b.x, &r.b.y ) != 4 )
    return false;
  r.b.x += r.a.x;
  r.b.y += r.a.y;

  if ( !extraLoad( f ) )
    return false;

  char b[32];
  while ( !feof( f ) ) {
    char pinName[32];
    int pio, idn, idm;
    bool pointIsNiple;
    if ( fscanf( f, "%s", b ) != 1 )
      return false;
    if ( strcmp( b, "pin" ) == 0 ) {
      if ( !getString( f, pinName ) )
	return false;
      if ( fscanf( f, "%s%d%d", b, &idn, &idm ) != 3 )
	return false;

      if ( strcmp( b, "in" ) == 0 )
	pio = pinIn;
      else if ( strcmp( b, "out" ) == 0 )
	pio = pinOut;
      else
	return false;

      QNode *pn = doc->getNode( idn );
      if ( !pn )
	return false;
      QNodePoint *pm = pn->getPoint( idm );
      if ( !pm )
	return false;
      insertPin( new QPin( pio, pn, pm, pinName ) );
    } else if ( strcmp( b, "endcomp" ) == 0 )
      return true;
    else
      return false;
  }
  return false; // Unexpected EOF
}