diff options
author | Joseph W. Joshua <joejoshw@gmail.com> | 2014-05-30 09:56:27 +0300 |
---|---|---|
committer | Thiago Macieira <thiago@macieira.org> | 2014-08-09 12:01:54 -0300 |
commit | a7c9b25b053ee77a816e1555f1c00c3e4b996396 (patch) | |
tree | 463cade2b4ceffd63f2f9ca4bd00cb5b34e8b306 /qt-ui | |
parent | 791fbee260b3b0884963b8ff0e2e2968ef130792 (diff) | |
download | subsurface-a7c9b25b053ee77a816e1555f1c00c3e4b996396.tar.gz |
Read basic details from dive computer
Added classes for reading data from dive computer. This is
at the basic level and I will expand it as I go along.
Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com>
Signed-off-by: Thiago Macieira <thiago@macieira.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/configuredivecomputer.cpp | 74 | ||||
-rw-r--r-- | qt-ui/configuredivecomputer.h | 58 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.cpp | 48 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.h | 11 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.ui | 17 |
5 files changed, 208 insertions, 0 deletions
diff --git a/qt-ui/configuredivecomputer.cpp b/qt-ui/configuredivecomputer.cpp new file mode 100644 index 000000000..d02ceffb7 --- /dev/null +++ b/qt-ui/configuredivecomputer.cpp @@ -0,0 +1,74 @@ +#include "configuredivecomputer.h" +#include "libdivecomputer/hw.h" +#include <QDebug> +ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) : + QObject(parent), + readThread(0) +{ + setState(INITIAL); +} + +void ConfigureDiveComputer::readSettings(device_data_t *data) +{ + setState(READING); + + if (readThread) + readThread->deleteLater(); + + readThread = new ReadSettingsThread(this, data); + connect (readThread, SIGNAL(finished()), + this, SLOT(readThreadFinished()), Qt::QueuedConnection); + connect (readThread, SIGNAL(error(QString)), this, SLOT(setError(QString))); + + readThread->start(); +} + +void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState) +{ + currentState = newState; + emit stateChanged(currentState); +} + +void ConfigureDiveComputer::setError(QString err) +{ + lastError = err; + emit error(err); +} + +void ConfigureDiveComputer::readHWSettings(device_data_t *data) +{ + +} + +void ConfigureDiveComputer::readThreadFinished() +{ + setState(DONE); + emit deviceSettings(readThread->result); +} + +ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) + : QThread(parent), data(data) +{ + +} + +void ReadSettingsThread::run() +{ + QString vendor = data->vendor; + dc_status_t rc; + rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname); + if (rc == DC_STATUS_SUCCESS) { + if (vendor.trimmed() == "Heinrichs Weikamp") { + unsigned char hw_data[10]; + hw_frog_device_version(data->device, hw_data, 10); + QTextStream (&result) << "Device Version: " << hw_data; //just a test. I will work on decoding this + } else { + lastError = tr("This feature is not yet available for the selected dive computer."); + emit error(lastError); + } + dc_device_close(data->device); + } else { + lastError = tr("Could not a establish connection to the dive computer."); + emit error(lastError); + } +} diff --git a/qt-ui/configuredivecomputer.h b/qt-ui/configuredivecomputer.h new file mode 100644 index 000000000..8441c0cec --- /dev/null +++ b/qt-ui/configuredivecomputer.h @@ -0,0 +1,58 @@ +#ifndef CONFIGUREDIVECOMPUTER_H +#define CONFIGUREDIVECOMPUTER_H + +#include <QObject> +#include <QThread> +#include "libdivecomputer.h" + +class ReadSettingsThread : public QThread { + Q_OBJECT +public: + ReadSettingsThread(QObject *parent, device_data_t *data); + virtual void run(); + QString result; + QString lastError; +signals: + void error(QString err); +private: + device_data_t *data; +}; + +class ConfigureDiveComputer : public QObject +{ + Q_OBJECT +public: + explicit ConfigureDiveComputer(QObject *parent = 0); + void readSettings(device_data_t *data); + + enum states { + INITIAL, + READING, + WRITING, + CANCELLING, + CANCELLED, + ERROR, + DONE, + }; + + QString lastError; + states currentState; +signals: + void deviceSettings(QString settings); + void message(QString msg); + void error(QString err); + void readFinished(); + void writeFinished(); + void stateChanged(states newState); +private: + ReadSettingsThread *readThread; + void setState(states newState); + + + void readHWSettings(device_data_t *data); +private slots: + void readThreadFinished(); + void setError(QString err); +}; + +#endif // CONFIGUREDIVECOMPUTER_H diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index 0af50b755..53544575c 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -6,6 +6,7 @@ #include "../helpers.h" #include "../display.h" #include "../divelist.h" +#include "configuredivecomputer.h" struct product { const char *product; dc_descriptor_t *descriptor; @@ -28,11 +29,17 @@ struct mydescriptor { ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigureDiveComputerDialog), + config(0), vendorModel(0), productModel(0) { ui->setupUi(this); + config = new ConfigureDiveComputer(this); + connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString))); + connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString))); + connect (config, SIGNAL(deviceSettings(QString)), ui->availableDetails, SLOT(setText(QString))); + fill_computer_list(); vendorModel = new QStringListModel(vendorList); @@ -46,6 +53,10 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : } if (default_dive_computer_device) ui->device->setEditText(default_dive_computer_device); + + memset(&device_data, 0, sizeof(device_data)); + + connect (ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings())); } ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog() @@ -137,3 +148,40 @@ void ConfigureDiveComputerDialog::on_product_currentIndexChanged(const QString & ui->device->setEnabled(false); } } + +void ConfigureDiveComputerDialog::readSettings() +{ + ui->statusLabel->clear(); + ui->errorLabel->clear(); + + getDeviceData(); + config->readSettings(&device_data); +} + +void ConfigureDiveComputerDialog::configMessage(QString msg) +{ + ui->statusLabel->setText(msg); +} + +void ConfigureDiveComputerDialog::configError(QString err) +{ + ui->errorLabel->setText(err); +} + +void ConfigureDiveComputerDialog::getDeviceData() +{ + device_data.devname = strdup(ui->device->currentText().toUtf8().data()); + device_data.vendor = strdup(ui->vendor->currentText().toUtf8().data()); + device_data.product = strdup(ui->product->currentText().toUtf8().data()); + + device_data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()]; + device_data.deviceid = device_data.diveid = 0; + + set_default_dive_computer(device_data.vendor, device_data.product); + set_default_dive_computer_device(device_data.devname); +} + +void ConfigureDiveComputerDialog::on_cancel_clicked() +{ + this->close(); +} diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h index 4f4fbb36c..116968b79 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/qt-ui/configuredivecomputerdialog.h @@ -4,6 +4,9 @@ #include <QDialog> #include <QStringListModel> #include "../libdivecomputer.h" + +class ConfigureDiveComputer; + namespace Ui { class ConfigureDiveComputerDialog; } @@ -21,9 +24,17 @@ private slots: void on_product_currentIndexChanged(const QString &product); + void readSettings(); + void configMessage(QString msg); + void configError(QString err); + void on_cancel_clicked(); private: Ui::ConfigureDiveComputerDialog *ui; + ConfigureDiveComputer *config; + device_data_t device_data; + void getDeviceData(); + QStringList vendorList; QHash<QString, QStringList> productList; QHash<QString, dc_descriptor_t *> descriptorLookup; diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui index 25d63007f..fe36512b2 100644 --- a/qt-ui/configuredivecomputerdialog.ui +++ b/qt-ui/configuredivecomputerdialog.ui @@ -95,6 +95,23 @@ <widget class="QTextBrowser" name="availableDetails"/> </item> <item> + <widget class="QLabel" name="errorLabel"> + <property name="styleSheet"> + <string notr="true">color: rgb(242, 19, 25);</string> + </property> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="statusLabel"> + <property name="text"> + <string/> + </property> + </widget> + </item> + <item> <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> <spacer name="horizontalSpacer_2"> |