mirror of
https://github.com/thunderbug1/Spherebot-Host-GUI.git
synced 2026-03-12 21:06:48 +01:00
ported the state machine to a QStateMachine
and enhanced the communication and removed txthread
This commit is contained in:
@@ -15,25 +15,23 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
ui->graphicsView->setScene(scene);
|
||||
////////////////////////////////////////////////////
|
||||
|
||||
sendState = Idle;
|
||||
this->bot = new spherebot();
|
||||
Receiver = new rxThread(this->bot);
|
||||
Transceiver = new txThread(this->bot);
|
||||
|
||||
penDownAngle = DEFAULTPENDOWN;
|
||||
penUpAngle = DEFAULTPENUP;
|
||||
|
||||
layerIndex = 0;
|
||||
|
||||
connect( this->bot, SIGNAL(dataSent(QString)),this, SLOT(sendDataUI(QString)));
|
||||
connect(Transceiver,SIGNAL(progressChanged(int)),this, SLOT(refreshSendProgress(int)));
|
||||
connect(Transceiver,SIGNAL(fileTransmitted()),this, SLOT(finishedTransmission()));
|
||||
connect(this->bot, SIGNAL(dataSent(QString)),this, SLOT(interpretSentString(QString)));
|
||||
connect(Transceiver,SIGNAL(layerTransmitted()),this, SLOT(finishedLayer()));
|
||||
connect(bot->port, SIGNAL(readyRead()), Receiver, SLOT(receiveData()));
|
||||
connect(bot, SIGNAL(dataSent(QString)),this, SLOT(sendDataUI(QString)));
|
||||
connect(bot, SIGNAL(progressChanged(int)),this, SLOT(refreshSendProgress(int)));
|
||||
//connect(bot, SIGNAL(fileTransmitted()),this, SLOT(finishedTransmission()));
|
||||
connect(Receiver, SIGNAL(lineReceived(QString)),this, SLOT(processReceivedData(QString)));
|
||||
connect(Receiver, SIGNAL(lineReceived(QString)),this->bot, SLOT(processAnswer(QString)));
|
||||
connect(Receiver, SIGNAL(lineReceived(QString)),this->bot, SLOT(processAnswer(QString)));
|
||||
|
||||
initUI();
|
||||
initSateMachine();
|
||||
|
||||
if(LoadSettings())
|
||||
{
|
||||
@@ -43,7 +41,10 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
FitInTimer.start();
|
||||
}
|
||||
|
||||
setWindowTitle("Spherebot Controll");
|
||||
|
||||
qDebug()<<"mainwindow initialised: ";
|
||||
connect(restartLayerMsgBox,SIGNAL(accepted()),this,SLOT(hey()));
|
||||
}
|
||||
|
||||
void MainWindow::fitgraphicsView() ////function to trigger the fitIn function for the graphics view. Actually this shouldn´t be necessary!
|
||||
@@ -55,23 +56,264 @@ void MainWindow::fitgraphicsView() ////function to trigger the fitIn functi
|
||||
qDebug()<<"fit in";
|
||||
}
|
||||
|
||||
void MainWindow::entry_connected()
|
||||
{
|
||||
qDebug() << " run connected1"<<endl;
|
||||
if(bot->connectWithBot(ui->portBox->currentText()))
|
||||
{
|
||||
//successfully connected
|
||||
qDebug() << " run connected2"<<endl;
|
||||
Receiver->run();
|
||||
ui->connectButton->setChecked(true);
|
||||
ui->controllBox->setEnabled(true);
|
||||
ui->portBox->setEnabled(false);
|
||||
ui->resetButton->setEnabled(false);
|
||||
ui->connectButton->setText("Disconnect");
|
||||
if(!ui->fileTextEdit->toPlainText().isEmpty()) ui->sendFileButton->setEnabled(true);
|
||||
statusBar()->showMessage(tr("Successfully connected to bot!"),4000);
|
||||
}
|
||||
else
|
||||
{
|
||||
statusBar()->showMessage(tr("Could not connect to bot!"),4000);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::entry_disconnected()
|
||||
{
|
||||
//disconnect
|
||||
bot->disconnectWithBot();
|
||||
ui->connectButton->setChecked(false);
|
||||
ui->connectButton->setText("Connect");
|
||||
ui->loadFileButton->setText("Load File");
|
||||
ui->sendFileButton->setText("Send File");
|
||||
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->portBox->setEnabled(true);
|
||||
ui->sendFileButton->setEnabled(false);
|
||||
ui->loadFileButton->setEnabled(false);
|
||||
ui->restartButton->setEnabled(false);
|
||||
ui->resetButton->setEnabled(true);
|
||||
|
||||
Receiver->exit();
|
||||
|
||||
ui->eggSlider->setValue(0);
|
||||
ui->diameterSlider->setValue(DEFAULTDIAMETER);
|
||||
ui->penSlider->setValue(0);
|
||||
ui->servoSlider->setValue(DEFAULTPENUP);
|
||||
ui->FeedratespinBox->setValue(DEFAULTFEEDRATE);
|
||||
ui->fileSendProgressBar->setValue(0);
|
||||
}
|
||||
|
||||
void MainWindow::entry_transmitting()
|
||||
{
|
||||
qDebug()<< "entry_transmitting"<< endl;
|
||||
ui->loadFileButton->setText("Abort"); //used as Abort button
|
||||
ui->fileSendProgressBar->setEnabled(true);
|
||||
ui->restartButton->setEnabled(true);
|
||||
ui->loadFileButton->setEnabled(true); //=abort button
|
||||
}
|
||||
|
||||
void MainWindow::entry_sending() //substate of transmitting
|
||||
{
|
||||
qDebug()<< "entry sending"<< endl;
|
||||
connect(this->bot, SIGNAL(dataSent(QString)),this, SLOT(interpretSentString(QString)));
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->sendFileButton->setText("Stop");
|
||||
bot->sendingFile = true;
|
||||
statusBar()->showMessage(tr("Sending File"));
|
||||
}
|
||||
|
||||
void MainWindow::entry_start_sending() //substate of transmitting
|
||||
{
|
||||
qDebug()<< "entry_start_sending"<< endl;
|
||||
bot->resetState();
|
||||
bot->set(ui->fileTextEdit->toPlainText());
|
||||
bot->sendNext();
|
||||
}
|
||||
|
||||
void MainWindow::leave_sending() //substate of transmitting
|
||||
{
|
||||
qDebug()<< "leave sending"<< endl;
|
||||
disconnect(this->bot,SIGNAL(dataSent(QString)),this,SLOT(interpretSentString(QString)));
|
||||
bot->sendingFile = false;
|
||||
}
|
||||
|
||||
void MainWindow::entry_stopped() //substate of transmitting
|
||||
{
|
||||
qDebug()<< "entry_stopped"<< endl;
|
||||
ui->sendFileButton->setText("Continue");
|
||||
statusBar()->showMessage(tr("Stoped sending File"));
|
||||
}
|
||||
|
||||
void MainWindow::entry_idle()
|
||||
{
|
||||
qDebug()<< "entry_idle"<< endl;
|
||||
ui->fileSendProgressBar->setValue(0);
|
||||
ui->sendFileButton->setText("Send File");
|
||||
ui->loadFileButton->setText("Load File");
|
||||
|
||||
ui->controllBox->setEnabled(true);
|
||||
ui->restartButton->setEnabled(false);
|
||||
ui->loadFileButton->setEnabled(true);
|
||||
ui->fileSendProgressBar->setEnabled(false);
|
||||
|
||||
bot->send("M 18"); //disable motors
|
||||
}
|
||||
|
||||
void MainWindow::entry_abort()
|
||||
{
|
||||
qDebug()<< "entry_abort"<< endl;
|
||||
}
|
||||
|
||||
void MainWindow::entry_restart()
|
||||
{
|
||||
qDebug()<< "entry restart"<< endl;
|
||||
layerIndex = 0;
|
||||
}
|
||||
|
||||
void MainWindow::entry_ask_for_restart()
|
||||
{
|
||||
qDebug()<< "entry_ask_for_restart"<< endl;
|
||||
statusBar()->showMessage(tr("File successfully sent"));
|
||||
SetBotToHomePosition();
|
||||
if(restartLayerMsgBox->exec() == QMessageBox::Ok) //workaround cause the signals don´t fire
|
||||
emit restartLayerMsgBox->accept();
|
||||
else
|
||||
emit restartLayerMsgBox->reject();
|
||||
}
|
||||
|
||||
void MainWindow::entry_ask_for_next_layer()
|
||||
{
|
||||
qDebug()<< "entry_ask_for_next_layer"<< endl;
|
||||
if(layerNames.size() > 1) layerIndex++;
|
||||
|
||||
qDebug()<<"layerIndex: "<<layerIndex;
|
||||
qDebug()<<"layerNames: "<<layerNames;
|
||||
qDebug()<<"layerNames.size(): "<<layerNames.size();
|
||||
if(layerIndex < layerNames.size()) //next layer
|
||||
{
|
||||
nextLayerMsgBox->setText("Please change the tool for layer: " + layerNames[layerIndex]);
|
||||
SetBotToHomePosition();
|
||||
nextLayerMsgBox->exec();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::entry_load_file_dialog()
|
||||
{
|
||||
QString fileName;
|
||||
if(!curDir.absolutePath().isEmpty())
|
||||
{
|
||||
fileName = QFileDialog::getOpenFileName(this,"",curDir.absolutePath());
|
||||
ui->saveFileButton->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileName = QFileDialog::getOpenFileName(this);
|
||||
}
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
loadFile(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::initSateMachine()
|
||||
{
|
||||
connected = new QState();
|
||||
disconnected = new QState();
|
||||
|
||||
transmitting = new QState(connected); //transmitting means sending or stopped
|
||||
sending = new QState(transmitting);
|
||||
stopped = new QState(transmitting);
|
||||
|
||||
idle = new QState(connected);
|
||||
abort = new QState(connected);
|
||||
ask_for_restart = new QState(connected);
|
||||
restart = new QState(connected);
|
||||
ask_for_next_layer=new QState(connected);
|
||||
load_file_dialog = new QState(connected);
|
||||
start_sending = new QState(connected);
|
||||
|
||||
/////////////////////////////////////////////////// Transitions
|
||||
|
||||
connected->addTransition(ui->connectButton, SIGNAL(clicked()),disconnected);
|
||||
disconnected->addTransition(ui->connectButton, SIGNAL(clicked()),connected);
|
||||
|
||||
connected->setInitialState(idle);
|
||||
|
||||
idle->addTransition(ui->sendFileButton,SIGNAL(clicked()),start_sending);
|
||||
idle->addTransition(ui->loadFileButton,SIGNAL(clicked()),load_file_dialog);
|
||||
|
||||
transmitting->addTransition(ui->loadFileButton, SIGNAL(clicked()),abort);
|
||||
transmitting->addTransition(ui->restartButton, SIGNAL(clicked()),restart);
|
||||
//
|
||||
sending->addTransition(ui->sendFileButton,SIGNAL(clicked()),stopped);
|
||||
sending->addTransition(this->bot, SIGNAL(fileTransmitted()),ask_for_restart);
|
||||
sending->addTransition(this->bot, SIGNAL(layerTransmitted()),ask_for_next_layer);
|
||||
|
||||
stopped->addTransition(ui->sendFileButton,SIGNAL(clicked()),start_sending);
|
||||
//
|
||||
start_sending->addTransition(start_sending,SIGNAL(entered()),sending);
|
||||
|
||||
ask_for_restart->addTransition(restartLayerMsgBox,SIGNAL(accepted()),restart);
|
||||
ask_for_restart->addTransition(restartLayerMsgBox,SIGNAL(rejected()),idle);
|
||||
connect(ask_for_restart,SIGNAL(exited()),this,SLOT(hey()));
|
||||
|
||||
ask_for_next_layer->addTransition(nextLayerMsgBox,SIGNAL(accepted()),sending);
|
||||
|
||||
load_file_dialog->addTransition(load_file_dialog,SIGNAL(entered()),idle);
|
||||
|
||||
abort->addTransition(abort,SIGNAL(entered()),idle);
|
||||
|
||||
restart->addTransition(restart,SIGNAL(entered()),start_sending);
|
||||
|
||||
/////////////////////////////////////////////////// Functions executed in states
|
||||
|
||||
connect(connected, SIGNAL(entered()),this,SLOT(entry_connected()));
|
||||
connect(disconnected, SIGNAL(entered()),this,SLOT(entry_disconnected()));
|
||||
connect(transmitting, SIGNAL(entered()),this,SLOT(entry_transmitting()));
|
||||
connect(idle, SIGNAL(entered()),this,SLOT(entry_idle()));
|
||||
connect(sending, SIGNAL(entered()),this,SLOT(entry_sending()));
|
||||
connect(start_sending, SIGNAL(entered()),this,SLOT(entry_start_sending()));
|
||||
connect(stopped, SIGNAL(entered()),this,SLOT(entry_stopped()));
|
||||
connect(restart, SIGNAL(entered()),this,SLOT(entry_restart()));
|
||||
connect(ask_for_restart,SIGNAL(entered()),this,SLOT(entry_ask_for_restart()));
|
||||
connect(ask_for_next_layer,SIGNAL(entered()),this,SLOT(entry_ask_for_next_layer()));
|
||||
connect(load_file_dialog,SIGNAL(entered()),this,SLOT(entry_load_file_dialog()));
|
||||
|
||||
connect(sending, SIGNAL(exited()), this,SLOT(leave_sending()));
|
||||
|
||||
///////////////////////////////////////////////////
|
||||
|
||||
machine.addState(connected);
|
||||
machine.addState(disconnected);
|
||||
|
||||
machine.setInitialState(disconnected);
|
||||
machine.start();
|
||||
}
|
||||
|
||||
void MainWindow::initUI()
|
||||
{
|
||||
nextLayerMsgBox = new QMessageBox(QMessageBox::Information,
|
||||
"Next Layer",
|
||||
"The Layer has been finished!\nplease insert the tool for the layer: " + QString::number(layerIndex),
|
||||
QMessageBox::Yes|QMessageBox::No);
|
||||
nextLayerMsgBox->setButtonText(QMessageBox::Yes,"OK");
|
||||
QMessageBox::Ok|QMessageBox::No);
|
||||
nextLayerMsgBox->setButtonText(QMessageBox::Ok,"OK");
|
||||
nextLayerMsgBox->setButtonText(QMessageBox::No,"Abort");
|
||||
|
||||
restartLayerMsgBox = new QMessageBox(QMessageBox::Information,
|
||||
"Restart?",
|
||||
"Do you want to restart the print?",
|
||||
QMessageBox::Yes|QMessageBox::No);
|
||||
//restartLayerMsgBox->setButtonText(QMessageBox::Yes,"OK");
|
||||
//restartLayerMsgBox->setButtonText(QMessageBox::No,"No");
|
||||
QMessageBox::Ok|QMessageBox::No);
|
||||
|
||||
connect(ui->undoButton,SIGNAL(clicked()),ui->fileTextEdit,SLOT(undo()));
|
||||
connect(ui->redoButton,SIGNAL(clicked()),ui->fileTextEdit,SLOT(redo()));
|
||||
|
||||
connect(ui->fileTextEdit,SIGNAL(undoAvailable(bool)),ui->saveFileButton,SLOT(setEnabled(bool)));
|
||||
connect(ui->fileTextEdit,SIGNAL(undoAvailable(bool)),ui->undoButton,SLOT(setEnabled(bool)));
|
||||
connect(ui->fileTextEdit,SIGNAL(redoAvailable(bool)),ui->redoButton,SLOT(setEnabled(bool)));
|
||||
|
||||
connect(ui->eggSlider,SIGNAL(valueChanged(int)),ui->eggRotationBox,SLOT(setValue(int)));
|
||||
connect(ui->penSlider,SIGNAL(valueChanged(int)),ui->penRotationBox,SLOT(setValue(int)));
|
||||
|
||||
//ui->baudBox->setEnabled(true);
|
||||
|
||||
@@ -112,9 +354,7 @@ bool MainWindow::LoadSettings()
|
||||
if(QString::compare(portList.at(i).portName(),SavedPortName) == 0)
|
||||
{
|
||||
ui->portBox->setCurrentIndex(i);
|
||||
bot->port->setPortName(SavedPortName);
|
||||
on_connectButton_clicked();
|
||||
ui->sendButton->setEnabled(true);
|
||||
bot->connectWithBot(SavedPortName);
|
||||
}
|
||||
}
|
||||
settings.endGroup();
|
||||
@@ -270,142 +510,47 @@ void MainWindow::refreshSendProgress(int value)
|
||||
ui->fileSendProgressBar->setValue(value);
|
||||
}
|
||||
|
||||
void MainWindow::finishedLayer()
|
||||
{
|
||||
if(layerNames.size() > 1)
|
||||
{
|
||||
layerIndex++;
|
||||
}
|
||||
qDebug()<<"layerIndex: "<<layerIndex;
|
||||
qDebug()<<"layerNames: "<<layerNames;
|
||||
qDebug()<<"layerNames.size(): "<<layerNames.size();
|
||||
if(layerIndex < layerNames.size()) //next layer
|
||||
{
|
||||
nextLayerMsgBox->setText("Please change the tool for layer: " + layerNames[layerIndex]);
|
||||
SetBotToHomePosition();
|
||||
switch(nextLayerMsgBox->exec())
|
||||
{
|
||||
case(QMessageBox::No):
|
||||
setState(Idle); //abort
|
||||
break;
|
||||
case(QMessageBox::Yes):
|
||||
break;
|
||||
default:
|
||||
setState(Idle); //abort
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::finishedTransmission()
|
||||
{
|
||||
disconnectTranceiver();
|
||||
this->Transceiver->resetState();
|
||||
ui->sendFileButton->setText("Send File");
|
||||
ui->loadFileButton->setText("Load File");
|
||||
ui->controllBox->setEnabled(true);
|
||||
ui->resetButton->setEnabled(false);
|
||||
ui->fileSendProgressBar->setValue(0);
|
||||
ui->fileSendProgressBar->setEnabled(false);
|
||||
ui->loadFileButton->setEnabled(true);
|
||||
statusBar()->showMessage(tr("File successfully sent"));
|
||||
sendState = Idle;
|
||||
layerIndex = 0;
|
||||
SetBotToHomePosition();
|
||||
if (QMessageBox::Yes == restartLayerMsgBox->exec())
|
||||
{
|
||||
on_sendFileButton_clicked();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::interpretSentString(QString string)
|
||||
{
|
||||
if(this->sendState == 1) //if currently sending
|
||||
QStringList list = string.split(" ");
|
||||
//qDebug()<<"string is : "<<string;
|
||||
for(int i = 0;i<list.size();i++)
|
||||
{
|
||||
QStringList list = string.split(" ");
|
||||
//qDebug()<<"string is : "<<string;
|
||||
for(int i = 0;i<list.size();i++)
|
||||
if(!list[i].isEmpty())
|
||||
{
|
||||
if(!list[i].isEmpty())
|
||||
if (list[i].startsWith('X'))
|
||||
{
|
||||
if (list[i].startsWith('X'))
|
||||
//qDebug()<<"setting eggslidervalue: ";
|
||||
ui->eggSlider->setValue(list[i].remove(0,1).toDouble());
|
||||
}
|
||||
else if (list[i].startsWith('Y'))
|
||||
{
|
||||
//qDebug()<<"setting penslidervalue";
|
||||
ui->penSlider->setValue(list[i].remove(0,1).toDouble());
|
||||
}
|
||||
else if (list[i].startsWith('M'))
|
||||
{
|
||||
if(list[i].remove(0,1) == "300")
|
||||
{
|
||||
//qDebug()<<"setting eggslidervalue: ";
|
||||
ui->eggSlider->setValue(list[i].remove(0,1).toDouble());
|
||||
//qDebug()<<"setting servoSlider";
|
||||
ui->servoSlider->setValue(list[i+1].remove(0,1).toDouble());
|
||||
}
|
||||
else if (list[i].startsWith('Y'))
|
||||
else if(list[i].remove(0,1) == "400")
|
||||
{
|
||||
//qDebug()<<"setting penslidervalue";
|
||||
ui->penSlider->setValue(list[i].remove(0,1).toDouble());
|
||||
}
|
||||
else if (list[i].startsWith('M'))
|
||||
{
|
||||
if(list[i].remove(0,1) == "300")
|
||||
{
|
||||
//qDebug()<<"setting servoSlider";
|
||||
ui->servoSlider->setValue(list[i+1].remove(0,1).toDouble());
|
||||
}
|
||||
else if(list[i].remove(0,1) == "400")
|
||||
{
|
||||
// qDebug()<<"setting diameterSlider";
|
||||
ui->diameterSlider->setValue(list[i+1].remove(0,1).toDouble());
|
||||
}
|
||||
}
|
||||
else if (list[i].startsWith('F'))
|
||||
{
|
||||
//qDebug()<<"setting servoFeedrateSlider";
|
||||
ui->servoFeedrateSlider->setValue(list[i].remove(0,1).toDouble());
|
||||
// qDebug()<<"setting diameterSlider";
|
||||
ui->diameterSlider->setValue(list[i+1].remove(0,1).toDouble());
|
||||
}
|
||||
}
|
||||
else if (list[i].startsWith('F'))
|
||||
{
|
||||
//qDebug()<<"setting servoFeedrateSlider";
|
||||
ui->servoFeedrateSlider->setValue(list[i].remove(0,1).toDouble());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
void MainWindow::on_connectButton_clicked()
|
||||
{
|
||||
if(bot->isConnected())
|
||||
{
|
||||
//disconnect
|
||||
bot->disconnectWithBot();
|
||||
ui->connectButton->setChecked(false);
|
||||
ui->connectButton->setText("Connect");
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->resetButton->setEnabled(true);
|
||||
ui->portBox->setEnabled(true);
|
||||
ui->sendFileButton->setEnabled(false);
|
||||
ui->eggSlider->setValue(0);
|
||||
ui->diameterSlider->setValue(DEFAULTDIAMETER);
|
||||
ui->penSlider->setValue(0);
|
||||
ui->servoSlider->setValue(DEFAULTPENUP);
|
||||
ui->FeedratespinBox->setValue(DEFAULTFEEDRATE);
|
||||
ui->fileSendProgressBar->setValue(0);
|
||||
sendState = Idle;
|
||||
ui->sendFileButton->setText("Send File");
|
||||
ui->sendFileButton->setEnabled(false);
|
||||
ui->restartButton->setEnabled(false);
|
||||
Receiver->exit();
|
||||
}
|
||||
else if(bot->connectWithBot(ui->portBox->currentText()))
|
||||
{
|
||||
//successfully connected
|
||||
Receiver->run();
|
||||
connect( this->bot->port, SIGNAL(readyRead()), Receiver, SLOT(receiveData()));
|
||||
ui->connectButton->setChecked(true);
|
||||
ui->controllBox->setEnabled(true);
|
||||
ui->portBox->setEnabled(false);
|
||||
ui->resetButton->setEnabled(false);
|
||||
ui->connectButton->setText("Disconnect");
|
||||
ui->loadFileButton->setText("Load File");
|
||||
if(!ui->fileTextEdit->toPlainText().isEmpty()) ui->sendFileButton->setEnabled(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::resetPortList()
|
||||
{
|
||||
QSerialPortInfo info;
|
||||
@@ -453,85 +598,27 @@ void MainWindow::on_sendButton_clicked()
|
||||
|
||||
void MainWindow::on_servoSlider_sliderMoved(int position)
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
QString tmp = ("M300 S" + QString::number(position));
|
||||
bot->send(tmp);
|
||||
}
|
||||
bot->send("M300 S" + QString::number(position));
|
||||
}
|
||||
|
||||
void MainWindow::on_servospinBox_valueChanged(int arg1)
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
ui->servoSlider->setValue(arg1);
|
||||
QString tmp = ("M300 S" + QString::number(arg1));
|
||||
bot->send(tmp);
|
||||
}
|
||||
ui->servoSlider->setValue(arg1);
|
||||
bot->send("M300 S" + QString::number(arg1));
|
||||
}
|
||||
|
||||
void MainWindow::on_penRotationBox_valueChanged(int arg1)
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
QString tmp = ("G1 Y" + QString::number((double)arg1));
|
||||
bot->send(tmp);
|
||||
ui->penSlider->setValue(arg1);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_penSlider_valueChanged(int value)
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
ui->penRotationBox->setValue(value);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_eggSlider_valueChanged(int value)
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
ui->eggRotationBox->setValue(value);
|
||||
}
|
||||
bot->send("G1 Y" + QString::number((double)arg1));
|
||||
ui->penSlider->setValue(arg1);
|
||||
}
|
||||
|
||||
void MainWindow::on_eggRotationBox_valueChanged(int arg1)
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
QString tmp = ("G1 X" + QString::number((double)arg1));
|
||||
bot->send(tmp);
|
||||
ui->eggSlider->setValue(arg1);
|
||||
}
|
||||
bot->send("G1 X" + QString::number((double)arg1));
|
||||
ui->eggSlider->setValue(arg1);
|
||||
}
|
||||
|
||||
void MainWindow::on_loadFileButton_clicked() //== Abort Button
|
||||
{
|
||||
if(sendState == Idle)
|
||||
{
|
||||
QString fileName;
|
||||
if(!curDir.absolutePath().isEmpty())
|
||||
{
|
||||
fileName = QFileDialog::getOpenFileName(this,"",curDir.absolutePath());
|
||||
ui->saveFileButton->setEnabled(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
fileName = QFileDialog::getOpenFileName(this);
|
||||
}
|
||||
if (!fileName.isEmpty())
|
||||
{
|
||||
loadFile(fileName);
|
||||
}
|
||||
}
|
||||
else //abort print
|
||||
{
|
||||
setState(Idle);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::on_saveFileButton_clicked()
|
||||
{
|
||||
saveFile(curFile);
|
||||
@@ -542,159 +629,12 @@ void MainWindow::on_fileTextEdit_textChanged()
|
||||
{
|
||||
if(!ui->fileTextEdit->toPlainText().isEmpty())
|
||||
{
|
||||
setWindowTitle("Spherebot Controll");
|
||||
ui->fileName->setText("");
|
||||
if(bot->isConnected()) ui->sendFileButton->setEnabled(true);
|
||||
else ui->sendButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::connectTranceiver()
|
||||
{
|
||||
connect(this->bot,SIGNAL(dataSent(QString)),Transceiver,SLOT(sendNext()));
|
||||
}
|
||||
|
||||
void MainWindow::disconnectTranceiver()
|
||||
{
|
||||
disconnect(this->bot,SIGNAL(dataSent(QString)),Transceiver,SLOT(sendNext()));
|
||||
}
|
||||
|
||||
void MainWindow::setState(MainWindow::SendStates state)
|
||||
{
|
||||
switch(state)
|
||||
{
|
||||
case(Idle):
|
||||
switch(sendState)
|
||||
{
|
||||
case(Sending): //from Sending to Idle == abort the print
|
||||
//same code as below
|
||||
ui->fileSendProgressBar->setValue(0);
|
||||
ui->sendString->setEnabled(true);
|
||||
if(bot->isConnected()){
|
||||
ui->sendFileButton->setText("Send File");
|
||||
ui->restartButton->setEnabled(true);
|
||||
}
|
||||
else{
|
||||
ui->restartButton->setEnabled(false);
|
||||
}
|
||||
ui->loadFileButton->setText("Load File");
|
||||
ui->loadFileButton->setEnabled(true);
|
||||
bot->send("M 18"); //disable motors
|
||||
case(Stoped): //from Stoped to Idle
|
||||
disconnectTranceiver();
|
||||
this->Transceiver->resetState();
|
||||
ui->sendFileButton->setText("Send File");
|
||||
ui->loadFileButton->setText("Load File");
|
||||
ui->restartButton->setEnabled(false);
|
||||
ui->controllBox->setEnabled(true);
|
||||
ui->fileSendProgressBar->setEnabled(false);
|
||||
ui->loadFileButton->setEnabled(true);
|
||||
sendState = Idle;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(Sending):
|
||||
switch(sendState)
|
||||
{
|
||||
case(Idle): //start sending //from Idle to Sending
|
||||
sendState = Sending;
|
||||
connectTranceiver();
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->fileSendProgressBar->setEnabled(true);
|
||||
ui->sendFileButton->setText("Stop");
|
||||
ui->restartButton->setEnabled(true);
|
||||
ui->loadFileButton->setText("Abort");
|
||||
ui->loadFileButton->setEnabled(true);
|
||||
ui->sendString->setEnabled(false);
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->sendButton->setEnabled(false);
|
||||
ui->sendString->setEnabled(false);
|
||||
Transceiver->set(ui->fileTextEdit->toPlainText());
|
||||
Transceiver->run();
|
||||
statusBar()->showMessage(tr("Sending File"));
|
||||
break;
|
||||
case(Stoped): //continue
|
||||
sendState = Sending;
|
||||
connectTranceiver();
|
||||
#ifdef Watchdog
|
||||
Transceiver.watchdogTimer->start();
|
||||
#endif
|
||||
this->Transceiver->sendNext();
|
||||
ui->loadFileButton->setEnabled(false);
|
||||
ui->resetButton->setEnabled(true);
|
||||
ui->loadFileButton->setText("Abort");
|
||||
ui->loadFileButton->setEnabled(true);
|
||||
ui->sendFileButton->setText("Stop");
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->sendButton->setEnabled(false);
|
||||
ui->sendString->setEnabled(false);
|
||||
statusBar()->showMessage(tr("Sending File"));
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case(Stoped):
|
||||
switch(sendState)
|
||||
{
|
||||
case(Idle):
|
||||
|
||||
break;
|
||||
case(Sending): //from Sending to Stoped
|
||||
sendState = Stoped;
|
||||
disconnectTranceiver();
|
||||
ui->restartButton->setEnabled(true);
|
||||
ui->sendFileButton->setText("Continue");
|
||||
ui->loadFileButton->setText("Abort"); //used as Abort button
|
||||
ui->loadFileButton->setEnabled(true);
|
||||
ui->controllBox->setEnabled(true);
|
||||
ui->sendButton->setEnabled(true);
|
||||
ui->sendString->setEnabled(true);
|
||||
statusBar()->showMessage(tr("Stoped sending File"));
|
||||
//vScrollBar->setSliderPosition(Transceiver.getLineCounter());
|
||||
//ui->fileTextEdit->setVerticalScrollBar();
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
qDebug()<<"state: "<<state;
|
||||
}
|
||||
|
||||
void MainWindow::on_sendFileButton_clicked()
|
||||
{
|
||||
// QScrollBar *vScrollBar = ui->fileTextEdit->verticalScrollBar();
|
||||
switch(sendState)
|
||||
{
|
||||
case 0: //start to send
|
||||
qDebug()<<"start sending";
|
||||
setState(Sending);
|
||||
break;
|
||||
case 1: //stop the print
|
||||
qDebug()<< "You have stoped sending";
|
||||
setState(Stoped);
|
||||
break;
|
||||
case 2: //continue
|
||||
setState(Sending);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_restartButton_clicked()
|
||||
{
|
||||
sendState = Sending;
|
||||
Transceiver->set(ui->fileTextEdit->toPlainText());
|
||||
connectTranceiver();
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->fileSendProgressBar->setEnabled(true);
|
||||
ui->sendFileButton->setText("Stop");
|
||||
ui->loadFileButton->setText("Load File");
|
||||
ui->controllBox->setEnabled(false);
|
||||
ui->sendButton->setEnabled(false);
|
||||
ui->sendString->setEnabled(false);
|
||||
ui->loadFileButton->setEnabled(false);
|
||||
Transceiver->set(ui->fileTextEdit->toPlainText());
|
||||
Transceiver->run();
|
||||
statusBar()->showMessage(tr("Sending File"));
|
||||
}
|
||||
|
||||
void MainWindow::SetBotToHomePosition()
|
||||
{
|
||||
QString tmp = ("G1 Y0");
|
||||
@@ -706,46 +646,13 @@ void MainWindow::SetBotToHomePosition()
|
||||
|
||||
void MainWindow::on_servoFeedrateSlider_valueChanged(int value)
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
QString tmp = ("G1 F" + QString::number(value));
|
||||
bot->send(tmp);
|
||||
}
|
||||
bot->send("G1 F" + QString::number(value));
|
||||
}
|
||||
|
||||
void MainWindow::on_setDiameterButton_clicked()
|
||||
{
|
||||
if(sendState != Sending)
|
||||
{
|
||||
QString tmp = ("M400 S" + QString::number(ui->diameterSlider->value()));
|
||||
bot->send(tmp);
|
||||
tmp.clear();
|
||||
tmp = ("M401 S" + QString::number(ui->diameterSlider->value()));
|
||||
bot->send(tmp);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_undoButton_clicked()
|
||||
{
|
||||
ui->fileTextEdit->undo();
|
||||
}
|
||||
|
||||
void MainWindow::on_redoButton_clicked()
|
||||
{
|
||||
ui->fileTextEdit->redo();
|
||||
}
|
||||
|
||||
void MainWindow::on_fileTextEdit_undoAvailable(bool b)
|
||||
{
|
||||
ui->saveFileButton->setEnabled(true);
|
||||
if(b) ui->undoButton->setEnabled(true);
|
||||
else ui->undoButton->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::on_fileTextEdit_redoAvailable(bool b)
|
||||
{
|
||||
if(b) ui->redoButton->setEnabled(true);
|
||||
else ui->redoButton->setEnabled(false);
|
||||
bot->send("M400 S" + QString::number(ui->diameterSlider->value()));
|
||||
bot->send("M401 S" + QString::number(ui->diameterSlider->value()));
|
||||
}
|
||||
|
||||
void MainWindow::on_sendString_textChanged(const QString &arg1)
|
||||
@@ -759,8 +666,3 @@ void MainWindow::on_sendString_textChanged(const QString &arg1)
|
||||
ui->sendButton->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_baudBox_currentIndexChanged(int index)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user