You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.4 KiB
45 lines
1.4 KiB
#pragma once |
|
|
|
#include "AP_RangeFinder.h" |
|
#include "AP_RangeFinder_Backend_Serial.h" |
|
|
|
class AP_RangeFinder_LightWareSerial : public AP_RangeFinder_Backend_Serial |
|
{ |
|
|
|
public: |
|
|
|
using AP_RangeFinder_Backend_Serial::AP_RangeFinder_Backend_Serial; |
|
|
|
protected: |
|
|
|
MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override { |
|
return MAV_DISTANCE_SENSOR_LASER; |
|
} |
|
|
|
bool get_signal_quality_pct(uint8_t &quality_pct) const override { |
|
quality_pct = no_signal ? 0 : 100; |
|
return true; |
|
} |
|
|
|
private: |
|
// get a reading |
|
bool get_reading(float &reading_m) override; |
|
bool is_lost_signal_distance(int16_t distance_cm, int16_t distance_cm_max); |
|
|
|
char linebuf[10]; // legacy protocol buffer |
|
uint8_t linebuf_len; // legacy protocol buffer length |
|
uint32_t last_init_ms; // init time used to switch lw20 to serial mode |
|
uint8_t high_byte; // binary protocol high byte |
|
bool high_byte_received; // true if high byte has been received |
|
|
|
// automatic protocol decision variables |
|
enum class ProtocolState { |
|
UNKNOWN, // the protocol used is not yet known |
|
LEGACY, // legacy protocol, distances are sent as strings |
|
BINARY // binary protocol, distances are sent using two bytes |
|
} protocol_state; |
|
uint8_t legacy_valid_count; |
|
uint8_t binary_valid_count; |
|
|
|
bool no_signal = false; |
|
};
|
|
|