mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Remove linear pressure interpolation detection code
Dirk says that divinglog hasn't been doing the linear pressure interpolation for a long while, so we're doing extra dive fixups that really aren't needed any more. Also, the code is actually buggy: it only ever worked on the first cylinder anyway (because only the first cylinder pressure_delta[] would be initialized). That was probably perfectly fine in practice, since it's unlikely that many tech divers used old versions of divinglog anyway, so the bug per se isn't a reason to remove it - but it is a sign that the code was a bit hard to read, so let's get rid of it if there is no reason to maintain it or fix it. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									7be962bfc2
								
							
						
					
					
						commit
						eb5907ab3b
					
				
					 1 changed files with 2 additions and 50 deletions
				
			
		
							
								
								
									
										52
									
								
								core/dive.c
									
										
									
									
									
								
							
							
						
						
									
										52
									
								
								core/dive.c
									
										
									
									
									
								
							| 
						 | 
					@ -1306,17 +1306,12 @@ static void fixup_dc_cylinder_index(struct dive *dive, struct divecomputer *dc)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/* Remove redundant pressure information */
 | 
				
			||||||
 * Simplify dc pressure information:
 | 
					 | 
				
			||||||
 *  (a) Remove redundant pressure information
 | 
					 | 
				
			||||||
 *  (b) Remove linearly interpolated pressure data
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
static void simplify_dc_pressures(struct dive *dive, struct divecomputer *dc)
 | 
					static void simplify_dc_pressures(struct dive *dive, struct divecomputer *dc)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	int i, j;
 | 
						int i;
 | 
				
			||||||
	int lastindex = -1;
 | 
						int lastindex = -1;
 | 
				
			||||||
	int lastpressure = 0, lasto2pressure = 0;
 | 
						int lastpressure = 0, lasto2pressure = 0;
 | 
				
			||||||
	int pressure_delta[MAX_CYLINDERS] = { INT_MAX, };
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	for (i = 0; i < dc->samples; i++) {
 | 
						for (i = 0; i < dc->samples; i++) {
 | 
				
			||||||
		struct sample *sample = dc->sample + i;
 | 
							struct sample *sample = dc->sample + i;
 | 
				
			||||||
| 
						 | 
					@ -1325,60 +1320,17 @@ static void simplify_dc_pressures(struct dive *dive, struct divecomputer *dc)
 | 
				
			||||||
		int index;
 | 
							int index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		index = sample->sensor;
 | 
							index = sample->sensor;
 | 
				
			||||||
 | 
					 | 
				
			||||||
		if (index == lastindex) {
 | 
							if (index == lastindex) {
 | 
				
			||||||
			/* Remove duplicate redundant pressure information */
 | 
								/* Remove duplicate redundant pressure information */
 | 
				
			||||||
			if (pressure == lastpressure)
 | 
								if (pressure == lastpressure)
 | 
				
			||||||
				sample->cylinderpressure.mbar = 0;
 | 
									sample->cylinderpressure.mbar = 0;
 | 
				
			||||||
			if (o2_pressure == lasto2pressure)
 | 
								if (o2_pressure == lasto2pressure)
 | 
				
			||||||
				sample->o2cylinderpressure.mbar = 0;
 | 
									sample->o2cylinderpressure.mbar = 0;
 | 
				
			||||||
			/* check for simply linear data in the samples
 | 
					 | 
				
			||||||
			   +INT_MAX means uninitialized, -INT_MAX means not linear */
 | 
					 | 
				
			||||||
			if (pressure_delta[index] != -INT_MAX && lastpressure) {
 | 
					 | 
				
			||||||
				if (pressure_delta[index] == INT_MAX) {
 | 
					 | 
				
			||||||
					pressure_delta[index] = abs(pressure - lastpressure);
 | 
					 | 
				
			||||||
				} else {
 | 
					 | 
				
			||||||
					int cur_delta = abs(pressure - lastpressure);
 | 
					 | 
				
			||||||
					if (cur_delta && abs(cur_delta - pressure_delta[index]) > 150) {
 | 
					 | 
				
			||||||
						/* ok the samples aren't just a linearisation
 | 
					 | 
				
			||||||
						 * between start and end */
 | 
					 | 
				
			||||||
						pressure_delta[index] = -INT_MAX;
 | 
					 | 
				
			||||||
					}
 | 
					 | 
				
			||||||
				}
 | 
					 | 
				
			||||||
			}
 | 
					 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		lastindex = index;
 | 
							lastindex = index;
 | 
				
			||||||
		lastpressure = pressure;
 | 
							lastpressure = pressure;
 | 
				
			||||||
		lasto2pressure = o2_pressure;
 | 
							lasto2pressure = o2_pressure;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					 | 
				
			||||||
	/* if all the samples for a cylinder have pressure data that
 | 
					 | 
				
			||||||
	 * is basically equidistant throw out the sample cylinder pressure
 | 
					 | 
				
			||||||
	 * information but make sure we still have a valid start and end
 | 
					 | 
				
			||||||
	 * pressure
 | 
					 | 
				
			||||||
	 * this happens when DivingLog decides to linearalize the
 | 
					 | 
				
			||||||
	 * pressure between beginning and end and for strange reasons
 | 
					 | 
				
			||||||
	 * decides to put that in the sample data as if it came from
 | 
					 | 
				
			||||||
	 * the dive computer; we don't want that (we'll visualize with
 | 
					 | 
				
			||||||
	 * constant SAC rate instead)
 | 
					 | 
				
			||||||
	 * WARNING WARNING - I have only seen this in single tank dives
 | 
					 | 
				
			||||||
	 * --- maybe I should try to create a multi tank dive and see what
 | 
					 | 
				
			||||||
	 * --- divinglog does there - but the code right now is only tested
 | 
					 | 
				
			||||||
	 * --- for the single tank case */
 | 
					 | 
				
			||||||
	for (j = 0; j < MAX_CYLINDERS; j++) {
 | 
					 | 
				
			||||||
		if (abs(pressure_delta[j]) != INT_MAX) {
 | 
					 | 
				
			||||||
			cylinder_t *cyl = dive->cylinder + j;
 | 
					 | 
				
			||||||
			for (i = 0; i < dc->samples; i++)
 | 
					 | 
				
			||||||
				if (dc->sample[i].sensor == j)
 | 
					 | 
				
			||||||
					dc->sample[i].cylinderpressure.mbar = 0;
 | 
					 | 
				
			||||||
			if (!cyl->start.mbar)
 | 
					 | 
				
			||||||
				cyl->start.mbar = cyl->sample_start.mbar;
 | 
					 | 
				
			||||||
			if (!cyl->end.mbar)
 | 
					 | 
				
			||||||
				cyl->end.mbar = cyl->sample_end.mbar;
 | 
					 | 
				
			||||||
			cyl->sample_start.mbar = 0;
 | 
					 | 
				
			||||||
			cyl->sample_end.mbar = 0;
 | 
					 | 
				
			||||||
		}
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* FIXME! sensor -> cylinder mapping? */
 | 
					/* FIXME! sensor -> cylinder mapping? */
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue