DAQ Settings in.

This commit is contained in:
Chris Esposito 2017-12-27 12:44:49 +11:00
parent d8ea339c56
commit d5dad1f13f
12 changed files with 310 additions and 31 deletions

View File

@ -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();
}

View File

@ -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

View File

@ -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

View File

@ -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){

View File

@ -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;
}

View File

@ -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();
};

View File

@ -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);
}

View File

@ -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

View File

@ -15,7 +15,6 @@ public:
double value;
private:
char printString[160];
};
#endif // SIPRINT_H

View File

@ -6,13 +6,166 @@
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>480</width>
<height>320</height>
</rect>
</property>
<property name="windowTitle">
<string>DAQ Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QGroupBox" name="sampleAveragingGroup">
<property name="title">
<string>Sample Averaging</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="numberOfPointsLabel">
<property name="toolTip">
<string/>
</property>
<property name="statusTip">
<string/>
</property>
<property name="whatsThis">
<string/>
</property>
<property name="text">
<string>Number of Points</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="numberOfPointsSpinBox">
<property name="minimum">
<number>2</number>
</property>
<property name="maximum">
<number>750000000</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="sampleRateLabel">
<property name="text">
<string>Effective Sample Rate (Standard Mode)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="sampleRateLabel_val">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="sampleRateLabel_Double">
<property name="text">
<string>Effective Sample Rate (Double Sample Rate)</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="sampleRateLabel_Double_val">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="limitFileSizeGroupBox">
<property name="title">
<string>Limit File Size</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="fileSizeLabel">
<property name="text">
<string>Maximum File Size (MB)</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="fileSizeSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>1024000000</number>
</property>
<property name="value">
<number>1024</number>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QLabel" name="numSamplesStoredLabel">
<property name="text">
<string>Number of Samples Stored</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="numSamplesStoredLabel_Value">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveAsDefaultsButton">
<property name="text">
<string>Save As Defaults</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>

View File

@ -1343,14 +1343,14 @@
</widget>
<widget class="QMenu" name="menuRecord">
<property name="title">
<string>Record</string>
<string>Enable Data Aquisition</string>
</property>
<addaction name="actionRecord_CH1"/>
<addaction name="actionRecord_CH2"/>
</widget>
<addaction name="menuRecord"/>
<addaction name="menuTake_Snapshot"/>
<addaction name="actionDAQ_Settings"/>
<addaction name="menuTake_Snapshot"/>
<addaction name="menuRecord"/>
</widget>
<widget class="QMenu" name="menuOscilloscope_2">
<property name="title">

View File

@ -99,7 +99,8 @@ void unixUsbDriver::usbSendControl(uint8_t RequestType, uint8_t Request, uint16_
else controlBuffer = LDATA;
int error = libusb_control_transfer(handle, RequestType, Request, Value, Index, controlBuffer, Length, 4000);
if(error){
if(error<0){
qDebug() << "Error number:" << error;
qDebug("unixUsbDriver::usbSendControl FAILED with error %s", libusb_error_name(error));
} //else qDebug() << "unixUsbDriver::usbSendControl SUCCESS";
if((error == LIBUSB_ERROR_NO_DEVICE) && (Request!=0xa7)){ //Bootloader Jump won't return; this is expected behaviour.