task main() { int t; int direction= TURN_RIGHT; while(true) { //estado = camino goFast(); while(SensorValue[lightSensor] < LIGHT_WHITE); goStop(); //estado = correccion optimista //giro 1 t= TURN_INIT_TIME; turn(direction); if(stopWhenBlackOrTimeout(t)) continue; //giro 2 turn*= -1; turn(direction); if(stopWhenBlackOrTimeout(t*2)) continue; //estado = correccion pesimista //deshace giro direction*= -1; turn(direction); wait1Msec(t); goStop(); //regresa goBackwards(); while(SensorValue[lightSensor] >= LIGHT_WHITE); goStop(); //find other wall while(SensorValue[lightSensor] < LIGHT_WHITE) { turn(direction); wait1Msec(t); goStop(); t+=20; direction*=-1; } //center in path turn(-direction); wait1Msec(CENTER_TIME); goStop(); } }
bool stopWhenBlackOrTimeout(int t) { int delay=0; while(SensorValue[lightSensor] >= LIGHT_WHITE) { wait1Msec(10); delay+=10; if( delay>= t) { goStop(); return false; } } goStop(); return true; }
// constructor // ------------------------------------------------------------------ rigctl::rigctl(QWidget * parent) : QDialog(parent), settings(QSettings::IniFormat, QSettings::UserScope,"QtLog", "qtlog") { setupUi(this); int n = settings.value("FontSize").toString().toInt(); QFont font; font.setPointSize(n); setFont(font); connect(ButtonESC, SIGNAL(pressed()), this, SLOT(goExit())); connect(ButtonHilfe, SIGNAL(pressed()), this, SLOT(goHilfe())); connect(ButtonRigList, SIGNAL(pressed()), this, SLOT(showRigList())); connect(ButtonInit, SIGNAL(pressed()), this, SLOT(hamlibServerInit())); connect(ButtonStart, SIGNAL(pressed()), this, SLOT(goStart())); connect(ButtonStop, SIGNAL(pressed()), this, SLOT(goStop())); connect(buttonReturn, SIGNAL(pressed()), this, SLOT(showRigPage())); connect(InterfaceBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(intefaceBoxChanged(QString))); connect(wrigList, SIGNAL(itemClicked(QTreeWidgetItem *,int)), this, SLOT(itemClickedCb(QTreeWidgetItem *,int))); tcpSocket = new QTcpSocket(this); // tspSocket connect(tcpSocket, SIGNAL(connected()), this, SLOT(sentCommand())); connect(tcpSocket, SIGNAL(readyRead()), this, SLOT(readRigReply())); connect(tcpSocket, SIGNAL(error(QAbstractSocket::SocketError)), this, SLOT(displayError(QAbstractSocket::SocketError))); QString home = getenv("HOME"); // lade alle devices s = "ls /dev/ttyS* > "+home+"/.qtlog/rigstatus"; i = system(s.toAscii()); // suche device ttyS0 .. n home += "/.qtlog/rigstatus"; // prüfe rigstatus QFile iniFile(home); iniFile.open(QIODevice::ReadOnly); QTextStream istream( &iniFile); // lese device_file RigDevBox->clear(); PttBitDevBox->clear(); i = 0; while(istream.atEnd() != true) { // RigBox_dev füllen s = istream.readLine(0); RigDevBox->insertItem(i,s); PttBitDevBox->insertItem(i++,s); } iniFile.close(); home = getenv("HOME"); s = "ls /dev/ttyU* > "+home+"/.qtlog/rigstatus"; n = system(s.toAscii()); // suche device ttyUSB0 .. n home += "/.qtlog/rigstatus"; QFile inuFile(home); inuFile.open(QIODevice::ReadOnly); QTextStream iustream( &inuFile); // oeffne device_file while(iustream.atEnd() != true) { s = iustream.readLine(0); RigDevBox->insertItem(i,s); // alle vorhndenen USB0 .. n devices übenehmen PttBitDevBox->insertItem(i++,s); } inuFile.close(); Retry = 0; Runing = 0; r = 0; Runing = -1; i = getRigModell(); // lade alle Rig_Modelle if(i != 0) { // falls hamlib installiert ist - lade Rig_Modelle if(settings.value("RigPid").toString().count() != 0) { // und Rig configuriert wurde QSqlQuery query; // hole config_parameter_discriptor qy = "SELECT * FROM wproz WHERE rigpid='"+settings.value("RigPid").toString()+"'"; query.exec(qy); while(query.next()) { proz = query.value(r++).toString(); // proz owner = query.value(r++).toString(); // owner editRig->setText(query.value(r++).toString()); // Rig editPid->setText(query.value(r++).toString()); // Pid editRetry->setText(query.value(r++).toString()); // retry Retry = editRetry->text().toInt(); i = RigDevBox->findText(query.value(r++).toString()); RigDevBox->setCurrentIndex(i); // Rig_device_Box i = BaudBox->findText(query.value(r++).toString()); BaudBox->setCurrentIndex(i); // Baud_device_box // - i = InterfaceBox->findText(query.value(r++).toString()); // FAM_Interface ONE InterfaceBox->setCurrentIndex(i); i = PttBitDevBox->findText(query.value(r++).toString()); PttBitDevBox->setCurrentIndex(i); // PTT_device_Box editRts->setText(query.value(r++).toString()); // RTS = OFF editDtr->setText(query.value(r++).toString()); // DTR = OFF editCts->setText(query.value(r++).toString()); // CTS = OFF // - if(InterfaceBox->currentText().compare("NO") == 0) { PttBitDevBox->setEnabled(FALSE); editRts->setEnabled(FALSE); editDtr->setEnabled(FALSE); editCts->setEnabled(FALSE); } editHost->setText(query.value(r++).toString()); // localhost editPort->setText(query.value(r++).toString()); // port Runing = query.value(r).toInt(); // runing_bit } } updateFlg = 0; // alles ok if( Runing == -1 ) ButtonInit->setPalette( QPalette(QColor(180, 210, 200))); // grün else if( Runing ) ButtonStop->setPalette( QPalette(QColor(180, 210, 200))); // STOP grün else ButtonStart->setPalette( QPalette(QColor(180, 210, 200))); // grün } else QTimer::singleShot(10, this, SLOT(hlibNoInstalled())); // Hamlib nicht installiert }