AnalogIn_ADS1115.h 981 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #pragma once
  2. #include "AP_HAL_Linux.h"
  3. #include <AP_ADC/AP_ADC_ADS1115.h>
  4. #define ADS1115_ADC_MAX_CHANNELS 6
  5. class AnalogSource_ADS1115: public AP_HAL::AnalogSource {
  6. public:
  7. friend class AnalogIn_ADS1115;
  8. AnalogSource_ADS1115(int16_t pin);
  9. float read_average() override;
  10. float read_latest() override;
  11. void set_pin(uint8_t p) override;
  12. float voltage_average() override;
  13. float voltage_latest() override;
  14. float voltage_average_ratiometric() override;
  15. private:
  16. int16_t _pin;
  17. float _value;
  18. };
  19. class AnalogIn_ADS1115: public AP_HAL::AnalogIn {
  20. public:
  21. AnalogIn_ADS1115();
  22. void init() override;
  23. AP_HAL::AnalogSource *channel(int16_t n) override;
  24. /* Board voltage is not available */
  25. float board_voltage() override { return 5.0f; }
  26. private:
  27. uint8_t _channels_number;
  28. void _update();
  29. AP_ADC_ADS1115 *_adc;
  30. AnalogSource_ADS1115 *_channels[ADS1115_ADC_MAX_CHANNELS];
  31. uint32_t _last_update_timestamp;
  32. };