From d771678c5552b2c4bccb76d780b528bc630cad58 Mon Sep 17 00:00:00 2001 From: Chris Esposito Date: Sat, 7 Apr 2018 12:26:53 +1000 Subject: [PATCH] librador_get_iso_data now returns volts (plus other minor fixes) --- .../___librador/demo/librademo/mainwindow.cpp | 15 ++- .../___librador/demo/librademo/mainwindow.h | 3 + .../___librador/demo/librademo/mainwindow.ui | 110 ++++++++++++++---- .../demo/librademo/moc_mainwindow.cpp | 50 ++++---- .../demo/librademo/ui_mainwindow.h | 55 ++++++++- .../___librador/librador/o1buffer.cpp | 22 +++- .../___librador/librador/o1buffer.h | 20 +++- .../___librador/librador/usbcallhandler.cpp | 28 ++++- 8 files changed, 242 insertions(+), 61 deletions(-) diff --git a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp index ebc7b6a6..90cd3821 100644 --- a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp +++ b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp @@ -75,7 +75,7 @@ void MainWindow::on_pushButton_5_clicked() QVector yaxis = QVector::fromStdVector(*(librador_get_iso_data(75000, 1, 1500, 0))); - qDebug() << yaxis; + //qDebug() << yaxis; QVector xaxis; for (int i=0; iwidget->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); +} diff --git a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.h b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.h index 41f20c08..3e52e752 100644 --- a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.h +++ b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.h @@ -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; }; diff --git a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.ui b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.ui index ce7a3704..5e2fe80c 100644 --- a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.ui +++ b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.ui @@ -88,32 +88,94 @@ - - - Digital Out 1 - - + + + + + Digital Out 1 + + + + + + + Digital Out 2 + + + + + + + Digital Out 3 + + + + + + + Digital Out 4 + + + + - - - Digital Out 2 - - - - - - - Digital Out 3 - - - - - - - Digital Out 4 - - + + + + + Set Gain: + + + + + + + 1 + + + + 0.5 + + + + + 1 + + + + + 2 + + + + + 4 + + + + + 8 + + + + + 16 + + + + + 32 + + + + + 64 + + + + + diff --git a/Matlab_Octave_API/___librador/demo/librademo/moc_mainwindow.cpp b/Matlab_Octave_API/___librador/demo/librademo/moc_mainwindow.cpp index 1a0ad448..3791745e 100644 --- a/Matlab_Octave_API/___librador/demo/librademo/moc_mainwindow.cpp +++ b/Matlab_Octave_API/___librador/demo/librademo/moc_mainwindow.cpp @@ -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(_a[0]) = -1; - _id -= 13; + _id -= 14; } return _id; } diff --git a/Matlab_Octave_API/___librador/demo/librademo/ui_mainwindow.h b/Matlab_Octave_API/___librador/demo/librademo/ui_mainwindow.h index 53ab4244..01b41bb5 100644 --- a/Matlab_Octave_API/___librador/demo/librademo/ui_mainwindow.h +++ b/Matlab_Octave_API/___librador/demo/librademo/ui_mainwindow.h @@ -14,9 +14,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -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 diff --git a/Matlab_Octave_API/___librador/librador/o1buffer.cpp b/Matlab_Octave_API/___librador/librador/o1buffer.cpp index 1829af13..d6b21543 100644 --- a/Matlab_Octave_API/___librador/librador/o1buffer.cpp +++ b/Matlab_Octave_API/___librador/librador/o1buffer.cpp @@ -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; +} + diff --git a/Matlab_Octave_API/___librador/librador/o1buffer.h b/Matlab_Octave_API/___librador/librador/o1buffer.h index 618fd13e..5e354d9c 100644 --- a/Matlab_Octave_API/___librador/librador/o1buffer.h +++ b/Matlab_Octave_API/___librador/librador/o1buffer.h @@ -4,7 +4,7 @@ #include #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 *getMany_double(int numToGet, int interval_samples, int delay_sample, int filter_mode); std::vector *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 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 diff --git a/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp b/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp index 081c16c3..97cb6645 100644 --- a/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp +++ b/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp @@ -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* 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; }