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:
Joseph W. Joshua 2014-05-30 09:56:27 +03:00 committed by Thiago Macieira
parent 791fbee260
commit a7c9b25b05
6 changed files with 212 additions and 2 deletions

View file

@ -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();
}