From 2bf709b09fc31ae0b7c40e848b0827acd3e43efb Mon Sep 17 00:00:00 2001 From: Teuniz Date: Tue, 2 Jun 2015 09:54:41 +0200 Subject: [PATCH] Work in progress. --- dsremote.pro | 2 ++ global.h | 3 +++ mainwindow.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- mainwindow.h | 3 +++ 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/dsremote.pro b/dsremote.pro index 31befcf..2f19a50 100644 --- a/dsremote.pro +++ b/dsremote.pro @@ -25,6 +25,7 @@ HEADERS += tmc_dev.h HEADERS += tled.h HEADERS += edflib.h HEADERS += signalcurve.h +HEADERS += select_device_dialog.h SOURCES += main.cpp SOURCES += mainwindow.cpp @@ -37,6 +38,7 @@ SOURCES += tmc_dev.c SOURCES += tled.cpp SOURCES += edflib.c SOURCES += signalcurve.cpp +SOURCES += select_device_dialog.cpp RESOURCES = images.qrc diff --git a/global.h b/global.h index 9b2f7fb..3c37904 100644 --- a/global.h +++ b/global.h @@ -75,6 +75,9 @@ struct device_settings { int connected; char modelname[128]; + char serialnr[128]; + char softwvers[128]; + double samplerate; // Samplefrequency int memdepth; // Number of waveform points that the oscilloscope can store in a single trigger sample int channel_cnt; // Device has 2 or 4 channels diff --git a/mainwindow.cpp b/mainwindow.cpp index 6127811..b617da4 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -55,6 +55,10 @@ UI_Mainwindow::UI_Mainwindow() setlocale(LC_NUMERIC, "C"); + QCoreApplication::setOrganizationName("TvB"); + QCoreApplication::setOrganizationDomain("teuniz.net"); + QCoreApplication::setApplicationName(PROGRAM_NAME); + memset(&devparms, 0, sizeof(struct device_settings)); devparms.screenshot_buf = (char *)malloc(1024 * 1024 * 2); @@ -70,8 +74,7 @@ UI_Mainwindow::UI_Mainwindow() devicemenu->setTitle("Device"); devicemenu->addAction("Connect", this, SLOT(open_connection())); devicemenu->addAction("Disconnect", this, SLOT(close_connection())); -// devicemenu->addAction("Save waveform", this, SLOT(save_waveform())); -// devicemenu->addAction("Save screenshot", this, SLOT(save_screenshot())); + devicemenu->addAction("Select", this, SLOT(select_device())); devicemenu->addAction("Exit", this, SLOT(close()), QKeySequence::Quit); menubar->addMenu(devicemenu); @@ -396,20 +399,37 @@ UI_Mainwindow::~UI_Mainwindow() } +void UI_Mainwindow::select_device() +{ + UI_select_device_window sel_device; +} + + void UI_Mainwindow::open_connection() { int n; char str[1024], - dev_str[128] = {"/dev/usbtmc0"}, + dev_str[128] = {""}, resp_str[1024], *ptr; + QSettings settings; + if(device != NULL) { return; } + strcpy(dev_str, settings.value("connection/device").toString().toLocal8Bit().data()); + + if(!strcmp(dev_str, "")) + { + strcpy(dev_str, "/dev/usbtmc0"); + + settings.setValue("connection/device", dev_str); + } + device = tmcdev_open(dev_str); if(device == NULL) { @@ -473,6 +493,26 @@ void UI_Mainwindow::open_connection() goto OUT_ERROR; } + ptr = strtok(NULL, ","); + if(ptr == NULL) + { + snprintf(str, 1024, "Received an unknown identification string from device:\n\n%s\n ", device->buf); + str[1023] = 0; + goto OUT_ERROR; + } + + strcpy(devparms.serialnr, ptr); + + ptr = strtok(NULL, ","); + if(ptr == NULL) + { + snprintf(str, 1024, "Received an unknown identification string from device:\n\n%s\n ", device->buf); + str[1023] = 0; + goto OUT_ERROR; + } + + strcpy(devparms.softwvers, ptr); + if(strncmp(devparms.modelname, "DS6", 3)) { QMessageBox msgBox; @@ -553,6 +593,10 @@ void UI_Mainwindow::open_connection() connect(trigAdjustDial, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(trigAdjustDialClicked(QPoint))); connect(adjDial, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(adjustDialClicked(QPoint))); + sprintf(str, PROGRAM_NAME " " PROGRAM_VERSION " %s %s", devparms.serialnr, devparms.softwvers); + + setWindowTitle(str); + statusLabel->setText("Connected"); devparms.connected = 1; @@ -594,6 +638,8 @@ void UI_Mainwindow::close_connection() adjdial_timer->stop(); + setWindowTitle(PROGRAM_NAME " " PROGRAM_VERSION); + disconnect(adjDial, SIGNAL(valueChanged(int)), this, SLOT(adjDialChanged(int))); disconnect(trigAdjustDial, SIGNAL(valueChanged(int)), this, SLOT(trigAdjustDialChanged(int))); disconnect(horScaleDial, SIGNAL(valueChanged(int)), this, SLOT(horScaleDialChanged(int))); @@ -1896,4 +1942,3 @@ void UI_Mainwindow::get_device_model(const char *str) - diff --git a/mainwindow.h b/mainwindow.h index ca05658..0b771bd 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -59,6 +59,7 @@ #include #include #include +#include #include #include @@ -75,6 +76,7 @@ #include "tled.h" #include "edflib.h" #include "signalcurve.h" +#include "select_device_dialog.h" @@ -202,6 +204,7 @@ private slots: void show_about_dialog(); void open_connection(); void close_connection(); + void select_device(); int get_device_settings(); void save_waveform(); void save_screenshot();