mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	Add "get_gasmix()" helper function to iterate over gas changes
We have a few places that used to get the gasmix by looking at the
sensor index in the plot data, which really doesn't work any more.
To make it easier for those users to convert to the new world order,
this adds a "get_gasmix()" function.  The gasmix function takes as its
argument the dive, the dive computer, and the time.
In addition, for good performance (to avoid looping over the event list
over and over and over again) it maintains a pointer to the next gas
switch event, and the previous gas.  Those need to be initialized to
NULL by the caller, so the standard use-case pattern basically looks
like this:
	struct gasmix *gasmix = NULL;
	struct event *ev = NULL;
	loop over samples or plot events in increasing time order: {
		...
		gasmix = get_gasmix(dive, dc, time, &ev, gasmix);
		...
	}
and then you can see what the currently breathing gas is at that time.
If for some reason you need to walk backwards in time, you can just pass
in a NULL gasmix again, which will reset the event iterator (at the cost
of now having to walk all the events again).
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
			
			
This commit is contained in:
		
							parent
							
								
									7e39be436b
								
							
						
					
					
						commit
						1e337518b8
					
				
					 1 changed files with 17 additions and 0 deletions
				
			
		
							
								
								
									
										17
									
								
								core/dive.h
									
										
									
									
									
								
							
							
						
						
									
										17
									
								
								core/dive.h
									
										
									
									
									
								
							|  | @ -913,6 +913,23 @@ void delete_single_dive(int idx); | |||
| 
 | ||||
| struct event *get_next_event(struct event *event, const char *name); | ||||
| 
 | ||||
| static inline struct gasmix *get_gasmix(struct dive *dive, struct divecomputer *dc, int time, struct event **evp, struct gasmix *gasmix) | ||||
| { | ||||
| 	struct event *ev = *evp; | ||||
| 
 | ||||
| 	if (!gasmix) { | ||||
| 		int cyl = explicit_first_cylinder(dive, dc); | ||||
| 		gasmix = &dive->cylinder[cyl].gasmix; | ||||
| 		ev = dc->events; | ||||
| 	} | ||||
| 	while (ev && ev->time.seconds < time) { | ||||
| 		gasmix = get_gasmix_from_event(dive, ev); | ||||
| 		ev = get_next_event(ev->next, "gaschange"); | ||||
| 	} | ||||
| 	*evp = ev; | ||||
| 	return gasmix; | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /* these structs holds the information that
 | ||||
|  * describes the cylinders / weight systems. | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue