mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Create class to write settings to dive computer
Adds a class to write settings to dive computer, and modifies the existing ones to integrate it. Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com> Signed-off-by: Thiago Macieira <thiago@macieira.org>
This commit is contained in:
parent
a7c9b25b05
commit
3e127a059f
5 changed files with 156 additions and 9 deletions
|
@ -3,7 +3,8 @@
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) :
|
ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
readThread(0)
|
readThread(0),
|
||||||
|
writeThread(0)
|
||||||
{
|
{
|
||||||
setState(INITIAL);
|
setState(INITIAL);
|
||||||
}
|
}
|
||||||
|
@ -23,29 +24,57 @@ void ConfigureDiveComputer::readSettings(device_data_t *data)
|
||||||
readThread->start();
|
readThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigureDiveComputer::setDeviceName(device_data_t *data, QString newName)
|
||||||
|
{
|
||||||
|
writeSettingToDevice(data, "Name", newName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureDiveComputer::setDeviceDateAndTime(device_data_t *data, QDateTime dateAndTime)
|
||||||
|
{
|
||||||
|
writeSettingToDevice(data, "DateAndTime", dateAndTime);
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
|
void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
|
||||||
{
|
{
|
||||||
currentState = newState;
|
currentState = newState;
|
||||||
emit stateChanged(currentState);
|
emit stateChanged(currentState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigureDiveComputer::writeSettingToDevice(device_data_t *data, QString settingName, QVariant settingValue)
|
||||||
|
{
|
||||||
|
setState(READING);
|
||||||
|
|
||||||
|
if (writeThread)
|
||||||
|
writeThread->deleteLater();
|
||||||
|
|
||||||
|
writeThread = new WriteSettingsThread(this, data, settingName, settingValue);
|
||||||
|
connect (writeThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
|
||||||
|
connect (writeThread, SIGNAL(finished()), this, SLOT(writeThreadFinished()));
|
||||||
|
|
||||||
|
writeThread->start();
|
||||||
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputer::setError(QString err)
|
void ConfigureDiveComputer::setError(QString err)
|
||||||
{
|
{
|
||||||
lastError = err;
|
lastError = err;
|
||||||
emit error(err);
|
emit error(err);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputer::readHWSettings(device_data_t *data)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigureDiveComputer::readThreadFinished()
|
void ConfigureDiveComputer::readThreadFinished()
|
||||||
{
|
{
|
||||||
setState(DONE);
|
setState(DONE);
|
||||||
emit deviceSettings(readThread->result);
|
emit deviceSettings(readThread->result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigureDiveComputer::writeThreadFinished()
|
||||||
|
{
|
||||||
|
setState(DONE);
|
||||||
|
if (writeThread->lastError.isEmpty()) {
|
||||||
|
//No error
|
||||||
|
emit message(tr("Setting successfully written to device"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data)
|
ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data)
|
||||||
: QThread(parent), data(data)
|
: QThread(parent), data(data)
|
||||||
{
|
{
|
||||||
|
@ -72,3 +101,54 @@ void ReadSettingsThread::run()
|
||||||
emit error(lastError);
|
emit error(lastError);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data, QString settingName, QVariant settingValue)
|
||||||
|
: QThread(parent), data(data), m_settingName(settingName), m_settingValue(settingValue)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteSettingsThread::run()
|
||||||
|
{
|
||||||
|
bool supported = false;
|
||||||
|
dc_status_t rc;
|
||||||
|
QString product = data->product;
|
||||||
|
QString vendor = data->vendor;
|
||||||
|
rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
|
||||||
|
if (rc == DC_STATUS_SUCCESS) {
|
||||||
|
dc_status_t result;
|
||||||
|
if (product.trimmed() == "OSTC 3") {
|
||||||
|
if (m_settingName == "Name") {
|
||||||
|
supported = true;
|
||||||
|
result = hw_ostc3_device_customtext(data->device, m_settingValue.toByteArray().data());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (vendor.trimmed() == "Heinrichs Weikamp" && m_settingName == "DateAndTime") {
|
||||||
|
supported = true;
|
||||||
|
QDateTime timeToSet = m_settingValue.toDateTime();
|
||||||
|
dc_datetime_t time;
|
||||||
|
time.year = timeToSet.date().year();
|
||||||
|
time.month = timeToSet.date().month();
|
||||||
|
time.day = timeToSet.date().day();
|
||||||
|
time.hour = timeToSet.time().hour();
|
||||||
|
time.minute = timeToSet.time().minute();
|
||||||
|
time.second = timeToSet.time().second();
|
||||||
|
result = hw_ostc_device_clock(data->device, &time); //Toto fix error here
|
||||||
|
}
|
||||||
|
if (result != DC_STATUS_SUCCESS) {
|
||||||
|
qDebug() << result;
|
||||||
|
lastError = tr("An error occurred while sending data to the dive computer.");
|
||||||
|
//Todo Update this message to change depending on actual result.
|
||||||
|
|
||||||
|
emit error(lastError);
|
||||||
|
}
|
||||||
|
dc_device_close(data->device);
|
||||||
|
} else {
|
||||||
|
lastError = tr("Could not a establish connection to the dive computer.");
|
||||||
|
emit error(lastError);
|
||||||
|
}
|
||||||
|
if (!supported) {
|
||||||
|
lastError = tr("This feature is not yet available for the selected dive computer.");
|
||||||
|
emit error(lastError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,8 +3,9 @@
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include <QVariant>
|
||||||
#include "libdivecomputer.h"
|
#include "libdivecomputer.h"
|
||||||
|
#include <QDateTime>
|
||||||
class ReadSettingsThread : public QThread {
|
class ReadSettingsThread : public QThread {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
@ -18,6 +19,21 @@ private:
|
||||||
device_data_t *data;
|
device_data_t *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class WriteSettingsThread : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
WriteSettingsThread(QObject *parent, device_data_t *data, QString settingName, QVariant settingValue);
|
||||||
|
virtual void run();
|
||||||
|
QString result;
|
||||||
|
QString lastError;
|
||||||
|
signals:
|
||||||
|
void error(QString err);
|
||||||
|
private:
|
||||||
|
device_data_t *data;
|
||||||
|
QString m_settingName;
|
||||||
|
QVariant m_settingValue;
|
||||||
|
};
|
||||||
|
|
||||||
class ConfigureDiveComputer : public QObject
|
class ConfigureDiveComputer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -37,6 +53,9 @@ public:
|
||||||
|
|
||||||
QString lastError;
|
QString lastError;
|
||||||
states currentState;
|
states currentState;
|
||||||
|
|
||||||
|
void setDeviceName(device_data_t *data, QString newName);
|
||||||
|
void setDeviceDateAndTime(device_data_t *data, QDateTime dateAndTime);
|
||||||
signals:
|
signals:
|
||||||
void deviceSettings(QString settings);
|
void deviceSettings(QString settings);
|
||||||
void message(QString msg);
|
void message(QString msg);
|
||||||
|
@ -46,12 +65,13 @@ signals:
|
||||||
void stateChanged(states newState);
|
void stateChanged(states newState);
|
||||||
private:
|
private:
|
||||||
ReadSettingsThread *readThread;
|
ReadSettingsThread *readThread;
|
||||||
|
WriteSettingsThread *writeThread;
|
||||||
void setState(states newState);
|
void setState(states newState);
|
||||||
|
|
||||||
|
void writeSettingToDevice(device_data_t *data, QString settingName, QVariant settingValue);
|
||||||
void readHWSettings(device_data_t *data);
|
|
||||||
private slots:
|
private slots:
|
||||||
void readThreadFinished();
|
void readThreadFinished();
|
||||||
|
void writeThreadFinished();
|
||||||
void setError(QString err);
|
void setError(QString err);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
#include "../display.h"
|
#include "../display.h"
|
||||||
#include "../divelist.h"
|
#include "../divelist.h"
|
||||||
#include "configuredivecomputer.h"
|
#include "configuredivecomputer.h"
|
||||||
|
#include <QInputDialog>
|
||||||
|
|
||||||
struct product {
|
struct product {
|
||||||
const char *product;
|
const char *product;
|
||||||
dc_descriptor_t *descriptor;
|
dc_descriptor_t *descriptor;
|
||||||
|
@ -185,3 +187,26 @@ void ConfigureDiveComputerDialog::on_cancel_clicked()
|
||||||
{
|
{
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConfigureDiveComputerDialog::on_setDeviceName_clicked()
|
||||||
|
{
|
||||||
|
ui->statusLabel->clear();
|
||||||
|
ui->errorLabel->clear();
|
||||||
|
ui->availableDetails->clear();
|
||||||
|
|
||||||
|
QString newDeviceName = QInputDialog::getText(this, tr("Set device name"), tr("Enter the new name for this device:"));
|
||||||
|
if (newDeviceName.length() > 0) {
|
||||||
|
getDeviceData();
|
||||||
|
config->setDeviceName(&device_data, newDeviceName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConfigureDiveComputerDialog::on_setDateAndTime_clicked()
|
||||||
|
{
|
||||||
|
ui->statusLabel->clear();
|
||||||
|
ui->errorLabel->clear();
|
||||||
|
ui->availableDetails->clear();
|
||||||
|
|
||||||
|
getDeviceData();
|
||||||
|
config->setDeviceDateAndTime(&device_data, QDateTime::currentDateTime());
|
||||||
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ private slots:
|
||||||
void configMessage(QString msg);
|
void configMessage(QString msg);
|
||||||
void configError(QString err);
|
void configError(QString err);
|
||||||
void on_cancel_clicked();
|
void on_cancel_clicked();
|
||||||
|
void on_setDeviceName_clicked();
|
||||||
|
|
||||||
|
void on_setDateAndTime_clicked();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ConfigureDiveComputerDialog *ui;
|
Ui::ConfigureDiveComputerDialog *ui;
|
||||||
|
|
||||||
|
|
|
@ -94,6 +94,24 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTextBrowser" name="availableDetails"/>
|
<widget class="QTextBrowser" name="availableDetails"/>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QPushButton" name="setDeviceName">
|
||||||
|
<property name="text">
|
||||||
|
<string>Set Device Name</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QPushButton" name="setDateAndTime">
|
||||||
|
<property name="text">
|
||||||
|
<string>Set Date && Time</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="errorLabel">
|
<widget class="QLabel" name="errorLabel">
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue