From de5311033c3c6704c9e31904e3d5b7d846f0de41 Mon Sep 17 00:00:00 2001 From: Michael Keller Date: Tue, 2 Jan 2024 10:52:29 +1300 Subject: [PATCH] Planner: Increase CCR Setpoint Precision to 0.01. Increase the precision of the setpoint that can be specified per planned leg of the dive to 0.01 mbar. Some rebreather models (APD Inspiration) support this precision for setpoint setting. Motivated-by: https://groups.google.com/g/subsurface-divelog/c/pD5gYlG5szI/m/G8_as4TyBwAJ Signed-off-by: Michael Keller --- core/planner.c | 34 ++++++++++++++++++++------------- desktop-widgets/diveplanner.cpp | 2 +- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/core/planner.c b/core/planner.c index 66547c82e..6d37d3101 100644 --- a/core/planner.c +++ b/core/planner.c @@ -1130,25 +1130,36 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i } /* - * Get a value in tenths (so "10.2" == 102, "9" = 90) + * Get a value with a given number of decimals: + * - get_decimals("10.2", &"10.2", 1) == 102 + * - get_decimals("9", &"9", 1) = 90 + * - get_decimals("1.35", &"1.35", 2) == 135)) * * Return negative for errors. */ -static int get_tenths(const char *begin, const char **endp) +static int get_decimals(const char *begin, const char **endp, const unsigned decimals) { char *end; int value = strtol(begin, &end, 10); if (begin == end) return -1; - value *= 10; /* Fraction? We only look at the first digit */ if (*end == '.') { - end++; - if (!isdigit(*end)) - return -1; - value += *end - '0'; + unsigned fraction = 0; + for (unsigned i = 0; i < decimals; i++) { + value *= 10; + + end++; + + if (!isdigit(*end)) + return -1; + + fraction = 10 * fraction + (*end - '0'); + } + value += fraction; + do { end++; } while (isdigit(*end)); @@ -1159,7 +1170,7 @@ static int get_tenths(const char *begin, const char **endp) static int get_permille(const char *begin, const char **end) { - int value = get_tenths(begin, end); + int value = get_decimals(begin, end, 1); if (value >= 0) { /* Allow a percentage sign */ if (**end == '%') @@ -1222,18 +1233,15 @@ int validate_po2(const char *text, int *mbar_po2) if (!text) return 0; - po2 = get_tenths(text, &text); + po2 = get_decimals(text, &text, 2); if (po2 < 0) return 0; - while (isspace(*text)) - text++; - while (isspace(*text)) text++; if (*text) return 0; - *mbar_po2 = po2 * 100; + *mbar_po2 = po2 * 10; return 1; } diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 1e1df3a4d..3a3eeaf81 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -85,7 +85,7 @@ DivePlannerWidget::DivePlannerWidget(dive &planned_dive, PlannerWidgets *parent) // the depth will be done in settingChanged() since this depends on the chosen units. ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::RUNTIME, new SpinBoxDelegate(0, INT_MAX, 1, this)); ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, 6000, 1, this)); - ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.1, this)); + ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.01, this)); connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DivePlannerWidget::settingsChanged);