mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Improve the code handling air temperature
Better helper functions make for easier to understand code. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
b4c2fcc802
commit
c6da79e1b0
3 changed files with 24 additions and 26 deletions
31
dive.c
31
dive.c
|
@ -484,34 +484,35 @@ static void fixup_watertemp(struct dive *dive)
|
|||
dive->watertemp.mkelvin = (sum + nr / 2) / nr;
|
||||
}
|
||||
|
||||
void fixup_airtemp(struct dive *dive)
|
||||
/*
|
||||
* What do the dive computers say the air temperature is?
|
||||
*/
|
||||
unsigned int dc_airtemp(struct divecomputer *dc)
|
||||
{
|
||||
struct divecomputer *dc;
|
||||
int sum = 0, nr = 0;
|
||||
|
||||
if (dive->airtemp.mkelvin)
|
||||
return;
|
||||
for_each_dc(dive, dc) {
|
||||
do {
|
||||
if (dc->airtemp.mkelvin) {
|
||||
sum += dc->airtemp.mkelvin;
|
||||
nr++;
|
||||
}
|
||||
}
|
||||
if (nr)
|
||||
dive->airtemp.mkelvin = (sum + nr / 2) / nr;
|
||||
} while ((dc = dc->next) != NULL);
|
||||
if (!nr)
|
||||
return 0;
|
||||
return (sum + nr / 2) / nr;
|
||||
}
|
||||
|
||||
static void fixup_airtemp(struct dive *dive)
|
||||
{
|
||||
if (!dive->airtemp.mkelvin)
|
||||
dive->airtemp.mkelvin = dc_airtemp(&dive->dc);
|
||||
}
|
||||
|
||||
/* zero out the airtemp in the dive structure if it was just created by
|
||||
* running fixup on the dive. keep it if it had been edited by hand */
|
||||
static void un_fixup_airtemp(struct dive *a)
|
||||
{
|
||||
temperature_t temp;
|
||||
temp.mkelvin = a->airtemp.mkelvin;
|
||||
a->airtemp.mkelvin = 0;
|
||||
fixup_airtemp(a);
|
||||
if (a->airtemp.mkelvin && a->airtemp.mkelvin != temp.mkelvin)
|
||||
a->airtemp.mkelvin = temp.mkelvin;
|
||||
else
|
||||
if (a->airtemp.mkelvin && a->airtemp.mkelvin == dc_airtemp(&a->dc))
|
||||
a->airtemp.mkelvin = 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue