2014-06-10 12:03:26 +00:00
|
|
|
#include "configuredivecomputerthreads.h"
|
|
|
|
#include "libdivecomputer/hw.h"
|
|
|
|
#include <QDebug>
|
2014-06-10 15:37:37 +00:00
|
|
|
#include <QDateTime>
|
2014-06-10 12:03:26 +00:00
|
|
|
|
2014-06-10 15:25:25 +00:00
|
|
|
ReadSettingsThread::ReadSettingsThread(QObject *parent, device_data_t *data)
|
|
|
|
: QThread(parent), m_data(data)
|
2014-06-10 12:03:26 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2014-06-10 15:25:25 +00:00
|
|
|
DeviceDetails *m_deviceDetails = new DeviceDetails(0);
|
2014-06-10 12:03:26 +00:00
|
|
|
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("");
|
2014-06-11 08:09:01 +00:00
|
|
|
m_deviceDetails->setCompassGain(0);
|
|
|
|
m_deviceDetails->setSalinity(0);
|
|
|
|
m_deviceDetails->setSamplingRate(0);
|
|
|
|
m_deviceDetails->setUnits(0);
|
|
|
|
|
2014-06-10 15:25:25 +00:00
|
|
|
//Read general settings
|
|
|
|
unsigned char uData[1] = {0};
|
2014-06-13 14:10:10 +00:00
|
|
|
//DiveMode
|
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x20, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setDiveMode(uData[0]);
|
|
|
|
//Saturation
|
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x2A, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setSaturation(uData[0]);
|
2014-06-11 08:09:01 +00:00
|
|
|
//LastDeco
|
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setLastDeco(uData[0]);
|
|
|
|
//Brightness
|
2014-06-10 12:03:26 +00:00
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x2D, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setBrightness(uData[0]);
|
2014-06-11 08:09:01 +00:00
|
|
|
//Units
|
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x2E, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setUnits(uData[0]);
|
|
|
|
//Sampling Rate
|
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x2F, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setSamplingRate(uData[0]);
|
|
|
|
//Salinity
|
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x30, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setSalinity(uData[0]);
|
|
|
|
//Dive mode colour
|
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x31, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setDiveModeColor(uData[0]);
|
|
|
|
//Language
|
2014-06-10 12:03:26 +00:00
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x32, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setLanguage(uData[0]);
|
2014-06-11 08:09:01 +00:00
|
|
|
//Date Format
|
2014-06-10 12:03:26 +00:00
|
|
|
rc = hw_ostc3_device_config_read(m_data->device, 0x33, uData, sizeof(uData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS)
|
|
|
|
m_deviceDetails->setDateFormat(uData[0]);
|
2014-06-10 15:25:25 +00:00
|
|
|
|
2014-06-11 08:09:01 +00:00
|
|
|
|
2014-06-10 15:25:25 +00:00
|
|
|
//read firmware settings
|
|
|
|
unsigned char fData[64] = {0};
|
|
|
|
rc = hw_ostc3_device_version (m_data->device, fData, sizeof (fData));
|
|
|
|
if (rc == DC_STATUS_SUCCESS) {
|
|
|
|
int serial = fData[0] + (fData[1] << 8);
|
|
|
|
m_deviceDetails->setSerialNo(QString::number(serial));
|
|
|
|
int fw = (fData[2] << 8) + fData[3];
|
|
|
|
m_deviceDetails->setFirmwareVersion(QString::number(fw));
|
|
|
|
QByteArray ar((char *)fData + 4, 60);
|
|
|
|
m_deviceDetails->setCustomText(ar.trimmed());
|
|
|
|
}
|
|
|
|
|
|
|
|
emit devicedetails(m_deviceDetails);
|
2014-06-10 12:03:26 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:25:25 +00:00
|
|
|
WriteSettingsThread::WriteSettingsThread(QObject *parent, device_data_t *data)
|
|
|
|
: QThread(parent), m_data(data) {
|
|
|
|
|
|
|
|
}
|
2014-06-10 12:03:26 +00:00
|
|
|
|
2014-06-10 15:25:25 +00:00
|
|
|
void WriteSettingsThread::setDeviceDetails(DeviceDetails *details)
|
|
|
|
{
|
|
|
|
m_deviceDetails = details;
|
2014-06-10 12:03:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void WriteSettingsThread::run()
|
|
|
|
{
|
|
|
|
bool supported = false;
|
|
|
|
dc_status_t rc;
|
2014-06-10 15:25:25 +00:00
|
|
|
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;
|
|
|
|
//write general settings
|
2014-06-11 08:09:01 +00:00
|
|
|
|
|
|
|
//custom text
|
2014-06-10 15:25:25 +00:00
|
|
|
hw_ostc3_device_customtext(m_data->device, m_deviceDetails->customText().toUtf8().data());
|
|
|
|
unsigned char data[1] = {0};
|
2014-06-11 08:09:01 +00:00
|
|
|
|
2014-06-13 14:10:10 +00:00
|
|
|
//dive mode
|
|
|
|
data[0] = m_deviceDetails->diveMode();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x20, data, sizeof(data));
|
|
|
|
|
|
|
|
//saturation
|
|
|
|
data[0] = m_deviceDetails->saturation();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x2A, data, sizeof(data));
|
|
|
|
|
2014-06-11 08:09:01 +00:00
|
|
|
//last deco
|
|
|
|
data[0] = m_deviceDetails->lastDeco();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x2C, data, sizeof(data));
|
|
|
|
|
|
|
|
//brightness
|
2014-06-10 15:25:25 +00:00
|
|
|
data[0] = m_deviceDetails->brightness();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x2D, data, sizeof(data));
|
2014-06-11 08:09:01 +00:00
|
|
|
|
|
|
|
//units
|
|
|
|
data[0] = m_deviceDetails->units();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x2E, data, sizeof(data));
|
|
|
|
|
|
|
|
//sampling rate
|
|
|
|
data[0] = m_deviceDetails->samplingRate();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x2F, data, sizeof(data));
|
|
|
|
|
|
|
|
//salinity
|
|
|
|
data[0] = m_deviceDetails->salinity();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x30, data, sizeof(data));
|
|
|
|
|
|
|
|
//dive mode colour
|
|
|
|
data[0] = m_deviceDetails->diveModeColor();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x31, data, sizeof(data));
|
|
|
|
|
|
|
|
//language
|
2014-06-10 15:25:25 +00:00
|
|
|
data[0] = m_deviceDetails->language();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x32, data, sizeof(data));
|
2014-06-11 08:09:01 +00:00
|
|
|
|
|
|
|
//date format
|
2014-06-10 15:25:25 +00:00
|
|
|
data[0] = m_deviceDetails->dateFormat();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x33, data, sizeof(data));
|
2014-06-10 15:37:37 +00:00
|
|
|
|
2014-06-11 08:09:01 +00:00
|
|
|
//compass gain
|
|
|
|
data[0] = m_deviceDetails->compassGain();
|
|
|
|
hw_ostc3_device_config_write(m_data->device, 0x34, data, sizeof(data));
|
|
|
|
|
2014-06-10 15:37:37 +00:00
|
|
|
//sync date and time
|
|
|
|
if (m_deviceDetails->syncTime()) {
|
|
|
|
QDateTime timeToSet = QDateTime::currentDateTime();
|
|
|
|
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();
|
|
|
|
hw_ostc3_device_clock(m_data->device, &time);
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:25:25 +00:00
|
|
|
break;
|
2014-06-10 12:03:26 +00:00
|
|
|
|
|
|
|
}
|
2014-06-10 15:25:25 +00:00
|
|
|
dc_device_close(m_data->device);
|
2014-06-10 12:03:26 +00:00
|
|
|
|
|
|
|
if (!supported) {
|
|
|
|
lastError = tr("This feature is not yet available for the selected dive computer.");
|
|
|
|
emit error(lastError);
|
|
|
|
}
|
|
|
|
}
|
2014-06-10 15:25:25 +00:00
|
|
|
else {
|
|
|
|
lastError = tr("Could not a establish connection to the dive computer.");
|
|
|
|
emit error(lastError);
|
|
|
|
}
|
2014-06-10 12:03:26 +00:00
|
|
|
}
|