diff options
-rw-r--r-- | qt-ui/configuredivecomputer.cpp | 23 | ||||
-rw-r--r-- | qt-ui/configuredivecomputer.h | 6 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.cpp | 32 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.h | 2 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerdialog.ui | 74 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerthreads.cpp | 61 | ||||
-rw-r--r-- | qt-ui/configuredivecomputerthreads.h | 12 |
7 files changed, 150 insertions, 60 deletions
diff --git a/qt-ui/configuredivecomputer.cpp b/qt-ui/configuredivecomputer.cpp index d24c8905d..ad431eefe 100644 --- a/qt-ui/configuredivecomputer.cpp +++ b/qt-ui/configuredivecomputer.cpp @@ -4,31 +4,42 @@ ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) : QObject(parent), readThread(0), - writeThread(0), - m_deviceDetails(0) + writeThread(0) { setState(INITIAL); } -void ConfigureDiveComputer::readSettings(DeviceDetails *deviceDetails, device_data_t *data) +void ConfigureDiveComputer::readSettings(device_data_t *data) { setState(READING); - m_deviceDetails = deviceDetails; if (readThread) readThread->deleteLater(); - readThread = new ReadSettingsThread(this, deviceDetails, data); + 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() +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(); } void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState) diff --git a/qt-ui/configuredivecomputer.h b/qt-ui/configuredivecomputer.h index 65ceaa780..f21f02910 100644 --- a/qt-ui/configuredivecomputer.h +++ b/qt-ui/configuredivecomputer.h @@ -13,7 +13,7 @@ class ConfigureDiveComputer : public QObject Q_OBJECT public: explicit ConfigureDiveComputer(QObject *parent = 0); - void readSettings(DeviceDetails *deviceDetails, device_data_t *data); + void readSettings(device_data_t *data); enum states { INITIAL, @@ -27,9 +27,8 @@ public: QString lastError; states currentState; - DeviceDetails *m_deviceDetails; device_data_t *m_data; - void saveDeviceDetails(); + void saveDeviceDetails(DeviceDetails *details, device_data_t *data); void fetchDeviceDetails(); signals: @@ -38,6 +37,7 @@ signals: void readFinished(); void writeFinished(); void stateChanged(states newState); + void deviceDetailsChanged(DeviceDetails *newDetails); private: ReadSettingsThread *readThread; diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp index 8ae250468..ea5e764dc 100644 --- a/qt-ui/configuredivecomputerdialog.cpp +++ b/qt-ui/configuredivecomputerdialog.cpp @@ -8,6 +8,7 @@ #include "../divelist.h" #include "configuredivecomputer.h" #include <QInputDialog> +#include <QDebug> struct product { const char *product; @@ -43,6 +44,8 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString))); connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString))); connect (config, SIGNAL(readFinished()), this, SLOT(deviceReadFinished())); + connect (config, SIGNAL(deviceDetailsChanged(DeviceDetails*)), + this, SLOT(deviceDetailsReceived(DeviceDetails*))); fill_computer_list(); @@ -159,7 +162,7 @@ void ConfigureDiveComputerDialog::readSettings() ui->errorLabel->clear(); getDeviceData(); - config->readSettings(deviceDetails, &device_data); + config->readSettings(&device_data); } void ConfigureDiveComputerDialog::configMessage(QString msg) @@ -183,8 +186,6 @@ 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() @@ -194,11 +195,32 @@ void ConfigureDiveComputerDialog::on_cancel_clicked() void ConfigureDiveComputerDialog::deviceReadFinished() { - ui->brightnessComboBox->setCurrentIndex(config->m_deviceDetails->brightness()); + } void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked() { - config->saveDeviceDetails(); + deviceDetails->setBrightness(ui->brightnessComboBox->currentIndex()); + deviceDetails->setLanguage(ui->languageComboBox->currentIndex()); + deviceDetails->setDateFormat(ui->dateFormatComboBox->currentIndex()); + deviceDetails->setCustomText(ui->customTextLlineEdit->text()); + getDeviceData(); + config->saveDeviceDetails(deviceDetails, &device_data); +} + +void ConfigureDiveComputerDialog::deviceDetailsReceived(DeviceDetails *newDeviceDetails) +{ + deviceDetails = newDeviceDetails; + reloadValues(); +} + +void ConfigureDiveComputerDialog::reloadValues() +{ + ui->serialNoLineEdit->setText(deviceDetails->serialNo()); + ui->firmwareVersionLineEdit->setText(deviceDetails->firmwareVersion()); + ui->customTextLlineEdit->setText(deviceDetails->customText()); + ui->brightnessComboBox->setCurrentIndex(deviceDetails->brightness()); + ui->languageComboBox->setCurrentIndex(deviceDetails->language()); + ui->dateFormatComboBox->setCurrentIndex(deviceDetails->dateFormat()); } diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h index 5a8bf63e1..e8c941fcf 100644 --- a/qt-ui/configuredivecomputerdialog.h +++ b/qt-ui/configuredivecomputerdialog.h @@ -29,6 +29,8 @@ private slots: void on_cancel_clicked(); void deviceReadFinished(); void on_saveSettingsPushButton_clicked(); + void deviceDetailsReceived(DeviceDetails *newDeviceDetails); + void reloadValues(); private: Ui::ConfigureDiveComputerDialog *ui; diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui index d7c584e0c..4f1c7a8af 100644 --- a/qt-ui/configuredivecomputerdialog.ui +++ b/qt-ui/configuredivecomputerdialog.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>343</width> - <height>365</height> + <height>390</height> </rect> </property> <property name="windowTitle"> @@ -93,12 +93,8 @@ </item> <item> <layout class="QGridLayout" name="gridLayout_2"> - <item row="3" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Brightness:</string> - </property> - </widget> + <item row="2" column="1"> + <widget class="QLineEdit" name="customTextLlineEdit"/> </item> <item row="3" column="1"> <widget class="QComboBox" name="brightnessComboBox"> @@ -119,10 +115,10 @@ </item> </widget> </item> - <item row="0" column="1"> - <widget class="QLineEdit" name="serialNoLineEdit"> - <property name="readOnly"> - <bool>true</bool> + <item row="1" column="0"> + <widget class="QLabel" name="label_8"> + <property name="text"> + <string>Firmware Version:</string> </property> </widget> </item> @@ -150,20 +146,17 @@ </item> </widget> </item> - <item row="2" column="1"> - <widget class="QLineEdit" name="customTextLlineEdit"/> - </item> - <item row="4" column="0"> - <widget class="QLabel" name="label_6"> + <item row="3" column="0"> + <widget class="QLabel" name="label_4"> <property name="text"> - <string>Language:</string> + <string>Brightness:</string> </property> </widget> </item> - <item row="0" column="0"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>Serial No.</string> + <item row="0" column="1"> + <widget class="QLineEdit" name="serialNoLineEdit"> + <property name="readOnly"> + <bool>true</bool> </property> </widget> </item> @@ -174,10 +167,17 @@ </property> </widget> </item> - <item row="1" column="0"> - <widget class="QLabel" name="label_8"> + <item row="0" column="0"> + <widget class="QLabel" name="label_7"> <property name="text"> - <string>Firmware Version:</string> + <string>Serial No.</string> + </property> + </widget> + </item> + <item row="4" column="0"> + <widget class="QLabel" name="label_6"> + <property name="text"> + <string>Language:</string> </property> </widget> </item> @@ -188,6 +188,32 @@ </property> </widget> </item> + <item row="5" column="0"> + <widget class="QLabel" name="label_9"> + <property name="text"> + <string>Date Format:</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <widget class="QComboBox" name="dateFormatComboBox"> + <item> + <property name="text"> + <string>MMDDYY</string> + </property> + </item> + <item> + <property name="text"> + <string>DDMMYY</string> + </property> + </item> + <item> + <property name="text"> + <string>YYMMDD</string> + </property> + </item> + </widget> + </item> </layout> </item> <item> diff --git a/qt-ui/configuredivecomputerthreads.cpp b/qt-ui/configuredivecomputerthreads.cpp index f1ac3b5d9..5d9f0e8b0 100644 --- a/qt-ui/configuredivecomputerthreads.cpp +++ b/qt-ui/configuredivecomputerthreads.cpp @@ -2,8 +2,8 @@ #include "libdivecomputer/hw.h" #include <QDebug> -ReadSettingsThread::ReadSettingsThread(QObject *parent, DeviceDetails *deviceDetails, device_data_t *data) - : QThread(parent), m_deviceDetails(deviceDetails), m_data(data) +ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) + : QThread(parent), m_data(data) { } @@ -14,6 +14,7 @@ void ReadSettingsThread::run() 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; @@ -25,7 +26,8 @@ void ReadSettingsThread::run() m_deviceDetails->setLanguage(0); m_deviceDetails->setLastDeco(0); m_deviceDetails->setSerialNo(""); - unsigned char uData[1]; + //Read general settings + unsigned char uData[1] = {0}; rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData)); if (rc == DC_STATUS_SUCCESS) m_deviceDetails->setBrightness(uData[0]); @@ -35,6 +37,20 @@ void ReadSettingsThread::run() 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; } @@ -51,31 +67,46 @@ void ReadSettingsThread::run() } } -WriteSettingsThread::WriteSettingsThread(QObject *parent, DeviceDetails *deviceDetails, QString settingName, QVariant settingValue) - : QThread(parent), m_deviceDetails(deviceDetails), m_settingName(settingName), m_settingValue(settingValue) -{ +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 + hw_ostc3_device_customtext(m_data->device, m_deviceDetails->customText().toUtf8().data()); + unsigned char data[1] = {0}; + data[0] = m_deviceDetails->brightness(); + hw_ostc3_device_config_write(m_data->device, 0x2D, data, sizeof(data)); + data[0] = m_deviceDetails->language(); + hw_ostc3_device_config_write(m_data->device, 0x32, data, sizeof(data)); + data[0] = m_deviceDetails->dateFormat(); + hw_ostc3_device_config_write(m_data->device, 0x33, data, sizeof(data)); + break; - 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; + 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 index c684cddaa..db54db460 100644 --- a/qt-ui/configuredivecomputerthreads.h +++ b/qt-ui/configuredivecomputerthreads.h @@ -11,31 +11,29 @@ class ReadSettingsThread : public QThread { Q_OBJECT public: - ReadSettingsThread(QObject *parent, DeviceDetails *deviceDetails, device_data_t *data); + ReadSettingsThread(QObject *parent, device_data_t *data); virtual void run(); QString result; QString lastError; signals: void error(QString err); + void devicedetails(DeviceDetails *newDeviceDetails); 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); + 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 *data; - QString m_settingName; - QVariant m_settingValue; - + device_data_t *m_data; DeviceDetails *m_deviceDetails; }; |