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: */
|
|
|
|
float read_average();
|
|
|
|
float read_latest();
|
|
|
|
void set_pin(uint8_t p);
|
2013-03-03 01:13:04 -04:00
|
|
|
float voltage_average();
|
2013-09-12 00:23:04 -03:00
|
|
|
float voltage_latest();
|
2015-05-04 21:59:07 -03:00
|
|
|
float voltage_average_ratiometric() {
|
|
|
|
return voltage_average();
|
|
|
|
}
|
2013-05-02 21:08:39 -03:00
|
|
|
void set_stop_pin(uint8_t pin) {}
|
|
|
|
void set_settle_time(uint16_t settle_time_ms) {}
|
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) {}
|
2015-12-02 11:14:20 -04:00
|
|
|
void init();
|
2012-12-14 21:54:26 -04:00
|
|
|
AP_HAL::AnalogSource* channel(int16_t n);
|
2015-05-04 21:59:07 -03:00
|
|
|
float board_voltage(void) {
|
|
|
|
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
|
|
|
};
|