diff --git a/Mainwindow.cpp b/Mainwindow.cpp index 7013133..6778b11 100644 --- a/Mainwindow.cpp +++ b/Mainwindow.cpp @@ -40,8 +40,7 @@ MainWindow::MainWindow(QWidget *parent) : ui->lineEdit_licksToReward->setValidator(intValidator); ui->lineEdit_iti->setValidator(doubleValidator); - - connect(this,SIGNAL(paused()), &smc, SIGNAL(pauseRequested())); + connect(&smc, SIGNAL(statusMessage(QString)), this, SLOT(onStatusMessage(QString))); } @@ -88,39 +87,30 @@ void MainWindow::on_pushButton_Run_clicked() } qDebug()<< settings.itiSequence; - - - - smc.runStateMachine(settings); + smc.startStateMachine(settings); } void MainWindow::on_pushButton_Pause_toggled(bool checked) { + smc.pauseStateMachine(); if (checked) { - qDebug() << "Paused"; ui->statusBar->showMessage("Paused"); ui->pushButton_Pause->setText("Resume"); - emit(paused()); - - } else { - qDebug() << "Resumed"; ui->statusBar->showMessage("Resumed"); ui->pushButton_Pause->setText("Pause"); - emit(resumed()); } - } void MainWindow::on_pushButton_Stop_clicked() { -// timerDialog->removeTimer(); -// mainTimer->stop(); -// stateMachine->stop(); + smc.stopStateMachine(); qDebug() << "Stopped and terminated"; ui->statusBar->showMessage("Stopped and terminated"); ui->pushButton_Run->setDisabled(false); - emit(stopped()); + ui->pushButton_Pause->setChecked(false); + ui->pushButton_Pause->setText("Pause"); + } @@ -223,6 +213,11 @@ void MainWindow::on_lineEdit_preImaq_editingFinished() updateIti(); } +void MainWindow::onStatusMessage(QString statusMessage) +{ + ui->statusBar->showMessage(statusMessage); +} + void MainWindow::updateIti() { double preImaq = ui->lineEdit_preImaq->text().toDouble(); diff --git a/Mainwindow.h b/Mainwindow.h index 6840c46..c3ff71d 100644 --- a/Mainwindow.h +++ b/Mainwindow.h @@ -43,6 +43,8 @@ private slots: void on_lineEdit_iti_editingFinished(); void on_lineEdit_preImaq_editingFinished(); + void onStatusMessage(QString statusMessage); + private: Ui::MainWindow *ui; @@ -61,12 +63,6 @@ private slots: QString selectedDirectory; QString selectedPositiveFileName; QString selectedNegativeFileName; - -signals: - void paused(); - void resumed(); - void stopped(); - }; #endif // MAINWINDOW_H diff --git a/StateMachineController.cpp b/StateMachineController.cpp index a83098a..341b584 100644 --- a/StateMachineController.cpp +++ b/StateMachineController.cpp @@ -29,8 +29,8 @@ StateMachineController::StateMachineController(QObject *parent) * of the object will be set to false/true. */ - runningState->assignProperty(this, "paused", false); - pausedState->assignProperty(this, "paused", true); +// runningState->assignProperty(this, "paused", false); +// pausedState->assignProperty(this, "paused", true); state_preDelay->addTransition(mainTimer, SIGNAL(timeout()), state_iti); state_iti->addTransition(mainTimer, SIGNAL(timeout()), state_userReaction); @@ -71,10 +71,15 @@ StateMachineController::StateMachineController(QObject *parent) //connect(state_sound, SIGNAL(entered()), mainTimer, SLOT(start())); connect(state_sound, SIGNAL(exited()), this, SLOT(onStateSoundExited())); + + connect(pausedState, SIGNAL(entered()), this, SLOT(onStatePauseEntered())); } -void StateMachineController::runStateMachine(audioGameSettings settings) +void StateMachineController::startStateMachine(audioGameSettings settings) { + if(stateMachine->isRunning()) + stateMachine->stop(); + this->settings = settings; trialsCurrent = 1; // set index for first trial (1-based) trialsTotal = settings.trialSequence.length(); @@ -104,6 +109,18 @@ void StateMachineController::runStateMachine(audioGameSettings settings) } +void StateMachineController::pauseStateMachine() +{ + emit(pauseRequested()); +} + +void StateMachineController::stopStateMachine() +{ + timerDialog->removeTimer(); + mainTimer->stop(); + stateMachine->stop(); +} + void StateMachineController::onStatePreDelayEntered() { @@ -126,10 +143,10 @@ void StateMachineController::onStateItiEntered() void StateMachineController::onStateUserReactionEntered() { -// timerDialog->removeTimer(); // remove previous timer dialog -// timerDialog->setUpTimer(settings.userReaction); -// timerDialog->show(); -// timerDialog->startTimer(); + timerDialog->removeTimer(); // remove previous timer dialog + timerDialog->setUpTimer(settings.userReaction); + timerDialog->show(); + timerDialog->startTimer(); qDebug()<< "Starting user reaction"; emit(statusMessage("Starting user reaction")); @@ -198,22 +215,8 @@ void StateMachineController::onStateSoundExited() } } - -//timerDialog->removeTimer(); -//bool MainWindow::paused() const -//{ -// return false;//m_paused; -//} - -//void MainWindow::setPaused(bool paused) -//{ -//// if (m_paused != paused) { -//// m_paused = paused; -//// emit pausedChanged(); -//// } -//} - -//void MainWindow::pause() -//{ -// //emit pauseRequested(); -//} +void StateMachineController::onStatePauseEntered() +{ + qDebug()<<"Pause state entered"; + timerDialog->removeTimer(); +} diff --git a/StateMachineController.h b/StateMachineController.h index 0400d45..e1926b7 100644 --- a/StateMachineController.h +++ b/StateMachineController.h @@ -22,7 +22,10 @@ class StateMachineController : public QObject public: explicit StateMachineController(QObject *parent = 0); audioGameSettings settings; - void runStateMachine(audioGameSettings); + void startStateMachine(audioGameSettings); + void pauseStateMachine(); + void stopStateMachine(); + private: // state machine @@ -52,16 +55,10 @@ public slots: void onStateAcquisitionBaselineEntered(); void onStateSoundEntered(); void onStateSoundExited(); + void onStatePauseEntered(); signals: void statusMessage(QString); -//Q_SIGNALS: - // change notification signals for the state properties - void pausedChanged(); - /** - * This signal is emitted when the pause() slot is invoked and is used - * by the internal state machine only. - */ void pauseRequested();