From aeb2d488095963f797523e1e359240eadafc0800 Mon Sep 17 00:00:00 2001 From: Chris Esposito Date: Sat, 7 Apr 2018 14:55:48 +1000 Subject: [PATCH] librador_get_iso_data takes inputs in seconds rather than per-sample. --- .../___librador/demo/librademo/mainwindow.cpp | 2 +- .../___librador/librador/librador.cpp | 14 ++++++++++++-- .../___librador/librador/librador.h | 2 +- .../___librador/librador/usbcallhandler.cpp | 17 +++++++++++++++++ .../___librador/librador/usbcallhandler.h | 1 + 5 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp index 90cd3821..6d2db9ad 100644 --- a/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp +++ b/Matlab_Octave_API/___librador/demo/librademo/mainwindow.cpp @@ -73,7 +73,7 @@ void MainWindow::on_pushButton_4_clicked() void MainWindow::on_pushButton_5_clicked() { - QVector yaxis = QVector::fromStdVector(*(librador_get_iso_data(75000, 1, 1500, 0))); + QVector yaxis = QVector::fromStdVector(*(librador_get_iso_data(0.5, 375000, 0.1, 0))); //qDebug() << yaxis; diff --git a/Matlab_Octave_API/___librador/librador/librador.cpp b/Matlab_Octave_API/___librador/librador/librador.cpp index 2b1bdf81..6f29c8ea 100644 --- a/Matlab_Octave_API/___librador/librador/librador.cpp +++ b/Matlab_Octave_API/___librador/librador/librador.cpp @@ -60,8 +60,18 @@ int librador_avr_debug(){ return internal_librador_object->usb_driver->avrDebug(); } -std::vector * librador_get_iso_data(int numToGet, int interval_samples, int delay_sample, int filter_mode){ - return internal_librador_object->usb_driver->getMany_double(numToGet, interval_samples, delay_sample, filter_mode); +std::vector * librador_get_iso_data(double timeWindow_seconds, double sample_rate_hz, double delay_seconds, int filter_mode){ + double samples_per_second = internal_librador_object->usb_driver->get_samples_per_second(); + + if(samples_per_second == 0){ + return NULL; + } + + + int interval_samples = round(samples_per_second / sample_rate_hz); + int delay_samples = round(delay_seconds * samples_per_second); + int numToGet = round(timeWindow_seconds * samples_per_second); + return internal_librador_object->usb_driver->getMany_double(numToGet, interval_samples, delay_samples, filter_mode); } int librador_reset_usb(){ diff --git a/Matlab_Octave_API/___librador/librador/librador.h b/Matlab_Octave_API/___librador/librador/librador.h index cd9ad6ce..20c76135 100644 --- a/Matlab_Octave_API/___librador/librador/librador.h +++ b/Matlab_Octave_API/___librador/librador/librador.h @@ -34,6 +34,6 @@ uint8_t LIBRADORSHARED_EXPORT librador_get_device_firmware_variant(); //aa //int LIBRADORSHARED_EXPORT librador_kickstart_isochronous_loop(); -std::vector * LIBRADORSHARED_EXPORT librador_get_iso_data(int numToGet, int interval_samples, int delay_sample, int filter_mode); +std::vector * LIBRADORSHARED_EXPORT librador_get_iso_data(double timeWindow_seconds, double sample_rate_hz, double delay_seconds, int filter_mode); #endif // LIBRADOR_H diff --git a/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp b/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp index 97cb6645..788438e0 100644 --- a/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp +++ b/Matlab_Octave_API/___librador/librador/usbcallhandler.cpp @@ -471,3 +471,20 @@ uint8_t usbCallHandler::get_firmware_variant(){ send_control_transfer(0xc0, 0xa9, 0, 0, 1, NULL); return *((uint8_t *) inBuffer); } + +double usbCallHandler::get_samples_per_second(){ + switch(deviceMode){ + case 0: + return (double)(375000.0); + case 1: + return (double)(375000.0); + case 2: + return (double)(375000.0); + case 6: + return (double)(750000.0); + case 7: + return (double)(375000.0); + default: + return 0; + } +} diff --git a/Matlab_Octave_API/___librador/librador/usbcallhandler.h b/Matlab_Octave_API/___librador/librador/usbcallhandler.h index 73fec559..732f16a7 100644 --- a/Matlab_Octave_API/___librador/librador/usbcallhandler.h +++ b/Matlab_Octave_API/___librador/librador/usbcallhandler.h @@ -58,6 +58,7 @@ public: int send_control_transfer(uint8_t RequestType, uint8_t Request, uint16_t Value, uint16_t Index, uint16_t Length, unsigned char *LDATA); int avrDebug(void); int send_device_reset(); + double get_samples_per_second(); std::vector *getMany_double(int numToGet, int interval_samples, int delay_sample, int filter_mode); bool connected; //Control Command Vars