Apply the gas mode immediately.
Because the gas mode takes precedence over the individual gas mix definitions, we can simplify the code by taking the gas mode into account immediately when parsing the gas mixes.
This commit is contained in:
parent
e0e6460372
commit
28135bc57a
@ -146,16 +146,22 @@ suunto_d9_parser_cache (suunto_d9_parser_t *parser)
|
||||
|
||||
// Cache the data for later use.
|
||||
parser->mode = data[gasmode_offset];
|
||||
parser->ngasmixes = gasmix_count;
|
||||
for (unsigned int i = 0; i < gasmix_count; ++i) {
|
||||
if (parser->model == HELO2 || parser->model == D4i ||
|
||||
parser->model == D6i || parser->model == D9tx ||
|
||||
parser->model == DX) {
|
||||
parser->oxygen[i] = data[gasmix_offset + 6 * i + 1];
|
||||
parser->helium[i] = data[gasmix_offset + 6 * i + 2];
|
||||
} else {
|
||||
parser->oxygen[i] = data[gasmix_offset + i];
|
||||
parser->helium[i] = 0.0;
|
||||
if (parser->mode == AIR) {
|
||||
parser->oxygen[0] = 21;
|
||||
parser->helium[0] = 0;
|
||||
parser->ngasmixes = 1;
|
||||
} else {
|
||||
parser->ngasmixes = gasmix_count;
|
||||
for (unsigned int i = 0; i < gasmix_count; ++i) {
|
||||
if (parser->model == HELO2 || parser->model == D4i ||
|
||||
parser->model == D6i || parser->model == D9tx ||
|
||||
parser->model == DX) {
|
||||
parser->oxygen[i] = data[gasmix_offset + 6 * i + 1];
|
||||
parser->helium[i] = data[gasmix_offset + 6 * i + 2];
|
||||
} else {
|
||||
parser->oxygen[i] = data[gasmix_offset + i];
|
||||
parser->helium[i] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
parser->config = config;
|
||||
@ -297,20 +303,11 @@ suunto_d9_parser_get_field (dc_parser_t *abstract, dc_field_type_t type, unsigne
|
||||
*((double *) value) = array_uint16_le (data + 0x09) / 100.0;
|
||||
break;
|
||||
case DC_FIELD_GASMIX_COUNT:
|
||||
if (parser->mode == AIR) {
|
||||
*((unsigned int *) value) = 1;
|
||||
} else {
|
||||
*((unsigned int *) value) = parser->ngasmixes;
|
||||
}
|
||||
*((unsigned int *) value) = parser->ngasmixes;
|
||||
break;
|
||||
case DC_FIELD_GASMIX:
|
||||
if (parser->mode == AIR) {
|
||||
gasmix->helium = 0.0;
|
||||
gasmix->oxygen = 0.21;
|
||||
} else {
|
||||
gasmix->helium = parser->helium[flags] / 100.0;
|
||||
gasmix->oxygen = parser->oxygen[flags] / 100.0;
|
||||
}
|
||||
gasmix->helium = parser->helium[flags] / 100.0;
|
||||
gasmix->oxygen = parser->oxygen[flags] / 100.0;
|
||||
gasmix->nitrogen = 1.0 - gasmix->oxygen - gasmix->helium;
|
||||
break;
|
||||
default:
|
||||
@ -460,15 +457,8 @@ suunto_d9_parser_samples_foreach (dc_parser_t *abstract, dc_sample_callback_t ca
|
||||
|
||||
// Initial gasmix.
|
||||
if (time == 0) {
|
||||
unsigned int he = 0;
|
||||
unsigned int o2 = 0;
|
||||
if (parser->mode == AIR) {
|
||||
he = 0;
|
||||
o2 = 21;
|
||||
} else {
|
||||
he = parser->helium[gasmix];
|
||||
o2 = parser->oxygen[gasmix];
|
||||
}
|
||||
unsigned int he = parser->helium[gasmix];
|
||||
unsigned int o2 = parser->oxygen[gasmix];
|
||||
sample.event.type = SAMPLE_EVENT_GASCHANGE2;
|
||||
sample.event.time = 0;
|
||||
sample.event.value = o2 | (he << 16);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user