diff --git a/src/suunto_d9_parser.c b/src/suunto_d9_parser.c index 300d07e..6e87173 100644 --- a/src/suunto_d9_parser.c +++ b/src/suunto_d9_parser.c @@ -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);