AP_LeakDetector_Analog.cpp 724 B

123456789101112131415161718192021
  1. #include "AP_LeakDetector_Analog.h"
  2. #include <AP_HAL/AP_HAL.h>
  3. extern const AP_HAL::HAL& hal;
  4. AP_LeakDetector_Analog::AP_LeakDetector_Analog(AP_LeakDetector &_leak_detector, AP_LeakDetector::LeakDetector_State &_state) :
  5. AP_LeakDetector_Backend(_leak_detector, _state)
  6. {
  7. source = hal.analogin->channel(leak_detector._pin[state.instance]);
  8. }
  9. void AP_LeakDetector_Analog::read()
  10. {
  11. if (source != NULL && leak_detector._pin[state.instance] >= 0) {
  12. source->set_pin(leak_detector._pin[state.instance]);
  13. state.status = source->voltage_average() > 2.0f;
  14. state.status = state.status==leak_detector._default_reading[state.instance]?false:true;
  15. } else {
  16. state.status = false;
  17. }
  18. }