Path: blob/master/libraries/AP_Compass/AP_Compass_ExternalAHRS.cpp
9383 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*/1415#include <AP_HAL/AP_HAL.h>16#include "AP_Compass_ExternalAHRS.h"1718#if AP_COMPASS_EXTERNALAHRS_ENABLED1920AP_Compass_Backend *AP_Compass_ExternalAHRS::probe(uint8_t port)21{22auto devid = AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_SERIAL,port,0,0);23auto *ret = NEW_NOTHROW AP_Compass_ExternalAHRS();24if (ret == nullptr) {25return nullptr;26}27if (!ret->register_compass(devid)) {28delete ret;29return nullptr;30}31ret->set_external(true);32return ret;33}3435void AP_Compass_ExternalAHRS::handle_external(const AP_ExternalAHRS::mag_data_message_t &pkt)36{37Vector3f field = pkt.field;38accumulate_sample(field);39}4041void AP_Compass_ExternalAHRS::read(void)42{43drain_accumulated_samples();44}4546#endif // AP_COMPASS_EXTERNALAHRS_ENABLED474849