mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Planner: Depth dependent setpoint changes in CCR mode
We had a user request to allow for setpoint changes
at certain depths for CCR deco.
You can now enter a cylinder with name like
"SP 1.4" ('S' and 'P' and ' ' and a float) with
a switch depth and that cylinder is interpreted as
a depth dependent setpoint switch.
This user interface is a hack. But I believe that such
setpoint changes are similar enough to gas switches during
deco and should thus be handled in a simiar manner.
I would be happy to hear ideas how this could be made
less easter eggish.
Suggested-by: Justin Ashworth
Signed-off-by: Robert C. Helling <helling@atdotde.de>
			
			
This commit is contained in:
		
							parent
							
								
									5595a70bd5
								
							
						
					
					
						commit
						6b8a07f0d9
					
				
					 1 changed files with 24 additions and 8 deletions
				
			
		| 
						 | 
					@ -382,7 +382,23 @@ struct gaschanges {
 | 
				
			||||||
	int gasidx;
 | 
						int gasidx;
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive *dive, int *gaschangenr, int depth, int *asc_cylinder)
 | 
					// Return new setpoint if cylinderi is a setpoint change an 0 if not
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static int setpoint_change(struct dive *dive, int cylinderid)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						cylinder_t *cylinder = get_cylinder(dive, cylinderid);
 | 
				
			||||||
 | 
						if (!cylinder->type.description)
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						if (!strncmp(cylinder->type.description, "SP ", 3)) {
 | 
				
			||||||
 | 
							float sp;
 | 
				
			||||||
 | 
							sscanf(cylinder->type.description + 3, "%f", &sp);
 | 
				
			||||||
 | 
							return (int) (sp * 1000);
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive *dive, int *gaschangenr, int depth, int *asc_cylinder, bool ccr)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int nr = 0;
 | 
						int nr = 0;
 | 
				
			||||||
	struct gaschanges *gaschanges = NULL;
 | 
						struct gaschanges *gaschanges = NULL;
 | 
				
			||||||
| 
						 | 
					@ -390,7 +406,7 @@ static struct gaschanges *analyze_gaslist(struct diveplan *diveplan, struct dive
 | 
				
			||||||
	int best_depth = get_cylinder(dive, *asc_cylinder)->depth.mm;
 | 
						int best_depth = get_cylinder(dive, *asc_cylinder)->depth.mm;
 | 
				
			||||||
	bool total_time_zero = true;
 | 
						bool total_time_zero = true;
 | 
				
			||||||
	while (dp) {
 | 
						while (dp) {
 | 
				
			||||||
		if (dp->time == 0 && total_time_zero) {
 | 
							if (dp->time == 0 && total_time_zero && (ccr == (bool) setpoint_change(dive, dp->cylinderid))) {
 | 
				
			||||||
			if (dp->depth.mm <= depth) {
 | 
								if (dp->depth.mm <= depth) {
 | 
				
			||||||
				int i = 0;
 | 
									int i = 0;
 | 
				
			||||||
				nr++;
 | 
									nr++;
 | 
				
			||||||
| 
						 | 
					@ -737,12 +753,8 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
 | 
				
			||||||
	best_first_ascend_cylinder = current_cylinder;
 | 
						best_first_ascend_cylinder = current_cylinder;
 | 
				
			||||||
	/* Find the gases available for deco */
 | 
						/* Find the gases available for deco */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (divemode == CCR && !prefs.dobailout) {	// Don't change gas in CCR mode
 | 
						gaschanges = analyze_gaslist(diveplan, dive, &gaschangenr, depth, &best_first_ascend_cylinder, divemode == CCR && !prefs.dobailout);
 | 
				
			||||||
		gaschanges = NULL;
 | 
					
 | 
				
			||||||
		gaschangenr = 0;
 | 
					 | 
				
			||||||
	} else {
 | 
					 | 
				
			||||||
		gaschanges = analyze_gaslist(diveplan, dive, &gaschangenr, depth, &best_first_ascend_cylinder);
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	/* Find the first potential decostopdepth above current depth */
 | 
						/* Find the first potential decostopdepth above current depth */
 | 
				
			||||||
	for (stopidx = 0; stopidx < decostoplevelcount; stopidx++)
 | 
						for (stopidx = 0; stopidx < decostoplevelcount; stopidx++)
 | 
				
			||||||
		if (*(decostoplevels + stopidx) >= depth)
 | 
							if (*(decostoplevels + stopidx) >= depth)
 | 
				
			||||||
| 
						 | 
					@ -929,6 +941,8 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
 | 
				
			||||||
						previous_point_time = clock;
 | 
											previous_point_time = clock;
 | 
				
			||||||
						current_cylinder = gaschanges[gi].gasidx;
 | 
											current_cylinder = gaschanges[gi].gasidx;
 | 
				
			||||||
						gas = get_cylinder(dive, current_cylinder)->gasmix;
 | 
											gas = get_cylinder(dive, current_cylinder)->gasmix;
 | 
				
			||||||
 | 
											if (divemode == CCR)
 | 
				
			||||||
 | 
												po2 = setpoint_change(dive, current_cylinder);
 | 
				
			||||||
#if DEBUG_PLAN & 16
 | 
					#if DEBUG_PLAN & 16
 | 
				
			||||||
						printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
 | 
											printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi].gasidx,
 | 
				
			||||||
							(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi].depth / 1000.0);
 | 
												(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi].depth / 1000.0);
 | 
				
			||||||
| 
						 | 
					@ -983,6 +997,8 @@ bool plan(struct deco_state *ds, struct diveplan *diveplan, struct dive *dive, i
 | 
				
			||||||
				if (pendinggaschange) {
 | 
									if (pendinggaschange) {
 | 
				
			||||||
					current_cylinder = gaschanges[gi + 1].gasidx;
 | 
										current_cylinder = gaschanges[gi + 1].gasidx;
 | 
				
			||||||
					gas = get_cylinder(dive, current_cylinder)->gasmix;
 | 
										gas = get_cylinder(dive, current_cylinder)->gasmix;
 | 
				
			||||||
 | 
										if (divemode == CCR)
 | 
				
			||||||
 | 
											po2 = setpoint_change(dive, current_cylinder);
 | 
				
			||||||
#if DEBUG_PLAN & 16
 | 
					#if DEBUG_PLAN & 16
 | 
				
			||||||
					printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi + 1].gasidx,
 | 
										printf("switch to gas %d (%d/%d) @ %5.2lfm\n", gaschanges[gi + 1].gasidx,
 | 
				
			||||||
						(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi + 1].depth / 1000.0);
 | 
											(get_o2(&gas) + 5) / 10, (get_he(&gas) + 5) / 10, gaschanges[gi + 1].depth / 1000.0);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue