Less crashes.

This commit is contained in:
Chris Esposito 2018-04-24 15:03:16 +10:00
parent 669a2a6f94
commit 494b0f2a36
5 changed files with 72 additions and 7 deletions

View File

@ -75,11 +75,11 @@ void MainWindow::on_pushButton_5_clicked()
{
double sampleRate = 375000;
if((current_channel == 1) || (current_channel == 2)){
std::vector<double> *from_librador = (librador_get_analog_data(current_channel, 0.05, sampleRate, 0.1, 0));
std::vector<double> *from_librador = (librador_get_analog_data(current_channel, 1, sampleRate, 0.1, 0));
plot_from_librador(from_librador, sampleRate, ui->widget->graph(0));
} else {
std::vector<double> *from_librador_ch1 = (librador_get_analog_data(1, 0.05, sampleRate, 0.1, 0));
std::vector<double> *from_librador_ch2 = (librador_get_analog_data(2, 0.05, sampleRate, 0.1, 0));
std::vector<double> *from_librador_ch1 = (librador_get_analog_data(1, 1, sampleRate, 0.1, 0));
std::vector<double> *from_librador_ch2 = (librador_get_analog_data(2, 1, sampleRate, 0.1, 0));
plot_from_librador(from_librador_ch1, sampleRate, ui->widget->graph(0));
plot_from_librador(from_librador_ch2, sampleRate, ui->widget->graph(1));
}
@ -198,11 +198,18 @@ void MainWindow::on_pushButton_14_clicked()
if((current_channel == 1) || (current_channel == 2)){
std::vector<double> *from_librador = (librador_get_analog_data_sincelast(current_channel, 10, sampleRate, 0.1, 0));
plot_from_librador(from_librador, sampleRate, ui->widget->graph(0));
} else {
std::vector<double> *from_librador_ch1 = (librador_get_analog_data_sincelast(1, 10, sampleRate, 0.1, 0));
std::vector<double> *from_librador_ch2 = (librador_get_analog_data_sincelast(2, 10, sampleRate, 0.1, 0));
plot_from_librador(from_librador_ch1, sampleRate, ui->widget->graph(0));
plot_from_librador(from_librador_ch2, sampleRate, ui->widget->graph(1));
}
}
void MainWindow::plot_from_librador(std::vector<double> *from_librador, double sampleRate, QCPGraph *graph)
{
qDebug() << "check1";
if(from_librador == NULL){
qDebug() << "from_librador NULL!";
return;

View File

@ -738,7 +738,37 @@ librador.o: librador.cpp librador.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qversiontagging.h \
librador_internal.h \
usbcallhandler.h \
../../../Desktop_Interface/build_linux/libusb/libusb.h
../../../Desktop_Interface/build_linux/libusb/libusb.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/QThread \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qthread.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobject.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobjectdefs.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qnamespace.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobjectdefs_impl.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstring.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qchar.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qbytearray.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qrefcount.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qarraydata.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringliteral.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringalgorithms.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringview.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringbuilder.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qlist.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qalgorithms.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qiterator.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qhashfunctions.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qpair.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qbytearraylist.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringlist.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qregexp.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qstringmatcher.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qcoreevent.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qscopedpointer.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qmetatype.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qvarlengtharray.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qcontainerfwd.h \
/home/esposch/Qt/5.10.0/gcc_64/include/QtCore/qobject_impl.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o librador.o librador.cpp
o1buffer.o: o1buffer.cpp o1buffer.h

View File

@ -58,10 +58,14 @@ int librador_setup_usb(){
int librador_avr_debug(){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->avrDebug();
}
std::vector<double> * librador_get_analog_data(int channel, double timeWindow_seconds, double sample_rate_hz, double delay_seconds, int filter_mode){
VECTOR_API_INIT_CHECK
VECTOR_USB_INIT_CHECK
double samples_per_second = internal_librador_object->usb_driver->get_samples_per_second();
if(samples_per_second == 0){
@ -77,6 +81,10 @@ std::vector<double> * librador_get_analog_data(int channel, double timeWindow_se
}
std::vector<double> * librador_get_analog_data_sincelast(int channel, double timeWindow_max_seconds, double sample_rate_hz, double delay_seconds, int filter_mode){
VECTOR_API_INIT_CHECK
VECTOR_USB_INIT_CHECK
double samples_per_second = internal_librador_object->usb_driver->get_samples_per_second();
if(samples_per_second == 0){
@ -94,6 +102,7 @@ std::vector<double> * librador_get_analog_data_sincelast(int channel, double tim
int librador_reset_usb(){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
delete internal_librador_object->usb_driver;
internal_librador_object->usb_driver = new usbCallHandler(LABRADOR_VID, LABRADOR_PID);
return 0;
@ -101,6 +110,7 @@ int librador_reset_usb(){
int librador_update_signal_gen_settings(int channel, unsigned char *sampleBuffer, int numSamples, double usecs_between_samples, double amplitude_v, double offset_v){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
int error = internal_librador_object->usb_driver->update_function_gen_settings(channel, sampleBuffer, numSamples, usecs_between_samples, amplitude_v, offset_v);
if(error){
return error-1000;
@ -109,21 +119,25 @@ int librador_update_signal_gen_settings(int channel, unsigned char *sampleBuffer
int librador_set_power_supply_voltage(double voltage){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->set_psu_voltage(voltage);
}
int librador_set_device_mode(int mode){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->set_device_mode(mode);
}
int librador_set_oscilloscope_gain(double gain){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->set_gain(gain);
}
int librador_set_digital_out(int channel, bool state_on){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
static uint8_t channelStates[4] = {0, 0, 0, 0};
channel--;
if((channel < 0) || (channel > 3)){
@ -136,21 +150,25 @@ int librador_set_digital_out(int channel, bool state_on){
int librador_reset_device(){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->reset_device(false);
}
int librador_jump_to_bootloader(){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->reset_device(true);
}
uint16_t librador_get_device_firmware_version(){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->get_firmware_version();
}
uint8_t librador_get_device_firmware_variant(){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return internal_librador_object->usb_driver->get_firmware_variant();
}
@ -186,6 +204,8 @@ unsigned char generator_triangle(double x)
int send_convenience_waveform(int channel, double frequency_Hz, double amplitude_v, double offset_v, unsigned char (*sample_generator)(double))
{
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
if((amplitude_v + offset_v) > 9.6){
return -1;
//Voltage range too high
@ -224,21 +244,25 @@ int send_convenience_waveform(int channel, double frequency_Hz, double amplitude
int librador_send_sin_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_sin);
}
int librador_send_square_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_square);
}
int librador_send_triangle_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_triangle);
}
int librador_send_sawtooth_wave(int channel, double frequency_Hz, double amplitude_v, double offset_v){
CHECK_API_INITIALISED
CHECK_USB_INITIALISED
return send_convenience_waveform(channel, frequency_Hz, amplitude_v, offset_v, generator_sawtooth);
}

View File

@ -7,6 +7,11 @@
#define LABRADOR_PID 0xba94
#define CHECK_API_INITIALISED if(internal_librador_object == NULL) return -420;
#define CHECK_USB_INITIALISED if(!internal_librador_object->usb_driver->connected) return -420420;
#define VECTOR_API_INIT_CHECK if(internal_librador_object == NULL) return NULL;
#define VECTOR_USB_INIT_CHECK if(!internal_librador_object->usb_driver->connected) return NULL;
class usbCallHandler;

View File

@ -298,7 +298,7 @@ int usbCallHandler::avrDebug(void){
}
std::vector<double>* usbCallHandler::getMany_double(int channel, int numToGet, int interval_samples, int delay_sample, int filter_mode){
std::vector<double>* temp_to_return;
std::vector<double>* temp_to_return = NULL;
buffer_read_write_mutex.lock();
switch(deviceMode){
@ -327,8 +327,7 @@ buffer_read_write_mutex.lock();
}
std::vector<double> *usbCallHandler::getMany_sincelast(int channel, int feasible_window_begin, int feasible_window_end, int interval_samples, int filter_mode){
std::vector<double>* temp_to_return;
std::vector<double>* temp_to_return = NULL;
buffer_read_write_mutex.lock();
switch(deviceMode){
case 0: