From d2b417325ba4024d1d8d1370298d23b17aebb6bd Mon Sep 17 00:00:00 2001 From: Cornelius Schmale Date: Tue, 4 Aug 2026 19:06:52 +0200 Subject: [PATCH] Restrict the default calibration override to the legacy layout When every enabled O2 sensor still carries the calibration value 2100, the parser treats that as a factory default, concludes the cells were never calibrated, and disables all of them. On Petrel Native Format logs that conclusion does not follow. PNF records an explicit per-cell calibrated flag in the same byte the sensor mask is read from, and a Petrel 3 sets it for all three cells while writing 2100 for each of them, at the opening and the closing record alike. The default value therefore says nothing about whether the diver calibrated, and suppressing on it discards cells the computer itself reports as calibrated. 2100 is also the factor the computer uses. Its display shows ppO2 1.3 where the cells read 62/65/62 mV, and it votes by median: 62 * 0.021 = 1.302. Measured on a Petrel 3 log with 419 CCR samples, the cells derived this way track the computer's own voted ppO2 within 0.05 bar across the whole dive. The heuristic keeps applying to the legacy Predator layout it was written for, where calibration is read from a fixed offset rather than from a record carrying its own calibrated flag. --- src/shearwater_predator_parser.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/shearwater_predator_parser.c b/src/shearwater_predator_parser.c index 81f6826e..908dddb7 100644 --- a/src/shearwater_predator_parser.c +++ b/src/shearwater_predator_parser.c @@ -680,12 +680,26 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser) nsensors++; } } - if (nsensors && nsensors == ndefaults) { + if (nsensors && nsensors == ndefaults && !pnf) { // If all (calibrated) sensors still have their factory default // calibration values (2100), they are probably not calibrated // properly. To avoid returning incorrect ppO2 values to the // application, they are manually disabled (e.g. marked as // uncalibrated). + // + // Submersion patch (Shearwater PNF O2 cells): restricted to the + // legacy layout this heuristic was written for. The Petrel Native + // Format records an explicit per-cell calibrated flag in the same + // byte read above, and a Petrel 3 sets it for all three cells while + // writing 2100 for each of them -- so on PNF the default value says + // nothing about whether the diver calibrated, and suppressing on it + // discards cells the computer itself reports as calibrated. 2100 is + // also the factor the computer uses: it displays ppO2 1.3 where the + // cells read 62/65/62 mV, and median(62) * 0.021 = 1.302. Verified + // against the log in test/native/fixtures/petrel3_ccr_o2_cells.bin, + // whose cells track the computer's own voted ppO2 within 0.05 bar + // across the whole dive. See + // packages/libdivecomputer_plugin/patches/0005-shearwater-pnf-o2-cell-calibration.patch. WARNING (abstract->context, "Disabled all O2 sensors due to a default calibration value."); parser->calibrated = 0; } else {