mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	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>
This commit is contained in:
		
							parent
							
								
									d63a3ce420
								
							
						
					
					
						commit
						74f27a0a39
					
				
					 7 changed files with 97 additions and 1 deletions
				
			
		|  | @ -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")); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -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); | ||||
| }; | ||||
| 
 | ||||
|  |  | |||
|  | @ -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); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -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
 | ||||
|  |  | |||
|  | @ -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); | ||||
|  |  | |||
|  | @ -21,6 +21,7 @@ public: | |||
| 
 | ||||
| private slots: | ||||
| 	void readSettings(); | ||||
| 	void resetSettings(); | ||||
| 	void configMessage(QString msg); | ||||
| 	void configError(QString err); | ||||
| 	void on_cancel_clicked(); | ||||
|  |  | |||
|  | @ -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"> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue