From 0781c1aea3021ac70199963018e7639ac4cf55d2 Mon Sep 17 00:00:00 2001 From: Tim Segers Date: Fri, 30 Sep 2022 13:22:30 +0200 Subject: Add decostate_t to segment callback parameters --- opendeco.c | 4 ++-- schedule.c | 23 +++++++++++++---------- schedule.h | 2 +- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/opendeco.c b/opendeco.c index 0e9880d..2f82a48 100644 --- a/opendeco.c +++ b/opendeco.c @@ -10,7 +10,7 @@ #define MOD_OXY (abs_depth(msw_to_bar(6))) -void print_segment_callback(const waypoint_t wp, segtype_t type) +void print_segment_callback(const decostate_t *ds, const waypoint_t wp, segtype_t type) { static double last_depth; static double runtime; @@ -32,7 +32,7 @@ void print_segment_callback(const waypoint_t wp, segtype_t type) last_depth = wp.depth; } -void empty_callback(const waypoint_t wp, segtype_t type) +void empty_callback(const decostate_t *ds, const waypoint_t wp, segtype_t type) { } diff --git a/schedule.c b/schedule.c index 5bfc1d5..0fc3c4e 100644 --- a/schedule.c +++ b/schedule.c @@ -69,7 +69,7 @@ void simulate_dive(decostate_t *ds, waypoint_t *waypoints, const int nof_waypoin runtime += add_segment_const(ds, d, t, g); } - seg_cb((waypoint_t){.depth = d, .time = t, .gas = g}, SEG_DIVE); + seg_cb(ds, (waypoint_t){.depth = d, .time = t, .gas = g}, SEG_DIVE); } } @@ -98,27 +98,29 @@ void extend_to_ndl(decostate_t *ds, const double depth, const double ascrate, co /* add segment to reach ndl */ if (ndl) { add_segment_const(ds, depth, ndl, gas); - seg_cb((waypoint_t){.depth = depth, .time = ndl, .gas = gas}, SEG_NDL); + seg_cb(ds, (waypoint_t){.depth = depth, .time = ndl, .gas = gas}, SEG_NDL); } /* either ascend directly or make a safety stop */ if (depth < SAFETY_STOP_DEPTH || ds->max_depth < abs_depth(msw_to_bar(10))) { /* surface */ add_segment_ascdec(ds, depth, SURFACE_PRESSURE, gauge_depth(depth) / ascrate, gas); - seg_cb((waypoint_t){.depth = SURFACE_PRESSURE, .time = gauge_depth(depth) / ascrate, .gas = gas}, SEG_SURFACE); + seg_cb(ds, (waypoint_t){.depth = SURFACE_PRESSURE, .time = gauge_depth(depth) / ascrate, .gas = gas}, + SEG_SURFACE); } else { /* ascend to safety stop */ add_segment_ascdec(ds, depth, SAFETY_STOP_DEPTH, (depth - SAFETY_STOP_DEPTH) / ascrate, gas); - seg_cb((waypoint_t){.depth = SAFETY_STOP_DEPTH, .time = (depth - SAFETY_STOP_DEPTH) / ascrate, .gas = gas}, + seg_cb(ds, (waypoint_t){.depth = SAFETY_STOP_DEPTH, .time = (depth - SAFETY_STOP_DEPTH) / ascrate, .gas = gas}, SEG_TRAVEL); /* stop for 3 minutes */ add_segment_const(ds, SAFETY_STOP_DEPTH, 3, gas); - seg_cb((waypoint_t){.depth = SAFETY_STOP_DEPTH, .time = 3, .gas = gas}, SEG_SAFETY_STOP); + seg_cb(ds, (waypoint_t){.depth = SAFETY_STOP_DEPTH, .time = 3, .gas = gas}, SEG_SAFETY_STOP); /* surface */ add_segment_ascdec(ds, SAFETY_STOP_DEPTH, SURFACE_PRESSURE, gauge_depth(SAFETY_STOP_DEPTH) / ascrate, gas); - seg_cb((waypoint_t){.depth = SURFACE_PRESSURE, .time = gauge_depth(SAFETY_STOP_DEPTH) / ascrate, .gas = gas}, + seg_cb(ds, + (waypoint_t){.depth = SURFACE_PRESSURE, .time = gauge_depth(SAFETY_STOP_DEPTH) / ascrate, .gas = gas}, SEG_SURFACE); } } @@ -168,6 +170,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta /* ascend to switch depth */ ret.tts += add_segment_ascdec(ds, depth, switch_depth, (depth - switch_depth) / asc_per_min, gas); seg_cb( + ds, (waypoint_t){.depth = switch_depth, .time = (depth - switch_depth) / asc_per_min, .gas = gas}, SEG_TRAVEL); @@ -178,7 +181,7 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta gas = next; add_segment_const(ds, switch_depth, 1, gas); - seg_cb((waypoint_t){.depth = depth, .time = 1, .gas = gas}, SEG_GAS_SWITCH); + seg_cb(ds, (waypoint_t){.depth = depth, .time = 1, .gas = gas}, SEG_GAS_SWITCH); continue; } @@ -187,10 +190,10 @@ decoinfo_t calc_deco(decostate_t *ds, const double start_depth, const gas_t *sta ret.tts += add_segment_ascdec(ds, depth, stopdep, (depth - stopdep) / asc_per_min, gas); if (stopdep <= SURFACE_PRESSURE) - seg_cb((waypoint_t){.depth = stopdep, .time = (depth - stopdep) / asc_per_min, .gas = gas}, + seg_cb(ds, (waypoint_t){.depth = stopdep, .time = (depth - stopdep) / asc_per_min, .gas = gas}, SEG_SURFACE); else - seg_cb((waypoint_t){.depth = stopdep, .time = (depth - stopdep) / asc_per_min, .gas = gas}, + seg_cb(ds, (waypoint_t){.depth = stopdep, .time = (depth - stopdep) / asc_per_min, .gas = gas}, SEG_TRAVEL); depth = stopdep; @@ -220,7 +223,7 @@ 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; - seg_cb((waypoint_t){.depth = depth, .time = stoplen, .gas = gas}, SEG_DECO_STOP); + seg_cb(ds, (waypoint_t){.depth = depth, .time = stoplen, .gas = gas}, SEG_DECO_STOP); } return ret; diff --git a/schedule.h b/schedule.h index b1703d7..63de45f 100644 --- a/schedule.h +++ b/schedule.h @@ -26,7 +26,7 @@ typedef enum segtype_t { SEG_TRAVEL, } segtype_t; -typedef void (*segment_callback_t)(const waypoint_t, const segtype_t); +typedef void (*segment_callback_t)(const decostate_t *ds, const waypoint_t, const segtype_t); const gas_t *best_gas(const double depth, const gas_t *gasses, const int nof_gasses); const gas_t *next_gas(const double depth, const gas_t *gasses, const int nof_gasses); -- cgit v1.2.3-70-g09d2