2011-12-16 16:18:29 -04:00
|
|
|
/// -*- tab-width: 4; Mode: C++; c-basic-offset: 4; indent-tabs-mode: nil -*-
|
2011-11-12 23:14:55 -04:00
|
|
|
|
|
|
|
#ifndef __AP_ANALOG_SOURCE_ARDUINO_H__
|
|
|
|
#define __AP_ANALOG_SOURCE_ARDUINO_H__
|
|
|
|
|
|
|
|
#include "AnalogSource.h"
|
2012-06-29 08:48:34 -03:00
|
|
|
#include "AP_PeriodicProcess.h"
|
|
|
|
|
|
|
|
// special pin number which is interpreted as a
|
|
|
|
// internal Vcc voltage read
|
|
|
|
#define ANALOG_PIN_VCC 255
|
2011-11-12 23:14:55 -04:00
|
|
|
|
|
|
|
class AP_AnalogSource_Arduino : public AP_AnalogSource
|
|
|
|
{
|
|
|
|
public:
|
2012-06-29 08:48:34 -03:00
|
|
|
AP_AnalogSource_Arduino( uint8_t pin, float prescale = 1.0 ) :
|
|
|
|
_prescale(prescale) {
|
|
|
|
assign_pin_index(pin);
|
|
|
|
}
|
|
|
|
|
|
|
|
// setup the timer callback
|
|
|
|
static void init_timer(AP_PeriodicProcess * scheduler);
|
|
|
|
|
|
|
|
// read a value with a prescale
|
2011-12-16 16:18:29 -04:00
|
|
|
float read(void);
|
2011-11-12 23:14:55 -04:00
|
|
|
|
2012-06-29 08:48:34 -03:00
|
|
|
// read the raw 16 bit ADC value
|
|
|
|
uint16_t read_raw(void);
|
|
|
|
|
|
|
|
// read a Vcc value in millivolts
|
|
|
|
uint16_t read_vcc(void);
|
|
|
|
|
|
|
|
// read the average 16 bit ADC value since
|
|
|
|
// we last called read_average().
|
|
|
|
uint16_t read_average(void);
|
|
|
|
|
2011-11-12 23:14:55 -04:00
|
|
|
private:
|
2012-06-29 08:48:34 -03:00
|
|
|
uint8_t _pin_index;
|
2011-12-16 16:18:29 -04:00
|
|
|
float _prescale;
|
2012-06-29 08:48:34 -03:00
|
|
|
|
|
|
|
void assign_pin_index(uint8_t pin);
|
2011-11-12 23:14:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // __AP_ANALOG_SOURCE_ARDUINO_H__
|