diff --git a/Desktop_Interface/daqform.cpp b/Desktop_Interface/daqform.cpp
index 2eb42b12..155d695a 100644
--- a/Desktop_Interface/daqform.cpp
+++ b/Desktop_Interface/daqform.cpp
@@ -1,14 +1,83 @@
#include "daqform.h"
#include "ui_daqform.h"
+#include "siprint.h"
+#include "desktop_settings.h"
-daqForm::daqForm(QWidget *parent) :
+daqForm::daqForm(QWidget *parent, int initialAverage, qulonglong initialMaxFileSize) :
QDialog(parent),
ui(new Ui::daqForm)
{
ui->setupUi(this);
+
+ //Set the Initial Average settings
+ if(initialAverage != 1){
+ ui->sampleAveragingGroup->setChecked(true);
+ ui->numberOfPointsSpinBox->setValue(initialAverage);
+ }
+
+ //Initialise the file size box
+ if(initialMaxFileSize == 0){
+ ui->limitFileSizeGroupBox->setChecked(false);
+ } else {
+ ui->limitFileSizeGroupBox->setChecked(true);
+ ui->fileSizeSpinBox->setValue(initialMaxFileSize/1000000);
+ }
+
+ updateLabels();
+ //Internal Signal Connect
+ //Changed values
+ connect(ui->fileSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateValues()));
+ connect(ui->numberOfPointsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateValues()));
+ connect(ui->limitFileSizeGroupBox, SIGNAL(toggled(bool)), this, SLOT(updateValues()));
+ connect(ui->sampleAveragingGroup, SIGNAL(toggled(bool)), this, SLOT(updateValues()));
+
+ //Label
+ connect(ui->numberOfPointsSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateLabels()));
+ connect(ui->fileSizeSpinBox, SIGNAL(valueChanged(int)), this, SLOT(updateLabels()));
+
+ //Save Button
+ connect(ui->saveAsDefaultsButton, SIGNAL(clicked(bool)), this, SLOT(trigger_saveButtonPressed()));
+
}
daqForm::~daqForm()
{
delete ui;
}
+
+void daqForm::updateLabels(){
+ double effective_sample_rate_single = 375000/((double)ui->numberOfPointsSpinBox->value());
+ double effective_sample_rate_double = 750000/((double)ui->numberOfPointsSpinBox->value());
+ int num_samples_stored = (ui->fileSizeSpinBox->value() * 1000000) / NUM_BYTES_STORED_PER_DAQ_SAMPLE;
+
+ //Print in SI units
+ siprint label_single_siprint("Hz", effective_sample_rate_single);
+ siprint label_double_siprint("Hz", effective_sample_rate_double);
+
+ //Shove commas in there, or decimal points if you're European!
+ QString label_numSamples = QLocale().toString(num_samples_stored);
+
+ ui->sampleRateLabel_val->setText(label_single_siprint.printVal());
+ ui->sampleRateLabel_Double_val->setText(label_double_siprint.printVal());
+ ui->numSamplesStoredLabel_Value->setText(label_numSamples);
+}
+
+void daqForm::updateValues(){
+ qDebug() << "daqForm::updateValues()";
+
+ //Averaging
+ if(ui->sampleAveragingGroup->isChecked()){
+ updatedAveraging(ui->numberOfPointsSpinBox->value());
+ } else updatedAveraging(1);
+
+ //File Size
+ if(ui->limitFileSizeGroupBox->isChecked()){
+ updatedMaxFileSize(ui->fileSizeSpinBox->value() * 1000000);
+ } else updatedMaxFileSize(0);
+
+}
+
+void daqForm::trigger_saveButtonPressed(){
+ saveButtonPressed();
+}
+
diff --git a/Desktop_Interface/daqform.h b/Desktop_Interface/daqform.h
index 56eed8b9..906a2cb4 100644
--- a/Desktop_Interface/daqform.h
+++ b/Desktop_Interface/daqform.h
@@ -12,11 +12,18 @@ class daqForm : public QDialog
Q_OBJECT
public:
- explicit daqForm(QWidget *parent = 0);
+ explicit daqForm(QWidget *parent, int initialAverage, qulonglong initialMaxFileSize);
~daqForm();
-
+signals:
+ void updatedAveraging(int);
+ void updatedMaxFileSize(qulonglong);
+ void saveButtonPressed();
private:
Ui::daqForm *ui;
+private slots:
+ void updateLabels();
+ void updateValues();
+ void trigger_saveButtonPressed();
};
#endif // DAQFORM_H
diff --git a/Desktop_Interface/desktop_settings.h b/Desktop_Interface/desktop_settings.h
index 2c29d780..8a82fcc5 100644
--- a/Desktop_Interface/desktop_settings.h
+++ b/Desktop_Interface/desktop_settings.h
@@ -44,5 +44,7 @@ extern unsigned char expected_variant;
#define ANDROID_SCALE_INSENSITIVITY 1.2
+#define NUM_BYTES_STORED_PER_DAQ_SAMPLE 9
+
#endif // DESKTOP_SETTINGS_H
diff --git a/Desktop_Interface/genericusbdriver.cpp b/Desktop_Interface/genericusbdriver.cpp
index 0919d20e..4333175d 100644
--- a/Desktop_Interface/genericusbdriver.cpp
+++ b/Desktop_Interface/genericusbdriver.cpp
@@ -307,6 +307,7 @@ void genericUsbDriver::setGain(double newGain){
void genericUsbDriver::avrDebug(void){
usbSendControl(0xc0, 0xa0, 0, 0, sizeof(unified_debug), NULL);
+ /*
#ifndef PLATFORM_ANDROID
unified_debug *udsPtr = (unified_debug *) inBuffer;
uint16_t trfcnt0 = (udsPtr->trfcntH0 << 8) + udsPtr->trfcntL0;
@@ -317,7 +318,6 @@ void genericUsbDriver::avrDebug(void){
uint16_t dma_ch0_cnt = (udsPtr->dma_ch0_cntH << 8) + udsPtr->dma_ch0_cntL;
uint16_t dma_ch1_cnt = (udsPtr->dma_ch1_cntH << 8) + udsPtr->dma_ch1_cntL;
-
qDebug("%s", udsPtr->header);
qDebug() << "trfcnt0 =" << trfcnt0;
qDebug() << "trfcnt1 =" << trfcnt1;
@@ -330,6 +330,7 @@ void genericUsbDriver::avrDebug(void){
qDebug() << "dma_ch0_cnt = " << dma_ch0_cnt;
qDebug() << "dma_ch1_cnt = " << dma_ch1_cnt;
#endif
+*/
}
void genericUsbDriver::requestFirmwareVersion(void){
diff --git a/Desktop_Interface/isobuffer.cpp b/Desktop_Interface/isobuffer.cpp
index 3fa73017..d6e65637 100644
--- a/Desktop_Interface/isobuffer.cpp
+++ b/Desktop_Interface/isobuffer.cpp
@@ -45,22 +45,34 @@ void isoBuffer::writeBuffer_char(char* data, int len)
//Output to CSV
if(fileIOEnabled){
- fileIO_sampleCount++; //Counter, determines if we've skipped enough.
+ //Current sample
+ convertedSample = sampleConvert(data[i], 128, channel==1 ? virtualParent->AC_CH1 : virtualParent->AC_CH2);
+
+ //Accumulate
+ average_sample_temp += convertedSample;
+ fileIO_sampleCount++;
+ //Check to see if we can write a new sample to file
if(fileIO_sampleCount == fileIO_maxIncrementedSampleValue){
- convertedSample = sampleConvert(data[i], 128, channel==1 ? virtualParent->AC_CH1 : virtualParent->AC_CH2);
char numStr[32];
- sprintf(numStr,"%7.5f, ", convertedSample); //10 bytes per character
+ sprintf(numStr,"%7.5f, ", average_sample_temp/((double)fileIO_maxIncrementedSampleValue));
currentFile->write(numStr);
currentColumn++;
if (currentColumn > COLUMN_BREAK){
currentFile->write("\n");
currentColumn = 0;
}
+
+ //Reset the average and sample count for next data point
fileIO_sampleCount = 0;
- fileIO_numBytesWritten += 10;
- if(fileIO_numBytesWritten >= fileIO_max_file_size){
- fileIOEnabled = false; //Just in case signalling fails.
- fileIOinternalDisable();
+ average_sample_temp = 0;
+
+ //Check to see if we've reached the max file size.
+ if(fileIO_max_file_size != 0){ //value of 0 means "no limit"
+ fileIO_numBytesWritten += 9; //7 chars for the number, 1 for the comma and 1 for the space = 9 bytes per sample.
+ if(fileIO_numBytesWritten >= fileIO_max_file_size){
+ fileIOEnabled = false; //Just in case signalling fails.
+ fileIOinternalDisable();
+ }
}
}
}
@@ -172,17 +184,28 @@ void isoBuffer::glitchInsert(short type)
}
-void isoBuffer::enableFileIO(QFile *file, int samplesToSkip, qulonglong max_file_size){
+void isoBuffer::enableFileIO(QFile *file, int samplesToAverage, qulonglong max_file_size){
+
+ //Open the file
file->open(QIODevice::WriteOnly);
currentFile = file;
- fileIOEnabled = true;
- fileIO_maxIncrementedSampleValue = samplesToSkip + 1;
+ //Add the header
+ char headerLine[256];
+ sprintf(headerLine, "EspoTek Labrador DAQ V1.0 Output File\nAveraging = %d\n", samplesToAverage);
+ currentFile->write(headerLine);
+
+ //Set up the isoBuffer for DAQ
+ fileIO_maxIncrementedSampleValue = samplesToAverage;
fileIO_max_file_size = max_file_size;
fileIO_sampleCount = 0;
fileIO_numBytesWritten = 0;
+ average_sample_temp = 0;
- qDebug("File IO enabled, skipping %d samples, max file size %uMB", samplesToSkip, max_file_size/1000000);
+ //Enable DAQ
+ fileIOEnabled = true;
+
+ qDebug("File IO enabled, averaging %d samples, max file size %uMB", samplesToAverage, max_file_size/1000000);
qDebug() << max_file_size;
return;
}
diff --git a/Desktop_Interface/isobuffer.h b/Desktop_Interface/isobuffer.h
index b2ef3994..2fd7c7dd 100644
--- a/Desktop_Interface/isobuffer.h
+++ b/Desktop_Interface/isobuffer.h
@@ -69,10 +69,11 @@ private:
//isoDriver *parent;
unsigned int currentColumn = 0;
isoDriver *virtualParent;
+ double average_sample_temp;
signals:
void fileIOinternalDisable();
public slots:
- void enableFileIO(QFile *file, int samplesToSkip, qulonglong max_file_size);
+ void enableFileIO(QFile *file, int samplesToAverage, qulonglong max_file_size);
void disableFileIO();
};
diff --git a/Desktop_Interface/mainwindow.cpp b/Desktop_Interface/mainwindow.cpp
index d3d6bc7c..ff05a40a 100644
--- a/Desktop_Interface/mainwindow.cpp
+++ b/Desktop_Interface/mainwindow.cpp
@@ -1098,8 +1098,8 @@ void MainWindow::readSettingsFile(){
double calibrate_gain_ch1 = settings->value("CalibrateGainCH1", R4/(R3+R4)).toDouble();
double calibrate_gain_ch2 = settings->value("CalibrateGainCH2", R4/(R3+R4)).toDouble();
- daq_sample_skip_interval = settings->value("daq_sample_skip_interval", 0).toInt();
- daq_max_file_size = settings->value("daq_max_file_size", 1024000000).toULongLong();
+ daq_num_to_average = settings->value("daq_defaultAverage", 1).toInt();
+ daq_max_file_size = settings->value("daq_defaultFileSize", 2048000000).toULongLong();
//Change connection Type
switch(connectionType){
@@ -1650,10 +1650,10 @@ void MainWindow::on_actionRecord_CH1_triggered(bool checked)
#endif
if(ui->controller_iso->driver->deviceMode!=6){
output375_CH1 = new QFile(fileName);
- ui->controller_iso->internalBuffer375_CH1->enableFileIO(output375_CH1, daq_sample_skip_interval, daq_max_file_size);
+ ui->controller_iso->internalBuffer375_CH1->enableFileIO(output375_CH1, daq_num_to_average, daq_max_file_size);
} else {
output750 = new QFile(fileName);
- ui->controller_iso->internalBuffer750->enableFileIO(output750, daq_sample_skip_interval, daq_max_file_size);
+ ui->controller_iso->internalBuffer750->enableFileIO(output750, daq_num_to_average, daq_max_file_size);
}
ui->bufferDisplay->scopeDsrDisableOverride = true;
ui->bufferDisplay->poke();
@@ -1681,7 +1681,7 @@ void MainWindow::on_actionRecord_CH2_triggered(bool checked)
}
#endif
output375_CH2 = new QFile(outputDir->filePath("375_CH2.csv"));
- ui->controller_iso->internalBuffer375_CH2->enableFileIO(output375_CH2, daq_sample_skip_interval, daq_max_file_size);
+ ui->controller_iso->internalBuffer375_CH2->enableFileIO(output375_CH2, daq_num_to_average, daq_max_file_size);
return;
}
@@ -1728,7 +1728,6 @@ void MainWindow::checkForI2C(int value){
ui->scopeGroup_CH1->setChecked(false);
ui->scopeGroup_CH2->setChecked(false);
ui->multimeterGroup->setChecked(false);
-
}
return;
}
@@ -1747,8 +1746,12 @@ void MainWindow::on_actionShow_Debug_Console_triggered()
void MainWindow::on_actionDAQ_Settings_triggered()
{
qDebug() << "on_actionDAQ_Settings_triggered()";
- daqForm df(this);
+ daqForm df(this, daq_num_to_average, daq_max_file_size);
df.setModal(true);
+ connect(&df, SIGNAL(updatedAveraging(int)), this, SLOT(daq_updatedAveraging(int)));
+ connect(&df, SIGNAL(updatedMaxFileSize(qulonglong)), this, SLOT(daq_updatedMaxFileSize(qulonglong)));
+ connect(&df, SIGNAL(saveButtonPressed()), this, SLOT(daq_saveButtonPressed()));
+
df.exec();
}
@@ -1772,3 +1775,18 @@ void MainWindow::fileLimitReached_CH2(void){
recordingStoppedMessageBox.exec();
}
+void MainWindow::daq_updatedAveraging(int newVal){
+ qDebug() << "MainWindow::daq_updatedAveraging" << newVal;
+ daq_num_to_average = newVal;
+}
+
+void MainWindow::daq_updatedMaxFileSize(qulonglong newVal){
+ qDebug() << "MainWindow::daq_updatedMaxFileSize" << newVal;
+ daq_max_file_size = newVal;
+}
+
+void MainWindow::daq_saveButtonPressed(){
+ qDebug() << "MainWindow::daq_saveButtonPressed";
+ settings->setValue("daq_defaultAverage", daq_num_to_average);
+ settings->setValue("daq_defaultFileSize", daq_max_file_size);
+}
diff --git a/Desktop_Interface/mainwindow.h b/Desktop_Interface/mainwindow.h
index 20a3e51a..a4845d12 100644
--- a/Desktop_Interface/mainwindow.h
+++ b/Desktop_Interface/mainwindow.h
@@ -167,6 +167,11 @@ private slots:
void fileLimitReached_CH1(void);
void fileLimitReached_CH2(void);
+ void daq_updatedAveraging(int newVal);
+ void daq_updatedMaxFileSize(qulonglong newVal);
+ void daq_saveButtonPressed();
+
+
private:
//Generic Vars
@@ -231,7 +236,7 @@ private:
//Duct Tape
bool dt_AlreadyAskedAboutCalibration = false;
int dt_userWantsToCalibrate;
- int daq_sample_skip_interval;
+ int daq_num_to_average;
qulonglong daq_max_file_size;
#ifdef PLATFORM_ANDROID
diff --git a/Desktop_Interface/ui_elements/siprint.h b/Desktop_Interface/ui_elements/siprint.h
index bcee87ac..9d9bd7e1 100644
--- a/Desktop_Interface/ui_elements/siprint.h
+++ b/Desktop_Interface/ui_elements/siprint.h
@@ -15,7 +15,6 @@ public:
double value;
private:
char printString[160];
-
};
#endif // SIPRINT_H
diff --git a/Desktop_Interface/ui_files_desktop/daqform.ui b/Desktop_Interface/ui_files_desktop/daqform.ui
index 25040d23..07561f4b 100644
--- a/Desktop_Interface/ui_files_desktop/daqform.ui
+++ b/Desktop_Interface/ui_files_desktop/daqform.ui
@@ -6,13 +6,166 @@
0
0
- 400
- 300
+ 480
+ 320
DAQ Settings
+
+ -
+
+
+ Sample Averaging
+
+
+ true
+
+
+ false
+
+
+
-
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+ Number of Points
+
+
+
+ -
+
+
+ 2
+
+
+ 750000000
+
+
+
+
+
+ -
+
+
-
+
+
+ Effective Sample Rate (Standard Mode)
+
+
+
+ -
+
+
+ TextLabel
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+
+
+ -
+
+
-
+
+
+ Effective Sample Rate (Double Sample Rate)
+
+
+
+ -
+
+
+ TextLabel
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+
+
+
+
+
+ -
+
+
+ Limit File Size
+
+
+ true
+
+
+
-
+
+
-
+
+
+ Maximum File Size (MB)
+
+
+
+ -
+
+
+ 1
+
+
+ 1024000000
+
+
+ 1024
+
+
+
+
+
+ -
+
+
-
+
+
+ Number of Samples Stored
+
+
+
+ -
+
+
+ TextLabel
+
+
+ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter
+
+
+
+
+
+
+
+
+ -
+
+
+ Save As Defaults
+
+
+
+
diff --git a/Desktop_Interface/ui_files_desktop/mainwindow.ui b/Desktop_Interface/ui_files_desktop/mainwindow.ui
index 68c14dda..c242f443 100644
--- a/Desktop_Interface/ui_files_desktop/mainwindow.ui
+++ b/Desktop_Interface/ui_files_desktop/mainwindow.ui
@@ -1343,14 +1343,14 @@
-
-
+
+