Skip to content
This repository has been archived by the owner. It is now read-only.

Commit

Permalink
Created individual methods for start/stop/pause
Browse files Browse the repository at this point in the history
  • Loading branch information
MPIBR-kretschmerf committed Sep 8, 2016
1 parent 8e11af9 commit 55c62fe
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 57 deletions.
29 changes: 12 additions & 17 deletions Mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));

}

Expand Down Expand Up @@ -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");

}


Expand Down Expand Up @@ -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();
Expand Down
8 changes: 2 additions & 6 deletions Mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ private slots:
void on_lineEdit_iti_editingFinished();
void on_lineEdit_preImaq_editingFinished();

void onStatusMessage(QString statusMessage);


private:
Ui::MainWindow *ui;
Expand All @@ -61,12 +63,6 @@ private slots:
QString selectedDirectory;
QString selectedPositiveFileName;
QString selectedNegativeFileName;

signals:
void paused();
void resumed();
void stopped();

};

#endif // MAINWINDOW_H
55 changes: 29 additions & 26 deletions StateMachineController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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()
{
Expand All @@ -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"));
Expand Down Expand Up @@ -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();
}
13 changes: 5 additions & 8 deletions StateMachineController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();


Expand Down

0 comments on commit 55c62fe

Please sign in to comment.