Line data Source code
1 : /* 2 : * Copyright (C) 2019 Lucas De Marchi <[email protected]> 3 : * 4 : * This file is free software: you can redistribute it and/or modify it 5 : * under the terms of the GNU General Public License as published by the 6 : * Free Software Foundation, either version 3 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * This file is distributed in the hope that it will be useful, but 10 : * WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 : * See the GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License along 15 : * with this program. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : #pragma once 18 : 19 : #include "AP_RangeFinder_config.h" 20 : 21 : #if AP_RANGEFINDER_BENEWAKE_TFMINIPLUS_ENABLED 22 : 23 : #include "AP_RangeFinder.h" 24 : #include "AP_RangeFinder_Backend_I2C.h" 25 : 26 : #include <AP_HAL/utility/sparse-endian.h> 27 : 28 : #define TFMINIPLUS_ADDR_DEFAULT 0x10 // TFMini default device id 29 : 30 : class AP_RangeFinder_Benewake_TFMiniPlus : public AP_RangeFinder_Backend_I2C 31 : { 32 : 33 : public: 34 : // static detection function 35 6 : static AP_RangeFinder_Backend *detect(RangeFinder::RangeFinder_State &_state, 36 : AP_RangeFinder_Params &_params, 37 : class AP_HAL::I2CDevice &dev) { 38 : // this will free the object if configuration fails: 39 6 : return configure(NEW_NOTHROW AP_RangeFinder_Benewake_TFMiniPlus(_state, _params, dev)); 40 : } 41 : 42 : // update state 43 : void update(void) override; 44 : 45 : protected: 46 : 47 749 : virtual MAV_DISTANCE_SENSOR _get_mav_distance_sensor_type() const override { 48 749 : return MAV_DISTANCE_SENSOR_LASER; 49 : } 50 : 51 : private: 52 : using AP_RangeFinder_Backend_I2C::AP_RangeFinder_Backend_I2C; 53 : 54 : bool init() override; 55 : void timer(); 56 : 57 : void process_raw_measure(le16_t distance_raw, le16_t strength_raw, 58 : uint16_t &output_distance_cm); 59 : 60 : bool check_checksum(uint8_t *arr, int pkt_len); 61 : 62 : // Track powered down status 63 : struct { 64 : bool commanded_power_down; 65 : bool current_power_down; 66 : } power_state; 67 : 68 : struct { 69 : uint32_t sum; 70 : uint32_t count; 71 : } accum; 72 : }; 73 : 74 : #endif