summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2014-10-18 00:33:47 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-18 15:22:22 -0700
commit74f27a0a399a1f7c63d5542eec744102c301671f (patch)
treebf56cb41966f9e6de5615fbb516e7c3e2aba2821
parentd63a3ce420fcaa6a4b576a840b9d17984f776b2a (diff)
downloadsubsurface-74f27a0a399a1f7c63d5542eec744102c301671f.tar.gz
Add support to reset OSTC3 settings to default
Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--configuredivecomputer.cpp27
-rw-r--r--configuredivecomputer.h4
-rw-r--r--configuredivecomputerthreads.cpp31
-rw-r--r--configuredivecomputerthreads.h15
-rw-r--r--qt-ui/configuredivecomputerdialog.cpp10
-rw-r--r--qt-ui/configuredivecomputerdialog.h1
-rw-r--r--qt-ui/configuredivecomputerdialog.ui10
7 files changed, 97 insertions, 1 deletions
diff --git a/configuredivecomputer.cpp b/configuredivecomputer.cpp
index efda2729a..1b2b9e80b 100644
--- a/configuredivecomputer.cpp
+++ b/configuredivecomputer.cpp
@@ -12,7 +12,8 @@
ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) :
QObject(parent),
readThread(0),
- writeThread(0)
+ writeThread(0),
+ resetThread(0)
{
setState(INITIAL);
}
@@ -514,6 +515,21 @@ void ConfigureDiveComputer::startFirmwareUpdate(QString fileName, device_data_t
}
+void ConfigureDiveComputer::resetSettings(device_data_t *data)
+{
+ setState(RESETTING);
+
+ if (resetThread)
+ resetThread->deleteLater();
+
+ resetThread = new ResetSettingsThread(this, data);
+ connect(resetThread, SIGNAL(finished()),
+ this, SLOT(resetThreadFinished()), Qt::QueuedConnection);
+ connect(resetThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
+
+ resetThread->start();
+}
+
void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
{
currentState = newState;
@@ -540,3 +556,12 @@ void ConfigureDiveComputer::writeThreadFinished()
emit message(tr("Setting successfully written to device"));
}
}
+
+void ConfigureDiveComputer::resetThreadFinished()
+{
+ setState(DONE);
+ if (resetThread->lastError.isEmpty()) {
+ //No error
+ emit message(tr("Device settings successfully resetted"));
+ }
+}
diff --git a/configuredivecomputer.h b/configuredivecomputer.h
index 4522e9fbe..8123576c1 100644
--- a/configuredivecomputer.h
+++ b/configuredivecomputer.h
@@ -21,6 +21,7 @@ public:
INITIAL,
READING,
WRITING,
+ RESETTING,
CANCELLING,
CANCELLED,
ERROR,
@@ -35,6 +36,7 @@ public:
bool saveXMLBackup(QString fileName, DeviceDetails *details, device_data_t *data);
bool restoreXMLBackup(QString fileName, DeviceDetails *details);
void startFirmwareUpdate(QString fileName, device_data_t *data);
+ void resetSettings(device_data_t *data);
signals:
void message(QString msg);
void error(QString err);
@@ -46,10 +48,12 @@ signals:
private:
ReadSettingsThread *readThread;
WriteSettingsThread *writeThread;
+ ResetSettingsThread *resetThread;
void setState(states newState);
private slots:
void readThreadFinished();
void writeThreadFinished();
+ void resetThreadFinished();
void setError(QString err);
};
diff --git a/configuredivecomputerthreads.cpp b/configuredivecomputerthreads.cpp
index 63ceb636f..a8465d7a4 100644
--- a/configuredivecomputerthreads.cpp
+++ b/configuredivecomputerthreads.cpp
@@ -714,3 +714,34 @@ void FirmwareUpdateThread::run()
emit error(lastError);
}
}
+
+
+ResetSettingsThread::ResetSettingsThread(QObject *parent, device_data_t *data)
+: QThread(parent), m_data(data)
+{
+}
+
+void ResetSettingsThread::run()
+{
+ bool supported = false;
+ dc_status_t rc;
+ 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);
+ }
+#endif // divecomputer 0.5.0
+ 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
index 66df7a93b..13f54c406 100644
--- a/configuredivecomputerthreads.h
+++ b/configuredivecomputerthreads.h
@@ -55,4 +55,19 @@ private:
QString m_fileName;
};
+class ResetSettingsThread : public QThread
+{
+ Q_OBJECT
+public:
+ ResetSettingsThread(QObject *parent, device_data_t *data);
+ virtual void run();
+ QString lastError;
+signals:
+ void progress(int percent);
+ void message(QString msg);
+ void error(QString err);
+private:
+ device_data_t *m_data;
+};
+
#endif // CONFIGUREDIVECOMPUTERTHREADS_H
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp
index 8a47e018d..92f4c3909 100644
--- a/qt-ui/configuredivecomputerdialog.cpp
+++ b/qt-ui/configuredivecomputerdialog.cpp
@@ -43,6 +43,7 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
connect(config, SIGNAL(deviceDetailsChanged(DeviceDetails*)),
this, SLOT(deviceDetailsReceived(DeviceDetails*)));
connect(ui.retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings()));
+ connect(ui.resetButton, SIGNAL(clicked()), this, SLOT(resetSettings()));
memset(&device_data, 0, sizeof(device_data));
fill_computer_list();
@@ -329,6 +330,15 @@ void ConfigureDiveComputerDialog::readSettings()
config->readSettings(&device_data);
}
+void ConfigureDiveComputerDialog::resetSettings()
+{
+ ui.statusLabel->clear();
+ ui.errorLabel->clear();
+
+ getDeviceData();
+ config->resetSettings(&device_data);
+}
+
void ConfigureDiveComputerDialog::configMessage(QString msg)
{
ui.statusLabel->setText(msg);
diff --git a/qt-ui/configuredivecomputerdialog.h b/qt-ui/configuredivecomputerdialog.h
index f4e364867..9d4068baf 100644
--- a/qt-ui/configuredivecomputerdialog.h
+++ b/qt-ui/configuredivecomputerdialog.h
@@ -21,6 +21,7 @@ public:
private slots:
void readSettings();
+ void resetSettings();
void configMessage(QString msg);
void configError(QString err);
void on_cancel_clicked();
diff --git a/qt-ui/configuredivecomputerdialog.ui b/qt-ui/configuredivecomputerdialog.ui
index cb192e1f9..c31372649 100644
--- a/qt-ui/configuredivecomputerdialog.ui
+++ b/qt-ui/configuredivecomputerdialog.ui
@@ -572,6 +572,16 @@
</property>
</widget>
</item>
+ <item row="10" column="3" colspan="2">
+ <widget class="QPushButton" name="resetButton">
+ <property name="enabled">
+ <bool>true</bool>
+ </property>
+ <property name="text">
+ <string>Reset device to default settings</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<widget class="QWidget" name="advancedSettings">