示例#1
0
void solver::on_actionLoad_Soup_triggered()
{
    QString f =  QFileDialog::getOpenFileName(this," sopa","Cargar sopa de letras");
    if(f.isEmpty())
       return;
    QLabel *l ;

    QFile file(f);
    if(file.open(QIODevice::ReadOnly)){
         QTextStream a(&file);
         QString len = a.readLine();
         this->lenX = readLen(len.indexOf("x:"),len);
         this->lenY = readLen(len.indexOf("y:"),len);
         this->crearArray();

         for(int i = 0; i<this->ui->soup->count(); i++)
             this->ui->soup->removeItem(this->ui->soup->itemAt(i));

         for(int y = 0; y < this->lenY; y++){
             QString i = a.readLine(); int at = 0;qDebug()<<i;
             for(int x = 0; x < this->lenX; x++){
                    l = new QLabel();
                 this->ui->soup->addWidget(l,y,x);
                 l->setText(QString(i.at(at)));
                  sopa[y][x] =   i.at(at);
                    at +=2;

             }
         }

    }

}
示例#2
0
void Adafruit_BNO055::getCalibData(byte * pbuffer)
{
   adafruit_bno055_opmode_t backupmode = _mode;
   setMode(OPERATION_MODE_CONFIG);
   delay(25);
    readLen(ACCEL_OFFSET_X_LSB_ADDR, pbuffer, 22); //read the whole range of offsets
   setMode(backupmode); //return to previous opmode
   delay(25);
}
示例#3
0
imu::Vector<3> Adafruit_BNO055::getVector(adafruit_vector_type_t vector_type)
{
  imu::Vector<3> xyz;
  uint8_t buffer[6];
  memset (buffer, 0, 6);
  
  int16_t x, y, z;
  x = y = z = 0;
  
  /* Read vector data (6 bytes) */
  readLen((adafruit_bno055_reg_t)vector_type, buffer, 6);
  
  x = ((int16_t)buffer[0]) | (((int16_t)buffer[1]) << 8);
  y = ((int16_t)buffer[2]) | (((int16_t)buffer[3]) << 8);
  z = ((int16_t)buffer[4]) | (((int16_t)buffer[5]) << 8);

  /* Convert the value to an appropriate range (section 3.6.4) */
  /* and assign the value to the Vector type */
  switch(vector_type)
  {
    case VECTOR_MAGNETOMETER:
      /* 1uT = 16 LSB */
      xyz[0] = ((double)x)/16.0;
      xyz[1] = ((double)y)/16.0;
      xyz[2] = ((double)z)/16.0;
      break;
    case VECTOR_GYROSCOPE:
      /* 1rps = 900 LSB */
      xyz[0] = ((double)x)/900.0;
      xyz[1] = ((double)y)/900.0;
      xyz[2] = ((double)z)/900.0;
      break;
    case VECTOR_EULER:
      /* 1 degree = 16 LSB */
      xyz[0] = ((double)x)/16.0;
      xyz[1] = ((double)y)/16.0;
      xyz[2] = ((double)z)/16.0;
      break;
    case VECTOR_ACCELEROMETER:
    case VECTOR_LINEARACCEL:
    case VECTOR_GRAVITY:
      /* 1m/s^2 = 100 LSB */
      xyz[0] = ((double)x)/100.0;
      xyz[1] = ((double)y)/100.0;
      xyz[2] = ((double)z)/100.0;
      break;
  }
  
  return xyz;
}
示例#4
0
文件: Connection.cpp 项目: go4and/lib
void Connection::processParams()
{
    MLOG_MESSAGE(Debug, "processParams(" << stream_.size() << ")");
    MLOG_MESSAGE(Debug, "processParams(" << mlog::dump(stream_) << ")");

    nexus::PacketReader reader(stream_);
    while(reader.left())
    {
        size_t nameLen = readLen(reader);
        size_t valueLen = readLen(reader);
        if(reader.raw() <= reader.end() && nameLen + valueLen <= reader.left())
        {
            std::string name(reader.raw(), reader.raw() + nameLen);
            reader.skip(nameLen);
            std::string value(reader.raw(), reader.raw() + valueLen);
            reader.skip(valueLen);
            params_.insert(Params::value_type(name, value));
            MLOG_MESSAGE(Debug, "param: " << name << ", value: " << value);
        } else {
            MLOG_MESSAGE(Error, "left: " << reader.left() << ", nameLen: " << nameLen << ", valueLen: " << valueLen);
            break;
        }
    }
}
/********************************************************************
* Read a word from the socket
* The word that was read is returned as a string
********************************************************************/
char *readWord(int fdSock) {
    int  iLen         = readLen(fdSock);
    int  iBytesToRead = 0;
    int  iBytesRead   = 0;
    char *szWord;
    char *szRetWord;
    char *szTmpWord;

    DEBUG ? printf("readWord iLen=%x\n", iLen) : 0;

    if (iLen > 0) {
        // allocate memory for strings
        szRetWord = calloc(sizeof(char), iLen + 1);
        szTmpWord = calloc(sizeof(char), 1024 + 1);

        while (iLen != 0) {
            // determine number of bytes to read this time around
            // lesser of 1024 or the number of byes left to read
            // in this word
            iBytesToRead = iLen > 1024 ? 1024 : iLen;

            // read iBytesToRead from the socket
            iBytesRead = recv(fdSock, szTmpWord, iBytesToRead, 0);
            if (iBytesRead <= 0) {
                free(szTmpWord);
                free(szRetWord);
                return 0;
            }

            // terminate szTmpWord
            szTmpWord[iBytesRead] = 0;

            // concatenate szTmpWord to szRetWord
            strcat(szRetWord, szTmpWord);

            // subtract the number of bytes we just read from iLen
            iLen -= iBytesRead;
        }

        // deallocate szTmpWord
        free(szTmpWord);

        DEBUG ? printf("word = %s\n", szRetWord) : 0;
        return szRetWord;
    } else {
        return NULL;
    }
}
imu::Quaternion Adafruit_BNO055::getQuat(void)
{
  uint8_t buffer[8];
  memset (buffer, 0, 8);
  
  int16_t x, y, z, w;
  x = y = z = w = 0;
  
  /* Read quat data (8 bytes) */
  readLen(BNO055_QUATERNION_DATA_W_LSB_ADDR, buffer, 8);
  w = (((uint16_t)buffer[1]) << 8) | ((uint16_t)buffer[0]);
  x = (((uint16_t)buffer[3]) << 8) | ((uint16_t)buffer[2]);
  y = (((uint16_t)buffer[5]) << 8) | ((uint16_t)buffer[4]);
  z = (((uint16_t)buffer[7]) << 8) | ((uint16_t)buffer[6]);

  /* Assign to Quaternion */
  imu::Quaternion quat((double)w, (double)x, (double)y, (double)z);
  return quat;
}
示例#7
0
imu::Quaternion Adafruit_BNO055::getQuat(void)
{
  uint8_t buffer[8];
  memset (buffer, 0, 8);
  
  int16_t x, y, z, w;
  x = y = z = w = 0;
  
  /* Read quat data (8 bytes) */
  readLen(BNO055_QUATERNION_DATA_W_LSB_ADDR, buffer, 8);
  w = (((uint16_t)buffer[1]) << 8) | ((uint16_t)buffer[0]);
  x = (((uint16_t)buffer[3]) << 8) | ((uint16_t)buffer[2]);
  y = (((uint16_t)buffer[5]) << 8) | ((uint16_t)buffer[4]);
  z = (((uint16_t)buffer[7]) << 8) | ((uint16_t)buffer[6]);

  /* Assign to Quaternion */
  /* See http://ae-bst.resource.bosch.com/media/products/dokumente/bno055/BST_BNO055_DS000_12~1.pdf
     3.6.5.5 Orientation (Quaternion)  */
  const double scale = (1.0 / (1<<14));
  imu::Quaternion quat(scale * w, scale * x, scale * y, scale * z);
  return quat;
}