Пример #1
0
void CSimpleStat::clear()
{
  if (mSampleBuffer != NULL)
    memset(mSampleBuffer, 0, mBufLength*sizeof(double));
  mBufPos   = 0;
  mAvgSum    = 0;
  mSqrSum    = 0;
  mAvgSumShd  = 0;
  mSqrSumShd  = 0;
  mHasWrapped  = false;
  resetMinMax();
}
DS18B20TempSensorThread::DS18B20TempSensorThread(uint8_t _address, uint8_t _pin )
{
    /* init the pin to read from */
    oneWirePin = _pin;
    DS18B20Address = _address;
    resetMinMax();
    ds = new OneWire(oneWirePin);

    if (!ds->search(addr)) 
    { // Recherche un module 1-Wire
        ds->reset_search();    // Réinitialise la recherche de module
        // return false;         // Retourne une erreur
    }

    if (OneWire::crc8(addr, 7) != addr[7]) // Vérifie que l'adresse a été correctement reçue
    {
        // return false;                        // Si le message est corrompu on retourne une erreur
    }

    if (addr[0] != DS18B20Address) // Vérifie qu'il s'agit bien d'un DS18B20
    {
        // return false;         // Si ce n'est pas le cas on retourne une erreur
    }
}
Пример #3
0
JoyDevice::ErrorCode JoyDevice::open()
{
  if ( joyFd != -1 ) return JoyDevice::SUCCESS;  // already open

  int fd = ::open(devName.latin1(), O_RDONLY);

  if ( fd == -1 )
    return JoyDevice::OPEN_FAILED;

  // we could open the devicefile, now check if a joystick is attached
  char name[128];

  if ( ::ioctl(fd, JSIOCGNAME(sizeof(name)), &name) == -1 )
  {
    ::close(fd);
    return JoyDevice::NO_JOYSTICK;
  }

  // check the kernel driver version
  int version;
  if ( ::ioctl(fd, JSIOCGVERSION, &version) == -1 )
  {
    ::close(fd);
    return JoyDevice::ERR_GET_VERSION;
  }

  if ( version != JS_VERSION )
  {
    ::close(fd);
    return JoyDevice::WRONG_VERSION;
  }

  char bt = 0, ax = 0;
  if ( ::ioctl(fd, JSIOCGBUTTONS, &bt) == -1 )
  {
    ::close(fd);
    return JoyDevice::ERR_GET_BUTTONS;
  }

  if ( ::ioctl(fd, JSIOCGAXES, &ax) == -1 )
  {
    ::close(fd);
    return JoyDevice::ERR_GET_AXES;
  }

  struct js_corr *oldCorr = new struct js_corr[ax];

  if ( ::ioctl(fd, JSIOCGCORR, oldCorr) == -1 )
  {
    ::close(fd);
    delete [] oldCorr;
    return JoyDevice::ERR_GET_CORR;
  }

  descr = name;
  joyFd = fd;
  axes = ax;
  buttons = bt;
  origCorr = oldCorr;
  corr = new struct js_corr[axes];

  amin = new int[axes];
  amax = new int[axes];

  int i;

  for (i = 0; i < axes; i++)
    resetMinMax(i);

  return JoyDevice::SUCCESS;
}
Пример #4
0
Mesh::Mesh(const char* off_filename) :
	_normals(0),
	_min(INFINITY, INFINITY, INFINITY),
	_max(-INFINITY, -INFINITY, -INFINITY),
	_fullyTriangulated(true)
{    
	_filename = off_filename;

    {
        QStringList sl = _filename.split('/');
        _name = sl.at(sl.size() - 1).split(".").at(0);
    }

    QFile file(_filename);
    if (not file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
		THROW(MeshException, QString("Unable to open file \'%1\' for reading.").arg(file.errorString()));

    }

    QTextStream in(&file);

    int lineNumber = 0;
    QString line;

    do
    {
        line = in.readLine();
        lineNumber++;
    }
    while (not line.isEmpty() and line.at(0) == '#');


    // is signature correct?
    line.truncate(3);
    if(line.isNull() or (line != "OFF" and line != "off"))
		THROW(MeshException, QString("\'%1\'' is not an OFF file ").arg(off_filename));
    lineNumber++;

    // skip comments
    do
    {
        line = in.readLine();
        lineNumber++;
    }
    while(not line.isNull() and line.at(0) == '#');
    QStringList lst = line.split(' ');

    // get vertex_count face_count edge_count
	size_t vertex_count = lst.at(0).toULong(), face_count = lst.at(1).toULong();//, edge_count = lst.at(2).toULong();

    resetMinMax();

    // process vertices
    for (size_t i = 0; i < vertex_count and not in.atEnd(); i++)
    {
        lineNumber++;
        float coord[3];
        in >> coord[0] >> coord[1] >> coord[2];
        if (in.status() != QTextStream::Ok)
			THROW(MeshException, QString(" in %1:%1 failed to read coordinate.").arg(off_filename, QString::number(lineNumber)));
		_vertices.push_back(QVector3D(coord[0], coord[1], coord[2]));
    }

    // process faces
    for(size_t i = 0; i < face_count and not in.atEnd(); i++)
    {
        unsigned firstIndex, lastIndex;
        int poly_type;
        in >> poly_type;
        if (in.status() == QTextStream::Ok)
        {
            if(poly_type != 3)
				_fullyTriangulated = false;

            unsigned vertexIndex;
            for(int i = 0; i < poly_type; i++)
            {
                lastIndex = vertexIndex;
                in >> vertexIndex;
                if (in.status() == QTextStream::Ok)
				{
                    if (i == 0)
                        firstIndex = vertexIndex;
                    else if (i > 2) // this triangulation should work for convex polygons
                    {
                        _triangleIndices.push_back(firstIndex);
                        _triangleIndices.push_back(lastIndex);
                    }

					_min = vecmin(_min, _vertices[vertexIndex]);
					_max = vecmax(_max, _vertices[vertexIndex]);
					_triangleIndices.push_back(vertexIndex);
				}
                else
					THROW(MeshException, QString("in %1:%2 polygon is not a Triangle.").arg(off_filename, QString::number(lineNumber)));
            }			
        }
        else
			THROW(MeshException, QString("in %1:%2 failed to read number of vertices.").arg(off_filename, QString::number(lineNumber)));

        lineNumber++;
    }