librador_get_iso_data now returns volts (plus other minor fixes)

This commit is contained in:
Chris Esposito 2018-04-07 12:26:53 +10:00
parent ebab7f8370
commit d771678c55
8 changed files with 242 additions and 61 deletions

View File

@ -75,7 +75,7 @@ void MainWindow::on_pushButton_5_clicked()
QVector<double> yaxis = QVector<double>::fromStdVector(*(librador_get_iso_data(75000, 1, 1500, 0)));
qDebug() << yaxis;
//qDebug() << yaxis;
QVector<double> xaxis;
for (int i=0; i<yaxis.length(); i++){
@ -85,7 +85,7 @@ void MainWindow::on_pushButton_5_clicked()
qDebug() << yaxis.length();
qDebug() << xaxis.length();
ui->widget->yAxis->setRange(0, 255);
ui->widget->yAxis->setRange(ymin, ymax);
ui->widget->xAxis->setRange(0, yaxis.length());
ui->widget->graph(0)->setData(xaxis, yaxis);
@ -132,3 +132,14 @@ void MainWindow::on_checkBox_4_stateChanged(int arg1)
{
qDebug() << librador_set_digital_out(4, arg1);
}
void MainWindow::on_comboBox_activated(int index)
{
double gainValues[8] = {0.5, 1, 2 , 4, 8, 16, 32, 64};
qDebug() << index;
double newGain = gainValues[index];
ymax = 1.65 + (11/newGain);
ymin = 1.65 - (11/newGain);
qDebug() << librador_set_oscilloscope_gain(newGain);
}

View File

@ -16,6 +16,7 @@ public:
~MainWindow();
private:
void initialisePlot();
double ymin = -20, ymax = 20;
private slots:
void on_pushButton_clicked();
@ -43,6 +44,8 @@ private slots:
void on_checkBox_4_stateChanged(int arg1);
void on_comboBox_activated(int index);
private:
Ui::MainWindow *ui;
};

View File

@ -88,32 +88,94 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Digital Out 1</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Digital Out 1</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>Digital Out 2</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>Digital Out 3</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_4">
<property name="text">
<string>Digital Out 4</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox_2">
<property name="text">
<string>Digital Out 2</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_3">
<property name="text">
<string>Digital Out 3</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_4">
<property name="text">
<string>Digital Out 4</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Set Gain:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="comboBox">
<property name="currentText">
<string>1</string>
</property>
<item>
<property name="text">
<string>0.5</string>
</property>
</item>
<item>
<property name="text">
<string>1</string>
</property>
</item>
<item>
<property name="text">
<string>2</string>
</property>
</item>
<item>
<property name="text">
<string>4</string>
</property>
</item>
<item>
<property name="text">
<string>8</string>
</property>
</item>
<item>
<property name="text">
<string>16</string>
</property>
</item>
<item>
<property name="text">
<string>32</string>
</property>
</item>
<item>
<property name="text">
<string>64</string>
</property>
</item>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="pushButton_5">

View File

@ -21,8 +21,8 @@ QT_BEGIN_MOC_NAMESPACE
QT_WARNING_PUSH
QT_WARNING_DISABLE_DEPRECATED
struct qt_meta_stringdata_MainWindow_t {
QByteArrayData data[16];
char stringdata0[337];
QByteArrayData data[18];
char stringdata0[365];
};
#define QT_MOC_LITERAL(idx, ofs, len) \
Q_STATIC_BYTE_ARRAY_DATA_HEADER_INITIALIZER_WITH_OFFSET(len, \
@ -46,7 +46,9 @@ QT_MOC_LITERAL(11, 226, 24), // "on_checkBox_stateChanged"
QT_MOC_LITERAL(12, 251, 4), // "arg1"
QT_MOC_LITERAL(13, 256, 26), // "on_checkBox_2_stateChanged"
QT_MOC_LITERAL(14, 283, 26), // "on_checkBox_3_stateChanged"
QT_MOC_LITERAL(15, 310, 26) // "on_checkBox_4_stateChanged"
QT_MOC_LITERAL(15, 310, 26), // "on_checkBox_4_stateChanged"
QT_MOC_LITERAL(16, 337, 21), // "on_comboBox_activated"
QT_MOC_LITERAL(17, 359, 5) // "index"
},
"MainWindow\0on_pushButton_clicked\0\0"
@ -57,7 +59,8 @@ QT_MOC_LITERAL(15, 310, 26) // "on_checkBox_4_stateChanged"
"on_checkBox_stateChanged\0arg1\0"
"on_checkBox_2_stateChanged\0"
"on_checkBox_3_stateChanged\0"
"on_checkBox_4_stateChanged"
"on_checkBox_4_stateChanged\0"
"on_comboBox_activated\0index"
};
#undef QT_MOC_LITERAL
@ -67,7 +70,7 @@ static const uint qt_meta_data_MainWindow[] = {
7, // revision
0, // classname
0, 0, // classinfo
13, 14, // methods
14, 14, // methods
0, 0, // properties
0, 0, // enums/sets
0, 0, // constructors
@ -75,19 +78,20 @@ static const uint qt_meta_data_MainWindow[] = {
0, // signalCount
// slots: name, argc, parameters, tag, flags
1, 0, 79, 2, 0x08 /* Private */,
3, 0, 80, 2, 0x08 /* Private */,
4, 0, 81, 2, 0x08 /* Private */,
5, 0, 82, 2, 0x08 /* Private */,
6, 0, 83, 2, 0x08 /* Private */,
7, 0, 84, 2, 0x08 /* Private */,
8, 0, 85, 2, 0x08 /* Private */,
9, 0, 86, 2, 0x08 /* Private */,
10, 0, 87, 2, 0x08 /* Private */,
11, 1, 88, 2, 0x08 /* Private */,
13, 1, 91, 2, 0x08 /* Private */,
14, 1, 94, 2, 0x08 /* Private */,
15, 1, 97, 2, 0x08 /* Private */,
1, 0, 84, 2, 0x08 /* Private */,
3, 0, 85, 2, 0x08 /* Private */,
4, 0, 86, 2, 0x08 /* Private */,
5, 0, 87, 2, 0x08 /* Private */,
6, 0, 88, 2, 0x08 /* Private */,
7, 0, 89, 2, 0x08 /* Private */,
8, 0, 90, 2, 0x08 /* Private */,
9, 0, 91, 2, 0x08 /* Private */,
10, 0, 92, 2, 0x08 /* Private */,
11, 1, 93, 2, 0x08 /* Private */,
13, 1, 96, 2, 0x08 /* Private */,
14, 1, 99, 2, 0x08 /* Private */,
15, 1, 102, 2, 0x08 /* Private */,
16, 1, 105, 2, 0x08 /* Private */,
// slots: parameters
QMetaType::Void,
@ -103,6 +107,7 @@ static const uint qt_meta_data_MainWindow[] = {
QMetaType::Void, QMetaType::Int, 12,
QMetaType::Void, QMetaType::Int, 12,
QMetaType::Void, QMetaType::Int, 12,
QMetaType::Void, QMetaType::Int, 17,
0 // eod
};
@ -126,6 +131,7 @@ void MainWindow::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id,
case 10: _t->on_checkBox_2_stateChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
case 11: _t->on_checkBox_3_stateChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
case 12: _t->on_checkBox_4_stateChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
case 13: _t->on_comboBox_activated((*reinterpret_cast< int(*)>(_a[1]))); break;
default: ;
}
}
@ -156,13 +162,13 @@ int MainWindow::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
if (_id < 0)
return _id;
if (_c == QMetaObject::InvokeMetaMethod) {
if (_id < 13)
if (_id < 14)
qt_static_metacall(this, _c, _id, _a);
_id -= 13;
_id -= 14;
} else if (_c == QMetaObject::RegisterMethodArgumentMetaType) {
if (_id < 13)
if (_id < 14)
*reinterpret_cast<int*>(_a[0]) = -1;
_id -= 13;
_id -= 14;
}
return _id;
}

View File

@ -14,9 +14,11 @@
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QCheckBox>
#include <QtWidgets/QComboBox>
#include <QtWidgets/QDoubleSpinBox>
#include <QtWidgets/QHBoxLayout>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QLabel>
#include <QtWidgets/QMainWindow>
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
@ -44,10 +46,14 @@ public:
QHBoxLayout *horizontalLayout_3;
QPushButton *pushButton_9;
QDoubleSpinBox *powerSupplySpinBox;
QHBoxLayout *horizontalLayout_2;
QCheckBox *checkBox;
QCheckBox *checkBox_2;
QCheckBox *checkBox_3;
QCheckBox *checkBox_4;
QHBoxLayout *horizontalLayout_4;
QLabel *label;
QComboBox *comboBox;
QPushButton *pushButton_5;
QCustomPlot *widget;
QMenuBar *menuBar;
@ -121,25 +127,55 @@ public:
verticalLayout->addLayout(horizontalLayout_3);
horizontalLayout_2 = new QHBoxLayout();
horizontalLayout_2->setSpacing(6);
horizontalLayout_2->setObjectName(QStringLiteral("horizontalLayout_2"));
checkBox = new QCheckBox(centralWidget);
checkBox->setObjectName(QStringLiteral("checkBox"));
verticalLayout->addWidget(checkBox);
horizontalLayout_2->addWidget(checkBox);
checkBox_2 = new QCheckBox(centralWidget);
checkBox_2->setObjectName(QStringLiteral("checkBox_2"));
verticalLayout->addWidget(checkBox_2);
horizontalLayout_2->addWidget(checkBox_2);
checkBox_3 = new QCheckBox(centralWidget);
checkBox_3->setObjectName(QStringLiteral("checkBox_3"));
verticalLayout->addWidget(checkBox_3);
horizontalLayout_2->addWidget(checkBox_3);
checkBox_4 = new QCheckBox(centralWidget);
checkBox_4->setObjectName(QStringLiteral("checkBox_4"));
verticalLayout->addWidget(checkBox_4);
horizontalLayout_2->addWidget(checkBox_4);
verticalLayout->addLayout(horizontalLayout_2);
horizontalLayout_4 = new QHBoxLayout();
horizontalLayout_4->setSpacing(6);
horizontalLayout_4->setObjectName(QStringLiteral("horizontalLayout_4"));
label = new QLabel(centralWidget);
label->setObjectName(QStringLiteral("label"));
horizontalLayout_4->addWidget(label);
comboBox = new QComboBox(centralWidget);
comboBox->addItem(QString());
comboBox->addItem(QString());
comboBox->addItem(QString());
comboBox->addItem(QString());
comboBox->addItem(QString());
comboBox->addItem(QString());
comboBox->addItem(QString());
comboBox->addItem(QString());
comboBox->setObjectName(QStringLiteral("comboBox"));
horizontalLayout_4->addWidget(comboBox);
verticalLayout->addLayout(horizontalLayout_4);
pushButton_5 = new QPushButton(centralWidget);
pushButton_5->setObjectName(QStringLiteral("pushButton_5"));
@ -186,6 +222,17 @@ public:
checkBox_2->setText(QApplication::translate("MainWindow", "Digital Out 2", nullptr));
checkBox_3->setText(QApplication::translate("MainWindow", "Digital Out 3", nullptr));
checkBox_4->setText(QApplication::translate("MainWindow", "Digital Out 4", nullptr));
label->setText(QApplication::translate("MainWindow", "Set Gain:", nullptr));
comboBox->setItemText(0, QApplication::translate("MainWindow", "0.5", nullptr));
comboBox->setItemText(1, QApplication::translate("MainWindow", "1", nullptr));
comboBox->setItemText(2, QApplication::translate("MainWindow", "2", nullptr));
comboBox->setItemText(3, QApplication::translate("MainWindow", "4", nullptr));
comboBox->setItemText(4, QApplication::translate("MainWindow", "8", nullptr));
comboBox->setItemText(5, QApplication::translate("MainWindow", "16", nullptr));
comboBox->setItemText(6, QApplication::translate("MainWindow", "32", nullptr));
comboBox->setItemText(7, QApplication::translate("MainWindow", "64", nullptr));
comboBox->setCurrentText(QApplication::translate("MainWindow", "1", nullptr));
pushButton_5->setText(QApplication::translate("MainWindow", "Get Scope Data", nullptr));
} // retranslateUi

View File

@ -39,7 +39,7 @@ int o1buffer::addVector(int *firstElement, int numElements){
return 0;
}
int o1buffer::addVector(unsigned char *firstElement, int numElements){
int o1buffer::addVector(char *firstElement, int numElements){
int currentAddress = mostRecentAddress;
for(int i=0; i< numElements; i++){
@ -153,7 +153,7 @@ double o1buffer::get_filtered_sample(int index, int filter_type, int filter_size
switch(filter_type){
case 0: //No filter
return buffer[index];
return sampleConvert(buffer[index]);
case 1: //Moving Average filter
if(currentPos < 0){
currentPos += NUM_SAMPLES_PER_CHANNEL;
@ -165,9 +165,25 @@ double o1buffer::get_filtered_sample(int index, int filter_type, int filter_size
accum += buffer[currentPos];
currentPos = (currentPos + 1) % NUM_SAMPLES_PER_CHANNEL;
}
return accum/((double)filter_size);
return sampleConvert(accum/((double)filter_size));
break;
default: //Default to "no filter"
return buffer[index];
}
}
double o1buffer::sampleConvert(int sample){
double voltageLevel;
voltageLevel = ((double)sample * (vcc/2)) / (frontendGain*librador_scope_gain*TOP);
if (!twelve_bit_multimeter) voltageLevel += voltage_ref;
#ifdef MULTIMETER_INVERT
if(twelve_bit_multimeter) voltageLevel *= -1;
#endif
if(AC){
voltageLevel -= voltage_ref;
}
return voltageLevel;
}

View File

@ -4,7 +4,7 @@
#include <vector>
#define NUM_SAMPLES_PER_CHANNEL 7500000
#define MULTIMETER_INVERT
class o1buffer
{
@ -13,18 +13,34 @@ public:
~o1buffer();
void add(int value, int address);
int addVector(int *firstElement, int numElements);
int addVector(unsigned char *firstElement, int numElements);
int addVector(char *firstElement, int numElements);
int get(int address);
int mostRecentAddress = 0;
int stream_index_at_last_call = 0;
int distanceFromMostRecentAddress(int index);
std::vector<double> *getMany_double(int numToGet, int interval_samples, int delay_sample, int filter_mode);
std::vector<double> *getSinceLast(int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode);
#warning Asssuming Mode 0 DC
#warning Asssuming Mode 0 DC
#warning Asssuming Mode 0 DC
#warning Asssuming Mode 0 DC
#warning Asssuming Mode 0 DC
#warning Asssuming Mode 0 DC
#warning Asssuming Mode 0 DC
#warning Asssuming Mode 0 DC
double librador_scope_gain = 1;
double vcc = 3.3;
bool AC = false;
double TOP = 128;
double frontendGain = (75.0/1075.0);
bool twelve_bit_multimeter = false;
double voltage_ref = 1.65;
private:
int *buffer;
std::vector<double> convertedStream_double;
void updateMostRecentAddress(int newAddress);
double get_filtered_sample(int index, int filter_type, int filter_size);
double sampleConvert(int sample);
};
#endif // O1BUFFER_H

View File

@ -42,7 +42,10 @@ bool safe_to_exit_thread(){
}
//shared vars
o1buffer *internal_o1_buffer;
o1buffer *internal_o1_buffer_375_CH1;
o1buffer *internal_o1_buffer_375_CH2;
o1buffer *internal_o1_buffer_750;
static void LIBUSB_CALL isoCallback(struct libusb_transfer * transfer){
@ -56,7 +59,7 @@ static void LIBUSB_CALL isoCallback(struct libusb_transfer * transfer){
//printf("\n");
}
//TODO: a switch statement here to handle all the modes.
internal_o1_buffer->addVector(packetPointer, 375);
internal_o1_buffer_375_CH1->addVector((char*) packetPointer, 375);
}
//printf("Re-arm the endpoint...\n");
if(usb_iso_needs_rearming()){
@ -97,7 +100,9 @@ usbCallHandler::usbCallHandler(unsigned short VID_in, unsigned short PID_in)
printf("pipeID %d = %d\n", k, pipeID[k]);
}
internal_o1_buffer = new o1buffer();
internal_o1_buffer_375_CH1 = new o1buffer();
internal_o1_buffer_375_CH2 = new o1buffer();
internal_o1_buffer_750 = new o1buffer();
//In case it was deleted before; reset the shared variables.
usb_shutdown_requested = false;
@ -275,7 +280,19 @@ int usbCallHandler::avrDebug(void){
}
std::vector<double>* usbCallHandler::getMany_double(int numToGet, int interval_samples, int delay_sample, int filter_mode){
return internal_o1_buffer->getMany_double(numToGet, interval_samples, delay_sample, filter_mode);
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
#warning ASSUMING MODE 0
return internal_o1_buffer_375_CH1->getMany_double(numToGet, interval_samples, delay_sample, filter_mode);
}
int usbCallHandler::send_device_reset(){
@ -314,6 +331,9 @@ int usbCallHandler::set_gain(double newGain){
gainMask = gainMask << 2;
gainMask |= (gainMask << 8);
send_control_transfer(0x40, 0xa5, deviceMode, gainMask, 0, NULL);
internal_o1_buffer_375_CH1->librador_scope_gain = newGain;
internal_o1_buffer_375_CH2->librador_scope_gain = newGain;
internal_o1_buffer_750->librador_scope_gain = newGain;
return 0;
}