From ec02737eda780284562692168569d9dd3837a1a9 Mon Sep 17 00:00:00 2001 From: "Joseph W. Joshua" Date: Thu, 29 May 2014 18:54:19 +0300 Subject: Create Dive Computer configuration dialog Create a dialog for reading and writing settings to and from dive computers, with a menu entry in MainWindow to open the dialog. I will build up on this dialog and change it as needed. Signed-off-by: Joseph W. Joshua Signed-off-by: Thiago Macieira --- subsurface.pro | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'subsurface.pro') diff --git a/subsurface.pro b/subsurface.pro index 1857f8405..ca3c8abdf 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -86,7 +86,8 @@ HEADERS = \ qt-ui/updatemanager.h \ qt-ui/divelogexportdialog.h \ qt-ui/usersurvey.h \ - subsurfacesysinfo.h + subsurfacesysinfo.h \ + qt-ui/configuredivecomputerdialog.h android: HEADERS -= \ qt-ui/usermanual.h \ @@ -165,7 +166,8 @@ SOURCES = \ qt-ui/updatemanager.cpp \ qt-ui/divelogexportdialog.cpp \ qt-ui/usersurvey.cpp \ - subsurfacesysinfo.cpp + subsurfacesysinfo.cpp \ + qt-ui/configuredivecomputerdialog.cpp android: SOURCES += android.cpp else: linux*: SOURCES += linux.c @@ -196,7 +198,8 @@ FORMS = \ qt-ui/searchbar.ui \ qt-ui/divelogexportdialog.ui \ qt-ui/plannerSettings.ui \ - qt-ui/usersurvey.ui + qt-ui/usersurvey.ui \ + qt-ui/configuredivecomputerdialog.ui # Nether usermanual or printing is supported on android right now android: FORMS -= qt-ui/printoptions.ui -- cgit v1.2.3-70-g09d2 From a7c9b25b053ee77a816e1555f1c00c3e4b996396 Mon Sep 17 00:00:00 2001 From: "Joseph W. Joshua" Date: Fri, 30 May 2014 09:56:27 +0300 Subject: 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 Signed-off-by: Thiago Macieira --- qt-ui/configuredivecomputer.cpp | 74 +++++++++++++++++++++++++++++++++++ qt-ui/configuredivecomputer.h | 58 +++++++++++++++++++++++++++ qt-ui/configuredivecomputerdialog.cpp | 48 +++++++++++++++++++++++ qt-ui/configuredivecomputerdialog.h | 11 ++++++ qt-ui/configuredivecomputerdialog.ui | 17 ++++++++ subsurface.pro | 6 ++- 6 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 qt-ui/configuredivecomputer.cpp create mode 100644 qt-ui/configuredivecomputer.h (limited to 'subsurface.pro') 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 +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 +#include +#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 #include #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 productList; QHash 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 @@ -94,6 +94,23 @@ + + + + color: rgb(242, 19, 25); + + + + + + + + + + + + + diff --git a/subsurface.pro b/subsurface.pro index ca3c8abdf..b532e3c99 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -87,7 +87,8 @@ HEADERS = \ qt-ui/divelogexportdialog.h \ qt-ui/usersurvey.h \ subsurfacesysinfo.h \ - qt-ui/configuredivecomputerdialog.h + qt-ui/configuredivecomputerdialog.h \ + qt-ui/configuredivecomputer.h \ android: HEADERS -= \ qt-ui/usermanual.h \ @@ -167,7 +168,8 @@ SOURCES = \ qt-ui/divelogexportdialog.cpp \ qt-ui/usersurvey.cpp \ subsurfacesysinfo.cpp \ - qt-ui/configuredivecomputerdialog.cpp + qt-ui/configuredivecomputerdialog.cpp \ + qt-ui/configuredivecomputer.cpp android: SOURCES += android.cpp else: linux*: SOURCES += linux.c -- cgit v1.2.3-70-g09d2 From 4fc16b16749a73b8c06d41cb7cb22b78c77ab29e Mon Sep 17 00:00:00 2001 From: "Joseph W. Joshua" Date: Tue, 10 Jun 2014 15:03:26 +0300 Subject: Move divecomputer configuration code to different files This splits the code in configuredivecomputer.cpp into multiple files. The read and write threads are moved to configuredivecomputerthreads.h/cpp, and the device details class is moved to devicedetails.h/.cpp Signed-off-by: Joseph W. Joshua Signed-off-by: Thiago Macieira --- qt-ui/configuredivecomputer.cpp | 141 ++------------------------------- qt-ui/configuredivecomputer.h | 40 ++-------- qt-ui/configuredivecomputerdialog.cpp | 36 +++------ qt-ui/configuredivecomputerdialog.h | 13 ++- qt-ui/configuredivecomputerdialog.ui | 127 +++++++++++++++++++++++------ qt-ui/configuredivecomputerthreads.cpp | 81 +++++++++++++++++++ qt-ui/configuredivecomputerthreads.h | 42 ++++++++++ qt-ui/devicedetails.cpp | 88 ++++++++++++++++++++ qt-ui/devicedetails.h | 54 +++++++++++++ subsurface.pro | 6 +- 10 files changed, 403 insertions(+), 225 deletions(-) create mode 100644 qt-ui/configuredivecomputerthreads.cpp create mode 100644 qt-ui/configuredivecomputerthreads.h create mode 100644 qt-ui/devicedetails.cpp create mode 100644 qt-ui/devicedetails.h (limited to 'subsurface.pro') diff --git a/qt-ui/configuredivecomputer.cpp b/qt-ui/configuredivecomputer.cpp index 8cc3a6953..d24c8905d 100644 --- a/qt-ui/configuredivecomputer.cpp +++ b/qt-ui/configuredivecomputer.cpp @@ -4,19 +4,21 @@ ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) : QObject(parent), readThread(0), - writeThread(0) + writeThread(0), + m_deviceDetails(0) { setState(INITIAL); } -void ConfigureDiveComputer::readSettings(device_data_t *data) +void ConfigureDiveComputer::readSettings(DeviceDetails *deviceDetails, device_data_t *data) { setState(READING); + m_deviceDetails = deviceDetails; if (readThread) readThread->deleteLater(); - readThread = new ReadSettingsThread(this, data); + readThread = new ReadSettingsThread(this, deviceDetails, data); connect (readThread, SIGNAL(finished()), this, SLOT(readThreadFinished()), Qt::QueuedConnection); connect (readThread, SIGNAL(error(QString)), this, SLOT(setError(QString))); @@ -24,19 +26,9 @@ void ConfigureDiveComputer::readSettings(device_data_t *data) readThread->start(); } -void ConfigureDiveComputer::setDeviceName(device_data_t *data, QString newName) +void ConfigureDiveComputer::saveDeviceDetails() { - writeSettingToDevice(data, "Name", newName); -} - -void ConfigureDiveComputer::setDeviceDateAndTime(device_data_t *data, QDateTime dateAndTime) -{ - writeSettingToDevice(data, "DateAndTime", dateAndTime); -} -void ConfigureDiveComputer::setDeviceBrightness(device_data_t *data, int brighnessLevel) -{ - writeSettingToDevice(data, "Brightness", brighnessLevel); } void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState) @@ -45,20 +37,6 @@ void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState) emit stateChanged(currentState); } -void ConfigureDiveComputer::writeSettingToDevice(device_data_t *data, QString settingName, QVariant settingValue) -{ - setState(READING); - - if (writeThread) - writeThread->deleteLater(); - - writeThread = new WriteSettingsThread(this, data, settingName, settingValue); - connect (writeThread, SIGNAL(error(QString)), this, SLOT(setError(QString))); - connect (writeThread, SIGNAL(finished()), this, SLOT(writeThreadFinished())); - - writeThread->start(); -} - void ConfigureDiveComputer::setError(QString err) { lastError = err; @@ -68,7 +46,7 @@ void ConfigureDiveComputer::setError(QString err) void ConfigureDiveComputer::readThreadFinished() { setState(DONE); - emit deviceSettings(readThread->result); + emit readFinished(); } void ConfigureDiveComputer::writeThreadFinished() @@ -79,108 +57,3 @@ void ConfigureDiveComputer::writeThreadFinished() emit message(tr("Setting successfully written to device")); } } - -ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) - : QThread(parent), data(data) -{ - -} - -void ReadSettingsThread::run() -{ - dc_status_t rc; - rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname); - if (rc == DC_STATUS_SUCCESS) { - if (dc_device_get_type(data->device) == DC_FAMILY_HW_OSTC3) { - unsigned char hw_data[10]; - hw_ostc3_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); - } -} - -WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data, QString settingName, QVariant settingValue) - : QThread(parent), data(data), m_settingName(settingName), m_settingValue(settingValue) -{ - -} - -void WriteSettingsThread::run() -{ - bool supported = false; - dc_status_t rc; - rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname); - if (rc == DC_STATUS_SUCCESS) { - dc_status_t result; - if (m_settingName == "Name") { - switch (dc_device_get_type(data->device)) { - case DC_FAMILY_HW_OSTC3: - supported = true; - result = hw_ostc3_device_customtext(data->device, m_settingValue.toByteArray().data()); - break; - case DC_FAMILY_HW_FROG: - supported = true; - result = hw_frog_device_customtext(data->device, m_settingValue.toByteArray().data()); - break; - } - } - if (m_settingName == "DateAndTime") { - QDateTime timeToSet = m_settingValue.toDateTime(); - dc_datetime_t time; - time.year = timeToSet.date().year(); - time.month = timeToSet.date().month(); - time.day = timeToSet.date().day(); - time.hour = timeToSet.time().hour(); - time.minute = timeToSet.time().minute(); - time.second = timeToSet.time().second(); - - switch (dc_device_get_type(data->device)) { - case DC_FAMILY_HW_OSTC3: - supported = true; - result = hw_ostc3_device_clock(data->device, &time); - break; - case DC_FAMILY_HW_OSTC: - supported = true; - result = hw_ostc_device_clock(data->device, &time); - break; - case DC_FAMILY_HW_FROG: - supported = true; - result = hw_frog_device_clock(data->device, &time); - break; - } - } - if (m_settingName == "Brightness") { - switch (dc_device_get_type(data->device)) { - case DC_FAMILY_HW_OSTC3: - qDebug() << "Brightness"; - supported = true; - unsigned char packet[1] = { m_settingValue.toInt() }; - result = hw_ostc3_device_config_write(data->device, 0x2D, packet, sizeof (packet)); - break; - } - } - qDebug() << result; - if (result != DC_STATUS_SUCCESS) { - qDebug() << result; - lastError = tr("An error occurred while sending data to the dive computer."); - //Todo Update this message to change depending on actual result. - - emit error(lastError); - } - dc_device_close(data->device); - } else { - lastError = tr("Could not a establish connection to the dive computer."); - emit error(lastError); - } - if (!supported) { - lastError = tr("This feature is not yet available for the selected dive computer."); - emit error(lastError); - } -} diff --git a/qt-ui/configuredivecomputer.h b/qt-ui/configuredivecomputer.h index 08c4e190f..65ceaa780 100644 --- a/qt-ui/configuredivecomputer.h +++ b/qt-ui/configuredivecomputer.h @@ -5,41 +5,15 @@ #include #include #include "libdivecomputer.h" +#include "configuredivecomputerthreads.h" #include -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 WriteSettingsThread : public QThread { - Q_OBJECT -public: - WriteSettingsThread(QObject *parent, device_data_t *data, QString settingName, QVariant settingValue); - virtual void run(); - QString result; - QString lastError; -signals: - void error(QString err); -private: - device_data_t *data; - QString m_settingName; - QVariant m_settingValue; -}; class ConfigureDiveComputer : public QObject { Q_OBJECT public: explicit ConfigureDiveComputer(QObject *parent = 0); - void readSettings(device_data_t *data); + void readSettings(DeviceDetails *deviceDetails, device_data_t *data); enum states { INITIAL, @@ -53,23 +27,23 @@ public: QString lastError; states currentState; + DeviceDetails *m_deviceDetails; + device_data_t *m_data; + void saveDeviceDetails(); + void fetchDeviceDetails(); - void setDeviceName(device_data_t *data, QString newName); - void setDeviceDateAndTime(device_data_t *data, QDateTime dateAndTime); - void setDeviceBrightness(device_data_t *data, int brighnessLevel); signals: - void deviceSettings(QString settings); void message(QString msg); void error(QString err); void readFinished(); void writeFinished(); void stateChanged(states newState); + private: ReadSettingsThread *readThread; WriteSettingsThread *writeThread; void setState(states newState); - void writeSettingToDevice(device_data_t *data, QString settingName, QVariant settingValue); private slots: void readThreadFinished(); void writeThreadFinished(); diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index 1d5b1d7f8..8ae250468 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -33,14 +33,16 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : ui(new Ui::ConfigureDiveComputerDialog), config(0), vendorModel(0), - productModel(0) + productModel(0), + deviceDetails(0) { ui->setupUi(this); + deviceDetails = new DeviceDetails(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))); + connect (config, SIGNAL(readFinished()), this, SLOT(deviceReadFinished())); fill_computer_list(); @@ -157,7 +159,7 @@ void ConfigureDiveComputerDialog::readSettings() ui->errorLabel->clear(); getDeviceData(); - config->readSettings(&device_data); + config->readSettings(deviceDetails, &device_data); } void ConfigureDiveComputerDialog::configMessage(QString msg) @@ -181,6 +183,8 @@ void ConfigureDiveComputerDialog::getDeviceData() set_default_dive_computer(device_data.vendor, device_data.product); set_default_dive_computer_device(device_data.devname); + + //deviceDetails->setData(&device_data); } void ConfigureDiveComputerDialog::on_cancel_clicked() @@ -188,31 +192,13 @@ void ConfigureDiveComputerDialog::on_cancel_clicked() this->close(); } -void ConfigureDiveComputerDialog::on_setDeviceName_clicked() +void ConfigureDiveComputerDialog::deviceReadFinished() { - ui->statusLabel->clear(); - ui->errorLabel->clear(); - ui->availableDetails->clear(); - - QString newDeviceName = QInputDialog::getText(this, tr("Set device name"), tr("Enter the new name for this device:")); - if (newDeviceName.length() > 0) { - getDeviceData(); - config->setDeviceName(&device_data, newDeviceName); - } + ui->brightnessComboBox->setCurrentIndex(config->m_deviceDetails->brightness()); } -void ConfigureDiveComputerDialog::on_setDateAndTime_clicked() +void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked() { - ui->statusLabel->clear(); - ui->errorLabel->clear(); - ui->availableDetails->clear(); - - getDeviceData(); - config->setDeviceDateAndTime(&device_data, QDateTime::currentDateTime()); + config->saveDeviceDetails(); } -void ConfigureDiveComputerDialog::on_setBrightnessButton_clicked() -{ - getDeviceData(); - config->setDeviceBrightness(&device_data, ui->brightnessComboBox->currentIndex()); -} diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h index 7c4243ab8..5a8bf63e1 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/qt-ui/configuredivecomputerdialog.h @@ -4,8 +4,7 @@ #include #include #include "../libdivecomputer.h" - -class ConfigureDiveComputer; +#include "configuredivecomputer.h" namespace Ui { class ConfigureDiveComputerDialog; @@ -28,12 +27,8 @@ private slots: void configMessage(QString msg); void configError(QString err); void on_cancel_clicked(); - void on_setDeviceName_clicked(); - - void on_setDateAndTime_clicked(); - - void on_setBrightnessButton_clicked(); - + void deviceReadFinished(); + void on_saveSettingsPushButton_clicked(); private: Ui::ConfigureDiveComputerDialog *ui; @@ -49,6 +44,8 @@ private: QStringListModel *productModel; void fill_computer_list(); void fill_device_list(int dc_type); + + DeviceDetails *deviceDetails; }; #endif // CONFIGUREDIVECOMPUTERDIALOG_H diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui index cb4dacb23..d7c584e0c 100644 --- a/qt-ui/configuredivecomputerdialog.ui +++ b/qt-ui/configuredivecomputerdialog.ui @@ -6,8 +6,8 @@ 0 0 - 362 - 375 + 343 + 365 @@ -91,33 +91,16 @@ - - - - - - - Set Device Name - - - - - - - Set Date && Time - - - - + Brightness: - + @@ -136,15 +119,90 @@ - - + + + + true + + + + + + + + English + + + + + German + + + + + French + + + + + Italian + + + + + + + + + + + Language: + + + + + + + Serial No. + + + + + + + Custom Text: + + + + + - ... + Firmware Version: + + + + + + + true + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -164,6 +222,13 @@ + + + + Save Chages to Device + + + @@ -188,6 +253,20 @@ + + vendor + product + device + search + retrieveDetails + serialNoLineEdit + firmwareVersionLineEdit + customTextLlineEdit + brightnessComboBox + languageComboBox + saveSettingsPushButton + cancel + diff --git a/qt-ui/configuredivecomputerthreads.cpp b/qt-ui/configuredivecomputerthreads.cpp new file mode 100644 index 000000000..f1ac3b5d9 --- /dev/null +++ b/qt-ui/configuredivecomputerthreads.cpp @@ -0,0 +1,81 @@ +#include "configuredivecomputerthreads.h" +#include "libdivecomputer/hw.h" +#include + +ReadSettingsThread::ReadSettingsThread(QObject *parent, DeviceDetails *deviceDetails, device_data_t *data) + : QThread(parent), m_deviceDetails(deviceDetails), m_data(data) +{ + +} + +void ReadSettingsThread::run() +{ + bool supported = false; + dc_status_t rc; + rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname); + if (rc == DC_STATUS_SUCCESS) { + switch (dc_device_get_type(m_data->device)) { + case DC_FAMILY_HW_OSTC3: + supported = true; + m_deviceDetails->setBrightness(0); + m_deviceDetails->setCustomText(""); + m_deviceDetails->setDateFormat(0); + m_deviceDetails->setDiveModeColor(0); + m_deviceDetails->setFirmwareVersion(""); + m_deviceDetails->setLanguage(0); + m_deviceDetails->setLastDeco(0); + m_deviceDetails->setSerialNo(""); + unsigned char uData[1]; + rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setBrightness(uData[0]); + rc = hw_ostc3_device_config_read(m_data->device, 0x32, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setLanguage(uData[0]); + rc = hw_ostc3_device_config_read(m_data->device, 0x33, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setDateFormat(uData[0]); + break; + + } + dc_device_close(m_data->device); + + if (!supported) { + lastError = tr("This feature is not yet available for the selected dive computer."); + emit error(lastError); + } + } + else { + lastError = tr("Could not a establish connection to the dive computer."); + emit error(lastError); + } +} + +WriteSettingsThread::WriteSettingsThread(QObject *parent, DeviceDetails *deviceDetails, QString settingName, QVariant settingValue) + : QThread(parent), m_deviceDetails(deviceDetails), m_settingName(settingName), m_settingValue(settingValue) +{ + +} + +void WriteSettingsThread::run() +{ + bool supported = false; + dc_status_t rc; + + switch (dc_device_get_type(data->device)) { + case DC_FAMILY_HW_OSTC3: + rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname); + if (rc == DC_STATUS_SUCCESS) { + + } else { + lastError = tr("Could not a establish connection to the dive computer."); + emit error(lastError); + } + break; + + if (!supported) { + lastError = tr("This feature is not yet available for the selected dive computer."); + emit error(lastError); + } + } +} diff --git a/qt-ui/configuredivecomputerthreads.h b/qt-ui/configuredivecomputerthreads.h new file mode 100644 index 000000000..c684cddaa --- /dev/null +++ b/qt-ui/configuredivecomputerthreads.h @@ -0,0 +1,42 @@ +#ifndef CONFIGUREDIVECOMPUTERTHREADS_H +#define CONFIGUREDIVECOMPUTERTHREADS_H + +#include +#include +#include +#include "libdivecomputer.h" +#include +#include "devicedetails.h" + +class ReadSettingsThread : public QThread { + Q_OBJECT +public: + ReadSettingsThread(QObject *parent, DeviceDetails *deviceDetails, device_data_t *data); + virtual void run(); + QString result; + QString lastError; +signals: + void error(QString err); +private: + DeviceDetails *m_deviceDetails; + device_data_t *m_data; +}; + +class WriteSettingsThread : public QThread { + Q_OBJECT +public: + WriteSettingsThread(QObject *parent, DeviceDetails *deviceDetails, QString settingName, QVariant settingValue); + virtual void run(); + QString result; + QString lastError; +signals: + void error(QString err); +private: + device_data_t *data; + QString m_settingName; + QVariant m_settingValue; + + DeviceDetails *m_deviceDetails; +}; + +#endif // CONFIGUREDIVECOMPUTERTHREADS_H diff --git a/qt-ui/devicedetails.cpp b/qt-ui/devicedetails.cpp new file mode 100644 index 000000000..e5a90b9da --- /dev/null +++ b/qt-ui/devicedetails.cpp @@ -0,0 +1,88 @@ +#include "devicedetails.h" + +DeviceDetails::DeviceDetails(QObject *parent) : + QObject(parent) +{ + +} +device_data_t *DeviceDetails::data() const +{ + return m_data; +} + +void DeviceDetails::setData(device_data_t *data) +{ + m_data = data; +} +QString DeviceDetails::serialNo() const +{ + return m_serialNo; +} + +void DeviceDetails::setSerialNo(const QString &serialNo) +{ + m_serialNo = serialNo; +} +QString DeviceDetails::firmwareVersion() const +{ + return m_firmwareVersion; +} + +void DeviceDetails::setFirmwareVersion(const QString &firmwareVersion) +{ + m_firmwareVersion = firmwareVersion; +} +QString DeviceDetails::customText() const +{ + return m_customText; +} + +void DeviceDetails::setCustomText(const QString &customText) +{ + m_customText = customText; +} +int DeviceDetails::brightness() const +{ + return m_brightness; +} + +void DeviceDetails::setBrightness(int brightness) +{ + m_brightness = brightness; +} +int DeviceDetails::diveModeColor() const +{ + return m_diveModeColor; +} + +void DeviceDetails::setDiveModeColor(int diveModeColor) +{ + m_diveModeColor = diveModeColor; +} +int DeviceDetails::language() const +{ + return m_language; +} + +void DeviceDetails::setLanguage(int language) +{ + m_language = language; +} +int DeviceDetails::dateFormat() const +{ + return m_dateFormat; +} + +void DeviceDetails::setDateFormat(int dateFormat) +{ + m_dateFormat = dateFormat; +} +int DeviceDetails::lastDeco() const +{ + return m_lastDeco; +} + +void DeviceDetails::setLastDeco(int lastDeco) +{ + m_lastDeco = lastDeco; +} diff --git a/qt-ui/devicedetails.h b/qt-ui/devicedetails.h new file mode 100644 index 000000000..9f5e7c1dd --- /dev/null +++ b/qt-ui/devicedetails.h @@ -0,0 +1,54 @@ +#ifndef DEVICEDETAILS_H +#define DEVICEDETAILS_H + +#include +#include +#include "libdivecomputer.h" + +class DeviceDetails : public QObject +{ + Q_OBJECT +public: + explicit DeviceDetails(QObject *parent = 0); + + device_data_t *data() const; + void setData(device_data_t *data); + + QString serialNo() const; + void setSerialNo(const QString &serialNo); + + QString firmwareVersion() const; + void setFirmwareVersion(const QString &firmwareVersion); + + QString customText() const; + void setCustomText(const QString &customText); + + int brightness() const; + void setBrightness(int brightness); + + int diveModeColor() const; + void setDiveModeColor(int diveModeColor); + + int language() const; + void setLanguage(int language); + + int dateFormat() const; + void setDateFormat(int dateFormat); + + int lastDeco() const; + void setLastDeco(int lastDeco); + +private: + device_data_t *m_data; + QString m_serialNo; + QString m_firmwareVersion; + QString m_customText; + int m_brightness; + int m_diveModeColor; + int m_language; + int m_dateFormat; + int m_lastDeco; +}; + + +#endif // DEVICEDETAILS_H diff --git a/subsurface.pro b/subsurface.pro index b532e3c99..8711ab505 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -89,6 +89,8 @@ HEADERS = \ subsurfacesysinfo.h \ qt-ui/configuredivecomputerdialog.h \ qt-ui/configuredivecomputer.h \ + qt-ui/configuredivecomputerthreads.h \ + qt-ui/devicedetails.h android: HEADERS -= \ qt-ui/usermanual.h \ @@ -169,7 +171,9 @@ SOURCES = \ qt-ui/usersurvey.cpp \ subsurfacesysinfo.cpp \ qt-ui/configuredivecomputerdialog.cpp \ - qt-ui/configuredivecomputer.cpp + qt-ui/configuredivecomputer.cpp \ + qt-ui/configuredivecomputerthreads.cpp \ + qt-ui/devicedetails.cpp android: SOURCES += android.cpp else: linux*: SOURCES += linux.c -- cgit v1.2.3-70-g09d2 From 4f37602836ef1f6778fbf76cd20f0d017d5fe305 Mon Sep 17 00:00:00 2001 From: "Joseph W. Joshua" Date: Fri, 20 Jun 2014 07:57:20 +0300 Subject: Move non gui code from qt-ui Moves non gui classes (configuredivecomputer, configuredivecomputerthreads and devicedetails) from qt-ui to the top level folder. Signed-off-by: Joseph W. Joshua Signed-off-by: Thiago Macieira --- configuredivecomputer.cpp | 209 ++++++++++++++ configuredivecomputer.h | 56 ++++ configuredivecomputerthreads.cpp | 229 ++++++++++++++++ configuredivecomputerthreads.h | 40 +++ devicedetails.cpp | 487 +++++++++++++++++++++++++++++++++ devicedetails.h | 202 ++++++++++++++ qt-ui/configuredivecomputer.cpp | 209 -------------- qt-ui/configuredivecomputer.h | 56 ---- qt-ui/configuredivecomputerthreads.cpp | 229 ---------------- qt-ui/configuredivecomputerthreads.h | 40 --- qt-ui/devicedetails.cpp | 487 --------------------------------- qt-ui/devicedetails.h | 202 -------------- subsurface.pro | 12 +- 13 files changed, 1229 insertions(+), 1229 deletions(-) create mode 100644 configuredivecomputer.cpp create mode 100644 configuredivecomputer.h create mode 100644 configuredivecomputerthreads.cpp create mode 100644 configuredivecomputerthreads.h create mode 100644 devicedetails.cpp create mode 100644 devicedetails.h delete mode 100644 qt-ui/configuredivecomputer.cpp delete mode 100644 qt-ui/configuredivecomputer.h delete mode 100644 qt-ui/configuredivecomputerthreads.cpp delete mode 100644 qt-ui/configuredivecomputerthreads.h delete mode 100644 qt-ui/devicedetails.cpp delete mode 100644 qt-ui/devicedetails.h (limited to 'subsurface.pro') diff --git a/configuredivecomputer.cpp b/configuredivecomputer.cpp new file mode 100644 index 000000000..01df1c744 --- /dev/null +++ b/configuredivecomputer.cpp @@ -0,0 +1,209 @@ +#include "configuredivecomputer.h" +#include "libdivecomputer/hw.h" +#include +#include +#include +#include +#include +#include +#include + +ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) : + QObject(parent), + readThread(0), + writeThread(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))); + connect (readThread, SIGNAL(devicedetails(DeviceDetails*)), this, + SIGNAL(deviceDetailsChanged(DeviceDetails*))); + + readThread->start(); +} + +void ConfigureDiveComputer::saveDeviceDetails(DeviceDetails *details, device_data_t *data) +{ + setState(WRITING); + + if (writeThread) + writeThread->deleteLater(); + + writeThread = new WriteSettingsThread(this, data); + connect (writeThread, SIGNAL(finished()), + this, SLOT(writeThreadFinished()), Qt::QueuedConnection); + connect (writeThread, SIGNAL(error(QString)), this, SLOT(setError(QString))); + + writeThread->setDeviceDetails(details); + writeThread->start(); +} + +bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText) +{ + QString xml = ""; + QString vendor = data->vendor; + QString product = data->product; + xml += ""; + xml += "\n"; + xml += addSettingToXML("Vendor", vendor); + xml += addSettingToXML("Product", product); + xml += "\n"; + xml += "\n"; + xml += addSettingToXML("CustomText", details->customText()); + xml += addSettingToXML("DiveMode", details->diveMode()); + xml += addSettingToXML("Saturation", details->saturation()); + xml += addSettingToXML("Desaturation", details->desaturation()); + xml += addSettingToXML("LastDeco", details->lastDeco()); + xml += addSettingToXML("Brightness", details->brightness()); + xml += addSettingToXML("Units", details->units()); + xml += addSettingToXML("SamplingRate", details->samplingRate()); + xml += addSettingToXML("Salinity", details->salinity()); + xml += addSettingToXML("DiveModeColor", details->diveModeColor()); + xml += addSettingToXML("Language", details->language()); + xml += addSettingToXML("DateFormat", details->dateFormat()); + xml += addSettingToXML("CompassGain", details->compassGain()); + xml += "\n"; + xml += "\n"; + QFile file(fileName); + if (!file.open(QIODevice::WriteOnly)) { + errorText = tr("Could not save the backup file %1. Error Message: %2") + .arg(fileName, file.errorString()); + return false; + } + //file open successful. write data and save. + QTextStream out(&file); + out << xml; + + file.close(); + return true; +} + +bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText) +{ + xmlDocPtr doc; + xmlNodePtr node; + xmlChar *key; + + doc = xmlParseFile(fileName.toUtf8().data()); + + if (doc == NULL) { + errorText = tr("Could not read the backup file."); + return false; + } + + node = xmlDocGetRootElement(doc); + if (node == NULL) { + errorText = tr("The specified file is invalid."); + xmlFreeDoc(doc); + return false; + } + + if (xmlStrcmp(node->name, (const xmlChar *) "DiveComputerSettingsBackup")) { + errorText = tr("The specified file does not contain a valid backup."); + xmlFreeDoc(doc); + return false; + } + + xmlNodePtr child = node->children; + + while (child != NULL) { + QString nodeName = (char *)child->name; + if (nodeName == "Settings") { + xmlNodePtr settingNode = child->children; + while (settingNode != NULL) { + QString settingName = (char *)settingNode->name; + key = xmlNodeListGetString(doc, settingNode->xmlChildrenNode, 1); + QString keyString = (char *)key; + if (settingName != "text") { + if (settingName == "CustomText") + details->setCustomText(keyString); + + if (settingName == "Saturation") + details->setSaturation(keyString.toInt()); + + if (settingName == "Desaturation") + details->setDesaturation(keyString.toInt()); + + if (settingName == "DiveMode") + details->setDiveMode(keyString.toInt()); + + if (settingName == "LastDeco") + details->setLastDeco(keyString.toInt()); + + if (settingName == "Brightness") + details->setBrightness(keyString.toInt()); + + if (settingName == "Units") + details->setUnits(keyString.toInt()); + + if (settingName == "SamplingRate") + details->setSamplingRate(keyString.toInt()); + + if (settingName == "Salinity") + details->setSalinity(keyString.toInt()); + + if (settingName == "DiveModeColour") + details->setDiveModeColor(keyString.toInt()); + + if (settingName == "Language") + details->setLanguage(keyString.toInt()); + + if (settingName == "DateFormat") + details->setDateFormat(keyString.toInt()); + + if (settingName == "CompassGain") + details->setCompassGain(keyString.toInt()); + } + + settingNode = settingNode->next; + } + } + child = child->next; + } + + return true; +} + +void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState) +{ + currentState = newState; + emit stateChanged(currentState); +} + + +QString ConfigureDiveComputer::addSettingToXML(QString settingName, QVariant value) +{ + return "\n<" + settingName + ">" + value.toString() + ""; +} + +void ConfigureDiveComputer::setError(QString err) +{ + lastError = err; + emit error(err); +} + +void ConfigureDiveComputer::readThreadFinished() +{ + setState(DONE); + emit readFinished(); +} + +void ConfigureDiveComputer::writeThreadFinished() +{ + setState(DONE); + if (writeThread->lastError.isEmpty()) { + //No error + emit message(tr("Setting successfully written to device")); + } +} diff --git a/configuredivecomputer.h b/configuredivecomputer.h new file mode 100644 index 000000000..31c0cb756 --- /dev/null +++ b/configuredivecomputer.h @@ -0,0 +1,56 @@ +#ifndef CONFIGUREDIVECOMPUTER_H +#define CONFIGUREDIVECOMPUTER_H + +#include +#include +#include +#include "libdivecomputer.h" +#include "configuredivecomputerthreads.h" +#include + +#include "libxml/xmlreader.h" + +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; + device_data_t *m_data; + void saveDeviceDetails(DeviceDetails *details, device_data_t *data); + void fetchDeviceDetails(); + bool saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText); + bool restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText); +signals: + void message(QString msg); + void error(QString err); + void readFinished(); + void writeFinished(); + void stateChanged(states newState); + void deviceDetailsChanged(DeviceDetails *newDetails); + +private: + ReadSettingsThread *readThread; + WriteSettingsThread *writeThread; + void setState(states newState); + QString addSettingToXML(QString settingName, QVariant value); +private slots: + void readThreadFinished(); + void writeThreadFinished(); + void setError(QString err); +}; + +#endif // CONFIGUREDIVECOMPUTER_H diff --git a/configuredivecomputerthreads.cpp b/configuredivecomputerthreads.cpp new file mode 100644 index 000000000..3afb11bc5 --- /dev/null +++ b/configuredivecomputerthreads.cpp @@ -0,0 +1,229 @@ +#include "configuredivecomputerthreads.h" +#include "libdivecomputer/hw.h" +#include +#include + +ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) + : QThread(parent), m_data(data) +{ + +} + +void ReadSettingsThread::run() +{ + bool supported = false; + dc_status_t rc; + rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname); + if (rc == DC_STATUS_SUCCESS) { + DeviceDetails *m_deviceDetails = new DeviceDetails(0); + switch (dc_device_get_type(m_data->device)) { + case DC_FAMILY_HW_OSTC3: + supported = true; + m_deviceDetails->setBrightness(0); + m_deviceDetails->setCustomText(""); + m_deviceDetails->setDateFormat(0); + m_deviceDetails->setDiveModeColor(0); + m_deviceDetails->setFirmwareVersion(""); + m_deviceDetails->setLanguage(0); + m_deviceDetails->setLastDeco(0); + m_deviceDetails->setSerialNo(""); + m_deviceDetails->setCompassGain(0); + m_deviceDetails->setSalinity(0); + m_deviceDetails->setSamplingRate(0); + m_deviceDetails->setUnits(0); + + + //Gread gas mixes + gas gas1; + gas gas2; + gas gas3; + gas gas4; + gas gas5; + //Gas 1 + unsigned char gasData[4] = {0,0,0,0}; + rc = hw_ostc3_device_config_read(m_data->device, 0x10, gasData, sizeof(gasData)); + if (rc == DC_STATUS_SUCCESS) { + //Gas 1 read successful + gas gas1; + gas1.depth = gasData[3]; + gas1.oxygen = gasData[0]; + gas1.helium = gasData[1]; + gas1.type = gasData[2]; + } + + m_deviceDetails->setGas1(gas1); + m_deviceDetails->setGas2(gas2); + m_deviceDetails->setGas3(gas3); + m_deviceDetails->setGas4(gas4); + m_deviceDetails->setGas5(gas5); + + //Read general settings + unsigned char uData[1] = {0}; + //DiveMode + rc = hw_ostc3_device_config_read(m_data->device, 0x20, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setDiveMode(uData[0]); + //Saturation + rc = hw_ostc3_device_config_read(m_data->device, 0x2A, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setSaturation(uData[0]); + //LastDeco + rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setLastDeco(uData[0]); + //Brightness + rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setBrightness(uData[0]); + //Units + rc = hw_ostc3_device_config_read(m_data->device, 0x2E, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setUnits(uData[0]); + //Sampling Rate + rc = hw_ostc3_device_config_read(m_data->device, 0x2F, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setSamplingRate(uData[0]); + //Salinity + rc = hw_ostc3_device_config_read(m_data->device, 0x30, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setSalinity(uData[0]); + //Dive mode colour + rc = hw_ostc3_device_config_read(m_data->device, 0x31, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setDiveModeColor(uData[0]); + //Language + rc = hw_ostc3_device_config_read(m_data->device, 0x32, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setLanguage(uData[0]); + //Date Format + rc = hw_ostc3_device_config_read(m_data->device, 0x33, uData, sizeof(uData)); + if (rc == DC_STATUS_SUCCESS) + m_deviceDetails->setDateFormat(uData[0]); + + + //read firmware settings + unsigned char fData[64] = {0}; + rc = hw_ostc3_device_version (m_data->device, fData, sizeof (fData)); + if (rc == DC_STATUS_SUCCESS) { + int serial = fData[0] + (fData[1] << 8); + m_deviceDetails->setSerialNo(QString::number(serial)); + int fw = (fData[2] << 8) + fData[3]; + m_deviceDetails->setFirmwareVersion(QString::number(fw)); + QByteArray ar((char *)fData + 4, 60); + m_deviceDetails->setCustomText(ar.trimmed()); + } + + emit devicedetails(m_deviceDetails); + break; + + } + dc_device_close(m_data->device); + + if (!supported) { + lastError = tr("This feature is not yet available for the selected dive computer."); + emit error(lastError); + } + } + else { + lastError = tr("Could not a establish connection to the dive computer."); + emit error(lastError); + } +} + +WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data) + : QThread(parent), m_data(data) { + +} + +void WriteSettingsThread::setDeviceDetails(DeviceDetails *details) +{ + m_deviceDetails = details; +} + +void WriteSettingsThread::run() +{ + bool supported = false; + dc_status_t rc; + rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname); + if (rc == DC_STATUS_SUCCESS) { + switch (dc_device_get_type(m_data->device)) { + case DC_FAMILY_HW_OSTC3: + supported = true; + //write general settings + + //custom text + hw_ostc3_device_customtext(m_data->device, m_deviceDetails->customText().toUtf8().data()); + unsigned char data[1] = {0}; + + //dive mode + data[0] = m_deviceDetails->diveMode(); + hw_ostc3_device_config_write(m_data->device, 0x20, data, sizeof(data)); + + //saturation + data[0] = m_deviceDetails->saturation(); + hw_ostc3_device_config_write(m_data->device, 0x2A, data, sizeof(data)); + + //last deco + data[0] = m_deviceDetails->lastDeco(); + hw_ostc3_device_config_write(m_data->device, 0x2C, data, sizeof(data)); + + //brightness + data[0] = m_deviceDetails->brightness(); + hw_ostc3_device_config_write(m_data->device, 0x2D, data, sizeof(data)); + + //units + data[0] = m_deviceDetails->units(); + hw_ostc3_device_config_write(m_data->device, 0x2E, data, sizeof(data)); + + //sampling rate + data[0] = m_deviceDetails->samplingRate(); + hw_ostc3_device_config_write(m_data->device, 0x2F, data, sizeof(data)); + + //salinity + data[0] = m_deviceDetails->salinity(); + hw_ostc3_device_config_write(m_data->device, 0x30, data, sizeof(data)); + + //dive mode colour + data[0] = m_deviceDetails->diveModeColor(); + hw_ostc3_device_config_write(m_data->device, 0x31, data, sizeof(data)); + + //language + data[0] = m_deviceDetails->language(); + hw_ostc3_device_config_write(m_data->device, 0x32, data, sizeof(data)); + + //date format + data[0] = m_deviceDetails->dateFormat(); + hw_ostc3_device_config_write(m_data->device, 0x33, data, sizeof(data)); + + //compass gain + data[0] = m_deviceDetails->compassGain(); + hw_ostc3_device_config_write(m_data->device, 0x34, data, sizeof(data)); + + //sync date and time + if (m_deviceDetails->syncTime()) { + QDateTime timeToSet = QDateTime::currentDateTime(); + dc_datetime_t time; + time.year = timeToSet.date().year(); + time.month = timeToSet.date().month(); + time.day = timeToSet.date().day(); + time.hour = timeToSet.time().hour(); + time.minute = timeToSet.time().minute(); + time.second = timeToSet.time().second(); + hw_ostc3_device_clock(m_data->device, &time); + } + + break; + + } + dc_device_close(m_data->device); + + if (!supported) { + lastError = tr("This feature is not yet available for the selected dive computer."); + emit error(lastError); + } + } + else { + lastError = tr("Could not a establish connection to the dive computer."); + emit error(lastError); + } +} diff --git a/configuredivecomputerthreads.h b/configuredivecomputerthreads.h new file mode 100644 index 000000000..db54db460 --- /dev/null +++ b/configuredivecomputerthreads.h @@ -0,0 +1,40 @@ +#ifndef CONFIGUREDIVECOMPUTERTHREADS_H +#define CONFIGUREDIVECOMPUTERTHREADS_H + +#include +#include +#include +#include "libdivecomputer.h" +#include +#include "devicedetails.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); + void devicedetails(DeviceDetails *newDeviceDetails); +private: + device_data_t *m_data; +}; + +class WriteSettingsThread : public QThread { + Q_OBJECT +public: + WriteSettingsThread(QObject *parent, device_data_t *data); + void setDeviceDetails(DeviceDetails *details); + virtual void run(); + QString result; + QString lastError; +signals: + void error(QString err); +private: + device_data_t *m_data; + DeviceDetails *m_deviceDetails; +}; + +#endif // CONFIGUREDIVECOMPUTERTHREADS_H diff --git a/devicedetails.cpp b/devicedetails.cpp new file mode 100644 index 000000000..db95cfd41 --- /dev/null +++ b/devicedetails.cpp @@ -0,0 +1,487 @@ +#include "devicedetails.h" + +DeviceDetails::DeviceDetails(QObject *parent) : + QObject(parent) +{ + +} + +device_data_t *DeviceDetails::data() const +{ + return m_data; +} + +void DeviceDetails::setData(device_data_t *data) +{ + m_data = data; +} + +QString DeviceDetails::serialNo() const +{ + return m_serialNo; +} + +void DeviceDetails::setSerialNo(const QString &serialNo) +{ + m_serialNo = serialNo; +} + +QString DeviceDetails::firmwareVersion() const +{ + return m_firmwareVersion; +} + +void DeviceDetails::setFirmwareVersion(const QString &firmwareVersion) +{ + m_firmwareVersion = firmwareVersion; +} + +QString DeviceDetails::customText() const +{ + return m_customText; +} + +void DeviceDetails::setCustomText(const QString &customText) +{ + m_customText = customText; +} + +int DeviceDetails::brightness() const +{ + return m_brightness; +} + +void DeviceDetails::setBrightness(int brightness) +{ + m_brightness = brightness; +} + +int DeviceDetails::diveModeColor() const +{ + return m_diveModeColor; +} + +void DeviceDetails::setDiveModeColor(int diveModeColor) +{ + m_diveModeColor = diveModeColor; +} + +int DeviceDetails::language() const +{ + return m_language; +} + +void DeviceDetails::setLanguage(int language) +{ + m_language = language; +} + +int DeviceDetails::dateFormat() const +{ + return m_dateFormat; +} + +void DeviceDetails::setDateFormat(int dateFormat) +{ + m_dateFormat = dateFormat; +} + +int DeviceDetails::lastDeco() const +{ + return m_lastDeco; +} + +void DeviceDetails::setLastDeco(int lastDeco) +{ + m_lastDeco = lastDeco; +} + +bool DeviceDetails::syncTime() const +{ + return m_syncTime; +} + +void DeviceDetails::setSyncTime(bool syncTime) +{ + m_syncTime = syncTime; +} + +gas DeviceDetails::gas1() const +{ + return m_gas1; +} + +void DeviceDetails::setGas1(const gas &gas1) +{ + m_gas1 = gas1; +} + +gas DeviceDetails::gas2() const +{ + return m_gas2; +} + +void DeviceDetails::setGas2(const gas &gas2) +{ + m_gas2 = gas2; +} + +gas DeviceDetails::gas3() const +{ + return m_gas3; +} + +void DeviceDetails::setGas3(const gas &gas3) +{ + m_gas3 = gas3; +} + +gas DeviceDetails::gas4() const +{ + return m_gas4; +} + +void DeviceDetails::setGas4(const gas &gas4) +{ + m_gas4 = gas4; +} + +gas DeviceDetails::gas5() const +{ + return m_gas5; +} + +void DeviceDetails::setGas5(const gas &gas5) +{ + m_gas5 = gas5; +} + +gas DeviceDetails::dil1() const +{ + return m_dil1; +} + +void DeviceDetails::setDil1(const gas &dil1) +{ + m_dil1 = dil1; +} + +gas DeviceDetails::dil2() const +{ + return m_dil2; +} + +void DeviceDetails::setDil2(const gas &dil2) +{ + m_dil2 = dil2; +} + +gas DeviceDetails::dil3() const +{ + return m_dil3; +} + +void DeviceDetails::setDil3(const gas &dil3) +{ + m_dil3 = dil3; +} + +gas DeviceDetails::dil4() const +{ + return m_dil4; +} + +void DeviceDetails::setDil4(const gas &dil4) +{ + m_dil4 = dil4; +} + +gas DeviceDetails::dil5() const +{ + return m_dil5; +} + +void DeviceDetails::setDil5(const gas &dil5) +{ + m_dil5 = dil5; +} + +setpoint DeviceDetails::sp1() const +{ + return m_sp1; +} + +void DeviceDetails::setSp1(const setpoint &sp1) +{ + m_sp1 = sp1; +} + +setpoint DeviceDetails::sp2() const +{ + return m_sp2; +} + +void DeviceDetails::setSp2(const setpoint &sp2) +{ + m_sp2 = sp2; +} + +setpoint DeviceDetails::sp3() const +{ + return m_sp3; +} + +void DeviceDetails::setSp3(const setpoint &sp3) +{ + m_sp3 = sp3; +} + +setpoint DeviceDetails::sp4() const +{ + return m_sp4; +} + +void DeviceDetails::setSp4(const setpoint &sp4) +{ + m_sp4 = sp4; +} + +setpoint DeviceDetails::sp5() const +{ + return m_sp5; +} + +void DeviceDetails::setSp5(const setpoint &sp5) +{ + m_sp5 = sp5; +} + +int DeviceDetails::ccrMode() const +{ + return m_ccrMode; +} + +void DeviceDetails::setCcrMode(int ccrMode) +{ + m_ccrMode = ccrMode; +} + +int DeviceDetails::diveMode() const +{ + return m_diveMode; +} + +void DeviceDetails::setDiveMode(int diveMode) +{ + m_diveMode = diveMode; +} + +int DeviceDetails::decoType() const +{ + return m_decoType; +} + +void DeviceDetails::setDecoType(int decoType) +{ + m_decoType = decoType; +} + +int DeviceDetails::pp02Max() const +{ + return m_pp02Max; +} + +void DeviceDetails::setPp02Max(int pp02Max) +{ + m_pp02Max = pp02Max; +} + +int DeviceDetails::pp02Min() const +{ + return m_pp02Min; +} + +void DeviceDetails::setPp02Min(int pp02Min) +{ + m_pp02Min = pp02Min; +} + +int DeviceDetails::futureTTS() const +{ + return m_futureTTS; +} + +void DeviceDetails::setFutureTTS(int futureTTS) +{ + m_futureTTS = futureTTS; +} + +int DeviceDetails::gfLow() const +{ + return m_gfLow; +} + +void DeviceDetails::setGfLow(int gfLow) +{ + m_gfLow = gfLow; +} + +int DeviceDetails::gfHigh() const +{ + return m_gfHigh; +} + +void DeviceDetails::setGfHigh(int gfHigh) +{ + m_gfHigh = gfHigh; +} + +int DeviceDetails::aGFLow() const +{ + return m_aGFLow; +} + +void DeviceDetails::setAGFLow(int aGFLow) +{ + m_aGFLow = aGFLow; +} + +int DeviceDetails::aGFHigh() const +{ + return m_aGFHigh; +} + +void DeviceDetails::setAGFHigh(int aGFHigh) +{ + m_aGFHigh = aGFHigh; +} + +int DeviceDetails::aGFSelectable() const +{ + return m_aGFSelectable; +} + +void DeviceDetails::setAGFSelectable(int aGFSelectable) +{ + m_aGFSelectable = aGFSelectable; +} + +int DeviceDetails::saturation() const +{ + return m_saturation; +} + +void DeviceDetails::setSaturation(int saturation) +{ + m_saturation = saturation; +} + +int DeviceDetails::desaturation() const +{ + return m_desaturation; +} + +void DeviceDetails::setDesaturation(int desaturation) +{ + m_desaturation = desaturation; +} + +int DeviceDetails::units() const +{ + return m_units; +} + +void DeviceDetails::setUnits(int units) +{ + m_units = units; +} + +int DeviceDetails::samplingRate() const +{ + return m_samplingRate; +} + +void DeviceDetails::setSamplingRate(int samplingRate) +{ + m_samplingRate = samplingRate; +} + +int DeviceDetails::salinity() const +{ + return m_salinity; +} + +void DeviceDetails::setSalinity(int salinity) +{ + m_salinity = salinity; +} + +int DeviceDetails::compassGain() const +{ + return m_compassGain; +} + +void DeviceDetails::setCompassGain(int compassGain) +{ + m_compassGain = compassGain; +} + +int DeviceDetails::pressureSensorOffset() const +{ + return m_pressureSensorOffset; +} + +void DeviceDetails::setPressureSensorOffset(int pressureSensorOffset) +{ + m_pressureSensorOffset = pressureSensorOffset; +} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/devicedetails.h b/devicedetails.h new file mode 100644 index 000000000..d754e9774 --- /dev/null +++ b/devicedetails.h @@ -0,0 +1,202 @@ +#ifndef DEVICEDETAILS_H +#define DEVICEDETAILS_H + +#include +#include +#include "libdivecomputer.h" + +struct gas { + int oxygen; + int helium; + int type; + int depth; +}; + +struct setpoint { + int sp; + int depth; +}; + +class DeviceDetails : public QObject +{ + Q_OBJECT +public: + explicit DeviceDetails(QObject *parent = 0); + + device_data_t *data() const; + void setData(device_data_t *data); + + QString serialNo() const; + void setSerialNo(const QString &serialNo); + + QString firmwareVersion() const; + void setFirmwareVersion(const QString &firmwareVersion); + + QString customText() const; + void setCustomText(const QString &customText); + + int brightness() const; + void setBrightness(int brightness); + + int diveModeColor() const; + void setDiveModeColor(int diveModeColor); + + int language() const; + void setLanguage(int language); + + int dateFormat() const; + void setDateFormat(int dateFormat); + + int lastDeco() const; + void setLastDeco(int lastDeco); + + bool syncTime() const; + void setSyncTime(bool syncTime); + + gas gas1() const; + void setGas1(const gas &gas1); + + gas gas2() const; + void setGas2(const gas &gas2); + + gas gas3() const; + void setGas3(const gas &gas3); + + gas gas4() const; + void setGas4(const gas &gas4); + + gas gas5() const; + void setGas5(const gas &gas5); + + gas dil1() const; + void setDil1(const gas &dil1); + + gas dil2() const; + void setDil2(const gas &dil2); + + gas dil3() const; + void setDil3(const gas &dil3); + + gas dil4() const; + void setDil4(const gas &dil4); + + gas dil5() const; + void setDil5(const gas &dil5); + + setpoint sp1() const; + void setSp1(const setpoint &sp1); + + setpoint sp2() const; + void setSp2(const setpoint &sp2); + + setpoint sp3() const; + void setSp3(const setpoint &sp3); + + setpoint sp4() const; + void setSp4(const setpoint &sp4); + + setpoint sp5() const; + void setSp5(const setpoint &sp5); + + int ccrMode() const; + void setCcrMode(int ccrMode); + + int diveMode() const; + void setDiveMode(int diveMode); + + int decoType() const; + void setDecoType(int decoType); + + int pp02Max() const; + void setPp02Max(int pp02Max); + + int pp02Min() const; + void setPp02Min(int pp02Min); + + int futureTTS() const; + void setFutureTTS(int futureTTS); + + int gfLow() const; + void setGfLow(int gfLow); + + int gfHigh() const; + void setGfHigh(int gfHigh); + + int aGFLow() const; + void setAGFLow(int aGFLow); + + int aGFHigh() const; + void setAGFHigh(int aGFHigh); + + int aGFSelectable() const; + void setAGFSelectable(int aGFSelectable); + + int saturation() const; + void setSaturation(int saturation); + + int desaturation() const; + void setDesaturation(int desaturation); + + int units() const; + void setUnits(int units); + + int samplingRate() const; + void setSamplingRate(int samplingRate); + + int salinity() const; + void setSalinity(int salinity); + + int compassGain() const; + void setCompassGain(int compassGain); + + int pressureSensorOffset() const; + void setPressureSensorOffset(int pressureSensorOffset); + +private: + device_data_t *m_data; + QString m_serialNo; + QString m_firmwareVersion; + QString m_customText; + bool m_syncTime; + gas m_gas1; + gas m_gas2; + gas m_gas3; + gas m_gas4; + gas m_gas5; + gas m_dil1; + gas m_dil2; + gas m_dil3; + gas m_dil4; + gas m_dil5; + setpoint m_sp1; + setpoint m_sp2; + setpoint m_sp3; + setpoint m_sp4; + setpoint m_sp5; + int m_ccrMode; + int m_diveMode; + int m_decoType; + int m_pp02Max; + int m_pp02Min; + int m_futureTTS; + int m_gfLow; + int m_gfHigh; + int m_aGFLow; + int m_aGFHigh; + int m_aGFSelectable; + int m_saturation; + int m_desaturation; + int m_lastDeco; + int m_brightness; + int m_units; + int m_samplingRate; + int m_salinity; + int m_diveModeColor; + int m_language; + int m_dateFormat; + int m_compassGain; + int m_pressureSensorOffset; +}; + + +#endif // DEVICEDETAILS_H diff --git a/qt-ui/configuredivecomputer.cpp b/qt-ui/configuredivecomputer.cpp deleted file mode 100644 index 01df1c744..000000000 --- a/qt-ui/configuredivecomputer.cpp +++ /dev/null @@ -1,209 +0,0 @@ -#include "configuredivecomputer.h" -#include "libdivecomputer/hw.h" -#include -#include -#include -#include -#include -#include -#include - -ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) : - QObject(parent), - readThread(0), - writeThread(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))); - connect (readThread, SIGNAL(devicedetails(DeviceDetails*)), this, - SIGNAL(deviceDetailsChanged(DeviceDetails*))); - - readThread->start(); -} - -void ConfigureDiveComputer::saveDeviceDetails(DeviceDetails *details, device_data_t *data) -{ - setState(WRITING); - - if (writeThread) - writeThread->deleteLater(); - - writeThread = new WriteSettingsThread(this, data); - connect (writeThread, SIGNAL(finished()), - this, SLOT(writeThreadFinished()), Qt::QueuedConnection); - connect (writeThread, SIGNAL(error(QString)), this, SLOT(setError(QString))); - - writeThread->setDeviceDetails(details); - writeThread->start(); -} - -bool ConfigureDiveComputer::saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText) -{ - QString xml = ""; - QString vendor = data->vendor; - QString product = data->product; - xml += ""; - xml += "\n"; - xml += addSettingToXML("Vendor", vendor); - xml += addSettingToXML("Product", product); - xml += "\n"; - xml += "\n"; - xml += addSettingToXML("CustomText", details->customText()); - xml += addSettingToXML("DiveMode", details->diveMode()); - xml += addSettingToXML("Saturation", details->saturation()); - xml += addSettingToXML("Desaturation", details->desaturation()); - xml += addSettingToXML("LastDeco", details->lastDeco()); - xml += addSettingToXML("Brightness", details->brightness()); - xml += addSettingToXML("Units", details->units()); - xml += addSettingToXML("SamplingRate", details->samplingRate()); - xml += addSettingToXML("Salinity", details->salinity()); - xml += addSettingToXML("DiveModeColor", details->diveModeColor()); - xml += addSettingToXML("Language", details->language()); - xml += addSettingToXML("DateFormat", details->dateFormat()); - xml += addSettingToXML("CompassGain", details->compassGain()); - xml += "\n"; - xml += "\n"; - QFile file(fileName); - if (!file.open(QIODevice::WriteOnly)) { - errorText = tr("Could not save the backup file %1. Error Message: %2") - .arg(fileName, file.errorString()); - return false; - } - //file open successful. write data and save. - QTextStream out(&file); - out << xml; - - file.close(); - return true; -} - -bool ConfigureDiveComputer::restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText) -{ - xmlDocPtr doc; - xmlNodePtr node; - xmlChar *key; - - doc = xmlParseFile(fileName.toUtf8().data()); - - if (doc == NULL) { - errorText = tr("Could not read the backup file."); - return false; - } - - node = xmlDocGetRootElement(doc); - if (node == NULL) { - errorText = tr("The specified file is invalid."); - xmlFreeDoc(doc); - return false; - } - - if (xmlStrcmp(node->name, (const xmlChar *) "DiveComputerSettingsBackup")) { - errorText = tr("The specified file does not contain a valid backup."); - xmlFreeDoc(doc); - return false; - } - - xmlNodePtr child = node->children; - - while (child != NULL) { - QString nodeName = (char *)child->name; - if (nodeName == "Settings") { - xmlNodePtr settingNode = child->children; - while (settingNode != NULL) { - QString settingName = (char *)settingNode->name; - key = xmlNodeListGetString(doc, settingNode->xmlChildrenNode, 1); - QString keyString = (char *)key; - if (settingName != "text") { - if (settingName == "CustomText") - details->setCustomText(keyString); - - if (settingName == "Saturation") - details->setSaturation(keyString.toInt()); - - if (settingName == "Desaturation") - details->setDesaturation(keyString.toInt()); - - if (settingName == "DiveMode") - details->setDiveMode(keyString.toInt()); - - if (settingName == "LastDeco") - details->setLastDeco(keyString.toInt()); - - if (settingName == "Brightness") - details->setBrightness(keyString.toInt()); - - if (settingName == "Units") - details->setUnits(keyString.toInt()); - - if (settingName == "SamplingRate") - details->setSamplingRate(keyString.toInt()); - - if (settingName == "Salinity") - details->setSalinity(keyString.toInt()); - - if (settingName == "DiveModeColour") - details->setDiveModeColor(keyString.toInt()); - - if (settingName == "Language") - details->setLanguage(keyString.toInt()); - - if (settingName == "DateFormat") - details->setDateFormat(keyString.toInt()); - - if (settingName == "CompassGain") - details->setCompassGain(keyString.toInt()); - } - - settingNode = settingNode->next; - } - } - child = child->next; - } - - return true; -} - -void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState) -{ - currentState = newState; - emit stateChanged(currentState); -} - - -QString ConfigureDiveComputer::addSettingToXML(QString settingName, QVariant value) -{ - return "\n<" + settingName + ">" + value.toString() + ""; -} - -void ConfigureDiveComputer::setError(QString err) -{ - lastError = err; - emit error(err); -} - -void ConfigureDiveComputer::readThreadFinished() -{ - setState(DONE); - emit readFinished(); -} - -void ConfigureDiveComputer::writeThreadFinished() -{ - setState(DONE); - if (writeThread->lastError.isEmpty()) { - //No error - emit message(tr("Setting successfully written to device")); - } -} diff --git a/qt-ui/configuredivecomputer.h b/qt-ui/configuredivecomputer.h deleted file mode 100644 index 31c0cb756..000000000 --- a/qt-ui/configuredivecomputer.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef CONFIGUREDIVECOMPUTER_H -#define CONFIGUREDIVECOMPUTER_H - -#include -#include -#include -#include "libdivecomputer.h" -#include "configuredivecomputerthreads.h" -#include - -#include "libxml/xmlreader.h" - -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; - device_data_t *m_data; - void saveDeviceDetails(DeviceDetails *details, device_data_t *data); - void fetchDeviceDetails(); - bool saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data, QString errorText); - bool restoreXMLBackup(QString fileName, DeviceDetails *details, QString errorText); -signals: - void message(QString msg); - void error(QString err); - void readFinished(); - void writeFinished(); - void stateChanged(states newState); - void deviceDetailsChanged(DeviceDetails *newDetails); - -private: - ReadSettingsThread *readThread; - WriteSettingsThread *writeThread; - void setState(states newState); - QString addSettingToXML(QString settingName, QVariant value); -private slots: - void readThreadFinished(); - void writeThreadFinished(); - void setError(QString err); -}; - -#endif // CONFIGUREDIVECOMPUTER_H diff --git a/qt-ui/configuredivecomputerthreads.cpp b/qt-ui/configuredivecomputerthreads.cpp deleted file mode 100644 index 3afb11bc5..000000000 --- a/qt-ui/configuredivecomputerthreads.cpp +++ /dev/null @@ -1,229 +0,0 @@ -#include "configuredivecomputerthreads.h" -#include "libdivecomputer/hw.h" -#include -#include - -ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) - : QThread(parent), m_data(data) -{ - -} - -void ReadSettingsThread::run() -{ - bool supported = false; - dc_status_t rc; - rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname); - if (rc == DC_STATUS_SUCCESS) { - DeviceDetails *m_deviceDetails = new DeviceDetails(0); - switch (dc_device_get_type(m_data->device)) { - case DC_FAMILY_HW_OSTC3: - supported = true; - m_deviceDetails->setBrightness(0); - m_deviceDetails->setCustomText(""); - m_deviceDetails->setDateFormat(0); - m_deviceDetails->setDiveModeColor(0); - m_deviceDetails->setFirmwareVersion(""); - m_deviceDetails->setLanguage(0); - m_deviceDetails->setLastDeco(0); - m_deviceDetails->setSerialNo(""); - m_deviceDetails->setCompassGain(0); - m_deviceDetails->setSalinity(0); - m_deviceDetails->setSamplingRate(0); - m_deviceDetails->setUnits(0); - - - //Gread gas mixes - gas gas1; - gas gas2; - gas gas3; - gas gas4; - gas gas5; - //Gas 1 - unsigned char gasData[4] = {0,0,0,0}; - rc = hw_ostc3_device_config_read(m_data->device, 0x10, gasData, sizeof(gasData)); - if (rc == DC_STATUS_SUCCESS) { - //Gas 1 read successful - gas gas1; - gas1.depth = gasData[3]; - gas1.oxygen = gasData[0]; - gas1.helium = gasData[1]; - gas1.type = gasData[2]; - } - - m_deviceDetails->setGas1(gas1); - m_deviceDetails->setGas2(gas2); - m_deviceDetails->setGas3(gas3); - m_deviceDetails->setGas4(gas4); - m_deviceDetails->setGas5(gas5); - - //Read general settings - unsigned char uData[1] = {0}; - //DiveMode - rc = hw_ostc3_device_config_read(m_data->device, 0x20, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setDiveMode(uData[0]); - //Saturation - rc = hw_ostc3_device_config_read(m_data->device, 0x2A, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setSaturation(uData[0]); - //LastDeco - rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setLastDeco(uData[0]); - //Brightness - rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setBrightness(uData[0]); - //Units - rc = hw_ostc3_device_config_read(m_data->device, 0x2E, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setUnits(uData[0]); - //Sampling Rate - rc = hw_ostc3_device_config_read(m_data->device, 0x2F, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setSamplingRate(uData[0]); - //Salinity - rc = hw_ostc3_device_config_read(m_data->device, 0x30, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setSalinity(uData[0]); - //Dive mode colour - rc = hw_ostc3_device_config_read(m_data->device, 0x31, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setDiveModeColor(uData[0]); - //Language - rc = hw_ostc3_device_config_read(m_data->device, 0x32, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setLanguage(uData[0]); - //Date Format - rc = hw_ostc3_device_config_read(m_data->device, 0x33, uData, sizeof(uData)); - if (rc == DC_STATUS_SUCCESS) - m_deviceDetails->setDateFormat(uData[0]); - - - //read firmware settings - unsigned char fData[64] = {0}; - rc = hw_ostc3_device_version (m_data->device, fData, sizeof (fData)); - if (rc == DC_STATUS_SUCCESS) { - int serial = fData[0] + (fData[1] << 8); - m_deviceDetails->setSerialNo(QString::number(serial)); - int fw = (fData[2] << 8) + fData[3]; - m_deviceDetails->setFirmwareVersion(QString::number(fw)); - QByteArray ar((char *)fData + 4, 60); - m_deviceDetails->setCustomText(ar.trimmed()); - } - - emit devicedetails(m_deviceDetails); - break; - - } - dc_device_close(m_data->device); - - if (!supported) { - lastError = tr("This feature is not yet available for the selected dive computer."); - emit error(lastError); - } - } - else { - lastError = tr("Could not a establish connection to the dive computer."); - emit error(lastError); - } -} - -WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data) - : QThread(parent), m_data(data) { - -} - -void WriteSettingsThread::setDeviceDetails(DeviceDetails *details) -{ - m_deviceDetails = details; -} - -void WriteSettingsThread::run() -{ - bool supported = false; - dc_status_t rc; - rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname); - if (rc == DC_STATUS_SUCCESS) { - switch (dc_device_get_type(m_data->device)) { - case DC_FAMILY_HW_OSTC3: - supported = true; - //write general settings - - //custom text - hw_ostc3_device_customtext(m_data->device, m_deviceDetails->customText().toUtf8().data()); - unsigned char data[1] = {0}; - - //dive mode - data[0] = m_deviceDetails->diveMode(); - hw_ostc3_device_config_write(m_data->device, 0x20, data, sizeof(data)); - - //saturation - data[0] = m_deviceDetails->saturation(); - hw_ostc3_device_config_write(m_data->device, 0x2A, data, sizeof(data)); - - //last deco - data[0] = m_deviceDetails->lastDeco(); - hw_ostc3_device_config_write(m_data->device, 0x2C, data, sizeof(data)); - - //brightness - data[0] = m_deviceDetails->brightness(); - hw_ostc3_device_config_write(m_data->device, 0x2D, data, sizeof(data)); - - //units - data[0] = m_deviceDetails->units(); - hw_ostc3_device_config_write(m_data->device, 0x2E, data, sizeof(data)); - - //sampling rate - data[0] = m_deviceDetails->samplingRate(); - hw_ostc3_device_config_write(m_data->device, 0x2F, data, sizeof(data)); - - //salinity - data[0] = m_deviceDetails->salinity(); - hw_ostc3_device_config_write(m_data->device, 0x30, data, sizeof(data)); - - //dive mode colour - data[0] = m_deviceDetails->diveModeColor(); - hw_ostc3_device_config_write(m_data->device, 0x31, data, sizeof(data)); - - //language - data[0] = m_deviceDetails->language(); - hw_ostc3_device_config_write(m_data->device, 0x32, data, sizeof(data)); - - //date format - data[0] = m_deviceDetails->dateFormat(); - hw_ostc3_device_config_write(m_data->device, 0x33, data, sizeof(data)); - - //compass gain - data[0] = m_deviceDetails->compassGain(); - hw_ostc3_device_config_write(m_data->device, 0x34, data, sizeof(data)); - - //sync date and time - if (m_deviceDetails->syncTime()) { - QDateTime timeToSet = QDateTime::currentDateTime(); - dc_datetime_t time; - time.year = timeToSet.date().year(); - time.month = timeToSet.date().month(); - time.day = timeToSet.date().day(); - time.hour = timeToSet.time().hour(); - time.minute = timeToSet.time().minute(); - time.second = timeToSet.time().second(); - hw_ostc3_device_clock(m_data->device, &time); - } - - break; - - } - dc_device_close(m_data->device); - - if (!supported) { - lastError = tr("This feature is not yet available for the selected dive computer."); - emit error(lastError); - } - } - else { - lastError = tr("Could not a establish connection to the dive computer."); - emit error(lastError); - } -} diff --git a/qt-ui/configuredivecomputerthreads.h b/qt-ui/configuredivecomputerthreads.h deleted file mode 100644 index db54db460..000000000 --- a/qt-ui/configuredivecomputerthreads.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef CONFIGUREDIVECOMPUTERTHREADS_H -#define CONFIGUREDIVECOMPUTERTHREADS_H - -#include -#include -#include -#include "libdivecomputer.h" -#include -#include "devicedetails.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); - void devicedetails(DeviceDetails *newDeviceDetails); -private: - device_data_t *m_data; -}; - -class WriteSettingsThread : public QThread { - Q_OBJECT -public: - WriteSettingsThread(QObject *parent, device_data_t *data); - void setDeviceDetails(DeviceDetails *details); - virtual void run(); - QString result; - QString lastError; -signals: - void error(QString err); -private: - device_data_t *m_data; - DeviceDetails *m_deviceDetails; -}; - -#endif // CONFIGUREDIVECOMPUTERTHREADS_H diff --git a/qt-ui/devicedetails.cpp b/qt-ui/devicedetails.cpp deleted file mode 100644 index db95cfd41..000000000 --- a/qt-ui/devicedetails.cpp +++ /dev/null @@ -1,487 +0,0 @@ -#include "devicedetails.h" - -DeviceDetails::DeviceDetails(QObject *parent) : - QObject(parent) -{ - -} - -device_data_t *DeviceDetails::data() const -{ - return m_data; -} - -void DeviceDetails::setData(device_data_t *data) -{ - m_data = data; -} - -QString DeviceDetails::serialNo() const -{ - return m_serialNo; -} - -void DeviceDetails::setSerialNo(const QString &serialNo) -{ - m_serialNo = serialNo; -} - -QString DeviceDetails::firmwareVersion() const -{ - return m_firmwareVersion; -} - -void DeviceDetails::setFirmwareVersion(const QString &firmwareVersion) -{ - m_firmwareVersion = firmwareVersion; -} - -QString DeviceDetails::customText() const -{ - return m_customText; -} - -void DeviceDetails::setCustomText(const QString &customText) -{ - m_customText = customText; -} - -int DeviceDetails::brightness() const -{ - return m_brightness; -} - -void DeviceDetails::setBrightness(int brightness) -{ - m_brightness = brightness; -} - -int DeviceDetails::diveModeColor() const -{ - return m_diveModeColor; -} - -void DeviceDetails::setDiveModeColor(int diveModeColor) -{ - m_diveModeColor = diveModeColor; -} - -int DeviceDetails::language() const -{ - return m_language; -} - -void DeviceDetails::setLanguage(int language) -{ - m_language = language; -} - -int DeviceDetails::dateFormat() const -{ - return m_dateFormat; -} - -void DeviceDetails::setDateFormat(int dateFormat) -{ - m_dateFormat = dateFormat; -} - -int DeviceDetails::lastDeco() const -{ - return m_lastDeco; -} - -void DeviceDetails::setLastDeco(int lastDeco) -{ - m_lastDeco = lastDeco; -} - -bool DeviceDetails::syncTime() const -{ - return m_syncTime; -} - -void DeviceDetails::setSyncTime(bool syncTime) -{ - m_syncTime = syncTime; -} - -gas DeviceDetails::gas1() const -{ - return m_gas1; -} - -void DeviceDetails::setGas1(const gas &gas1) -{ - m_gas1 = gas1; -} - -gas DeviceDetails::gas2() const -{ - return m_gas2; -} - -void DeviceDetails::setGas2(const gas &gas2) -{ - m_gas2 = gas2; -} - -gas DeviceDetails::gas3() const -{ - return m_gas3; -} - -void DeviceDetails::setGas3(const gas &gas3) -{ - m_gas3 = gas3; -} - -gas DeviceDetails::gas4() const -{ - return m_gas4; -} - -void DeviceDetails::setGas4(const gas &gas4) -{ - m_gas4 = gas4; -} - -gas DeviceDetails::gas5() const -{ - return m_gas5; -} - -void DeviceDetails::setGas5(const gas &gas5) -{ - m_gas5 = gas5; -} - -gas DeviceDetails::dil1() const -{ - return m_dil1; -} - -void DeviceDetails::setDil1(const gas &dil1) -{ - m_dil1 = dil1; -} - -gas DeviceDetails::dil2() const -{ - return m_dil2; -} - -void DeviceDetails::setDil2(const gas &dil2) -{ - m_dil2 = dil2; -} - -gas DeviceDetails::dil3() const -{ - return m_dil3; -} - -void DeviceDetails::setDil3(const gas &dil3) -{ - m_dil3 = dil3; -} - -gas DeviceDetails::dil4() const -{ - return m_dil4; -} - -void DeviceDetails::setDil4(const gas &dil4) -{ - m_dil4 = dil4; -} - -gas DeviceDetails::dil5() const -{ - return m_dil5; -} - -void DeviceDetails::setDil5(const gas &dil5) -{ - m_dil5 = dil5; -} - -setpoint DeviceDetails::sp1() const -{ - return m_sp1; -} - -void DeviceDetails::setSp1(const setpoint &sp1) -{ - m_sp1 = sp1; -} - -setpoint DeviceDetails::sp2() const -{ - return m_sp2; -} - -void DeviceDetails::setSp2(const setpoint &sp2) -{ - m_sp2 = sp2; -} - -setpoint DeviceDetails::sp3() const -{ - return m_sp3; -} - -void DeviceDetails::setSp3(const setpoint &sp3) -{ - m_sp3 = sp3; -} - -setpoint DeviceDetails::sp4() const -{ - return m_sp4; -} - -void DeviceDetails::setSp4(const setpoint &sp4) -{ - m_sp4 = sp4; -} - -setpoint DeviceDetails::sp5() const -{ - return m_sp5; -} - -void DeviceDetails::setSp5(const setpoint &sp5) -{ - m_sp5 = sp5; -} - -int DeviceDetails::ccrMode() const -{ - return m_ccrMode; -} - -void DeviceDetails::setCcrMode(int ccrMode) -{ - m_ccrMode = ccrMode; -} - -int DeviceDetails::diveMode() const -{ - return m_diveMode; -} - -void DeviceDetails::setDiveMode(int diveMode) -{ - m_diveMode = diveMode; -} - -int DeviceDetails::decoType() const -{ - return m_decoType; -} - -void DeviceDetails::setDecoType(int decoType) -{ - m_decoType = decoType; -} - -int DeviceDetails::pp02Max() const -{ - return m_pp02Max; -} - -void DeviceDetails::setPp02Max(int pp02Max) -{ - m_pp02Max = pp02Max; -} - -int DeviceDetails::pp02Min() const -{ - return m_pp02Min; -} - -void DeviceDetails::setPp02Min(int pp02Min) -{ - m_pp02Min = pp02Min; -} - -int DeviceDetails::futureTTS() const -{ - return m_futureTTS; -} - -void DeviceDetails::setFutureTTS(int futureTTS) -{ - m_futureTTS = futureTTS; -} - -int DeviceDetails::gfLow() const -{ - return m_gfLow; -} - -void DeviceDetails::setGfLow(int gfLow) -{ - m_gfLow = gfLow; -} - -int DeviceDetails::gfHigh() const -{ - return m_gfHigh; -} - -void DeviceDetails::setGfHigh(int gfHigh) -{ - m_gfHigh = gfHigh; -} - -int DeviceDetails::aGFLow() const -{ - return m_aGFLow; -} - -void DeviceDetails::setAGFLow(int aGFLow) -{ - m_aGFLow = aGFLow; -} - -int DeviceDetails::aGFHigh() const -{ - return m_aGFHigh; -} - -void DeviceDetails::setAGFHigh(int aGFHigh) -{ - m_aGFHigh = aGFHigh; -} - -int DeviceDetails::aGFSelectable() const -{ - return m_aGFSelectable; -} - -void DeviceDetails::setAGFSelectable(int aGFSelectable) -{ - m_aGFSelectable = aGFSelectable; -} - -int DeviceDetails::saturation() const -{ - return m_saturation; -} - -void DeviceDetails::setSaturation(int saturation) -{ - m_saturation = saturation; -} - -int DeviceDetails::desaturation() const -{ - return m_desaturation; -} - -void DeviceDetails::setDesaturation(int desaturation) -{ - m_desaturation = desaturation; -} - -int DeviceDetails::units() const -{ - return m_units; -} - -void DeviceDetails::setUnits(int units) -{ - m_units = units; -} - -int DeviceDetails::samplingRate() const -{ - return m_samplingRate; -} - -void DeviceDetails::setSamplingRate(int samplingRate) -{ - m_samplingRate = samplingRate; -} - -int DeviceDetails::salinity() const -{ - return m_salinity; -} - -void DeviceDetails::setSalinity(int salinity) -{ - m_salinity = salinity; -} - -int DeviceDetails::compassGain() const -{ - return m_compassGain; -} - -void DeviceDetails::setCompassGain(int compassGain) -{ - m_compassGain = compassGain; -} - -int DeviceDetails::pressureSensorOffset() const -{ - return m_pressureSensorOffset; -} - -void DeviceDetails::setPressureSensorOffset(int pressureSensorOffset) -{ - m_pressureSensorOffset = pressureSensorOffset; -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qt-ui/devicedetails.h b/qt-ui/devicedetails.h deleted file mode 100644 index d754e9774..000000000 --- a/qt-ui/devicedetails.h +++ /dev/null @@ -1,202 +0,0 @@ -#ifndef DEVICEDETAILS_H -#define DEVICEDETAILS_H - -#include -#include -#include "libdivecomputer.h" - -struct gas { - int oxygen; - int helium; - int type; - int depth; -}; - -struct setpoint { - int sp; - int depth; -}; - -class DeviceDetails : public QObject -{ - Q_OBJECT -public: - explicit DeviceDetails(QObject *parent = 0); - - device_data_t *data() const; - void setData(device_data_t *data); - - QString serialNo() const; - void setSerialNo(const QString &serialNo); - - QString firmwareVersion() const; - void setFirmwareVersion(const QString &firmwareVersion); - - QString customText() const; - void setCustomText(const QString &customText); - - int brightness() const; - void setBrightness(int brightness); - - int diveModeColor() const; - void setDiveModeColor(int diveModeColor); - - int language() const; - void setLanguage(int language); - - int dateFormat() const; - void setDateFormat(int dateFormat); - - int lastDeco() const; - void setLastDeco(int lastDeco); - - bool syncTime() const; - void setSyncTime(bool syncTime); - - gas gas1() const; - void setGas1(const gas &gas1); - - gas gas2() const; - void setGas2(const gas &gas2); - - gas gas3() const; - void setGas3(const gas &gas3); - - gas gas4() const; - void setGas4(const gas &gas4); - - gas gas5() const; - void setGas5(const gas &gas5); - - gas dil1() const; - void setDil1(const gas &dil1); - - gas dil2() const; - void setDil2(const gas &dil2); - - gas dil3() const; - void setDil3(const gas &dil3); - - gas dil4() const; - void setDil4(const gas &dil4); - - gas dil5() const; - void setDil5(const gas &dil5); - - setpoint sp1() const; - void setSp1(const setpoint &sp1); - - setpoint sp2() const; - void setSp2(const setpoint &sp2); - - setpoint sp3() const; - void setSp3(const setpoint &sp3); - - setpoint sp4() const; - void setSp4(const setpoint &sp4); - - setpoint sp5() const; - void setSp5(const setpoint &sp5); - - int ccrMode() const; - void setCcrMode(int ccrMode); - - int diveMode() const; - void setDiveMode(int diveMode); - - int decoType() const; - void setDecoType(int decoType); - - int pp02Max() const; - void setPp02Max(int pp02Max); - - int pp02Min() const; - void setPp02Min(int pp02Min); - - int futureTTS() const; - void setFutureTTS(int futureTTS); - - int gfLow() const; - void setGfLow(int gfLow); - - int gfHigh() const; - void setGfHigh(int gfHigh); - - int aGFLow() const; - void setAGFLow(int aGFLow); - - int aGFHigh() const; - void setAGFHigh(int aGFHigh); - - int aGFSelectable() const; - void setAGFSelectable(int aGFSelectable); - - int saturation() const; - void setSaturation(int saturation); - - int desaturation() const; - void setDesaturation(int desaturation); - - int units() const; - void setUnits(int units); - - int samplingRate() const; - void setSamplingRate(int samplingRate); - - int salinity() const; - void setSalinity(int salinity); - - int compassGain() const; - void setCompassGain(int compassGain); - - int pressureSensorOffset() const; - void setPressureSensorOffset(int pressureSensorOffset); - -private: - device_data_t *m_data; - QString m_serialNo; - QString m_firmwareVersion; - QString m_customText; - bool m_syncTime; - gas m_gas1; - gas m_gas2; - gas m_gas3; - gas m_gas4; - gas m_gas5; - gas m_dil1; - gas m_dil2; - gas m_dil3; - gas m_dil4; - gas m_dil5; - setpoint m_sp1; - setpoint m_sp2; - setpoint m_sp3; - setpoint m_sp4; - setpoint m_sp5; - int m_ccrMode; - int m_diveMode; - int m_decoType; - int m_pp02Max; - int m_pp02Min; - int m_futureTTS; - int m_gfLow; - int m_gfHigh; - int m_aGFLow; - int m_aGFHigh; - int m_aGFSelectable; - int m_saturation; - int m_desaturation; - int m_lastDeco; - int m_brightness; - int m_units; - int m_samplingRate; - int m_salinity; - int m_diveModeColor; - int m_language; - int m_dateFormat; - int m_compassGain; - int m_pressureSensorOffset; -}; - - -#endif // DEVICEDETAILS_H diff --git a/subsurface.pro b/subsurface.pro index 8711ab505..723513d0e 100644 --- a/subsurface.pro +++ b/subsurface.pro @@ -88,9 +88,9 @@ HEADERS = \ qt-ui/usersurvey.h \ subsurfacesysinfo.h \ qt-ui/configuredivecomputerdialog.h \ - qt-ui/configuredivecomputer.h \ - qt-ui/configuredivecomputerthreads.h \ - qt-ui/devicedetails.h + configuredivecomputer.h \ + configuredivecomputerthreads.h \ + devicedetails.h android: HEADERS -= \ qt-ui/usermanual.h \ @@ -171,9 +171,9 @@ SOURCES = \ qt-ui/usersurvey.cpp \ subsurfacesysinfo.cpp \ qt-ui/configuredivecomputerdialog.cpp \ - qt-ui/configuredivecomputer.cpp \ - qt-ui/configuredivecomputerthreads.cpp \ - qt-ui/devicedetails.cpp + configuredivecomputer.cpp \ + configuredivecomputerthreads.cpp \ + devicedetails.cpp android: SOURCES += android.cpp else: linux*: SOURCES += linux.c -- cgit v1.2.3-70-g09d2