summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--configuredivecomputer.cpp45
-rw-r--r--configuredivecomputer.h6
-rw-r--r--configuredivecomputerthreads.cpp284
-rw-r--r--qt-ui/configuredivecomputerdialog.cpp64
-rw-r--r--qt-ui/configuredivecomputerdialog.h4
-rw-r--r--qt-ui/configuredivecomputerdialog.ui31
6 files changed, 209 insertions, 225 deletions
diff --git a/configuredivecomputer.cpp b/configuredivecomputer.cpp
index 65cf3ce72..9e03bc66e 100644
--- a/configuredivecomputer.cpp
+++ b/configuredivecomputer.cpp
@@ -611,3 +611,48 @@ void ConfigureDiveComputer::resetThreadFinished()
emit message(tr("Device settings successfully reset"));
}
}
+
+QString ConfigureDiveComputer::dc_open(device_data_t *data)
+{
+ FILE *fp = NULL;
+ dc_status_t rc;
+
+ if (data->libdc_log)
+ fp = subsurface_fopen(logfile_name, "w");
+
+ data->libdc_logfile = fp;
+
+ rc = dc_context_new(&data->context);
+ if (rc != DC_STATUS_SUCCESS) {
+ return tr("Unable to create libdivecomputer context");
+ }
+
+ if (fp) {
+ dc_context_set_loglevel(data->context, DC_LOGLEVEL_ALL);
+ dc_context_set_logfunc(data->context, logfunc, fp);
+ }
+
+ rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
+ if (rc != DC_STATUS_SUCCESS) {
+ return tr("Could not a establish connection to the dive computer.");
+ }
+
+ setState(OPEN);
+
+ return NULL;
+}
+
+void ConfigureDiveComputer::dc_close(device_data_t *data)
+{
+ if (data->device)
+ dc_device_close(data->device);
+ data->device = NULL;
+ if (data->context)
+ dc_context_free(data->context);
+ data->context = NULL;
+
+ if (data->libdc_logfile)
+ fclose(data->libdc_logfile);
+
+ setState(INITIAL);
+}
diff --git a/configuredivecomputer.h b/configuredivecomputer.h
index fe468ffc2..f14eeeca3 100644
--- a/configuredivecomputer.h
+++ b/configuredivecomputer.h
@@ -17,6 +17,7 @@ public:
void readSettings(device_data_t *data);
enum states {
+ OPEN,
INITIAL,
READING,
WRITING,
@@ -36,6 +37,11 @@ public:
bool restoreXMLBackup(QString fileName, DeviceDetails *details);
void startFirmwareUpdate(QString fileName, device_data_t *data);
void resetSettings(device_data_t *data);
+
+ QString dc_open(device_data_t *data);
+public
+slots:
+ void dc_close(device_data_t *data);
signals:
void progress(int percent);
void message(QString msg);
diff --git a/configuredivecomputerthreads.cpp b/configuredivecomputerthreads.cpp
index f775b8ba9..2c6583e04 100644
--- a/configuredivecomputerthreads.cpp
+++ b/configuredivecomputerthreads.cpp
@@ -1572,78 +1572,43 @@ ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data) : D
void ReadSettingsThread::run()
{
- FILE *fp = NULL;
- bool supported = false;
dc_status_t rc;
- if (m_data->libdc_log)
- fp = subsurface_fopen(logfile_name, "w");
-
- m_data->libdc_logfile = fp;
-
- rc = dc_context_new(&m_data->context);
- if (rc != DC_STATUS_SUCCESS) {
- emit error(tr("Unable to create libdivecomputer context"));
- return;
- }
-
- if (fp) {
- dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
- dc_context_set_logfunc(m_data->context, logfunc, fp);
- }
-
- 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_SUUNTO_VYPER:
- rc = read_suunto_vyper_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
- if (rc == DC_STATUS_SUCCESS) {
- supported = true;
- emit devicedetails(m_deviceDetails);
- } else if (rc == DC_STATUS_UNSUPPORTED) {
- supported = false;
- } else {
- emit error("Failed!");
- }
- break;
+ DeviceDetails *m_deviceDetails = new DeviceDetails(0);
+ switch (dc_device_get_type(m_data->device)) {
+ case DC_FAMILY_SUUNTO_VYPER:
+ rc = read_suunto_vyper_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
+ if (rc == DC_STATUS_SUCCESS) {
+ emit devicedetails(m_deviceDetails);
+ } else if (rc == DC_STATUS_UNSUPPORTED) {
+ emit error(tr("This feature is not yet available for the selected dive computer."));
+ } else {
+ emit error("Failed!");
+ }
+ break;
#if DC_VERSION_CHECK(0, 5, 0)
- case DC_FAMILY_HW_OSTC3:
- supported = true;
- rc = read_ostc3_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
- if (rc == DC_STATUS_SUCCESS)
- emit devicedetails(m_deviceDetails);
- else
- emit error("Failed!");
- break;
+ case DC_FAMILY_HW_OSTC3:
+ rc = read_ostc3_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
+ if (rc == DC_STATUS_SUCCESS)
+ emit devicedetails(m_deviceDetails);
+ else
+ emit error("Failed!");
+ break;
#endif // divecomputer 0.5.0
#ifdef DEBUG_OSTC
- case DC_FAMILY_NULL:
+ case DC_FAMILY_NULL:
#endif
- case DC_FAMILY_HW_OSTC:
- supported = true;
- rc = read_ostc_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
- if (rc == DC_STATUS_SUCCESS)
- emit devicedetails(m_deviceDetails);
- else
- emit error("Failed!");
- break;
- default:
- supported = false;
- break;
- }
- dc_device_close(m_data->device);
-
- if (!supported) {
- emit error(tr("This feature is not yet available for the selected dive computer."));
- }
- } else {
- emit error(tr("Could not a establish connection to the dive computer."));
+ case DC_FAMILY_HW_OSTC:
+ rc = read_ostc_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
+ if (rc == DC_STATUS_SUCCESS)
+ emit devicedetails(m_deviceDetails);
+ else
+ emit error("Failed!");
+ break;
+ default:
+ emit error(tr("This feature is not yet available for the selected dive computer."));
+ break;
}
- dc_context_free(m_data->context);
-
- if (fp)
- fclose(fp);
}
WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data) :
@@ -1659,73 +1624,36 @@ void WriteSettingsThread::setDeviceDetails(DeviceDetails *details)
void WriteSettingsThread::run()
{
- FILE *fp = NULL;
- bool supported = false;
dc_status_t rc;
- if (m_data->libdc_log)
- fp = subsurface_fopen(logfile_name, "w");
-
- m_data->libdc_logfile = fp;
-
- rc = dc_context_new(&m_data->context);
- if (rc != DC_STATUS_SUCCESS) {
- emit error(tr("Unable to create libdivecomputer context"));
- return;
- }
-
- if (fp) {
- dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
- dc_context_set_logfunc(m_data->context, logfunc, fp);
- }
-
- 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_SUUNTO_VYPER:
- rc = write_suunto_vyper_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
- if (rc == DC_STATUS_SUCCESS) {
- supported = true;
- } else if (rc == DC_STATUS_UNSUPPORTED) {
- supported = false;
- } else {
- emit error(tr("Failed!"));
- }
- break;
+ switch (dc_device_get_type(m_data->device)) {
+ case DC_FAMILY_SUUNTO_VYPER:
+ rc = write_suunto_vyper_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
+ if (rc == DC_STATUS_UNSUPPORTED) {
+ emit error(tr("This feature is not yet available for the selected dive computer."));
+ } else if (rc != DC_STATUS_SUCCESS) {
+ emit error(tr("Failed!"));
+ }
+ break;
#if DC_VERSION_CHECK(0, 5, 0)
- case DC_FAMILY_HW_OSTC3:
- supported = true;
- rc = write_ostc3_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
- if (rc != DC_STATUS_SUCCESS)
- emit error(tr("Failed!"));
- break;
+ case DC_FAMILY_HW_OSTC3:
+ rc = write_ostc3_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
+ if (rc != DC_STATUS_SUCCESS)
+ emit error(tr("Failed!"));
+ break;
#endif // divecomputer 0.5.0
#ifdef DEBUG_OSTC
- case DC_FAMILY_NULL:
+ case DC_FAMILY_NULL:
#endif
- case DC_FAMILY_HW_OSTC:
- supported = true;
- rc = write_ostc_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
- if (rc != DC_STATUS_SUCCESS)
- emit error(tr("Failed!"));
- break;
- default:
- supported = false;
- break;
- }
- dc_device_close(m_data->device);
-
- if (!supported) {
- emit error(tr("This feature is not yet available for the selected dive computer."));
- }
- } else {
- emit error(tr("Could not a establish connection to the dive computer."));
+ case DC_FAMILY_HW_OSTC:
+ rc = write_ostc_settings(m_data->device, m_deviceDetails, DeviceThread::event_cb, this);
+ if (rc != DC_STATUS_SUCCESS)
+ emit error(tr("Failed!"));
+ break;
+ default:
+ emit error(tr("This feature is not yet available for the selected dive computer."));
+ break;
}
-
- dc_context_free(m_data->context);
-
- if (fp)
- fclose(fp);
}
@@ -1735,64 +1663,30 @@ FirmwareUpdateThread::FirmwareUpdateThread(QObject *parent, device_data_t *data,
void FirmwareUpdateThread::run()
{
- FILE *fp = NULL;
- bool supported = false;
dc_status_t rc;
- if (m_data->libdc_log)
- fp = subsurface_fopen(logfile_name, "w");
-
- m_data->libdc_logfile = fp;
-
- rc = dc_context_new(&m_data->context);
+ rc = dc_device_set_events(m_data->device, DC_EVENT_PROGRESS, DeviceThread::event_cb, this);
if (rc != DC_STATUS_SUCCESS) {
- emit error(tr("Unable to create libdivecomputer context"));
+ emit error("Error registering the event handler.");
return;
}
-
- if (fp) {
- dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
- dc_context_set_logfunc(m_data->context, logfunc, fp);
- }
-
- rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
- if (rc == DC_STATUS_SUCCESS) {
- rc = dc_device_set_events(m_data->device, DC_EVENT_PROGRESS, DeviceThread::event_cb, this);
- if (rc != DC_STATUS_SUCCESS) {
- emit error("Error registering the event handler.");
- dc_device_close(m_data->device);
- goto firmware_run_out;
- }
- switch (dc_device_get_type(m_data->device)) {
+ switch (dc_device_get_type(m_data->device)) {
#if DC_VERSION_CHECK(0, 5, 0)
- case DC_FAMILY_HW_OSTC3:
- supported = true;
- rc = hw_ostc3_device_fwupdate(m_data->device, m_fileName.toUtf8().data());
- break;
- case DC_FAMILY_HW_OSTC:
- supported = true;
- rc = hw_ostc_device_fwupdate(m_data->device, m_fileName.toUtf8().data());
- break;
+ case DC_FAMILY_HW_OSTC3:
+ rc = hw_ostc3_device_fwupdate(m_data->device, m_fileName.toUtf8().data());
+ break;
+ case DC_FAMILY_HW_OSTC:
+ rc = hw_ostc_device_fwupdate(m_data->device, m_fileName.toUtf8().data());
+ break;
#endif // divecomputer 0.5.0
- default:
- supported = false;
- break;
- }
- dc_device_close(m_data->device);
-
- if (!supported) {
- emit error(tr("This feature is not yet available for the selected dive computer."));
- } else if (rc != DC_STATUS_SUCCESS) {
- emit error(tr("Firmware update failed!"));
- }
- } else {
- emit error(tr("Could not a establish connection to the dive computer."));
+ default:
+ emit error(tr("This feature is not yet available for the selected dive computer."));
+ return;
}
-firmware_run_out:
- dc_context_free(m_data->context);
- if (fp)
- fclose(fp);
+ if (rc != DC_STATUS_SUCCESS) {
+ emit error(tr("Firmware update failed!"));
+ }
}
@@ -1802,45 +1696,15 @@ ResetSettingsThread::ResetSettingsThread(QObject *parent, device_data_t *data) :
void ResetSettingsThread::run()
{
- FILE *fp = NULL;
- bool supported = false;
dc_status_t rc;
- if (m_data->libdc_log)
- fp = subsurface_fopen(logfile_name, "w");
-
- m_data->libdc_logfile = fp;
-
- rc = dc_context_new(&m_data->context);
- if (rc != DC_STATUS_SUCCESS) {
- emit error(tr("Unable to create libdivecomputer context"));
- return;
- }
-
- if (fp) {
- dc_context_set_loglevel(m_data->context, DC_LOGLEVEL_ALL);
- dc_context_set_logfunc(m_data->context, logfunc, fp);
- }
-
- rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
- if (rc == DC_STATUS_SUCCESS) {
#if DC_VERSION_CHECK(0, 5, 0)
- if (dc_device_get_type(m_data->device) == DC_FAMILY_HW_OSTC3) {
- supported = true;
- hw_ostc3_device_config_reset(m_data->device);
- emit progress(100);
- }
+ if (dc_device_get_type(m_data->device) == DC_FAMILY_HW_OSTC3) {
+ rc = hw_ostc3_device_config_reset(m_data->device);
+ emit progress(100);
+ }
#endif // divecomputer 0.5.0
- dc_device_close(m_data->device);
-
- if (!supported) {
- emit error(tr("This feature is not yet available for the selected dive computer."));
- }
- } else {
- emit error(tr("Could not a establish connection to the dive computer."));
+ if (rc != DC_STATUS_SUCCESS) {
+ emit error(tr("Reset settings failed!"));
}
- dc_context_free(m_data->context);
-
- if (fp)
- fclose(fp);
}
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp
index aa8c6cf36..537b23121 100644
--- a/qt-ui/configuredivecomputerdialog.cpp
+++ b/qt-ui/configuredivecomputerdialog.cpp
@@ -131,6 +131,8 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) : QDia
ui.chooseLogFile->setEnabled(ui.logToFile->isChecked());
connect(ui.chooseLogFile, SIGNAL(clicked()), this, SLOT(pickLogFile()));
connect(ui.logToFile, SIGNAL(stateChanged(int)), this, SLOT(checkLogFile(int)));
+ connect(ui.connectButton, SIGNAL(clicked()), this, SLOT(dc_open()));
+ connect(ui.disconnectButton, SIGNAL(clicked()), this, SLOT(dc_close()));
memset(&device_data, 0, sizeof(device_data));
fill_computer_list();
@@ -302,15 +304,20 @@ void OstcFirmwareCheck::saveOstcFirmware(QNetworkReply *reply)
connect(config, SIGNAL(message(QString)), dialog, SLOT(setLabelText(QString)));
connect(config, SIGNAL(error(QString)), dialog, SLOT(setLabelText(QString)));
connect(config, SIGNAL(progress(int)), dialog, SLOT(setValue(int)));
+ connect(dialog, SIGNAL(finished(int)), config, SLOT(dc_close()));
+ config->dc_open(&devData);
config->startFirmwareUpdate(storeFirmware, &devData);
}
ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog()
{
+ delete config;
}
void ConfigureDiveComputerDialog::closeEvent(QCloseEvent *event)
{
+ dc_close();
+
QSettings settings;
settings.beginGroup("ConfigureDiveComputerDialog");
settings.beginGroup("ostc3GasTable");
@@ -710,7 +717,6 @@ void ConfigureDiveComputerDialog::readSettings()
ui.progressBar->setFormat("%p%");
ui.progressBar->setTextVisible(true);
- getDeviceData();
config->readSettings(&device_data);
}
@@ -720,7 +726,6 @@ void ConfigureDiveComputerDialog::resetSettings()
ui.progressBar->setFormat("%p%");
ui.progressBar->setTextVisible(true);
- getDeviceData();
config->resetSettings(&device_data);
}
@@ -758,7 +763,6 @@ void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked()
ui.progressBar->setTextVisible(true);
populateDeviceDetails();
- getDeviceData();
config->saveDeviceDetails(deviceDetails, &device_data);
}
@@ -1067,7 +1071,6 @@ void ConfigureDiveComputerDialog::on_backupButton_clicked()
filename, tr("Backup files (*.xml)"));
if (!backupPath.isEmpty()) {
populateDeviceDetails();
- getDeviceData();
if (!config->saveXMLBackup(backupPath, deviceDetails, &device_data)) {
QMessageBox::critical(this, tr("XML backup error"),
tr("An error occurred while saving the backup file.\n%1")
@@ -1094,8 +1097,6 @@ void ConfigureDiveComputerDialog::on_restoreBackupButton_clicked()
.arg(config->lastError));
} else {
reloadValues();
- //getDeviceData();
- //config->saveDeviceDetails(deviceDetails, &device_data);
QMessageBox::information(this, tr("Restore succeeded"),
tr("Your settings have been restored successfully."));
}
@@ -1114,7 +1115,6 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked()
ui.progressBar->setFormat("%p%");
ui.progressBar->setTextVisible(true);
- getDeviceData();
config->startFirmwareUpdate(firmwarePath, &device_data);
}
}
@@ -1122,25 +1122,21 @@ void ConfigureDiveComputerDialog::on_updateFirmwareButton_clicked()
void ConfigureDiveComputerDialog::on_DiveComputerList_currentRowChanged(int currentRow)
{
- // Disable the buttons to do operations on this data
- ui.saveSettingsPushButton->setEnabled(false);
- ui.backupButton->setEnabled(false);
-
switch (currentRow) {
case 0:
selected_vendor = "Heinrichs Weikamp";
selected_product = "OSTC 3";
- ui.updateFirmwareButton->setEnabled(true);
+ fw_upgrade_possible = true;
break;
case 1:
selected_vendor = "Suunto";
selected_product = "Vyper";
- ui.updateFirmwareButton->setEnabled(false);
+ fw_upgrade_possible = false;
break;
case 2:
selected_vendor = "Heinrichs Weikamp";
selected_product = "OSTC 2N";
- ui.updateFirmwareButton->setEnabled(true);
+ fw_upgrade_possible = true;
break;
default:
/* Not Supported */
@@ -1176,3 +1172,43 @@ void ConfigureDiveComputerDialog::pickLogFile()
logfile_name = strdup(logFile.toUtf8().data());
}
}
+
+void ConfigureDiveComputerDialog::dc_open()
+{
+ getDeviceData();
+
+ QString err = config->dc_open(&device_data);
+
+ if (err != "")
+ return ui.progressBar->setFormat(err);
+
+ ui.retrieveDetails->setEnabled(true);
+ ui.resetButton->setEnabled(true);
+ ui.updateFirmwareButton->setEnabled(true);
+ ui.disconnectButton->setEnabled(true);
+ ui.restoreBackupButton->setEnabled(true);
+ ui.connectButton->setEnabled(false);
+ ui.DiveComputerList->setEnabled(false);
+ ui.logToFile->setEnabled(false);
+ if (fw_upgrade_possible)
+ ui.updateFirmwareButton->setEnabled(true);
+ ui.progressBar->setFormat("Connected to device");
+}
+
+void ConfigureDiveComputerDialog::dc_close()
+{
+ config->dc_close(&device_data);
+
+ ui.retrieveDetails->setEnabled(false);
+ ui.resetButton->setEnabled(false);
+ ui.updateFirmwareButton->setEnabled(false);
+ ui.disconnectButton->setEnabled(false);
+ ui.connectButton->setEnabled(true);
+ ui.backupButton->setEnabled(false);
+ ui.saveSettingsPushButton->setEnabled(false);
+ ui.restoreBackupButton->setEnabled(false);
+ ui.DiveComputerList->setEnabled(true);
+ ui.logToFile->setEnabled(true);
+ ui.updateFirmwareButton->setEnabled(false);
+ ui.progressBar->setFormat("Disonnected from device");
+}
diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h
index 19bab0a5b..d11726873 100644
--- a/qt-ui/configuredivecomputerdialog.h
+++ b/qt-ui/configuredivecomputerdialog.h
@@ -81,6 +81,9 @@ slots:
void on_DiveComputerList_currentRowChanged(int currentRow);
+ void dc_open();
+ void dc_close();
+
private:
Ui::ConfigureDiveComputerDialog ui;
@@ -108,6 +111,7 @@ private:
QString selected_vendor;
QString selected_product;
+ bool fw_upgrade_possible;
};
class OstcFirmwareCheck : QObject {
diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui
index a0a0a2eac..edc24e29e 100644
--- a/qt-ui/configuredivecomputerdialog.ui
+++ b/qt-ui/configuredivecomputerdialog.ui
@@ -30,6 +30,12 @@
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QComboBox" name="device">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Maximum">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
<property name="editable">
<bool>true</bool>
</property>
@@ -42,6 +48,23 @@
</property>
</widget>
</item>
+ <item>
+ <widget class="QPushButton" name="connectButton">
+ <property name="text">
+ <string>Connect</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QPushButton" name="disconnectButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
+ <property name="text">
+ <string>Disconnect</string>
+ </property>
+ </widget>
+ </item>
</layout>
</item>
</layout>
@@ -50,6 +73,9 @@
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="retrieveDetails">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
<property name="text">
<string>Retrieve available details</string>
</property>
@@ -96,6 +122,9 @@
</item>
<item>
<widget class="QPushButton" name="restoreBackupButton">
+ <property name="enabled">
+ <bool>false</bool>
+ </property>
<property name="text">
<string>Restore backup</string>
</property>
@@ -595,7 +624,7 @@
<item row="10" column="3" colspan="2">
<widget class="QPushButton" name="resetButton">
<property name="enabled">
- <bool>true</bool>
+ <bool>false</bool>
</property>
<property name="text">
<string>Reset device to default settings</string>