void MainWindow::resetPortList()
{
    QSerialPortInfo info;
    portList = info.availablePorts();
    ui->portBox->clear();
    for(int i=0;i<portList.size();i++)
    {
        ui->portBox->addItem(portList[i].portName());
    }
}
bool MainWindow::LoadSettings()
{
    bool returnvalue = false;
    QSettings settings("thunderbug","SpherebotSettings");
    settings.beginGroup("settings");
    curFile = settings.value("fileName", "").toString();
    curDir = settings.value("currentDirectory", "").toString();
    qDebug() << "curdir"<< curDir<<endl;
    if(!curFile.isEmpty())
    {
        if(QFile::exists(curFile))
        {
            qDebug()<<"load last file.";
            loadFile(curFile);
            returnvalue = true;
        }
    }
    qDebug()<<"load: "<<curFile;
    QString SavedPortName = settings.value("PortName", "").toString();
    QSerialPortInfo info;
    portList = info.availablePorts();
    for(int i = 0; i < portList.size();i++)
    {
        if(QString::compare(portList.at(i).portName(),SavedPortName) == 0)
        {
            ui->portBox->setCurrentIndex(i);
            bot->connectWithBot(SavedPortName);
        }
    }
    settings.endGroup();
    qDebug()<<"settings loaded: ";
    return returnvalue;
}
Esempio n. 3
0
bool ProjectProperties::Edit(Project * project)
{
	if (project == NULL) {
		return false;
	}
	ok = false;	

	ui.stackedWidget->setCurrentIndex(0);
	ui.menuList->setCurrentRow(0);

	ui.lblName->setText("General options for project '" + project->name + "':");
	
	// set board names combobox
	ui.cbBoardName->clear();
	map <QString, BoardDef>::iterator board;
	for (board = config.boards.begin(); board != config.boards.end() ;board++) {
		ui.cbBoardName->addItem(board->first);
		if (board->first == project->boardName) {
			ui.cbBoardName->setCurrentIndex(ui.cbBoardName->count()-1);
		}
	}
	if (ui.cbBoardName->currentIndex() < 0) {
		if (ui.cbBoardName->count() > 0) {
			ui.cbBoardName->setCurrentIndex(0);
		}
	}	

	// get list of serial ports
	// to do: use QSerialPort

	ui.cbSerialPort->clear();
	ui.cbSerialPort->addItem("N/A");

	QSerialPortInfo serial;
	for (int i=0; i < serial.availablePorts().count();i++) {
		ui.cbSerialPort->addItem(serial.availablePorts().at(i).portName());
	}
	
	/*ui.cbSerialPort->addItem("COM 1");
	ui.cbSerialPort->addItem("COM 2");
	ui.cbSerialPort->addItem("COM 3");
	ui.cbSerialPort->addItem("COM 4");
	ui.cbSerialPort->addItem("COM 5");
	ui.cbSerialPort->addItem("COM 6");
	*/
	ui.cbSerialPort->setCurrentIndex(0);
	for (int i=0; i < ui.cbSerialPort->count(); i++) {
		if (project->serialPort == ui.cbSerialPort->itemText(i)) {
			ui.cbSerialPort->setCurrentIndex(i);
		}
	}

	// populate programmers list
	ui.cbExternalProgrammer->clear();
	map <QString, ProgrammerDef>::iterator prog;
	for (prog = config.programmers.begin(); prog != config.programmers.end(); prog++) {
		ui.cbExternalProgrammer->addItem(prog->first);
		if (prog->first == project->programmer) {
			ui.cbExternalProgrammer->setCurrentIndex(ui.cbExternalProgrammer->count()-1);
		}
	}
	if (ui.cbExternalProgrammer->currentIndex() < 0) {
		if (ui.cbExternalProgrammer->count() > 0) {
			ui.cbExternalProgrammer->setCurrentIndex(0);
		}
	}	

	if (project->programmer == "") {
		ui.rbNoExternalProgrammer->setChecked(true);
		ui.cbExternalProgrammer->setEnabled(false);
	} else {
		ui.rbYesExternalProgrammer->setChecked(true);
		ui.cbExternalProgrammer->setEnabled(true);
	}

	exec();

	if (ok == false) {
		return false;
	}

	project->serialPort = ui.cbSerialPort->itemText(ui.cbSerialPort->currentIndex());
	if (project->serialPort == "N/A") {
		project->serialPort = "";
	}

	if (ui.rbNoExternalProgrammer->isChecked()) {
		project->programmer = "";
	} else {
		project->programmer = ui.cbExternalProgrammer->itemText(ui.cbExternalProgrammer->currentIndex());
	}

	project->boardName = ui.cbBoardName->itemText(ui.cbBoardName->currentIndex());
	
	return true;
}
Esempio n. 4
0
QString Builder::GetLeonardoSerialPort(QString defaultPort)
{
    QStringList before, after;
    QSerialPortInfo serialList;
    QSerialPort port;

    SetPercentage(100);

    for (int i=0; i < serialList.availablePorts().count(); i++) {
        before.append(serialList.availablePorts().at(i).portName());
    }

    /*#ifdef Q_OS_WIN
       	PrepareSerialPort(project->serialPort, "1200");
    #endif*/
    port.setPortName(project->serialPort);
    port.setFlowControl(QSerialPort::NoFlowControl);
    port.setBaudRate(QSerialPort::Baud1200);
    port.setParity(QSerialPort::NoParity);
    port.setStopBits(QSerialPort::OneStop);
    port.setDataBits(QSerialPort::Data8);
    bool open = port.open (QIODevice::ReadWrite);
//#endif
    if (open == false) {
        progress->SetPhase(BuildWindowTypes::detectingLeonardo2);
        msg.Add("Could not reset board automatically via serial port " + project->serialPort + "! Press RESET button at your board NOW!", mtWarning);
    }
    /*char buffer[20] = "Hello!\r\n";
    port.write ((const char *)buffer);*/
    //QThread::msleep(10);
    port.close();

    QThread::msleep(100);

    int counter = 50;
    after.clear();
    bool warningMessage = true;
    while (counter > 0) {
        QSerialPortInfo newSerialList;
        for (int i=0; i < newSerialList.availablePorts().count(); i++) {
            after.append(newSerialList.availablePorts().at(i).portName());
        }

        for (int i=0; i < after.count(); i++) {
            if (before.indexOf(after.at(i)) < 0) {
                return after.at(i);
            }
        }
        QThread::msleep(120);
        counter--;

        if ( (progress->value() > 40) && warningMessage) {
            warningMessage = false;
            progress->SetPhase(BuildWindowTypes::detectingLeonardo2);
            msg.Add("Could not reset board automatically via serial port " + project->serialPort + "! Press RESET button at your board NOW!", mtWarning);
        }

        SetPercentage(100 - counter * 2);
        if (GetCancel()) {
            counter = 0;
            break;
        }
    }

    msg.Add("Could not detect Leonardo serial port for programming. Please try pressing the RESET button at your board when you see the dialog message 'Detecting Leonardo port...'!", mtError);
    return "";
}