2016-02-17 21:25:28 -04:00
|
|
|
#pragma once
|
2012-12-14 21:54:26 -04:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2015-05-04 03:15:12 -03:00
|
|
|
#include "AP_HAL_SITL_Namespace.h"
|
2012-12-14 21:54:26 -04:00
|
|
|
|
|
|
|
#define SITL_INPUT_MAX_CHANNELS 12
|
|
|
|
|
2015-05-04 03:15:12 -03:00
|
|
|
class HALSITL::ADCSource : public AP_HAL::AnalogSource {
|
2012-12-14 21:54:26 -04:00
|
|
|
public:
|
2016-01-10 02:23:32 -04:00
|
|
|
friend class HALSITL::AnalogIn;
|
2015-05-04 03:15:12 -03:00
|
|
|
/* pin designates the ADC input number */
|
2017-01-09 08:22:43 -04:00
|
|
|
ADCSource(SITL_State *sitlState, int16_t pin);
|
2012-12-14 21:54:26 -04:00
|
|
|
|
|
|
|
/* implement AnalogSource virtual api: */
|
2019-02-21 19:06:59 -04:00
|
|
|
float read_average() override;
|
|
|
|
float read_latest() override;
|
2021-09-22 16:49:14 -03:00
|
|
|
bool set_pin(uint8_t p) override;
|
2019-02-21 19:06:59 -04:00
|
|
|
float voltage_average() override;
|
|
|
|
float voltage_latest() override;
|
|
|
|
float voltage_average_ratiometric() override {
|
2015-05-04 21:59:07 -03:00
|
|
|
return voltage_average();
|
|
|
|
}
|
2012-12-14 21:54:26 -04:00
|
|
|
|
|
|
|
private:
|
2012-12-18 03:42:48 -04:00
|
|
|
SITL_State *_sitlState;
|
2017-01-09 08:22:43 -04:00
|
|
|
int16_t _pin;
|
2012-12-14 21:54:26 -04:00
|
|
|
};
|
|
|
|
|
2016-01-10 02:23:32 -04:00
|
|
|
/* AnalogIn : a concrete class providing the implementations of the
|
2012-12-14 21:54:26 -04:00
|
|
|
* timer event and the AP_HAL::AnalogIn interface */
|
2016-01-10 02:23:32 -04:00
|
|
|
class HALSITL::AnalogIn : public AP_HAL::AnalogIn {
|
2012-12-14 21:54:26 -04:00
|
|
|
public:
|
2017-01-09 08:22:43 -04:00
|
|
|
explicit AnalogIn(SITL_State *sitlState): _sitlState(sitlState) {}
|
2019-02-21 19:06:59 -04:00
|
|
|
void init() override;
|
|
|
|
AP_HAL::AnalogSource* channel(int16_t n) override;
|
|
|
|
float board_voltage(void) override {
|
2015-05-04 21:59:07 -03:00
|
|
|
return 5.0f;
|
|
|
|
}
|
2012-12-14 21:54:26 -04:00
|
|
|
private:
|
|
|
|
static ADCSource* _channels[SITL_INPUT_MAX_CHANNELS];
|
2012-12-18 03:42:48 -04:00
|
|
|
SITL_State *_sitlState;
|
2012-12-14 21:54:26 -04:00
|
|
|
};
|