LCOV - code coverage report
Current view: top level - AP_LeakDetector - AP_LeakDetector.cpp (source / functions) Hit Total Coverage
Test: lcov.info Lines: 21 33 63.6 %
Date: 2026-09-09 11:02:08 Functions: 4 5 80.0 %

          Line data    Source code
       1             : #include "AP_LeakDetector.h"
       2             : #include "AP_LeakDetector_Analog.h"
       3             : #include "AP_LeakDetector_Digital.h"
       4             : 
       5             : extern const AP_HAL::HAL &hal;
       6             : 
       7             : const AP_Param::GroupInfo AP_LeakDetector::var_info[] = {
       8             : 
       9             :     // @Param: 1_PIN
      10             :     // @DisplayName: Pin that leak detector is connected to
      11             :     // @Description: Pin that the leak detector is connected to
      12             :     // @Values: -1:Disabled,50:AUX1,51:AUX2,52:AUX3,53:AUX4,54:AUX5,55:AUX6,13:Pixhawk 3.3ADC1,14:Pixhawk 3.3ADC2,15:Pixhawk 6.6ADC,27:Navigator Built-In
      13             :     // @Range: -1 127
      14             :     // @User: Standard
      15             :     // @RebootRequired: True
      16             :     AP_GROUPINFO("1_PIN", 1, AP_LeakDetector, _pin[0], -1),
      17             : 
      18             :     // @Param: 1_LOGIC
      19             :     // @DisplayName: Default reading of leak detector when dry
      20             :     // @Description: Default reading of leak detector when dry
      21             :     // @Values: 0:Low,1:High
      22             :     // @User: Standard
      23             :     AP_GROUPINFO("1_LOGIC", 2, AP_LeakDetector, _default_reading[0], 0),
      24             : 
      25             :     // 7 was 1_TYPE, specifying analog or digital input type
      26             : 
      27             : #if LEAKDETECTOR_MAX_INSTANCES > 1
      28             :     // @Param: 2_PIN
      29             :     // @DisplayName: Pin that leak detector is connected to
      30             :     // @Description: Pin that the leak detector is connected to
      31             :     // @Values: -1:Disabled,50:AUX1,51:AUX2,52:AUX3,53:AUX4,54:AUX5,55:AUX6,13:Pixhawk 3.3ADC1,14:Pixhawk 3.3ADC2,15:Pixhawk 6.6ADC,27:Navigator Leak1
      32             :     // @Range: -1 127
      33             :     // @User: Standard
      34             :     // @RebootRequired: True
      35             :     AP_GROUPINFO("2_PIN", 3, AP_LeakDetector, _pin[1], -1),
      36             : 
      37             :     // @Param: 2_LOGIC
      38             :     // @DisplayName: Default reading of leak detector when dry
      39             :     // @Description: Default reading of leak detector when dry
      40             :     // @Values: 0:Low,1:High
      41             :     // @User: Standard
      42             :     AP_GROUPINFO("2_LOGIC", 4, AP_LeakDetector, _default_reading[1], 0),
      43             : 
      44             :     // 8 was 2_TYPE, specifying analog or digital input type
      45             : #endif
      46             : 
      47             : #if LEAKDETECTOR_MAX_INSTANCES > 2
      48             :     // @Param: 3_PIN
      49             :     // @DisplayName: Pin that leak detector is connected to
      50             :     // @Description: Pin that the leak detector is connected to
      51             :     // @Values: -1:Disabled,50:AUX1,51:AUX2,52:AUX3,53:AUX4,54:AUX5,55:AUX6,13:Pixhawk 3.3ADC1,14:Pixhawk 3.3ADC2,15:Pixhawk 6.6ADC,27:Navigator Leak1
      52             :     // @Range: -1 127
      53             :     // @User: Standard
      54             :     // @RebootRequired: True
      55             :     AP_GROUPINFO("3_PIN", 5, AP_LeakDetector, _pin[2], -1),
      56             : 
      57             :     // @Param: 3_LOGIC
      58             :     // @DisplayName: Default reading of leak detector when dry
      59             :     // @Description: Default reading of leak detector when dry
      60             :     // @Values: 0:Low,1:High
      61             :     // @User: Standard
      62             :     AP_GROUPINFO("3_LOGIC", 6, AP_LeakDetector, _default_reading[2], 0),
      63             : 
      64             :     // 9 was 3_TYPE, specifying analog or digital input type
      65             : #endif
      66             : 
      67             :     AP_GROUPEND
      68             : };
      69             : 
      70          83 : AP_LeakDetector::AP_LeakDetector() :
      71          83 :     _status(false),
      72         581 :     _last_detect_ms(0)
      73             : {
      74          83 :     AP_Param::setup_object_defaults(this, var_info);
      75             : 
      76          83 :     memset(_state,0,sizeof(_state));
      77          83 :     memset(_drivers,0,sizeof(_drivers));
      78          83 : };
      79             : 
      80          82 : void AP_LeakDetector::init()
      81             : {
      82         328 :     for (int i = 0; i < LEAKDETECTOR_MAX_INSTANCES; i++) {
      83         246 :         if (_pin[i] < 0) {
      84         246 :             continue;
      85             :         }
      86           0 :         if (hal.analogin->valid_analog_pin(_pin[i])) {
      87           0 :                 _state[i].instance = i;
      88           0 :                 _drivers[i] = NEW_NOTHROW AP_LeakDetector_Analog(*this, _state[i]);
      89             :         } else {
      90           0 :                 _state[i].instance = i;
      91           0 :                 _drivers[i] = NEW_NOTHROW AP_LeakDetector_Digital(*this, _state[i]);
      92             :         }
      93             :     }
      94          82 : }
      95             : 
      96       16343 : bool AP_LeakDetector::update()
      97             : {
      98       16343 :     uint32_t tnow = AP_HAL::millis();
      99             : 
     100       65372 :     for (int i = 0; i < LEAKDETECTOR_MAX_INSTANCES; i++) {
     101       49029 :         if (_drivers[i] != NULL) {
     102           0 :             _drivers[i]->read();
     103           0 :             if (_state[i].status) {
     104           0 :                 _last_detect_ms = tnow;
     105             :             }
     106             :         }
     107             :     }
     108             : 
     109       16343 :     _status = tnow < _last_detect_ms + LEAKDETECTOR_COOLDOWN_MS;
     110             : 
     111       16343 :     return _status;
     112             : }
     113             : 
     114           0 : void AP_LeakDetector::set_detect()
     115             : {
     116           0 :     _last_detect_ms = AP_HAL::millis();
     117           0 : }
     118             : 
     119         246 : int8_t AP_LeakDetector::get_pin(uint8_t instance) const
     120             : {
     121         246 :     if (instance >= LEAKDETECTOR_MAX_INSTANCES) {
     122           0 :         return 0;
     123             :     }
     124         246 :     return _pin[instance];
     125             : }

Generated by: LCOV version 1.14