예제 #1
0
bool MainWindow::connectRobot (const QString& address) {
  if (m_connectedRobots.end() != m_connectedRobots.find(address)) {
    /* The requested robot is already connected */
    return true;
  }

  auto newrobot = new mobot_t;
  Mobot_init(newrobot);

  /* extract the 8-bit byte array from QString, from which we can then extract
   * the C-string */
  auto baAddress = address.toLocal8Bit();

  if (-1 == Mobot_connectWithAddress(newrobot, baAddress.data(), 1)) {
    delete newrobot;
    qDebug() << "(barobolab) ERROR: Mobot_connectWithTTY failed\n";
    return false;
  }
  Mobot_enableButtonCallback(newrobot, strdup(baAddress.data()), JsInterface::robotButtonCallback);
  auto l = new RobotListener(newrobot, address);
  QObject::connect(l, SIGNAL(scrollUp(QString)), m_interface, SLOT(scrollUpSlot(QString)));
  QObject::connect(l, SIGNAL(scrollDown(QString)), m_interface, SLOT(scrollDownSlot(QString)));
  QThread *thread = new QThread(this);
  l->moveToThread(thread);
  thread->start();
  QMetaObject::invokeMethod(l, "startWork", Qt::QueuedConnection);
  m_connectedRobots.insert(std::make_pair(address, newrobot));
  m_robotListeners.insert(std::make_pair(address, l));
  return true;
}
예제 #2
0
int main()
{
  int i = 0;
  mobot_t mobot;
  Mobot_init(&mobot);
  //Mobot_connectWithAddress(&mobot, "LQLX", 1);
  Mobot_connectWithAddress(&mobot, "S3S3", 1);
  Mobot_enableJointEventCallback(&mobot, NULL, jointcb);
  Mobot_enableAccelEventCallback(&mobot, NULL, accelcb);
  printf("Press enter to quit.\n");
  getchar();

  return 0;
}