From 74f27a0a399a1f7c63d5542eec744102c301671f Mon Sep 17 00:00:00 2001 From: Anton Lundin Date: Sat, 18 Oct 2014 00:33:47 +0200 Subject: Add support to reset OSTC3 settings to default Signed-off-by: Anton Lundin Signed-off-by: Dirk Hohndel --- configuredivecomputer.cpp | 27 ++++++++++++++++++++++++++- configuredivecomputer.h | 4 ++++ configuredivecomputerthreads.cpp | 31 +++++++++++++++++++++++++++++++ configuredivecomputerthreads.h | 15 +++++++++++++++ qt-ui/configuredivecomputerdialog.cpp | 10 ++++++++++ qt-ui/configuredivecomputerdialog.h | 1 + qt-ui/configuredivecomputerdialog.ui | 10 ++++++++++ 7 files changed, 97 insertions(+), 1 deletion(-) 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 @@ + + + + true + + + Reset device to default settings + + + -- cgit v1.2.3-70-g09d2