2016-01-28 20:34:51 -04:00
|
|
|
#pragma once
|
2014-11-26 08:03:06 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include "AP_HAL_Linux.h"
|
2018-07-10 02:30:02 -03:00
|
|
|
#include <AP_ADC/AP_ADC_ADS1115.h>
|
2014-11-26 08:03:06 -04:00
|
|
|
|
2015-11-02 11:23:18 -04:00
|
|
|
#define ADS1115_ADC_MAX_CHANNELS 6
|
2014-11-26 08:03:06 -04:00
|
|
|
|
2016-01-28 20:34:51 -04:00
|
|
|
class AnalogSource_ADS1115: public AP_HAL::AnalogSource {
|
2014-11-26 08:03:06 -04:00
|
|
|
public:
|
2016-01-28 20:34:51 -04:00
|
|
|
friend class AnalogIn_ADS1115;
|
|
|
|
AnalogSource_ADS1115(int16_t pin);
|
2019-02-21 19:08:12 -04:00
|
|
|
float read_average() override;
|
|
|
|
float read_latest() override;
|
2021-09-22 16:48:45 -03:00
|
|
|
bool set_pin(uint8_t p) override;
|
2019-02-21 19:08:12 -04:00
|
|
|
float voltage_average() override;
|
|
|
|
float voltage_latest() override;
|
|
|
|
float voltage_average_ratiometric() override;
|
2014-11-26 08:03:06 -04:00
|
|
|
private:
|
|
|
|
int16_t _pin;
|
|
|
|
float _value;
|
|
|
|
};
|
|
|
|
|
2016-01-28 20:34:51 -04:00
|
|
|
class AnalogIn_ADS1115: public AP_HAL::AnalogIn {
|
2014-11-26 08:03:06 -04:00
|
|
|
public:
|
2016-01-28 20:34:51 -04:00
|
|
|
AnalogIn_ADS1115();
|
2016-07-28 11:00:36 -03:00
|
|
|
|
|
|
|
void init() override;
|
|
|
|
AP_HAL::AnalogSource *channel(int16_t n) override;
|
2014-11-26 08:03:06 -04:00
|
|
|
|
|
|
|
/* Board voltage is not available */
|
2016-07-28 11:00:36 -03:00
|
|
|
float board_voltage() override { return 5.0f; }
|
|
|
|
|
2014-11-26 08:03:06 -04:00
|
|
|
private:
|
|
|
|
uint8_t _channels_number;
|
|
|
|
void _update();
|
|
|
|
|
2016-01-28 20:34:51 -04:00
|
|
|
AP_ADC_ADS1115 *_adc;
|
|
|
|
AnalogSource_ADS1115 *_channels[ADS1115_ADC_MAX_CHANNELS];
|
|
|
|
uint32_t _last_update_timestamp;
|
2021-02-05 19:03:58 -04:00
|
|
|
HAL_Semaphore _semaphore;
|
2014-11-26 08:03:06 -04:00
|
|
|
};
|