Skip to content

Conversation

@mikeller
Copy link
Member

Display the configured dive mode for Shearwater dive computers in the
Extra Info tab.

image

Signed-off-by: Michael Keller [email protected]

@mikeller mikeller requested a review from Copilot July 18, 2025 11:50

This comment was marked as outdated.

@mikeller mikeller force-pushed the shearwater_add_divemode branch from 8b42e08 to 4ea0a06 Compare July 18, 2025 11:55
@mikeller mikeller requested a review from Copilot July 18, 2025 11:55

This comment was marked as outdated.

@mikeller mikeller force-pushed the shearwater_add_divemode branch from 4ea0a06 to f2766d8 Compare July 18, 2025 11:59
@mikeller mikeller requested a review from Copilot July 18, 2025 11:59
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds display functionality for Shearwater dive computer dive modes in the Extra Info tab. The change extracts and formats dive mode information from the dive computer data, providing users with clear visibility into the configured dive mode for their dives.

  • Adds constants for OC Recreational sub-modes and implements dive mode parsing logic
  • Displays appropriate dive mode names based on the main dive mode and sub-mode configuration
  • Includes minor code cleanup improvements for variable naming and error handling


unsigned int offset = headersize;
unsigned int length = size - footersize;
unsigned int sub_mode = SM_OC_REC;
Copy link

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The sub_mode variable is initialized to SM_OC_REC but only gets updated conditionally. Consider initializing it to a more neutral value or adding a comment explaining why SM_OC_REC is the default.

Suggested change
unsigned int sub_mode = SM_OC_REC;
unsigned int sub_mode = UNDEFINED; // Initialize to UNDEFINED to indicate it has not been set yet.

Copilot uses AI. Check for mistakes.
"Nitrox",
"OC Recreational",
};
dc_field_add_string_fmt(&parser->cache, name, "%s", sub_mode <= SM_OC_REC ? oc_rec_modes[sub_mode] : "Unknown divemode");
Copy link

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Array bounds check uses <= SM_OC_REC but the oc_rec_modes array has 4 elements (indices 0-3). If sub_mode equals SM_OC_REC (which is 3), this will access the last valid index, but the logic suggests this should be a strict bounds check.

Suggested change
dc_field_add_string_fmt(&parser->cache, name, "%s", sub_mode <= SM_OC_REC ? oc_rec_modes[sub_mode] : "Unknown divemode");
dc_field_add_string_fmt(&parser->cache, name, "%s", sub_mode < 4 ? oc_rec_modes[sub_mode] : "Unknown divemode");

Copilot uses AI. Check for mistakes.
"OC Recreational",
"Freedive",
};
dc_field_add_string_fmt(&parser->cache, name, "%s", divemode <= M_FREEDIVE ? modes[divemode] : "Unknown divemode");
Copy link

Copilot AI Jul 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar array bounds issue: the modes array has 8 elements (indices 0-7) and M_FREEDIVE is 7. The <= comparison is correct here, but this inconsistency with the sub_mode check above suggests a potential logic error in one of them.

Suggested change
dc_field_add_string_fmt(&parser->cache, name, "%s", divemode <= M_FREEDIVE ? modes[divemode] : "Unknown divemode");
dc_field_add_string_fmt(&parser->cache, name, "%s", divemode < sizeof(modes) / sizeof(modes[0]) ? modes[divemode] : "Unknown divemode");

Copilot uses AI. Check for mistakes.
Display the configured dive mode for Shearwater dive computers in the
Extra Info tab.

Signed-off-by: Michael Keller <[email protected]>
@mikeller mikeller force-pushed the shearwater_add_divemode branch from f2766d8 to 3ebdf39 Compare July 18, 2025 19:48
@mikeller mikeller merged commit 4e4f1f7 into subsurface:Subsurface-DS9 Jul 23, 2025
8 checks passed
@mikeller mikeller deleted the shearwater_add_divemode branch July 23, 2025 11:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant