Path: blob/master/libraries/AP_Compass/AP_Compass_MSP.cpp
9374 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_Compass_MSP.h"1617#if AP_COMPASS_MSP_ENABLED1819#include <AP_HAL/AP_HAL.h>2021AP_Compass_Backend *AP_Compass_MSP::probe(uint8_t _msp_instance)22{23auto *ret = NEW_NOTHROW AP_Compass_MSP(_msp_instance);24if (ret == nullptr) {25return nullptr;26}27if (!ret->init()) {28delete ret;29return nullptr;30}31return ret;32}3334bool AP_Compass_MSP::init()35{36auto devid = AP_HAL::Device::make_bus_id(AP_HAL::Device::BUS_TYPE_MSP, 0, msp_instance, 0);37if (!register_compass(devid)) {38return false;39}4041set_external(true);4243return true;44}4546void AP_Compass_MSP::handle_msp(const MSP::msp_compass_data_message_t &pkt)47{48if (pkt.instance != msp_instance) {49return;50}51Vector3f field(pkt.magX, pkt.magY, pkt.magZ);52accumulate_sample(field, instance);53}5455void AP_Compass_MSP::read(void)56{57drain_accumulated_samples();58}5960#endif // AP_COMPASS_MSP_ENABLED61626364