Line data Source code
1 : #pragma once 2 : 3 : #include "AP_RangeFinder_config.h" 4 : 5 : #if AP_RANGEFINDER_MAXSONARI2CXL_ENABLED 6 : 7 : #include "AP_RangeFinder.h" 8 : #include "AP_RangeFinder_Backend_I2C.h" 9 : 10 : #define AP_RANGE_FINDER_MAXSONARI2CXL_DEFAULT_ADDR 0x70 11 : #define AP_RANGE_FINDER_MAXSONARI2CXL_COMMAND_TAKE_RANGE_READING 0x51 12 : 13 : class AP_RangeFinder_MaxsonarI2CXL : public AP_RangeFinder_Backend_I2C 14 : { 15 : public: 16 : // static detection function 17 8 : static AP_RangeFinder_Backend *detect(RangeFinder::RangeFinder_State &_state, 18 : AP_RangeFinder_Params &_params, 19 : class AP_HAL::I2CDevice &dev) { 20 : // this will free the object if configuration fails: 21 8 : return configure(NEW_NOTHROW AP_RangeFinder_MaxsonarI2CXL(_state, _params, dev)); 22 : } 23 : 24 : // update state 25 : void update(void) override; 26 : 27 : protected: 28 : 29 3902 : MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override { 30 3902 : return MAV_DISTANCE_SENSOR_ULTRASOUND; 31 : } 32 : 33 : private: 34 : // constructor 35 : using AP_RangeFinder_Backend_I2C::AP_RangeFinder_Backend_I2C; 36 : 37 : bool init(void) override; 38 : void _timer(void); 39 : 40 : uint16_t distance; 41 : bool new_distance; 42 : 43 : // start a reading 44 : bool start_reading(void); 45 : bool get_reading(uint16_t &reading_cm); 46 : }; 47 : 48 : #endif // AP_RANGEFINDER_MAXSONARI2CXL_ENABLED