2016-02-17 21:25:44 -04:00
|
|
|
#pragma once
|
2015-08-28 06:52:34 -03:00
|
|
|
|
2019-11-10 22:47:38 -04:00
|
|
|
#include "AP_RangeFinder.h"
|
|
|
|
#include "AP_RangeFinder_Backend.h"
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#ifndef AP_RANGEFINDER_LWI2C_ENABLED
|
|
|
|
#define AP_RANGEFINDER_LWI2C_ENABLED AP_RANGEFINDER_BACKEND_DEFAULT_ENABLED
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if AP_RANGEFINDER_LWI2C_ENABLED
|
|
|
|
|
2016-05-24 15:51:54 -03:00
|
|
|
#include <AP_HAL/I2CDevice.h>
|
2015-08-28 06:52:34 -03:00
|
|
|
|
2019-08-14 22:05:30 -03:00
|
|
|
#define NUM_SF20_DATA_STREAMS 1
|
|
|
|
|
2015-08-28 06:52:34 -03:00
|
|
|
class AP_RangeFinder_LightWareI2C : public AP_RangeFinder_Backend
|
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
// static detection function
|
2017-08-07 00:41:01 -03:00
|
|
|
static AP_RangeFinder_Backend *detect(RangeFinder::RangeFinder_State &_state,
|
2019-02-03 22:21:58 -04:00
|
|
|
AP_RangeFinder_Params &_params,
|
2017-08-07 00:41:01 -03:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
|
2015-08-28 06:52:34 -03:00
|
|
|
|
|
|
|
// update state
|
2018-11-07 07:01:51 -04:00
|
|
|
void update(void) override;
|
2015-08-28 06:52:34 -03:00
|
|
|
|
2017-08-08 04:32:53 -03:00
|
|
|
protected:
|
|
|
|
|
2019-08-14 22:05:30 -03:00
|
|
|
virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override
|
|
|
|
{
|
2017-08-08 04:32:53 -03:00
|
|
|
return MAV_DISTANCE_SENSOR_LASER;
|
|
|
|
}
|
|
|
|
|
2015-08-28 06:52:34 -03:00
|
|
|
private:
|
2016-05-24 15:51:54 -03:00
|
|
|
|
2019-08-14 22:05:30 -03:00
|
|
|
uint16_t sf20_stream_val[NUM_SF20_DATA_STREAMS];
|
|
|
|
int currentStreamSequenceIndex = 0;
|
|
|
|
|
|
|
|
// constructor
|
|
|
|
AP_RangeFinder_LightWareI2C(RangeFinder::RangeFinder_State &_state,
|
|
|
|
AP_RangeFinder_Params &_params,
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
|
|
|
|
|
|
|
|
bool write_bytes(uint8_t *write_buf_u8, uint32_t len_u8);
|
2019-09-05 00:06:48 -03:00
|
|
|
void sf20_disable_address_tagging();
|
2019-08-14 22:05:30 -03:00
|
|
|
bool sf20_send_and_expect(const char* send, const char* expected_reply);
|
|
|
|
bool sf20_set_lost_signal_confirmations();
|
2019-09-05 00:06:48 -03:00
|
|
|
void sf20_get_version(const char* send_msg, const char *reply_prefix, char reply[5]);
|
2019-08-14 22:05:30 -03:00
|
|
|
bool sf20_wait_on_reply(uint8_t *rx_two_bytes);
|
|
|
|
bool init();
|
|
|
|
bool legacy_init();
|
|
|
|
bool sf20_init();
|
|
|
|
void sf20_init_streamRecovery();
|
|
|
|
void legacy_timer();
|
|
|
|
void sf20_timer();
|
2017-01-13 15:26:14 -04:00
|
|
|
|
2015-08-28 06:52:34 -03:00
|
|
|
// get a reading
|
2021-10-18 02:45:33 -03:00
|
|
|
bool legacy_get_reading(float &reading_m);
|
|
|
|
bool sf20_get_reading(float &reading_m);
|
2019-08-14 22:05:30 -03:00
|
|
|
bool sf20_parse_stream(uint8_t *stream_buf,
|
|
|
|
size_t *p_num_processed_chars,
|
|
|
|
const char *string_identifier,
|
|
|
|
uint16_t &val);
|
|
|
|
void data_log(uint16_t *val);
|
2016-05-24 15:51:54 -03:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
|
2015-08-28 06:52:34 -03:00
|
|
|
};
|
2022-03-12 06:37:29 -04:00
|
|
|
|
|
|
|
#endif // AP_RANGEFINDER_LWI2C_ENABLED
|