mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-02-21 23:33:57 -04:00
AP_RangeFinder: add intermediate serial backend class to share common code
This commit is contained in:
parent
c51eed1f2a
commit
3538fe360b
@ -43,7 +43,6 @@
|
||||
|
||||
#include <AP_BoardConfig/AP_BoardConfig.h>
|
||||
#include <AP_Logger/AP_Logger.h>
|
||||
#include <AP_SerialManager/AP_SerialManager.h>
|
||||
#include <AP_Vehicle/AP_Vehicle_Type.h>
|
||||
|
||||
extern const AP_HAL::HAL &hal;
|
||||
|
49
libraries/AP_RangeFinder/RangeFinder_Backend_Serial.cpp
Normal file
49
libraries/AP_RangeFinder/RangeFinder_Backend_Serial.cpp
Normal file
@ -0,0 +1,49 @@
|
||||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <AP_HAL/AP_HAL.h>
|
||||
#include "RangeFinder_Backend_Serial.h"
|
||||
#include <AP_SerialManager/AP_SerialManager.h>
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
extern const AP_HAL::HAL& hal;
|
||||
|
||||
/*
|
||||
The constructor also initialises the rangefinder. Note that this
|
||||
constructor is not called until detect() returns true, so we
|
||||
already know that we should setup the rangefinder
|
||||
*/
|
||||
AP_RangeFinder_Backend_Serial::AP_RangeFinder_Backend_Serial(
|
||||
RangeFinder::RangeFinder_State &_state,
|
||||
AP_RangeFinder_Params &_params,
|
||||
uint8_t serial_instance) :
|
||||
AP_RangeFinder_Backend(_state, _params)
|
||||
{
|
||||
const AP_SerialManager &serial_manager = AP::serialmanager();
|
||||
uart = serial_manager.find_serial(AP_SerialManager::SerialProtocol_Rangefinder, serial_instance);
|
||||
if (uart != nullptr) {
|
||||
uart->begin(serial_manager.find_baudrate(AP_SerialManager::SerialProtocol_Rangefinder, serial_instance));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
detect if a Serial rangefinder is connected. We'll detect by simply
|
||||
checking for SerialManager configuration
|
||||
*/
|
||||
bool AP_RangeFinder_Backend_Serial::detect(uint8_t serial_instance)
|
||||
{
|
||||
return AP::serialmanager().find_serial(AP_SerialManager::SerialProtocol_Rangefinder, serial_instance) != nullptr;
|
||||
}
|
19
libraries/AP_RangeFinder/RangeFinder_Backend_Serial.h
Normal file
19
libraries/AP_RangeFinder/RangeFinder_Backend_Serial.h
Normal file
@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
|
||||
#include "RangeFinder_Backend.h"
|
||||
|
||||
class AP_RangeFinder_Backend_Serial : public AP_RangeFinder_Backend
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
AP_RangeFinder_Backend_Serial(RangeFinder::RangeFinder_State &_state,
|
||||
AP_RangeFinder_Params &_params,
|
||||
uint8_t serial_instance);
|
||||
|
||||
// static detection function
|
||||
static bool detect(uint8_t serial_instance);
|
||||
|
||||
protected:
|
||||
|
||||
AP_HAL::UARTDriver *uart = nullptr;
|
||||
};
|
Loading…
Reference in New Issue
Block a user