summaryrefslogtreecommitdiffstats
path: root/qt-ui/configuredivecomputerthreads.cpp
blob: f1ac3b5d9de1077298c0c0e234e975ff323635fe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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);
		}
	}
}