예제 #1
0
void MainWindow::baroboInit () {
  Mobot_init(m_dongle.get());
  char tty[64];
  if (-1 == Mobot_dongleGetTTY(tty, sizeof(tty))) {
    qWarning("(barobolab) WARNING: Mobot_dongleGetTTY failed\n");
  }
  if (-1 == Mobot_connectWithTTY(m_dongle.get(), tty)) {
    qWarning("(barobolab) WARNING: Mobot_connectWithTTY failed\n");
  }
  Mobot_setDongleMobot(m_dongle.get());
}
void Dialog::beginProgramming()
{
  int numTries = 0;
  char buf[1024];
  int rc;
  QMessageBox msgbox;
#ifdef _WIN32
    Sleep(3000);
#else
    usleep(3000000);
#endif
  rc = Mobot_dongleGetTTY(buf, 1024);
  if(rc) {
    msgbox.setText("No connected robots detected.");
    msgbox.exec();
    return;
  }
  while(1) {
    qDebug() << "Connecting to: " << buf;
    stk_ = new CStkComms();
    rc = stk_->connectWithTTY(buf);
    qDebug() << "Connection finish with code: " << rc;
    if(rc) { 
      if(numTries > 20) {
        msgbox.setText("Detected robot not running valid bootloader. Please make "
            "sure that the \"Program Firmware\" button is being clicked after "
            "the red LED flashes but before the solid blue LED is showing. 1");
        msgbox.exec();
        return; 
      } else {
#ifdef _WIN32
        Sleep(100);
#else
        usleep(100000);
#endif
        numTries++;
      }
    } else {
      break;
    }
    numTries = 0;
#if 0
    qDebug() << "Attempting handshake...";
    rc = stk_->handshake();
    qDebug() << "Handshake finished with code " << rc;
    if(rc) { 
      if(numTries > 5) {
        msgbox.setText("Detected robot not running valid bootloader. Please make "
            "sure that the \"Program Firmware\" button is being clicked after "
            "the red LED flashes but before the solid blue LED is showing. 2");
        msgbox.exec();
        return; 
      } else {
#ifdef _WIN32
        Sleep(500);
#else
        usleep(500000);
#endif
        numTries++;
      }
    }
#endif
  }
  qDebug() << "Attempting to begin programming...";
  stk_->programAllAsync(g_hexfilename.c_str());
  ui->progressBar->setEnabled(true);
  /* Start a timer to update the progress bar */
  timer_ = new QTimer(this);
  QObject::connect(timer_, SIGNAL(timeout()), this, SLOT(update_progress_bar()));
  timer_->start(1000);
}