summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-10 13:35:27 -0300
committerGravatar Tomaz Canabrava <tcanabrava@kde.org>2013-06-10 13:35:27 -0300
commit3eac2360e7173580c7325ccb9814be538d3ee078 (patch)
tree3a5989688dac4f548c9454da6f1c441eb1f02210
parentbd8470ebcfe07a347c3c47d2a72e0b8cdd316630 (diff)
downloadsubsurface-3eac2360e7173580c7325ccb9814be538d3ee078.tar.gz
Moved the 'create fake dc' to it's own function in device.c
Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org>
-rw-r--r--device.c28
-rw-r--r--device.h2
-rw-r--r--qt-ui/profilegraphics.cpp22
3 files changed, 32 insertions, 20 deletions
diff --git a/device.c b/device.c
index 660cfc1ab..9666a4869 100644
--- a/device.c
+++ b/device.c
@@ -109,3 +109,31 @@ struct device_info *remove_device_info(const char *model, uint32_t deviceid)
}
return entry;
}
+
+struct divecomputer* fake_dc(struct divecomputer* dc)
+{
+ static struct sample fake[4];
+ static struct divecomputer fakedc;
+ static bool initialized = 0;
+ if (!initialized){
+ fakedc = (*dc);
+ fakedc.sample = fake;
+ fakedc.samples = 4;
+
+ /* The dive has no samples, so create a few fake ones. This assumes an
+ ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
+ int duration = dc->duration.seconds;
+ int maxdepth = dc->maxdepth.mm;
+ int asc_desc_time = dc->maxdepth.mm*60/9000;
+ if (asc_desc_time * 2 >= duration)
+ asc_desc_time = duration / 2;
+ fake[1].time.seconds = asc_desc_time;
+ fake[1].depth.mm = maxdepth;
+ fake[2].time.seconds = duration - asc_desc_time;
+ fake[2].depth.mm = maxdepth;
+ fake[3].time.seconds = duration * 1.00;
+ fakedc.events = dc->events;
+ }
+ return &fakedc;
+}
+
diff --git a/device.h b/device.h
index 636eb73c6..086b4a5bb 100644
--- a/device.h
+++ b/device.h
@@ -2,6 +2,7 @@
#define DEVICE_INFO_H
#ifdef __cplusplus
+#include "dive.h"
extern "C" {
#endif
@@ -20,6 +21,7 @@ extern struct device_info *get_different_device_info(const char *model, uint32_t
extern struct device_info *create_device_info(const char *model, uint32_t deviceid);
extern struct device_info *remove_device_info(const char *model, uint32_t deviceid);
extern struct device_info *head_of_device_info_list(void);
+extern struct divecomputer *fake_dc(struct divecomputer* dc);
#ifdef __cplusplus
}
diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp
index 164de13ff..98d542788 100644
--- a/qt-ui/profilegraphics.cpp
+++ b/qt-ui/profilegraphics.cpp
@@ -17,6 +17,7 @@
#include "../display.h"
#include "../dive.h"
#include "../profile.h"
+#include "../device.h"
#include <libdivecomputer/parser.h>
#include <libdivecomputer/version.h>
@@ -265,26 +266,7 @@ void ProfileGraphicsView::plot(struct dive *d, bool forceRedraw)
// plot_set_scale(scale_mode_t);
if (!dc->samples) {
- static struct sample fake[4];
- static struct divecomputer fakedc;
- fakedc = dive->dc;
- fakedc.sample = fake;
- fakedc.samples = 4;
-
- /* The dive has no samples, so create a few fake ones. This assumes an
- ascent/descent rate of 9 m/min, which is just below the limit for FAST. */
- int duration = dive->dc.duration.seconds;
- int maxdepth = dive->dc.maxdepth.mm;
- int asc_desc_time = dive->dc.maxdepth.mm*60/9000;
- if (asc_desc_time * 2 >= duration)
- asc_desc_time = duration / 2;
- fake[1].time.seconds = asc_desc_time;
- fake[1].depth.mm = maxdepth;
- fake[2].time.seconds = duration - asc_desc_time;
- fake[2].depth.mm = maxdepth;
- fake[3].time.seconds = duration * 1.00;
- fakedc.events = dc->events;
- dc = &fakedc;
+ dc = fake_dc(dc);
}
/*