Line data Source code
1 : /* 2 : This program is free software: you can redistribute it and/or modify 3 : it under the terms of the GNU General Public License as published by 4 : the Free Software Foundation, either version 3 of the License, or 5 : (at your option) any later version. 6 : 7 : This program is distributed in the hope that it will be useful, 8 : but WITHOUT ANY WARRANTY; without even the implied warranty of 9 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 : GNU General Public License for more details. 11 : 12 : You should have received a copy of the GNU General Public License 13 : along with this program. If not, see <http://www.gnu.org/licenses/>. 14 : */ 15 : 16 : #include "AP_Proximity_Backend_Serial.h" 17 : 18 : #if HAL_PROXIMITY_ENABLED 19 : #include <AP_SerialManager/AP_SerialManager.h> 20 : 21 : /* 22 : The constructor also initialises the proximity sensor. Note that this 23 : constructor is not called until detect() returns true, so we 24 : already know that we should setup the proximity sensor 25 : */ 26 6 : AP_Proximity_Backend_Serial::AP_Proximity_Backend_Serial(AP_Proximity &_frontend, 27 : AP_Proximity::Proximity_State &_state, 28 : AP_Proximity_Params &_params, 29 6 : uint8_t serial_instance) : 30 6 : AP_Proximity_Backend(_frontend, _state, _params) 31 : { 32 6 : const AP_SerialManager &serial_manager = AP::serialmanager(); 33 6 : _uart = serial_manager.find_serial(AP_SerialManager::SerialProtocol_Lidar360, serial_instance); 34 6 : if (_uart != nullptr) { 35 : // start uart with larger receive buffer 36 6 : _uart->begin(serial_manager.find_baudrate(AP_SerialManager::SerialProtocol_Lidar360, serial_instance), rxspace(), 0); 37 : } 38 6 : } 39 : 40 : // static detection function 41 : // detect if a proximity sensor is connected by looking for a configured serial port 42 : // serial_instance affects which serial port is used. Should be 0 or 1 depending on whether this is the 1st or 2nd proximity sensor with a serial interface 43 6 : bool AP_Proximity_Backend_Serial::detect(uint8_t serial_instance) 44 : { 45 6 : return AP::serialmanager().have_serial(AP_SerialManager::SerialProtocol_Lidar360, serial_instance); 46 : } 47 : 48 : #endif // HAL_PROXIMITY_ENABLED