Browse Source

AP_RangeFinder: make BLPing backend use new intermediate class

zr-v5.1
Peter Barker 5 years ago committed by Peter Barker
parent
commit
82268ab12c
  1. 24
      libraries/AP_RangeFinder/AP_RangeFinder_BLPing.cpp
  2. 13
      libraries/AP_RangeFinder/AP_RangeFinder_BLPing.h

24
libraries/AP_RangeFinder/AP_RangeFinder_BLPing.cpp

@ -14,7 +14,6 @@
*/ */
#include <AP_HAL/AP_HAL.h> #include <AP_HAL/AP_HAL.h>
#include <AP_SerialManager/AP_SerialManager.h>
#include <GCS_MAVLink/GCS.h> #include <GCS_MAVLink/GCS.h>
#include "AP_RangeFinder_BLPing.h" #include "AP_RangeFinder_BLPing.h"
@ -46,29 +45,6 @@
// 8-n uint8_t[] payload message payload // 8-n uint8_t[] payload message payload
// (n+1)-(n+2) uint16_t checksum the sum of all the non-checksum bytes in the message (low byte, high byte) // (n+1)-(n+2) uint16_t checksum the sum of all the non-checksum bytes in the message (low byte, high byte)
/*
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_BLPing::AP_RangeFinder_BLPing(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 port has been setup to accept rangefinder input
bool AP_RangeFinder_BLPing::detect(uint8_t serial_instance)
{
return AP::serialmanager().find_serial(AP_SerialManager::SerialProtocol_Rangefinder, serial_instance) != nullptr;
}
/* /*
update the state of the sensor update the state of the sensor
*/ */

13
libraries/AP_RangeFinder/AP_RangeFinder_BLPing.h

@ -1,20 +1,14 @@
#pragma once #pragma once
#include "RangeFinder.h" #include "RangeFinder.h"
#include "RangeFinder_Backend.h" #include "RangeFinder_Backend_Serial.h"
class AP_RangeFinder_BLPing : public AP_RangeFinder_Backend class AP_RangeFinder_BLPing : public AP_RangeFinder_Backend_Serial
{ {
public: public:
// constructor using AP_RangeFinder_Backend_Serial::AP_RangeFinder_Backend_Serial;
AP_RangeFinder_BLPing(RangeFinder::RangeFinder_State &_state,
AP_RangeFinder_Params &_params,
uint8_t serial_instance);
// static detection function
static bool detect(uint8_t serial_instance);
// update state // update state
void update(void) override; void update(void) override;
@ -54,7 +48,6 @@ private:
CRC_H CRC_H
}; };
AP_HAL::UARTDriver *uart;
uint32_t last_init_ms; // system time that sensor was last initialised uint32_t last_init_ms; // system time that sensor was last initialised
uint16_t distance_cm; // latest distance uint16_t distance_cm; // latest distance

Loading…
Cancel
Save