mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Move divecomputer configuration code to different files
This splits the code in configuredivecomputer.cpp into multiple files. The read and write threads are moved to configuredivecomputerthreads.h/cpp, and the device details class is moved to devicedetails.h/.cpp Signed-off-by: Joseph W. Joshua <joejoshw@gmail.com> Signed-off-by: Thiago Macieira <thiago@macieira.org>
This commit is contained in:
parent
2432350064
commit
4fc16b1674
10 changed files with 403 additions and 225 deletions
|
@ -4,19 +4,21 @@
|
||||||
ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) :
|
ConfigureDiveComputer::ConfigureDiveComputer(QObject *parent) :
|
||||||
QObject(parent),
|
QObject(parent),
|
||||||
readThread(0),
|
readThread(0),
|
||||||
writeThread(0)
|
writeThread(0),
|
||||||
|
m_deviceDetails(0)
|
||||||
{
|
{
|
||||||
setState(INITIAL);
|
setState(INITIAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputer::readSettings(device_data_t *data)
|
void ConfigureDiveComputer::readSettings(DeviceDetails *deviceDetails, device_data_t *data)
|
||||||
{
|
{
|
||||||
setState(READING);
|
setState(READING);
|
||||||
|
m_deviceDetails = deviceDetails;
|
||||||
|
|
||||||
if (readThread)
|
if (readThread)
|
||||||
readThread->deleteLater();
|
readThread->deleteLater();
|
||||||
|
|
||||||
readThread = new ReadSettingsThread(this, data);
|
readThread = new ReadSettingsThread(this, deviceDetails, data);
|
||||||
connect (readThread, SIGNAL(finished()),
|
connect (readThread, SIGNAL(finished()),
|
||||||
this, SLOT(readThreadFinished()), Qt::QueuedConnection);
|
this, SLOT(readThreadFinished()), Qt::QueuedConnection);
|
||||||
connect (readThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
|
connect (readThread, SIGNAL(error(QString)), this, SLOT(setError(QString)));
|
||||||
|
@ -24,19 +26,9 @@ void ConfigureDiveComputer::readSettings(device_data_t *data)
|
||||||
readThread->start();
|
readThread->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputer::setDeviceName(device_data_t *data, QString newName)
|
void ConfigureDiveComputer::saveDeviceDetails()
|
||||||
{
|
{
|
||||||
writeSettingToDevice(data, "Name", newName);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigureDiveComputer::setDeviceDateAndTime(device_data_t *data, QDateTime dateAndTime)
|
|
||||||
{
|
|
||||||
writeSettingToDevice(data, "DateAndTime", dateAndTime);
|
|
||||||
}
|
|
||||||
|
|
||||||
void ConfigureDiveComputer::setDeviceBrightness(device_data_t *data, int brighnessLevel)
|
|
||||||
{
|
|
||||||
writeSettingToDevice(data, "Brightness", brighnessLevel);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
|
void ConfigureDiveComputer::setState(ConfigureDiveComputer::states newState)
|
||||||
|
@ -45,20 +37,6 @@ void ConfigureDiveComputer::setState(ConfigureDiveComputer::states 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;
|
||||||
|
@ -68,7 +46,7 @@ void ConfigureDiveComputer::setError(QString err)
|
||||||
void ConfigureDiveComputer::readThreadFinished()
|
void ConfigureDiveComputer::readThreadFinished()
|
||||||
{
|
{
|
||||||
setState(DONE);
|
setState(DONE);
|
||||||
emit deviceSettings(readThread->result);
|
emit readFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputer::writeThreadFinished()
|
void ConfigureDiveComputer::writeThreadFinished()
|
||||||
|
@ -79,108 +57,3 @@ void ConfigureDiveComputer::writeThreadFinished()
|
||||||
emit message(tr("Setting successfully written to device"));
|
emit message(tr("Setting successfully written to device"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data)
|
|
||||||
: QThread(parent), data(data)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void ReadSettingsThread::run()
|
|
||||||
{
|
|
||||||
dc_status_t rc;
|
|
||||||
rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
|
|
||||||
if (rc == DC_STATUS_SUCCESS) {
|
|
||||||
if (dc_device_get_type(data->device) == DC_FAMILY_HW_OSTC3) {
|
|
||||||
unsigned char hw_data[10];
|
|
||||||
hw_ostc3_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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
|
|
||||||
if (rc == DC_STATUS_SUCCESS) {
|
|
||||||
dc_status_t result;
|
|
||||||
if (m_settingName == "Name") {
|
|
||||||
switch (dc_device_get_type(data->device)) {
|
|
||||||
case DC_FAMILY_HW_OSTC3:
|
|
||||||
supported = true;
|
|
||||||
result = hw_ostc3_device_customtext(data->device, m_settingValue.toByteArray().data());
|
|
||||||
break;
|
|
||||||
case DC_FAMILY_HW_FROG:
|
|
||||||
supported = true;
|
|
||||||
result = hw_frog_device_customtext(data->device, m_settingValue.toByteArray().data());
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_settingName == "DateAndTime") {
|
|
||||||
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();
|
|
||||||
|
|
||||||
switch (dc_device_get_type(data->device)) {
|
|
||||||
case DC_FAMILY_HW_OSTC3:
|
|
||||||
supported = true;
|
|
||||||
result = hw_ostc3_device_clock(data->device, &time);
|
|
||||||
break;
|
|
||||||
case DC_FAMILY_HW_OSTC:
|
|
||||||
supported = true;
|
|
||||||
result = hw_ostc_device_clock(data->device, &time);
|
|
||||||
break;
|
|
||||||
case DC_FAMILY_HW_FROG:
|
|
||||||
supported = true;
|
|
||||||
result = hw_frog_device_clock(data->device, &time);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (m_settingName == "Brightness") {
|
|
||||||
switch (dc_device_get_type(data->device)) {
|
|
||||||
case DC_FAMILY_HW_OSTC3:
|
|
||||||
qDebug() << "Brightness";
|
|
||||||
supported = true;
|
|
||||||
unsigned char packet[1] = { m_settingValue.toInt() };
|
|
||||||
result = hw_ostc3_device_config_write(data->device, 0x2D, packet, sizeof (packet));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
qDebug() << result;
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -5,41 +5,15 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
#include "libdivecomputer.h"
|
#include "libdivecomputer.h"
|
||||||
|
#include "configuredivecomputerthreads.h"
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
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 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
|
||||||
public:
|
public:
|
||||||
explicit ConfigureDiveComputer(QObject *parent = 0);
|
explicit ConfigureDiveComputer(QObject *parent = 0);
|
||||||
void readSettings(device_data_t *data);
|
void readSettings(DeviceDetails *deviceDetails, device_data_t *data);
|
||||||
|
|
||||||
enum states {
|
enum states {
|
||||||
INITIAL,
|
INITIAL,
|
||||||
|
@ -53,23 +27,23 @@ public:
|
||||||
|
|
||||||
QString lastError;
|
QString lastError;
|
||||||
states currentState;
|
states currentState;
|
||||||
|
DeviceDetails *m_deviceDetails;
|
||||||
|
device_data_t *m_data;
|
||||||
|
void saveDeviceDetails();
|
||||||
|
void fetchDeviceDetails();
|
||||||
|
|
||||||
void setDeviceName(device_data_t *data, QString newName);
|
|
||||||
void setDeviceDateAndTime(device_data_t *data, QDateTime dateAndTime);
|
|
||||||
void setDeviceBrightness(device_data_t *data, int brighnessLevel);
|
|
||||||
signals:
|
signals:
|
||||||
void deviceSettings(QString settings);
|
|
||||||
void message(QString msg);
|
void message(QString msg);
|
||||||
void error(QString err);
|
void error(QString err);
|
||||||
void readFinished();
|
void readFinished();
|
||||||
void writeFinished();
|
void writeFinished();
|
||||||
void stateChanged(states newState);
|
void stateChanged(states newState);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ReadSettingsThread *readThread;
|
ReadSettingsThread *readThread;
|
||||||
WriteSettingsThread *writeThread;
|
WriteSettingsThread *writeThread;
|
||||||
void setState(states newState);
|
void setState(states newState);
|
||||||
|
|
||||||
void writeSettingToDevice(device_data_t *data, QString settingName, QVariant settingValue);
|
|
||||||
private slots:
|
private slots:
|
||||||
void readThreadFinished();
|
void readThreadFinished();
|
||||||
void writeThreadFinished();
|
void writeThreadFinished();
|
||||||
|
|
|
@ -33,14 +33,16 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
|
||||||
ui(new Ui::ConfigureDiveComputerDialog),
|
ui(new Ui::ConfigureDiveComputerDialog),
|
||||||
config(0),
|
config(0),
|
||||||
vendorModel(0),
|
vendorModel(0),
|
||||||
productModel(0)
|
productModel(0),
|
||||||
|
deviceDetails(0)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
deviceDetails = new DeviceDetails(this);
|
||||||
config = new ConfigureDiveComputer(this);
|
config = new ConfigureDiveComputer(this);
|
||||||
connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
|
connect (config, SIGNAL(error(QString)), this, SLOT(configError(QString)));
|
||||||
connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
|
connect (config, SIGNAL(message(QString)), this, SLOT(configMessage(QString)));
|
||||||
connect (config, SIGNAL(deviceSettings(QString)), ui->availableDetails, SLOT(setText(QString)));
|
connect (config, SIGNAL(readFinished()), this, SLOT(deviceReadFinished()));
|
||||||
|
|
||||||
fill_computer_list();
|
fill_computer_list();
|
||||||
|
|
||||||
|
@ -157,7 +159,7 @@ void ConfigureDiveComputerDialog::readSettings()
|
||||||
ui->errorLabel->clear();
|
ui->errorLabel->clear();
|
||||||
|
|
||||||
getDeviceData();
|
getDeviceData();
|
||||||
config->readSettings(&device_data);
|
config->readSettings(deviceDetails, &device_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputerDialog::configMessage(QString msg)
|
void ConfigureDiveComputerDialog::configMessage(QString msg)
|
||||||
|
@ -181,6 +183,8 @@ void ConfigureDiveComputerDialog::getDeviceData()
|
||||||
|
|
||||||
set_default_dive_computer(device_data.vendor, device_data.product);
|
set_default_dive_computer(device_data.vendor, device_data.product);
|
||||||
set_default_dive_computer_device(device_data.devname);
|
set_default_dive_computer_device(device_data.devname);
|
||||||
|
|
||||||
|
//deviceDetails->setData(&device_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputerDialog::on_cancel_clicked()
|
void ConfigureDiveComputerDialog::on_cancel_clicked()
|
||||||
|
@ -188,31 +192,13 @@ void ConfigureDiveComputerDialog::on_cancel_clicked()
|
||||||
this->close();
|
this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputerDialog::on_setDeviceName_clicked()
|
void ConfigureDiveComputerDialog::deviceReadFinished()
|
||||||
{
|
{
|
||||||
ui->statusLabel->clear();
|
ui->brightnessComboBox->setCurrentIndex(config->m_deviceDetails->brightness());
|
||||||
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()
|
void ConfigureDiveComputerDialog::on_saveSettingsPushButton_clicked()
|
||||||
{
|
{
|
||||||
ui->statusLabel->clear();
|
config->saveDeviceDetails();
|
||||||
ui->errorLabel->clear();
|
|
||||||
ui->availableDetails->clear();
|
|
||||||
|
|
||||||
getDeviceData();
|
|
||||||
config->setDeviceDateAndTime(&device_data, QDateTime::currentDateTime());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConfigureDiveComputerDialog::on_setBrightnessButton_clicked()
|
|
||||||
{
|
|
||||||
getDeviceData();
|
|
||||||
config->setDeviceBrightness(&device_data, ui->brightnessComboBox->currentIndex());
|
|
||||||
}
|
|
||||||
|
|
|
@ -4,8 +4,7 @@
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QStringListModel>
|
#include <QStringListModel>
|
||||||
#include "../libdivecomputer.h"
|
#include "../libdivecomputer.h"
|
||||||
|
#include "configuredivecomputer.h"
|
||||||
class ConfigureDiveComputer;
|
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ConfigureDiveComputerDialog;
|
class ConfigureDiveComputerDialog;
|
||||||
|
@ -28,12 +27,8 @@ 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 deviceReadFinished();
|
||||||
|
void on_saveSettingsPushButton_clicked();
|
||||||
void on_setDateAndTime_clicked();
|
|
||||||
|
|
||||||
void on_setBrightnessButton_clicked();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ConfigureDiveComputerDialog *ui;
|
Ui::ConfigureDiveComputerDialog *ui;
|
||||||
|
|
||||||
|
@ -49,6 +44,8 @@ private:
|
||||||
QStringListModel *productModel;
|
QStringListModel *productModel;
|
||||||
void fill_computer_list();
|
void fill_computer_list();
|
||||||
void fill_device_list(int dc_type);
|
void fill_device_list(int dc_type);
|
||||||
|
|
||||||
|
DeviceDetails *deviceDetails;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONFIGUREDIVECOMPUTERDIALOG_H
|
#endif // CONFIGUREDIVECOMPUTERDIALOG_H
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>362</width>
|
<width>343</width>
|
||||||
<height>375</height>
|
<height>365</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -91,33 +91,16 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QTextBrowser" name="availableDetails"/>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="0" column="0">
|
<item row="3" 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>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QLabel" name="label_4">
|
<widget class="QLabel" name="label_4">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Brightness:</string>
|
<string>Brightness:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="1">
|
<item row="3" column="1">
|
||||||
<widget class="QComboBox" name="brightnessComboBox">
|
<widget class="QComboBox" name="brightnessComboBox">
|
||||||
<item>
|
<item>
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -136,15 +119,90 @@
|
||||||
</item>
|
</item>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="2">
|
<item row="0" column="1">
|
||||||
<widget class="QToolButton" name="setBrightnessButton">
|
<widget class="QLineEdit" name="serialNoLineEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="1">
|
||||||
|
<widget class="QComboBox" name="languageComboBox">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>English</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>German</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>French</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Italian</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="1">
|
||||||
|
<widget class="QLineEdit" name="customTextLlineEdit"/>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="label_6">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>...</string>
|
<string>Language:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Serial No.</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Custom Text:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_8">
|
||||||
|
<property name="text">
|
||||||
|
<string>Firmware Version:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QLineEdit" name="firmwareVersionLineEdit">
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="errorLabel">
|
<widget class="QLabel" name="errorLabel">
|
||||||
<property name="styleSheet">
|
<property name="styleSheet">
|
||||||
|
@ -164,6 +222,13 @@
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="saveSettingsPushButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Save Chages to Device</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer_2">
|
<spacer name="horizontalSpacer_2">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -188,6 +253,20 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<tabstops>
|
||||||
|
<tabstop>vendor</tabstop>
|
||||||
|
<tabstop>product</tabstop>
|
||||||
|
<tabstop>device</tabstop>
|
||||||
|
<tabstop>search</tabstop>
|
||||||
|
<tabstop>retrieveDetails</tabstop>
|
||||||
|
<tabstop>serialNoLineEdit</tabstop>
|
||||||
|
<tabstop>firmwareVersionLineEdit</tabstop>
|
||||||
|
<tabstop>customTextLlineEdit</tabstop>
|
||||||
|
<tabstop>brightnessComboBox</tabstop>
|
||||||
|
<tabstop>languageComboBox</tabstop>
|
||||||
|
<tabstop>saveSettingsPushButton</tabstop>
|
||||||
|
<tabstop>cancel</tabstop>
|
||||||
|
</tabstops>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
81
qt-ui/configuredivecomputerthreads.cpp
Normal file
81
qt-ui/configuredivecomputerthreads.cpp
Normal file
|
@ -0,0 +1,81 @@
|
||||||
|
#include "configuredivecomputerthreads.h"
|
||||||
|
#include "libdivecomputer/hw.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
ReadSettingsThread::ReadSettingsThread(QObject *parent, DeviceDetails *deviceDetails, device_data_t *data)
|
||||||
|
: QThread(parent), m_deviceDetails(deviceDetails), m_data(data)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReadSettingsThread::run()
|
||||||
|
{
|
||||||
|
bool supported = false;
|
||||||
|
dc_status_t rc;
|
||||||
|
rc = rc = dc_device_open(&m_data->device, m_data->context, m_data->descriptor, m_data->devname);
|
||||||
|
if (rc == DC_STATUS_SUCCESS) {
|
||||||
|
switch (dc_device_get_type(m_data->device)) {
|
||||||
|
case DC_FAMILY_HW_OSTC3:
|
||||||
|
supported = true;
|
||||||
|
m_deviceDetails->setBrightness(0);
|
||||||
|
m_deviceDetails->setCustomText("");
|
||||||
|
m_deviceDetails->setDateFormat(0);
|
||||||
|
m_deviceDetails->setDiveModeColor(0);
|
||||||
|
m_deviceDetails->setFirmwareVersion("");
|
||||||
|
m_deviceDetails->setLanguage(0);
|
||||||
|
m_deviceDetails->setLastDeco(0);
|
||||||
|
m_deviceDetails->setSerialNo("");
|
||||||
|
unsigned char uData[1];
|
||||||
|
rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData));
|
||||||
|
if (rc == DC_STATUS_SUCCESS)
|
||||||
|
m_deviceDetails->setBrightness(uData[0]);
|
||||||
|
rc = hw_ostc3_device_config_read(m_data->device, 0x32, uData, sizeof(uData));
|
||||||
|
if (rc == DC_STATUS_SUCCESS)
|
||||||
|
m_deviceDetails->setLanguage(uData[0]);
|
||||||
|
rc = hw_ostc3_device_config_read(m_data->device, 0x33, uData, sizeof(uData));
|
||||||
|
if (rc == DC_STATUS_SUCCESS)
|
||||||
|
m_deviceDetails->setDateFormat(uData[0]);
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
WriteSettingsThread::WriteSettingsThread(QObject *parent, DeviceDetails *deviceDetails, QString settingName, QVariant settingValue)
|
||||||
|
: QThread(parent), m_deviceDetails(deviceDetails), m_settingName(settingName), m_settingValue(settingValue)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void WriteSettingsThread::run()
|
||||||
|
{
|
||||||
|
bool supported = false;
|
||||||
|
dc_status_t rc;
|
||||||
|
|
||||||
|
switch (dc_device_get_type(data->device)) {
|
||||||
|
case DC_FAMILY_HW_OSTC3:
|
||||||
|
rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname);
|
||||||
|
if (rc == DC_STATUS_SUCCESS) {
|
||||||
|
|
||||||
|
} else {
|
||||||
|
lastError = tr("Could not a establish connection to the dive computer.");
|
||||||
|
emit error(lastError);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (!supported) {
|
||||||
|
lastError = tr("This feature is not yet available for the selected dive computer.");
|
||||||
|
emit error(lastError);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
42
qt-ui/configuredivecomputerthreads.h
Normal file
42
qt-ui/configuredivecomputerthreads.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
#ifndef CONFIGUREDIVECOMPUTERTHREADS_H
|
||||||
|
#define CONFIGUREDIVECOMPUTERTHREADS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QThread>
|
||||||
|
#include <QVariant>
|
||||||
|
#include "libdivecomputer.h"
|
||||||
|
#include <QDateTime>
|
||||||
|
#include "devicedetails.h"
|
||||||
|
|
||||||
|
class ReadSettingsThread : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
ReadSettingsThread(QObject *parent, DeviceDetails *deviceDetails, device_data_t *data);
|
||||||
|
virtual void run();
|
||||||
|
QString result;
|
||||||
|
QString lastError;
|
||||||
|
signals:
|
||||||
|
void error(QString err);
|
||||||
|
private:
|
||||||
|
DeviceDetails *m_deviceDetails;
|
||||||
|
device_data_t *m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
class WriteSettingsThread : public QThread {
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
WriteSettingsThread(QObject *parent, DeviceDetails *deviceDetails, 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;
|
||||||
|
|
||||||
|
DeviceDetails *m_deviceDetails;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONFIGUREDIVECOMPUTERTHREADS_H
|
88
qt-ui/devicedetails.cpp
Normal file
88
qt-ui/devicedetails.cpp
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
#include "devicedetails.h"
|
||||||
|
|
||||||
|
DeviceDetails::DeviceDetails(QObject *parent) :
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
device_data_t *DeviceDetails::data() const
|
||||||
|
{
|
||||||
|
return m_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setData(device_data_t *data)
|
||||||
|
{
|
||||||
|
m_data = data;
|
||||||
|
}
|
||||||
|
QString DeviceDetails::serialNo() const
|
||||||
|
{
|
||||||
|
return m_serialNo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setSerialNo(const QString &serialNo)
|
||||||
|
{
|
||||||
|
m_serialNo = serialNo;
|
||||||
|
}
|
||||||
|
QString DeviceDetails::firmwareVersion() const
|
||||||
|
{
|
||||||
|
return m_firmwareVersion;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setFirmwareVersion(const QString &firmwareVersion)
|
||||||
|
{
|
||||||
|
m_firmwareVersion = firmwareVersion;
|
||||||
|
}
|
||||||
|
QString DeviceDetails::customText() const
|
||||||
|
{
|
||||||
|
return m_customText;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setCustomText(const QString &customText)
|
||||||
|
{
|
||||||
|
m_customText = customText;
|
||||||
|
}
|
||||||
|
int DeviceDetails::brightness() const
|
||||||
|
{
|
||||||
|
return m_brightness;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setBrightness(int brightness)
|
||||||
|
{
|
||||||
|
m_brightness = brightness;
|
||||||
|
}
|
||||||
|
int DeviceDetails::diveModeColor() const
|
||||||
|
{
|
||||||
|
return m_diveModeColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setDiveModeColor(int diveModeColor)
|
||||||
|
{
|
||||||
|
m_diveModeColor = diveModeColor;
|
||||||
|
}
|
||||||
|
int DeviceDetails::language() const
|
||||||
|
{
|
||||||
|
return m_language;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setLanguage(int language)
|
||||||
|
{
|
||||||
|
m_language = language;
|
||||||
|
}
|
||||||
|
int DeviceDetails::dateFormat() const
|
||||||
|
{
|
||||||
|
return m_dateFormat;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setDateFormat(int dateFormat)
|
||||||
|
{
|
||||||
|
m_dateFormat = dateFormat;
|
||||||
|
}
|
||||||
|
int DeviceDetails::lastDeco() const
|
||||||
|
{
|
||||||
|
return m_lastDeco;
|
||||||
|
}
|
||||||
|
|
||||||
|
void DeviceDetails::setLastDeco(int lastDeco)
|
||||||
|
{
|
||||||
|
m_lastDeco = lastDeco;
|
||||||
|
}
|
54
qt-ui/devicedetails.h
Normal file
54
qt-ui/devicedetails.h
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
#ifndef DEVICEDETAILS_H
|
||||||
|
#define DEVICEDETAILS_H
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QDateTime>
|
||||||
|
#include "libdivecomputer.h"
|
||||||
|
|
||||||
|
class DeviceDetails : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
explicit DeviceDetails(QObject *parent = 0);
|
||||||
|
|
||||||
|
device_data_t *data() const;
|
||||||
|
void setData(device_data_t *data);
|
||||||
|
|
||||||
|
QString serialNo() const;
|
||||||
|
void setSerialNo(const QString &serialNo);
|
||||||
|
|
||||||
|
QString firmwareVersion() const;
|
||||||
|
void setFirmwareVersion(const QString &firmwareVersion);
|
||||||
|
|
||||||
|
QString customText() const;
|
||||||
|
void setCustomText(const QString &customText);
|
||||||
|
|
||||||
|
int brightness() const;
|
||||||
|
void setBrightness(int brightness);
|
||||||
|
|
||||||
|
int diveModeColor() const;
|
||||||
|
void setDiveModeColor(int diveModeColor);
|
||||||
|
|
||||||
|
int language() const;
|
||||||
|
void setLanguage(int language);
|
||||||
|
|
||||||
|
int dateFormat() const;
|
||||||
|
void setDateFormat(int dateFormat);
|
||||||
|
|
||||||
|
int lastDeco() const;
|
||||||
|
void setLastDeco(int lastDeco);
|
||||||
|
|
||||||
|
private:
|
||||||
|
device_data_t *m_data;
|
||||||
|
QString m_serialNo;
|
||||||
|
QString m_firmwareVersion;
|
||||||
|
QString m_customText;
|
||||||
|
int m_brightness;
|
||||||
|
int m_diveModeColor;
|
||||||
|
int m_language;
|
||||||
|
int m_dateFormat;
|
||||||
|
int m_lastDeco;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // DEVICEDETAILS_H
|
|
@ -89,6 +89,8 @@ HEADERS = \
|
||||||
subsurfacesysinfo.h \
|
subsurfacesysinfo.h \
|
||||||
qt-ui/configuredivecomputerdialog.h \
|
qt-ui/configuredivecomputerdialog.h \
|
||||||
qt-ui/configuredivecomputer.h \
|
qt-ui/configuredivecomputer.h \
|
||||||
|
qt-ui/configuredivecomputerthreads.h \
|
||||||
|
qt-ui/devicedetails.h
|
||||||
|
|
||||||
android: HEADERS -= \
|
android: HEADERS -= \
|
||||||
qt-ui/usermanual.h \
|
qt-ui/usermanual.h \
|
||||||
|
@ -169,7 +171,9 @@ SOURCES = \
|
||||||
qt-ui/usersurvey.cpp \
|
qt-ui/usersurvey.cpp \
|
||||||
subsurfacesysinfo.cpp \
|
subsurfacesysinfo.cpp \
|
||||||
qt-ui/configuredivecomputerdialog.cpp \
|
qt-ui/configuredivecomputerdialog.cpp \
|
||||||
qt-ui/configuredivecomputer.cpp
|
qt-ui/configuredivecomputer.cpp \
|
||||||
|
qt-ui/configuredivecomputerthreads.cpp \
|
||||||
|
qt-ui/devicedetails.cpp
|
||||||
|
|
||||||
android: SOURCES += android.cpp
|
android: SOURCES += android.cpp
|
||||||
else: linux*: SOURCES += linux.c
|
else: linux*: SOURCES += linux.c
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue