Path: blob/master/libraries/AP_Airspeed/AP_Airspeed_analog.cpp
9645 views
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/14/*15* analog airspeed driver16*/1718#include "AP_Airspeed_analog.h"1920#if AP_AIRSPEED_ANALOG_ENABLED2122#include <AP_HAL/AP_HAL.h>23#include <AP_Common/AP_Common.h>2425#include "AP_Airspeed.h"2627extern const AP_HAL::HAL &hal;2829// scaling for 3DR analog airspeed sensor30#define VOLTS_TO_PASCAL 8193132AP_Airspeed_Analog::AP_Airspeed_Analog(AP_Airspeed &_frontend, uint8_t _instance) :33AP_Airspeed_Backend(_frontend, _instance)34{35_source = hal.analogin->channel(get_pin());36}3738bool AP_Airspeed_Analog::init()39{40return _source != nullptr;41}4243// read the airspeed sensor44bool AP_Airspeed_Analog::get_differential_pressure(float &pressure)45{46// allow pin to change47if (_source == nullptr || !_source->set_pin(get_pin())) {48return false;49}50pressure = _source->voltage_average_ratiometric() * VOLTS_TO_PASCAL / get_psi_range();51return true;52}5354#endif // AP_AIRSPEED_ANALOG_ENABLED555657