core: introduce a few user-defined literals for unit types

Thise makes initialization of unit types more palatable.

For example:

    surface.time = sample.time - duration_t { .seconds = 20 };
=>  surface.time = sample.time - 20_sec;

    delta_depth.mm = feet_to_mm(1.0); // 1ft
=>  delta_depth = 1_ft;

    get_cylinderid_at_time(..., { .seconds = 20 * 60 + 1 }));
=>  get_cylinderid_at_time(..., 20_min + 1_sec));

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-09-03 17:04:48 +02:00 committed by bstoeger
parent f09601bc93
commit ae81b42fe2
36 changed files with 320 additions and 264 deletions

View file

@ -160,7 +160,7 @@ static dc_status_t parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_
}
}
bool no_volume = true;
struct gasmix bottom_gas = { { .permille = 1000}, {} }; /* Default to pure O2, or air if there are no mixes defined */
struct gasmix bottom_gas = { 100_percent, 0_percent }; /* Default to pure O2, or air if there are no mixes defined */
if (ngases == 0) {
bottom_gas = gasmix_air;
}
@ -291,7 +291,7 @@ static dc_status_t parse_gasmixes(device_data_t *devdata, struct dive *dive, dc_
cyl.end.mbar = lrint(tank.endpressure * 1000);
} else if (devdata->vendor == "Uwatec") {
cyl.start.mbar = lrint(tank.beginpressure * 1000 + 30000);
cyl.end.mbar = 30000;
cyl.end = 30_bar;
}
}
}
@ -850,7 +850,7 @@ static int dive_cb(const unsigned char *data, unsigned int size,
/* Various libdivecomputer interface fixups */
if (dive->dcs[0].airtemp.mkelvin == 0 && first_temp_is_air && !dive->dcs[0].samples.empty()) {
dive->dcs[0].airtemp = dive->dcs[0].samples[0].temperature;
dive->dcs[0].samples[0].temperature.mkelvin = 0;
dive->dcs[0].samples[0].temperature = 0_K;
}
/* special case for bug in Tecdiving DiveComputer.eu