2019-12-04 00:49:29 -04:00
/*
This program is free software : you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 3 of the License , or
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
along with this program . If not , see < http : //www.gnu.org/licenses/>.
*/
# include "AP_Proximity_Backend_Serial.h"
2021-03-25 04:32:09 -03:00
# if HAL_PROXIMITY_ENABLED
2019-12-04 00:49:29 -04:00
# include <AP_SerialManager/AP_SerialManager.h>
/*
The constructor also initialises the proximity sensor . Note that this
constructor is not called until detect ( ) returns true , so we
already know that we should setup the proximity sensor
*/
AP_Proximity_Backend_Serial : : AP_Proximity_Backend_Serial ( AP_Proximity & _frontend ,
2022-07-05 04:28:24 -03:00
AP_Proximity : : Proximity_State & _state ,
2022-07-12 02:29:35 -03:00
AP_Proximity_Params & _params ,
uint8_t serial_instance ) :
2022-07-05 04:28:24 -03:00
AP_Proximity_Backend ( _frontend , _state , _params )
2019-12-04 00:49:29 -04:00
{
const AP_SerialManager & serial_manager = AP : : serialmanager ( ) ;
2022-07-12 02:29:35 -03:00
_uart = serial_manager . find_serial ( AP_SerialManager : : SerialProtocol_Lidar360 , serial_instance ) ;
2019-12-04 00:49:29 -04:00
if ( _uart ! = nullptr ) {
// start uart with larger receive buffer
2022-07-12 02:29:35 -03:00
_uart - > begin ( serial_manager . find_baudrate ( AP_SerialManager : : SerialProtocol_Lidar360 , serial_instance ) , rxspace ( ) , 0 ) ;
2019-12-04 00:49:29 -04:00
}
}
2022-07-12 02:29:35 -03:00
// static detection function
// detect if a proximity sensor is connected by looking for a configured serial port
// 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
bool AP_Proximity_Backend_Serial : : detect ( uint8_t serial_instance )
2019-12-04 00:49:29 -04:00
{
2022-07-12 02:29:35 -03:00
return AP : : serialmanager ( ) . have_serial ( AP_SerialManager : : SerialProtocol_Lidar360 , serial_instance ) ;
2019-12-04 00:49:29 -04:00
}
2021-03-25 04:32:09 -03:00
# endif // HAL_PROXIMITY_ENABLED