- 
                Notifications
    
You must be signed in to change notification settings  - Fork 99
 
Shearwater: Display Dive Mode. #89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shearwater: Display Dive Mode. #89
Conversation
8b42e08    to
    4ea0a06      
    Compare
  
    4ea0a06    to
    f2766d8      
    Compare
  
    There was a problem hiding this 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; | 
    
      
    
      Copilot
AI
    
    
    
      Jul 18, 2025 
    
  
There was a problem hiding this comment.
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.
| unsigned int sub_mode = SM_OC_REC; | |
| unsigned int sub_mode = UNDEFINED; // Initialize to UNDEFINED to indicate it has not been set yet. | 
| "Nitrox", | ||
| "OC Recreational", | ||
| }; | ||
| dc_field_add_string_fmt(&parser->cache, name, "%s", sub_mode <= SM_OC_REC ? oc_rec_modes[sub_mode] : "Unknown divemode"); | 
    
      
    
      Copilot
AI
    
    
    
      Jul 18, 2025 
    
  
There was a problem hiding this comment.
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.
| 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"); | 
| "OC Recreational", | ||
| "Freedive", | ||
| }; | ||
| dc_field_add_string_fmt(&parser->cache, name, "%s", divemode <= M_FREEDIVE ? modes[divemode] : "Unknown divemode"); | 
    
      
    
      Copilot
AI
    
    
    
      Jul 18, 2025 
    
  
There was a problem hiding this comment.
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.
| 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"); | 
Display the configured dive mode for Shearwater dive computers in the Extra Info tab. Signed-off-by: Michael Keller <[email protected]>
f2766d8    to
    3ebdf39      
    Compare
  
    
Display the configured dive mode for Shearwater dive computers in the
Extra Info tab.
Signed-off-by: Michael Keller [email protected]