mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Read basic details from dive computer
Added classes for reading data from dive computer. This is at the basic level and I will expand it as I go along. Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com> Signed-off-by: Thiago Macieira <thiago@macieira.org>
This commit is contained in:
		
							parent
							
								
									791fbee260
								
							
						
					
					
						commit
						a7c9b25b05
					
				
					 6 changed files with 212 additions and 2 deletions
				
			
		
							
								
								
									
										74
									
								
								qt-ui/configuredivecomputer.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								qt-ui/configuredivecomputer.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,74 @@
 | 
			
		|||
#include "configuredivecomputer.h"
 | 
			
		||||
#include "libdivecomputer/hw.h"
 | 
			
		||||
#include <QDebug>
 | 
			
		||||
ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) :
 | 
			
		||||
	QObject(parent),
 | 
			
		||||
	readThread(0)
 | 
			
		||||
{
 | 
			
		||||
	setState(INITIAL);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputer::readSettings(device_data_t *data)
 | 
			
		||||
{
 | 
			
		||||
	setState(READING);
 | 
			
		||||
 | 
			
		||||
	if (readThread)
 | 
			
		||||
		readThread->deleteLater();
 | 
			
		||||
 | 
			
		||||
	readThread = new ReadSettingsThread(this, data);
 | 
			
		||||
	connect (readThread, SIGNAL(finished()),
 | 
			
		||||
		 this, SLOT(readThreadFinished()), Qt::QueuedConnection);
 | 
			
		||||
	connect (readThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
 | 
			
		||||
 | 
			
		||||
	readThread->start();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
 | 
			
		||||
{
 | 
			
		||||
	currentState = newState;
 | 
			
		||||
	emit stateChanged(currentState);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputer::setError(QString err)
 | 
			
		||||
{
 | 
			
		||||
	lastError = err;
 | 
			
		||||
	emit error(err);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputer::readHWSettings(device_data_t *data)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputer::readThreadFinished()
 | 
			
		||||
{
 | 
			
		||||
	setState(DONE);
 | 
			
		||||
	emit deviceSettings(readThread->result);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data)
 | 
			
		||||
	: QThread(parent), data(data)
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ReadSettingsThread::run()
 | 
			
		||||
{
 | 
			
		||||
	QString vendor = data->vendor;
 | 
			
		||||
	dc_status_t rc;
 | 
			
		||||
	rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
 | 
			
		||||
	if (rc == DC_STATUS_SUCCESS) {
 | 
			
		||||
		if (vendor.trimmed() == "Heinrichs Weikamp") {
 | 
			
		||||
			unsigned char hw_data[10];
 | 
			
		||||
			hw_frog_device_version(data->device, hw_data, 10);
 | 
			
		||||
			QTextStream (&result) << "Device Version: " << hw_data; //just a test. I will work on decoding this
 | 
			
		||||
		} else {
 | 
			
		||||
			lastError = tr("This feature is not yet available for the selected dive computer.");
 | 
			
		||||
			emit error(lastError);
 | 
			
		||||
		}
 | 
			
		||||
		dc_device_close(data->device);
 | 
			
		||||
	} else {
 | 
			
		||||
		lastError = tr("Could not a establish connection to the dive computer.");
 | 
			
		||||
		emit error(lastError);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										58
									
								
								qt-ui/configuredivecomputer.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								qt-ui/configuredivecomputer.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,58 @@
 | 
			
		|||
#ifndef CONFIGUREDIVECOMPUTER_H
 | 
			
		||||
#define CONFIGUREDIVECOMPUTER_H
 | 
			
		||||
 | 
			
		||||
#include <QObject>
 | 
			
		||||
#include <QThread>
 | 
			
		||||
#include "libdivecomputer.h"
 | 
			
		||||
 | 
			
		||||
class ReadSettingsThread : public QThread {
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
	ReadSettingsThread(QObject *parent, device_data_t *data);
 | 
			
		||||
	virtual void run();
 | 
			
		||||
	QString result;
 | 
			
		||||
	QString lastError;
 | 
			
		||||
signals:
 | 
			
		||||
	void error(QString err);
 | 
			
		||||
private:
 | 
			
		||||
	device_data_t *data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class ConfigureDiveComputer : public QObject
 | 
			
		||||
{
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
public:
 | 
			
		||||
	explicit ConfigureDiveComputer(QObject *parent = 0);
 | 
			
		||||
	void readSettings(device_data_t *data);
 | 
			
		||||
 | 
			
		||||
	enum states {
 | 
			
		||||
			INITIAL,
 | 
			
		||||
			READING,
 | 
			
		||||
			WRITING,
 | 
			
		||||
			CANCELLING,
 | 
			
		||||
			CANCELLED,
 | 
			
		||||
			ERROR,
 | 
			
		||||
			DONE,
 | 
			
		||||
		};
 | 
			
		||||
 | 
			
		||||
	QString lastError;
 | 
			
		||||
	states currentState;
 | 
			
		||||
signals:
 | 
			
		||||
	void deviceSettings(QString settings);
 | 
			
		||||
	void message(QString msg);
 | 
			
		||||
	void error(QString err);
 | 
			
		||||
	void readFinished();
 | 
			
		||||
	void writeFinished();
 | 
			
		||||
	void stateChanged(states newState);
 | 
			
		||||
private:
 | 
			
		||||
	ReadSettingsThread *readThread;
 | 
			
		||||
	void setState(states newState);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	void readHWSettings(device_data_t *data);
 | 
			
		||||
private slots:
 | 
			
		||||
	void readThreadFinished();
 | 
			
		||||
	void setError(QString err);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // CONFIGUREDIVECOMPUTER_H
 | 
			
		||||
| 
						 | 
				
			
			@ -6,6 +6,7 @@
 | 
			
		|||
#include "../helpers.h"
 | 
			
		||||
#include "../display.h"
 | 
			
		||||
#include "../divelist.h"
 | 
			
		||||
#include "configuredivecomputer.h"
 | 
			
		||||
struct product {
 | 
			
		||||
	const char *product;
 | 
			
		||||
	dc_descriptor_t *descriptor;
 | 
			
		||||
| 
						 | 
				
			
			@ -28,11 +29,17 @@ struct mydescriptor {
 | 
			
		|||
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
 | 
			
		||||
	QDialog(parent),
 | 
			
		||||
	ui(new Ui::ConfigureDiveComputerDialog),
 | 
			
		||||
	config(0),
 | 
			
		||||
	vendorModel(0),
 | 
			
		||||
	productModel(0)
 | 
			
		||||
{
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
 | 
			
		||||
	config = new ConfigureDiveComputer(this);
 | 
			
		||||
	connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
 | 
			
		||||
	connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
 | 
			
		||||
	connect (config, SIGNAL(deviceSettings(QString)), ui->availableDetails, SLOT(setText(QString)));
 | 
			
		||||
 | 
			
		||||
	fill_computer_list();
 | 
			
		||||
 | 
			
		||||
	vendorModel = new QStringListModel(vendorList);
 | 
			
		||||
| 
						 | 
				
			
			@ -46,6 +53,10 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
 | 
			
		|||
	}
 | 
			
		||||
	if (default_dive_computer_device)
 | 
			
		||||
		ui->device->setEditText(default_dive_computer_device);
 | 
			
		||||
 | 
			
		||||
	memset(&device_data, 0, sizeof(device_data));
 | 
			
		||||
 | 
			
		||||
	connect (ui->retrieveDetails, SIGNAL(clicked()), this, SLOT(readSettings()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ConfigureDiveComputerDialog::~ConfigureDiveComputerDialog()
 | 
			
		||||
| 
						 | 
				
			
			@ -137,3 +148,40 @@ void ConfigureDiveComputerDialog::on_product_currentIndexChanged(const QString &
 | 
			
		|||
		ui->device->setEnabled(false);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputerDialog::readSettings()
 | 
			
		||||
{
 | 
			
		||||
	ui->statusLabel->clear();
 | 
			
		||||
	ui->errorLabel->clear();
 | 
			
		||||
 | 
			
		||||
	getDeviceData();
 | 
			
		||||
	config->readSettings(&device_data);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputerDialog::configMessage(QString msg)
 | 
			
		||||
{
 | 
			
		||||
	ui->statusLabel->setText(msg);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputerDialog::configError(QString err)
 | 
			
		||||
{
 | 
			
		||||
	ui->errorLabel->setText(err);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputerDialog::getDeviceData()
 | 
			
		||||
{
 | 
			
		||||
	device_data.devname = strdup(ui->device->currentText().toUtf8().data());
 | 
			
		||||
	device_data.vendor = strdup(ui->vendor->currentText().toUtf8().data());
 | 
			
		||||
	device_data.product = strdup(ui->product->currentText().toUtf8().data());
 | 
			
		||||
 | 
			
		||||
	device_data.descriptor = descriptorLookup[ui->vendor->currentText() + ui->product->currentText()];
 | 
			
		||||
	device_data.deviceid = device_data.diveid = 0;
 | 
			
		||||
 | 
			
		||||
	set_default_dive_computer(device_data.vendor, device_data.product);
 | 
			
		||||
	set_default_dive_computer_device(device_data.devname);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConfigureDiveComputerDialog::on_cancel_clicked()
 | 
			
		||||
{
 | 
			
		||||
	this->close();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,6 +4,9 @@
 | 
			
		|||
#include <QDialog>
 | 
			
		||||
#include <QStringListModel>
 | 
			
		||||
#include "../libdivecomputer.h"
 | 
			
		||||
 | 
			
		||||
class ConfigureDiveComputer;
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class ConfigureDiveComputerDialog;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -21,9 +24,17 @@ private slots:
 | 
			
		|||
 | 
			
		||||
	void on_product_currentIndexChanged(const QString &product);
 | 
			
		||||
 | 
			
		||||
	void readSettings();
 | 
			
		||||
	void configMessage(QString msg);
 | 
			
		||||
	void configError(QString err);
 | 
			
		||||
	void on_cancel_clicked();
 | 
			
		||||
private:
 | 
			
		||||
	Ui::ConfigureDiveComputerDialog *ui;
 | 
			
		||||
 | 
			
		||||
	ConfigureDiveComputer *config;
 | 
			
		||||
	device_data_t device_data;
 | 
			
		||||
	void getDeviceData();
 | 
			
		||||
 | 
			
		||||
	QStringList vendorList;
 | 
			
		||||
	QHash<QString, QStringList> productList;
 | 
			
		||||
	QHash<QString, dc_descriptor_t *> descriptorLookup;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -94,6 +94,23 @@
 | 
			
		|||
   <item>
 | 
			
		||||
    <widget class="QTextBrowser" name="availableDetails"/>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QLabel" name="errorLabel">
 | 
			
		||||
     <property name="styleSheet">
 | 
			
		||||
      <string notr="true">color: rgb(242, 19, 25);</string>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="text">
 | 
			
		||||
      <string/>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QLabel" name="statusLabel">
 | 
			
		||||
     <property name="text">
 | 
			
		||||
      <string/>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QHBoxLayout" name="horizontalLayout_3">
 | 
			
		||||
     <item>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -87,7 +87,8 @@ HEADERS = \
 | 
			
		|||
	qt-ui/divelogexportdialog.h \
 | 
			
		||||
	qt-ui/usersurvey.h \
 | 
			
		||||
	subsurfacesysinfo.h \
 | 
			
		||||
	qt-ui/configuredivecomputerdialog.h
 | 
			
		||||
	qt-ui/configuredivecomputerdialog.h \
 | 
			
		||||
	qt-ui/configuredivecomputer.h \
 | 
			
		||||
 | 
			
		||||
android: HEADERS -= \
 | 
			
		||||
	qt-ui/usermanual.h \
 | 
			
		||||
| 
						 | 
				
			
			@ -167,7 +168,8 @@ SOURCES =  \
 | 
			
		|||
	qt-ui/divelogexportdialog.cpp \
 | 
			
		||||
	qt-ui/usersurvey.cpp \
 | 
			
		||||
	subsurfacesysinfo.cpp \
 | 
			
		||||
	qt-ui/configuredivecomputerdialog.cpp
 | 
			
		||||
	qt-ui/configuredivecomputerdialog.cpp \
 | 
			
		||||
	qt-ui/configuredivecomputer.cpp
 | 
			
		||||
 | 
			
		||||
android: SOURCES += android.cpp
 | 
			
		||||
else: linux*: SOURCES += linux.c
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue