summaryrefslogtreecommitdiffstats
path: root/qt-ui/configuredivecomputer.cpp
diff options
context:
space:
mode:
authorGravatar Joseph W. Joshua <joejoshw@gmail.com>2014-05-30 09:56:27 +0300
committerGravatar Thiago Macieira <thiago@macieira.org>2014-08-09 12:01:54 -0300
commita7c9b25b053ee77a816e1555f1c00c3e4b996396 (patch)
tree463cade2b4ceffd63f2f9ca4bd00cb5b34e8b306 /qt-ui/configuredivecomputer.cpp
parent791fbee260b3b0884963b8ff0e2e2968ef130792 (diff)
downloadsubsurface-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/configuredivecomputer.cpp')
-rw-r--r--qt-ui/configuredivecomputer.cpp74
1 files changed, 74 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);
+ }
+}