aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorGravatar Tim Segers <tsegers@pm.me>2022-10-03 11:17:11 +0200
committerGravatar Tim Segers <tsegers@pm.me>2022-10-03 11:17:11 +0200
commite2ff193809aeb9cbc4cda896a48ecbefa4adb00c (patch)
treeaf384704f7bcf1d025183b58e04c14877f1d1f43
parent723d76f2912faeac891156ee061eb57fc2700f51 (diff)
downloadopendeco-e2ff193809aeb9cbc4cda896a48ecbefa4adb00c.tar.gz
Allow NULL instead of empty waypoint callback function
-rw-r--r--opendeco.c6
-rw-r--r--schedule.c23
2 files changed, 16 insertions, 13 deletions
diff --git a/opendeco.c b/opendeco.c
index 2f82a48..59c9892 100644
--- a/opendeco.c
+++ b/opendeco.c
@@ -32,10 +32,6 @@ void print_segment_callback(const decostate_t *ds, const waypoint_t wp, segtype_
last_depth = wp.depth;
}
-void empty_callback(const decostate_t *ds, const waypoint_t wp, segtype_t type)
-{
-}
-
int main(int argc, const char *argv[])
{
setlocale(LC_ALL, "en_US.utf8");
@@ -68,7 +64,7 @@ int main(int argc, const char *argv[])
/* determine @+5 TTS */
decostate_t ds_ = ds;
add_segment_const(&ds_, depth, 5, gas);
- decoinfo_t di_plus5 = calc_deco(&ds_, depth, gas, deco_gasses, len(deco_gasses), &empty_callback);
+ decoinfo_t di_plus5 = calc_deco(&ds_, depth, gas, deco_gasses, len(deco_gasses), NULL);
/* print actual deco schedule */
decoinfo_t di = calc_deco(&ds, depth, gas, deco_gasses, len(deco_gasses), &print_segment_callback);
diff --git a/schedule.c b/schedule.c
index f7f998a..b737453 100644
--- a/schedule.c
+++ b/schedule.c
@@ -68,7 +68,8 @@ void simulate_dive(decostate_t *ds, waypoint_t *waypoints, const int nof_waypoin
runtime += add_segment_const(ds, d, t, g);
}
- wp_cb(ds, (waypoint_t){.depth = d, .time = t, .gas = g}, SEG_DIVE);
+ if (wp_cb)
+ wp_cb(ds, (waypoint_t){.depth = d, .time = t, .gas = g}, SEG_DIVE);
}
}
@@ -168,14 +169,19 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
* callback should be called.
*/
waypoint_time = fabs(last_waypoint_depth - depth) / asc_per_min;
- wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_TRAVEL);
+
+ if (wp_cb)
+ wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_TRAVEL);
+
last_waypoint_depth = depth;
/* switch gas */
gas = next;
ret.tts += add_segment_const(ds, switch_depth, 1, gas);
- wp_cb(ds, (waypoint_t){.depth = depth, .time = 1, .gas = gas}, SEG_GAS_SWITCH);
+
+ if (wp_cb)
+ wp_cb(ds, (waypoint_t){.depth = depth, .time = 1, .gas = gas}, SEG_GAS_SWITCH);
continue;
}
@@ -195,11 +201,10 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
* callback should be called.
*/
waypoint_time = fabs(last_waypoint_depth - depth) / asc_per_min;
+ enum segtype_t segtype = depth <= SURFACE_PRESSURE ? SEG_SURFACE : SEG_TRAVEL;
- if (depth <= SURFACE_PRESSURE)
- wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_SURFACE);
- else
- wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, SEG_TRAVEL);
+ if (wp_cb)
+ wp_cb(ds, (waypoint_t){.depth = depth, .time = waypoint_time, .gas = gas}, segtype);
break;
}
@@ -221,7 +226,9 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta
stoplen += add_segment_const(ds, depth, 1, gas);
ret.tts += stoplen;
- wp_cb(ds, (waypoint_t){.depth = depth, .time = stoplen, .gas = gas}, SEG_DECO_STOP);
+
+ if (wp_cb)
+ wp_cb(ds, (waypoint_t){.depth = depth, .time = stoplen, .gas = gas}, SEG_DECO_STOP);
}
return ret;