diff --git a/AudioGameGUI.pro b/AudioGameGUI.pro
index ec63ced..89f50cf 100644
--- a/AudioGameGUI.pro
+++ b/AudioGameGUI.pro
@@ -1,31 +1,56 @@
-#-------------------------------------------------
-#
-# Project created by QtCreator 2016-07-26T13:26:15
-#
-#-------------------------------------------------
-
-QT += core gui
-
-greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
-CONFIG += c++11
-
-TARGET = AudioGameGUI
-TEMPLATE = app
-
-
-SOURCES += main.cpp\
- StateMachineController.cpp \
- Mainwindow.cpp \
- TimerDialog.cpp
-
-HEADERS += \
- helpers.h \
- StateMachineController.h \
- TimerDialog.h \
- Mainwindow.h \
- SettingStructures.h
-
-FORMS += mainwindow.ui \
- timerdialog.ui
-
-DISTFILES +=
+#-------------------------------------------------
+#
+# Project created by QtCreator 2016-07-26T13:26:15
+#
+#-------------------------------------------------
+
+QT += core gui
+
+greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
+CONFIG += c++11
+QT += axcontainer
+TYPELIBS = $$system(dumpcpp -getfile {D323A622-1D13-11D4-8858-444553540000})
+
+
+isEmpty(TYPELIBS) {
+ message("TDT library not found!")
+} else {
+ TYPELIBS = $$system(dumpcpp {D323A622-1D13-11D4-8858-444553540000})
+ HEADERS += rpcoxlib.h
+ SOURCES += rpcoxlib.cpp
+}
+
+TARGET = AudioGameGUI
+TEMPLATE = app
+
+LIBS += -L"C:\\Program Files (x86)\\National Instruments\\NI-DAQ\\DAQmx ANSI C Dev\\lib\\msvc" \
+ -lNIDAQmx
+
+
+SOURCES += main.cpp\
+ StateMachineController.cpp \
+ Mainwindow.cpp \
+ TimerDialog.cpp \
+ TDTInterface.cpp \
+ trialseq.cpp \
+ NIDAQmxInterface.cpp
+
+
+HEADERS += \
+ NIDAQmxInterface.h \
+ StateMachineController.h \
+ TimerDialog.h \
+ Mainwindow.h \
+ SettingStructures.h \
+ TDTInterface.h \
+ trialseq.h
+
+
+
+#LIBS += -L"C:\\TDT\\lib64" \
+# -lRPco
+
+FORMS += mainwindow.ui \
+ timerdialog.ui
+
+DISTFILES +=
diff --git a/AudioGameGUI.pro.user b/AudioGameGUI.pro.user
index 107cc57..b64f336 100644
--- a/AudioGameGUI.pro.user
+++ b/AudioGameGUI.pro.user
@@ -1,11 +1,7 @@
-
+
-
- EnvironmentId
- {2ed301e3-4f04-4cfb-b8ea-e4f5caa11dd8}
-
ProjectExplorer.Project.ActiveTarget
0
@@ -33,12 +29,9 @@
false
4
false
- 80
- true
true
1
true
- false
0
true
0
@@ -65,18 +58,17 @@
0
0
- /local/disk1/home/kretschmerf/projects/Developer/build-AudioGameGUI-Desktop-Debug
+ /home/kretschmerf/projectsbuild-AudioGameGUI-Desktop-Debug
true
qmake
QtProjectManager.QMakeBuildStep
- true
+ false
+ true
false
- false
- false
true
@@ -125,7 +117,7 @@
true
- /local/disk1/home/kretschmerf/projects/Developer/build-AudioGameGUI-Desktop-Release
+ /home/kretschmerf/projectsbuild-AudioGameGUI-Desktop-Release
true
@@ -133,10 +125,9 @@
QtProjectManager.QMakeBuildStep
false
+ true
false
- false
- false
true
@@ -184,67 +175,7 @@
0
true
-
- /local/disk1/home/kretschmerf/projects/Developer/build-AudioGameGUI-Desktop-Profile
-
-
- true
- qmake
-
- QtProjectManager.QMakeBuildStep
- true
-
- false
- true
- false
-
-
- true
- Make
-
- Qt4ProjectManager.MakeStep
-
- -w
- -r
-
- false
-
-
-
- 2
- Build
-
- ProjectExplorer.BuildSteps.Build
-
-
-
- true
- Make
-
- Qt4ProjectManager.MakeStep
-
- -w
- -r
-
- true
- clean
-
-
- 1
- Clean
-
- ProjectExplorer.BuildSteps.Clean
-
- 2
- false
-
- Profile
-
- Qt4ProjectManager.Qt4BuildConfiguration
- 0
- true
-
- 3
+ 2
0
@@ -260,58 +191,19 @@
1
- false
- 1000
-
- true
-
- false
- false
- false
- false
- true
- 0.01
- 10
- true
- 1
- 25
-
- 1
- true
- false
- true
- valgrind
-
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
-
2
AudioGameGUI
- Qt4ProjectManager.Qt4RunConfiguration:/local/disk1/home/kretschmerf/projects/Developer/AudioGameGUI/AudioGameGUI.pro
- true
+ Qt4ProjectManager.Qt4RunConfiguration:/storage/scic/Data/External/Developer/AudioGameGUI/AudioGameGUI.pro
AudioGameGUI.pro
false
false
3768
- false
- true
+ true
+ false
false
false
true
@@ -324,11 +216,11 @@
1
- ProjectExplorer.Project.Updater.FileVersion
- 18
+ ProjectExplorer.Project.Updater.EnvironmentId
+ {2ed301e3-4f04-4cfb-b8ea-e4f5caa11dd8}
- Version
- 18
+ ProjectExplorer.Project.Updater.FileVersion
+ 15
diff --git a/Mainwindow.cpp b/Mainwindow.cpp
index 6778b11..725f877 100644
--- a/Mainwindow.cpp
+++ b/Mainwindow.cpp
@@ -1,6 +1,6 @@
#include "Mainwindow.h"
#include "ui_mainwindow.h"
-#include "helpers.h"
+
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
@@ -58,16 +58,16 @@ void MainWindow::on_pushButton_Run_clicked()
int sorting;
switch(ui->comboBox_trialSequence->currentIndex()){
case 0:
- sorting = ORDERED;
+ sorting = TrialSeq::ORDERED;
break;
case 1:
- sorting = SORTED;
+ sorting = TrialSeq::SORTED;
break;
case 2:
- sorting = SHUFFLED;
+ sorting = TrialSeq::SHUFFLED;
break;
default:
- sorting = ORDERED;
+ sorting = TrialSeq::ORDERED;
}
/*Populate settings with GUI values*/
@@ -77,13 +77,13 @@ void MainWindow::on_pushButton_Run_clicked()
settings.soundDurationPositive = ui->lineEdit_soundDurationPositive->text().toDouble();
settings.soundDurationNegative = ui->lineEdit_soundDurationNegative->text().toDouble();
settings.userReaction = userReaction;
- settings.trialSequence = generateTrialSequence(sorting, ui->lineEdit_repeatPositive->text().toInt(), ui->lineEdit_repeatNegative->text().toInt());
+ settings.trialSequence = TrialSeq::generateTrialSequence(sorting, ui->lineEdit_repeatPositive->text().toInt(), ui->lineEdit_repeatNegative->text().toInt());
if(ui->checkBox_itiExternal->isChecked()){
qDebug()<<"Using iti from file";
- settings.itiSequence = loadExternalItiSequence("/Users/davidunzue/iti_external.txt", ui->lineEdit_repeatPositive->text().toInt(), ui->lineEdit_repeatNegative->text().toInt());
+ settings.itiSequence = TrialSeq::loadExternalItiSequence("/Users/davidunzue/iti_external.txt", ui->lineEdit_repeatPositive->text().toInt(), ui->lineEdit_repeatNegative->text().toInt());
}else{
- settings.itiSequence = generateItiSequence(userReaction, ui->lineEdit_iti->text(), ui->lineEdit_preImaq->text().toDouble(), ui->lineEdit_repeatPositive->text().toInt(), ui->lineEdit_repeatNegative->text().toInt());
+ settings.itiSequence = TrialSeq::generateItiSequence(userReaction, ui->lineEdit_iti->text(), ui->lineEdit_preImaq->text().toDouble(), ui->lineEdit_repeatPositive->text().toInt(), ui->lineEdit_repeatNegative->text().toInt());
}
qDebug()<< settings.itiSequence;
@@ -227,7 +227,7 @@ void MainWindow::updateIti()
if(lineEdit_iti_str.contains(',')) {
QStringList iti_range = lineEdit_iti_str.split(',');
if((iti_range.first().toDouble() < userReaction + preImaq) |
- iti_range.last().toDouble() < userReaction + preImaq){
+ (iti_range.last().toDouble() < userReaction + preImaq)){
ui->lineEdit_iti->setText(QString("%1,%2").arg(QString::number(iti_range.first().toDouble() + userReaction + preImaq), QString::number(iti_range.last().toDouble() + userReaction + preImaq)));
}
} else {
diff --git a/Mainwindow.h b/Mainwindow.h
index c3ff71d..19de4a7 100644
--- a/Mainwindow.h
+++ b/Mainwindow.h
@@ -10,10 +10,7 @@
#include "TimerDialog.h"
#include "StateMachineController.h"
#include "SettingStructures.h"
-
-// values for trial sequence sorting
-enum SORTING {ORDERED, SORTED, SHUFFLED};
-
+#include "trialseq.h"
namespace Ui {
class MainWindow;
diff --git a/NIDAQmxInterface.h b/NIDAQmxInterface.h
new file mode 100644
index 0000000..37466a2
--- /dev/null
+++ b/NIDAQmxInterface.h
@@ -0,0 +1,85 @@
+#ifndef NIDAQmxInterface_h
+#define NIDAQmxInterface_h
+
+#include
+#include
+#include
+#include
+#include
+#include "C:\Program Files (x86)\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\NIDAQmx.h"
+//#include
+
+/* define port bit states */
+#define DAQ_PORT_NULL 0x00
+#define DAQ_PORT_TRUE 0x01
+
+#define DAQ_PORT_DI_SHUTTER 0x01
+#define DAQ_PORT_DI_BACKLIGHT 0x02
+#define DAQ_PORT_DI_FRAME 0x04
+#define DAQ_PORT_DI_AIR 0x08
+#define DAQ_PORT_DI_WATER 0x10
+#define DAQ_PORT_DI_SOUND 0x20
+#define DAQ_PORT_DI_LICK 0x40
+#define DAQ_PORT_DI_SCANNER 0x80
+
+#define DAQ_PORT_DO_MONITOR 0x01
+#define DAQ_PORT_DO_AIR 0x02
+#define DAQ_PORT_DO_WATER 0x04
+#define DAQ_PORT_DO_SOUND 0x08
+#define DAQ_PORT_DO_IMGAQ 0x10
+#define DAQ_PORT_DO_FREQGEN 0x20
+
+#define DAQ_PORT_DE_MONITOR 0x01
+#define DAQ_PORT_DE_AIR 0x02
+#define DAQ_PORT_DE_WATER 0x04
+
+#define DO_PULSE_WIDTH 0.08// in seconds
+
+/* define DAQmxErrChk macro */
+#define DAQmxErrChk(functionCall)\
+ if((functionCall) < 0)\
+ {\
+ char errBuffer[2048];\
+ DAQmxGetExtendedErrorInfo(errBuffer, 2048);\
+ fprintf(stderr, "DAQmxError: %s\n Calling: %s\n", errBuffer, #functionCall);\
+ exit(EXIT_FAILURE);\
+ }
+
+/* define DAQmxData type */
+typedef struct _DAQmxEngine
+{
+ TaskHandle di_port;
+ TaskHandle do_port;
+ TaskHandle do_clk;
+ TaskHandle di_error;
+ uInt8 di_bit_now;
+ uInt8 di_bit_prev;
+ uInt8 do_bit_wrt;
+ uInt8 do_bit_qry;
+ uInt8 flag_scanner;
+ uInt32 di_cntr_lick;
+ uInt32 di_cntr_frame;
+ uInt32 di_cntr_imaq;
+ FILE *fp_log;
+} DAQmxEngine;
+
+/* function prototypes */
+void DAQmxInitializeInterface(DAQmxEngine *);
+void DAQmxDestroyInterface(DAQmxEngine *);
+void DAQmxSetDefaultEngine(DAQmxEngine *);
+void DAQmxReadErrorPort(DAQmxEngine *);
+void DAQmxStartCustomTask(TaskHandle);
+void DAQmxStopCustomTask(TaskHandle);
+void DAQtest();
+
+void DAQmxTriggerDO(DAQmxEngine *, uInt8, bool);
+void DAQmxWriteDO(DAQmxEngine *, uInt8);
+
+void DAQmxLogToFile(FILE *, const char *, uInt32, uInt32);
+
+/* events callback functions */
+int32 CVICALLBACK FcnCbckDetectDI(TaskHandle, int32, void *);
+int32 CVICALLBACK FcnCbckTriggerStopDO(TaskHandle, int32, void *);
+
+
+#endif /* define (NIDAQmxInterface_h) */
diff --git a/StateMachineController.cpp b/StateMachineController.cpp
index 341b584..a006b4b 100644
--- a/StateMachineController.cpp
+++ b/StateMachineController.cpp
@@ -5,6 +5,7 @@ StateMachineController::StateMachineController(QObject *parent)
// seed randomizer
srand(time(0));
timerDialog = new TimerDialog();
+ //TDTInitializeInterface();
mainTimer = new QTimer(this);
mainTimer->setSingleShot(true);
@@ -24,14 +25,6 @@ StateMachineController::StateMachineController(QObject *parent)
QHistoryState *historyState = new QHistoryState(runningState);
- /**
- * Depending on whether we are in runningState or pausedState, the 'paused' property
- * of the object will be set to false/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);
state_userReaction->addTransition(mainTimer, SIGNAL(timeout()), state_acquisitionBaseline);
@@ -68,11 +61,15 @@ StateMachineController::StateMachineController(QObject *parent)
//connect(state_acquisitionBaseline, SIGNAL(entered()), mainTimer, SLOT(start()));
// state sound
connect(state_sound, SIGNAL(entered()), this, SLOT(onStateSoundEntered()));
- //connect(state_sound, SIGNAL(entered()), mainTimer, SLOT(start()));
connect(state_sound, SIGNAL(exited()), this, SLOT(onStateSoundExited()));
+ connect(pausedState, SIGNAL(entered()), this, SLOT(onStatePauseEntered()));
+ rp = new RPCOXLib::RPcoX();
+ daq = new DAQmxEngine();
+ DAQmxSetDefaultEngine(daq);
+ //DAQmxInitializeInterface(daq);
+ //DAQmxLogToFile(daq->fp_log, "INIT", 0, 0);
- connect(pausedState, SIGNAL(entered()), this, SLOT(onStatePauseEntered()));
}
void StateMachineController::startStateMachine(audioGameSettings settings)
@@ -83,6 +80,36 @@ void StateMachineController::startStateMachine(audioGameSettings settings)
this->settings = settings;
trialsCurrent = 1; // set index for first trial (1-based)
trialsTotal = settings.trialSequence.length();
+ //rp->ReadTag("test");
+ /* connect to RP2 system */
+ if (!rp->ConnectRP2("USB", 1))
+ {
+ fprintf(stderr, "TDTError:TDTInterface/TDTInitializeInterface:\n\tfailed to connect to RP2!\n");
+ exit(EXIT_FAILURE);
+ }
+
+ /* check status */
+// tdt_status = rp->GetStatus();
+
+ /* check if device is connected */
+// if ((tdt_status & TDT_STATUS_CONNECTED) == TDT_STATUS_CONNECTED)
+// {
+// printf("TDT RP2 connected\n");
+
+// /* check if device is running */
+// if ((tdt_status & TDT_STATUS_CIRCUIT_RUNNING) == TDT_STATUS_CIRCUIT_RUNNING)
+// rp->Halt();
+
+// /* check if device memory is full */
+// if ((tdt_status & TDT_STATUS_CIRCUIT_LOADED) == TDT_STATUS_CIRCUIT_LOADED)
+// rp->ClearCOF();
+// }
+ QString fileName;
+ rp->Halt();
+ rp->ClearCOF();
+//RP.GetSFreq/2
+ // rp->LoadCOF(settings.fileNameNegative);
+
// /* set default values */
@@ -176,7 +203,8 @@ void StateMachineController::onStateSoundEntered()
mainTimer->setInterval(settings.soundDurationNegative * 1000);
//state_sound->assignProperty(mainTimer, "interval", (settings.soundDurationNegative * 1000));
qDebug() << "Loading negative sound file:" << settings.fileNameNegative;
-
+ rp->LoadCOF(settings.fileNameNegative);
+ rp->Run();
//TDTLoadRCXCircuit(settings.fileNameNegative);
break;
case 1:
@@ -184,7 +212,8 @@ void StateMachineController::onStateSoundEntered()
//state_sound->assignProperty(mainTimer, "interval", (settings.soundDurationPositive * 1000));
qDebug() << "Loading positive sound file:" << settings.fileNamePositive;
//TDTLoadRCXCircuit(settings.fileNamePositive);
-
+ rp->LoadCOF(settings.fileNamePositive);
+ rp->Run();
break;
}
diff --git a/StateMachineController.h b/StateMachineController.h
index e1926b7..3182820 100644
--- a/StateMachineController.h
+++ b/StateMachineController.h
@@ -8,12 +8,20 @@
#include
#include
#include
+#include
#include
#include //std::random_shuffle
#include "SettingStructures.h"
#include "TimerDialog.h"
+#include "NIDAQmxInterface.h"
+
+//#include "TDTInterface.h"
+#include "rpcoxlib.h"
+#include "C:\Program Files (x86)\National Instruments\NI-DAQ\DAQmx ANSI C Dev\include\NIDAQmx.h"
+
+void DAQmxSetDefaultEngine(DAQmxEngine *);
class StateMachineController : public QObject
{
@@ -26,7 +34,6 @@ class StateMachineController : public QObject
void pauseStateMachine();
void stopStateMachine();
-
private:
// state machine
QStateMachine *stateMachine;
@@ -36,18 +43,16 @@ class StateMachineController : public QObject
QState *state_acquisitionBaseline;
QState *state_sound;
- bool m_paused;
-
// the timer that triggers the state changes
QTimer *mainTimer;
TimerDialog *timerDialog;
- //DAQmxEngine *daq;
+ DAQmxEngine* daq;
+ RPCOXLib::RPcoX* rp;
int trialsTotal = -1;
int trialsCurrent = -1; // is gonna be 1-based, so first trial has index 1
-
public slots:
void onStatePreDelayEntered();
void onStateItiEntered();
diff --git a/TDTInterface.h b/TDTInterface.h
new file mode 100644
index 0000000..321aa5e
--- /dev/null
+++ b/TDTInterface.h
@@ -0,0 +1,18 @@
+#ifndef TDTInterface_h
+#define TDTInterface_h
+
+#include
+#include
+#include "rpcoxlib.h"
+
+#define TDT_STATUS_NULL 0x00
+#define TDT_STATUS_CONNECTED 0x01
+#define TDT_STATUS_CIRCUIT_LOADED 0x02
+#define TDT_STATUS_CIRCUIT_RUNNING 0x04
+
+///* funciton prototypes */
+void TDTInitializeInterface(void);
+void TDTLoadRCXCircuit(const char *);
+void TDTDestroyInterface(void);
+
+#endif /* define (TDTInterface_h) */
diff --git a/helpers.h b/helpers.h
deleted file mode 100644
index e2fdfd3..0000000
--- a/helpers.h
+++ /dev/null
@@ -1,117 +0,0 @@
-#ifndef HELPERS_H
-#define HELPERS_H
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-// random generator function:
-int randomGenerator (int i) { return rand()%i; }
-
-double randomMinMax (double min, double max) {
- std::mt19937 rng;
- std::uniform_real_distribution dist(min, max); //(min, max)
- rng.seed(std::random_device{}()); //non-deterministic seed
- return dist(rng);
-}
-
-
-
-QVector generateTrialSequence(int sorting, int repeatPositive, int repeatNegative)
-{
- QVector trialSequence;
- int currentRepeatPositive;
- int currentRepeatNegative;
-
- switch(sorting){
- case ORDERED:
- currentRepeatPositive = 1;
- currentRepeatNegative = 1;
- while(currentRepeatPositive <= repeatPositive || currentRepeatNegative <= repeatNegative) {
- if(currentRepeatPositive <= repeatPositive) {
- trialSequence.append(1);
- currentRepeatPositive++;
- }
- if(currentRepeatNegative <= repeatNegative) {
- trialSequence.append(0);
- currentRepeatNegative++;
- }
- }
- break;
- case SORTED:
- for (currentRepeatPositive = 1; currentRepeatPositive <= repeatPositive; ++currentRepeatPositive) {
- trialSequence.append(1);
- }
- for (currentRepeatNegative = 1; currentRepeatNegative <= repeatNegative; ++currentRepeatNegative) {
- trialSequence.append(0);
- }
- break;
- case SHUFFLED:
- for (currentRepeatPositive = 1; currentRepeatPositive <= repeatPositive; ++currentRepeatPositive) {
- trialSequence.append(1);
- }
- for (currentRepeatNegative = 1; currentRepeatNegative <= repeatNegative; ++currentRepeatNegative) {
- trialSequence.append(0);
- }
- // shuffle trial sequence
- std::random_shuffle(trialSequence.begin(), trialSequence.end(), randomGenerator);
- break;
- default:
- for (currentRepeatPositive = 1; currentRepeatPositive <= repeatPositive; ++currentRepeatPositive) {
- trialSequence.append(1);
- for (currentRepeatNegative = 1; currentRepeatNegative <= repeatNegative; ++currentRepeatNegative) {
- trialSequence.append(0);
- }
- }
- }
- //qDebug() << trialSequence;
- return trialSequence;
-
-}
-
-QVector generateItiSequence(double userReaction, QString itiList, double preImaq, int repeatPositive, int repeatNegative)
-{
- QVector itiSequence;
- int itiSequenceLength = repeatPositive + repeatNegative;
- if(!itiList.isEmpty()) {
- if(itiList.contains(',')) {
- QStringList iti_range = itiList.split(',');
- double itiValueMin = iti_range.first().toDouble() - userReaction - preImaq;
- double itiValueMax = iti_range.last().toDouble() - userReaction - preImaq;
- for (int itiSequenceElement = 0; itiSequenceElement < itiSequenceLength; ++itiSequenceElement) {
- itiSequence.append(randomMinMax(itiValueMin, itiValueMax));
- }
- } else {
- double itiValue = itiList.toDouble() - userReaction - preImaq;
- for (int itiSequenceElement = 0; itiSequenceElement < itiSequenceLength; ++itiSequenceElement) {
- itiSequence.append(itiValue);
- }
- }
- }
-
- return itiSequence;
-}
-
-
-QVector loadExternalItiSequence(QString fileName, int repeatPositive, int repeatNegative)
-{
- QVector itiSequence;
-
- // get iti duration value from external file
- QFile file(fileName);
- if (file.open(QIODevice::ReadOnly | QIODevice::Text)){
- QTextStream in(&file);
- while (!in.atEnd()) {
- QString line = in.readLine();
- itiSequence.append(10); /*Get proper value*/
- qDebug() << line;
- }
- }
- return itiSequence;
-}
-
-
-#endif // HELPERS_H
diff --git a/main.cpp b/main.cpp
index 46e6dae..53479dc 100644
--- a/main.cpp
+++ b/main.cpp
@@ -1,4 +1,4 @@
-#include "mainwindow.h"
+#include "Mainwindow.h"
#include
int main(int argc, char *argv[])