diff options
author | Anton Lundin <glance@acc.umu.se> | 2015-09-12 22:37:34 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2015-09-12 14:02:12 -0700 |
commit | a42df06dbfc9d55d74ee416d14ab79a8606f34f7 (patch) | |
tree | 6f0b5bedecd6b2d4366b39af308451216b0dcf0d /configuredivecomputer.cpp | |
parent | f38f8ce4c9a04921a5835b5390b665ef74d05390 (diff) | |
download | subsurface-a42df06dbfc9d55d74ee416d14ab79a8606f34f7.tar.gz |
Lift dis- and connect out from config operations
When working with ostc's via bluetooth, they will reboot and exit
bluetooth mode when you send the disconnect command. Thats kinda
inconvenient when you would like to read your settings, change something
and write it back, you need to start bluetooth mode on your device
twice.
Signed-off-by: Anton Lundin <glance@acc.umu.se>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'configuredivecomputer.cpp')
-rw-r--r-- | configuredivecomputer.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/configuredivecomputer.cpp b/configuredivecomputer.cpp index 65cf3ce72..9e03bc66e 100644 --- a/configuredivecomputer.cpp +++ b/configuredivecomputer.cpp @@ -611,3 +611,48 @@ void ConfigureDiveComputer::resetThreadFinished() emit message(tr("Device settings successfully reset")); } } + +QString ConfigureDiveComputer::dc_open(device_data_t *data) +{ + FILE *fp = NULL; + dc_status_t rc; + + if (data->libdc_log) + fp = subsurface_fopen(logfile_name, "w"); + + data->libdc_logfile = fp; + + rc = dc_context_new(&data->context); + if (rc != DC_STATUS_SUCCESS) { + return tr("Unable to create libdivecomputer context"); + } + + if (fp) { + dc_context_set_loglevel(data->context, DC_LOGLEVEL_ALL); + dc_context_set_logfunc(data->context, logfunc, fp); + } + + rc = dc_device_open(&data->device, data->context, data->descriptor, data->devname); + if (rc != DC_STATUS_SUCCESS) { + return tr("Could not a establish connection to the dive computer."); + } + + setState(OPEN); + + return NULL; +} + +void ConfigureDiveComputer::dc_close(device_data_t *data) +{ + if (data->device) + dc_device_close(data->device); + data->device = NULL; + if (data->context) + dc_context_free(data->context); + data->context = NULL; + + if (data->libdc_logfile) + fclose(data->libdc_logfile); + + setState(INITIAL); +} |