Skip to content

Commit 3ebdf39

Browse files
committed
Shearwater: Display Dive Mode.
Display the configured dive mode for Shearwater dive computers in the Extra Info tab. Signed-off-by: Michael Keller <[email protected]>
1 parent 6814e19 commit 3ebdf39

File tree

1 file changed

+38
-5
lines changed

1 file changed

+38
-5
lines changed

src/shearwater_predator_parser.c

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@
8181
#define M_OC_REC 6
8282
#define M_FREEDIVE 7
8383

84+
#define SM_3_GAS_NX 0
85+
#define SM_AIR 1
86+
#define SM_NX 2
87+
#define SM_OC_REC 3
88+
8489
#define AI_OFF 0
8590
#define AI_HPCCR 4
8691
#define AI_ON 5
@@ -428,12 +433,12 @@ static void print_calibration(shearwater_predator_parser_t *parser)
428433
{
429434
for (size_t i = 0; i < 3; ++i) {
430435
if (parser->calibrated & (1 << i)) {
431-
static const char *name[] = {
436+
static const char *names[] = {
432437
"Sensor 1 calibration [bar / V]",
433438
"Sensor 2 calibration [bar / V]",
434439
"Sensor 3 calibration [bar / V]",
435440
};
436-
dc_field_add_string_fmt(&parser->cache, name[i], "%.2f", parser->calibration[i] * 1000);
441+
dc_field_add_string_fmt(&parser->cache, names[i], "%.2f", parser->calibration[i] * 1000);
437442
}
438443
}
439444
}
@@ -522,6 +527,7 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
522527

523528
unsigned int offset = headersize;
524529
unsigned int length = size - footersize;
530+
unsigned int sub_mode = SM_OC_REC;
525531
unsigned int stack_time_total_s = 0;
526532
unsigned int stack_time_remaining_s;
527533
while (offset + parser->samplesize <= length) {
@@ -718,6 +724,11 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
718724
dc_field_add_string_fmt(&parser->cache, "Remaining stack time at start [hh:mm:ss]", "%d:%02d:%02d", stack_time_remaining_s / 3600, (stack_time_remaining_s / 60) % 60, stack_time_remaining_s % 60);
719725
}
720726
}
727+
if (logversion >= 12) {
728+
if (divemode == M_OC_REC) {
729+
sub_mode = data[offset + 5];
730+
}
731+
}
721732
if (logversion >= 13) {
722733
tank[0].enabled = data[offset + 19];
723734
memcpy (tank[0].name, data + offset + 20, sizeof (tank[0].name));
@@ -904,14 +915,13 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
904915
break;
905916
}
906917

907-
dc_status_t rc = DC_STATUS_SUCCESS;
908918
if (parser->needs_divecan_calibration_estimate) {
909919
struct dc_parser_sensor_calibration_t data = { 0 };
910920

911-
rc = shearwater_predator_parser_samples_foreach(abstract, NULL, (void *)&data);
921+
dc_status_t rc = shearwater_predator_parser_samples_foreach(abstract, NULL, (void *)&data);
912922

913923
bool calibrated = false;
914-
if (data.sum_ppo2 != 0) {
924+
if (rc == DC_STATUS_SUCCESS && data.sum_ppo2 != 0) {
915925
double calibration = data.sum_calculated_ppo2 / data.sum_ppo2;
916926
if (calibration < 0.98 || calibration > 1.02) {
917927
// The calibration scaling is significant, use it.
@@ -933,6 +943,29 @@ shearwater_predator_parser_cache (shearwater_predator_parser_t *parser)
933943
parser->needs_divecan_calibration_estimate = false;
934944
}
935945

946+
static const char *name = "Divemode";
947+
if (divemode == M_OC_REC) {
948+
static const char *oc_rec_modes[] = {
949+
"3 Gas Nitrox",
950+
"Air",
951+
"Nitrox",
952+
"OC Recreational",
953+
};
954+
dc_field_add_string_fmt(&parser->cache, name, "%s", sub_mode <= SM_OC_REC ? oc_rec_modes[sub_mode] : "Unknown divemode");
955+
} else {
956+
static const char *modes[] = {
957+
"CC / BO",
958+
"OC Technical",
959+
"Gauge",
960+
"PPO2 Display",
961+
"SC / BO",
962+
"CC / BO 2",
963+
"OC Recreational",
964+
"Freedive",
965+
};
966+
dc_field_add_string_fmt(&parser->cache, name, "%s", divemode <= M_FREEDIVE ? modes[divemode] : "Unknown divemode");
967+
}
968+
936969
return DC_STATUS_SUCCESS;
937970
}
938971

0 commit comments

Comments
 (0)